]> Git Repo - qemu.git/blame - hw/intc/openpic.c
hw/intc/arm_gicv3: Fix secure-GIC NS ICC_PMR and ICC_RPR accesses
[qemu.git] / hw / intc / openpic.c
CommitLineData
dbda808a
FB
1/*
2 * OpenPIC emulation
5fafdf24 3 *
dbda808a 4 * Copyright (c) 2004 Jocelyn Mayer
704c7e5d 5 * 2011 Alexander Graf
5fafdf24 6 *
dbda808a
FB
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
25/*
26 *
27 * Based on OpenPic implementations:
67b55785 28 * - Intel GW80314 I/O companion chip developer's manual
dbda808a
FB
29 * - Motorola MPC8245 & MPC8540 user manuals.
30 * - Motorola MCP750 (aka Raven) programmer manual.
31 * - Motorola Harrier programmer manuel
32 *
33 * Serial interrupts, as implemented in Raven chipset are not supported yet.
5fafdf24 34 *
dbda808a 35 */
90191d07 36#include "qemu/osdep.h"
83c9f4ca
PB
37#include "hw/hw.h"
38#include "hw/ppc/mac.h"
39#include "hw/pci/pci.h"
0d09e41a 40#include "hw/ppc/openpic.h"
2b927571 41#include "hw/ppc/ppc_e500.h"
83c9f4ca
PB
42#include "hw/sysbus.h"
43#include "hw/pci/msi.h"
da34e65c 44#include "qapi/error.h"
e69a17f6 45#include "qemu/bitops.h"
73d963c0 46#include "qapi/qmp/qerror.h"
03dd024f 47#include "qemu/log.h"
ddd5140b 48#include "qemu/timer.h"
df592270 49#include "qemu/error-report.h"
dbda808a 50
611493d9 51//#define DEBUG_OPENPIC
dbda808a
FB
52
53#ifdef DEBUG_OPENPIC
4c4f0e48 54static const int debug_openpic = 1;
dbda808a 55#else
4c4f0e48 56static const int debug_openpic = 0;
dbda808a 57#endif
dbda808a 58
ddd5140b 59static int get_current_cpu(void);
4c4f0e48
SW
60#define DPRINTF(fmt, ...) do { \
61 if (debug_openpic) { \
df592270 62 info_report("Core%d: " fmt, get_current_cpu(), ## __VA_ARGS__); \
4c4f0e48
SW
63 } \
64 } while (0)
65
d0b72631 66/* OpenPIC capability flags */
be7c236f 67#define OPENPIC_FLAG_IDR_CRIT (1 << 0)
e0dfe5b1 68#define OPENPIC_FLAG_ILR (2 << 0)
dbda808a 69
d0b72631 70/* OpenPIC address map */
780d16b7
AG
71#define OPENPIC_GLB_REG_START 0x0
72#define OPENPIC_GLB_REG_SIZE 0x10F0
73#define OPENPIC_TMR_REG_START 0x10F0
74#define OPENPIC_TMR_REG_SIZE 0x220
732aa6ec
AG
75#define OPENPIC_MSI_REG_START 0x1600
76#define OPENPIC_MSI_REG_SIZE 0x200
e0dfe5b1
SW
77#define OPENPIC_SUMMARY_REG_START 0x3800
78#define OPENPIC_SUMMARY_REG_SIZE 0x800
780d16b7 79#define OPENPIC_SRC_REG_START 0x10000
8935a442 80#define OPENPIC_SRC_REG_SIZE (OPENPIC_MAX_SRC * 0x20)
780d16b7
AG
81#define OPENPIC_CPU_REG_START 0x20000
82#define OPENPIC_CPU_REG_SIZE 0x100 + ((MAX_CPU - 1) * 0x1000)
83
e0dfe5b1
SW
84static FslMpicInfo fsl_mpic_20 = {
85 .max_ext = 12,
86};
b7169916 87
e0dfe5b1
SW
88static FslMpicInfo fsl_mpic_42 = {
89 .max_ext = 12,
90};
3e772232 91
be7c236f
SW
92#define FRR_NIRQ_SHIFT 16
93#define FRR_NCPU_SHIFT 8
94#define FRR_VID_SHIFT 0
825463b3
AG
95
96#define VID_REVISION_1_2 2
d0b72631 97#define VID_REVISION_1_3 3
825463b3 98
be7c236f 99#define VIR_GENERIC 0x00000000 /* Generic Vendor ID */
58b62835 100#define VIR_MPIC2A 0x00004614 /* IBM MPIC-2A */
825463b3 101
be7c236f 102#define GCR_RESET 0x80000000
68c2dd70
AG
103#define GCR_MODE_PASS 0x00000000
104#define GCR_MODE_MIXED 0x20000000
105#define GCR_MODE_PROXY 0x60000000
71c6cacb 106
be7c236f
SW
107#define TBCR_CI 0x80000000 /* count inhibit */
108#define TCCR_TOG 0x80000000 /* toggles when decrement to zero */
825463b3 109
1945dbc1 110#define IDR_EP_SHIFT 31
def60298 111#define IDR_EP_MASK (1U << IDR_EP_SHIFT)
1945dbc1
AG
112#define IDR_CI0_SHIFT 30
113#define IDR_CI1_SHIFT 29
114#define IDR_P1_SHIFT 1
115#define IDR_P0_SHIFT 0
b7169916 116
e0dfe5b1
SW
117#define ILR_INTTGT_MASK 0x000000ff
118#define ILR_INTTGT_INT 0x00
119#define ILR_INTTGT_CINT 0x01 /* critical */
120#define ILR_INTTGT_MCP 0x02 /* machine check */
121
122/* The currently supported INTTGT values happen to be the same as QEMU's
123 * openpic output codes, but don't depend on this. The output codes
124 * could change (unlikely, but...) or support could be added for
125 * more INTTGT values.
126 */
127static const int inttgt_output[][2] = {
128 { ILR_INTTGT_INT, OPENPIC_OUTPUT_INT },
129 { ILR_INTTGT_CINT, OPENPIC_OUTPUT_CINT },
130 { ILR_INTTGT_MCP, OPENPIC_OUTPUT_MCK },
131};
132
133static int inttgt_to_output(int inttgt)
134{
135 int i;
136
137 for (i = 0; i < ARRAY_SIZE(inttgt_output); i++) {
138 if (inttgt_output[i][0] == inttgt) {
139 return inttgt_output[i][1];
140 }
141 }
142
df592270 143 error_report("%s: unsupported inttgt %d", __func__, inttgt);
e0dfe5b1
SW
144 return OPENPIC_OUTPUT_INT;
145}
146
147static int output_to_inttgt(int output)
148{
149 int i;
150
151 for (i = 0; i < ARRAY_SIZE(inttgt_output); i++) {
152 if (inttgt_output[i][1] == output) {
153 return inttgt_output[i][0];
154 }
155 }
156
157 abort();
158}
159
732aa6ec
AG
160#define MSIIR_OFFSET 0x140
161#define MSIIR_SRS_SHIFT 29
162#define MSIIR_SRS_MASK (0x7 << MSIIR_SRS_SHIFT)
163#define MSIIR_IBS_SHIFT 24
164#define MSIIR_IBS_MASK (0x1f << MSIIR_IBS_SHIFT)
165
704c7e5d
AG
166static int get_current_cpu(void)
167{
4917cf44 168 if (!current_cpu) {
c3203fa5
SW
169 return -1;
170 }
171
4917cf44 172 return current_cpu->cpu_index;
704c7e5d
AG
173}
174
a8170e5e 175static uint32_t openpic_cpu_read_internal(void *opaque, hwaddr addr,
704c7e5d 176 int idx);
a8170e5e 177static void openpic_cpu_write_internal(void *opaque, hwaddr addr,
704c7e5d 178 uint32_t val, int idx);
8ebe65f3 179static void openpic_reset(DeviceState *d);
704c7e5d 180
ddd5140b
AL
181/* Convert between openpic clock ticks and nanosecs. In the hardware the clock
182 frequency is driven by board inputs to the PIC which the PIC would then
183 divide by 4 or 8. For now hard code to 25MZ.
184*/
185#define OPENPIC_TIMER_FREQ_MHZ 25
186#define OPENPIC_TIMER_NS_PER_TICK (1000 / OPENPIC_TIMER_FREQ_MHZ)
187static inline uint64_t ns_to_ticks(uint64_t ns)
188{
189 return ns / OPENPIC_TIMER_NS_PER_TICK;
190}
191static inline uint64_t ticks_to_ns(uint64_t ticks)
192{
193 return ticks * OPENPIC_TIMER_NS_PER_TICK;
194}
195
af7e9e74 196static inline void IRQ_setbit(IRQQueue *q, int n_IRQ)
dbda808a 197{
e69a17f6 198 set_bit(n_IRQ, q->queue);
dbda808a
FB
199}
200
af7e9e74 201static inline void IRQ_resetbit(IRQQueue *q, int n_IRQ)
dbda808a 202{
e69a17f6 203 clear_bit(n_IRQ, q->queue);
dbda808a
FB
204}
205
af7e9e74 206static void IRQ_check(OpenPICState *opp, IRQQueue *q)
dbda808a 207{
4417c733
SW
208 int irq = -1;
209 int next = -1;
210 int priority = -1;
211
212 for (;;) {
213 irq = find_next_bit(q->queue, opp->max_irq, irq + 1);
214 if (irq == opp->max_irq) {
215 break;
216 }
76aec1f8 217
df592270 218 DPRINTF("IRQ_check: irq %d set ivpr_pr=%d pr=%d",
4417c733 219 irq, IVPR_PRIORITY(opp->src[irq].ivpr), priority);
76aec1f8 220
4417c733
SW
221 if (IVPR_PRIORITY(opp->src[irq].ivpr) > priority) {
222 next = irq;
223 priority = IVPR_PRIORITY(opp->src[irq].ivpr);
060fbfe1 224 }
dbda808a 225 }
76aec1f8 226
dbda808a
FB
227 q->next = next;
228 q->priority = priority;
229}
230
af7e9e74 231static int IRQ_get_next(OpenPICState *opp, IRQQueue *q)
dbda808a 232{
3c94378e
SW
233 /* XXX: optimize */
234 IRQ_check(opp, q);
dbda808a
FB
235
236 return q->next;
237}
238
9f1d4b1d
SW
239static void IRQ_local_pipe(OpenPICState *opp, int n_CPU, int n_IRQ,
240 bool active, bool was_active)
dbda808a 241{
af7e9e74
AG
242 IRQDest *dst;
243 IRQSource *src;
dbda808a
FB
244 int priority;
245
246 dst = &opp->dst[n_CPU];
247 src = &opp->src[n_IRQ];
5e22c276 248
df592270 249 DPRINTF("%s: IRQ %d active %d was %d",
9f1d4b1d
SW
250 __func__, n_IRQ, active, was_active);
251
5e22c276 252 if (src->output != OPENPIC_OUTPUT_INT) {
df592270 253 DPRINTF("%s: output %d irq %d active %d was %d count %d",
9f1d4b1d
SW
254 __func__, src->output, n_IRQ, active, was_active,
255 dst->outputs_active[src->output]);
256
5e22c276
SW
257 /* On Freescale MPIC, critical interrupts ignore priority,
258 * IACK, EOI, etc. Before MPIC v4.1 they also ignore
259 * masking.
260 */
9f1d4b1d
SW
261 if (active) {
262 if (!was_active && dst->outputs_active[src->output]++ == 0) {
df592270 263 DPRINTF("%s: Raise OpenPIC output %d cpu %d irq %d",
9f1d4b1d
SW
264 __func__, src->output, n_CPU, n_IRQ);
265 qemu_irq_raise(dst->irqs[src->output]);
266 }
267 } else {
268 if (was_active && --dst->outputs_active[src->output] == 0) {
df592270 269 DPRINTF("%s: Lower OpenPIC output %d cpu %d irq %d",
9f1d4b1d
SW
270 __func__, src->output, n_CPU, n_IRQ);
271 qemu_irq_lower(dst->irqs[src->output]);
272 }
273 }
274
060fbfe1 275 return;
dbda808a 276 }
5e22c276 277
be7c236f 278 priority = IVPR_PRIORITY(src->ivpr);
9f1d4b1d
SW
279
280 /* Even if the interrupt doesn't have enough priority,
281 * it is still raised, in case ctpr is lowered later.
282 */
283 if (active) {
284 IRQ_setbit(&dst->raised, n_IRQ);
285 } else {
286 IRQ_resetbit(&dst->raised, n_IRQ);
dbda808a 287 }
9f1d4b1d 288
3c94378e 289 IRQ_check(opp, &dst->raised);
9f1d4b1d
SW
290
291 if (active && priority <= dst->ctpr) {
df592270 292 DPRINTF("%s: IRQ %d priority %d too low for ctpr %d on CPU %d",
9f1d4b1d
SW
293 __func__, n_IRQ, priority, dst->ctpr, n_CPU);
294 active = 0;
e9df014c 295 }
9f1d4b1d
SW
296
297 if (active) {
298 if (IRQ_get_next(opp, &dst->servicing) >= 0 &&
299 priority <= dst->servicing.priority) {
df592270 300 DPRINTF("%s: IRQ %d is hidden by servicing IRQ %d on CPU %d",
9f1d4b1d
SW
301 __func__, n_IRQ, dst->servicing.next, n_CPU);
302 } else {
df592270 303 DPRINTF("%s: Raise OpenPIC INT output cpu %d irq %d/%d",
9f1d4b1d
SW
304 __func__, n_CPU, n_IRQ, dst->raised.next);
305 qemu_irq_raise(opp->dst[n_CPU].irqs[OPENPIC_OUTPUT_INT]);
306 }
307 } else {
308 IRQ_get_next(opp, &dst->servicing);
309 if (dst->raised.priority > dst->ctpr &&
310 dst->raised.priority > dst->servicing.priority) {
df592270 311 DPRINTF("%s: IRQ %d inactive, IRQ %d prio %d above %d/%d, CPU %d",
9f1d4b1d
SW
312 __func__, n_IRQ, dst->raised.next, dst->raised.priority,
313 dst->ctpr, dst->servicing.priority, n_CPU);
314 /* IRQ line stays asserted */
315 } else {
df592270 316 DPRINTF("%s: IRQ %d inactive, current prio %d/%d, CPU %d",
9f1d4b1d
SW
317 __func__, n_IRQ, dst->ctpr, dst->servicing.priority, n_CPU);
318 qemu_irq_lower(opp->dst[n_CPU].irqs[OPENPIC_OUTPUT_INT]);
319 }
dbda808a
FB
320 }
321}
322
611493d9 323/* update pic state because registers for n_IRQ have changed value */
6d544ee8 324static void openpic_update_irq(OpenPICState *opp, int n_IRQ)
dbda808a 325{
af7e9e74 326 IRQSource *src;
9f1d4b1d 327 bool active, was_active;
dbda808a
FB
328 int i;
329
330 src = &opp->src[n_IRQ];
9f1d4b1d 331 active = src->pending;
611493d9 332
72c1da2c 333 if ((src->ivpr & IVPR_MASK_MASK) && !src->nomask) {
060fbfe1 334 /* Interrupt source is disabled */
df592270 335 DPRINTF("%s: IRQ %d is disabled", __func__, n_IRQ);
9f1d4b1d 336 active = false;
dbda808a 337 }
9f1d4b1d
SW
338
339 was_active = !!(src->ivpr & IVPR_ACTIVITY_MASK);
340
341 /*
342 * We don't have a similar check for already-active because
343 * ctpr may have changed and we need to withdraw the interrupt.
344 */
345 if (!active && !was_active) {
df592270 346 DPRINTF("%s: IRQ %d is already inactive", __func__, n_IRQ);
060fbfe1 347 return;
dbda808a 348 }
9f1d4b1d
SW
349
350 if (active) {
351 src->ivpr |= IVPR_ACTIVITY_MASK;
352 } else {
353 src->ivpr &= ~IVPR_ACTIVITY_MASK;
611493d9 354 }
9f1d4b1d 355
f40c360c 356 if (src->destmask == 0) {
060fbfe1 357 /* No target */
df592270 358 DPRINTF("%s: IRQ %d has no target", __func__, n_IRQ);
060fbfe1 359 return;
dbda808a 360 }
611493d9 361
f40c360c 362 if (src->destmask == (1 << src->last_cpu)) {
e9df014c 363 /* Only one CPU is allowed to receive this IRQ */
9f1d4b1d 364 IRQ_local_pipe(opp, src->last_cpu, n_IRQ, active, was_active);
be7c236f 365 } else if (!(src->ivpr & IVPR_MODE_MASK)) {
611493d9
FB
366 /* Directed delivery mode */
367 for (i = 0; i < opp->nb_cpus; i++) {
5e22c276 368 if (src->destmask & (1 << i)) {
9f1d4b1d 369 IRQ_local_pipe(opp, i, n_IRQ, active, was_active);
1945dbc1 370 }
611493d9 371 }
dbda808a 372 } else {
611493d9 373 /* Distributed delivery mode */
e9df014c 374 for (i = src->last_cpu + 1; i != src->last_cpu; i++) {
af7e9e74 375 if (i == opp->nb_cpus) {
611493d9 376 i = 0;
af7e9e74 377 }
5e22c276 378 if (src->destmask & (1 << i)) {
9f1d4b1d 379 IRQ_local_pipe(opp, i, n_IRQ, active, was_active);
611493d9
FB
380 src->last_cpu = i;
381 break;
382 }
383 }
384 }
385}
386
d537cf6c 387static void openpic_set_irq(void *opaque, int n_IRQ, int level)
611493d9 388{
6d544ee8 389 OpenPICState *opp = opaque;
af7e9e74 390 IRQSource *src;
611493d9 391
8935a442 392 if (n_IRQ >= OPENPIC_MAX_IRQ) {
df592270 393 error_report("%s: IRQ %d out of range", __func__, n_IRQ);
65b9d0d5
SW
394 abort();
395 }
611493d9
FB
396
397 src = &opp->src[n_IRQ];
df592270 398 DPRINTF("openpic: set irq %d = %d ivpr=0x%08x",
be7c236f 399 n_IRQ, level, src->ivpr);
6c5e84c2 400 if (src->level) {
611493d9
FB
401 /* level-sensitive irq */
402 src->pending = level;
9f1d4b1d 403 openpic_update_irq(opp, n_IRQ);
611493d9
FB
404 } else {
405 /* edge-sensitive irq */
af7e9e74 406 if (level) {
611493d9 407 src->pending = 1;
9f1d4b1d
SW
408 openpic_update_irq(opp, n_IRQ);
409 }
410
411 if (src->output != OPENPIC_OUTPUT_INT) {
412 /* Edge-triggered interrupts shouldn't be used
413 * with non-INT delivery, but just in case,
414 * try to make it do something sane rather than
415 * cause an interrupt storm. This is close to
416 * what you'd probably see happen in real hardware.
417 */
418 src->pending = 0;
419 openpic_update_irq(opp, n_IRQ);
af7e9e74 420 }
dbda808a
FB
421 }
422}
423
be7c236f 424static inline uint32_t read_IRQreg_idr(OpenPICState *opp, int n_IRQ)
dbda808a 425{
be7c236f 426 return opp->src[n_IRQ].idr;
8d3a8c1e 427}
dbda808a 428
e0dfe5b1
SW
429static inline uint32_t read_IRQreg_ilr(OpenPICState *opp, int n_IRQ)
430{
431 if (opp->flags & OPENPIC_FLAG_ILR) {
432 return output_to_inttgt(opp->src[n_IRQ].output);
433 }
434
435 return 0xffffffff;
436}
437
be7c236f 438static inline uint32_t read_IRQreg_ivpr(OpenPICState *opp, int n_IRQ)
8d3a8c1e 439{
be7c236f 440 return opp->src[n_IRQ].ivpr;
dbda808a
FB
441}
442
be7c236f 443static inline void write_IRQreg_idr(OpenPICState *opp, int n_IRQ, uint32_t val)
dbda808a 444{
5e22c276
SW
445 IRQSource *src = &opp->src[n_IRQ];
446 uint32_t normal_mask = (1UL << opp->nb_cpus) - 1;
447 uint32_t crit_mask = 0;
448 uint32_t mask = normal_mask;
449 int crit_shift = IDR_EP_SHIFT - opp->nb_cpus;
450 int i;
451
452 if (opp->flags & OPENPIC_FLAG_IDR_CRIT) {
453 crit_mask = mask << crit_shift;
454 mask |= crit_mask | IDR_EP;
455 }
456
457 src->idr = val & mask;
df592270 458 DPRINTF("Set IDR %d to 0x%08x", n_IRQ, src->idr);
5e22c276
SW
459
460 if (opp->flags & OPENPIC_FLAG_IDR_CRIT) {
461 if (src->idr & crit_mask) {
462 if (src->idr & normal_mask) {
463 DPRINTF("%s: IRQ configured for multiple output types, using "
df592270 464 "critical", __func__);
5e22c276 465 }
dbda808a 466
5e22c276 467 src->output = OPENPIC_OUTPUT_CINT;
72c1da2c 468 src->nomask = true;
5e22c276
SW
469 src->destmask = 0;
470
471 for (i = 0; i < opp->nb_cpus; i++) {
472 int n_ci = IDR_CI0_SHIFT - i;
dbda808a 473
5e22c276
SW
474 if (src->idr & (1UL << n_ci)) {
475 src->destmask |= 1UL << i;
476 }
477 }
478 } else {
479 src->output = OPENPIC_OUTPUT_INT;
72c1da2c 480 src->nomask = false;
5e22c276
SW
481 src->destmask = src->idr & normal_mask;
482 }
483 } else {
484 src->destmask = src->idr;
485 }
11de8b71
AG
486}
487
e0dfe5b1
SW
488static inline void write_IRQreg_ilr(OpenPICState *opp, int n_IRQ, uint32_t val)
489{
490 if (opp->flags & OPENPIC_FLAG_ILR) {
491 IRQSource *src = &opp->src[n_IRQ];
492
493 src->output = inttgt_to_output(val & ILR_INTTGT_MASK);
df592270 494 DPRINTF("Set ILR %d to 0x%08x, output %d", n_IRQ, src->idr,
e0dfe5b1
SW
495 src->output);
496
497 /* TODO: on MPIC v4.0 only, set nomask for non-INT */
498 }
499}
500
be7c236f 501static inline void write_IRQreg_ivpr(OpenPICState *opp, int n_IRQ, uint32_t val)
11de8b71 502{
6c5e84c2
SW
503 uint32_t mask;
504
505 /* NOTE when implementing newer FSL MPIC models: starting with v4.0,
506 * the polarity bit is read-only on internal interrupts.
507 */
508 mask = IVPR_MASK_MASK | IVPR_PRIORITY_MASK | IVPR_SENSE_MASK |
509 IVPR_POLARITY_MASK | opp->vector_mask;
510
11de8b71 511 /* ACTIVITY bit is read-only */
6c5e84c2
SW
512 opp->src[n_IRQ].ivpr =
513 (opp->src[n_IRQ].ivpr & IVPR_ACTIVITY_MASK) | (val & mask);
514
515 /* For FSL internal interrupts, The sense bit is reserved and zero,
516 * and the interrupt is always level-triggered. Timers and IPIs
517 * have no sense or polarity bits, and are edge-triggered.
518 */
519 switch (opp->src[n_IRQ].type) {
520 case IRQ_TYPE_NORMAL:
521 opp->src[n_IRQ].level = !!(opp->src[n_IRQ].ivpr & IVPR_SENSE_MASK);
522 break;
523
524 case IRQ_TYPE_FSLINT:
525 opp->src[n_IRQ].ivpr &= ~IVPR_SENSE_MASK;
526 break;
527
528 case IRQ_TYPE_FSLSPECIAL:
529 opp->src[n_IRQ].ivpr &= ~(IVPR_POLARITY_MASK | IVPR_SENSE_MASK);
530 break;
531 }
532
11de8b71 533 openpic_update_irq(opp, n_IRQ);
df592270 534 DPRINTF("Set IVPR %d to 0x%08x -> 0x%08x", n_IRQ, val,
be7c236f 535 opp->src[n_IRQ].ivpr);
dbda808a
FB
536}
537
7f11573b
AG
538static void openpic_gcr_write(OpenPICState *opp, uint64_t val)
539{
e49798b1 540 bool mpic_proxy = false;
1ac3d713 541
7f11573b 542 if (val & GCR_RESET) {
e1766344 543 openpic_reset(DEVICE(opp));
1ac3d713
AG
544 return;
545 }
7f11573b 546
1ac3d713
AG
547 opp->gcr &= ~opp->mpic_mode_mask;
548 opp->gcr |= val & opp->mpic_mode_mask;
7f11573b 549
1ac3d713
AG
550 /* Set external proxy mode */
551 if ((val & opp->mpic_mode_mask) == GCR_MODE_PROXY) {
e49798b1 552 mpic_proxy = true;
7f11573b 553 }
e49798b1
AG
554
555 ppce500_set_mpic_proxy(mpic_proxy);
7f11573b
AG
556}
557
b9b2aaa3
AG
558static void openpic_gbl_write(void *opaque, hwaddr addr, uint64_t val,
559 unsigned len)
dbda808a 560{
6d544ee8 561 OpenPICState *opp = opaque;
af7e9e74 562 IRQDest *dst;
e9df014c 563 int idx;
dbda808a 564
df592270 565 DPRINTF("%s: addr %#" HWADDR_PRIx " <= %08" PRIx64,
4c4f0e48 566 __func__, addr, val);
af7e9e74 567 if (addr & 0xF) {
dbda808a 568 return;
af7e9e74 569 }
dbda808a 570 switch (addr) {
3e772232
BB
571 case 0x00: /* Block Revision Register1 (BRR1) is Readonly */
572 break;
704c7e5d
AG
573 case 0x40:
574 case 0x50:
575 case 0x60:
576 case 0x70:
577 case 0x80:
578 case 0x90:
579 case 0xA0:
580 case 0xB0:
581 openpic_cpu_write_internal(opp, addr, val, get_current_cpu());
dbda808a 582 break;
be7c236f 583 case 0x1000: /* FRR */
dbda808a 584 break;
be7c236f 585 case 0x1020: /* GCR */
7f11573b 586 openpic_gcr_write(opp, val);
060fbfe1 587 break;
be7c236f 588 case 0x1080: /* VIR */
060fbfe1 589 break;
be7c236f 590 case 0x1090: /* PIR */
e9df014c 591 for (idx = 0; idx < opp->nb_cpus; idx++) {
be7c236f 592 if ((val & (1 << idx)) && !(opp->pir & (1 << idx))) {
df592270 593 DPRINTF("Raise OpenPIC RESET output for CPU %d", idx);
e9df014c
JM
594 dst = &opp->dst[idx];
595 qemu_irq_raise(dst->irqs[OPENPIC_OUTPUT_RESET]);
be7c236f 596 } else if (!(val & (1 << idx)) && (opp->pir & (1 << idx))) {
df592270 597 DPRINTF("Lower OpenPIC RESET output for CPU %d", idx);
e9df014c
JM
598 dst = &opp->dst[idx];
599 qemu_irq_lower(dst->irqs[OPENPIC_OUTPUT_RESET]);
600 }
dbda808a 601 }
be7c236f 602 opp->pir = val;
060fbfe1 603 break;
be7c236f 604 case 0x10A0: /* IPI_IVPR */
704c7e5d
AG
605 case 0x10B0:
606 case 0x10C0:
607 case 0x10D0:
dbda808a
FB
608 {
609 int idx;
704c7e5d 610 idx = (addr - 0x10A0) >> 4;
be7c236f 611 write_IRQreg_ivpr(opp, opp->irq_ipi0 + idx, val);
dbda808a
FB
612 }
613 break;
704c7e5d 614 case 0x10E0: /* SPVE */
0fe04622 615 opp->spve = val & opp->vector_mask;
dbda808a 616 break;
dbda808a
FB
617 default:
618 break;
619 }
620}
621
b9b2aaa3 622static uint64_t openpic_gbl_read(void *opaque, hwaddr addr, unsigned len)
dbda808a 623{
6d544ee8 624 OpenPICState *opp = opaque;
dbda808a
FB
625 uint32_t retval;
626
df592270 627 DPRINTF("%s: addr %#" HWADDR_PRIx, __func__, addr);
dbda808a 628 retval = 0xFFFFFFFF;
af7e9e74 629 if (addr & 0xF) {
dbda808a 630 return retval;
af7e9e74 631 }
dbda808a 632 switch (addr) {
be7c236f
SW
633 case 0x1000: /* FRR */
634 retval = opp->frr;
dbda808a 635 break;
be7c236f
SW
636 case 0x1020: /* GCR */
637 retval = opp->gcr;
060fbfe1 638 break;
be7c236f
SW
639 case 0x1080: /* VIR */
640 retval = opp->vir;
060fbfe1 641 break;
be7c236f 642 case 0x1090: /* PIR */
dbda808a 643 retval = 0x00000000;
060fbfe1 644 break;
3e772232 645 case 0x00: /* Block Revision Register1 (BRR1) */
0d404683
SW
646 retval = opp->brr1;
647 break;
704c7e5d
AG
648 case 0x40:
649 case 0x50:
650 case 0x60:
651 case 0x70:
652 case 0x80:
653 case 0x90:
654 case 0xA0:
dbda808a 655 case 0xB0:
704c7e5d
AG
656 retval = openpic_cpu_read_internal(opp, addr, get_current_cpu());
657 break;
be7c236f 658 case 0x10A0: /* IPI_IVPR */
704c7e5d
AG
659 case 0x10B0:
660 case 0x10C0:
661 case 0x10D0:
dbda808a
FB
662 {
663 int idx;
704c7e5d 664 idx = (addr - 0x10A0) >> 4;
be7c236f 665 retval = read_IRQreg_ivpr(opp, opp->irq_ipi0 + idx);
dbda808a 666 }
060fbfe1 667 break;
704c7e5d 668 case 0x10E0: /* SPVE */
dbda808a
FB
669 retval = opp->spve;
670 break;
dbda808a
FB
671 default:
672 break;
673 }
df592270 674 DPRINTF("%s: => 0x%08x", __func__, retval);
dbda808a
FB
675
676 return retval;
677}
678
ddd5140b
AL
679static void openpic_tmr_set_tmr(OpenPICTimer *tmr, uint32_t val, bool enabled);
680
681static void qemu_timer_cb(void *opaque)
682{
683 OpenPICTimer *tmr = opaque;
684 OpenPICState *opp = tmr->opp;
685 uint32_t n_IRQ = tmr->n_IRQ;
686 uint32_t val = tmr->tbcr & ~TBCR_CI;
687 uint32_t tog = ((tmr->tccr & TCCR_TOG) ^ TCCR_TOG); /* invert toggle. */
688
df592270 689 DPRINTF("%s n_IRQ=%d", __func__, n_IRQ);
ddd5140b
AL
690 /* Reload current count from base count and setup timer. */
691 tmr->tccr = val | tog;
692 openpic_tmr_set_tmr(tmr, val, /*enabled=*/true);
693 /* Raise the interrupt. */
694 opp->src[n_IRQ].destmask = read_IRQreg_idr(opp, n_IRQ);
695 openpic_set_irq(opp, n_IRQ, 1);
696 openpic_set_irq(opp, n_IRQ, 0);
697}
698
699/* If enabled is true, arranges for an interrupt to be raised val clocks into
700 the future, if enabled is false cancels the timer. */
701static void openpic_tmr_set_tmr(OpenPICTimer *tmr, uint32_t val, bool enabled)
702{
703 uint64_t ns = ticks_to_ns(val & ~TCCR_TOG);
704 /* A count of zero causes a timer to be set to expire immediately. This
705 effectively stops the simulation since the timer is constantly expiring
706 which prevents guest code execution, so we don't honor that
707 configuration. On real hardware, this situation would generate an
708 interrupt on every clock cycle if the interrupt was unmasked. */
709 if ((ns == 0) || !enabled) {
710 tmr->qemu_timer_active = false;
711 tmr->tccr = tmr->tccr & TCCR_TOG;
712 timer_del(tmr->qemu_timer); /* set timer to never expire. */
713 } else {
714 tmr->qemu_timer_active = true;
715 uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
716 tmr->origin_time = now;
717 timer_mod(tmr->qemu_timer, now + ns); /* set timer expiration. */
718 }
719}
720
721/* Returns the currrent tccr value, i.e., timer value (in clocks) with
722 appropriate TOG. */
723static uint64_t openpic_tmr_get_timer(OpenPICTimer *tmr)
724{
725 uint64_t retval;
726 if (!tmr->qemu_timer_active) {
727 retval = tmr->tccr;
728 } else {
729 uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
730 uint64_t used = now - tmr->origin_time; /* nsecs */
731 uint32_t used_ticks = (uint32_t)ns_to_ticks(used);
732 uint32_t count = (tmr->tccr & ~TCCR_TOG) - used_ticks;
733 retval = (uint32_t)((tmr->tccr & TCCR_TOG) | (count & ~TCCR_TOG));
734 }
735 return retval;
736}
737
6d544ee8 738static void openpic_tmr_write(void *opaque, hwaddr addr, uint64_t val,
a09f7443 739 unsigned len)
dbda808a 740{
6d544ee8 741 OpenPICState *opp = opaque;
dbda808a
FB
742 int idx;
743
df592270 744 DPRINTF("%s: addr %#" HWADDR_PRIx " <= %08" PRIx64,
a09f7443 745 __func__, (addr + 0x10f0), val);
af7e9e74 746 if (addr & 0xF) {
dbda808a 747 return;
af7e9e74 748 }
c38c0b8a 749
a09f7443 750 if (addr == 0) {
be7c236f
SW
751 /* TFRR */
752 opp->tfrr = val;
c38c0b8a
AG
753 return;
754 }
a09f7443 755 addr -= 0x10; /* correct for TFRR */
03274d44 756 idx = (addr >> 6) & 0x3;
03274d44 757
c38c0b8a 758 switch (addr & 0x30) {
be7c236f 759 case 0x00: /* TCCR */
dbda808a 760 break;
be7c236f 761 case 0x10: /* TBCR */
ddd5140b
AL
762 /* Did the enable status change? */
763 if ((opp->timers[idx].tbcr & TBCR_CI) != (val & TBCR_CI)) {
764 /* Did "Count Inhibit" transition from 1 to 0? */
765 if ((val & TBCR_CI) == 0) {
766 opp->timers[idx].tccr = val & ~TCCR_TOG;
767 }
768 openpic_tmr_set_tmr(&opp->timers[idx],
769 (val & ~TBCR_CI),
770 /*enabled=*/((val & TBCR_CI) == 0));
71c6cacb 771 }
be7c236f 772 opp->timers[idx].tbcr = val;
060fbfe1 773 break;
be7c236f
SW
774 case 0x20: /* TVPR */
775 write_IRQreg_ivpr(opp, opp->irq_tim0 + idx, val);
060fbfe1 776 break;
be7c236f
SW
777 case 0x30: /* TDR */
778 write_IRQreg_idr(opp, opp->irq_tim0 + idx, val);
060fbfe1 779 break;
dbda808a
FB
780 }
781}
782
6d544ee8 783static uint64_t openpic_tmr_read(void *opaque, hwaddr addr, unsigned len)
dbda808a 784{
6d544ee8 785 OpenPICState *opp = opaque;
c38c0b8a 786 uint32_t retval = -1;
dbda808a
FB
787 int idx;
788
df592270 789 DPRINTF("%s: addr %#" HWADDR_PRIx, __func__, addr + 0x10f0);
c38c0b8a
AG
790 if (addr & 0xF) {
791 goto out;
792 }
a09f7443 793 if (addr == 0) {
be7c236f
SW
794 /* TFRR */
795 retval = opp->tfrr;
c38c0b8a
AG
796 goto out;
797 }
a09f7443
AL
798 addr -= 0x10; /* correct for TFRR */
799 idx = (addr >> 6) & 0x3;
c38c0b8a 800 switch (addr & 0x30) {
be7c236f 801 case 0x00: /* TCCR */
ddd5140b 802 retval = openpic_tmr_get_timer(&opp->timers[idx]);
dbda808a 803 break;
be7c236f
SW
804 case 0x10: /* TBCR */
805 retval = opp->timers[idx].tbcr;
060fbfe1 806 break;
a09f7443 807 case 0x20: /* TVPR */
be7c236f 808 retval = read_IRQreg_ivpr(opp, opp->irq_tim0 + idx);
060fbfe1 809 break;
a09f7443 810 case 0x30: /* TDR */
be7c236f 811 retval = read_IRQreg_idr(opp, opp->irq_tim0 + idx);
060fbfe1 812 break;
dbda808a 813 }
c38c0b8a
AG
814
815out:
df592270 816 DPRINTF("%s: => 0x%08x", __func__, retval);
dbda808a
FB
817
818 return retval;
819}
820
b9b2aaa3
AG
821static void openpic_src_write(void *opaque, hwaddr addr, uint64_t val,
822 unsigned len)
dbda808a 823{
6d544ee8 824 OpenPICState *opp = opaque;
dbda808a
FB
825 int idx;
826
df592270 827 DPRINTF("%s: addr %#" HWADDR_PRIx " <= %08" PRIx64,
4c4f0e48 828 __func__, addr, val);
e0dfe5b1
SW
829
830 addr = addr & 0xffff;
dbda808a 831 idx = addr >> 5;
e0dfe5b1
SW
832
833 switch (addr & 0x1f) {
834 case 0x00:
be7c236f 835 write_IRQreg_ivpr(opp, idx, val);
e0dfe5b1
SW
836 break;
837 case 0x10:
838 write_IRQreg_idr(opp, idx, val);
839 break;
840 case 0x18:
841 write_IRQreg_ilr(opp, idx, val);
842 break;
dbda808a
FB
843 }
844}
845
b9b2aaa3 846static uint64_t openpic_src_read(void *opaque, uint64_t addr, unsigned len)
dbda808a 847{
6d544ee8 848 OpenPICState *opp = opaque;
dbda808a
FB
849 uint32_t retval;
850 int idx;
851
df592270 852 DPRINTF("%s: addr %#" HWADDR_PRIx, __func__, addr);
dbda808a 853 retval = 0xFFFFFFFF;
e0dfe5b1
SW
854
855 addr = addr & 0xffff;
dbda808a 856 idx = addr >> 5;
e0dfe5b1
SW
857
858 switch (addr & 0x1f) {
859 case 0x00:
be7c236f 860 retval = read_IRQreg_ivpr(opp, idx);
e0dfe5b1
SW
861 break;
862 case 0x10:
863 retval = read_IRQreg_idr(opp, idx);
864 break;
865 case 0x18:
866 retval = read_IRQreg_ilr(opp, idx);
867 break;
dbda808a 868 }
dbda808a 869
df592270 870 DPRINTF("%s: => 0x%08x", __func__, retval);
dbda808a
FB
871 return retval;
872}
873
732aa6ec
AG
874static void openpic_msi_write(void *opaque, hwaddr addr, uint64_t val,
875 unsigned size)
876{
877 OpenPICState *opp = opaque;
878 int idx = opp->irq_msi;
879 int srs, ibs;
880
df592270 881 DPRINTF("%s: addr %#" HWADDR_PRIx " <= 0x%08" PRIx64,
4c4f0e48 882 __func__, addr, val);
732aa6ec
AG
883 if (addr & 0xF) {
884 return;
885 }
886
887 switch (addr) {
888 case MSIIR_OFFSET:
889 srs = val >> MSIIR_SRS_SHIFT;
890 idx += srs;
891 ibs = (val & MSIIR_IBS_MASK) >> MSIIR_IBS_SHIFT;
892 opp->msi[srs].msir |= 1 << ibs;
893 openpic_set_irq(opp, idx, 1);
894 break;
895 default:
896 /* most registers are read-only, thus ignored */
897 break;
898 }
899}
900
901static uint64_t openpic_msi_read(void *opaque, hwaddr addr, unsigned size)
902{
903 OpenPICState *opp = opaque;
904 uint64_t r = 0;
905 int i, srs;
906
df592270 907 DPRINTF("%s: addr %#" HWADDR_PRIx, __func__, addr);
732aa6ec
AG
908 if (addr & 0xF) {
909 return -1;
910 }
911
912 srs = addr >> 4;
913
914 switch (addr) {
915 case 0x00:
916 case 0x10:
917 case 0x20:
918 case 0x30:
919 case 0x40:
920 case 0x50:
921 case 0x60:
922 case 0x70: /* MSIRs */
923 r = opp->msi[srs].msir;
924 /* Clear on read */
925 opp->msi[srs].msir = 0;
e99fd8af 926 openpic_set_irq(opp, opp->irq_msi + srs, 0);
732aa6ec
AG
927 break;
928 case 0x120: /* MSISR */
929 for (i = 0; i < MAX_MSI; i++) {
930 r |= (opp->msi[i].msir ? 1 : 0) << i;
931 }
932 break;
933 }
934
935 return r;
936}
937
e0dfe5b1
SW
938static uint64_t openpic_summary_read(void *opaque, hwaddr addr, unsigned size)
939{
940 uint64_t r = 0;
941
df592270 942 DPRINTF("%s: addr %#" HWADDR_PRIx, __func__, addr);
e0dfe5b1
SW
943
944 /* TODO: EISR/EIMR */
945
946 return r;
947}
948
949static void openpic_summary_write(void *opaque, hwaddr addr, uint64_t val,
950 unsigned size)
951{
df592270 952 DPRINTF("%s: addr %#" HWADDR_PRIx " <= 0x%08" PRIx64,
e0dfe5b1
SW
953 __func__, addr, val);
954
955 /* TODO: EISR/EIMR */
956}
957
a8170e5e 958static void openpic_cpu_write_internal(void *opaque, hwaddr addr,
704c7e5d 959 uint32_t val, int idx)
dbda808a 960{
6d544ee8 961 OpenPICState *opp = opaque;
af7e9e74
AG
962 IRQSource *src;
963 IRQDest *dst;
704c7e5d 964 int s_IRQ, n_IRQ;
dbda808a 965
df592270 966 DPRINTF("%s: cpu %d addr %#" HWADDR_PRIx " <= 0x%08x", __func__, idx,
704c7e5d 967 addr, val);
c3203fa5 968
04d2acbb 969 if (idx < 0 || idx >= opp->nb_cpus) {
dbda808a 970 return;
c3203fa5
SW
971 }
972
af7e9e74 973 if (addr & 0xF) {
dbda808a 974 return;
af7e9e74 975 }
dbda808a
FB
976 dst = &opp->dst[idx];
977 addr &= 0xFF0;
978 switch (addr) {
704c7e5d 979 case 0x40: /* IPIDR */
dbda808a
FB
980 case 0x50:
981 case 0x60:
982 case 0x70:
983 idx = (addr - 0x40) >> 4;
a675155e 984 /* we use IDE as mask which CPUs to deliver the IPI to still. */
f40c360c 985 opp->src[opp->irq_ipi0 + idx].destmask |= val;
b7169916
AJ
986 openpic_set_irq(opp, opp->irq_ipi0 + idx, 1);
987 openpic_set_irq(opp, opp->irq_ipi0 + idx, 0);
dbda808a 988 break;
be7c236f
SW
989 case 0x80: /* CTPR */
990 dst->ctpr = val & 0x0000000F;
9f1d4b1d 991
df592270 992 DPRINTF("%s: set CPU %d ctpr to %d, raised %d servicing %d",
9f1d4b1d
SW
993 __func__, idx, dst->ctpr, dst->raised.priority,
994 dst->servicing.priority);
995
996 if (dst->raised.priority <= dst->ctpr) {
df592270 997 DPRINTF("%s: Lower OpenPIC INT output cpu %d due to ctpr",
9f1d4b1d
SW
998 __func__, idx);
999 qemu_irq_lower(dst->irqs[OPENPIC_OUTPUT_INT]);
1000 } else if (dst->raised.priority > dst->servicing.priority) {
df592270 1001 DPRINTF("%s: Raise OpenPIC INT output cpu %d irq %d",
9f1d4b1d
SW
1002 __func__, idx, dst->raised.next);
1003 qemu_irq_raise(dst->irqs[OPENPIC_OUTPUT_INT]);
1004 }
1005
060fbfe1 1006 break;
dbda808a 1007 case 0x90: /* WHOAMI */
060fbfe1
AJ
1008 /* Read-only register */
1009 break;
be7c236f 1010 case 0xA0: /* IACK */
060fbfe1
AJ
1011 /* Read-only register */
1012 break;
be7c236f 1013 case 0xB0: /* EOI */
df592270 1014 DPRINTF("EOI");
060fbfe1 1015 s_IRQ = IRQ_get_next(opp, &dst->servicing);
65b9d0d5
SW
1016
1017 if (s_IRQ < 0) {
df592270 1018 DPRINTF("%s: EOI with no interrupt in service", __func__);
65b9d0d5
SW
1019 break;
1020 }
1021
060fbfe1 1022 IRQ_resetbit(&dst->servicing, s_IRQ);
060fbfe1
AJ
1023 /* Set up next servicing IRQ */
1024 s_IRQ = IRQ_get_next(opp, &dst->servicing);
e9df014c
JM
1025 /* Check queued interrupts. */
1026 n_IRQ = IRQ_get_next(opp, &dst->raised);
1027 src = &opp->src[n_IRQ];
1028 if (n_IRQ != -1 &&
1029 (s_IRQ == -1 ||
be7c236f 1030 IVPR_PRIORITY(src->ivpr) > dst->servicing.priority)) {
df592270 1031 DPRINTF("Raise OpenPIC INT output cpu %d irq %d",
e9df014c 1032 idx, n_IRQ);
5e22c276 1033 qemu_irq_raise(opp->dst[idx].irqs[OPENPIC_OUTPUT_INT]);
e9df014c 1034 }
060fbfe1 1035 break;
dbda808a
FB
1036 default:
1037 break;
1038 }
1039}
1040
b9b2aaa3
AG
1041static void openpic_cpu_write(void *opaque, hwaddr addr, uint64_t val,
1042 unsigned len)
704c7e5d
AG
1043{
1044 openpic_cpu_write_internal(opaque, addr, val, (addr & 0x1f000) >> 12);
1045}
1046
a898a8fc
SW
1047
1048static uint32_t openpic_iack(OpenPICState *opp, IRQDest *dst, int cpu)
1049{
1050 IRQSource *src;
1051 int retval, irq;
1052
df592270 1053 DPRINTF("Lower OpenPIC INT output");
a898a8fc
SW
1054 qemu_irq_lower(dst->irqs[OPENPIC_OUTPUT_INT]);
1055
1056 irq = IRQ_get_next(opp, &dst->raised);
df592270 1057 DPRINTF("IACK: irq=%d", irq);
a898a8fc
SW
1058
1059 if (irq == -1) {
1060 /* No more interrupt pending */
1061 return opp->spve;
1062 }
1063
1064 src = &opp->src[irq];
1065 if (!(src->ivpr & IVPR_ACTIVITY_MASK) ||
1066 !(IVPR_PRIORITY(src->ivpr) > dst->ctpr)) {
df592270 1067 error_report("%s: bad raised IRQ %d ctpr %d ivpr 0x%08x",
9f1d4b1d
SW
1068 __func__, irq, dst->ctpr, src->ivpr);
1069 openpic_update_irq(opp, irq);
a898a8fc
SW
1070 retval = opp->spve;
1071 } else {
1072 /* IRQ enter servicing state */
1073 IRQ_setbit(&dst->servicing, irq);
1074 retval = IVPR_VECTOR(opp, src->ivpr);
1075 }
9f1d4b1d 1076
a898a8fc
SW
1077 if (!src->level) {
1078 /* edge-sensitive IRQ */
1079 src->ivpr &= ~IVPR_ACTIVITY_MASK;
1080 src->pending = 0;
9f1d4b1d 1081 IRQ_resetbit(&dst->raised, irq);
a898a8fc
SW
1082 }
1083
ddd5140b
AL
1084 /* Timers and IPIs support multicast. */
1085 if (((irq >= opp->irq_ipi0) && (irq < (opp->irq_ipi0 + OPENPIC_MAX_IPI))) ||
1086 ((irq >= opp->irq_tim0) && (irq < (opp->irq_tim0 + OPENPIC_MAX_TMR)))) {
df592270 1087 DPRINTF("irq is IPI or TMR");
f40c360c
SW
1088 src->destmask &= ~(1 << cpu);
1089 if (src->destmask && !src->level) {
a898a8fc
SW
1090 /* trigger on CPUs that didn't know about it yet */
1091 openpic_set_irq(opp, irq, 1);
1092 openpic_set_irq(opp, irq, 0);
1093 /* if all CPUs knew about it, set active bit again */
1094 src->ivpr |= IVPR_ACTIVITY_MASK;
1095 }
1096 }
1097
1098 return retval;
1099}
1100
a8170e5e 1101static uint32_t openpic_cpu_read_internal(void *opaque, hwaddr addr,
704c7e5d 1102 int idx)
dbda808a 1103{
6d544ee8 1104 OpenPICState *opp = opaque;
af7e9e74 1105 IRQDest *dst;
dbda808a 1106 uint32_t retval;
3b46e624 1107
df592270 1108 DPRINTF("%s: cpu %d addr %#" HWADDR_PRIx, __func__, idx, addr);
dbda808a 1109 retval = 0xFFFFFFFF;
c3203fa5 1110
04d2acbb 1111 if (idx < 0 || idx >= opp->nb_cpus) {
c3203fa5
SW
1112 return retval;
1113 }
1114
af7e9e74 1115 if (addr & 0xF) {
dbda808a 1116 return retval;
af7e9e74 1117 }
dbda808a
FB
1118 dst = &opp->dst[idx];
1119 addr &= 0xFF0;
1120 switch (addr) {
be7c236f
SW
1121 case 0x80: /* CTPR */
1122 retval = dst->ctpr;
060fbfe1 1123 break;
dbda808a 1124 case 0x90: /* WHOAMI */
060fbfe1
AJ
1125 retval = idx;
1126 break;
be7c236f 1127 case 0xA0: /* IACK */
a898a8fc 1128 retval = openpic_iack(opp, dst, idx);
060fbfe1 1129 break;
be7c236f 1130 case 0xB0: /* EOI */
060fbfe1
AJ
1131 retval = 0;
1132 break;
dbda808a
FB
1133 default:
1134 break;
1135 }
df592270 1136 DPRINTF("%s: => 0x%08x", __func__, retval);
dbda808a
FB
1137
1138 return retval;
1139}
1140
b9b2aaa3 1141static uint64_t openpic_cpu_read(void *opaque, hwaddr addr, unsigned len)
704c7e5d
AG
1142{
1143 return openpic_cpu_read_internal(opaque, addr, (addr & 0x1f000) >> 12);
1144}
1145
35732cb4 1146static const MemoryRegionOps openpic_glb_ops_le = {
780d16b7
AG
1147 .write = openpic_gbl_write,
1148 .read = openpic_gbl_read,
1149 .endianness = DEVICE_LITTLE_ENDIAN,
1150 .impl = {
1151 .min_access_size = 4,
1152 .max_access_size = 4,
1153 },
1154};
dbda808a 1155
35732cb4
AG
1156static const MemoryRegionOps openpic_glb_ops_be = {
1157 .write = openpic_gbl_write,
1158 .read = openpic_gbl_read,
1159 .endianness = DEVICE_BIG_ENDIAN,
1160 .impl = {
1161 .min_access_size = 4,
1162 .max_access_size = 4,
1163 },
1164};
1165
1166static const MemoryRegionOps openpic_tmr_ops_le = {
6d544ee8
AG
1167 .write = openpic_tmr_write,
1168 .read = openpic_tmr_read,
780d16b7
AG
1169 .endianness = DEVICE_LITTLE_ENDIAN,
1170 .impl = {
1171 .min_access_size = 4,
1172 .max_access_size = 4,
1173 },
1174};
dbda808a 1175
35732cb4 1176static const MemoryRegionOps openpic_tmr_ops_be = {
6d544ee8
AG
1177 .write = openpic_tmr_write,
1178 .read = openpic_tmr_read,
35732cb4
AG
1179 .endianness = DEVICE_BIG_ENDIAN,
1180 .impl = {
1181 .min_access_size = 4,
1182 .max_access_size = 4,
1183 },
1184};
1185
1186static const MemoryRegionOps openpic_cpu_ops_le = {
780d16b7
AG
1187 .write = openpic_cpu_write,
1188 .read = openpic_cpu_read,
1189 .endianness = DEVICE_LITTLE_ENDIAN,
1190 .impl = {
1191 .min_access_size = 4,
1192 .max_access_size = 4,
1193 },
1194};
dbda808a 1195
35732cb4
AG
1196static const MemoryRegionOps openpic_cpu_ops_be = {
1197 .write = openpic_cpu_write,
1198 .read = openpic_cpu_read,
1199 .endianness = DEVICE_BIG_ENDIAN,
1200 .impl = {
1201 .min_access_size = 4,
1202 .max_access_size = 4,
1203 },
1204};
1205
1206static const MemoryRegionOps openpic_src_ops_le = {
780d16b7
AG
1207 .write = openpic_src_write,
1208 .read = openpic_src_read,
23c5e4ca 1209 .endianness = DEVICE_LITTLE_ENDIAN,
b9b2aaa3
AG
1210 .impl = {
1211 .min_access_size = 4,
1212 .max_access_size = 4,
1213 },
23c5e4ca
AK
1214};
1215
35732cb4
AG
1216static const MemoryRegionOps openpic_src_ops_be = {
1217 .write = openpic_src_write,
1218 .read = openpic_src_read,
1219 .endianness = DEVICE_BIG_ENDIAN,
1220 .impl = {
1221 .min_access_size = 4,
1222 .max_access_size = 4,
1223 },
1224};
1225
e0dfe5b1 1226static const MemoryRegionOps openpic_msi_ops_be = {
732aa6ec
AG
1227 .read = openpic_msi_read,
1228 .write = openpic_msi_write,
e0dfe5b1 1229 .endianness = DEVICE_BIG_ENDIAN,
732aa6ec
AG
1230 .impl = {
1231 .min_access_size = 4,
1232 .max_access_size = 4,
1233 },
1234};
1235
e0dfe5b1
SW
1236static const MemoryRegionOps openpic_summary_ops_be = {
1237 .read = openpic_summary_read,
1238 .write = openpic_summary_write,
732aa6ec
AG
1239 .endianness = DEVICE_BIG_ENDIAN,
1240 .impl = {
1241 .min_access_size = 4,
1242 .max_access_size = 4,
1243 },
1244};
1245
8ebe65f3
PJ
1246static void openpic_reset(DeviceState *d)
1247{
1248 OpenPICState *opp = OPENPIC(d);
1249 int i;
1250
1251 opp->gcr = GCR_RESET;
1252 /* Initialise controller registers */
1253 opp->frr = ((opp->nb_irqs - 1) << FRR_NIRQ_SHIFT) |
1254 ((opp->nb_cpus - 1) << FRR_NCPU_SHIFT) |
1255 (opp->vid << FRR_VID_SHIFT);
1256
1257 opp->pir = 0;
1258 opp->spve = -1 & opp->vector_mask;
1259 opp->tfrr = opp->tfrr_reset;
1260 /* Initialise IRQ sources */
1261 for (i = 0; i < opp->max_irq; i++) {
1262 opp->src[i].ivpr = opp->ivpr_reset;
8ebe65f3
PJ
1263 switch (opp->src[i].type) {
1264 case IRQ_TYPE_NORMAL:
1265 opp->src[i].level = !!(opp->ivpr_reset & IVPR_SENSE_MASK);
1266 break;
1267
1268 case IRQ_TYPE_FSLINT:
1269 opp->src[i].ivpr |= IVPR_POLARITY_MASK;
1270 break;
1271
1272 case IRQ_TYPE_FSLSPECIAL:
1273 break;
1274 }
ffd5e9fe
PJ
1275
1276 write_IRQreg_idr(opp, i, opp->idr_reset);
8ebe65f3
PJ
1277 }
1278 /* Initialise IRQ destinations */
2ada66f9 1279 for (i = 0; i < opp->nb_cpus; i++) {
8ebe65f3 1280 opp->dst[i].ctpr = 15;
8ebe65f3 1281 opp->dst[i].raised.next = -1;
2ada66f9
MCA
1282 opp->dst[i].raised.priority = 0;
1283 bitmap_clear(opp->dst[i].raised.queue, 0, IRQQUEUE_SIZE_BITS);
8ebe65f3 1284 opp->dst[i].servicing.next = -1;
2ada66f9
MCA
1285 opp->dst[i].servicing.priority = 0;
1286 bitmap_clear(opp->dst[i].servicing.queue, 0, IRQQUEUE_SIZE_BITS);
8ebe65f3
PJ
1287 }
1288 /* Initialise timers */
1289 for (i = 0; i < OPENPIC_MAX_TMR; i++) {
1290 opp->timers[i].tccr = 0;
1291 opp->timers[i].tbcr = TBCR_CI;
ddd5140b
AL
1292 if (opp->timers[i].qemu_timer_active) {
1293 timer_del(opp->timers[i].qemu_timer); /* Inhibit timer */
1294 opp->timers[i].qemu_timer_active = false;
1295 }
8ebe65f3
PJ
1296 }
1297 /* Go out of RESET state */
1298 opp->gcr = 0;
1299}
1300
af7e9e74 1301typedef struct MemReg {
d0b72631
AG
1302 const char *name;
1303 MemoryRegionOps const *ops;
1304 hwaddr start_addr;
1305 ram_addr_t size;
af7e9e74 1306} MemReg;
d0b72631 1307
e0dfe5b1
SW
1308static void fsl_common_init(OpenPICState *opp)
1309{
1310 int i;
8935a442 1311 int virq = OPENPIC_MAX_SRC;
e0dfe5b1
SW
1312
1313 opp->vid = VID_REVISION_1_2;
1314 opp->vir = VIR_GENERIC;
1315 opp->vector_mask = 0xFFFF;
1316 opp->tfrr_reset = 0;
1317 opp->ivpr_reset = IVPR_MASK_MASK;
1318 opp->idr_reset = 1 << 0;
8935a442 1319 opp->max_irq = OPENPIC_MAX_IRQ;
e0dfe5b1
SW
1320
1321 opp->irq_ipi0 = virq;
8935a442 1322 virq += OPENPIC_MAX_IPI;
e0dfe5b1 1323 opp->irq_tim0 = virq;
8935a442 1324 virq += OPENPIC_MAX_TMR;
e0dfe5b1 1325
8935a442 1326 assert(virq <= OPENPIC_MAX_IRQ);
e0dfe5b1
SW
1327
1328 opp->irq_msi = 224;
1329
226419d6 1330 msi_nonbroken = true;
e0dfe5b1
SW
1331 for (i = 0; i < opp->fsl->max_ext; i++) {
1332 opp->src[i].level = false;
1333 }
1334
1335 /* Internal interrupts, including message and MSI */
8935a442 1336 for (i = 16; i < OPENPIC_MAX_SRC; i++) {
e0dfe5b1
SW
1337 opp->src[i].type = IRQ_TYPE_FSLINT;
1338 opp->src[i].level = true;
1339 }
1340
1341 /* timers and IPIs */
8935a442 1342 for (i = OPENPIC_MAX_SRC; i < virq; i++) {
e0dfe5b1
SW
1343 opp->src[i].type = IRQ_TYPE_FSLSPECIAL;
1344 opp->src[i].level = false;
1345 }
ddd5140b
AL
1346
1347 for (i = 0; i < OPENPIC_MAX_TMR; i++) {
1348 opp->timers[i].n_IRQ = opp->irq_tim0 + i;
1349 opp->timers[i].qemu_timer_active = false;
1350 opp->timers[i].qemu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
1351 &qemu_timer_cb,
1352 &opp->timers[i]);
1353 opp->timers[i].opp = opp;
1354 }
e0dfe5b1
SW
1355}
1356
1357static void map_list(OpenPICState *opp, const MemReg *list, int *count)
1358{
1359 while (list->name) {
1360 assert(*count < ARRAY_SIZE(opp->sub_io_mem));
1361
1437c94b
PB
1362 memory_region_init_io(&opp->sub_io_mem[*count], OBJECT(opp), list->ops,
1363 opp, list->name, list->size);
e0dfe5b1
SW
1364
1365 memory_region_add_subregion(&opp->mem, list->start_addr,
1366 &opp->sub_io_mem[*count]);
1367
1368 (*count)++;
1369 list++;
1370 }
1371}
1372
e5f6e732
MCA
1373static const VMStateDescription vmstate_openpic_irq_queue = {
1374 .name = "openpic_irq_queue",
1375 .version_id = 0,
1376 .minimum_version_id = 0,
1377 .fields = (VMStateField[]) {
1378 VMSTATE_BITMAP(queue, IRQQueue, 0, queue_size),
1379 VMSTATE_INT32(next, IRQQueue),
1380 VMSTATE_INT32(priority, IRQQueue),
1381 VMSTATE_END_OF_LIST()
1382 }
1383};
1384
1385static const VMStateDescription vmstate_openpic_irqdest = {
1386 .name = "openpic_irqdest",
1387 .version_id = 0,
1388 .minimum_version_id = 0,
1389 .fields = (VMStateField[]) {
1390 VMSTATE_INT32(ctpr, IRQDest),
1391 VMSTATE_STRUCT(raised, IRQDest, 0, vmstate_openpic_irq_queue,
1392 IRQQueue),
1393 VMSTATE_STRUCT(servicing, IRQDest, 0, vmstate_openpic_irq_queue,
1394 IRQQueue),
1395 VMSTATE_UINT32_ARRAY(outputs_active, IRQDest, OPENPIC_OUTPUT_NB),
1396 VMSTATE_END_OF_LIST()
1397 }
1398};
1399
1400static const VMStateDescription vmstate_openpic_irqsource = {
1401 .name = "openpic_irqsource",
1402 .version_id = 0,
1403 .minimum_version_id = 0,
1404 .fields = (VMStateField[]) {
1405 VMSTATE_UINT32(ivpr, IRQSource),
1406 VMSTATE_UINT32(idr, IRQSource),
1407 VMSTATE_UINT32(destmask, IRQSource),
1408 VMSTATE_INT32(last_cpu, IRQSource),
1409 VMSTATE_INT32(pending, IRQSource),
1410 VMSTATE_END_OF_LIST()
1411 }
1412};
1413
1414static const VMStateDescription vmstate_openpic_timer = {
1415 .name = "openpic_timer",
1416 .version_id = 0,
1417 .minimum_version_id = 0,
1418 .fields = (VMStateField[]) {
1419 VMSTATE_UINT32(tccr, OpenPICTimer),
1420 VMSTATE_UINT32(tbcr, OpenPICTimer),
1421 VMSTATE_END_OF_LIST()
1422 }
1423};
1424
1425static const VMStateDescription vmstate_openpic_msi = {
1426 .name = "openpic_msi",
1427 .version_id = 0,
1428 .minimum_version_id = 0,
1429 .fields = (VMStateField[]) {
1430 VMSTATE_UINT32(msir, OpenPICMSI),
1431 VMSTATE_END_OF_LIST()
1432 }
1433};
1434
1435static int openpic_post_load(void *opaque, int version_id)
1436{
1437 OpenPICState *opp = (OpenPICState *)opaque;
1438 int i;
1439
1440 /* Update internal ivpr and idr variables */
1441 for (i = 0; i < opp->max_irq; i++) {
1442 write_IRQreg_idr(opp, i, opp->src[i].idr);
1443 write_IRQreg_ivpr(opp, i, opp->src[i].ivpr);
1444 }
1445
1446 return 0;
1447}
1448
1449static const VMStateDescription vmstate_openpic = {
1450 .name = "openpic",
1451 .version_id = 3,
1452 .minimum_version_id = 3,
1453 .post_load = openpic_post_load,
1454 .fields = (VMStateField[]) {
1455 VMSTATE_UINT32(gcr, OpenPICState),
1456 VMSTATE_UINT32(vir, OpenPICState),
1457 VMSTATE_UINT32(pir, OpenPICState),
1458 VMSTATE_UINT32(spve, OpenPICState),
1459 VMSTATE_UINT32(tfrr, OpenPICState),
1460 VMSTATE_UINT32(max_irq, OpenPICState),
1461 VMSTATE_STRUCT_VARRAY_UINT32(src, OpenPICState, max_irq, 0,
1462 vmstate_openpic_irqsource, IRQSource),
d2164ad3 1463 VMSTATE_UINT32_EQUAL(nb_cpus, OpenPICState, NULL),
e5f6e732
MCA
1464 VMSTATE_STRUCT_VARRAY_UINT32(dst, OpenPICState, nb_cpus, 0,
1465 vmstate_openpic_irqdest, IRQDest),
1466 VMSTATE_STRUCT_ARRAY(timers, OpenPICState, OPENPIC_MAX_TMR, 0,
1467 vmstate_openpic_timer, OpenPICTimer),
1468 VMSTATE_STRUCT_ARRAY(msi, OpenPICState, MAX_MSI, 0,
1469 vmstate_openpic_msi, OpenPICMSI),
1470 VMSTATE_UINT32(irq_ipi0, OpenPICState),
1471 VMSTATE_UINT32(irq_tim0, OpenPICState),
1472 VMSTATE_UINT32(irq_msi, OpenPICState),
1473 VMSTATE_END_OF_LIST()
1474 }
1475};
1476
cbe72019 1477static void openpic_init(Object *obj)
dbda808a 1478{
cbe72019
AF
1479 OpenPICState *opp = OPENPIC(obj);
1480
1437c94b 1481 memory_region_init(&opp->mem, obj, "openpic", 0x40000);
cbe72019
AF
1482}
1483
1484static void openpic_realize(DeviceState *dev, Error **errp)
1485{
1486 SysBusDevice *d = SYS_BUS_DEVICE(dev);
e1766344 1487 OpenPICState *opp = OPENPIC(dev);
d0b72631 1488 int i, j;
e0dfe5b1
SW
1489 int list_count = 0;
1490 static const MemReg list_le[] = {
1491 {"glb", &openpic_glb_ops_le,
732aa6ec 1492 OPENPIC_GLB_REG_START, OPENPIC_GLB_REG_SIZE},
e0dfe5b1 1493 {"tmr", &openpic_tmr_ops_le,
732aa6ec 1494 OPENPIC_TMR_REG_START, OPENPIC_TMR_REG_SIZE},
e0dfe5b1 1495 {"src", &openpic_src_ops_le,
732aa6ec 1496 OPENPIC_SRC_REG_START, OPENPIC_SRC_REG_SIZE},
e0dfe5b1 1497 {"cpu", &openpic_cpu_ops_le,
732aa6ec 1498 OPENPIC_CPU_REG_START, OPENPIC_CPU_REG_SIZE},
e0dfe5b1 1499 {NULL}
780d16b7 1500 };
e0dfe5b1
SW
1501 static const MemReg list_be[] = {
1502 {"glb", &openpic_glb_ops_be,
732aa6ec 1503 OPENPIC_GLB_REG_START, OPENPIC_GLB_REG_SIZE},
e0dfe5b1 1504 {"tmr", &openpic_tmr_ops_be,
732aa6ec 1505 OPENPIC_TMR_REG_START, OPENPIC_TMR_REG_SIZE},
e0dfe5b1 1506 {"src", &openpic_src_ops_be,
732aa6ec 1507 OPENPIC_SRC_REG_START, OPENPIC_SRC_REG_SIZE},
e0dfe5b1 1508 {"cpu", &openpic_cpu_ops_be,
732aa6ec 1509 OPENPIC_CPU_REG_START, OPENPIC_CPU_REG_SIZE},
e0dfe5b1 1510 {NULL}
d0b72631 1511 };
e0dfe5b1
SW
1512 static const MemReg list_fsl[] = {
1513 {"msi", &openpic_msi_ops_be,
1514 OPENPIC_MSI_REG_START, OPENPIC_MSI_REG_SIZE},
1515 {"summary", &openpic_summary_ops_be,
1516 OPENPIC_SUMMARY_REG_START, OPENPIC_SUMMARY_REG_SIZE},
1517 {NULL}
1518 };
1519
73d963c0 1520 if (opp->nb_cpus > MAX_CPU) {
c6bd8c70
MA
1521 error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
1522 TYPE_OPENPIC, "nb_cpus", (uint64_t)opp->nb_cpus,
1523 (uint64_t)0, (uint64_t)MAX_CPU);
73d963c0
MR
1524 return;
1525 }
1526
d0b72631
AG
1527 switch (opp->model) {
1528 case OPENPIC_MODEL_FSL_MPIC_20:
1529 default:
e0dfe5b1
SW
1530 opp->fsl = &fsl_mpic_20;
1531 opp->brr1 = 0x00400200;
be7c236f 1532 opp->flags |= OPENPIC_FLAG_IDR_CRIT;
d0b72631 1533 opp->nb_irqs = 80;
e0dfe5b1 1534 opp->mpic_mode_mask = GCR_MODE_MIXED;
68c2dd70 1535
e0dfe5b1
SW
1536 fsl_common_init(opp);
1537 map_list(opp, list_be, &list_count);
1538 map_list(opp, list_fsl, &list_count);
6c5e84c2 1539
e0dfe5b1 1540 break;
6c5e84c2 1541
e0dfe5b1
SW
1542 case OPENPIC_MODEL_FSL_MPIC_42:
1543 opp->fsl = &fsl_mpic_42;
1544 opp->brr1 = 0x00400402;
1545 opp->flags |= OPENPIC_FLAG_ILR;
1546 opp->nb_irqs = 196;
1547 opp->mpic_mode_mask = GCR_MODE_PROXY;
6c5e84c2 1548
e0dfe5b1
SW
1549 fsl_common_init(opp);
1550 map_list(opp, list_be, &list_count);
1551 map_list(opp, list_fsl, &list_count);
6c5e84c2 1552
d0b72631 1553 break;
6c5e84c2 1554
d0b72631
AG
1555 case OPENPIC_MODEL_RAVEN:
1556 opp->nb_irqs = RAVEN_MAX_EXT;
1557 opp->vid = VID_REVISION_1_3;
be7c236f 1558 opp->vir = VIR_GENERIC;
0fe04622 1559 opp->vector_mask = 0xFF;
be7c236f
SW
1560 opp->tfrr_reset = 4160000;
1561 opp->ivpr_reset = IVPR_MASK_MASK | IVPR_MODE_MASK;
1562 opp->idr_reset = 0;
d0b72631
AG
1563 opp->max_irq = RAVEN_MAX_IRQ;
1564 opp->irq_ipi0 = RAVEN_IPI_IRQ;
1565 opp->irq_tim0 = RAVEN_TMR_IRQ;
dbbbfd60 1566 opp->brr1 = -1;
86e56a88 1567 opp->mpic_mode_mask = GCR_MODE_MIXED;
d0b72631 1568
d0b72631 1569 if (opp->nb_cpus != 1) {
cbe72019
AF
1570 error_setg(errp, "Only UP supported today");
1571 return;
d0b72631 1572 }
780d16b7 1573
58b62835
BH
1574 map_list(opp, list_le, &list_count);
1575 break;
1576
1577 case OPENPIC_MODEL_KEYLARGO:
1578 opp->nb_irqs = KEYLARGO_MAX_EXT;
1579 opp->vid = VID_REVISION_1_2;
1580 opp->vir = VIR_GENERIC;
1581 opp->vector_mask = 0xFF;
1582 opp->tfrr_reset = 4160000;
1583 opp->ivpr_reset = IVPR_MASK_MASK | IVPR_MODE_MASK;
1584 opp->idr_reset = 0;
1585 opp->max_irq = KEYLARGO_MAX_IRQ;
1586 opp->irq_ipi0 = KEYLARGO_IPI_IRQ;
1587 opp->irq_tim0 = KEYLARGO_TMR_IRQ;
1588 opp->brr1 = -1;
1589 opp->mpic_mode_mask = GCR_MODE_MIXED;
1590
1591 if (opp->nb_cpus != 1) {
1592 error_setg(errp, "Only UP supported today");
1593 return;
1594 }
1595
e0dfe5b1
SW
1596 map_list(opp, list_le, &list_count);
1597 break;
780d16b7 1598 }
3b46e624 1599
d0b72631 1600 for (i = 0; i < opp->nb_cpus; i++) {
aa2ac1da 1601 opp->dst[i].irqs = g_new0(qemu_irq, OPENPIC_OUTPUT_NB);
d0b72631 1602 for (j = 0; j < OPENPIC_OUTPUT_NB; j++) {
cbe72019 1603 sysbus_init_irq(d, &opp->dst[i].irqs[j]);
d0b72631 1604 }
2ada66f9 1605
e5f6e732 1606 opp->dst[i].raised.queue_size = IRQQUEUE_SIZE_BITS;
2ada66f9 1607 opp->dst[i].raised.queue = bitmap_new(IRQQUEUE_SIZE_BITS);
e5f6e732 1608 opp->dst[i].servicing.queue_size = IRQQUEUE_SIZE_BITS;
2ada66f9 1609 opp->dst[i].servicing.queue = bitmap_new(IRQQUEUE_SIZE_BITS);
d0b72631
AG
1610 }
1611
cbe72019
AF
1612 sysbus_init_mmio(d, &opp->mem);
1613 qdev_init_gpio_in(dev, openpic_set_irq, opp->max_irq);
b7169916
AJ
1614}
1615
d0b72631
AG
1616static Property openpic_properties[] = {
1617 DEFINE_PROP_UINT32("model", OpenPICState, model, OPENPIC_MODEL_FSL_MPIC_20),
1618 DEFINE_PROP_UINT32("nb_cpus", OpenPICState, nb_cpus, 1),
1619 DEFINE_PROP_END_OF_LIST(),
1620};
71cf9e62 1621
cbe72019 1622static void openpic_class_init(ObjectClass *oc, void *data)
d0b72631 1623{
cbe72019 1624 DeviceClass *dc = DEVICE_CLASS(oc);
b7169916 1625
cbe72019 1626 dc->realize = openpic_realize;
d0b72631
AG
1627 dc->props = openpic_properties;
1628 dc->reset = openpic_reset;
e5f6e732 1629 dc->vmsd = &vmstate_openpic;
29f8dd66 1630 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
d0b72631 1631}
71cf9e62 1632
8c43a6f0 1633static const TypeInfo openpic_info = {
e1766344 1634 .name = TYPE_OPENPIC,
d0b72631
AG
1635 .parent = TYPE_SYS_BUS_DEVICE,
1636 .instance_size = sizeof(OpenPICState),
cbe72019 1637 .instance_init = openpic_init,
d0b72631
AG
1638 .class_init = openpic_class_init,
1639};
b7169916 1640
d0b72631
AG
1641static void openpic_register_types(void)
1642{
1643 type_register_static(&openpic_info);
dbda808a 1644}
d0b72631
AG
1645
1646type_init(openpic_register_types)
This page took 1.149969 seconds and 4 git commands to generate.