hw/pci-host: Add Kconfig selector for IGD PCIe pass-through
v2 cover hw/pci-host: Add Kconfig selector for IGD PCIe pass-through
Introduce a kconfig selector to allow builds without Intel Integrated Graphics Device GPU PCIe passthrough.
We keep the default as enabled.
v2:
- do not mix with vfio code (Alex)
- extract to different file to avoid #ifdef (Thomas)
Philippe Mathieu-Daudé (6):
hw/pci-host/i440fx: Correct the header description hw/pci-host/i440fx: Extract PCII440FXState to "hw/pci-host/i440fx.h" hw/pci-host/i440fx: Use size_t to iterate over ARRAY_SIZE() hw/pci-host/i440fx: Use definitions instead of magic values hw/pci-host/i440fx: Extract the IGD Passthrough Host Bridge device hw/pci-host: Add Kconfig entry to select the IGD Passthrough Host Bridge
include/hw/pci-host/i440fx.h | 19 +++++- hw/pci-host/i440fx.c | 105 +----------------------------- hw/pci-host/igd_pt.c | 120 +++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/pci-host/Kconfig | 4 ++ hw/pci-host/Makefile.objs | 1 + 6 files changed, 144 insertions(+), 106 deletions(-) create mode 100644 hw/pci-host/igd_pt.c
Signature · 1 line
2.21.0
PATCH v2 1/6 hw/pci-host/i440fx: Correct the header description
Missed during the refactor in commits 14a026dd58 and 0f25d865a, this file is now only about the i440FX chipset.
--- hw/pci-host/i440fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/pci-host/i440fx.c +1 -1
@@ -1,5 +1,5 @@/* -* QEMU i440FX/PIIX3 PCI Bridge Emulation +* QEMU i440FX PCI Bridge Emulation * * Copyright (c) 2006 Fabrice Bellard *
Signature · 1 line
2.21.0
PATCH v2 2/6 hw/pci-host/i440fx: Extract PCII440FXState to "hw/pci-host/i440fx.h"
In reply to Philippe Mathieu-DaudéMake the PCII440FXState structure public, so it can be used out of this source file. This will allow us to extract the IGD Passthrough Host Bridge, which is a children of the TYPE_I440FX_PCI_DEVICE.
--- include/hw/pci-host/i440fx.h | 19 +++++++++++++++++-- hw/pci-host/i440fx.c | 18 ------------------ 2 files changed, 17 insertions(+), 20 deletions(-)
include/hw/pci-host/i440fx.h +17 -2
@@ -13,12 +13,27 @@#include "hw/hw.h" #include "hw/pci/pci_bus.h" - -typedef struct PCII440FXState PCII440FXState ; +#include "hw/pci-host/pam.h" #define TYPE_I440FX_PCI_HOST_BRIDGE "i440FX-pcihost"#define TYPE_I440FX_PCI_DEVICE "i440FX" +#define I440FX_PCI_DEVICE (obj) \ + OBJECT_CHECK(PCII440FXState, (obj), TYPE_I440FX_PCI_DEVICE) + +typedef struct PCII440FXState { +/*< private >*/ +PCIDevice parent_obj; +/*< public >*/ + +MemoryRegion *system_memory; +MemoryRegion *pci_address_space; +MemoryRegion *ram_memory; +PAMMemoryRegion pam_regions[13 ]; +MemoryRegion smram_region; +MemoryRegion smram, low_smram; +}PCII440FXState ; +#define TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE "igd-passthrough-i440FX" PCIBus *i440fx_init(const char *host_type, const char *pci_type,
hw/pci-host/i440fx.c +0 -18
@@ -31,7 +31,6 @@#include "hw/sysbus.h" #include "qapi/error.h" #include "migration/vmstate.h" -#include "hw/pci-host/pam.h" #include "qapi/visitor.h" #include "qemu/error-report.h"
@@ -51,23 +50,6 @@ typedef struct I440FXState {uint32_t short_root_bus; } I440FXState; -#define I440FX_PCI_DEVICE (obj) \ - OBJECT_CHECK(PCII440FXState, (obj), TYPE_I440FX_PCI_DEVICE) - -struct PCII440FXState { -/*< private >*/ -PCIDevice parent_obj; -/*< public >*/ - -MemoryRegion *system_memory; -MemoryRegion *pci_address_space; -MemoryRegion *ram_memory; -PAMMemoryRegion pam_regions[13 ]; -MemoryRegion smram_region; -MemoryRegion smram, low_smram; -}; - -#define I440FX_PAM 0x59#define I440FX_PAM_SIZE 7#define I440FX_SMRAM 0x72
Signature · 1 line
2.21.0
PATCH v2 3/6 hw/pci-host/i440fx: Use size_t to iterate over ARRAY_SIZE()
In reply to Philippe Mathieu-DaudéWe don't enforce the -Wsign-conversion CPPFLAG, but it doesn't hurt to avoid this warning:
warning: implicit conversion changes signedness: 'int' to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
--- hw/pci-host/i440fx.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
hw/pci-host/i440fx.c +2 -3
@@ -419,12 +419,11 @@ out:static void igd_pt_i440fx_realize (PCIDevice *pci_dev,Error **errp) {uint32_t val =0 ; -int i, num; +size_t i;int pos, len;Error *local_err =NULL ; - num =ARRAY_SIZE (igd_host_bridge_infos); -for (i =0 ; i < num; i++) { +for (i =0 ; i <ARRAY_SIZE (igd_host_bridge_infos); i++) { pos = igd_host_bridge_infos[i].offset; len = igd_host_bridge_infos[i].len;host_pci_config_read (pos, len, &val, &local_err);
Signature · 1 line
2.21.0
PATCH v2 4/6 hw/pci-host/i440fx: Use existing definitions instead of magic values
In reply to Philippe Mathieu-DaudéUse definitions from "hw/pci/pci_regs.h".
This also helps when using git-grep.
--- hw/pci-host/i440fx.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
hw/pci-host/i440fx.c +7 -7
@@ -376,13 +376,13 @@ 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 */ - {0x50 ,2 },/* SNB: processor graphics control register */ - {0x52 ,2 },/* processor graphics control register */ - {0xa4 ,4 },/* SNB: graphics base of stolen memory */ - {0xa8 ,4 },/* SNB: base of GTT stolen memory */ + {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 */ + {0xa8 ,4 },/* SNB: base of GTT stolen memory */ };static void host_pci_config_read (int pos,int len,uint32_t *val,Error **errp)
Signature · 1 line
2.21.0
PATCH v2 5/6 hw/pci-host/i440fx: Extract the IGD Passthrough Host Bridge device
In reply to Philippe Mathieu-DaudéWe can use a i440FX without the IGD passthrough host bridge.
Extract it into a new file, 'hw/pci-host/igd_pt.c'.
--- hw/pci-host/i440fx.c | 84 -------------------------- hw/pci-host/igd_pt.c | 120 ++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/pci-host/Makefile.objs | 1 + 4 files changed, 122 insertions(+), 84 deletions(-) create mode 100644 hw/pci-host/igd_pt.c
hw/pci-host/i440fx.c +0 -84
@@ -368,89 +368,6 @@ static const TypeInfo i440fx_info = { }, }; -/* IGD Passthrough Host Bridge. */ -typedef struct { -uint8_t offset; -uint8_t len; -}IGDHostInfo ; - -/* Here we just expose minimal host bridge offset subset. */ -static const IGDHostInfo igd_host_bridge_infos[] = { - {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 */ - {0xa8 ,4 },/* SNB: base of GTT stolen memory */ -}; - -static void host_pci_config_read (int pos,int len,uint32_t *val,Error **errp) -{ -int rc, config_fd; -/* Access real host bridge. */ -char *path =g_strdup_printf ("/sys/bus/pci/devices/%04x:%02x:%02x.%d/%s" , -0 ,0 ,0 ,0 ,"config" ); - - config_fd =open (path,O_RDWR ); -if (config_fd <0 ) { -error_setg_errno (errp, errno,"Failed to open: %s" , path); - goto out; - } - -if (lseek (config_fd, pos,SEEK_SET ) != pos) { -error_setg_errno (errp, errno,"Failed to seek: %s" , path); - goto out_close_fd; - } - -do { - rc =read (config_fd, (uint8_t *)val, len); - }while (rc <0 && (errno ==EINTR || errno ==EAGAIN )); -if (rc != len) { -error_setg_errno (errp, errno,"Failed to read: %s" , path); - } - -out_close_fd: -close (config_fd); -out: -g_free (path); -} - -static void igd_pt_i440fx_realize (PCIDevice *pci_dev,Error **errp) -{ -uint32_t val =0 ; -size_t i; -int pos, len; -Error *local_err =NULL ; - -for (i =0 ; i <ARRAY_SIZE (igd_host_bridge_infos); i++) { - pos = igd_host_bridge_infos[i].offset; - len = igd_host_bridge_infos[i].len; -host_pci_config_read (pos, len, &val, &local_err); -if (local_err) { -error_propagate (errp, local_err); -return ; - } -pci_default_write_config (pci_dev, pos, val, len); - } -} - -static void igd_passthrough_i440fx_class_init (ObjectClass *klass,void *data) -{ -DeviceClass *dc =DEVICE_CLASS (klass); -PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); - - k->realize = igd_pt_i440fx_realize; - dc->desc ="IGD Passthrough Host bridge" ; -} - -static const TypeInfo igd_passthrough_i440fx_info = { - .name =TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE , - .parent =TYPE_I440FX_PCI_DEVICE , - .instance_size =sizeof (PCII440FXState), - .class_init = igd_passthrough_i440fx_class_init, -}; -static const char *i440fx_pcihost_root_bus_path (PCIHostState *host_bridge,PCIBus *rootbus) {
@@ -495,7 +412,6 @@ static const TypeInfo i440fx_pcihost_info = {static void i440fx_register_types (void ) {type_register_static (&i440fx_info); -type_register_static (&igd_passthrough_i440fx_info);type_register_static (&i440fx_pcihost_info); }
hw/pci-host/igd_pt.c new file +120 -0
120 lines not on this page · raw message
MAINTAINERS +1 -0
@@ -1242,6 +1242,7 @@ S: Supported F: include/hw/i386/ F: hw/i386/ F: hw/pci-host/i440fx.c +F: hw/pci-host/igd_pt.c F: hw/pci-host/q35.c F: hw/pci-host/pam.c F: include/hw/pci-host/i440fx.h
hw/pci-host/Makefile.objs +1 -0
@@ -14,6 +14,7 @@ common-obj-$(CONFIG_VERSATILE_PCI) += versatile.o common-obj-$(CONFIG_PCI_SABRE) += sabre.o common-obj-$(CONFIG_FULONG) += bonito.o common-obj-$(CONFIG_PCI_I440FX) += i440fx.o +common-obj-$(CONFIG_PCI_I440FX) += igd_pt.o common-obj-$(CONFIG_PCI_EXPRESS_Q35) += q35.o common-obj-$(CONFIG_PCI_EXPRESS_GENERIC_BRIDGE) += gpex.o common-obj-$(CONFIG_PCI_EXPRESS_XILINX) += xilinx-pcie.o
Signature · 1 line
2.21.0
PATCH v2 6/6 hw/pci-host: Add Kconfig entry to select the IGD Passthrough Host Bridge
In reply to Philippe Mathieu-DaudéAdd the INTEL_IGD_PASSTHROUGH Kconfig option.
Since it is implied by the PCI_I440FX option, this does not change the default selection. However users are now able to deselelect it.
--- hw/pci-host/Kconfig | 4 ++++ hw/pci-host/Makefile.objs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-)
hw/pci-host/Kconfig +4 -0
@@ -1,6 +1,9 @@ config PAM bool +config INTEL_IGD_PASSTHROUGH + bool + config PREP_PCI bool select PCI
@@ -32,6 +35,7 @@ config PCI_I440FX bool select PCI select PAM + imply INTEL_IGD_PASSTHROUGH config PCI_EXPRESS_Q35 bool
hw/pci-host/Makefile.objs +1 -1
@@ -14,7 +14,7 @@ common-obj-$(CONFIG_VERSATILE_PCI) += versatile.o common-obj-$(CONFIG_PCI_SABRE) += sabre.o common-obj-$(CONFIG_FULONG) += bonito.o common-obj-$(CONFIG_PCI_I440FX) += i440fx.o -common-obj-$(CONFIG_PCI_I440FX) += igd_pt.o +common-obj-$(CONFIG_INTEL_IGD_PASSTHROUGH) += igd_pt.o common-obj-$(CONFIG_PCI_EXPRESS_Q35) += q35.o common-obj-$(CONFIG_PCI_EXPRESS_GENERIC_BRIDGE) += gpex.o common-obj-$(CONFIG_PCI_EXPRESS_XILINX) += xilinx-pcie.o
Signature · 1 line
2.21.0
Re: [PATCH-for-5.0 v2 6/6] hw/pci-host: Add Kconfig entry to select the IGD Passthrough Host Bridge
Quoted 16 lines · On Fri, 6 Dec 2019 18:25:14 +0100 Philippe Mathieu-Daudé <[email protected]>…
Add the
INTEL_IGD_PASSTHROUGHKconfigoption.Since it is implied by the
PCI_I440FXoption, this does not change the default selection. However users are now able to deselelect it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/pci-host/Kconfig | 4 ++++ hw/pci-host/Makefile.objs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-)hw/pci-host/Kconfig +0
-0
hw/pci-host/Kconfig line 5
Quoted 5 lines
hw/pci-host/Kconfig +2
-0@@ -1,6 +1,9 @@ config PAM bool +config INTEL_IGD_PASSTHROUGH + bool
I'd be tempted to suggest a 'depends on XEN' here and maybe use XEN in the config name and perhaps the file name in patch 5/6 as well. There's already confusion as to the extent that this is used generically between both Xen and vfio assignment (it's not), so might as well take this opportunity. Thanks,
Alex
Quoted 25 lines
hw/pci-host/Kconfig +2
-0+ config PREP_PCI bool select PCI@@ -32,6 +35,7 @@ config PCI_I440FX bool select PCI select PAM + imply INTEL_IGD_PASSTHROUGH config PCI_EXPRESS_Q35 boolhw/pci-host/Makefile.objs +1
-1@@ -14,7 +14,7 @@ common-obj-$(CONFIG_VERSATILE_PCI) += versatile.o common-obj-$(CONFIG_PCI_SABRE) += sabre.o common-obj-$(CONFIG_FULONG) += bonito.o common-obj-$(CONFIG_PCI_I440FX) += i440fx.o -common-obj-$(CONFIG_PCI_I440FX) += igd_pt.o +common-obj-$(CONFIG_INTEL_IGD_PASSTHROUGH) += igd_pt.o common-obj-$(CONFIG_PCI_EXPRESS_Q35) += q35.o common-obj-$(CONFIG_PCI_EXPRESS_GENERIC_BRIDGE) += gpex.o common-obj-$(CONFIG_PCI_EXPRESS_XILINX) += xilinx-pcie.o