xref: /openbmc/qemu/include/hw/ppc/openpic.h (revision a68694cd)
1 #ifndef OPENPIC_H
2 #define OPENPIC_H
3 
4 #include "hw/sysbus.h"
5 #include "hw/core/cpu.h"
6 #include "qom/object.h"
7 
8 #define MAX_CPU     32
9 #define MAX_MSI     8
10 #define VID         0x03 /* MPIC version ID */
11 
12 /* OpenPIC have 5 outputs per CPU connected and one IRQ out single output */
13 enum {
14     OPENPIC_OUTPUT_INT = 0, /* IRQ                       */
15     OPENPIC_OUTPUT_CINT,    /* critical IRQ              */
16     OPENPIC_OUTPUT_MCK,     /* Machine check event       */
17     OPENPIC_OUTPUT_DEBUG,   /* Inconditional debug event */
18     OPENPIC_OUTPUT_RESET,   /* Core reset event          */
19     OPENPIC_OUTPUT_NB,
20 };
21 
22 typedef struct IrqLines { qemu_irq irq[OPENPIC_OUTPUT_NB]; } IrqLines;
23 
24 #define OPENPIC_MODEL_RAVEN       0
25 #define OPENPIC_MODEL_FSL_MPIC_20 1
26 #define OPENPIC_MODEL_FSL_MPIC_42 2
27 #define OPENPIC_MODEL_KEYLARGO    3
28 
29 #define OPENPIC_MAX_SRC     256
30 #define OPENPIC_MAX_TMR     4
31 #define OPENPIC_MAX_IPI     4
32 #define OPENPIC_MAX_IRQ     (OPENPIC_MAX_SRC + OPENPIC_MAX_IPI + \
33                              OPENPIC_MAX_TMR)
34 
35 /* Raven */
36 #define RAVEN_MAX_CPU      2
37 #define RAVEN_MAX_EXT     48
38 #define RAVEN_MAX_IRQ     64
39 #define RAVEN_MAX_TMR      OPENPIC_MAX_TMR
40 #define RAVEN_MAX_IPI      OPENPIC_MAX_IPI
41 
42 /* KeyLargo */
43 #define KEYLARGO_MAX_CPU  4
44 #define KEYLARGO_MAX_EXT  64
45 #define KEYLARGO_MAX_IPI  4
46 #define KEYLARGO_MAX_IRQ  (64 + KEYLARGO_MAX_IPI)
47 #define KEYLARGO_MAX_TMR  0
48 #define KEYLARGO_IPI_IRQ  (KEYLARGO_MAX_EXT) /* First IPI IRQ */
49 /* Timers don't exist but this makes the code happy... */
50 #define KEYLARGO_TMR_IRQ  (KEYLARGO_IPI_IRQ + KEYLARGO_MAX_IPI)
51 
52 /* Interrupt definitions */
53 #define RAVEN_FE_IRQ     (RAVEN_MAX_EXT)     /* Internal functional IRQ */
54 #define RAVEN_ERR_IRQ    (RAVEN_MAX_EXT + 1) /* Error IRQ */
55 #define RAVEN_TMR_IRQ    (RAVEN_MAX_EXT + 2) /* First timer IRQ */
56 #define RAVEN_IPI_IRQ    (RAVEN_TMR_IRQ + RAVEN_MAX_TMR) /* First IPI IRQ */
57 /* First doorbell IRQ */
58 #define RAVEN_DBL_IRQ    (RAVEN_IPI_IRQ + (RAVEN_MAX_CPU * RAVEN_MAX_IPI))
59 
60 typedef struct FslMpicInfo {
61     int max_ext;
62 } FslMpicInfo;
63 
64 typedef enum IRQType {
65     IRQ_TYPE_NORMAL = 0,
66     IRQ_TYPE_FSLINT,        /* FSL internal interrupt -- level only */
67     IRQ_TYPE_FSLSPECIAL,    /* FSL timer/IPI interrupt, edge, no polarity */
68 } IRQType;
69 
70 /* Round up to the nearest 64 IRQs so that the queue length
71  * won't change when moving between 32 and 64 bit hosts.
72  */
73 #define IRQQUEUE_SIZE_BITS ((OPENPIC_MAX_IRQ + 63) & ~63)
74 
75 typedef struct IRQQueue {
76     unsigned long *queue;
77     int32_t queue_size; /* Only used for VMSTATE_BITMAP */
78     int next;
79     int priority;
80 } IRQQueue;
81 
82 typedef struct IRQSource {
83     uint32_t ivpr;  /* IRQ vector/priority register */
84     uint32_t idr;   /* IRQ destination register */
85     uint32_t destmask; /* bitmap of CPU destinations */
86     int last_cpu;
87     int output;     /* IRQ level, e.g. OPENPIC_OUTPUT_INT */
88     int pending;    /* TRUE if IRQ is pending */
89     IRQType type;
90     bool level:1;   /* level-triggered */
91     bool nomask:1;  /* critical interrupts ignore mask on some FSL MPICs */
92 } IRQSource;
93 
94 #define IVPR_MASK_SHIFT       31
95 #define IVPR_MASK_MASK        (1U << IVPR_MASK_SHIFT)
96 #define IVPR_ACTIVITY_SHIFT   30
97 #define IVPR_ACTIVITY_MASK    (1U << IVPR_ACTIVITY_SHIFT)
98 #define IVPR_MODE_SHIFT       29
99 #define IVPR_MODE_MASK        (1U << IVPR_MODE_SHIFT)
100 #define IVPR_POLARITY_SHIFT   23
101 #define IVPR_POLARITY_MASK    (1U << IVPR_POLARITY_SHIFT)
102 #define IVPR_SENSE_SHIFT      22
103 #define IVPR_SENSE_MASK       (1U << IVPR_SENSE_SHIFT)
104 
105 #define IVPR_PRIORITY_MASK     (0xFU << 16)
106 #define IVPR_PRIORITY(_ivprr_) ((int)(((_ivprr_) & IVPR_PRIORITY_MASK) >> 16))
107 #define IVPR_VECTOR(opp, _ivprr_) ((_ivprr_) & (opp)->vector_mask)
108 
109 /* IDR[EP/CI] are only for FSL MPIC prior to v4.0 */
110 #define IDR_EP      0x80000000  /* external pin */
111 #define IDR_CI      0x40000000  /* critical interrupt */
112 
113 typedef struct OpenPICTimer {
114     uint32_t tccr;  /* Global timer current count register */
115     uint32_t tbcr;  /* Global timer base count register */
116     int                   n_IRQ;
117     bool                  qemu_timer_active; /* Is the qemu_timer is running? */
118     struct QEMUTimer     *qemu_timer;
119     struct OpenPICState  *opp;          /* Device timer is part of. */
120     /* The QEMU_CLOCK_VIRTUAL time (in ns) corresponding to the last
121        current_count written or read, only defined if qemu_timer_active. */
122     uint64_t              origin_time;
123 } OpenPICTimer;
124 
125 typedef struct OpenPICMSI {
126     uint32_t msir;   /* Shared Message Signaled Interrupt Register */
127 } OpenPICMSI;
128 
129 typedef struct IRQDest {
130     int32_t ctpr; /* CPU current task priority */
131     IRQQueue raised;
132     IRQQueue servicing;
133     qemu_irq *irqs;
134 
135     /* Count of IRQ sources asserting on non-INT outputs */
136     uint32_t outputs_active[OPENPIC_OUTPUT_NB];
137 } IRQDest;
138 
139 #define TYPE_OPENPIC "openpic"
140 typedef struct OpenPICState OpenPICState;
141 DECLARE_INSTANCE_CHECKER(OpenPICState, OPENPIC,
142                          TYPE_OPENPIC)
143 
144 struct OpenPICState {
145     /*< private >*/
146     SysBusDevice parent_obj;
147     /*< public >*/
148 
149     MemoryRegion mem;
150 
151     /* Behavior control */
152     FslMpicInfo *fsl;
153     uint32_t model;
154     uint32_t flags;
155     uint32_t nb_irqs;
156     uint32_t vid;
157     uint32_t vir; /* Vendor identification register */
158     uint32_t vector_mask;
159     uint32_t tfrr_reset;
160     uint32_t ivpr_reset;
161     uint32_t idr_reset;
162     uint32_t brr1;
163     uint32_t mpic_mode_mask;
164 
165     /* Sub-regions */
166     MemoryRegion sub_io_mem[6];
167 
168     /* Global registers */
169     uint32_t frr; /* Feature reporting register */
170     uint32_t gcr; /* Global configuration register  */
171     uint32_t pir; /* Processor initialization register */
172     uint32_t spve; /* Spurious vector register */
173     uint32_t tfrr; /* Timer frequency reporting register */
174     /* Source registers */
175     IRQSource src[OPENPIC_MAX_IRQ];
176     /* Local registers per output pin */
177     IRQDest dst[MAX_CPU];
178     uint32_t nb_cpus;
179     /* Timer registers */
180     OpenPICTimer timers[OPENPIC_MAX_TMR];
181     uint32_t max_tmr;
182 
183     /* Shared MSI registers */
184     OpenPICMSI msi[MAX_MSI];
185     uint32_t max_irq;
186     uint32_t irq_ipi0;
187     uint32_t irq_tim0;
188     uint32_t irq_msi;
189 };
190 
191 #endif /* OPENPIC_H */
192