Skip to content

Commit b166b8a

Browse files
Jiqian Chenjgross1
authored andcommitted
xen/pvh: Setup gsi for passthrough device
In PVH dom0, the gsis don't get registered, but the gsi of a passthrough device must be configured for it to be able to be mapped into a domU. When assigning a device to passthrough, proactively setup the gsi of the device during that process. Signed-off-by: Jiqian Chen <[email protected]> Signed-off-by: Huang Rui <[email protected]> Signed-off-by: Jiqian Chen <[email protected]> Reviewed-by: Stefano Stabellini <[email protected]> Message-ID: <[email protected]> Signed-off-by: Juergen Gross <[email protected]>
1 parent 88801d0 commit b166b8a

File tree

6 files changed

+113
-1
lines changed

6 files changed

+113
-1
lines changed

arch/x86/xen/enlighten_pvh.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <linux/mm.h>
55

66
#include <xen/hvc-console.h>
7+
#include <xen/acpi.h>
78

89
#include <asm/bootparam.h>
910
#include <asm/io_apic.h>
@@ -28,6 +29,28 @@
2829
bool __ro_after_init xen_pvh;
2930
EXPORT_SYMBOL_GPL(xen_pvh);
3031

32+
#ifdef CONFIG_XEN_DOM0
33+
int xen_pvh_setup_gsi(int gsi, int trigger, int polarity)
34+
{
35+
int ret;
36+
struct physdev_setup_gsi setup_gsi;
37+
38+
setup_gsi.gsi = gsi;
39+
setup_gsi.triggering = (trigger == ACPI_EDGE_SENSITIVE ? 0 : 1);
40+
setup_gsi.polarity = (polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
41+
42+
ret = HYPERVISOR_physdev_op(PHYSDEVOP_setup_gsi, &setup_gsi);
43+
if (ret == -EEXIST) {
44+
xen_raw_printk("Already setup the GSI :%d\n", gsi);
45+
ret = 0;
46+
} else if (ret)
47+
xen_raw_printk("Fail to setup GSI (%d)!\n", gsi);
48+
49+
return ret;
50+
}
51+
EXPORT_SYMBOL_GPL(xen_pvh_setup_gsi);
52+
#endif
53+
3154
/*
3255
* Reserve e820 UNUSABLE regions to inflate the memory balloon.
3356
*

drivers/acpi/pci_irq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static int acpi_reroute_boot_interrupt(struct pci_dev *dev,
288288
}
289289
#endif /* CONFIG_X86_IO_APIC */
290290

291-
static struct acpi_prt_entry *acpi_pci_irq_lookup(struct pci_dev *dev, int pin)
291+
struct acpi_prt_entry *acpi_pci_irq_lookup(struct pci_dev *dev, int pin)
292292
{
293293
struct acpi_prt_entry *entry = NULL;
294294
struct pci_dev *bridge;

drivers/xen/acpi.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* IN THE SOFTWARE.
3131
*/
3232

33+
#include <linux/pci.h>
3334
#include <xen/acpi.h>
3435
#include <xen/interface/platform.h>
3536
#include <asm/xen/hypercall.h>
@@ -75,3 +76,52 @@ int xen_acpi_notify_hypervisor_extended_sleep(u8 sleep_state,
7576
return xen_acpi_notify_hypervisor_state(sleep_state, val_a,
7677
val_b, true);
7778
}
79+
80+
struct acpi_prt_entry {
81+
struct acpi_pci_id id;
82+
u8 pin;
83+
acpi_handle link;
84+
u32 index;
85+
};
86+
87+
int xen_acpi_get_gsi_info(struct pci_dev *dev,
88+
int *gsi_out,
89+
int *trigger_out,
90+
int *polarity_out)
91+
{
92+
int gsi;
93+
u8 pin;
94+
struct acpi_prt_entry *entry;
95+
int trigger = ACPI_LEVEL_SENSITIVE;
96+
int polarity = acpi_irq_model == ACPI_IRQ_MODEL_GIC ?
97+
ACPI_ACTIVE_HIGH : ACPI_ACTIVE_LOW;
98+
99+
if (!dev || !gsi_out || !trigger_out || !polarity_out)
100+
return -EINVAL;
101+
102+
pin = dev->pin;
103+
if (!pin)
104+
return -EINVAL;
105+
106+
entry = acpi_pci_irq_lookup(dev, pin);
107+
if (entry) {
108+
if (entry->link)
109+
gsi = acpi_pci_link_allocate_irq(entry->link,
110+
entry->index,
111+
&trigger, &polarity,
112+
NULL);
113+
else
114+
gsi = entry->index;
115+
} else
116+
gsi = -1;
117+
118+
if (gsi < 0)
119+
return -EINVAL;
120+
121+
*gsi_out = gsi;
122+
*trigger_out = trigger;
123+
*polarity_out = polarity;
124+
125+
return 0;
126+
}
127+
EXPORT_SYMBOL_GPL(xen_acpi_get_gsi_info);

drivers/xen/xen-pciback/pci_stub.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
#include <xen/events.h>
2222
#include <xen/pci.h>
2323
#include <xen/xen.h>
24+
#ifdef CONFIG_XEN_ACPI
25+
#include <xen/acpi.h>
26+
#endif
2427
#include <asm/xen/hypervisor.h>
2528
#include <xen/interface/physdev.h>
2629
#include "pciback.h"
@@ -367,6 +370,9 @@ static int pcistub_match(struct pci_dev *dev)
367370
static int pcistub_init_device(struct pci_dev *dev)
368371
{
369372
struct xen_pcibk_dev_data *dev_data;
373+
#ifdef CONFIG_XEN_ACPI
374+
int gsi, trigger, polarity;
375+
#endif
370376
int err = 0;
371377

372378
dev_dbg(&dev->dev, "initializing...\n");
@@ -435,6 +441,20 @@ static int pcistub_init_device(struct pci_dev *dev)
435441
goto config_release;
436442
pci_restore_state(dev);
437443
}
444+
445+
#ifdef CONFIG_XEN_ACPI
446+
if (xen_initial_domain() && xen_pvh_domain()) {
447+
err = xen_acpi_get_gsi_info(dev, &gsi, &trigger, &polarity);
448+
if (err) {
449+
dev_err(&dev->dev, "Fail to get gsi info!\n");
450+
goto config_release;
451+
}
452+
err = xen_pvh_setup_gsi(gsi, trigger, polarity);
453+
if (err)
454+
goto config_release;
455+
}
456+
#endif
457+
438458
/* Now disable the device (this also ensures some private device
439459
* data is setup before we export)
440460
*/

include/linux/acpi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ void acpi_unregister_gsi (u32 gsi);
362362

363363
struct pci_dev;
364364

365+
struct acpi_prt_entry *acpi_pci_irq_lookup(struct pci_dev *dev, int pin);
365366
int acpi_pci_irq_enable (struct pci_dev *dev);
366367
void acpi_penalize_isa_irq(int irq, int active);
367368
bool acpi_isa_irq_available(int irq);

include/xen/acpi.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,28 @@ static inline void xen_acpi_sleep_register(void)
6767
acpi_suspend_lowlevel = xen_acpi_suspend_lowlevel;
6868
}
6969
}
70+
int xen_pvh_setup_gsi(int gsi, int trigger, int polarity);
71+
int xen_acpi_get_gsi_info(struct pci_dev *dev,
72+
int *gsi_out,
73+
int *trigger_out,
74+
int *polarity_out);
7075
#else
7176
static inline void xen_acpi_sleep_register(void)
7277
{
7378
}
79+
80+
static inline int xen_pvh_setup_gsi(int gsi, int trigger, int polarity)
81+
{
82+
return -1;
83+
}
84+
85+
static inline int xen_acpi_get_gsi_info(struct pci_dev *dev,
86+
int *gsi_out,
87+
int *trigger_out,
88+
int *polarity_out)
89+
{
90+
return -1;
91+
}
7492
#endif
7593

7694
#endif /* _XEN_ACPI_H */

0 commit comments

Comments
 (0)