@@ -39,6 +39,19 @@ ptdev_lookup_entry_by_sid(uint32_t intr_type,
39
39
return NULL ;
40
40
}
41
41
42
+ static inline struct ptdev_remapping_info *
43
+ ptdev_lookup_entry_by_vpin (struct acrn_vm * vm , uint8_t virt_pin , bool pic_pin )
44
+ {
45
+ struct ptdev_remapping_info * entry ;
46
+
47
+ if (pic_pin ) {
48
+ entry = vm -> arch_vm .vpic .vpin_to_pt_entry [virt_pin ];
49
+ } else {
50
+ entry = vm -> arch_vm .vioapic .vpin_to_pt_entry [virt_pin ];
51
+ }
52
+ return entry ;
53
+ }
54
+
42
55
#ifdef HV_DEBUG
43
56
static bool ptdev_hv_owned_intx (const struct acrn_vm * vm , const union source_id * virt_sid )
44
57
{
@@ -277,14 +290,20 @@ static struct ptdev_remapping_info *add_intx_remapping(struct acrn_vm *vm, uint8
277
290
DEFINE_IOAPIC_SID (virt_sid , virt_pin , vpin_src );
278
291
uint32_t phys_irq = pin_to_irq (phys_pin );
279
292
293
+ if ((!pic_pin && virt_pin >= vioapic_pincount (vm ))
294
+ || (pic_pin && virt_pin >= vpic_pincount ())) {
295
+ pr_err ("ptdev_add_intx_remapping fails!\n" );
296
+ return NULL ;
297
+ }
298
+
280
299
if (!irq_is_gsi (phys_irq )) {
281
300
pr_err ("%s, invalid phys_pin: %d <-> irq: 0x%x is not a GSI\n" , __func__ , phys_pin , phys_irq );
282
301
return NULL ;
283
302
}
284
303
285
304
entry = ptdev_lookup_entry_by_sid (PTDEV_INTR_INTX , & phys_sid , NULL );
286
305
if (entry == NULL ) {
287
- if (ptdev_lookup_entry_by_sid ( PTDEV_INTR_INTX , & virt_sid , vm ) != NULL ) {
306
+ if (ptdev_lookup_entry_by_vpin ( vm , virt_pin , pic_pin ) != NULL ) {
288
307
pr_err ("INTX re-add vpin %d" , virt_pin );
289
308
return NULL ;
290
309
}
@@ -314,26 +333,33 @@ static struct ptdev_remapping_info *add_intx_remapping(struct acrn_vm *vm, uint8
314
333
* required. */
315
334
}
316
335
317
- dev_dbg (ACRN_DBG_IRQ , "VM%d INTX add pin mapping vpin%d:ppin%d" , vm -> vm_id , virt_pin , phys_pin );
336
+ if (pic_pin ) {
337
+ vm -> arch_vm .vpic .vpin_to_pt_entry [virt_pin ] = entry ;
338
+ } else {
339
+ vm -> arch_vm .vioapic .vpin_to_pt_entry [virt_pin ] = entry ;
340
+ }
341
+
342
+ dev_dbg (ACRN_DBG_IRQ , "VM%d INTX add pin mapping vpin%d:ppin%d" , entry -> vm -> vm_id , virt_pin , phys_pin );
318
343
319
344
return entry ;
320
345
}
321
346
322
347
/* deactive & remove mapping entry of vpin for vm */
323
- static void remove_intx_remapping (const struct acrn_vm * vm , uint8_t virt_pin , bool pic_pin )
348
+ static void remove_intx_remapping (struct acrn_vm * vm , uint8_t virt_pin , bool pic_pin )
324
349
{
325
350
uint32_t phys_irq ;
326
351
struct ptdev_remapping_info * entry ;
327
- enum ptdev_vpin_source vpin_src =
328
- pic_pin ? PTDEV_VPIN_PIC : PTDEV_VPIN_IOAPIC ;
329
- DEFINE_IOAPIC_SID (virt_sid , virt_pin , vpin_src );
330
352
353
+ if ((!pic_pin && virt_pin >= vioapic_pincount (vm ))
354
+ || (pic_pin && virt_pin >= vpic_pincount ())) {
355
+ pr_err ("virtual irq pin is invalid!\n" );
356
+ return ;
357
+ }
331
358
332
- entry = ptdev_lookup_entry_by_sid ( PTDEV_INTR_INTX , & virt_sid , vm );
359
+ entry = ptdev_lookup_entry_by_vpin ( vm , virt_pin , pic_pin );
333
360
if (entry == NULL ) {
334
361
return ;
335
362
}
336
-
337
363
if (is_entry_active (entry )) {
338
364
phys_irq = entry -> allocated_pirq ;
339
365
/* disable interrupt */
@@ -342,13 +368,18 @@ static void remove_intx_remapping(const struct acrn_vm *vm, uint8_t virt_pin, bo
342
368
ptdev_deactivate_entry (entry );
343
369
dev_dbg (ACRN_DBG_IRQ ,
344
370
"deactive %s intx entry:ppin=%d, pirq=%d " ,
345
- vpin_src == PTDEV_VPIN_PIC ?
346
- "vPIC" : "vIOAPIC" ,
371
+ pic_pin ? "vPIC" : "vIOAPIC" ,
347
372
entry -> phys_sid .intx_id .pin , phys_irq );
348
373
dev_dbg (ACRN_DBG_IRQ , "from vm%d vpin=%d\n" ,
349
374
entry -> vm -> vm_id , virt_pin );
350
375
}
351
376
377
+ if (pic_pin ) {
378
+ vm -> arch_vm .vpic .vpin_to_pt_entry [virt_pin ] = NULL ;
379
+ } else {
380
+ vm -> arch_vm .vioapic .vpin_to_pt_entry [virt_pin ] = NULL ;
381
+ }
382
+
352
383
release_entry (entry );
353
384
}
354
385
@@ -464,9 +495,9 @@ void ptdev_intx_ack(struct acrn_vm *vm, uint8_t virt_pin,
464
495
{
465
496
uint32_t phys_irq ;
466
497
struct ptdev_remapping_info * entry ;
467
- DEFINE_IOAPIC_SID ( virt_sid , virt_pin , vpin_src );
498
+ bool pic_pin = ( vpin_src == PTDEV_VPIN_PIC );
468
499
469
- entry = ptdev_lookup_entry_by_sid ( PTDEV_INTR_INTX , & virt_sid , vm );
500
+ entry = ptdev_lookup_entry_by_vpin ( vm , virt_pin , pic_pin );
470
501
if (entry == NULL ) {
471
502
return ;
472
503
}
@@ -600,6 +631,7 @@ int ptdev_intx_pin_remap(struct acrn_vm *vm, uint8_t virt_pin,
600
631
struct ptdev_remapping_info * entry ;
601
632
bool need_switch_vpin_src = false;
602
633
DEFINE_IOAPIC_SID (virt_sid , virt_pin , vpin_src );
634
+ bool pic_pin = (vpin_src == PTDEV_VPIN_PIC );
603
635
604
636
/*
605
637
* virt pin could come from vpic master, vpic slave or vioapic
@@ -620,10 +652,9 @@ int ptdev_intx_pin_remap(struct acrn_vm *vm, uint8_t virt_pin,
620
652
#endif
621
653
/* query if we have virt to phys mapping */
622
654
spinlock_obtain (& ptdev_lock );
623
- entry = ptdev_lookup_entry_by_sid ( PTDEV_INTR_INTX , & virt_sid , vm );
655
+ entry = ptdev_lookup_entry_by_vpin ( vm , virt_pin , pic_pin );
624
656
if (entry == NULL ) {
625
657
if (is_vm0 (vm )) {
626
- bool pic_pin = (vpin_src == PTDEV_VPIN_PIC );
627
658
628
659
/* for vm0, there is chance of vpin source switch
629
660
* between vPIC & vIOAPIC for one legacy phys_pin.
@@ -633,12 +664,9 @@ int ptdev_intx_pin_remap(struct acrn_vm *vm, uint8_t virt_pin,
633
664
* switch vpin source is needed
634
665
*/
635
666
if (virt_pin < NR_LEGACY_PIN ) {
636
- DEFINE_IOAPIC_SID (tmp_vsid ,
637
- pic_ioapic_pin_map [virt_pin ],
638
- pic_pin ? PTDEV_VPIN_IOAPIC :
639
- PTDEV_VPIN_PIC );
640
- entry = ptdev_lookup_entry_by_sid (
641
- PTDEV_INTR_INTX , & tmp_vsid , vm );
667
+ uint8_t vpin = pic_ioapic_pin_map [virt_pin ];
668
+
669
+ entry = ptdev_lookup_entry_by_vpin (vm , vpin , !pic_pin );
642
670
if (entry != NULL ) {
643
671
need_switch_vpin_src = true;
644
672
}
@@ -707,12 +735,6 @@ int ptdev_add_intx_remapping(struct acrn_vm *vm, uint8_t virt_pin, uint8_t phys_
707
735
{
708
736
struct ptdev_remapping_info * entry ;
709
737
710
- if ((!pic_pin && virt_pin >= vioapic_pincount (vm ))
711
- || (pic_pin && virt_pin >= vpic_pincount ())) {
712
- pr_err ("ptdev_add_intx_remapping fails!\n" );
713
- return - EINVAL ;
714
- }
715
-
716
738
spinlock_obtain (& ptdev_lock );
717
739
entry = add_intx_remapping (vm , virt_pin , phys_pin , pic_pin );
718
740
spinlock_release (& ptdev_lock );
@@ -723,7 +745,7 @@ int ptdev_add_intx_remapping(struct acrn_vm *vm, uint8_t virt_pin, uint8_t phys_
723
745
/*
724
746
* @pre vm != NULL
725
747
*/
726
- void ptdev_remove_intx_remapping (const struct acrn_vm * vm , uint8_t virt_pin , bool pic_pin )
748
+ void ptdev_remove_intx_remapping (struct acrn_vm * vm , uint8_t virt_pin , bool pic_pin )
727
749
{
728
750
spinlock_obtain (& ptdev_lock );
729
751
remove_intx_remapping (vm , virt_pin , pic_pin );
0 commit comments