@@ -192,10 +192,17 @@ static void config_pirq(struct rt_pic *pic, struct rt_pic_irq *pirq, int irq, in
192
192
int rt_pic_config_ipi (struct rt_pic * pic , int ipi_index , int hwirq )
193
193
{
194
194
int ipi = ipi_index ;
195
+ struct rt_pic_irq * pirq ;
195
196
196
197
if (pic && ipi < RT_ARRAY_SIZE (_ipi_hash ) && hwirq >= 0 && pic -> ops -> irq_send_ipi )
197
198
{
198
- config_pirq (pic , & _pirq_hash [ipi ], ipi , hwirq );
199
+ pirq = & _pirq_hash [ipi ];
200
+ config_pirq (pic , pirq , ipi , hwirq );
201
+
202
+ for (int cpuid = 0 ; cpuid < RT_CPUS_NR ; ++ cpuid )
203
+ {
204
+ bitmap_set_bit (pirq -> affinity , cpuid );
205
+ }
199
206
200
207
LOG_D ("%s config %s %d to hwirq %d" , pic -> ops -> name , "ipi" , ipi , hwirq );
201
208
}
@@ -404,7 +411,7 @@ rt_err_t rt_pic_detach_irq(int irq, void *uid)
404
411
}
405
412
else
406
413
{
407
- struct rt_pic_isr * next_isr = rt_list_entry ( isr -> list . next , struct rt_pic_isr , list );
414
+ struct rt_pic_isr * next_isr = rt_list_first_entry ( & isr -> list , struct rt_pic_isr , list );
408
415
409
416
rt_list_remove (& next_isr -> list );
410
417
@@ -518,9 +525,6 @@ rt_err_t rt_pic_handle_isr(struct rt_pic_irq *pirq)
518
525
pirq -> stat .current_irq_begin [rt_hw_cpu_id ()] = ts .tv_sec * (1000UL * 1000 * 1000 ) + ts .tv_nsec ;
519
526
#endif
520
527
521
- /* Corrected irq affinity */
522
- rt_bitmap_set_bit (pirq -> affinity , rt_hw_cpu_id ());
523
-
524
528
handler_nodes = & pirq -> isr .list ;
525
529
action = & pirq -> isr .action ;
526
530
@@ -593,6 +597,48 @@ rt_weak rt_err_t rt_pic_user_extends(struct rt_pic *pic)
593
597
return - RT_ENOSYS ;
594
598
}
595
599
600
+ static void pic_fixup_runner (void * param )
601
+ {
602
+ /* Fixup system PIC setting */
603
+ struct rt_pic_irq * pirq , * pirq_end ;
604
+
605
+ pirq = & _pirq_hash [RT_ARRAY_SIZE (_ipi_hash )];
606
+ pirq_end = & _pirq_hash [RT_ARRAY_SIZE (_pirq_hash )];
607
+
608
+ for (; pirq < pirq_end ; ++ pirq )
609
+ {
610
+ if (!pirq -> pic )
611
+ {
612
+ continue ;
613
+ }
614
+
615
+ /* Only fixup who no bind to CPU#0 */
616
+ if (!bitmap_test_bit (pirq -> affinity , 0 ) &&
617
+ pirq -> pic -> ops -> flags & RT_PIC_F_AFFINITY_POST )
618
+ {
619
+ rt_pic_irq_set_affinity (pirq -> irq , pirq -> affinity );
620
+ }
621
+ }
622
+ }
623
+
624
+ static int pic_fixup_prepare (void )
625
+ {
626
+ rt_thread_t tid ;
627
+
628
+ /*
629
+ * We assume that the SMP startup has been confirmed (system is working)
630
+ * to be complete after the "main" thread finishes.
631
+ */
632
+ tid = rt_thread_create ("pic" , pic_fixup_runner , RT_NULL ,
633
+ RT_MAIN_THREAD_STACK_SIZE , RT_MAIN_THREAD_PRIORITY + 1 , 20 );
634
+ RT_ASSERT (tid != RT_NULL );
635
+
636
+ rt_thread_startup (tid );
637
+
638
+ return 0 ;
639
+ }
640
+ INIT_PREV_EXPORT (pic_fixup_prepare );
641
+
596
642
rt_err_t rt_pic_irq_init (void )
597
643
{
598
644
rt_err_t err = RT_EOK ;
0 commit comments