xref: /openbmc/qemu/include/hw/ppc/openpic.h (revision 86229b68a28a8414797dd5548f3c5284f009fb53)
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_FSL_MPIC_20 1
25 #define OPENPIC_MODEL_FSL_MPIC_42 2
26 #define OPENPIC_MODEL_KEYLARGO    3
27 
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 + \
32                              OPENPIC_MAX_TMR)
33 
34 /* KeyLargo */
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)
43 
44 typedef struct FslMpicInfo {
45     int max_ext;
46 } FslMpicInfo;
47 
48 typedef enum IRQType {
49     IRQ_TYPE_NORMAL = 0,
50     IRQ_TYPE_FSLINT,        /* FSL internal interrupt -- level only */
51     IRQ_TYPE_FSLSPECIAL,    /* FSL timer/IPI interrupt, edge, no polarity */
52 } IRQType;
53 
54 /* Round up to the nearest 64 IRQs so that the queue length
55  * won't change when moving between 32 and 64 bit hosts.
56  */
57 #define IRQQUEUE_SIZE_BITS ((OPENPIC_MAX_IRQ + 63) & ~63)
58 
59 typedef struct IRQQueue {
60     unsigned long *queue;
61     int32_t queue_size; /* Only used for VMSTATE_BITMAP */
62     int next;
63     int priority;
64 } IRQQueue;
65 
66 typedef struct IRQSource {
67     uint32_t ivpr;  /* IRQ vector/priority register */
68     uint32_t idr;   /* IRQ destination register */
69     uint32_t destmask; /* bitmap of CPU destinations */
70     int last_cpu;
71     int output;     /* IRQ level, e.g. OPENPIC_OUTPUT_INT */
72     int pending;    /* TRUE if IRQ is pending */
73     IRQType type;
74     bool level:1;   /* level-triggered */
75     bool nomask:1;  /* critical interrupts ignore mask on some FSL MPICs */
76 } IRQSource;
77 
78 #define IVPR_MASK_SHIFT       31
79 #define IVPR_MASK_MASK        (1U << IVPR_MASK_SHIFT)
80 #define IVPR_ACTIVITY_SHIFT   30
81 #define IVPR_ACTIVITY_MASK    (1U << IVPR_ACTIVITY_SHIFT)
82 #define IVPR_MODE_SHIFT       29
83 #define IVPR_MODE_MASK        (1U << IVPR_MODE_SHIFT)
84 #define IVPR_POLARITY_SHIFT   23
85 #define IVPR_POLARITY_MASK    (1U << IVPR_POLARITY_SHIFT)
86 #define IVPR_SENSE_SHIFT      22
87 #define IVPR_SENSE_MASK       (1U << IVPR_SENSE_SHIFT)
88 
89 #define IVPR_PRIORITY_MASK     (0xFU << 16)
90 #define IVPR_PRIORITY(_ivprr_) ((int)(((_ivprr_) & IVPR_PRIORITY_MASK) >> 16))
91 #define IVPR_VECTOR(opp, _ivprr_) ((_ivprr_) & (opp)->vector_mask)
92 
93 /* IDR[EP/CI] are only for FSL MPIC prior to v4.0 */
94 #define IDR_EP      0x80000000  /* external pin */
95 #define IDR_CI      0x40000000  /* critical interrupt */
96 
97 typedef struct OpenPICTimer {
98     uint32_t tccr;  /* Global timer current count register */
99     uint32_t tbcr;  /* Global timer base count register */
100     int                   n_IRQ;
101     bool                  qemu_timer_active; /* Is the qemu_timer is running? */
102     struct QEMUTimer     *qemu_timer;
103     struct OpenPICState  *opp;          /* Device timer is part of. */
104     /* The QEMU_CLOCK_VIRTUAL time (in ns) corresponding to the last
105        current_count written or read, only defined if qemu_timer_active. */
106     uint64_t              origin_time;
107 } OpenPICTimer;
108 
109 typedef struct OpenPICMSI {
110     uint32_t msir;   /* Shared Message Signaled Interrupt Register */
111 } OpenPICMSI;
112 
113 typedef struct IRQDest {
114     int32_t ctpr; /* CPU current task priority */
115     IRQQueue raised;
116     IRQQueue servicing;
117     qemu_irq *irqs;
118 
119     /* Count of IRQ sources asserting on non-INT outputs */
120     uint32_t outputs_active[OPENPIC_OUTPUT_NB];
121 } IRQDest;
122 
123 #define TYPE_OPENPIC "openpic"
124 OBJECT_DECLARE_SIMPLE_TYPE(OpenPICState, OPENPIC)
125 
126 struct OpenPICState {
127     /*< private >*/
128     SysBusDevice parent_obj;
129     /*< public >*/
130 
131     MemoryRegion mem;
132 
133     /* Behavior control */
134     FslMpicInfo *fsl;
135     uint32_t model;
136     uint32_t flags;
137     uint32_t nb_irqs;
138     uint32_t vid;
139     uint32_t vir; /* Vendor identification register */
140     uint32_t vector_mask;
141     uint32_t tfrr_reset;
142     uint32_t ivpr_reset;
143     uint32_t idr_reset;
144     uint32_t brr1;
145     uint32_t mpic_mode_mask;
146 
147     /* Sub-regions */
148     MemoryRegion sub_io_mem[6];
149 
150     /* Global registers */
151     uint32_t frr; /* Feature reporting register */
152     uint32_t gcr; /* Global configuration register  */
153     uint32_t pir; /* Processor initialization register */
154     uint32_t spve; /* Spurious vector register */
155     uint32_t tfrr; /* Timer frequency reporting register */
156     /* Source registers */
157     IRQSource src[OPENPIC_MAX_IRQ];
158     /* Local registers per output pin */
159     IRQDest dst[MAX_CPU];
160     uint32_t nb_cpus;
161     /* Timer registers */
162     OpenPICTimer timers[OPENPIC_MAX_TMR];
163     uint32_t max_tmr;
164 
165     /* Shared MSI registers */
166     OpenPICMSI msi[MAX_MSI];
167     uint32_t max_irq;
168     uint32_t irq_ipi0;
169     uint32_t irq_tim0;
170     uint32_t irq_msi;
171 };
172 
173 #endif /* OPENPIC_H */
174