igd passthrough chipset tweaks
v2 cover igd passthrough chipset tweaks
Hi,
We have some code in our tree to support pci passthrough of intel graphics devices (igd) on xen, which requires some chipset tweaks for (a) the host bridge and (b) the lpc/isa-bridge to meat the expectations of the guest driver.
For kvm we need pretty much the same, also the requirements for vgpu (xengt/kvmgt) are very simliar. This patch wires up the existing support for kvm. It also brings a bunch of bugfixes and cleanups.
Unfortunaly the oldish laptop I had planned to use for testing turned out to have no working iommu support for igd, so this patch series still has seen very light testing only. Any testing feedback is very welcome.
Testing with kvm/i440fx:
Add '-M pc,igd-passthru=on -device igd-passthrough-isa-bridge,addr=1f' to turn on the chipset tweaks. Passthrough the igd using vfio.
Testing with kvm/q35:
Add '-M q35,igd-passthru=on' to turn on the the chipset tweaks. Pick up the linux kernel patch referenced in patch #10, build a custom kernel with it. Passthrough the igd using vfio.
Testing with xen:
Existing setups should continue working ;)
Changes in v2:
* Added igd-passthrough-isa-bridge support form kvm.
* Added patch to drop has_igd_gfx_passthru.
TODO:
* Possibly handle igd-passthrough-isa-bridge automatically (see patch 10).
* Figure a way to handle the opregion, probably via vfio extension. Beyond the scope of this patch series, but probably needed to make laptop panels work correctly.
Gerd Hoffmann (10):
pc: wire up TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE for !xen
pc: remove has_igd_gfx_passthru global
pc: move igd support code to igd.c
igd: switch TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE to realize
igd: TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE: call parent realize
igd: use defines for standard pci config space offsets
igd: revamp host config read
igd: add q35 support
igd: move igd-passthrough-isa-bridge to igd.c too
igd: handle igd-passthrough-isa-bridge setup in realize()
hw/i386/pc_piix.c | 124 ++----------------------------- hw/pci-host/Makefile.objs | 3 + hw/pci-host/igd.c | 181 ++++++++++++++++++++++++++++++++++++++++++++++ hw/pci-host/piix.c | 88 ---------------------- hw/pci-host/q35.c | 6 +- hw/xen/xen_pt.h | 3 +- vl.c | 10 --- 7 files changed, 195 insertions(+), 220 deletions(-) create mode 100644 hw/pci-host/igd.c
Signature · 1 line
1.8.3.1
PATCH 1/1 ehci: make idt processing more robust
Make ehci_process_itd return an error in case we didn't do any actual iso transfer because we've found no active transaction. That'll avoid ehci happily run in circles forever if the guest builds a loop out of idts.
--- hw/usb/hcd-ehci.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/usb/hcd-ehci.c +3 -2
@@ -1389,7 +1389,7 @@ static int ehci_process_itd(EHCIState *ehci, {USBDevice *dev;USBEndpoint *ep; -uint32_t i, len, pid, dir, devaddr, endp; +uint32_t i, len, pid, dir, devaddr, endp, xfers =0 ;uint32_t pg, off, ptr1, ptr2, max, mult; ehci->periodic_sched_active =PERIODIC_ACTIVE ;
@@ -1479,9 +1479,10 @@ static int ehci_process_itd(EHCIState *ehci,ehci_raise_irq (ehci,USBSTS_INT ); } itd->transact[i] &= ~ITD_XACT_ACTIVE ; + xfers++; } } -return 0 ; +return xfers ?0 :-1 ; }
Signature · 1 line
1.8.3.1
PATCH v2 1/10 pc: wire up TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE for !xen
In reply to Gerd Hoffmannrename pc_xen_hvm_init_pci to pc_i440fx_init_pci,
use it for both xen and non-xen init.
That changes behavior of all pc-i440fx-$version machine types where specifying -machine igd-passthru=on used to have no effect and now it has. It is unlikely to cause any trouble though as there used to be no reason to add that option to kvm guests in the first place.
--- hw/i386/pc_piix.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
hw/i386/pc_piix.c +5 -6
@@ -419,10 +419,9 @@ static void pc_init_isa(MachineState *machine)pc_init1 (machine,TYPE_I440FX_PCI_HOST_BRIDGE ,TYPE_I440FX_PCI_DEVICE ); } -#ifdef CONFIG_XEN -static void pc_xen_hvm_init_pci (MachineState *machine) +static void pc_i440fx_init_pci (MachineState *machine) { -const char *pci_type = has_igd_gfx_passthru ? +const char *pci_type = machine->igd_gfx_passthru ?TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE :TYPE_I440FX_PCI_DEVICE ; pc_init1(machine,
@@ -430,6 +429,7 @@ static void pc_xen_hvm_init_pci(MachineState *machine) pci_type); } +#ifdef CONFIG_XEN static void pc_xen_hvm_init (MachineState *machine) {PCIBus *bus;
@@ -439,7 +439,7 @@ static void pc_xen_hvm_init(MachineState *machine)exit (1 ); } -pc_xen_hvm_init_pci (machine); +pc_i440fx_init_pci (machine); bus =pci_find_primary_bus ();if (bus !=NULL ) {
@@ -455,8 +455,7 @@ static void pc_xen_hvm_init(MachineState *machine)if (compat) { \compat (machine); \ } \ -pc_init1 (machine,TYPE_I440FX_PCI_HOST_BRIDGE , \ -TYPE_I440FX_PCI_DEVICE ); \ +pc_i440fx_init_pci (machine); \ } \ DEFINE_PC_MACHINE(suffix, name, pc_init_##suffix, optionfn)
Signature · 1 line
1.8.3.1
PATCH v2 2/10 pc: remove has_igd_gfx_passthru global
In reply to Gerd Hoffmann--- hw/xen/xen_pt.h | 3 +-- vl.c | 10 ---------- 2 files changed, 1 insertion(+), 12 deletions(-)
hw/xen/xen_pt.h +1 -2
@@ -320,10 +320,9 @@ extern void *pci_assign_dev_load_option_rom(PCIDevice *dev,unsigned int domain, unsigned int bus, unsigned int slot, unsigned int function); -extern bool has_igd_gfx_passthru;static inline bool is_igd_vga_passthrough (XenHostPCIDevice *dev) { -return (has_igd_gfx_passthru +return (qdev_get_machine->igd_gfx_passthru && ((dev->class_code >>0x8 ) ==PCI_CLASS_DISPLAY_VGA )); }int xen_pt_register_vga_regions (XenHostPCIDevice *dev);
vl.c +0 -10
@@ -1365,13 +1365,6 @@ static inline void semihosting_arg_fallback(const char *file, const char *cmd) } } -/* Now we still need this for compatibility with XEN. */ -bool has_igd_gfx_passthru; -static void igd_gfx_passthru (void ) -{ - has_igd_gfx_passthru = current_machine->igd_gfx_passthru; -} -/***********************************************************/ /* USB devices */
@@ -4550,9 +4543,6 @@ int main(int argc, char **argv, char **envp)exit (1 ); } -/* Check if IGD GFX passthrough. */ -igd_gfx_passthru (); -/* init generic devices */ if (qemu_opts_foreach (qemu_find_opts ("device" ), device_init_func,NULL ,NULL )) {
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v2 02/10] pc: remove has_igd_gfx_passthru global
Quoted 11 lines · Gerd Hoffmann
Signed-off-by Gerd Hoffmann <[email protected]>--- hw/xen/xen_pt.h | 3 +-- vl.c | 10 ---------- 2 files changed, 1 insertion(+), 12 deletions(-)hw/xen/xen_pt.h +0
-0
hw/xen/xen_pt.h extern void *pci_assign_dev_load_option_rom(PCIDevice *dev, · line 327
Quoted 10 lines
hw/xen/xen_pt.h +1
-2@@ -320,10 +320,9 @@ extern void *pci_assign_dev_load_option_rom(PCIDevice *dev,unsigned int domain, unsigned int bus, unsigned int slot, unsigned int function); -extern bool has_igd_gfx_passthru;static inline bool is_igd_vga_passthrough (XenHostPCIDevice *dev) { -return (has_igd_gfx_passthru +return (qdev_get_machine->igd_gfx_passthru && ((dev->class_code >>0x8 ) ==PCI_CLASS_DISPLAY_VGA )); }
Doesn't compile:
qemu/hw/xen/xen_pt.h: In function ‘is_igd_vga_passthrough’:qemu/hw/xen/xen_pt.h:325:29: error: request for member ‘igd_gfx_passthru’ in something not a structure or union
return (qdev_get_machine->igd_gfx_passthru
^Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v2 02/10] pc: remove has_igd_gfx_passthru global
Quoted 9 lines
Quoted 3 lines
+ return (
qdev_get_machine->igd_gfx_passthru&& ((dev->class_code >> 0x8) == PCI_CLASS_DISPLAY_VGA));}
Doesn't compile:
qemu/hw/xen/xen_pt.h: In function ‘is_igd_vga_passthrough’:qemu/hw/xen/xen_pt.h:325:29: error: request for member ‘igd_gfx_passthru’ in something not a structure or unionreturn (qdev_get_machine->igd_gfx_passthru
Incremental fix attached (will squash into v2).
cheers,
Gerd
From b30226140f80202c4d2dda23acae9533aba6136b Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <[email protected]>
Date: Fri, 18 Dec 2015 08:44:48 +0100
Subject: [PATCH] [fixup] build on xen
--- hw/xen/xen_pt.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
hw/xen/xen_pt.h +3 -1
@@ -4,6 +4,7 @@#include "qemu-common.h" #include "hw/xen/xen_common.h" #include "hw/pci/pci.h" +#include "hw/boards.h" #include "xen-host-pci-device.h" void xen_pt_log(const PCIDevice *d, const char *f, ...) GCC_FMT_ATTR(2, 3);
@@ -322,7 +323,8 @@ extern void *pci_assign_dev_load_option_rom(PCIDevice *dev, unsigned int function);static inline bool is_igd_vga_passthrough (XenHostPCIDevice *dev) { -return (qdev_get_machine->igd_gfx_passthru +MachineState *machine =MACHINE (qdev_get_machine ()); +return (machine->igd_gfx_passthru && ((dev->class_code >>0x8 ) ==PCI_CLASS_DISPLAY_VGA )); }int xen_pt_register_vga_regions (XenHostPCIDevice *dev);
Signature · 1 line
1.8.3.1
PATCH v2 3/10 pc: move igd support code to igd.c
In reply to Gerd HoffmannPure code motion, except for dropping instance_size for TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE (no need to set, we can inherit it from TYPE_I440FX_PCI_DEVICE).
--- hw/pci-host/Makefile.objs | 3 ++ hw/pci-host/igd.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++ hw/pci-host/piix.c | 88 ------------------------------------------- 3 files changed, 99 insertions(+), 88 deletions(-) create mode 100644 hw/pci-host/igd.c
hw/pci-host/Makefile.objs +3 -0
@@ -11,6 +11,9 @@ common-obj-$(CONFIG_PPCE500_PCI) += ppce500.o # ARM devices common-obj-$(CONFIG_VERSATILE_PCI) += versatile.o +# igd passthrough support +common-obj-$(CONFIG_LINUX) += igd.o + common-obj-$(CONFIG_PCI_APB) += apb.o common-obj-$(CONFIG_FULONG) += bonito.o common-obj-$(CONFIG_PCI_PIIX) += piix.o
hw/pci-host/igd.c new file +96 -0
96 lines not on this page · raw message
hw/pci-host/piix.c +0 -88
100 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 4/10 igd: switch TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE to realize
In reply to Gerd Hoffmann--- hw/pci-host/igd.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
hw/pci-host/igd.c +4 -5
@@ -53,7 +53,7 @@ out:return ret; } -static int igd_pt_i440fx_initfn (struct PCIDevice *pci_dev) +static void igd_pt_i440fx_realize (PCIDevice *pci_dev,Error **errp) {uint32_t val =0 ;int rc, i, num;
@@ -65,12 +65,11 @@ static int igd_pt_i440fx_initfn(struct PCIDevice *pci_dev) len = igd_host_bridge_infos[i].len; rc =host_pci_config_read (pos, len, val);if (rc) { -return -ENODEV ; +error_setg (errp,"failed to read host config" ); +return ; }pci_default_write_config (pci_dev, pos, val, len); } - -return 0 ; }static void igd_passthrough_i440fx_class_init (ObjectClass *klass,void *data)
@@ -78,7 +77,7 @@ static void igd_passthrough_i440fx_class_init(ObjectClass *klass, void *data)DeviceClass *dc =DEVICE_CLASS (klass);PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); - k->init = igd_pt_i440fx_initfn; + k->realize = igd_pt_i440fx_realize; dc->desc ="IGD Passthrough Host bridge" ; }
Signature · 1 line
1.8.3.1
PATCH v2 5/10 igd: TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE: call parent realize
In reply to Gerd Hoffmann--- hw/pci-host/igd.c | 9 +++++++++ 1 file changed, 9 insertions(+)
hw/pci-host/igd.c +9 -0
@@ -53,12 +53,20 @@ out:return ret; } +static void (*i440fx_realize)(PCIDevice *pci_dev,Error **errp);static void igd_pt_i440fx_realize (PCIDevice *pci_dev,Error **errp) { +Error *err =NULL ;uint32_t val =0 ;int rc, i, num;int pos, len; +i440fx_realize (pci_dev, &err); +if (err !=NULL ) { +error_propagate (errp, err); +return ; + } + num =ARRAY_SIZE (igd_host_bridge_infos);for (i =0 ; i < num; i++) { pos = igd_host_bridge_infos[i].offset;
@@ -77,6 +85,7 @@ static void igd_passthrough_i440fx_class_init(ObjectClass *klass, void *data)DeviceClass *dc =DEVICE_CLASS (klass);PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); + i440fx_realize = k->realize; k->realize = igd_pt_i440fx_realize; dc->desc ="IGD Passthrough Host bridge" ; }
Signature · 1 line
1.8.3.1
PATCH v2 6/10 igd: use defines for standard pci config space offsets
In reply to Gerd Hoffmann--- hw/pci-host/igd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/pci-host/igd.c +3 -3
@@ -10,9 +10,9 @@ typedef struct {/* Here we just expose minimal host bridge offset subset. */ static const IGDHostInfo igd_host_bridge_infos[] = { - {0x08 ,2 },/* revision id */ - {0x2c ,2 },/* sybsystem vendor id */ - {0x2e ,2 },/* sybsystem id */ + {PCI_REVISION_ID ,2 }, + {PCI_SUBSYSTEM_VENDOR_ID ,2 }, + {PCI_SUBSYSTEM_ID ,2 }, {0x50 ,2 },/* SNB: processor graphics control register */ {0x52 ,2 },/* processor graphics control register */ {0xa4 ,4 },/* SNB: graphics base of stolen memory */
Signature · 1 line
1.8.3.1
PATCH v2 7/10 igd: revamp host config read
In reply to Gerd HoffmannMove all work to the host_pci_config_copy helper function, which we can easily reuse when adding q35 support. Open sysfs file only once for all values. Use pread. Proper error handling. Fix bugs:
* Don't throw away results (like old host_pci_config_read did because val was passed by value not reference).
* Update config space directly (writing via pci_default_write_config only works for registers whitelisted in wmask).
Hmm, this code can hardly ever worked before,
/me wonders what test coverage it had.
With this patch in place igd-passthru=on actually works, although it still requires root priviledges because linux refuses to allow non-root users access pci config space above offset 0x50.
--- hw/pci-host/igd.c | 65 +++++++++++++++++++++++-------------------------------- 1 file changed, 27 insertions(+), 38 deletions(-)
hw/pci-host/igd.c +27 -38
@@ -19,47 +19,39 @@ static const IGDHostInfo igd_host_bridge_infos[] = { {0xa8, 4}, /* SNB: base of GTT stolen memory */ }; -static int host_pci_config_read (int pos,int len,uint32_t val) +static void host_pci_config_copy (PCIDevice *guest,const char *host, +const IGDHostInfo *list,int len,Error **errp) { -char path[PATH_MAX ]; -int config_fd; -ssize_t size =sizeof (path); -/* Access real host bridge. */ -int rc =snprintf (path, size,"/sys/bus/pci/devices/%04x:%02x:%02x.%d/%s" , -0 ,0 ,0 ,0 ,"config" ); -int ret =0 ; +char *path; +int config_fd, rc, i; -if (rc >= size || rc <0 ) { -return -ENODEV ; - } - - config_fd =open (path,O_RDWR ); + path =g_strdup_printf ("/sys/bus/pci/devices/%s/config" , host); + config_fd =open (path,O_RDONLY );if (config_fd <0 ) { -return -ENODEV ; +error_setg_file_open (errp, errno, path); + goto out_free; } -if (lseek (config_fd, pos,SEEK_SET ) != pos) { - ret = -errno; - goto out; +for (i =0 ; i < len; i++) { + rc =pread (config_fd, guest->config + list[i].offset, + list[i].len, list[i].offset); +if (rc != list[i].len) { +error_setg_errno (errp, errno,"read %s, offset 0x%x" , + path, list[i].offset); + goto out_close; + } } -do { - rc =read (config_fd, (uint8_t *)&val, len); - }while (rc <0 && (errno ==EINTR || errno ==EAGAIN )); -if (rc != len) { - ret = -errno; - } -out: + +out_close:close (config_fd); -return ret; +out_free: +g_free (path); }static void (*i440fx_realize)(PCIDevice *pci_dev,Error **errp);static void igd_pt_i440fx_realize (PCIDevice *pci_dev,Error **errp) {Error *err =NULL ; -uint32_t val =0 ; -int rc, i, num; -int pos, len;i440fx_realize (pci_dev, &err);if (err !=NULL ) {
@@ -67,16 +59,13 @@ static void igd_pt_i440fx_realize(PCIDevice *pci_dev, Error **errp)return ; } - num =ARRAY_SIZE (igd_host_bridge_infos); -for (i =0 ; i < num; i++) { - pos = igd_host_bridge_infos[i].offset; - len = igd_host_bridge_infos[i].len; - rc =host_pci_config_read (pos, len, val); -if (rc) { -error_setg (errp,"failed to read host config" ); -return ; - } -pci_default_write_config (pci_dev, pos, val, len); +host_pci_config_copy (pci_dev,"0000:00:00.0" , + igd_host_bridge_infos, +ARRAY_SIZE (igd_host_bridge_infos), + &err); +if (err !=NULL ) { +error_propagate (errp, err); +return ; } }
Signature · 1 line
1.8.3.1
PATCH v2 8/10 igd: add q35 support
In reply to Gerd Hoffmann--- hw/pci-host/igd.c | 41 ++++++++++++++++++++++++++++++++++++++++- hw/pci-host/q35.c | 6 +++++- 2 files changed, 45 insertions(+), 2 deletions(-)
hw/pci-host/igd.c +40 -1
@@ -1,5 +1,6 @@#include "qemu-common.h" #include "hw/pci/pci.h" +#include "hw/pci-host/q35.h" #include "hw/i386/pc.h" /* IGD Passthrough Host Bridge. */
@@ -76,7 +77,7 @@ static void igd_passthrough_i440fx_class_init(ObjectClass *klass, void *data) i440fx_realize = k->realize; k->realize = igd_pt_i440fx_realize; - dc->desc ="IGD Passthrough Host bridge" ; + dc->desc ="IGD Passthrough Host bridge (i440fx)" ; }static const TypeInfo igd_passthrough_i440fx_info = {
@@ -85,9 +86,47 @@ static const TypeInfo igd_passthrough_i440fx_info = { .class_init = igd_passthrough_i440fx_class_init, }; +static void (*q35_realize)(PCIDevice *pci_dev,Error **errp); +static void igd_pt_q35_realize (PCIDevice *pci_dev,Error **errp) +{ +Error *err =NULL ; + +q35_realize (pci_dev, &err); +if (err !=NULL ) { +error_propagate (errp, err); +return ; + } + +host_pci_config_copy (pci_dev,"0000:00:00.0" , + igd_host_bridge_infos, +ARRAY_SIZE (igd_host_bridge_infos), + &err); +if (err !=NULL ) { +error_propagate (errp, err); +return ; + } +} + +static void igd_passthrough_q35_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); + + q35_realize = k->realize; + k->realize = igd_pt_q35_realize; + dc->desc ="IGD Passthrough Host bridge (q35)" ; +} + +static const TypeInfo igd_passthrough_q35_info = { + .name ="igd-passthrough-q35-mch" , + .parent =TYPE_MCH_PCI_DEVICE , + .class_init = igd_passthrough_q35_class_init, +}; +static void igd_register_types (void ) {type_register_static (&igd_passthrough_i440fx_info); +type_register_static (&igd_passthrough_q35_info); }type_init (igd_register_types)
hw/pci-host/q35.c +5 -1
@@ -151,7 +151,11 @@ static void q35_host_initfn(Object *obj)memory_region_init_io (&phb->data_mem, obj, &pci_host_data_le_ops, phb,"pci-conf-data" ,4 ); -object_initialize (&s->mch,sizeof (s->mch),TYPE_MCH_PCI_DEVICE ); +if (object_property_get_bool (qdev_get_machine (),"igd-passthru" ,NULL )) { +object_initialize (&s->mch,sizeof (s->mch),"igd-passthrough-q35-mch" ); + }else { +object_initialize (&s->mch,sizeof (s->mch),TYPE_MCH_PCI_DEVICE ); + }object_property_add_child (OBJECT (s),"mch" ,OBJECT (&s->mch),NULL );qdev_prop_set_uint32 (DEVICE (&s->mch),"addr" ,PCI_DEVFN (0 ,0 ));qdev_prop_set_bit (DEVICE (&s->mch),"multifunction" , false);
Signature · 1 line
1.8.3.1
PATCH v2 9/10 igd: move igd-passthrough-isa-bridge to igd.c too
In reply to Gerd Hoffmann--- hw/i386/pc_piix.c | 113 ------------------------------------------------------ hw/pci-host/igd.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 113 deletions(-)
hw/i386/pc_piix.c +0 -113
@@ -921,119 +921,6 @@ static void pc_i440fx_0_10_machine_options(MachineClass *m)DEFINE_I440FX_MACHINE (v0_10,"pc-0.10" , pc_compat_0_13, pc_i440fx_0_10_machine_options); -typedef struct { -uint16_t gpu_device_id; -uint16_t pch_device_id; -uint8_t pch_revision_id; -}IGDDeviceIDInfo ; - -/* In real world different GPU should have different PCH. But actually -* the different PCH DIDs likely map to different PCH SKUs. We do the -* same thing for the GPU. For PCH, the different SKUs are going to be -* all the same silicon design and implementation, just different -* features turn on and off with fuses. The SW interfaces should be -* consistent across all SKUs in a given family (eg LPT). But just same -* features may not be supported. -* -* Most of these different PCH features probably don't matter to the -* Gfx driver, but obviously any difference in display port connections -* will so it should be fine with any PCH in case of passthrough. -* -* So currently use one PCH version, 0x8c4e, to cover all HSW(Haswell) -* scenarios, 0x9cc3 for BDW(Broadwell). -*/ -static const IGDDeviceIDInfo igd_combo_id_infos[] = { -/* HSW Classic */ - {0x0402 ,0x8c4e ,0x04 },/* HSWGT1D, HSWD_w7 */ - {0x0406 ,0x8c4e ,0x04 },/* HSWGT1M, HSWM_w7 */ - {0x0412 ,0x8c4e ,0x04 },/* HSWGT2D, HSWD_w7 */ - {0x0416 ,0x8c4e ,0x04 },/* HSWGT2M, HSWM_w7 */ - {0x041E ,0x8c4e ,0x04 },/* HSWGT15D, HSWD_w7 */ -/* HSW ULT */ - {0x0A06 ,0x8c4e ,0x04 },/* HSWGT1UT, HSWM_w7 */ - {0x0A16 ,0x8c4e ,0x04 },/* HSWGT2UT, HSWM_w7 */ - {0x0A26 ,0x8c4e ,0x06 },/* HSWGT3UT, HSWM_w7 */ - {0x0A2E ,0x8c4e ,0x04 },/* HSWGT3UT28W, HSWM_w7 */ - {0x0A1E ,0x8c4e ,0x04 },/* HSWGT2UX, HSWM_w7 */ - {0x0A0E ,0x8c4e ,0x04 },/* HSWGT1ULX, HSWM_w7 */ -/* HSW CRW */ - {0x0D26 ,0x8c4e ,0x04 },/* HSWGT3CW, HSWM_w7 */ - {0x0D22 ,0x8c4e ,0x04 },/* HSWGT3CWDT, HSWD_w7 */ -/* HSW Server */ - {0x041A ,0x8c4e ,0x04 },/* HSWSVGT2, HSWD_w7 */ -/* HSW SRVR */ - {0x040A ,0x8c4e ,0x04 },/* HSWSVGT1, HSWD_w7 */ -/* BSW */ - {0x1606 ,0x9cc3 ,0x03 },/* BDWULTGT1, BDWM_w7 */ - {0x1616 ,0x9cc3 ,0x03 },/* BDWULTGT2, BDWM_w7 */ - {0x1626 ,0x9cc3 ,0x03 },/* BDWULTGT3, BDWM_w7 */ - {0x160E ,0x9cc3 ,0x03 },/* BDWULXGT1, BDWM_w7 */ - {0x161E ,0x9cc3 ,0x03 },/* BDWULXGT2, BDWM_w7 */ - {0x1602 ,0x9cc3 ,0x03 },/* BDWHALOGT1, BDWM_w7 */ - {0x1612 ,0x9cc3 ,0x03 },/* BDWHALOGT2, BDWM_w7 */ - {0x1622 ,0x9cc3 ,0x03 },/* BDWHALOGT3, BDWM_w7 */ - {0x162B ,0x9cc3 ,0x03 },/* BDWHALO28W, BDWM_w7 */ - {0x162A ,0x9cc3 ,0x03 },/* BDWGT3WRKS, BDWM_w7 */ - {0x162D ,0x9cc3 ,0x03 },/* BDWGT3SRVR, BDWM_w7 */ -}; - -static void isa_bridge_class_init (ObjectClass *klass,void *data) -{ -DeviceClass *dc =DEVICE_CLASS (klass); -PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); - - dc->desc ="ISA bridge faked to support IGD PT" ; - k->vendor_id =PCI_VENDOR_ID_INTEL ; - k->class_id =PCI_CLASS_BRIDGE_ISA ; -}; - -static TypeInfo isa_bridge_info = { - .name ="igd-passthrough-isa-bridge" , - .parent =TYPE_PCI_DEVICE , - .instance_size =sizeof (PCIDevice), - .class_init = isa_bridge_class_init, -}; - -static void pt_graphics_register_types (void ) -{ -type_register_static (&isa_bridge_info); -} -type_init (pt_graphics_register_types) - -void igd_passthrough_isa_bridge_create(PCIBus *bus, uint16_t gpu_dev_id) -{ -struct PCIDevice *bridge_dev; -int i, num; -uint16_t pch_dev_id =0xffff ; -uint8_t pch_rev_id; - - num =ARRAY_SIZE (igd_combo_id_infos); -for (i =0 ; i < num; i++) { -if (gpu_dev_id == igd_combo_id_infos[i].gpu_device_id) { - pch_dev_id = igd_combo_id_infos[i].pch_device_id; - pch_rev_id = igd_combo_id_infos[i].pch_revision_id; - } - } - -if (pch_dev_id ==0xffff ) { -return ; - } - -/* Currently IGD drivers always need to access PCH by 1f.0. */ - bridge_dev =pci_create_simple (bus,PCI_DEVFN (0x1f ,0 ), -"igd-passthrough-isa-bridge" ); - -/* -* Note that vendor id is always PCI_VENDOR_ID_INTEL. -*/ -if (!bridge_dev) { -fprintf (stderr,"set igd-passthrough-isa-bridge failed!\n" ); -return ; - } -pci_config_set_device_id (bridge_dev->config, pch_dev_id); -pci_config_set_revision (bridge_dev->config, pch_rev_id); -} -static void isapc_machine_options (MachineClass *m) { m->desc ="ISA-only PC" ;
hw/pci-host/igd.c +108 -0
118 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 10/10 igd: handle igd-passthrough-isa-bridge setup in realize()
In reply to Gerd HoffmannThat way a simple '-device igd-passthrough-isa-bridge,addr=1f' will do the setup.
Also instead of looking up reasonable PCI IDs based on the graphic device id simply copy over the ids from the host, thereby reusing the infrastructure we have in place for the igd host bridges. Less code, and should be more robust as we don't have to maintain the id table to keep things going.
Note that igd-passthrough-isa-bridge will be needed for '-machine pc' only. For q35 the plan is https://lkml.org/lkml/2015/11/26/183 (should land in the next merge window, i.e. linux 4.5).
TODO: Figure if and how we are going to add this to the virtual machine automatically. The options I see are:
(1) Nothing automatic, users must add the device manually. This is what you get with this patch, except when running on xen.
(2) Do it the xen way, let the pci pass-thru code add it when it finds a igd device (i.e. vfio-pci for kvm). It's a bit ugly though, and it also has the problem that pc and q35 machine types have different needs here.
(3) Let machine init do it in case igd-passthru=on is set.
--- hw/pci-host/igd.c | 115 +++++++++++++----------------------------------------- 1 file changed, 28 insertions(+), 87 deletions(-)
hw/pci-host/igd.c +28 -87
@@ -123,111 +123,52 @@ static const TypeInfo igd_passthrough_q35_info = { .class_init = igd_passthrough_q35_class_init, }; -typedef struct { -uint16_t gpu_device_id; -uint16_t pch_device_id; -uint8_t pch_revision_id; -}IGDDeviceIDInfo ; - -/* In real world different GPU should have different PCH. But actually -* the different PCH DIDs likely map to different PCH SKUs. We do the -* same thing for the GPU. For PCH, the different SKUs are going to be -* all the same silicon design and implementation, just different -* features turn on and off with fuses. The SW interfaces should be -* consistent across all SKUs in a given family (eg LPT). But just same -* features may not be supported. -* -* Most of these different PCH features probably don't matter to the -* Gfx driver, but obviously any difference in display port connections -* will so it should be fine with any PCH in case of passthrough. -* -* So currently use one PCH version, 0x8c4e, to cover all HSW(Haswell) -* scenarios, 0x9cc3 for BDW(Broadwell). -*/ -static const IGDDeviceIDInfo igd_combo_id_infos[] = { -/* HSW Classic */ - {0x0402 ,0x8c4e ,0x04 },/* HSWGT1D, HSWD_w7 */ - {0x0406 ,0x8c4e ,0x04 },/* HSWGT1M, HSWM_w7 */ - {0x0412 ,0x8c4e ,0x04 },/* HSWGT2D, HSWD_w7 */ - {0x0416 ,0x8c4e ,0x04 },/* HSWGT2M, HSWM_w7 */ - {0x041E ,0x8c4e ,0x04 },/* HSWGT15D, HSWD_w7 */ -/* HSW ULT */ - {0x0A06 ,0x8c4e ,0x04 },/* HSWGT1UT, HSWM_w7 */ - {0x0A16 ,0x8c4e ,0x04 },/* HSWGT2UT, HSWM_w7 */ - {0x0A26 ,0x8c4e ,0x06 },/* HSWGT3UT, HSWM_w7 */ - {0x0A2E ,0x8c4e ,0x04 },/* HSWGT3UT28W, HSWM_w7 */ - {0x0A1E ,0x8c4e ,0x04 },/* HSWGT2UX, HSWM_w7 */ - {0x0A0E ,0x8c4e ,0x04 },/* HSWGT1ULX, HSWM_w7 */ -/* HSW CRW */ - {0x0D26 ,0x8c4e ,0x04 },/* HSWGT3CW, HSWM_w7 */ - {0x0D22 ,0x8c4e ,0x04 },/* HSWGT3CWDT, HSWD_w7 */ -/* HSW Server */ - {0x041A ,0x8c4e ,0x04 },/* HSWSVGT2, HSWD_w7 */ -/* HSW SRVR */ - {0x040A ,0x8c4e ,0x04 },/* HSWSVGT1, HSWD_w7 */ -/* BSW */ - {0x1606 ,0x9cc3 ,0x03 },/* BDWULTGT1, BDWM_w7 */ - {0x1616 ,0x9cc3 ,0x03 },/* BDWULTGT2, BDWM_w7 */ - {0x1626 ,0x9cc3 ,0x03 },/* BDWULTGT3, BDWM_w7 */ - {0x160E ,0x9cc3 ,0x03 },/* BDWULXGT1, BDWM_w7 */ - {0x161E ,0x9cc3 ,0x03 },/* BDWULXGT2, BDWM_w7 */ - {0x1602 ,0x9cc3 ,0x03 },/* BDWHALOGT1, BDWM_w7 */ - {0x1612 ,0x9cc3 ,0x03 },/* BDWHALOGT2, BDWM_w7 */ - {0x1622 ,0x9cc3 ,0x03 },/* BDWHALOGT3, BDWM_w7 */ - {0x162B ,0x9cc3 ,0x03 },/* BDWHALO28W, BDWM_w7 */ - {0x162A ,0x9cc3 ,0x03 },/* BDWGT3WRKS, BDWM_w7 */ - {0x162D ,0x9cc3 ,0x03 },/* BDWGT3SRVR, BDWM_w7 */ +static const IGDHostInfo igd_isa_bridge_infos[] = { + {PCI_VENDOR_ID ,2 }, + {PCI_DEVICE_ID ,2 }, + {PCI_REVISION_ID ,2 }, + {PCI_SUBSYSTEM_VENDOR_ID ,2 }, + {PCI_SUBSYSTEM_ID ,2 }, }; +static void igd_pt_isa_bridge_realize (PCIDevice *pci_dev,Error **errp) +{ +Error *err =NULL ; + +if (pci_dev->devfn !=PCI_DEVFN (0x1f ,0 )) { +error_setg (errp,"igd isa bridge must have address 1f.0" ); +return ; + } + +host_pci_config_copy (pci_dev,"0000:00:1f.0" , + igd_isa_bridge_infos, +ARRAY_SIZE (igd_isa_bridge_infos), + &err); +if (err !=NULL ) { +error_propagate (errp, err); +return ; + } +} +static void isa_bridge_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); - dc->desc ="ISA bridge faked to support IGD PT" ; - k->vendor_id =PCI_VENDOR_ID_INTEL ; + k->realize = igd_pt_isa_bridge_realize; k->class_id =PCI_CLASS_BRIDGE_ISA ; + dc->desc ="ISA bridge faked to support IGD PT" ; };static TypeInfo igd_passthrough_isa_bridge_info = { .name ="igd-passthrough-isa-bridge" , .parent =TYPE_PCI_DEVICE , - .instance_size =sizeof (PCIDevice), .class_init = isa_bridge_class_init, };void igd_passthrough_isa_bridge_create (PCIBus *bus,uint16_t gpu_dev_id) { -struct PCIDevice *bridge_dev; -int i, num; -uint16_t pch_dev_id =0xffff ; -uint8_t pch_rev_id; - - num =ARRAY_SIZE (igd_combo_id_infos); -for (i =0 ; i < num; i++) { -if (gpu_dev_id == igd_combo_id_infos[i].gpu_device_id) { - pch_dev_id = igd_combo_id_infos[i].pch_device_id; - pch_rev_id = igd_combo_id_infos[i].pch_revision_id; - } - } - -if (pch_dev_id ==0xffff ) { -return ; - } - -/* Currently IGD drivers always need to access PCH by 1f.0. */ - bridge_dev =pci_create_simple (bus,PCI_DEVFN (0x1f ,0 ), -"igd-passthrough-isa-bridge" ); - -/* -* Note that vendor id is always PCI_VENDOR_ID_INTEL. -*/ -if (!bridge_dev) { -fprintf (stderr,"set igd-passthrough-isa-bridge failed!\n" ); -return ; - } -pci_config_set_device_id (bridge_dev->config, pch_dev_id); -pci_config_set_revision (bridge_dev->config, pch_rev_id); +pci_create_simple (bus,PCI_DEVFN (0x1f ,0 ),"igd-passthrough-isa-bridge" ); }static void igd_register_types (void )
Signature · 1 line
1.8.3.1