From: Gerd Hoffmann <kraxel@redhat.com> To: kevin.tian@intel.com, Alex Williamson <alex.williamson@redhat.com>, Stefano Stabellini <stefano.stabellini@eu.citrix.com> Cc: "open list:All patches CC here" <qemu-devel@nongnu.org>, igvt-g@ml01.01.org, xen-devel@lists.xensource.com, Gerd Hoffmann <kraxel@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com> Subject: [Qemu-devel] [PATCH v4 2/8] pc: move igd support code to igd.c Date: Tue, 8 Mar 2016 15:27:21 +0100 [thread overview] Message-ID: <1457447247-4865-3-git-send-email-kraxel@redhat.com> (raw) In-Reply-To: <1457447247-4865-1-git-send-email-kraxel@redhat.com> Pure 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). Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> --- default-configs/x86_64-softmmu.mak | 1 + hw/pci-host/Makefile.objs | 3 ++ hw/pci-host/igd.c | 99 ++++++++++++++++++++++++++++++++++++++ hw/pci-host/piix.c | 90 ---------------------------------- 4 files changed, 103 insertions(+), 90 deletions(-) create mode 100644 hw/pci-host/igd.c diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/x86_64-softmmu.mak index 6e3b312..cd3340e 100644 --- a/default-configs/x86_64-softmmu.mak +++ b/default-configs/x86_64-softmmu.mak @@ -58,3 +58,4 @@ CONFIG_IOH3420=y CONFIG_I82801B11=y CONFIG_SMBIOS=y CONFIG_HYPERV_TESTDEV=$(CONFIG_KVM) +CONFIG_PCI_IGD=y diff --git a/hw/pci-host/Makefile.objs b/hw/pci-host/Makefile.objs index 45f1f0e..c03210b 100644 --- a/hw/pci-host/Makefile.objs +++ b/hw/pci-host/Makefile.objs @@ -16,3 +16,6 @@ common-obj-$(CONFIG_FULONG) += bonito.o common-obj-$(CONFIG_PCI_PIIX) += piix.o common-obj-$(CONFIG_PCI_Q35) += q35.o common-obj-$(CONFIG_PCI_GENERIC) += gpex.o + +# igd passthrough support +common-obj-$(CONFIG_PCI_IGD) += igd.o diff --git a/hw/pci-host/igd.c b/hw/pci-host/igd.c new file mode 100644 index 0000000..331e9e1 --- /dev/null +++ b/hw/pci-host/igd.c @@ -0,0 +1,99 @@ +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "hw/pci/pci.h" +#include "hw/i386/pc.h" + +/* 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[] = { + {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 */ +}; + +static int host_pci_config_read(int pos, int len, uint32_t *val) +{ + 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; + + if (rc >= size || rc < 0) { + return -ENODEV; + } + + config_fd = open(path, O_RDWR); + if (config_fd < 0) { + return -ENODEV; + } + + if (lseek(config_fd, pos, SEEK_SET) != pos) { + ret = -errno; + goto out; + } + + do { + rc = read(config_fd, (uint8_t *)val, len); + } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); + if (rc != len) { + ret = -errno; + } + +out: + close(config_fd); + return ret; +} + +static int igd_pt_i440fx_initfn(struct PCIDevice *pci_dev) +{ + uint32_t val = 0; + int rc, i, num; + int pos, len; + + 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) { + return -ENODEV; + } + pci_default_write_config(pci_dev, pos, val, len); + } + + return 0; +} + +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; + 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, + .class_init = igd_passthrough_i440fx_class_init, +}; + +static void igd_register_types(void) +{ + type_register_static(&igd_passthrough_i440fx_info); +} + +type_init(igd_register_types) diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c index 41aa66f..6eb8bff 100644 --- a/hw/pci-host/piix.c +++ b/hw/pci-host/piix.c @@ -747,95 +747,6 @@ static const TypeInfo i440fx_info = { .class_init = i440fx_class_init, }; -/* 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[] = { - {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 */ -}; - -static int host_pci_config_read(int pos, int len, uint32_t *val) -{ - 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; - - if (rc >= size || rc < 0) { - return -ENODEV; - } - - config_fd = open(path, O_RDWR); - if (config_fd < 0) { - return -ENODEV; - } - - if (lseek(config_fd, pos, SEEK_SET) != pos) { - ret = -errno; - goto out; - } - - do { - rc = read(config_fd, (uint8_t *)val, len); - } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); - if (rc != len) { - ret = -errno; - } - -out: - close(config_fd); - return ret; -} - -static int igd_pt_i440fx_initfn(struct PCIDevice *pci_dev) -{ - uint32_t val = 0; - int rc, i, num; - int pos, len; - - 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) { - return -ENODEV; - } - pci_default_write_config(pci_dev, pos, val, len); - } - - return 0; -} - -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; - 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) { @@ -877,7 +788,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(&piix3_pci_type_info); type_register_static(&piix3_info); type_register_static(&piix3_xen_info); -- 1.8.3.1
WARNING: multiple messages have this Message-ID (diff)
From: Gerd Hoffmann <kraxel@redhat.com> To: kevin.tian@intel.com, Alex Williamson <alex.williamson@redhat.com>, Stefano Stabellini <stefano.stabellini@eu.citrix.com> Cc: "open list:All patches CC here" <qemu-devel@nongnu.org>, igvt-g@ml01.01.org, xen-devel@lists.xensource.com, Gerd Hoffmann <kraxel@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com> Subject: [PATCH v4 2/8] pc: move igd support code to igd.c Date: Tue, 8 Mar 2016 15:27:21 +0100 [thread overview] Message-ID: <1457447247-4865-3-git-send-email-kraxel@redhat.com> (raw) In-Reply-To: <1457447247-4865-1-git-send-email-kraxel@redhat.com> Pure 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). Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> --- default-configs/x86_64-softmmu.mak | 1 + hw/pci-host/Makefile.objs | 3 ++ hw/pci-host/igd.c | 99 ++++++++++++++++++++++++++++++++++++++ hw/pci-host/piix.c | 90 ---------------------------------- 4 files changed, 103 insertions(+), 90 deletions(-) create mode 100644 hw/pci-host/igd.c diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/x86_64-softmmu.mak index 6e3b312..cd3340e 100644 --- a/default-configs/x86_64-softmmu.mak +++ b/default-configs/x86_64-softmmu.mak @@ -58,3 +58,4 @@ CONFIG_IOH3420=y CONFIG_I82801B11=y CONFIG_SMBIOS=y CONFIG_HYPERV_TESTDEV=$(CONFIG_KVM) +CONFIG_PCI_IGD=y diff --git a/hw/pci-host/Makefile.objs b/hw/pci-host/Makefile.objs index 45f1f0e..c03210b 100644 --- a/hw/pci-host/Makefile.objs +++ b/hw/pci-host/Makefile.objs @@ -16,3 +16,6 @@ common-obj-$(CONFIG_FULONG) += bonito.o common-obj-$(CONFIG_PCI_PIIX) += piix.o common-obj-$(CONFIG_PCI_Q35) += q35.o common-obj-$(CONFIG_PCI_GENERIC) += gpex.o + +# igd passthrough support +common-obj-$(CONFIG_PCI_IGD) += igd.o diff --git a/hw/pci-host/igd.c b/hw/pci-host/igd.c new file mode 100644 index 0000000..331e9e1 --- /dev/null +++ b/hw/pci-host/igd.c @@ -0,0 +1,99 @@ +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "hw/pci/pci.h" +#include "hw/i386/pc.h" + +/* 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[] = { + {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 */ +}; + +static int host_pci_config_read(int pos, int len, uint32_t *val) +{ + 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; + + if (rc >= size || rc < 0) { + return -ENODEV; + } + + config_fd = open(path, O_RDWR); + if (config_fd < 0) { + return -ENODEV; + } + + if (lseek(config_fd, pos, SEEK_SET) != pos) { + ret = -errno; + goto out; + } + + do { + rc = read(config_fd, (uint8_t *)val, len); + } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); + if (rc != len) { + ret = -errno; + } + +out: + close(config_fd); + return ret; +} + +static int igd_pt_i440fx_initfn(struct PCIDevice *pci_dev) +{ + uint32_t val = 0; + int rc, i, num; + int pos, len; + + 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) { + return -ENODEV; + } + pci_default_write_config(pci_dev, pos, val, len); + } + + return 0; +} + +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; + 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, + .class_init = igd_passthrough_i440fx_class_init, +}; + +static void igd_register_types(void) +{ + type_register_static(&igd_passthrough_i440fx_info); +} + +type_init(igd_register_types) diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c index 41aa66f..6eb8bff 100644 --- a/hw/pci-host/piix.c +++ b/hw/pci-host/piix.c @@ -747,95 +747,6 @@ static const TypeInfo i440fx_info = { .class_init = i440fx_class_init, }; -/* 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[] = { - {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 */ -}; - -static int host_pci_config_read(int pos, int len, uint32_t *val) -{ - 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; - - if (rc >= size || rc < 0) { - return -ENODEV; - } - - config_fd = open(path, O_RDWR); - if (config_fd < 0) { - return -ENODEV; - } - - if (lseek(config_fd, pos, SEEK_SET) != pos) { - ret = -errno; - goto out; - } - - do { - rc = read(config_fd, (uint8_t *)val, len); - } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); - if (rc != len) { - ret = -errno; - } - -out: - close(config_fd); - return ret; -} - -static int igd_pt_i440fx_initfn(struct PCIDevice *pci_dev) -{ - uint32_t val = 0; - int rc, i, num; - int pos, len; - - 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) { - return -ENODEV; - } - pci_default_write_config(pci_dev, pos, val, len); - } - - return 0; -} - -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; - 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) { @@ -877,7 +788,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(&piix3_pci_type_info); type_register_static(&piix3_info); type_register_static(&piix3_xen_info); -- 1.8.3.1
next prev parent reply other threads:[~2016-03-08 14:27 UTC|newest] Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top 2016-03-08 14:27 [PATCH v4 0/8] igd passthrough chipset tweaks Gerd Hoffmann 2016-03-08 14:27 ` [Qemu-devel] [PATCH v4 1/8] pc: remove has_igd_gfx_passthru global Gerd Hoffmann 2016-03-08 14:27 ` Gerd Hoffmann 2016-03-08 14:27 ` Gerd Hoffmann [this message] 2016-03-08 14:27 ` [PATCH v4 2/8] pc: move igd support code to igd.c Gerd Hoffmann 2016-03-09 15:08 ` [Qemu-devel] " Gerd Hoffmann 2016-03-09 15:08 ` Gerd Hoffmann 2016-03-10 5:56 ` [Qemu-devel] " Tian, Kevin 2016-03-10 5:56 ` Tian, Kevin 2016-03-10 17:51 ` [Qemu-devel] " Kay, Allen M 2016-03-10 17:51 ` Kay, Allen M 2016-03-08 14:27 ` [Qemu-devel] [PATCH v4 3/8] igd: switch TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE to realize Gerd Hoffmann 2016-03-08 14:27 ` Gerd Hoffmann 2016-03-08 14:27 ` [Qemu-devel] [PATCH v4 4/8] igd: TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE: call parent realize Gerd Hoffmann 2016-03-08 14:27 ` Gerd Hoffmann 2016-03-08 14:27 ` [Qemu-devel] [PATCH v4 5/8] igd: use defines for standard pci config space offsets Gerd Hoffmann 2016-03-08 14:27 ` Gerd Hoffmann 2016-03-08 14:27 ` [Qemu-devel] [PATCH v4 6/8] igd: revamp host config read Gerd Hoffmann 2016-03-08 14:27 ` Gerd Hoffmann 2016-03-08 14:27 ` [Qemu-devel] [PATCH v4 7/8] igd: move igd-passthrough-isa-bridge to igd.c too Gerd Hoffmann 2016-03-08 14:27 ` Gerd Hoffmann 2016-03-08 14:27 ` [Qemu-devel] [PATCH v4 8/8] igd: handle igd-passthrough-isa-bridge setup in realize() Gerd Hoffmann 2016-03-08 14:27 ` Gerd Hoffmann
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1457447247-4865-3-git-send-email-kraxel@redhat.com \ --to=kraxel@redhat.com \ --cc=alex.williamson@redhat.com \ --cc=igvt-g@ml01.01.org \ --cc=kevin.tian@intel.com \ --cc=mst@redhat.com \ --cc=qemu-devel@nongnu.org \ --cc=stefano.stabellini@eu.citrix.com \ --cc=xen-devel@lists.xensource.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.