@@ -30,11 +30,12 @@ entry_id(struct ptdev_remapping_info *entry)
30
30
{
31
31
uint32_t id ;
32
32
33
- if (entry -> type == PTDEV_INTR_INTX )
33
+ if (entry -> type == PTDEV_INTR_INTX ) {
34
34
id = entry_id_from_intx (entry -> ptdev_intr_info .intx .phys_pin );
35
- else
35
+ } else {
36
36
id = entry_id_from_msix (entry -> phys_bdf ,
37
37
entry -> ptdev_intr_info .msi .msix_entry_index );
38
+ }
38
39
39
40
return id ;
40
41
}
@@ -61,8 +62,9 @@ _lookup_entry_by_id(uint32_t id)
61
62
list_for_each (pos , & ptdev_list ) {
62
63
entry = list_entry (pos , struct ptdev_remapping_info ,
63
64
entry_node );
64
- if (entry_id (entry ) == id )
65
+ if (entry_id (entry ) == id ) {
65
66
return entry ;
67
+ }
66
68
}
67
69
68
70
return NULL ;
@@ -82,8 +84,9 @@ _lookup_entry_by_vmsi(struct vm *vm, uint16_t vbdf, int32_t index)
82
84
&& (entry -> vm == vm )
83
85
&& (entry -> virt_bdf == vbdf )
84
86
&& (entry -> ptdev_intr_info .msi .msix_entry_index
85
- == index ))
87
+ == index )) {
86
88
return entry ;
89
+ }
87
90
}
88
91
89
92
return NULL ;
@@ -114,8 +117,9 @@ _lookup_entry_by_vintx(struct vm *vm, uint8_t vpin,
114
117
if ((entry -> type == PTDEV_INTR_INTX )
115
118
&& (entry -> vm == vm )
116
119
&& (entry -> ptdev_intr_info .intx .virt_pin == vpin )
117
- && (entry -> ptdev_intr_info .intx .vpin_src == vpin_src ))
120
+ && (entry -> ptdev_intr_info .intx .vpin_src == vpin_src )) {
118
121
return entry ;
122
+ }
119
123
}
120
124
121
125
return NULL ;
@@ -151,13 +155,15 @@ ptdev_update_irq_handler(struct vm *vm, struct ptdev_remapping_info *entry)
151
155
152
156
/* VPIN_IOAPIC src means we have vioapic enabled */
153
157
vioapic_get_rte (vm , entry -> ptdev_intr_info .intx .virt_pin , & rte );
154
- if ((rte & IOAPIC_RTE_TRGRMOD ) == IOAPIC_RTE_TRGRLVL )
158
+ if ((rte & IOAPIC_RTE_TRGRMOD ) == IOAPIC_RTE_TRGRLVL ) {
155
159
trigger_lvl = true;
160
+ }
156
161
157
- if (trigger_lvl )
162
+ if (trigger_lvl ) {
158
163
update_irq_handler (phys_irq , common_dev_handler_level );
159
- else
164
+ } else {
160
165
update_irq_handler (phys_irq , common_handler_edge );
166
+ }
161
167
}
162
168
/* update irq handler for PIC */
163
169
if ((entry -> type == PTDEV_INTR_INTX ) && (phys_irq < NR_LEGACY_IRQ )
@@ -167,20 +173,22 @@ ptdev_update_irq_handler(struct vm *vm, struct ptdev_remapping_info *entry)
167
173
/* VPIN_PIC src means we have vpic enabled */
168
174
vpic_get_irq_trigger (vm ,
169
175
entry -> ptdev_intr_info .intx .virt_pin , & trigger );
170
- if (trigger == LEVEL_TRIGGER )
176
+ if (trigger == LEVEL_TRIGGER ) {
171
177
update_irq_handler (phys_irq , common_dev_handler_level );
172
- else
178
+ } else {
173
179
update_irq_handler (phys_irq , common_handler_edge );
180
+ }
174
181
}
175
182
}
176
183
177
184
static bool ptdev_hv_owned_intx (struct vm * vm , struct ptdev_intx_info * info )
178
185
{
179
186
/* vm0 pin 4 (uart) is owned by hypervisor under debug version */
180
- if (is_vm0 (vm ) && (vm -> vuart != NULL ) && info -> virt_pin == 4U )
187
+ if (is_vm0 (vm ) && (vm -> vuart != NULL ) && info -> virt_pin == 4U ) {
181
188
return true;
182
- else
189
+ } else {
183
190
return false;
191
+ }
184
192
}
185
193
186
194
static void ptdev_build_physical_msi (struct vm * vm , struct ptdev_msi_info * info ,
@@ -200,8 +208,9 @@ static void ptdev_build_physical_msi(struct vm *vm, struct ptdev_msi_info *info,
200
208
201
209
/* get physical delivery mode */
202
210
delmode = info -> vmsi_data & APIC_DELMODE_MASK ;
203
- if (delmode != APIC_DELMODE_FIXED && delmode != APIC_DELMODE_LOWPRIO )
211
+ if (delmode != APIC_DELMODE_FIXED && delmode != APIC_DELMODE_LOWPRIO ) {
204
212
delmode = APIC_DELMODE_LOWPRIO ;
213
+ }
205
214
206
215
/* update physical delivery mode & vector */
207
216
info -> pmsi_data = info -> vmsi_data ;
@@ -244,8 +253,9 @@ static uint64_t ptdev_build_physical_rte(struct vm *vm,
244
253
/* physical delivery mode */
245
254
delmode = low & IOAPIC_RTE_DELMOD ;
246
255
if ((delmode != IOAPIC_RTE_DELFIXED ) &&
247
- (delmode != IOAPIC_RTE_DELLOPRI ))
256
+ (delmode != IOAPIC_RTE_DELLOPRI )) {
248
257
delmode = IOAPIC_RTE_DELLOPRI ;
258
+ }
249
259
250
260
/* update physical delivery mode, dest mode(logical) & vector */
251
261
low &= ~(IOAPIC_RTE_DESTMOD |
@@ -271,8 +281,9 @@ static uint64_t ptdev_build_physical_rte(struct vm *vm,
271
281
rte &= ~IOAPIC_RTE_TRGRMOD ;
272
282
vpic_get_irq_trigger (vm ,
273
283
entry -> ptdev_intr_info .intx .virt_pin , & trigger );
274
- if (trigger == LEVEL_TRIGGER )
284
+ if (trigger == LEVEL_TRIGGER ) {
275
285
rte |= IOAPIC_RTE_TRGRLVL ;
286
+ }
276
287
277
288
dev_dbg (ACRN_DBG_IRQ , "IOAPIC RTE = 0x%x:%x(P) -> 0x%x:%x(P)" ,
278
289
physical_rte >> 32 , (uint32_t )physical_rte ,
@@ -339,12 +350,14 @@ remove_msix_remapping(struct vm *vm, uint16_t virt_bdf, int msix_entry_index)
339
350
340
351
spinlock_obtain (& ptdev_lock );
341
352
entry = _lookup_entry_by_vmsi (vm , virt_bdf , msix_entry_index );
342
- if (entry == NULL )
353
+ if (entry == NULL ) {
343
354
goto END ;
355
+ }
344
356
345
- if (is_entry_active (entry ))
357
+ if (is_entry_active (entry )) {
346
358
/*TODO: disable MSIX device when HV can in future */
347
359
ptdev_deactivate_entry (entry );
360
+ }
348
361
349
362
dev_dbg (ACRN_DBG_IRQ ,
350
363
"VM%d MSIX remove vector mapping vbdf-pbdf:0x%x-0x%x idx=%d" ,
@@ -420,13 +433,15 @@ static void remove_intx_remapping(struct vm *vm, uint8_t virt_pin, bool pic_pin)
420
433
421
434
spinlock_obtain (& ptdev_lock );
422
435
entry = _lookup_entry_by_vintx (vm , virt_pin , vpin_src );
423
- if (entry == NULL )
436
+ if (entry == NULL ) {
424
437
goto END ;
438
+ }
425
439
426
440
if (is_entry_active (entry )) {
427
441
phys_irq = dev_to_irq (entry -> node );
428
- if (!irq_is_gsi (phys_irq ))
442
+ if (!irq_is_gsi (phys_irq )) {
429
443
goto END ;
444
+ }
430
445
431
446
/* disable interrupt */
432
447
GSI_MASK_IRQ (phys_irq );
@@ -459,15 +474,17 @@ static void ptdev_intr_handle_irq(struct vm *vm,
459
474
460
475
/* VPIN_IOAPIC src means we have vioapic enabled */
461
476
vioapic_get_rte (vm , entry -> ptdev_intr_info .intx .virt_pin , & rte );
462
- if ((rte & IOAPIC_RTE_TRGRMOD ) == IOAPIC_RTE_TRGRLVL )
477
+ if ((rte & IOAPIC_RTE_TRGRMOD ) == IOAPIC_RTE_TRGRLVL ) {
463
478
trigger_lvl = true;
479
+ }
464
480
465
- if (trigger_lvl )
481
+ if (trigger_lvl ) {
466
482
vioapic_assert_irq (vm ,
467
483
entry -> ptdev_intr_info .intx .virt_pin );
468
- else
484
+ } else {
469
485
vioapic_pulse_irq (vm ,
470
486
entry -> ptdev_intr_info .intx .virt_pin );
487
+ }
471
488
472
489
dev_dbg (ACRN_DBG_PTIRQ ,
473
490
"dev-assign: irq=0x%x assert vr: 0x%x vRTE=0x%x" ,
@@ -482,12 +499,13 @@ static void ptdev_intr_handle_irq(struct vm *vm,
482
499
/* VPIN_PIC src means we have vpic enabled */
483
500
vpic_get_irq_trigger (vm ,
484
501
entry -> ptdev_intr_info .intx .virt_pin , & trigger );
485
- if (trigger == LEVEL_TRIGGER )
502
+ if (trigger == LEVEL_TRIGGER ) {
486
503
vpic_assert_irq (vm ,
487
504
entry -> ptdev_intr_info .intx .virt_pin );
488
- else
505
+ } else {
489
506
vpic_pulse_irq (vm ,
490
507
entry -> ptdev_intr_info .intx .virt_pin );
508
+ }
491
509
break ;
492
510
}
493
511
default :
@@ -501,8 +519,9 @@ void ptdev_softirq(__unused uint16_t cpu_id)
501
519
struct ptdev_remapping_info * entry = ptdev_dequeue_softirq ();
502
520
struct vm * vm ;
503
521
504
- if (entry == NULL )
522
+ if (entry == NULL ) {
505
523
break ;
524
+ }
506
525
507
526
/* skip any inactive entry */
508
527
if (!is_entry_active (entry )) {
@@ -514,9 +533,9 @@ void ptdev_softirq(__unused uint16_t cpu_id)
514
533
vm = entry -> vm ;
515
534
516
535
/* handle real request */
517
- if (entry -> type == PTDEV_INTR_INTX )
536
+ if (entry -> type == PTDEV_INTR_INTX ) {
518
537
ptdev_intr_handle_irq (vm , entry );
519
- else {
538
+ } else {
520
539
/* TODO: msi destmode check required */
521
540
vlapic_intr_msi (vm ,
522
541
entry -> ptdev_intr_info .msi .vmsi_addr ,
@@ -542,13 +561,15 @@ void ptdev_intx_ack(struct vm *vm, int virt_pin,
542
561
int phys_pin ;
543
562
544
563
entry = lookup_entry_by_vintx (vm , virt_pin , vpin_src );
545
- if (entry == NULL )
564
+ if (entry == NULL ) {
546
565
return ;
566
+ }
547
567
548
568
phys_pin = entry -> ptdev_intr_info .intx .phys_pin ;
549
569
phys_irq = pin_to_irq (phys_pin );
550
- if (!irq_is_gsi (phys_irq ))
570
+ if (!irq_is_gsi (phys_irq )) {
551
571
return ;
572
+ }
552
573
553
574
/* NOTE: only Level trigger will process EOI/ACK and if we got here
554
575
* means we have this vioapic or vpic or both enabled
@@ -651,12 +672,14 @@ static bool vpin_masked(struct vm *vm, uint8_t virt_pin,
651
672
uint64_t rte ;
652
673
653
674
vioapic_get_rte (vm , virt_pin , & rte );
654
- if ((rte & IOAPIC_RTE_INTMASK ) == IOAPIC_RTE_INTMSET )
675
+ if ((rte & IOAPIC_RTE_INTMASK ) == IOAPIC_RTE_INTMSET ) {
655
676
return true;
656
- else
677
+ } else {
657
678
return false;
658
- } else
679
+ }
680
+ } else {
659
681
return vpic_is_pin_mask (vm -> vpic , virt_pin );
682
+ }
660
683
}
661
684
662
685
static void activate_physical_ioapic (struct vm * vm ,
@@ -705,8 +728,9 @@ int ptdev_intx_pin_remap(struct vm *vm, struct ptdev_intx_info *info)
705
728
*/
706
729
707
730
/* no remap for hypervisor owned intx */
708
- if (ptdev_hv_owned_intx (vm , info ))
731
+ if (ptdev_hv_owned_intx (vm , info )) {
709
732
goto END ;
733
+ }
710
734
711
735
/* query if we have virt to phys mapping */
712
736
entry = lookup_entry_by_vintx (vm , info -> virt_pin , info -> vpin_src );
@@ -726,22 +750,25 @@ int ptdev_intx_pin_remap(struct vm *vm, struct ptdev_intx_info *info)
726
750
pic_ioapic_pin_map [info -> virt_pin ],
727
751
pic_pin ? PTDEV_VPIN_IOAPIC
728
752
: PTDEV_VPIN_PIC );
729
- if (entry != NULL )
753
+ if (entry != NULL ) {
730
754
need_switch_vpin_src = true;
755
+ }
731
756
}
732
757
733
758
/* entry could be updated by above switch check */
734
759
if (entry == NULL ) {
735
760
/* allocate entry during first unmask */
736
761
if (vpin_masked (vm , info -> virt_pin ,
737
- info -> vpin_src ))
762
+ info -> vpin_src )) {
738
763
goto END ;
764
+ }
739
765
740
766
info -> phys_pin = info -> virt_pin ;
741
767
/* fix vPIC pin to correct native IOAPIC pin */
742
- if (pic_pin )
768
+ if (pic_pin ) {
743
769
info -> phys_pin =
744
770
pic_ioapic_pin_map [info -> virt_pin ];
771
+ }
745
772
746
773
entry = add_intx_remapping (vm , info -> virt_pin ,
747
774
info -> phys_pin , pic_pin );
@@ -762,14 +789,16 @@ int ptdev_intx_pin_remap(struct vm *vm, struct ptdev_intx_info *info)
762
789
763
790
/* no need update if vpin is masked && entry is not active */
764
791
if (!is_entry_active (entry ) &&
765
- vpin_masked (vm , info -> virt_pin , info -> vpin_src ))
792
+ vpin_masked (vm , info -> virt_pin , info -> vpin_src )) {
766
793
goto END ;
794
+ }
767
795
768
796
/* phys_pin from physical IOAPIC */
769
797
phys_pin = entry -> ptdev_intr_info .intx .phys_pin ;
770
798
phys_irq = pin_to_irq (phys_pin );
771
- if (!irq_is_gsi (phys_irq ))
799
+ if (!irq_is_gsi (phys_irq )) {
772
800
goto END ;
801
+ }
773
802
774
803
/* if vpin source need switch, make sure the entry is deactived */
775
804
if (need_switch_vpin_src ) {
@@ -852,8 +881,9 @@ int ptdev_add_intx_remapping(struct vm *vm,
852
881
}
853
882
854
883
entry = add_intx_remapping (vm , virt_pin , phys_pin , pic_pin );
855
- if (is_entry_invalid (entry ))
884
+ if (is_entry_invalid (entry )) {
856
885
return - ENODEV ;
886
+ }
857
887
858
888
return 0 ;
859
889
}
@@ -881,8 +911,9 @@ int ptdev_add_msix_remapping(struct vm *vm, uint16_t virt_bdf,
881
911
882
912
for (i = 0 ; i < vector_count ; i ++ ) {
883
913
entry = add_msix_remapping (vm , virt_bdf , phys_bdf , i );
884
- if (is_entry_invalid (entry ))
914
+ if (is_entry_invalid (entry )) {
885
915
return - ENODEV ;
916
+ }
886
917
}
887
918
888
919
return 0 ;
@@ -914,10 +945,11 @@ static void get_entry_info(struct ptdev_remapping_info *entry, char *type,
914
945
* dest = (entry -> ptdev_intr_info .msi .pmsi_addr & 0xFF000U )
915
946
>> 12 ;
916
947
if ((entry -> ptdev_intr_info .msi .pmsi_data &
917
- APIC_TRIGMOD_LEVEL ) != 0U )
948
+ APIC_TRIGMOD_LEVEL ) != 0U ) {
918
949
* lvl_tm = true;
919
- else
950
+ } else {
920
951
* lvl_tm = false;
952
+ }
921
953
* pin = IRQ_INVALID ;
922
954
* vpin = -1 ;
923
955
* bdf = entry -> phys_bdf ;
@@ -928,16 +960,18 @@ static void get_entry_info(struct ptdev_remapping_info *entry, char *type,
928
960
uint64_t rte = 0 ;
929
961
930
962
if (entry -> ptdev_intr_info .intx .vpin_src
931
- == PTDEV_VPIN_IOAPIC )
963
+ == PTDEV_VPIN_IOAPIC ) {
932
964
(void )strcpy_s (type , 16 , "IOAPIC" );
933
- else
965
+ } else {
934
966
(void )strcpy_s (type , 16 , "PIC" );
967
+ }
935
968
ioapic_get_rte (phys_irq , & rte );
936
969
* dest = ((rte >> 32 ) & IOAPIC_RTE_DEST ) >> 24 ;
937
- if ((rte & IOAPIC_RTE_TRGRLVL ) != 0U )
970
+ if ((rte & IOAPIC_RTE_TRGRLVL ) != 0U ) {
938
971
* lvl_tm = true;
939
- else
972
+ } else {
940
973
* lvl_tm = false;
974
+ }
941
975
* pin = entry -> ptdev_intr_info .intx .phys_pin ;
942
976
* vpin = entry -> ptdev_intr_info .intx .virt_pin ;
943
977
* bdf = 0 ;
0 commit comments