@@ -36,26 +36,28 @@ uint32_t alloc_irq_num(uint32_t req_irq)
36
36
{
37
37
uint32_t irq = req_irq ;
38
38
uint64_t rflags ;
39
+ uint32_t ret ;
39
40
40
41
if ((irq >= NR_IRQS ) && (irq != IRQ_INVALID )) {
41
42
pr_err ("[%s] invalid req_irq %u" , __func__ , req_irq );
42
- return IRQ_INVALID ;
43
- }
44
-
45
- spinlock_irqsave_obtain (& irq_alloc_spinlock , & rflags );
46
- if (irq == IRQ_INVALID ) {
47
- /* if no valid irq num given, find a free one */
48
- irq = (uint32_t )ffz64_ex (irq_alloc_bitmap , NR_IRQS );
49
- }
50
-
51
- if (irq >= NR_IRQS ) {
52
- irq = IRQ_INVALID ;
43
+ ret = IRQ_INVALID ;
53
44
} else {
54
- bitmap_set_nolock ((uint16_t )(irq & 0x3FU ),
55
- irq_alloc_bitmap + (irq >> 6U ));
45
+ spinlock_irqsave_obtain (& irq_alloc_spinlock , & rflags );
46
+ if (irq == IRQ_INVALID ) {
47
+ /* if no valid irq num given, find a free one */
48
+ irq = (uint32_t )ffz64_ex (irq_alloc_bitmap , NR_IRQS );
49
+ }
50
+
51
+ if (irq >= NR_IRQS ) {
52
+ irq = IRQ_INVALID ;
53
+ } else {
54
+ bitmap_set_nolock ((uint16_t )(irq & 0x3FU ),
55
+ irq_alloc_bitmap + (irq >> 6U ));
56
+ }
57
+ spinlock_irqrestore_release (& irq_alloc_spinlock , rflags );
58
+ ret = irq ;
56
59
}
57
- spinlock_irqrestore_release (& irq_alloc_spinlock , rflags );
58
- return irq ;
60
+ return ret ;
59
61
}
60
62
61
63
/*
@@ -66,15 +68,13 @@ void free_irq_num(uint32_t irq)
66
68
{
67
69
uint64_t rflags ;
68
70
69
- if (irq >= NR_IRQS ) {
70
- return ;
71
- }
72
-
73
- if (irq_is_gsi (irq ) == false) {
74
- spinlock_irqsave_obtain (& irq_alloc_spinlock , & rflags );
75
- (void )bitmap_test_and_clear_nolock ((uint16_t )(irq & 0x3FU ),
76
- irq_alloc_bitmap + (irq >> 6U ));
77
- spinlock_irqrestore_release (& irq_alloc_spinlock , rflags );
71
+ if (irq < NR_IRQS ) {
72
+ if (!irq_is_gsi (irq )) {
73
+ spinlock_irqsave_obtain (& irq_alloc_spinlock , & rflags );
74
+ (void )bitmap_test_and_clear_nolock ((uint16_t )(irq & 0x3FU ),
75
+ irq_alloc_bitmap + (irq >> 6U ));
76
+ spinlock_irqrestore_release (& irq_alloc_spinlock , rflags );
77
+ }
78
78
}
79
79
}
80
80
@@ -89,43 +89,44 @@ uint32_t alloc_irq_vector(uint32_t irq)
89
89
uint32_t vr ;
90
90
struct irq_desc * desc ;
91
91
uint64_t rflags ;
92
+ uint32_t ret ;
92
93
93
- if (irq >= NR_IRQS ) {
94
- pr_err ("invalid irq[%u] to alloc vector" , irq );
95
- return VECTOR_INVALID ;
96
- }
97
-
98
- desc = & irq_desc_array [irq ];
99
-
100
- if (desc -> vector != VECTOR_INVALID ) {
101
- if (vector_to_irq [desc -> vector ] == irq ) {
102
- /* statically binded */
103
- vr = desc -> vector ;
94
+ if (irq < NR_IRQS ) {
95
+ desc = & irq_desc_array [irq ];
96
+
97
+ if (desc -> vector != VECTOR_INVALID ) {
98
+ if (vector_to_irq [desc -> vector ] == irq ) {
99
+ /* statically binded */
100
+ vr = desc -> vector ;
101
+ } else {
102
+ pr_err ("[%s] irq[%u]:vector[%u] mismatch" ,
103
+ __func__ , irq , desc -> vector );
104
+ vr = VECTOR_INVALID ;
105
+ }
104
106
} else {
105
- pr_err ("[%s] irq[%u]:vector[%u] mismatch" ,
106
- __func__ , irq , desc -> vector );
107
- vr = VECTOR_INVALID ;
108
- }
109
- } else {
110
- /* alloc a vector between:
111
- * VECTOR_DYNAMIC_START ~ VECTOR_DYNAMC_END
112
- */
113
- spinlock_irqsave_obtain (& irq_alloc_spinlock , & rflags );
114
-
115
- for (vr = VECTOR_DYNAMIC_START ;
116
- vr <= VECTOR_DYNAMIC_END ; vr ++ ) {
117
- if (vector_to_irq [vr ] == IRQ_INVALID ) {
118
- desc -> vector = vr ;
119
- vector_to_irq [vr ] = irq ;
120
- break ;
107
+ /* alloc a vector between:
108
+ * VECTOR_DYNAMIC_START ~ VECTOR_DYNAMC_END
109
+ */
110
+ spinlock_irqsave_obtain (& irq_alloc_spinlock , & rflags );
111
+
112
+ for (vr = VECTOR_DYNAMIC_START ;
113
+ vr <= VECTOR_DYNAMIC_END ; vr ++ ) {
114
+ if (vector_to_irq [vr ] == IRQ_INVALID ) {
115
+ desc -> vector = vr ;
116
+ vector_to_irq [vr ] = irq ;
117
+ break ;
118
+ }
121
119
}
122
- }
123
- vr = (vr > VECTOR_DYNAMIC_END ) ? VECTOR_INVALID : vr ;
120
+ vr = (vr > VECTOR_DYNAMIC_END ) ? VECTOR_INVALID : vr ;
124
121
125
- spinlock_irqrestore_release (& irq_alloc_spinlock , rflags );
122
+ spinlock_irqrestore_release (& irq_alloc_spinlock , rflags );
123
+ }
124
+ ret = vr ;
125
+ } else {
126
+ pr_err ("invalid irq[%u] to alloc vector" , irq );
127
+ ret = VECTOR_INVALID ;
126
128
}
127
-
128
- return vr ;
129
+ return ret ;
129
130
}
130
131
131
132
/* free the vector allocated via alloc_irq_vector() */
@@ -226,50 +227,49 @@ void free_irq(uint32_t irq)
226
227
uint64_t rflags ;
227
228
struct irq_desc * desc ;
228
229
229
- if (irq >= NR_IRQS ) {
230
- return ;
231
- }
232
-
233
- desc = & irq_desc_array [irq ];
234
- dev_dbg (ACRN_DBG_IRQ , "[%s] irq%d vr:0x%x" ,
235
- __func__ , irq , irq_to_vector (irq ));
230
+ if (irq < NR_IRQS ) {
231
+ desc = & irq_desc_array [irq ];
232
+ dev_dbg (ACRN_DBG_IRQ , "[%s] irq%d vr:0x%x" ,
233
+ __func__ , irq , irq_to_vector (irq ));
236
234
237
- free_irq_vector (irq );
238
- free_irq_num (irq );
235
+ free_irq_vector (irq );
236
+ free_irq_num (irq );
239
237
240
- spinlock_irqsave_obtain (& desc -> lock , & rflags );
241
- desc -> action = NULL ;
242
- desc -> priv_data = NULL ;
243
- desc -> flags = IRQF_NONE ;
244
- spinlock_irqrestore_release (& desc -> lock , rflags );
238
+ spinlock_irqsave_obtain (& desc -> lock , & rflags );
239
+ desc -> action = NULL ;
240
+ desc -> priv_data = NULL ;
241
+ desc -> flags = IRQF_NONE ;
242
+ spinlock_irqrestore_release (& desc -> lock , rflags );
243
+ }
245
244
}
246
245
247
246
void set_irq_trigger_mode (uint32_t irq , bool is_level_triggered )
248
247
{
249
248
uint64_t rflags ;
250
249
struct irq_desc * desc ;
251
250
252
- if (irq >= NR_IRQS ) {
253
- return ;
254
- }
255
-
256
- desc = & irq_desc_array [irq ];
257
- spinlock_irqsave_obtain (& desc -> lock , & rflags );
258
- if (is_level_triggered == true) {
259
- desc -> flags |= IRQF_LEVEL ;
260
- } else {
261
- desc -> flags &= ~IRQF_LEVEL ;
251
+ if (irq < NR_IRQS ) {
252
+ desc = & irq_desc_array [irq ];
253
+ spinlock_irqsave_obtain (& desc -> lock , & rflags );
254
+ if (is_level_triggered == true) {
255
+ desc -> flags |= IRQF_LEVEL ;
256
+ } else {
257
+ desc -> flags &= ~IRQF_LEVEL ;
258
+ }
259
+ spinlock_irqrestore_release (& desc -> lock , rflags );
262
260
}
263
- spinlock_irqrestore_release (& desc -> lock , rflags );
264
261
}
265
262
266
263
uint32_t irq_to_vector (uint32_t irq )
267
264
{
265
+ uint32_t ret ;
268
266
if (irq < NR_IRQS ) {
269
- return irq_desc_array [irq ].vector ;
267
+ ret = irq_desc_array [irq ].vector ;
270
268
} else {
271
- return VECTOR_INVALID ;
269
+ ret = VECTOR_INVALID ;
272
270
}
271
+
272
+ return ret ;
273
273
}
274
274
275
275
static void handle_spurious_interrupt (uint32_t vector )
@@ -435,16 +435,14 @@ static void disable_pic_irqs(void)
435
435
436
436
void init_default_irqs (uint16_t cpu_id )
437
437
{
438
- if (cpu_id != BOOT_CPU_ID ) {
439
- return ;
440
- }
438
+ if (cpu_id == BOOT_CPU_ID ) {
439
+ init_irq_descs ();
441
440
442
- init_irq_descs ();
443
-
444
- /* we use ioapic only, disable legacy PIC */
445
- disable_pic_irqs ();
446
- setup_ioapic_irqs ();
447
- init_softirq ();
441
+ /* we use ioapic only, disable legacy PIC */
442
+ disable_pic_irqs ();
443
+ setup_ioapic_irqs ();
444
+ init_softirq ();
445
+ }
448
446
}
449
447
450
448
void interrupt_init (uint16_t pcpu_id )
0 commit comments