5 #include "hw/core/cpu.h"
9 #define VID 0x03 /* MPIC version ID */
11 /* OpenPIC have 5 outputs per CPU connected and one IRQ out single output */
13 OPENPIC_OUTPUT_INT
= 0, /* IRQ */
14 OPENPIC_OUTPUT_CINT
, /* critical IRQ */
15 OPENPIC_OUTPUT_MCK
, /* Machine check event */
16 OPENPIC_OUTPUT_DEBUG
, /* Inconditional debug event */
17 OPENPIC_OUTPUT_RESET
, /* Core reset event */
21 typedef struct IrqLines
{ qemu_irq irq
[OPENPIC_OUTPUT_NB
]; } IrqLines
;
23 #define OPENPIC_MODEL_RAVEN 0
24 #define OPENPIC_MODEL_FSL_MPIC_20 1
25 #define OPENPIC_MODEL_FSL_MPIC_42 2
26 #define OPENPIC_MODEL_KEYLARGO 3
28 #define OPENPIC_MAX_SRC 256
29 #define OPENPIC_MAX_TMR 4
30 #define OPENPIC_MAX_IPI 4
31 #define OPENPIC_MAX_IRQ (OPENPIC_MAX_SRC + OPENPIC_MAX_IPI + \
35 #define RAVEN_MAX_CPU 2
36 #define RAVEN_MAX_EXT 48
37 #define RAVEN_MAX_IRQ 64
38 #define RAVEN_MAX_TMR OPENPIC_MAX_TMR
39 #define RAVEN_MAX_IPI OPENPIC_MAX_IPI
42 #define KEYLARGO_MAX_CPU 4
43 #define KEYLARGO_MAX_EXT 64
44 #define KEYLARGO_MAX_IPI 4
45 #define KEYLARGO_MAX_IRQ (64 + KEYLARGO_MAX_IPI)
46 #define KEYLARGO_MAX_TMR 0
47 #define KEYLARGO_IPI_IRQ (KEYLARGO_MAX_EXT) /* First IPI IRQ */
48 /* Timers don't exist but this makes the code happy... */
49 #define KEYLARGO_TMR_IRQ (KEYLARGO_IPI_IRQ + KEYLARGO_MAX_IPI)
51 /* Interrupt definitions */
52 #define RAVEN_FE_IRQ (RAVEN_MAX_EXT) /* Internal functional IRQ */
53 #define RAVEN_ERR_IRQ (RAVEN_MAX_EXT + 1) /* Error IRQ */
54 #define RAVEN_TMR_IRQ (RAVEN_MAX_EXT + 2) /* First timer IRQ */
55 #define RAVEN_IPI_IRQ (RAVEN_TMR_IRQ + RAVEN_MAX_TMR) /* First IPI IRQ */
56 /* First doorbell IRQ */
57 #define RAVEN_DBL_IRQ (RAVEN_IPI_IRQ + (RAVEN_MAX_CPU * RAVEN_MAX_IPI))
59 typedef struct FslMpicInfo
{
63 typedef enum IRQType
{
65 IRQ_TYPE_FSLINT
, /* FSL internal interrupt -- level only */
66 IRQ_TYPE_FSLSPECIAL
, /* FSL timer/IPI interrupt, edge, no polarity */
69 /* Round up to the nearest 64 IRQs so that the queue length
70 * won't change when moving between 32 and 64 bit hosts.
72 #define IRQQUEUE_SIZE_BITS ((OPENPIC_MAX_IRQ + 63) & ~63)
74 typedef struct IRQQueue
{
76 int32_t queue_size
; /* Only used for VMSTATE_BITMAP */
81 typedef struct IRQSource
{
82 uint32_t ivpr
; /* IRQ vector/priority register */
83 uint32_t idr
; /* IRQ destination register */
84 uint32_t destmask
; /* bitmap of CPU destinations */
86 int output
; /* IRQ level, e.g. OPENPIC_OUTPUT_INT */
87 int pending
; /* TRUE if IRQ is pending */
89 bool level
:1; /* level-triggered */
90 bool nomask
:1; /* critical interrupts ignore mask on some FSL MPICs */
93 #define IVPR_MASK_SHIFT 31
94 #define IVPR_MASK_MASK (1U << IVPR_MASK_SHIFT)
95 #define IVPR_ACTIVITY_SHIFT 30
96 #define IVPR_ACTIVITY_MASK (1U << IVPR_ACTIVITY_SHIFT)
97 #define IVPR_MODE_SHIFT 29
98 #define IVPR_MODE_MASK (1U << IVPR_MODE_SHIFT)
99 #define IVPR_POLARITY_SHIFT 23
100 #define IVPR_POLARITY_MASK (1U << IVPR_POLARITY_SHIFT)
101 #define IVPR_SENSE_SHIFT 22
102 #define IVPR_SENSE_MASK (1U << IVPR_SENSE_SHIFT)
104 #define IVPR_PRIORITY_MASK (0xFU << 16)
105 #define IVPR_PRIORITY(_ivprr_) ((int)(((_ivprr_) & IVPR_PRIORITY_MASK) >> 16))
106 #define IVPR_VECTOR(opp, _ivprr_) ((_ivprr_) & (opp)->vector_mask)
108 /* IDR[EP/CI] are only for FSL MPIC prior to v4.0 */
109 #define IDR_EP 0x80000000 /* external pin */
110 #define IDR_CI 0x40000000 /* critical interrupt */
112 typedef struct OpenPICTimer
{
113 uint32_t tccr
; /* Global timer current count register */
114 uint32_t tbcr
; /* Global timer base count register */
116 bool qemu_timer_active
; /* Is the qemu_timer is running? */
117 struct QEMUTimer
*qemu_timer
;
118 struct OpenPICState
*opp
; /* Device timer is part of. */
119 /* The QEMU_CLOCK_VIRTUAL time (in ns) corresponding to the last
120 current_count written or read, only defined if qemu_timer_active. */
121 uint64_t origin_time
;
124 typedef struct OpenPICMSI
{
125 uint32_t msir
; /* Shared Message Signaled Interrupt Register */
128 typedef struct IRQDest
{
129 int32_t ctpr
; /* CPU current task priority */
134 /* Count of IRQ sources asserting on non-INT outputs */
135 uint32_t outputs_active
[OPENPIC_OUTPUT_NB
];
138 #define TYPE_OPENPIC "openpic"
139 #define OPENPIC(obj) OBJECT_CHECK(OpenPICState, (obj), TYPE_OPENPIC)
141 typedef struct OpenPICState
{
143 SysBusDevice parent_obj
;
148 /* Behavior control */
154 uint32_t vir
; /* Vendor identification register */
155 uint32_t vector_mask
;
160 uint32_t mpic_mode_mask
;
163 MemoryRegion sub_io_mem
[6];
165 /* Global registers */
166 uint32_t frr
; /* Feature reporting register */
167 uint32_t gcr
; /* Global configuration register */
168 uint32_t pir
; /* Processor initialization register */
169 uint32_t spve
; /* Spurious vector register */
170 uint32_t tfrr
; /* Timer frequency reporting register */
171 /* Source registers */
172 IRQSource src
[OPENPIC_MAX_IRQ
];
173 /* Local registers per output pin */
174 IRQDest dst
[MAX_CPU
];
176 /* Timer registers */
177 OpenPICTimer timers
[OPENPIC_MAX_TMR
];
180 /* Shared MSI registers */
181 OpenPICMSI msi
[MAX_MSI
];
188 #endif /* OPENPIC_H */