4 * Copyright (c) 2004 Jocelyn Mayer
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:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
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
27 * Based on OpenPic implementations:
28 * - Intel GW80314 I/O companion chip developer's manual
29 * - Motorola MPC8245 & MPC8540 user manuals.
30 * - Motorola MCP750 (aka Raven) programmer manual.
31 * - Motorola Harrier programmer manuel
33 * Serial interrupts, as implemented in Raven chipset are not supported yet.
37 #include "hw/ppc/mac.h"
38 #include "hw/pci/pci.h"
39 #include "hw/ppc/openpic.h"
40 #include "hw/sysbus.h"
41 #include "hw/pci/msi.h"
42 #include "qemu/bitops.h"
43 #include "hw/ppc/ppc.h"
45 //#define DEBUG_OPENPIC
48 static const int debug_openpic
= 1;
50 static const int debug_openpic
= 0;
53 #define DPRINTF(fmt, ...) do { \
54 if (debug_openpic) { \
55 printf(fmt , ## __VA_ARGS__); \
61 #define VID 0x03 /* MPIC version ID */
63 /* OpenPIC capability flags */
64 #define OPENPIC_FLAG_IDR_CRIT (1 << 0)
65 #define OPENPIC_FLAG_ILR (2 << 0)
67 /* OpenPIC address map */
68 #define OPENPIC_GLB_REG_START 0x0
69 #define OPENPIC_GLB_REG_SIZE 0x10F0
70 #define OPENPIC_TMR_REG_START 0x10F0
71 #define OPENPIC_TMR_REG_SIZE 0x220
72 #define OPENPIC_MSI_REG_START 0x1600
73 #define OPENPIC_MSI_REG_SIZE 0x200
74 #define OPENPIC_SUMMARY_REG_START 0x3800
75 #define OPENPIC_SUMMARY_REG_SIZE 0x800
76 #define OPENPIC_SRC_REG_START 0x10000
77 #define OPENPIC_SRC_REG_SIZE (OPENPIC_MAX_SRC * 0x20)
78 #define OPENPIC_CPU_REG_START 0x20000
79 #define OPENPIC_CPU_REG_SIZE 0x100 + ((MAX_CPU - 1) * 0x1000)
82 #define RAVEN_MAX_CPU 2
83 #define RAVEN_MAX_EXT 48
84 #define RAVEN_MAX_IRQ 64
85 #define RAVEN_MAX_TMR OPENPIC_MAX_TMR
86 #define RAVEN_MAX_IPI OPENPIC_MAX_IPI
88 /* Interrupt definitions */
89 #define RAVEN_FE_IRQ (RAVEN_MAX_EXT) /* Internal functional IRQ */
90 #define RAVEN_ERR_IRQ (RAVEN_MAX_EXT + 1) /* Error IRQ */
91 #define RAVEN_TMR_IRQ (RAVEN_MAX_EXT + 2) /* First timer IRQ */
92 #define RAVEN_IPI_IRQ (RAVEN_TMR_IRQ + RAVEN_MAX_TMR) /* First IPI IRQ */
93 /* First doorbell IRQ */
94 #define RAVEN_DBL_IRQ (RAVEN_IPI_IRQ + (RAVEN_MAX_CPU * RAVEN_MAX_IPI))
96 typedef struct FslMpicInfo
{
100 static FslMpicInfo fsl_mpic_20
= {
104 static FslMpicInfo fsl_mpic_42
= {
108 #define FRR_NIRQ_SHIFT 16
109 #define FRR_NCPU_SHIFT 8
110 #define FRR_VID_SHIFT 0
112 #define VID_REVISION_1_2 2
113 #define VID_REVISION_1_3 3
115 #define VIR_GENERIC 0x00000000 /* Generic Vendor ID */
117 #define GCR_RESET 0x80000000
118 #define GCR_MODE_PASS 0x00000000
119 #define GCR_MODE_MIXED 0x20000000
120 #define GCR_MODE_PROXY 0x60000000
122 #define TBCR_CI 0x80000000 /* count inhibit */
123 #define TCCR_TOG 0x80000000 /* toggles when decrement to zero */
125 #define IDR_EP_SHIFT 31
126 #define IDR_EP_MASK (1 << IDR_EP_SHIFT)
127 #define IDR_CI0_SHIFT 30
128 #define IDR_CI1_SHIFT 29
129 #define IDR_P1_SHIFT 1
130 #define IDR_P0_SHIFT 0
132 #define ILR_INTTGT_MASK 0x000000ff
133 #define ILR_INTTGT_INT 0x00
134 #define ILR_INTTGT_CINT 0x01 /* critical */
135 #define ILR_INTTGT_MCP 0x02 /* machine check */
137 /* The currently supported INTTGT values happen to be the same as QEMU's
138 * openpic output codes, but don't depend on this. The output codes
139 * could change (unlikely, but...) or support could be added for
140 * more INTTGT values.
142 static const int inttgt_output
[][2] = {
143 { ILR_INTTGT_INT
, OPENPIC_OUTPUT_INT
},
144 { ILR_INTTGT_CINT
, OPENPIC_OUTPUT_CINT
},
145 { ILR_INTTGT_MCP
, OPENPIC_OUTPUT_MCK
},
148 static int inttgt_to_output(int inttgt
)
152 for (i
= 0; i
< ARRAY_SIZE(inttgt_output
); i
++) {
153 if (inttgt_output
[i
][0] == inttgt
) {
154 return inttgt_output
[i
][1];
158 fprintf(stderr
, "%s: unsupported inttgt %d\n", __func__
, inttgt
);
159 return OPENPIC_OUTPUT_INT
;
162 static int output_to_inttgt(int output
)
166 for (i
= 0; i
< ARRAY_SIZE(inttgt_output
); i
++) {
167 if (inttgt_output
[i
][1] == output
) {
168 return inttgt_output
[i
][0];
175 #define MSIIR_OFFSET 0x140
176 #define MSIIR_SRS_SHIFT 29
177 #define MSIIR_SRS_MASK (0x7 << MSIIR_SRS_SHIFT)
178 #define MSIIR_IBS_SHIFT 24
179 #define MSIIR_IBS_MASK (0x1f << MSIIR_IBS_SHIFT)
181 static int get_current_cpu(void)
183 CPUState
*cpu_single_cpu
;
185 if (!cpu_single_env
) {
189 cpu_single_cpu
= ENV_GET_CPU(cpu_single_env
);
190 return cpu_single_cpu
->cpu_index
;
193 static uint32_t openpic_cpu_read_internal(void *opaque
, hwaddr addr
,
195 static void openpic_cpu_write_internal(void *opaque
, hwaddr addr
,
196 uint32_t val
, int idx
);
198 typedef enum IRQType
{
200 IRQ_TYPE_FSLINT
, /* FSL internal interrupt -- level only */
201 IRQ_TYPE_FSLSPECIAL
, /* FSL timer/IPI interrupt, edge, no polarity */
204 typedef struct IRQQueue
{
205 /* Round up to the nearest 64 IRQs so that the queue length
206 * won't change when moving between 32 and 64 bit hosts.
208 unsigned long queue
[BITS_TO_LONGS((OPENPIC_MAX_IRQ
+ 63) & ~63)];
213 typedef struct IRQSource
{
214 uint32_t ivpr
; /* IRQ vector/priority register */
215 uint32_t idr
; /* IRQ destination register */
216 uint32_t destmask
; /* bitmap of CPU destinations */
218 int output
; /* IRQ level, e.g. OPENPIC_OUTPUT_INT */
219 int pending
; /* TRUE if IRQ is pending */
221 bool level
:1; /* level-triggered */
222 bool nomask
:1; /* critical interrupts ignore mask on some FSL MPICs */
225 #define IVPR_MASK_SHIFT 31
226 #define IVPR_MASK_MASK (1 << IVPR_MASK_SHIFT)
227 #define IVPR_ACTIVITY_SHIFT 30
228 #define IVPR_ACTIVITY_MASK (1 << IVPR_ACTIVITY_SHIFT)
229 #define IVPR_MODE_SHIFT 29
230 #define IVPR_MODE_MASK (1 << IVPR_MODE_SHIFT)
231 #define IVPR_POLARITY_SHIFT 23
232 #define IVPR_POLARITY_MASK (1 << IVPR_POLARITY_SHIFT)
233 #define IVPR_SENSE_SHIFT 22
234 #define IVPR_SENSE_MASK (1 << IVPR_SENSE_SHIFT)
236 #define IVPR_PRIORITY_MASK (0xF << 16)
237 #define IVPR_PRIORITY(_ivprr_) ((int)(((_ivprr_) & IVPR_PRIORITY_MASK) >> 16))
238 #define IVPR_VECTOR(opp, _ivprr_) ((_ivprr_) & (opp)->vector_mask)
240 /* IDR[EP/CI] are only for FSL MPIC prior to v4.0 */
241 #define IDR_EP 0x80000000 /* external pin */
242 #define IDR_CI 0x40000000 /* critical interrupt */
244 typedef struct IRQDest
{
245 int32_t ctpr
; /* CPU current task priority */
250 /* Count of IRQ sources asserting on non-INT outputs */
251 uint32_t outputs_active
[OPENPIC_OUTPUT_NB
];
254 #define OPENPIC(obj) OBJECT_CHECK(OpenPICState, (obj), TYPE_OPENPIC)
256 typedef struct OpenPICState
{
258 SysBusDevice parent_obj
;
263 /* Behavior control */
269 uint32_t vir
; /* Vendor identification register */
270 uint32_t vector_mask
;
275 uint32_t mpic_mode_mask
;
278 MemoryRegion sub_io_mem
[6];
280 /* Global registers */
281 uint32_t frr
; /* Feature reporting register */
282 uint32_t gcr
; /* Global configuration register */
283 uint32_t pir
; /* Processor initialization register */
284 uint32_t spve
; /* Spurious vector register */
285 uint32_t tfrr
; /* Timer frequency reporting register */
286 /* Source registers */
287 IRQSource src
[OPENPIC_MAX_IRQ
];
288 /* Local registers per output pin */
289 IRQDest dst
[MAX_CPU
];
291 /* Timer registers */
293 uint32_t tccr
; /* Global timer current count register */
294 uint32_t tbcr
; /* Global timer base count register */
295 } timers
[OPENPIC_MAX_TMR
];
296 /* Shared MSI registers */
298 uint32_t msir
; /* Shared Message Signaled Interrupt Register */
306 static inline void IRQ_setbit(IRQQueue
*q
, int n_IRQ
)
308 set_bit(n_IRQ
, q
->queue
);
311 static inline void IRQ_resetbit(IRQQueue
*q
, int n_IRQ
)
313 clear_bit(n_IRQ
, q
->queue
);
316 static inline int IRQ_testbit(IRQQueue
*q
, int n_IRQ
)
318 return test_bit(n_IRQ
, q
->queue
);
321 static void IRQ_check(OpenPICState
*opp
, IRQQueue
*q
)
328 irq
= find_next_bit(q
->queue
, opp
->max_irq
, irq
+ 1);
329 if (irq
== opp
->max_irq
) {
333 DPRINTF("IRQ_check: irq %d set ivpr_pr=%d pr=%d\n",
334 irq
, IVPR_PRIORITY(opp
->src
[irq
].ivpr
), priority
);
336 if (IVPR_PRIORITY(opp
->src
[irq
].ivpr
) > priority
) {
338 priority
= IVPR_PRIORITY(opp
->src
[irq
].ivpr
);
343 q
->priority
= priority
;
346 static int IRQ_get_next(OpenPICState
*opp
, IRQQueue
*q
)
354 static void IRQ_local_pipe(OpenPICState
*opp
, int n_CPU
, int n_IRQ
,
355 bool active
, bool was_active
)
361 dst
= &opp
->dst
[n_CPU
];
362 src
= &opp
->src
[n_IRQ
];
364 DPRINTF("%s: IRQ %d active %d was %d\n",
365 __func__
, n_IRQ
, active
, was_active
);
367 if (src
->output
!= OPENPIC_OUTPUT_INT
) {
368 DPRINTF("%s: output %d irq %d active %d was %d count %d\n",
369 __func__
, src
->output
, n_IRQ
, active
, was_active
,
370 dst
->outputs_active
[src
->output
]);
372 /* On Freescale MPIC, critical interrupts ignore priority,
373 * IACK, EOI, etc. Before MPIC v4.1 they also ignore
377 if (!was_active
&& dst
->outputs_active
[src
->output
]++ == 0) {
378 DPRINTF("%s: Raise OpenPIC output %d cpu %d irq %d\n",
379 __func__
, src
->output
, n_CPU
, n_IRQ
);
380 qemu_irq_raise(dst
->irqs
[src
->output
]);
383 if (was_active
&& --dst
->outputs_active
[src
->output
] == 0) {
384 DPRINTF("%s: Lower OpenPIC output %d cpu %d irq %d\n",
385 __func__
, src
->output
, n_CPU
, n_IRQ
);
386 qemu_irq_lower(dst
->irqs
[src
->output
]);
393 priority
= IVPR_PRIORITY(src
->ivpr
);
395 /* Even if the interrupt doesn't have enough priority,
396 * it is still raised, in case ctpr is lowered later.
399 IRQ_setbit(&dst
->raised
, n_IRQ
);
401 IRQ_resetbit(&dst
->raised
, n_IRQ
);
404 IRQ_check(opp
, &dst
->raised
);
406 if (active
&& priority
<= dst
->ctpr
) {
407 DPRINTF("%s: IRQ %d priority %d too low for ctpr %d on CPU %d\n",
408 __func__
, n_IRQ
, priority
, dst
->ctpr
, n_CPU
);
413 if (IRQ_get_next(opp
, &dst
->servicing
) >= 0 &&
414 priority
<= dst
->servicing
.priority
) {
415 DPRINTF("%s: IRQ %d is hidden by servicing IRQ %d on CPU %d\n",
416 __func__
, n_IRQ
, dst
->servicing
.next
, n_CPU
);
418 DPRINTF("%s: Raise OpenPIC INT output cpu %d irq %d/%d\n",
419 __func__
, n_CPU
, n_IRQ
, dst
->raised
.next
);
420 qemu_irq_raise(opp
->dst
[n_CPU
].irqs
[OPENPIC_OUTPUT_INT
]);
423 IRQ_get_next(opp
, &dst
->servicing
);
424 if (dst
->raised
.priority
> dst
->ctpr
&&
425 dst
->raised
.priority
> dst
->servicing
.priority
) {
426 DPRINTF("%s: IRQ %d inactive, IRQ %d prio %d above %d/%d, CPU %d\n",
427 __func__
, n_IRQ
, dst
->raised
.next
, dst
->raised
.priority
,
428 dst
->ctpr
, dst
->servicing
.priority
, n_CPU
);
429 /* IRQ line stays asserted */
431 DPRINTF("%s: IRQ %d inactive, current prio %d/%d, CPU %d\n",
432 __func__
, n_IRQ
, dst
->ctpr
, dst
->servicing
.priority
, n_CPU
);
433 qemu_irq_lower(opp
->dst
[n_CPU
].irqs
[OPENPIC_OUTPUT_INT
]);
438 /* update pic state because registers for n_IRQ have changed value */
439 static void openpic_update_irq(OpenPICState
*opp
, int n_IRQ
)
442 bool active
, was_active
;
445 src
= &opp
->src
[n_IRQ
];
446 active
= src
->pending
;
448 if ((src
->ivpr
& IVPR_MASK_MASK
) && !src
->nomask
) {
449 /* Interrupt source is disabled */
450 DPRINTF("%s: IRQ %d is disabled\n", __func__
, n_IRQ
);
454 was_active
= !!(src
->ivpr
& IVPR_ACTIVITY_MASK
);
457 * We don't have a similar check for already-active because
458 * ctpr may have changed and we need to withdraw the interrupt.
460 if (!active
&& !was_active
) {
461 DPRINTF("%s: IRQ %d is already inactive\n", __func__
, n_IRQ
);
466 src
->ivpr
|= IVPR_ACTIVITY_MASK
;
468 src
->ivpr
&= ~IVPR_ACTIVITY_MASK
;
471 if (src
->destmask
== 0) {
473 DPRINTF("%s: IRQ %d has no target\n", __func__
, n_IRQ
);
477 if (src
->destmask
== (1 << src
->last_cpu
)) {
478 /* Only one CPU is allowed to receive this IRQ */
479 IRQ_local_pipe(opp
, src
->last_cpu
, n_IRQ
, active
, was_active
);
480 } else if (!(src
->ivpr
& IVPR_MODE_MASK
)) {
481 /* Directed delivery mode */
482 for (i
= 0; i
< opp
->nb_cpus
; i
++) {
483 if (src
->destmask
& (1 << i
)) {
484 IRQ_local_pipe(opp
, i
, n_IRQ
, active
, was_active
);
488 /* Distributed delivery mode */
489 for (i
= src
->last_cpu
+ 1; i
!= src
->last_cpu
; i
++) {
490 if (i
== opp
->nb_cpus
) {
493 if (src
->destmask
& (1 << i
)) {
494 IRQ_local_pipe(opp
, i
, n_IRQ
, active
, was_active
);
502 static void openpic_set_irq(void *opaque
, int n_IRQ
, int level
)
504 OpenPICState
*opp
= opaque
;
507 if (n_IRQ
>= OPENPIC_MAX_IRQ
) {
508 fprintf(stderr
, "%s: IRQ %d out of range\n", __func__
, n_IRQ
);
512 src
= &opp
->src
[n_IRQ
];
513 DPRINTF("openpic: set irq %d = %d ivpr=0x%08x\n",
514 n_IRQ
, level
, src
->ivpr
);
516 /* level-sensitive irq */
517 src
->pending
= level
;
518 openpic_update_irq(opp
, n_IRQ
);
520 /* edge-sensitive irq */
523 openpic_update_irq(opp
, n_IRQ
);
526 if (src
->output
!= OPENPIC_OUTPUT_INT
) {
527 /* Edge-triggered interrupts shouldn't be used
528 * with non-INT delivery, but just in case,
529 * try to make it do something sane rather than
530 * cause an interrupt storm. This is close to
531 * what you'd probably see happen in real hardware.
534 openpic_update_irq(opp
, n_IRQ
);
539 static void openpic_reset(DeviceState
*d
)
541 OpenPICState
*opp
= OPENPIC(d
);
544 opp
->gcr
= GCR_RESET
;
545 /* Initialise controller registers */
546 opp
->frr
= ((opp
->nb_irqs
- 1) << FRR_NIRQ_SHIFT
) |
547 ((opp
->nb_cpus
- 1) << FRR_NCPU_SHIFT
) |
548 (opp
->vid
<< FRR_VID_SHIFT
);
551 opp
->spve
= -1 & opp
->vector_mask
;
552 opp
->tfrr
= opp
->tfrr_reset
;
553 /* Initialise IRQ sources */
554 for (i
= 0; i
< opp
->max_irq
; i
++) {
555 opp
->src
[i
].ivpr
= opp
->ivpr_reset
;
556 opp
->src
[i
].idr
= opp
->idr_reset
;
558 switch (opp
->src
[i
].type
) {
559 case IRQ_TYPE_NORMAL
:
560 opp
->src
[i
].level
= !!(opp
->ivpr_reset
& IVPR_SENSE_MASK
);
563 case IRQ_TYPE_FSLINT
:
564 opp
->src
[i
].ivpr
|= IVPR_POLARITY_MASK
;
567 case IRQ_TYPE_FSLSPECIAL
:
571 /* Initialise IRQ destinations */
572 for (i
= 0; i
< MAX_CPU
; i
++) {
573 opp
->dst
[i
].ctpr
= 15;
574 memset(&opp
->dst
[i
].raised
, 0, sizeof(IRQQueue
));
575 opp
->dst
[i
].raised
.next
= -1;
576 memset(&opp
->dst
[i
].servicing
, 0, sizeof(IRQQueue
));
577 opp
->dst
[i
].servicing
.next
= -1;
579 /* Initialise timers */
580 for (i
= 0; i
< OPENPIC_MAX_TMR
; i
++) {
581 opp
->timers
[i
].tccr
= 0;
582 opp
->timers
[i
].tbcr
= TBCR_CI
;
584 /* Go out of RESET state */
588 static inline uint32_t read_IRQreg_idr(OpenPICState
*opp
, int n_IRQ
)
590 return opp
->src
[n_IRQ
].idr
;
593 static inline uint32_t read_IRQreg_ilr(OpenPICState
*opp
, int n_IRQ
)
595 if (opp
->flags
& OPENPIC_FLAG_ILR
) {
596 return output_to_inttgt(opp
->src
[n_IRQ
].output
);
602 static inline uint32_t read_IRQreg_ivpr(OpenPICState
*opp
, int n_IRQ
)
604 return opp
->src
[n_IRQ
].ivpr
;
607 static inline void write_IRQreg_idr(OpenPICState
*opp
, int n_IRQ
, uint32_t val
)
609 IRQSource
*src
= &opp
->src
[n_IRQ
];
610 uint32_t normal_mask
= (1UL << opp
->nb_cpus
) - 1;
611 uint32_t crit_mask
= 0;
612 uint32_t mask
= normal_mask
;
613 int crit_shift
= IDR_EP_SHIFT
- opp
->nb_cpus
;
616 if (opp
->flags
& OPENPIC_FLAG_IDR_CRIT
) {
617 crit_mask
= mask
<< crit_shift
;
618 mask
|= crit_mask
| IDR_EP
;
621 src
->idr
= val
& mask
;
622 DPRINTF("Set IDR %d to 0x%08x\n", n_IRQ
, src
->idr
);
624 if (opp
->flags
& OPENPIC_FLAG_IDR_CRIT
) {
625 if (src
->idr
& crit_mask
) {
626 if (src
->idr
& normal_mask
) {
627 DPRINTF("%s: IRQ configured for multiple output types, using "
628 "critical\n", __func__
);
631 src
->output
= OPENPIC_OUTPUT_CINT
;
635 for (i
= 0; i
< opp
->nb_cpus
; i
++) {
636 int n_ci
= IDR_CI0_SHIFT
- i
;
638 if (src
->idr
& (1UL << n_ci
)) {
639 src
->destmask
|= 1UL << i
;
643 src
->output
= OPENPIC_OUTPUT_INT
;
645 src
->destmask
= src
->idr
& normal_mask
;
648 src
->destmask
= src
->idr
;
652 static inline void write_IRQreg_ilr(OpenPICState
*opp
, int n_IRQ
, uint32_t val
)
654 if (opp
->flags
& OPENPIC_FLAG_ILR
) {
655 IRQSource
*src
= &opp
->src
[n_IRQ
];
657 src
->output
= inttgt_to_output(val
& ILR_INTTGT_MASK
);
658 DPRINTF("Set ILR %d to 0x%08x, output %d\n", n_IRQ
, src
->idr
,
661 /* TODO: on MPIC v4.0 only, set nomask for non-INT */
665 static inline void write_IRQreg_ivpr(OpenPICState
*opp
, int n_IRQ
, uint32_t val
)
669 /* NOTE when implementing newer FSL MPIC models: starting with v4.0,
670 * the polarity bit is read-only on internal interrupts.
672 mask
= IVPR_MASK_MASK
| IVPR_PRIORITY_MASK
| IVPR_SENSE_MASK
|
673 IVPR_POLARITY_MASK
| opp
->vector_mask
;
675 /* ACTIVITY bit is read-only */
676 opp
->src
[n_IRQ
].ivpr
=
677 (opp
->src
[n_IRQ
].ivpr
& IVPR_ACTIVITY_MASK
) | (val
& mask
);
679 /* For FSL internal interrupts, The sense bit is reserved and zero,
680 * and the interrupt is always level-triggered. Timers and IPIs
681 * have no sense or polarity bits, and are edge-triggered.
683 switch (opp
->src
[n_IRQ
].type
) {
684 case IRQ_TYPE_NORMAL
:
685 opp
->src
[n_IRQ
].level
= !!(opp
->src
[n_IRQ
].ivpr
& IVPR_SENSE_MASK
);
688 case IRQ_TYPE_FSLINT
:
689 opp
->src
[n_IRQ
].ivpr
&= ~IVPR_SENSE_MASK
;
692 case IRQ_TYPE_FSLSPECIAL
:
693 opp
->src
[n_IRQ
].ivpr
&= ~(IVPR_POLARITY_MASK
| IVPR_SENSE_MASK
);
697 openpic_update_irq(opp
, n_IRQ
);
698 DPRINTF("Set IVPR %d to 0x%08x -> 0x%08x\n", n_IRQ
, val
,
699 opp
->src
[n_IRQ
].ivpr
);
702 static void openpic_gcr_write(OpenPICState
*opp
, uint64_t val
)
704 bool mpic_proxy
= false;
706 if (val
& GCR_RESET
) {
707 openpic_reset(DEVICE(opp
));
711 opp
->gcr
&= ~opp
->mpic_mode_mask
;
712 opp
->gcr
|= val
& opp
->mpic_mode_mask
;
714 /* Set external proxy mode */
715 if ((val
& opp
->mpic_mode_mask
) == GCR_MODE_PROXY
) {
719 ppce500_set_mpic_proxy(mpic_proxy
);
722 static void openpic_gbl_write(void *opaque
, hwaddr addr
, uint64_t val
,
725 OpenPICState
*opp
= opaque
;
729 DPRINTF("%s: addr %#" HWADDR_PRIx
" <= %08" PRIx64
"\n",
730 __func__
, addr
, val
);
735 case 0x00: /* Block Revision Register1 (BRR1) is Readonly */
745 openpic_cpu_write_internal(opp
, addr
, val
, get_current_cpu());
747 case 0x1000: /* FRR */
749 case 0x1020: /* GCR */
750 openpic_gcr_write(opp
, val
);
752 case 0x1080: /* VIR */
754 case 0x1090: /* PIR */
755 for (idx
= 0; idx
< opp
->nb_cpus
; idx
++) {
756 if ((val
& (1 << idx
)) && !(opp
->pir
& (1 << idx
))) {
757 DPRINTF("Raise OpenPIC RESET output for CPU %d\n", idx
);
758 dst
= &opp
->dst
[idx
];
759 qemu_irq_raise(dst
->irqs
[OPENPIC_OUTPUT_RESET
]);
760 } else if (!(val
& (1 << idx
)) && (opp
->pir
& (1 << idx
))) {
761 DPRINTF("Lower OpenPIC RESET output for CPU %d\n", idx
);
762 dst
= &opp
->dst
[idx
];
763 qemu_irq_lower(dst
->irqs
[OPENPIC_OUTPUT_RESET
]);
768 case 0x10A0: /* IPI_IVPR */
774 idx
= (addr
- 0x10A0) >> 4;
775 write_IRQreg_ivpr(opp
, opp
->irq_ipi0
+ idx
, val
);
778 case 0x10E0: /* SPVE */
779 opp
->spve
= val
& opp
->vector_mask
;
786 static uint64_t openpic_gbl_read(void *opaque
, hwaddr addr
, unsigned len
)
788 OpenPICState
*opp
= opaque
;
791 DPRINTF("%s: addr %#" HWADDR_PRIx
"\n", __func__
, addr
);
797 case 0x1000: /* FRR */
800 case 0x1020: /* GCR */
803 case 0x1080: /* VIR */
806 case 0x1090: /* PIR */
809 case 0x00: /* Block Revision Register1 (BRR1) */
820 retval
= openpic_cpu_read_internal(opp
, addr
, get_current_cpu());
822 case 0x10A0: /* IPI_IVPR */
828 idx
= (addr
- 0x10A0) >> 4;
829 retval
= read_IRQreg_ivpr(opp
, opp
->irq_ipi0
+ idx
);
832 case 0x10E0: /* SPVE */
838 DPRINTF("%s: => 0x%08x\n", __func__
, retval
);
843 static void openpic_tmr_write(void *opaque
, hwaddr addr
, uint64_t val
,
846 OpenPICState
*opp
= opaque
;
851 DPRINTF("%s: addr %#" HWADDR_PRIx
" <= %08" PRIx64
"\n",
852 __func__
, addr
, val
);
857 if (addr
== 0x10f0) {
863 idx
= (addr
>> 6) & 0x3;
866 switch (addr
& 0x30) {
867 case 0x00: /* TCCR */
869 case 0x10: /* TBCR */
870 if ((opp
->timers
[idx
].tccr
& TCCR_TOG
) != 0 &&
871 (val
& TBCR_CI
) == 0 &&
872 (opp
->timers
[idx
].tbcr
& TBCR_CI
) != 0) {
873 opp
->timers
[idx
].tccr
&= ~TCCR_TOG
;
875 opp
->timers
[idx
].tbcr
= val
;
877 case 0x20: /* TVPR */
878 write_IRQreg_ivpr(opp
, opp
->irq_tim0
+ idx
, val
);
881 write_IRQreg_idr(opp
, opp
->irq_tim0
+ idx
, val
);
886 static uint64_t openpic_tmr_read(void *opaque
, hwaddr addr
, unsigned len
)
888 OpenPICState
*opp
= opaque
;
889 uint32_t retval
= -1;
892 DPRINTF("%s: addr %#" HWADDR_PRIx
"\n", __func__
, addr
);
896 idx
= (addr
>> 6) & 0x3;
902 switch (addr
& 0x30) {
903 case 0x00: /* TCCR */
904 retval
= opp
->timers
[idx
].tccr
;
906 case 0x10: /* TBCR */
907 retval
= opp
->timers
[idx
].tbcr
;
909 case 0x20: /* TIPV */
910 retval
= read_IRQreg_ivpr(opp
, opp
->irq_tim0
+ idx
);
912 case 0x30: /* TIDE (TIDR) */
913 retval
= read_IRQreg_idr(opp
, opp
->irq_tim0
+ idx
);
918 DPRINTF("%s: => 0x%08x\n", __func__
, retval
);
923 static void openpic_src_write(void *opaque
, hwaddr addr
, uint64_t val
,
926 OpenPICState
*opp
= opaque
;
929 DPRINTF("%s: addr %#" HWADDR_PRIx
" <= %08" PRIx64
"\n",
930 __func__
, addr
, val
);
932 addr
= addr
& 0xffff;
935 switch (addr
& 0x1f) {
937 write_IRQreg_ivpr(opp
, idx
, val
);
940 write_IRQreg_idr(opp
, idx
, val
);
943 write_IRQreg_ilr(opp
, idx
, val
);
948 static uint64_t openpic_src_read(void *opaque
, uint64_t addr
, unsigned len
)
950 OpenPICState
*opp
= opaque
;
954 DPRINTF("%s: addr %#" HWADDR_PRIx
"\n", __func__
, addr
);
957 addr
= addr
& 0xffff;
960 switch (addr
& 0x1f) {
962 retval
= read_IRQreg_ivpr(opp
, idx
);
965 retval
= read_IRQreg_idr(opp
, idx
);
968 retval
= read_IRQreg_ilr(opp
, idx
);
972 DPRINTF("%s: => 0x%08x\n", __func__
, retval
);
976 static void openpic_msi_write(void *opaque
, hwaddr addr
, uint64_t val
,
979 OpenPICState
*opp
= opaque
;
980 int idx
= opp
->irq_msi
;
983 DPRINTF("%s: addr %#" HWADDR_PRIx
" <= 0x%08" PRIx64
"\n",
984 __func__
, addr
, val
);
991 srs
= val
>> MSIIR_SRS_SHIFT
;
993 ibs
= (val
& MSIIR_IBS_MASK
) >> MSIIR_IBS_SHIFT
;
994 opp
->msi
[srs
].msir
|= 1 << ibs
;
995 openpic_set_irq(opp
, idx
, 1);
998 /* most registers are read-only, thus ignored */
1003 static uint64_t openpic_msi_read(void *opaque
, hwaddr addr
, unsigned size
)
1005 OpenPICState
*opp
= opaque
;
1009 DPRINTF("%s: addr %#" HWADDR_PRIx
"\n", __func__
, addr
);
1024 case 0x70: /* MSIRs */
1025 r
= opp
->msi
[srs
].msir
;
1027 opp
->msi
[srs
].msir
= 0;
1028 openpic_set_irq(opp
, opp
->irq_msi
+ srs
, 0);
1030 case 0x120: /* MSISR */
1031 for (i
= 0; i
< MAX_MSI
; i
++) {
1032 r
|= (opp
->msi
[i
].msir
? 1 : 0) << i
;
1040 static uint64_t openpic_summary_read(void *opaque
, hwaddr addr
, unsigned size
)
1044 DPRINTF("%s: addr %#" HWADDR_PRIx
"\n", __func__
, addr
);
1046 /* TODO: EISR/EIMR */
1051 static void openpic_summary_write(void *opaque
, hwaddr addr
, uint64_t val
,
1054 DPRINTF("%s: addr %#" HWADDR_PRIx
" <= 0x%08" PRIx64
"\n",
1055 __func__
, addr
, val
);
1057 /* TODO: EISR/EIMR */
1060 static void openpic_cpu_write_internal(void *opaque
, hwaddr addr
,
1061 uint32_t val
, int idx
)
1063 OpenPICState
*opp
= opaque
;
1068 DPRINTF("%s: cpu %d addr %#" HWADDR_PRIx
" <= 0x%08x\n", __func__
, idx
,
1078 dst
= &opp
->dst
[idx
];
1081 case 0x40: /* IPIDR */
1085 idx
= (addr
- 0x40) >> 4;
1086 /* we use IDE as mask which CPUs to deliver the IPI to still. */
1087 opp
->src
[opp
->irq_ipi0
+ idx
].destmask
|= val
;
1088 openpic_set_irq(opp
, opp
->irq_ipi0
+ idx
, 1);
1089 openpic_set_irq(opp
, opp
->irq_ipi0
+ idx
, 0);
1091 case 0x80: /* CTPR */
1092 dst
->ctpr
= val
& 0x0000000F;
1094 DPRINTF("%s: set CPU %d ctpr to %d, raised %d servicing %d\n",
1095 __func__
, idx
, dst
->ctpr
, dst
->raised
.priority
,
1096 dst
->servicing
.priority
);
1098 if (dst
->raised
.priority
<= dst
->ctpr
) {
1099 DPRINTF("%s: Lower OpenPIC INT output cpu %d due to ctpr\n",
1101 qemu_irq_lower(dst
->irqs
[OPENPIC_OUTPUT_INT
]);
1102 } else if (dst
->raised
.priority
> dst
->servicing
.priority
) {
1103 DPRINTF("%s: Raise OpenPIC INT output cpu %d irq %d\n",
1104 __func__
, idx
, dst
->raised
.next
);
1105 qemu_irq_raise(dst
->irqs
[OPENPIC_OUTPUT_INT
]);
1109 case 0x90: /* WHOAMI */
1110 /* Read-only register */
1112 case 0xA0: /* IACK */
1113 /* Read-only register */
1115 case 0xB0: /* EOI */
1117 s_IRQ
= IRQ_get_next(opp
, &dst
->servicing
);
1120 DPRINTF("%s: EOI with no interrupt in service\n", __func__
);
1124 IRQ_resetbit(&dst
->servicing
, s_IRQ
);
1125 /* Set up next servicing IRQ */
1126 s_IRQ
= IRQ_get_next(opp
, &dst
->servicing
);
1127 /* Check queued interrupts. */
1128 n_IRQ
= IRQ_get_next(opp
, &dst
->raised
);
1129 src
= &opp
->src
[n_IRQ
];
1132 IVPR_PRIORITY(src
->ivpr
) > dst
->servicing
.priority
)) {
1133 DPRINTF("Raise OpenPIC INT output cpu %d irq %d\n",
1135 qemu_irq_raise(opp
->dst
[idx
].irqs
[OPENPIC_OUTPUT_INT
]);
1143 static void openpic_cpu_write(void *opaque
, hwaddr addr
, uint64_t val
,
1146 openpic_cpu_write_internal(opaque
, addr
, val
, (addr
& 0x1f000) >> 12);
1150 static uint32_t openpic_iack(OpenPICState
*opp
, IRQDest
*dst
, int cpu
)
1155 DPRINTF("Lower OpenPIC INT output\n");
1156 qemu_irq_lower(dst
->irqs
[OPENPIC_OUTPUT_INT
]);
1158 irq
= IRQ_get_next(opp
, &dst
->raised
);
1159 DPRINTF("IACK: irq=%d\n", irq
);
1162 /* No more interrupt pending */
1166 src
= &opp
->src
[irq
];
1167 if (!(src
->ivpr
& IVPR_ACTIVITY_MASK
) ||
1168 !(IVPR_PRIORITY(src
->ivpr
) > dst
->ctpr
)) {
1169 fprintf(stderr
, "%s: bad raised IRQ %d ctpr %d ivpr 0x%08x\n",
1170 __func__
, irq
, dst
->ctpr
, src
->ivpr
);
1171 openpic_update_irq(opp
, irq
);
1174 /* IRQ enter servicing state */
1175 IRQ_setbit(&dst
->servicing
, irq
);
1176 retval
= IVPR_VECTOR(opp
, src
->ivpr
);
1180 /* edge-sensitive IRQ */
1181 src
->ivpr
&= ~IVPR_ACTIVITY_MASK
;
1183 IRQ_resetbit(&dst
->raised
, irq
);
1186 if ((irq
>= opp
->irq_ipi0
) && (irq
< (opp
->irq_ipi0
+ OPENPIC_MAX_IPI
))) {
1187 src
->destmask
&= ~(1 << cpu
);
1188 if (src
->destmask
&& !src
->level
) {
1189 /* trigger on CPUs that didn't know about it yet */
1190 openpic_set_irq(opp
, irq
, 1);
1191 openpic_set_irq(opp
, irq
, 0);
1192 /* if all CPUs knew about it, set active bit again */
1193 src
->ivpr
|= IVPR_ACTIVITY_MASK
;
1200 static uint32_t openpic_cpu_read_internal(void *opaque
, hwaddr addr
,
1203 OpenPICState
*opp
= opaque
;
1207 DPRINTF("%s: cpu %d addr %#" HWADDR_PRIx
"\n", __func__
, idx
, addr
);
1208 retval
= 0xFFFFFFFF;
1217 dst
= &opp
->dst
[idx
];
1220 case 0x80: /* CTPR */
1223 case 0x90: /* WHOAMI */
1226 case 0xA0: /* IACK */
1227 retval
= openpic_iack(opp
, dst
, idx
);
1229 case 0xB0: /* EOI */
1235 DPRINTF("%s: => 0x%08x\n", __func__
, retval
);
1240 static uint64_t openpic_cpu_read(void *opaque
, hwaddr addr
, unsigned len
)
1242 return openpic_cpu_read_internal(opaque
, addr
, (addr
& 0x1f000) >> 12);
1245 static const MemoryRegionOps openpic_glb_ops_le
= {
1246 .write
= openpic_gbl_write
,
1247 .read
= openpic_gbl_read
,
1248 .endianness
= DEVICE_LITTLE_ENDIAN
,
1250 .min_access_size
= 4,
1251 .max_access_size
= 4,
1255 static const MemoryRegionOps openpic_glb_ops_be
= {
1256 .write
= openpic_gbl_write
,
1257 .read
= openpic_gbl_read
,
1258 .endianness
= DEVICE_BIG_ENDIAN
,
1260 .min_access_size
= 4,
1261 .max_access_size
= 4,
1265 static const MemoryRegionOps openpic_tmr_ops_le
= {
1266 .write
= openpic_tmr_write
,
1267 .read
= openpic_tmr_read
,
1268 .endianness
= DEVICE_LITTLE_ENDIAN
,
1270 .min_access_size
= 4,
1271 .max_access_size
= 4,
1275 static const MemoryRegionOps openpic_tmr_ops_be
= {
1276 .write
= openpic_tmr_write
,
1277 .read
= openpic_tmr_read
,
1278 .endianness
= DEVICE_BIG_ENDIAN
,
1280 .min_access_size
= 4,
1281 .max_access_size
= 4,
1285 static const MemoryRegionOps openpic_cpu_ops_le
= {
1286 .write
= openpic_cpu_write
,
1287 .read
= openpic_cpu_read
,
1288 .endianness
= DEVICE_LITTLE_ENDIAN
,
1290 .min_access_size
= 4,
1291 .max_access_size
= 4,
1295 static const MemoryRegionOps openpic_cpu_ops_be
= {
1296 .write
= openpic_cpu_write
,
1297 .read
= openpic_cpu_read
,
1298 .endianness
= DEVICE_BIG_ENDIAN
,
1300 .min_access_size
= 4,
1301 .max_access_size
= 4,
1305 static const MemoryRegionOps openpic_src_ops_le
= {
1306 .write
= openpic_src_write
,
1307 .read
= openpic_src_read
,
1308 .endianness
= DEVICE_LITTLE_ENDIAN
,
1310 .min_access_size
= 4,
1311 .max_access_size
= 4,
1315 static const MemoryRegionOps openpic_src_ops_be
= {
1316 .write
= openpic_src_write
,
1317 .read
= openpic_src_read
,
1318 .endianness
= DEVICE_BIG_ENDIAN
,
1320 .min_access_size
= 4,
1321 .max_access_size
= 4,
1325 static const MemoryRegionOps openpic_msi_ops_be
= {
1326 .read
= openpic_msi_read
,
1327 .write
= openpic_msi_write
,
1328 .endianness
= DEVICE_BIG_ENDIAN
,
1330 .min_access_size
= 4,
1331 .max_access_size
= 4,
1335 static const MemoryRegionOps openpic_summary_ops_be
= {
1336 .read
= openpic_summary_read
,
1337 .write
= openpic_summary_write
,
1338 .endianness
= DEVICE_BIG_ENDIAN
,
1340 .min_access_size
= 4,
1341 .max_access_size
= 4,
1345 static void openpic_save_IRQ_queue(QEMUFile
* f
, IRQQueue
*q
)
1349 for (i
= 0; i
< ARRAY_SIZE(q
->queue
); i
++) {
1350 /* Always put the lower half of a 64-bit long first, in case we
1351 * restore on a 32-bit host. The least significant bits correspond
1352 * to lower IRQ numbers in the bitmap.
1354 qemu_put_be32(f
, (uint32_t)q
->queue
[i
]);
1355 #if LONG_MAX > 0x7FFFFFFF
1356 qemu_put_be32(f
, (uint32_t)(q
->queue
[i
] >> 32));
1360 qemu_put_sbe32s(f
, &q
->next
);
1361 qemu_put_sbe32s(f
, &q
->priority
);
1364 static void openpic_save(QEMUFile
* f
, void *opaque
)
1366 OpenPICState
*opp
= (OpenPICState
*)opaque
;
1369 qemu_put_be32s(f
, &opp
->gcr
);
1370 qemu_put_be32s(f
, &opp
->vir
);
1371 qemu_put_be32s(f
, &opp
->pir
);
1372 qemu_put_be32s(f
, &opp
->spve
);
1373 qemu_put_be32s(f
, &opp
->tfrr
);
1375 qemu_put_be32s(f
, &opp
->nb_cpus
);
1377 for (i
= 0; i
< opp
->nb_cpus
; i
++) {
1378 qemu_put_sbe32s(f
, &opp
->dst
[i
].ctpr
);
1379 openpic_save_IRQ_queue(f
, &opp
->dst
[i
].raised
);
1380 openpic_save_IRQ_queue(f
, &opp
->dst
[i
].servicing
);
1381 qemu_put_buffer(f
, (uint8_t *)&opp
->dst
[i
].outputs_active
,
1382 sizeof(opp
->dst
[i
].outputs_active
));
1385 for (i
= 0; i
< OPENPIC_MAX_TMR
; i
++) {
1386 qemu_put_be32s(f
, &opp
->timers
[i
].tccr
);
1387 qemu_put_be32s(f
, &opp
->timers
[i
].tbcr
);
1390 for (i
= 0; i
< opp
->max_irq
; i
++) {
1391 qemu_put_be32s(f
, &opp
->src
[i
].ivpr
);
1392 qemu_put_be32s(f
, &opp
->src
[i
].idr
);
1393 qemu_get_be32s(f
, &opp
->src
[i
].destmask
);
1394 qemu_put_sbe32s(f
, &opp
->src
[i
].last_cpu
);
1395 qemu_put_sbe32s(f
, &opp
->src
[i
].pending
);
1399 static void openpic_load_IRQ_queue(QEMUFile
* f
, IRQQueue
*q
)
1403 for (i
= 0; i
< ARRAY_SIZE(q
->queue
); i
++) {
1406 val
= qemu_get_be32(f
);
1407 #if LONG_MAX > 0x7FFFFFFF
1409 val
|= qemu_get_be32(f
);
1415 qemu_get_sbe32s(f
, &q
->next
);
1416 qemu_get_sbe32s(f
, &q
->priority
);
1419 static int openpic_load(QEMUFile
* f
, void *opaque
, int version_id
)
1421 OpenPICState
*opp
= (OpenPICState
*)opaque
;
1424 if (version_id
!= 1) {
1428 qemu_get_be32s(f
, &opp
->gcr
);
1429 qemu_get_be32s(f
, &opp
->vir
);
1430 qemu_get_be32s(f
, &opp
->pir
);
1431 qemu_get_be32s(f
, &opp
->spve
);
1432 qemu_get_be32s(f
, &opp
->tfrr
);
1434 qemu_get_be32s(f
, &opp
->nb_cpus
);
1436 for (i
= 0; i
< opp
->nb_cpus
; i
++) {
1437 qemu_get_sbe32s(f
, &opp
->dst
[i
].ctpr
);
1438 openpic_load_IRQ_queue(f
, &opp
->dst
[i
].raised
);
1439 openpic_load_IRQ_queue(f
, &opp
->dst
[i
].servicing
);
1440 qemu_get_buffer(f
, (uint8_t *)&opp
->dst
[i
].outputs_active
,
1441 sizeof(opp
->dst
[i
].outputs_active
));
1444 for (i
= 0; i
< OPENPIC_MAX_TMR
; i
++) {
1445 qemu_get_be32s(f
, &opp
->timers
[i
].tccr
);
1446 qemu_get_be32s(f
, &opp
->timers
[i
].tbcr
);
1449 for (i
= 0; i
< opp
->max_irq
; i
++) {
1452 val
= qemu_get_be32(f
);
1453 write_IRQreg_idr(opp
, i
, val
);
1454 val
= qemu_get_be32(f
);
1455 write_IRQreg_ivpr(opp
, i
, val
);
1457 qemu_get_be32s(f
, &opp
->src
[i
].ivpr
);
1458 qemu_get_be32s(f
, &opp
->src
[i
].idr
);
1459 qemu_get_be32s(f
, &opp
->src
[i
].destmask
);
1460 qemu_get_sbe32s(f
, &opp
->src
[i
].last_cpu
);
1461 qemu_get_sbe32s(f
, &opp
->src
[i
].pending
);
1467 typedef struct MemReg
{
1469 MemoryRegionOps
const *ops
;
1474 static void fsl_common_init(OpenPICState
*opp
)
1477 int virq
= OPENPIC_MAX_SRC
;
1479 opp
->vid
= VID_REVISION_1_2
;
1480 opp
->vir
= VIR_GENERIC
;
1481 opp
->vector_mask
= 0xFFFF;
1482 opp
->tfrr_reset
= 0;
1483 opp
->ivpr_reset
= IVPR_MASK_MASK
;
1484 opp
->idr_reset
= 1 << 0;
1485 opp
->max_irq
= OPENPIC_MAX_IRQ
;
1487 opp
->irq_ipi0
= virq
;
1488 virq
+= OPENPIC_MAX_IPI
;
1489 opp
->irq_tim0
= virq
;
1490 virq
+= OPENPIC_MAX_TMR
;
1492 assert(virq
<= OPENPIC_MAX_IRQ
);
1496 msi_supported
= true;
1497 for (i
= 0; i
< opp
->fsl
->max_ext
; i
++) {
1498 opp
->src
[i
].level
= false;
1501 /* Internal interrupts, including message and MSI */
1502 for (i
= 16; i
< OPENPIC_MAX_SRC
; i
++) {
1503 opp
->src
[i
].type
= IRQ_TYPE_FSLINT
;
1504 opp
->src
[i
].level
= true;
1507 /* timers and IPIs */
1508 for (i
= OPENPIC_MAX_SRC
; i
< virq
; i
++) {
1509 opp
->src
[i
].type
= IRQ_TYPE_FSLSPECIAL
;
1510 opp
->src
[i
].level
= false;
1514 static void map_list(OpenPICState
*opp
, const MemReg
*list
, int *count
)
1516 while (list
->name
) {
1517 assert(*count
< ARRAY_SIZE(opp
->sub_io_mem
));
1519 memory_region_init_io(&opp
->sub_io_mem
[*count
], OBJECT(opp
), list
->ops
,
1520 opp
, list
->name
, list
->size
);
1522 memory_region_add_subregion(&opp
->mem
, list
->start_addr
,
1523 &opp
->sub_io_mem
[*count
]);
1530 static void openpic_init(Object
*obj
)
1532 OpenPICState
*opp
= OPENPIC(obj
);
1534 memory_region_init(&opp
->mem
, obj
, "openpic", 0x40000);
1537 static void openpic_realize(DeviceState
*dev
, Error
**errp
)
1539 SysBusDevice
*d
= SYS_BUS_DEVICE(dev
);
1540 OpenPICState
*opp
= OPENPIC(dev
);
1543 static const MemReg list_le
[] = {
1544 {"glb", &openpic_glb_ops_le
,
1545 OPENPIC_GLB_REG_START
, OPENPIC_GLB_REG_SIZE
},
1546 {"tmr", &openpic_tmr_ops_le
,
1547 OPENPIC_TMR_REG_START
, OPENPIC_TMR_REG_SIZE
},
1548 {"src", &openpic_src_ops_le
,
1549 OPENPIC_SRC_REG_START
, OPENPIC_SRC_REG_SIZE
},
1550 {"cpu", &openpic_cpu_ops_le
,
1551 OPENPIC_CPU_REG_START
, OPENPIC_CPU_REG_SIZE
},
1554 static const MemReg list_be
[] = {
1555 {"glb", &openpic_glb_ops_be
,
1556 OPENPIC_GLB_REG_START
, OPENPIC_GLB_REG_SIZE
},
1557 {"tmr", &openpic_tmr_ops_be
,
1558 OPENPIC_TMR_REG_START
, OPENPIC_TMR_REG_SIZE
},
1559 {"src", &openpic_src_ops_be
,
1560 OPENPIC_SRC_REG_START
, OPENPIC_SRC_REG_SIZE
},
1561 {"cpu", &openpic_cpu_ops_be
,
1562 OPENPIC_CPU_REG_START
, OPENPIC_CPU_REG_SIZE
},
1565 static const MemReg list_fsl
[] = {
1566 {"msi", &openpic_msi_ops_be
,
1567 OPENPIC_MSI_REG_START
, OPENPIC_MSI_REG_SIZE
},
1568 {"summary", &openpic_summary_ops_be
,
1569 OPENPIC_SUMMARY_REG_START
, OPENPIC_SUMMARY_REG_SIZE
},
1573 switch (opp
->model
) {
1574 case OPENPIC_MODEL_FSL_MPIC_20
:
1576 opp
->fsl
= &fsl_mpic_20
;
1577 opp
->brr1
= 0x00400200;
1578 opp
->flags
|= OPENPIC_FLAG_IDR_CRIT
;
1580 opp
->mpic_mode_mask
= GCR_MODE_MIXED
;
1582 fsl_common_init(opp
);
1583 map_list(opp
, list_be
, &list_count
);
1584 map_list(opp
, list_fsl
, &list_count
);
1588 case OPENPIC_MODEL_FSL_MPIC_42
:
1589 opp
->fsl
= &fsl_mpic_42
;
1590 opp
->brr1
= 0x00400402;
1591 opp
->flags
|= OPENPIC_FLAG_ILR
;
1593 opp
->mpic_mode_mask
= GCR_MODE_PROXY
;
1595 fsl_common_init(opp
);
1596 map_list(opp
, list_be
, &list_count
);
1597 map_list(opp
, list_fsl
, &list_count
);
1601 case OPENPIC_MODEL_RAVEN
:
1602 opp
->nb_irqs
= RAVEN_MAX_EXT
;
1603 opp
->vid
= VID_REVISION_1_3
;
1604 opp
->vir
= VIR_GENERIC
;
1605 opp
->vector_mask
= 0xFF;
1606 opp
->tfrr_reset
= 4160000;
1607 opp
->ivpr_reset
= IVPR_MASK_MASK
| IVPR_MODE_MASK
;
1609 opp
->max_irq
= RAVEN_MAX_IRQ
;
1610 opp
->irq_ipi0
= RAVEN_IPI_IRQ
;
1611 opp
->irq_tim0
= RAVEN_TMR_IRQ
;
1613 opp
->mpic_mode_mask
= GCR_MODE_MIXED
;
1615 if (opp
->nb_cpus
!= 1) {
1616 error_setg(errp
, "Only UP supported today");
1620 map_list(opp
, list_le
, &list_count
);
1624 for (i
= 0; i
< opp
->nb_cpus
; i
++) {
1625 opp
->dst
[i
].irqs
= g_new(qemu_irq
, OPENPIC_OUTPUT_NB
);
1626 for (j
= 0; j
< OPENPIC_OUTPUT_NB
; j
++) {
1627 sysbus_init_irq(d
, &opp
->dst
[i
].irqs
[j
]);
1631 register_savevm(dev
, "openpic", 0, 2,
1632 openpic_save
, openpic_load
, opp
);
1634 sysbus_init_mmio(d
, &opp
->mem
);
1635 qdev_init_gpio_in(dev
, openpic_set_irq
, opp
->max_irq
);
1638 static Property openpic_properties
[] = {
1639 DEFINE_PROP_UINT32("model", OpenPICState
, model
, OPENPIC_MODEL_FSL_MPIC_20
),
1640 DEFINE_PROP_UINT32("nb_cpus", OpenPICState
, nb_cpus
, 1),
1641 DEFINE_PROP_END_OF_LIST(),
1644 static void openpic_class_init(ObjectClass
*oc
, void *data
)
1646 DeviceClass
*dc
= DEVICE_CLASS(oc
);
1648 dc
->realize
= openpic_realize
;
1649 dc
->props
= openpic_properties
;
1650 dc
->reset
= openpic_reset
;
1653 static const TypeInfo openpic_info
= {
1654 .name
= TYPE_OPENPIC
,
1655 .parent
= TYPE_SYS_BUS_DEVICE
,
1656 .instance_size
= sizeof(OpenPICState
),
1657 .instance_init
= openpic_init
,
1658 .class_init
= openpic_class_init
,
1661 static void openpic_register_types(void)
1663 type_register_static(&openpic_info
);
1666 type_init(openpic_register_types
)