5 #include "hw/core/cpu.h"
6 #include "qom/object.h"
10 #define VID 0x03 /* MPIC version ID */
12 /* OpenPIC have 5 outputs per CPU connected and one IRQ out single output */
14 OPENPIC_OUTPUT_INT
= 0, /* IRQ */
15 OPENPIC_OUTPUT_CINT
, /* critical IRQ */
16 OPENPIC_OUTPUT_MCK
, /* Machine check event */
17 OPENPIC_OUTPUT_DEBUG
, /* Unconditional debug event */
18 OPENPIC_OUTPUT_RESET
, /* Core reset event */
22 typedef struct IrqLines
{ qemu_irq irq
[OPENPIC_OUTPUT_NB
]; } IrqLines
;
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 KEYLARGO_MAX_CPU 4
36 #define KEYLARGO_MAX_EXT 64
37 #define KEYLARGO_MAX_IPI 4
38 #define KEYLARGO_MAX_IRQ (64 + KEYLARGO_MAX_IPI)
39 #define KEYLARGO_MAX_TMR 0
40 #define KEYLARGO_IPI_IRQ (KEYLARGO_MAX_EXT) /* First IPI IRQ */
41 /* Timers don't exist but this makes the code happy... */
42 #define KEYLARGO_TMR_IRQ (KEYLARGO_IPI_IRQ + KEYLARGO_MAX_IPI)
44 typedef struct FslMpicInfo
{
48 typedef enum IRQType
{
50 IRQ_TYPE_FSLINT
, /* FSL internal interrupt -- level only */
51 IRQ_TYPE_FSLSPECIAL
, /* FSL timer/IPI interrupt, edge, no polarity */
55 * Round up to the nearest 64 IRQs so that the queue length
56 * won't change when moving between 32 and 64 bit hosts.
58 #define IRQQUEUE_SIZE_BITS ROUND_UP(OPENPIC_MAX_IRQ, 64)
60 typedef struct IRQQueue
{
62 int32_t queue_size
; /* Only used for VMSTATE_BITMAP */
67 typedef struct IRQSource
{
68 uint32_t ivpr
; /* IRQ vector/priority register */
69 uint32_t idr
; /* IRQ destination register */
70 uint32_t destmask
; /* bitmap of CPU destinations */
72 int output
; /* IRQ level, e.g. OPENPIC_OUTPUT_INT */
73 int pending
; /* TRUE if IRQ is pending */
75 bool level
:1; /* level-triggered */
76 bool nomask
:1; /* critical interrupts ignore mask on some FSL MPICs */
79 #define IVPR_MASK_SHIFT 31
80 #define IVPR_MASK_MASK (1U << IVPR_MASK_SHIFT)
81 #define IVPR_ACTIVITY_SHIFT 30
82 #define IVPR_ACTIVITY_MASK (1U << IVPR_ACTIVITY_SHIFT)
83 #define IVPR_MODE_SHIFT 29
84 #define IVPR_MODE_MASK (1U << IVPR_MODE_SHIFT)
85 #define IVPR_POLARITY_SHIFT 23
86 #define IVPR_POLARITY_MASK (1U << IVPR_POLARITY_SHIFT)
87 #define IVPR_SENSE_SHIFT 22
88 #define IVPR_SENSE_MASK (1U << IVPR_SENSE_SHIFT)
90 #define IVPR_PRIORITY_MASK (0xFU << 16)
91 #define IVPR_PRIORITY(_ivprr_) ((int)(((_ivprr_) & IVPR_PRIORITY_MASK) >> 16))
92 #define IVPR_VECTOR(opp, _ivprr_) ((_ivprr_) & (opp)->vector_mask)
94 /* IDR[EP/CI] are only for FSL MPIC prior to v4.0 */
95 #define IDR_EP 0x80000000 /* external pin */
96 #define IDR_CI 0x40000000 /* critical interrupt */
98 typedef struct OpenPICTimer
{
99 uint32_t tccr
; /* Global timer current count register */
100 uint32_t tbcr
; /* Global timer base count register */
102 bool qemu_timer_active
; /* Is the qemu_timer is running? */
103 struct QEMUTimer
*qemu_timer
;
104 struct OpenPICState
*opp
; /* Device timer is part of. */
106 * The QEMU_CLOCK_VIRTUAL time (in ns) corresponding to the last
107 * current_count written or read, only defined if qemu_timer_active.
109 uint64_t origin_time
;
112 typedef struct OpenPICMSI
{
113 uint32_t msir
; /* Shared Message Signaled Interrupt Register */
116 typedef struct IRQDest
{
117 int32_t ctpr
; /* CPU current task priority */
122 /* Count of IRQ sources asserting on non-INT outputs */
123 uint32_t outputs_active
[OPENPIC_OUTPUT_NB
];
126 #define TYPE_OPENPIC "openpic"
127 OBJECT_DECLARE_SIMPLE_TYPE(OpenPICState
, OPENPIC
)
129 struct OpenPICState
{
131 SysBusDevice parent_obj
;
136 /* Behavior control */
142 uint32_t vir
; /* Vendor identification register */
143 uint32_t vector_mask
;
148 uint32_t mpic_mode_mask
;
151 MemoryRegion sub_io_mem
[6];
153 /* Global registers */
154 uint32_t frr
; /* Feature reporting register */
155 uint32_t gcr
; /* Global configuration register */
156 uint32_t pir
; /* Processor initialization register */
157 uint32_t spve
; /* Spurious vector register */
158 uint32_t tfrr
; /* Timer frequency reporting register */
159 /* Source registers */
160 IRQSource src
[OPENPIC_MAX_IRQ
];
161 /* Local registers per output pin */
162 IRQDest dst
[MAX_CPU
];
164 /* Timer registers */
165 OpenPICTimer timers
[OPENPIC_MAX_TMR
];
168 /* Shared MSI registers */
169 OpenPICMSI msi
[MAX_MSI
];
176 #endif /* OPENPIC_H */