67
67
DEVICE_MMIO_TOPLEVEL_STATIC (ioapic_regs , DT_DRV_INST (0 ));
68
68
69
69
#define IOAPIC_REG DEVICE_MMIO_TOPLEVEL_GET(ioapic_regs)
70
- #define BITS_PER_IRQ 4
71
- #define IOAPIC_BITFIELD_HI_LO 0
72
- #define IOAPIC_BITFIELD_LVL_EDGE 1
73
- #define IOAPIC_BITFIELD_ENBL_DSBL 2
74
- #define IOAPIC_BITFIELD_DELIV_MODE 3
75
- #define BIT_POS_FOR_IRQ_OPTION (irq , option ) ((irq) * BITS_PER_IRQ + (option))
76
- #define SUSPEND_BITS_REQD (ROUND_UP((CONFIG_IOAPIC_NUM_RTES * BITS_PER_IRQ), 32))
77
70
78
71
/*
79
72
* Destination field (bits[56:63]) defines a set of processors, which is
@@ -92,10 +85,27 @@ DEVICE_MMIO_TOPLEVEL_STATIC(ioapic_regs, DT_DRV_INST(0));
92
85
*/
93
86
#define DEFAULT_RTE_DEST (0xFF << 24)
94
87
88
+ static uint32_t ioapic_rtes ;
89
+
95
90
#ifdef CONFIG_PM_DEVICE
96
91
#include <power/power.h>
92
+
93
+ #define BITS_PER_IRQ 4
94
+ #define IOAPIC_BITFIELD_HI_LO 0
95
+ #define IOAPIC_BITFIELD_LVL_EDGE 1
96
+ #define IOAPIC_BITFIELD_ENBL_DSBL 2
97
+ #define IOAPIC_BITFIELD_DELIV_MODE 3
98
+
99
+ #define BIT_POS_FOR_IRQ_OPTION (irq , option ) ((irq) * BITS_PER_IRQ + (option))
100
+
101
+ /* Allocating up to 256 irq bits bufffer for RTEs, RTEs are dynamically found
102
+ * so let's just assume the maximum, it's only 128 bytes in total.
103
+ */
104
+ #define SUSPEND_BITS_REQD (ROUND_UP((256 * BITS_PER_IRQ), 32))
105
+
97
106
uint32_t ioapic_suspend_buf [SUSPEND_BITS_REQD / 32 ] = {0 };
98
107
static uint32_t ioapic_device_power_state = DEVICE_PM_ACTIVE_STATE ;
108
+
99
109
#endif
100
110
101
111
static uint32_t __IoApicGet (int32_t offset );
@@ -126,30 +136,30 @@ int ioapic_init(const struct device *unused)
126
136
127
137
DEVICE_MMIO_TOPLEVEL_MAP (ioapic_regs , K_MEM_CACHE_NONE );
128
138
139
+ /* Reading MRE: this will give the number of RTEs available */
140
+ ioapic_rtes = ((__IoApicGet (IOAPIC_VERS ) &
141
+ IOAPIC_MRE_MASK ) >> IOAPIC_MRE_POS ) + 1 ;
142
+
129
143
#ifdef CONFIG_IOAPIC_MASK_RTE
130
144
int32_t ix ; /* redirection table index */
131
145
uint32_t rteValue ; /* value to copy into redirection table entry */
132
146
133
- /*
134
- * The platform must set the Kconfig option IOAPIC_NUM_RTES to indicate
135
- * the number of redirection table entries supported by the IOAPIC.
136
- *
137
- * Note: The number of actual IRQs supported by the IOAPIC can be
138
- * determined at runtime by computing:
139
- *
140
- * ((__IoApicGet(IOAPIC_VERS) & IOAPIC_MRE_MASK) >> 16) + 1
141
- */
142
147
rteValue = IOAPIC_EDGE | IOAPIC_HIGH | IOAPIC_FIXED | IOAPIC_INT_MASK |
143
148
IOAPIC_LOGICAL | 0 /* dummy vector */ ;
144
149
145
- for (ix = 0 ; ix < CONFIG_IOAPIC_NUM_RTES ; ix ++ ) {
150
+ for (ix = 0 ; ix < ioapic_rtes ; ix ++ ) {
146
151
ioApicRedSetHi (ix , DEFAULT_RTE_DEST );
147
152
ioApicRedSetLo (ix , rteValue );
148
153
}
149
154
#endif
150
155
return 0 ;
151
156
}
152
157
158
+ uint32_t z_ioapic_num_rtes (void )
159
+ {
160
+ return ioapic_rtes ;
161
+ }
162
+
153
163
/**
154
164
*
155
165
* @brief Enable a specified APIC interrupt input line
@@ -244,7 +254,7 @@ int ioapic_suspend(const struct device *port)
244
254
245
255
ARG_UNUSED (port );
246
256
(void )memset (ioapic_suspend_buf , 0 , (SUSPEND_BITS_REQD >> 3 ));
247
- for (irq = 0 ; irq < CONFIG_IOAPIC_NUM_RTES ; irq ++ ) {
257
+ for (irq = 0 ; irq < ioapic_rtes ; irq ++ ) {
248
258
/*
249
259
* The following check is to figure out the registered
250
260
* IRQ lines, so as to limit ourselves to saving the
@@ -267,7 +277,7 @@ int ioapic_resume_from_suspend(const struct device *port)
267
277
268
278
ARG_UNUSED (port );
269
279
270
- for (irq = 0 ; irq < CONFIG_IOAPIC_NUM_RTES ; irq ++ ) {
280
+ for (irq = 0 ; irq < ioapic_rtes ; irq ++ ) {
271
281
if (_irq_to_interrupt_vector [irq ]) {
272
282
/* Get the saved flags */
273
283
flags = restore_flags (irq );
0 commit comments