@@ -151,31 +151,12 @@ static void disable_pic_irq(void)
151
151
pio_write8 (0xffU , 0x21U );
152
152
}
153
153
154
- static void
155
- irq_desc_append_dev (struct irq_desc * desc , void * node )
156
- {
157
- spinlock_rflags ;
158
-
159
- spinlock_irqsave_obtain (& desc -> irq_lock );
160
-
161
- ASSERT (desc -> action == NULL , "irq already registered" );
162
- /* assign if first node */
163
- desc -> action = node ;
164
- desc -> used = IRQ_ASSIGNED ;
165
- if (desc -> irq_handler == NULL ) {
166
- desc -> irq_handler = common_handler_edge ;
167
- }
168
-
169
- spinlock_irqrestore_release (& desc -> irq_lock );
170
- }
171
-
172
- static struct dev_handler_node *
173
- common_register_handler (uint32_t irq_arg ,
154
+ static int32_t common_register_handler (uint32_t irq_arg ,
174
155
struct irq_request_info * info )
175
156
{
176
- struct dev_handler_node * node = NULL ;
177
157
struct irq_desc * desc ;
178
158
uint32_t irq = irq_arg ;
159
+ spinlock_rflags ;
179
160
180
161
/* ======================================================
181
162
* This is low level ISR handler registering function
@@ -217,43 +198,48 @@ common_register_handler(uint32_t irq_arg,
217
198
218
199
if (irq >= NR_IRQS ) {
219
200
pr_err ("failed to assign IRQ" );
220
- goto OUT ;
221
- }
222
-
223
- node = calloc (1U , sizeof (struct dev_handler_node ));
224
- if (node == NULL ) {
225
- pr_err ("failed to alloc node" );
226
- irq_desc_try_free_vector (irq );
227
- goto OUT ;
201
+ return - EINVAL ;
228
202
}
229
203
230
204
desc = & irq_desc_array [irq ];
231
- irq_desc_append_dev (desc , node );
205
+ if (desc -> irq_handler == NULL ) {
206
+ desc -> irq_handler = common_handler_edge ;
207
+ }
232
208
233
209
if (info -> vector >= VECTOR_FIXED_START &&
234
210
info -> vector <= VECTOR_FIXED_END ) {
235
211
irq_desc_set_vector (irq , info -> vector );
236
212
} else if (info -> vector > NR_MAX_VECTOR ) {
237
213
irq_desc_alloc_vector (irq );
238
- } else {
214
+ }
215
+
216
+ if (desc -> vector == VECTOR_INVALID ) {
239
217
pr_err ("the input vector is not correct" );
240
- free ( node );
241
- return NULL ;
218
+ /* FIXME: free allocated irq */
219
+ return - EINVAL ;
242
220
}
243
221
244
- node -> dev_handler = info -> func ;
245
- node -> dev_data = info -> dev_data ;
246
- node -> desc = desc ;
247
- /* we are okay using strcpy_s here even with spinlock
248
- * since no #PG in HV right now
249
- */
250
- (void )strcpy_s (node -> name , 32U , info -> name );
222
+ if (desc -> action == NULL ) {
223
+ spinlock_irqsave_obtain (& desc -> irq_lock );
224
+ desc -> priv_data = info -> priv_data ;
225
+ desc -> action = info -> func ;
251
226
252
- dev_dbg (ACRN_DBG_IRQ , "[%s] %s irq%d vr:0x%x" ,
253
- __func__ , node -> name , irq , desc -> vector );
227
+ /* we are okay using strcpy_s here even with spinlock
228
+ * since no #PG in HV right now
229
+ */
230
+ (void )strcpy_s (desc -> name , 32U , info -> name );
254
231
255
- OUT :
256
- return node ;
232
+ spinlock_irqrestore_release (& desc -> irq_lock );
233
+ } else {
234
+ pr_err ("%s: request irq(%u) vr(%u) for %s failed,\
235
+ already requested" , __func__ ,
236
+ irq , irq_to_vector (irq ), info -> name );
237
+ return - EBUSY ;
238
+ }
239
+
240
+ dev_dbg (ACRN_DBG_IRQ , "[%s] %s irq%d vr:0x%x" ,
241
+ __func__ , info -> name , irq , desc -> vector );
242
+ return (int32_t )irq ;
257
243
}
258
244
259
245
/* it is safe to call irq_desc_alloc_vector multiple times*/
@@ -318,16 +304,6 @@ uint32_t irq_to_vector(uint32_t irq)
318
304
}
319
305
}
320
306
321
- uint32_t dev_to_irq (struct dev_handler_node * node )
322
- {
323
- return node -> desc -> irq ;
324
- }
325
-
326
- uint32_t dev_to_vector (struct dev_handler_node * node )
327
- {
328
- return node -> desc -> vector ;
329
- }
330
-
331
307
void init_default_irqs (uint16_t cpu_id )
332
308
{
333
309
if (cpu_id != BOOT_CPU_ID ) {
@@ -395,7 +371,7 @@ void dispatch_interrupt(struct intr_excp_ctx *ctx)
395
371
goto ERR ;
396
372
}
397
373
398
- desc -> irq_handler (desc , desc -> handler_data );
374
+ desc -> irq_handler (desc , NULL );
399
375
return ;
400
376
ERR :
401
377
handle_spurious_interrupt (vr );
@@ -427,7 +403,7 @@ void partition_mode_dispatch_interrupt(struct intr_excp_ctx *ctx)
427
403
int handle_level_interrupt_common (struct irq_desc * desc ,
428
404
__unused void * handler_data )
429
405
{
430
- struct dev_handler_node * action = desc -> action ;
406
+ irq_action_t action = desc -> action ;
431
407
spinlock_rflags ;
432
408
433
409
/*
@@ -451,9 +427,9 @@ int handle_level_interrupt_common(struct irq_desc *desc,
451
427
/* Send EOI to LAPIC/IOAPIC IRR */
452
428
send_lapic_eoi ();
453
429
454
- if (action != NULL && action -> dev_handler != NULL ) {
455
- action -> dev_handler (desc -> irq , action -> dev_data );
456
- }
430
+ if (action != NULL ) {
431
+ action (desc -> irq , desc -> priv_data );
432
+ }
457
433
458
434
if (irq_is_gsi (desc -> irq )) {
459
435
GSI_UNMASK_IRQ (desc -> irq );
@@ -467,7 +443,7 @@ int handle_level_interrupt_common(struct irq_desc *desc,
467
443
468
444
int common_handler_edge (struct irq_desc * desc , __unused void * handler_data )
469
445
{
470
- struct dev_handler_node * action = desc -> action ;
446
+ irq_action_t action = desc -> action ;
471
447
spinlock_rflags ;
472
448
473
449
/*
@@ -486,8 +462,8 @@ int common_handler_edge(struct irq_desc *desc, __unused void *handler_data)
486
462
/* Send EOI to LAPIC/IOAPIC IRR */
487
463
send_lapic_eoi ();
488
464
489
- if (action != NULL && action -> dev_handler != NULL ) {
490
- action -> dev_handler (desc -> irq , action -> dev_data );
465
+ if (action != NULL ) {
466
+ action (desc -> irq , desc -> priv_data );
491
467
}
492
468
493
469
desc -> state = IRQ_DESC_PENDING ;
@@ -498,7 +474,7 @@ int common_handler_edge(struct irq_desc *desc, __unused void *handler_data)
498
474
499
475
int common_dev_handler_level (struct irq_desc * desc , __unused void * handler_data )
500
476
{
501
- struct dev_handler_node * action = desc -> action ;
477
+ irq_action_t action = desc -> action ;
502
478
spinlock_rflags ;
503
479
504
480
/*
@@ -522,8 +498,8 @@ int common_dev_handler_level(struct irq_desc *desc, __unused void *handler_data)
522
498
/* Send EOI to LAPIC/IOAPIC IRR */
523
499
send_lapic_eoi ();
524
500
525
- if (action != NULL && action -> dev_handler != NULL ) {
526
- action -> dev_handler (desc -> irq , action -> dev_data );
501
+ if (action != NULL ) {
502
+ action (desc -> irq , desc -> priv_data );
527
503
}
528
504
529
505
desc -> state = IRQ_DESC_PENDING ;
@@ -536,13 +512,13 @@ int common_dev_handler_level(struct irq_desc *desc, __unused void *handler_data)
536
512
/* no desc->irq_lock for quick handling local interrupt like lapic timer */
537
513
int quick_handler_nolock (struct irq_desc * desc , __unused void * handler_data )
538
514
{
539
- struct dev_handler_node * action = desc -> action ;
515
+ irq_action_t action = desc -> action ;
540
516
541
517
/* Send EOI to LAPIC/IOAPIC IRR */
542
518
send_lapic_eoi ();
543
519
544
- if (action != NULL && action -> dev_handler != NULL ) {
545
- action -> dev_handler (desc -> irq , action -> dev_data );
520
+ if (action != NULL ) {
521
+ action (desc -> irq , desc -> priv_data );
546
522
}
547
523
548
524
return 0 ;
@@ -564,45 +540,43 @@ void update_irq_handler(uint32_t irq, irq_handler_t func)
564
540
spinlock_irqrestore_release (& desc -> irq_lock );
565
541
}
566
542
567
- void unregister_handler_common (struct dev_handler_node * node )
543
+ void unregister_handler_common (uint32_t irq )
568
544
{
569
545
struct irq_desc * desc ;
570
546
571
547
spinlock_rflags ;
572
548
573
- if (node == NULL ) {
549
+ if (irq >= NR_IRQS ) {
574
550
return ;
575
551
}
576
552
553
+ desc = & irq_desc_array [irq ];
577
554
dev_dbg (ACRN_DBG_IRQ , "[%s] %s irq%d vr:0x%x" ,
578
- __func__ , node -> name ,
579
- dev_to_irq (node ),
580
- dev_to_vector (node ));
555
+ __func__ , desc -> name , irq , irq_to_vector (irq ));
581
556
582
- desc = node -> desc ;
583
557
spinlock_irqsave_obtain (& desc -> irq_lock );
584
558
585
559
desc -> action = NULL ;
560
+ desc -> priv_data = NULL ;
561
+ memset (desc -> name , '\0' , 32U );
586
562
587
563
spinlock_irqrestore_release (& desc -> irq_lock );
588
564
irq_desc_try_free_vector (desc -> irq );
589
- free (node );
590
565
}
591
566
592
567
/*
593
568
* Allocate IRQ with Vector from VECTOR_DYNAMIC_START ~ VECTOR_DYNAMIC_END
594
569
*/
595
- struct dev_handler_node *
596
- normal_register_handler (uint32_t irq ,
597
- dev_handler_t func ,
598
- void * dev_data ,
570
+ int32_t normal_register_handler (uint32_t irq ,
571
+ irq_action_t func ,
572
+ void * priv_data ,
599
573
const char * name )
600
574
{
601
575
struct irq_request_info info ;
602
576
603
577
info .vector = VECTOR_INVALID ;
604
578
info .func = func ;
605
- info .dev_data = dev_data ;
579
+ info .priv_data = priv_data ;
606
580
info .name = (char * )name ;
607
581
608
582
return common_register_handler (irq , & info );
@@ -614,22 +588,21 @@ normal_register_handler(uint32_t irq,
614
588
* User can install same irq/isr on different CPU by call this function multiple
615
589
* times
616
590
*/
617
- struct dev_handler_node *
618
- pri_register_handler (uint32_t irq ,
591
+ int32_t pri_register_handler (uint32_t irq ,
619
592
uint32_t vector ,
620
- dev_handler_t func ,
621
- void * dev_data ,
593
+ irq_action_t func ,
594
+ void * priv_data ,
622
595
const char * name )
623
596
{
624
597
struct irq_request_info info ;
625
598
626
599
if (vector < VECTOR_FIXED_START || vector > VECTOR_FIXED_END ) {
627
- return NULL ;
600
+ return - EINVAL ;
628
601
}
629
602
630
603
info .vector = vector ;
631
604
info .func = func ;
632
- info .dev_data = dev_data ;
605
+ info .priv_data = priv_data ;
633
606
info .name = (char * )name ;
634
607
635
608
return common_register_handler (irq , & info );
0 commit comments