Xen PCI Passthrough
v13 cover Xen PCI Passthrough
Hi all,
This patch series introduces the PCI passthrough for Xen.
Changes since the last version:
- New patch that introduce a new qdev-property pci-host-devaddr. => the "export pci_parse_devaddr" patch is not anymore usefull.
Thanks,
Allen Kay (2):
Introduce Xen PCI Passthrough, qdevice (1/3) Introduce Xen PCI Passthrough, PCI config space helpers (2/3)
Anthony PERARD (6):
pci_ids: Add INTEL_82599_SFP_VF id.
configure: Introduce --enable-xen-pci-passthrough. Introduce XenHostPCIDevice to access a pci device on the host. pci.c: Add opaque argument to pci_for_each_device.
qdev-properties: Introduce pci-host-devaddr. Introduce apic-msidef.h
Jiang Yunhong (1):
Introduce Xen PCI Passthrough, MSI (3/3)
configure | 29 + hw/apic-msidef.h | 30 + hw/apic.c | 11 +- hw/i386/Makefile.objs | 2 + hw/pci.c | 11 +- hw/pci.h | 4 +- hw/pci_ids.h | 1 + hw/qdev-properties.c | 107 +++ hw/qdev.h | 3 + hw/xen-host-pci-device.c | 396 ++++++++++ hw/xen-host-pci-device.h | 55 ++ hw/xen_common.h | 3 + hw/xen_platform.c | 8 +- hw/xen_pt.c | 851 +++++++++++++++++++++ hw/xen_pt.h | 301 ++++++++ hw/xen_pt_config_init.c | 1869 ++++++++++++++++++++++++++++++++++++++++++++++ hw/xen_pt_msi.c | 620 +++++++++++++++ qemu-common.h | 7 + xen-all.c | 12 + 19 files changed, 4301 insertions(+), 19 deletions(-) create mode 100644 hw/apic-msidef.h create mode 100644 hw/xen-host-pci-device.c create mode 100644 hw/xen-host-pci-device.h create mode 100644 hw/xen_pt.c create mode 100644 hw/xen_pt.h create mode 100644 hw/xen_pt_config_init.c create mode 100644 hw/xen_pt_msi.c
Signature · 1 line
Anthony PERARD
PATCH v13 1/9 pci_ids: Add INTEL_82599_SFP_VF id.
We are using this in our quirk lookup provided by patch
titled: Introduce Xen PCI Passthrough, PCI config space helpers.
--- hw/pci_ids.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
hw/pci_ids.h +1 -0
@@ -118,6 +118,7 @@#define PCI_DEVICE_ID_INTEL_82801I_UHCI6 0x2939#define PCI_DEVICE_ID_INTEL_82801I_EHCI1 0x293a#define PCI_DEVICE_ID_INTEL_82801I_EHCI2 0x293c +#define PCI_DEVICE_ID_INTEL_82599_SFP_VF 0x10ed#define PCI_VENDOR_ID_XEN 0x5853#define PCI_DEVICE_ID_XEN_PLATFORM 0x0001
Signature · 1 line
Anthony PERARD
Re: [Qemu-devel] [PATCH V13 1/9] pci_ids: Add INTEL_82599_SFP_VF id.
Quoted 5 lines · Anthony PERARD
We are using this in our quirk lookup provided by patch
titled: Introduce Xen PCI Passthrough, PCI config space helpers.Signed-off-by Anthony PERARD <[email protected]>
Quoted 18 lines
--- hw/pci_ids.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)hw/pci_ids.h +1
-0@@ -118,6 +118,7 @@#define PCI_DEVICE_ID_INTEL_82801I_UHCI6 0x2939#define PCI_DEVICE_ID_INTEL_82801I_EHCI1 0x293a#define PCI_DEVICE_ID_INTEL_82801I_EHCI2 0x293c +#define PCI_DEVICE_ID_INTEL_82599_SFP_VF 0x10ed#define PCI_VENDOR_ID_XEN 0x5853#define PCI_DEVICE_ID_XEN_PLATFORM 0x0001Signature · 1 line
Anthony PERARD
Re: [PATCH V13 1/9] pci_ids: Add INTEL_82599_SFP_VF id.
In reply to Anthony PERARDQuoted 5 lines · Anthony PERARD
We are using this in our quirk lookup provided by patch
titled: Introduce Xen PCI Passthrough, PCI config space helpers.Signed-off-by Anthony PERARD <[email protected]>
Quoted 18 lines
--- hw/pci_ids.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)hw/pci_ids.h +1
-0@@ -118,6 +118,7 @@#define PCI_DEVICE_ID_INTEL_82801I_UHCI6 0x2939#define PCI_DEVICE_ID_INTEL_82801I_EHCI1 0x293a#define PCI_DEVICE_ID_INTEL_82801I_EHCI2 0x293c +#define PCI_DEVICE_ID_INTEL_82599_SFP_VF 0x10ed#define PCI_VENDOR_ID_XEN 0x5853#define PCI_DEVICE_ID_XEN_PLATFORM 0x0001Signature · 1 line
Anthony PERARD
Re: [PATCH V13 1/9] pci_ids: Add INTEL_82599_SFP_VF id.
In reply to Anthony PERARDQuoted 5 lines · Anthony PERARD
We are using this in our quirk lookup provided by patch
titled: Introduce Xen PCI Passthrough, PCI config space helpers.Signed-off-by Anthony PERARD <[email protected]>
Quoted 24 lines
--- hw/pci_ids.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)hw/pci_ids.h +1
-0@@ -118,6 +118,7 @@#define PCI_DEVICE_ID_INTEL_82801I_UHCI6 0x2939#define PCI_DEVICE_ID_INTEL_82801I_EHCI1 0x293a#define PCI_DEVICE_ID_INTEL_82801I_EHCI2 0x293c +#define PCI_DEVICE_ID_INTEL_82599_SFP_VF 0x10ed#define PCI_VENDOR_ID_XEN 0x5853#define PCI_DEVICE_ID_XEN_PLATFORM 0x0001Signature · 7 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [Qemu-devel] [Xen-devel] [PATCH V13 1/9] pci_ids: Add INTEL_82599_SFP_VF id.
In reply to Anthony PERARDQuoted 5 lines · Anthony PERARD
We are using this in our quirk lookup provided by patch
titled: Introduce Xen PCI Passthrough, PCI config space helpers.Signed-off-by Anthony PERARD <[email protected]>
Quoted 24 lines
--- hw/pci_ids.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)hw/pci_ids.h +1
-0@@ -118,6 +118,7 @@#define PCI_DEVICE_ID_INTEL_82801I_UHCI6 0x2939#define PCI_DEVICE_ID_INTEL_82801I_EHCI1 0x293a#define PCI_DEVICE_ID_INTEL_82801I_EHCI2 0x293c +#define PCI_DEVICE_ID_INTEL_82599_SFP_VF 0x10ed#define PCI_VENDOR_ID_XEN 0x5853#define PCI_DEVICE_ID_XEN_PLATFORM 0x0001Signature · 7 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v13 2/9 configure: Introduce --enable-xen-pci-passthrough.
In reply to Anthony PERARD--- configure | 29 +++++++++++++++++++++++++++++ 1 files changed, 29 insertions(+), 0 deletions(-)
configure +29 -0
@@ -137,6 +137,7 @@ vnc_png="" vnc_thread="no" xen="" xen_ctrl_version="" +xen_pci_passthrough="" linux_aio="" cap_ng="" attr=""
@@ -685,6 +686,10 @@ for opt do ;; --enable-xen) xen="yes" ;; + --disable-xen-pci-passthrough) xen_pci_passthrough="no" + ;; + --enable-xen-pci-passthrough) xen_pci_passthrough="yes" + ;; --disable-brlapi) brlapi="no" ;; --enable-brlapi) brlapi="yes"
@@ -1032,6 +1037,8 @@ echo " (affects only QEMU, not qemu-img)" echo " --enable-mixemu enable mixer emulation" echo " --disable-xen disable xen backend driver support" echo " --enable-xen enable xen backend driver support" +echo " --disable-xen-pci-passthrough" +echo " --enable-xen-pci-passthrough" echo " --disable-brlapi disable BrlAPI" echo " --enable-brlapi enable BrlAPI" echo " --disable-vnc-tls disable TLS encryption for VNC server"
@@ -1508,6 +1515,25 @@ EOF fi fi +if test "$xen_pci_passthrough" != "no"; then + if test "$xen" = "yes" && test "$linux" = "yes" && + test "$xen_ctrl_version" -ge 340; then + xen_pci_passthrough=yes + else + if test "$xen_pci_passthrough" = "yes"; then + echo "ERROR" + echo "ERROR: User requested feature Xen PCI Passthrough" + echo "ERROR: but this feature require /sys from Linux" + if test "$xen_ctrl_version" -lt 340; then + echo "ERROR: This feature does not work with Xen 3.3" + fi + echo "ERROR" + exit 1; + fi + xen_pci_passthrough=no + fi +fi + ########################################## # pkg-config probe
@@ -3699,6 +3725,9 @@ case "$target_arch2" in if test "$xen" = "yes" -a "$target_softmmu" = "yes" ; then target_phys_bits=64 echo "CONFIG_XEN=y" >> $config_target_mak + if test "$xen_pci_passthrough" = yes; then + echo "CONFIG_XEN_PCI_PASSTHROUGH=y" >> "$config_target_mak" + fi else echo "CONFIG_NO_XEN=y" >> $config_target_mak fi
Signature · 1 line
Anthony PERARD
PATCH v13 2/9 configure: Introduce --enable-xen-pci-passthrough.
In reply to Anthony PERARD--- configure | 29 +++++++++++++++++++++++++++++ 1 files changed, 29 insertions(+), 0 deletions(-)
configure +29 -0
@@ -137,6 +137,7 @@ vnc_png="" vnc_thread="no" xen="" xen_ctrl_version="" +xen_pci_passthrough="" linux_aio="" cap_ng="" attr=""
@@ -685,6 +686,10 @@ for opt do ;; --enable-xen) xen="yes" ;; + --disable-xen-pci-passthrough) xen_pci_passthrough="no" + ;; + --enable-xen-pci-passthrough) xen_pci_passthrough="yes" + ;; --disable-brlapi) brlapi="no" ;; --enable-brlapi) brlapi="yes"
@@ -1032,6 +1037,8 @@ echo " (affects only QEMU, not qemu-img)" echo " --enable-mixemu enable mixer emulation" echo " --disable-xen disable xen backend driver support" echo " --enable-xen enable xen backend driver support" +echo " --disable-xen-pci-passthrough" +echo " --enable-xen-pci-passthrough" echo " --disable-brlapi disable BrlAPI" echo " --enable-brlapi enable BrlAPI" echo " --disable-vnc-tls disable TLS encryption for VNC server"
@@ -1508,6 +1515,25 @@ EOF fi fi +if test "$xen_pci_passthrough" != "no"; then + if test "$xen" = "yes" && test "$linux" = "yes" && + test "$xen_ctrl_version" -ge 340; then + xen_pci_passthrough=yes + else + if test "$xen_pci_passthrough" = "yes"; then + echo "ERROR" + echo "ERROR: User requested feature Xen PCI Passthrough" + echo "ERROR: but this feature require /sys from Linux" + if test "$xen_ctrl_version" -lt 340; then + echo "ERROR: This feature does not work with Xen 3.3" + fi + echo "ERROR" + exit 1; + fi + xen_pci_passthrough=no + fi +fi + ########################################## # pkg-config probe
@@ -3699,6 +3725,9 @@ case "$target_arch2" in if test "$xen" = "yes" -a "$target_softmmu" = "yes" ; then target_phys_bits=64 echo "CONFIG_XEN=y" >> $config_target_mak + if test "$xen_pci_passthrough" = yes; then + echo "CONFIG_XEN_PCI_PASSTHROUGH=y" >> "$config_target_mak" + fi else echo "CONFIG_NO_XEN=y" >> $config_target_mak fi
Signature · 1 line
Anthony PERARD
PATCH v13 3/9 Introduce XenHostPCIDevice to access a pci device on the host.
In reply to Anthony PERARD--- hw/i386/Makefile.objs | 1 + hw/xen-host-pci-device.c | 396 ++++++++++++++++++++++++++++++++++++++++++++++ hw/xen-host-pci-device.h | 55 +++++++ 3 files changed, 452 insertions(+), 0 deletions(-) create mode 100644 hw/xen-host-pci-device.c create mode 100644 hw/xen-host-pci-device.h
hw/i386/Makefile.objs +1 -0
@@ -7,6 +7,7 @@ obj-y += debugcon.o multiboot.o obj-y += pc_piix.o obj-y += pc_sysfw.o obj-$(CONFIG_XEN) += xen_platform.o xen_apic.o +obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o obj-$(CONFIG_KVM) += kvm/clock.o kvm/apic.o kvm/i8259.o kvm/ioapic.o kvm/i8254.o obj-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
hw/xen-host-pci-device.c new file +396 -0
396 lines not on this page · raw message
hw/xen-host-pci-device.h new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
Anthony PERARD
Re: [PATCH V13 3/9] Introduce XenHostPCIDevice to access a pci device on the host.
Quoted 1 line · Anthony PERARD
Signed-off-by Anthony PERARD <[email protected]>
Quoted 491 lines
--- hw/i386/Makefile.objs | 1 + hw/xen-host-pci-device.c | 396 ++++++++++++++++++++++++++++++++++++++++++++++ hw/xen-host-pci-device.h | 55 +++++++ 3 files changed, 452 insertions(+), 0 deletions(-) create mode 100644 hw/xen-host-pci-device.c create mode 100644 hw/xen-host-pci-device.hhw/i386/Makefile.objs +1
-0@@ -7,6 +7,7 @@ obj-y += debugcon.o multiboot.o obj-y += pc_piix.o obj-y += pc_sysfw.o obj-$(CONFIG_XEN) += xen_platform.o xen_apic.o +obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o obj-$(CONFIG_KVM) += kvm/clock.o kvm/apic.o kvm/i8259.o kvm/ioapic.o kvm/i8254.o obj-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.ohw/xen-host-pci-device.c new file +396
-0@@ -0,0 +1,396 @@ +/* +* Copyright (C) 2011 Citrix Ltd. +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +*/ + +#include "qemu-common.h" +#include "xen-host-pci-device.h" + +#define XEN_HOST_PCI_MAX_EXT_CAP \ + ((PCIE_CONFIG_SPACE_SIZE - PCI_CONFIG_SPACE_SIZE) / (PCI_CAP_SIZEOF + 4)) + +#ifdef XEN_HOST_PCI_DEVICE_DEBUG +# define XEN_HOST_PCI_LOG(f, a...) fprintf(stderr, "%s: " f, __func__, ##a) +#else +# define XEN_HOST_PCI_LOG(f, a...) (void)0 +#endif + +/* +* from linux/ioport.h +* IO resources have these defined flags. +*/ +#define IORESOURCE_BITS 0x000000ff/* Bus-specific bits */ + +#define IORESOURCE_TYPE_BITS 0x00000f00/* Resource type */ +#define IORESOURCE_IO 0x00000100 +#define IORESOURCE_MEM 0x00000200 + +#define IORESOURCE_PREFETCH 0x00001000/* No side effects */ +#define IORESOURCE_MEM_64 0x00100000 + +static int xen_host_pci_sysfs_path (const XenHostPCIDevice *d, +const char *name,char *buf,ssize_t size) +{ +int rc; + + rc =snprintf (buf, size,"/sys/bus/pci/devices/%04x:%02x:%02x.%d/%s" , + d->domain, d->bus, d->dev, d->func, name); + +if (rc >= size || rc <0 ) { +/* The ouput is truncated or an other error is encountered */ +return -ENODEV ; + } +return 0 ; +} + + +/* This size should be enough to read the first 7 lines of a ressource file */ +#define XEN_HOST_PCI_RESSOURCE_BUFFER_SIZE 400 +static int xen_host_pci_get_resource (XenHostPCIDevice *d) +{ +int i, rc, fd; +char path[PATH_MAX ]; +char buf[XEN_HOST_PCI_RESSOURCE_BUFFER_SIZE ]; +unsigned long long start, end, flags, size; +char *endptr, *s; +uint8_t type; + + rc =xen_host_pci_sysfs_path (d,"resource" , path,sizeof (path)); +if (rc) { +return rc; + } + fd =open (path,O_RDONLY ); +if (fd ==-1 ) { +XEN_HOST_PCI_LOG ("Error: Can't open %s: %s\n" , path,strerror (errno)); +return -errno; + } + +do { + rc =read (fd, &buf,sizeof (buf) -1 ); +if (rc <0 && errno !=EINTR ) { + rc = -errno; + goto out; + } + }while (rc <0 ); + buf[rc] =0 ; + rc =0 ; + + s = buf; +for (i =0 ; i <PCI_NUM_REGIONS ; i++) { + type =0 ; + + start =strtoll (s, &endptr,16 ); +if (*endptr !=' ' || s == endptr) { +break ; + } + s = endptr +1 ; + end =strtoll (s, &endptr,16 ); +if (*endptr !=' ' || s == endptr) { +break ; + } + s = endptr +1 ; + flags =strtoll (s, &endptr,16 ); +if (*endptr !='\n' || s == endptr) { +break ; + } + s = endptr +1 ; + +if (start) { + size = end - start +1 ; + }else { + size =0 ; + } + +if (flags &IORESOURCE_IO ) { + type |=XEN_HOST_PCI_REGION_TYPE_IO ; + } +if (flags &IORESOURCE_MEM ) { + type |=XEN_HOST_PCI_REGION_TYPE_MEM ; + } +if (flags &IORESOURCE_PREFETCH ) { + type |=XEN_HOST_PCI_REGION_TYPE_PREFETCH ; + } +if (flags &IORESOURCE_MEM_64 ) { + type |=XEN_HOST_PCI_REGION_TYPE_MEM_64 ; + } + +if (i <PCI_ROM_SLOT ) { + d->io_regions[i].base_addr = start; + d->io_regions[i].size = size; + d->io_regions[i].type = type; + d->io_regions[i].bus_flags = flags &IORESOURCE_BITS ; + }else { + d->rom.base_addr = start; + d->rom.size = size; + d->rom.type = type; + d->rom.bus_flags = flags &IORESOURCE_BITS ; + } + } +if (i !=PCI_NUM_REGIONS ) { +/* Invalid format or input to short */ + rc = -ENODEV ; + } + +out: +close (fd); +return rc; +} + +/* This size should be enough to read a long from a file */ +#define XEN_HOST_PCI_GET_VALUE_BUFFER_SIZE 22 +static int xen_host_pci_get_value (XenHostPCIDevice *d,const char *name, +unsigned int *pvalue,int base) +{ +char path[PATH_MAX ]; +char buf[XEN_HOST_PCI_GET_VALUE_BUFFER_SIZE ]; +int fd, rc; +unsigned long value; +char *endptr; + + rc =xen_host_pci_sysfs_path (d, name, path,sizeof (path)); +if (rc) { +return rc; + } + fd =open (path,O_RDONLY ); +if (fd ==-1 ) { +XEN_HOST_PCI_LOG ("Error: Can't open %s: %s\n" , path,strerror (errno)); +return -errno; + } +do { + rc =read (fd, &buf,sizeof (buf) -1 ); +if (rc <0 && errno !=EINTR ) { + rc = -errno; + goto out; + } + }while (rc <0 ); + buf[rc] =0 ; + value =strtol (buf, &endptr, base); +if (endptr == buf || *endptr !='\n' ) { + rc =-1 ; + }else if ((value ==LONG_MIN || value ==LONG_MAX ) && errno ==ERANGE ) { + rc = -errno; + }else { + rc =0 ; + *pvalue = value; + } +out: +close (fd); +return rc; +} + +static inline int xen_host_pci_get_hex_value (XenHostPCIDevice *d, +const char *name, +unsigned int *pvalue) +{ +return xen_host_pci_get_value (d, name, pvalue,16 ); +} + +static inline int xen_host_pci_get_dec_value (XenHostPCIDevice *d, +const char *name, +unsigned int *pvalue) +{ +return xen_host_pci_get_value (d, name, pvalue,10 ); +} + +static bool xen_host_pci_dev_is_virtfn (XenHostPCIDevice *d) +{ +char path[PATH_MAX ]; +struct stat buf; + +if (xen_host_pci_sysfs_path (d,"physfn" , path,sizeof (path))) { +return false; + } +return !stat (path, &buf); +} + +static int xen_host_pci_config_open (XenHostPCIDevice *d) +{ +char path[PATH_MAX ]; +int rc; + + rc =xen_host_pci_sysfs_path (d,"config" , path,sizeof (path)); +if (rc) { +return rc; + } + d->config_fd =open (path,O_RDWR ); +if (d->config_fd <0 ) { +return -errno; + } +return 0 ; +} + +static int xen_host_pci_config_read (XenHostPCIDevice *d, +int pos,void *buf,int len) +{ +int rc; + +do { + rc =pread (d->config_fd, buf, len, pos); + }while (rc <0 && (errno ==EINTR || errno ==EAGAIN )); +if (rc != len) { +return -errno; + } +return 0 ; +} + +static int xen_host_pci_config_write (XenHostPCIDevice *d, +int pos,const void *buf,int len) +{ +int rc; + +do { + rc =pwrite (d->config_fd, buf, len, pos); + }while (rc <0 && (errno ==EINTR || errno ==EAGAIN )); +if (rc != len) { +return -errno; + } +return 0 ; +} + + +int xen_host_pci_get_byte (XenHostPCIDevice *d,int pos,uint8_t *p) +{ +uint8_t buf; +int rc =xen_host_pci_config_read (d, pos, &buf,1 ); +if (!rc) { + *p = buf; + } +return rc; +} + +int xen_host_pci_get_word (XenHostPCIDevice *d,int pos,uint16_t *p) +{ +uint16_t buf; +int rc =xen_host_pci_config_read (d, pos, &buf,2 ); +if (!rc) { + *p =le16_to_cpu (buf); + } +return rc; +} + +int xen_host_pci_get_long (XenHostPCIDevice *d,int pos,uint32_t *p) +{ +uint32_t buf; +int rc =xen_host_pci_config_read (d, pos, &buf,4 ); +if (!rc) { + *p =le32_to_cpu (buf); + } +return rc; +} + +int xen_host_pci_get_block (XenHostPCIDevice *d,int pos,uint8_t *buf,int len) +{ +return xen_host_pci_config_read (d, pos, buf, len); +} + +int xen_host_pci_set_byte (XenHostPCIDevice *d,int pos,uint8_t data) +{ +return xen_host_pci_config_write (d, pos, &data,1 ); +} + +int xen_host_pci_set_word (XenHostPCIDevice *d,int pos,uint16_t data) +{ + data =cpu_to_le16 (data); +return xen_host_pci_config_write (d, pos, &data,2 ); +} + +int xen_host_pci_set_long (XenHostPCIDevice *d,int pos,uint32_t data) +{ + data =cpu_to_le32 (data); +return xen_host_pci_config_write (d, pos, &data,4 ); +} + +int xen_host_pci_set_block (XenHostPCIDevice *d,int pos,uint8_t *buf,int len) +{ +return xen_host_pci_config_write (d, pos, buf, len); +} + +int xen_host_pci_find_ext_cap_offset (XenHostPCIDevice *d,uint32_t cap) +{ +uint32_t header =0 ; +int max_cap =XEN_HOST_PCI_MAX_EXT_CAP ; +int pos =PCI_CONFIG_SPACE_SIZE ; + +do { +if (xen_host_pci_get_long (d, pos, &header)) { +break ; + } +/* +* If we have no capabilities, this is indicated by cap ID, +* cap version and next pointer all being 0. +*/ +if (header ==0 ) { +break ; + } + +if (PCI_EXT_CAP_ID (header) == cap) { +return pos; + } + + pos =PCI_EXT_CAP_NEXT (header); +if (pos <PCI_CONFIG_SPACE_SIZE ) { +break ; + } + + max_cap--; + }while (max_cap >0 ); + +return -1 ; +} + +int xen_host_pci_device_get (XenHostPCIDevice *d,uint16_t domain, +uint8_t bus,uint8_t dev,uint8_t func) +{ +unsigned int v; +int rc =0 ; + + d->config_fd =-1 ; + d->domain = domain; + d->bus = bus; + d->dev = dev; + d->func = func; + + rc =xen_host_pci_config_open (d); +if (rc) { + goto error; + } + rc =xen_host_pci_get_resource (d); +if (rc) { + goto error; + } + rc =xen_host_pci_get_hex_value (d,"vendor" , &v); +if (rc) { + goto error; + } + d->vendor_id = v; + rc =xen_host_pci_get_hex_value (d,"device" , &v); +if (rc) { + goto error; + } + d->device_id = v; + rc =xen_host_pci_get_dec_value (d,"irq" , &v); +if (rc) { + goto error; + } + d->irq = v; + d->is_virtfn =xen_host_pci_dev_is_virtfn (d); + +return 0 ; +error: +if (d->config_fd >=0 ) { +close (d->config_fd); + d->config_fd =-1 ; + } +return rc; +} + +void xen_host_pci_device_put (XenHostPCIDevice *d) +{ +if (d->config_fd >=0 ) { +close (d->config_fd); + d->config_fd =-1 ; + } +}hw/xen-host-pci-device.h new file +55
-0@@ -0,0 +1,55 @@ +#ifndef XEN_HOST_PCI_DEVICE_H +#define XEN_HOST_PCI_DEVICE_H + +#include "pci.h" + +enum { +XEN_HOST_PCI_REGION_TYPE_IO =1 <<1 , +XEN_HOST_PCI_REGION_TYPE_MEM =1 <<2 , +XEN_HOST_PCI_REGION_TYPE_PREFETCH =1 <<3 , +XEN_HOST_PCI_REGION_TYPE_MEM_64 =1 <<4 , +}; + +typedef struct XenHostPCIIORegion { +pcibus_t base_addr; +pcibus_t size; +uint8_t type; +uint8_t bus_flags;/* Bus-specific bits */ +}XenHostPCIIORegion ; + +typedef struct XenHostPCIDevice { +uint16_t domain; +uint8_t bus; +uint8_t dev; +uint8_t func; + +uint16_t vendor_id; +uint16_t device_id; +int irq; + +XenHostPCIIORegion io_regions[PCI_NUM_REGIONS -1 ]; +XenHostPCIIORegion rom; + +bool is_virtfn; + +int config_fd; +}XenHostPCIDevice ; + +int xen_host_pci_device_get (XenHostPCIDevice *d,uint16_t domain, +uint8_t bus,uint8_t dev,uint8_t func); +void xen_host_pci_device_put (XenHostPCIDevice *pci_dev); + +int xen_host_pci_get_byte (XenHostPCIDevice *d,int pos,uint8_t *p); +int xen_host_pci_get_word (XenHostPCIDevice *d,int pos,uint16_t *p); +int xen_host_pci_get_long (XenHostPCIDevice *d,int pos,uint32_t *p); +int xen_host_pci_get_block (XenHostPCIDevice *d,int pos,uint8_t *buf, +int len); +int xen_host_pci_set_byte (XenHostPCIDevice *d,int pos,uint8_t data); +int xen_host_pci_set_word (XenHostPCIDevice *d,int pos,uint16_t data); +int xen_host_pci_set_long (XenHostPCIDevice *d,int pos,uint32_t data); +int xen_host_pci_set_block (XenHostPCIDevice *d,int pos,uint8_t *buf, +int len); + +int xen_host_pci_find_ext_cap_offset (XenHostPCIDevice *s,uint32_t cap); + +#endif /* !XEN_HOST_PCI_DEVICE_H_ */ Signature · 7 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [Qemu-devel] [Xen-devel] [PATCH V13 3/9] Introduce XenHostPCIDevice to access a pci device on the host.
In reply to Anthony PERARDQuoted 1 line · Anthony PERARD
Signed-off-by Anthony PERARD <[email protected]>
Quoted 491 lines
--- hw/i386/Makefile.objs | 1 + hw/xen-host-pci-device.c | 396 ++++++++++++++++++++++++++++++++++++++++++++++ hw/xen-host-pci-device.h | 55 +++++++ 3 files changed, 452 insertions(+), 0 deletions(-) create mode 100644 hw/xen-host-pci-device.c create mode 100644 hw/xen-host-pci-device.hhw/i386/Makefile.objs +1
-0@@ -7,6 +7,7 @@ obj-y += debugcon.o multiboot.o obj-y += pc_piix.o obj-y += pc_sysfw.o obj-$(CONFIG_XEN) += xen_platform.o xen_apic.o +obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o obj-$(CONFIG_KVM) += kvm/clock.o kvm/apic.o kvm/i8259.o kvm/ioapic.o kvm/i8254.o obj-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.ohw/xen-host-pci-device.c new file +396
-0@@ -0,0 +1,396 @@ +/* +* Copyright (C) 2011 Citrix Ltd. +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +*/ + +#include "qemu-common.h" +#include "xen-host-pci-device.h" + +#define XEN_HOST_PCI_MAX_EXT_CAP \ + ((PCIE_CONFIG_SPACE_SIZE - PCI_CONFIG_SPACE_SIZE) / (PCI_CAP_SIZEOF + 4)) + +#ifdef XEN_HOST_PCI_DEVICE_DEBUG +# define XEN_HOST_PCI_LOG(f, a...) fprintf(stderr, "%s: " f, __func__, ##a) +#else +# define XEN_HOST_PCI_LOG(f, a...) (void)0 +#endif + +/* +* from linux/ioport.h +* IO resources have these defined flags. +*/ +#define IORESOURCE_BITS 0x000000ff/* Bus-specific bits */ + +#define IORESOURCE_TYPE_BITS 0x00000f00/* Resource type */ +#define IORESOURCE_IO 0x00000100 +#define IORESOURCE_MEM 0x00000200 + +#define IORESOURCE_PREFETCH 0x00001000/* No side effects */ +#define IORESOURCE_MEM_64 0x00100000 + +static int xen_host_pci_sysfs_path (const XenHostPCIDevice *d, +const char *name,char *buf,ssize_t size) +{ +int rc; + + rc =snprintf (buf, size,"/sys/bus/pci/devices/%04x:%02x:%02x.%d/%s" , + d->domain, d->bus, d->dev, d->func, name); + +if (rc >= size || rc <0 ) { +/* The ouput is truncated or an other error is encountered */ +return -ENODEV ; + } +return 0 ; +} + + +/* This size should be enough to read the first 7 lines of a ressource file */ +#define XEN_HOST_PCI_RESSOURCE_BUFFER_SIZE 400 +static int xen_host_pci_get_resource (XenHostPCIDevice *d) +{ +int i, rc, fd; +char path[PATH_MAX ]; +char buf[XEN_HOST_PCI_RESSOURCE_BUFFER_SIZE ]; +unsigned long long start, end, flags, size; +char *endptr, *s; +uint8_t type; + + rc =xen_host_pci_sysfs_path (d,"resource" , path,sizeof (path)); +if (rc) { +return rc; + } + fd =open (path,O_RDONLY ); +if (fd ==-1 ) { +XEN_HOST_PCI_LOG ("Error: Can't open %s: %s\n" , path,strerror (errno)); +return -errno; + } + +do { + rc =read (fd, &buf,sizeof (buf) -1 ); +if (rc <0 && errno !=EINTR ) { + rc = -errno; + goto out; + } + }while (rc <0 ); + buf[rc] =0 ; + rc =0 ; + + s = buf; +for (i =0 ; i <PCI_NUM_REGIONS ; i++) { + type =0 ; + + start =strtoll (s, &endptr,16 ); +if (*endptr !=' ' || s == endptr) { +break ; + } + s = endptr +1 ; + end =strtoll (s, &endptr,16 ); +if (*endptr !=' ' || s == endptr) { +break ; + } + s = endptr +1 ; + flags =strtoll (s, &endptr,16 ); +if (*endptr !='\n' || s == endptr) { +break ; + } + s = endptr +1 ; + +if (start) { + size = end - start +1 ; + }else { + size =0 ; + } + +if (flags &IORESOURCE_IO ) { + type |=XEN_HOST_PCI_REGION_TYPE_IO ; + } +if (flags &IORESOURCE_MEM ) { + type |=XEN_HOST_PCI_REGION_TYPE_MEM ; + } +if (flags &IORESOURCE_PREFETCH ) { + type |=XEN_HOST_PCI_REGION_TYPE_PREFETCH ; + } +if (flags &IORESOURCE_MEM_64 ) { + type |=XEN_HOST_PCI_REGION_TYPE_MEM_64 ; + } + +if (i <PCI_ROM_SLOT ) { + d->io_regions[i].base_addr = start; + d->io_regions[i].size = size; + d->io_regions[i].type = type; + d->io_regions[i].bus_flags = flags &IORESOURCE_BITS ; + }else { + d->rom.base_addr = start; + d->rom.size = size; + d->rom.type = type; + d->rom.bus_flags = flags &IORESOURCE_BITS ; + } + } +if (i !=PCI_NUM_REGIONS ) { +/* Invalid format or input to short */ + rc = -ENODEV ; + } + +out: +close (fd); +return rc; +} + +/* This size should be enough to read a long from a file */ +#define XEN_HOST_PCI_GET_VALUE_BUFFER_SIZE 22 +static int xen_host_pci_get_value (XenHostPCIDevice *d,const char *name, +unsigned int *pvalue,int base) +{ +char path[PATH_MAX ]; +char buf[XEN_HOST_PCI_GET_VALUE_BUFFER_SIZE ]; +int fd, rc; +unsigned long value; +char *endptr; + + rc =xen_host_pci_sysfs_path (d, name, path,sizeof (path)); +if (rc) { +return rc; + } + fd =open (path,O_RDONLY ); +if (fd ==-1 ) { +XEN_HOST_PCI_LOG ("Error: Can't open %s: %s\n" , path,strerror (errno)); +return -errno; + } +do { + rc =read (fd, &buf,sizeof (buf) -1 ); +if (rc <0 && errno !=EINTR ) { + rc = -errno; + goto out; + } + }while (rc <0 ); + buf[rc] =0 ; + value =strtol (buf, &endptr, base); +if (endptr == buf || *endptr !='\n' ) { + rc =-1 ; + }else if ((value ==LONG_MIN || value ==LONG_MAX ) && errno ==ERANGE ) { + rc = -errno; + }else { + rc =0 ; + *pvalue = value; + } +out: +close (fd); +return rc; +} + +static inline int xen_host_pci_get_hex_value (XenHostPCIDevice *d, +const char *name, +unsigned int *pvalue) +{ +return xen_host_pci_get_value (d, name, pvalue,16 ); +} + +static inline int xen_host_pci_get_dec_value (XenHostPCIDevice *d, +const char *name, +unsigned int *pvalue) +{ +return xen_host_pci_get_value (d, name, pvalue,10 ); +} + +static bool xen_host_pci_dev_is_virtfn (XenHostPCIDevice *d) +{ +char path[PATH_MAX ]; +struct stat buf; + +if (xen_host_pci_sysfs_path (d,"physfn" , path,sizeof (path))) { +return false; + } +return !stat (path, &buf); +} + +static int xen_host_pci_config_open (XenHostPCIDevice *d) +{ +char path[PATH_MAX ]; +int rc; + + rc =xen_host_pci_sysfs_path (d,"config" , path,sizeof (path)); +if (rc) { +return rc; + } + d->config_fd =open (path,O_RDWR ); +if (d->config_fd <0 ) { +return -errno; + } +return 0 ; +} + +static int xen_host_pci_config_read (XenHostPCIDevice *d, +int pos,void *buf,int len) +{ +int rc; + +do { + rc =pread (d->config_fd, buf, len, pos); + }while (rc <0 && (errno ==EINTR || errno ==EAGAIN )); +if (rc != len) { +return -errno; + } +return 0 ; +} + +static int xen_host_pci_config_write (XenHostPCIDevice *d, +int pos,const void *buf,int len) +{ +int rc; + +do { + rc =pwrite (d->config_fd, buf, len, pos); + }while (rc <0 && (errno ==EINTR || errno ==EAGAIN )); +if (rc != len) { +return -errno; + } +return 0 ; +} + + +int xen_host_pci_get_byte (XenHostPCIDevice *d,int pos,uint8_t *p) +{ +uint8_t buf; +int rc =xen_host_pci_config_read (d, pos, &buf,1 ); +if (!rc) { + *p = buf; + } +return rc; +} + +int xen_host_pci_get_word (XenHostPCIDevice *d,int pos,uint16_t *p) +{ +uint16_t buf; +int rc =xen_host_pci_config_read (d, pos, &buf,2 ); +if (!rc) { + *p =le16_to_cpu (buf); + } +return rc; +} + +int xen_host_pci_get_long (XenHostPCIDevice *d,int pos,uint32_t *p) +{ +uint32_t buf; +int rc =xen_host_pci_config_read (d, pos, &buf,4 ); +if (!rc) { + *p =le32_to_cpu (buf); + } +return rc; +} + +int xen_host_pci_get_block (XenHostPCIDevice *d,int pos,uint8_t *buf,int len) +{ +return xen_host_pci_config_read (d, pos, buf, len); +} + +int xen_host_pci_set_byte (XenHostPCIDevice *d,int pos,uint8_t data) +{ +return xen_host_pci_config_write (d, pos, &data,1 ); +} + +int xen_host_pci_set_word (XenHostPCIDevice *d,int pos,uint16_t data) +{ + data =cpu_to_le16 (data); +return xen_host_pci_config_write (d, pos, &data,2 ); +} + +int xen_host_pci_set_long (XenHostPCIDevice *d,int pos,uint32_t data) +{ + data =cpu_to_le32 (data); +return xen_host_pci_config_write (d, pos, &data,4 ); +} + +int xen_host_pci_set_block (XenHostPCIDevice *d,int pos,uint8_t *buf,int len) +{ +return xen_host_pci_config_write (d, pos, buf, len); +} + +int xen_host_pci_find_ext_cap_offset (XenHostPCIDevice *d,uint32_t cap) +{ +uint32_t header =0 ; +int max_cap =XEN_HOST_PCI_MAX_EXT_CAP ; +int pos =PCI_CONFIG_SPACE_SIZE ; + +do { +if (xen_host_pci_get_long (d, pos, &header)) { +break ; + } +/* +* If we have no capabilities, this is indicated by cap ID, +* cap version and next pointer all being 0. +*/ +if (header ==0 ) { +break ; + } + +if (PCI_EXT_CAP_ID (header) == cap) { +return pos; + } + + pos =PCI_EXT_CAP_NEXT (header); +if (pos <PCI_CONFIG_SPACE_SIZE ) { +break ; + } + + max_cap--; + }while (max_cap >0 ); + +return -1 ; +} + +int xen_host_pci_device_get (XenHostPCIDevice *d,uint16_t domain, +uint8_t bus,uint8_t dev,uint8_t func) +{ +unsigned int v; +int rc =0 ; + + d->config_fd =-1 ; + d->domain = domain; + d->bus = bus; + d->dev = dev; + d->func = func; + + rc =xen_host_pci_config_open (d); +if (rc) { + goto error; + } + rc =xen_host_pci_get_resource (d); +if (rc) { + goto error; + } + rc =xen_host_pci_get_hex_value (d,"vendor" , &v); +if (rc) { + goto error; + } + d->vendor_id = v; + rc =xen_host_pci_get_hex_value (d,"device" , &v); +if (rc) { + goto error; + } + d->device_id = v; + rc =xen_host_pci_get_dec_value (d,"irq" , &v); +if (rc) { + goto error; + } + d->irq = v; + d->is_virtfn =xen_host_pci_dev_is_virtfn (d); + +return 0 ; +error: +if (d->config_fd >=0 ) { +close (d->config_fd); + d->config_fd =-1 ; + } +return rc; +} + +void xen_host_pci_device_put (XenHostPCIDevice *d) +{ +if (d->config_fd >=0 ) { +close (d->config_fd); + d->config_fd =-1 ; + } +}hw/xen-host-pci-device.h new file +55
-0@@ -0,0 +1,55 @@ +#ifndef XEN_HOST_PCI_DEVICE_H +#define XEN_HOST_PCI_DEVICE_H + +#include "pci.h" + +enum { +XEN_HOST_PCI_REGION_TYPE_IO =1 <<1 , +XEN_HOST_PCI_REGION_TYPE_MEM =1 <<2 , +XEN_HOST_PCI_REGION_TYPE_PREFETCH =1 <<3 , +XEN_HOST_PCI_REGION_TYPE_MEM_64 =1 <<4 , +}; + +typedef struct XenHostPCIIORegion { +pcibus_t base_addr; +pcibus_t size; +uint8_t type; +uint8_t bus_flags;/* Bus-specific bits */ +}XenHostPCIIORegion ; + +typedef struct XenHostPCIDevice { +uint16_t domain; +uint8_t bus; +uint8_t dev; +uint8_t func; + +uint16_t vendor_id; +uint16_t device_id; +int irq; + +XenHostPCIIORegion io_regions[PCI_NUM_REGIONS -1 ]; +XenHostPCIIORegion rom; + +bool is_virtfn; + +int config_fd; +}XenHostPCIDevice ; + +int xen_host_pci_device_get (XenHostPCIDevice *d,uint16_t domain, +uint8_t bus,uint8_t dev,uint8_t func); +void xen_host_pci_device_put (XenHostPCIDevice *pci_dev); + +int xen_host_pci_get_byte (XenHostPCIDevice *d,int pos,uint8_t *p); +int xen_host_pci_get_word (XenHostPCIDevice *d,int pos,uint16_t *p); +int xen_host_pci_get_long (XenHostPCIDevice *d,int pos,uint32_t *p); +int xen_host_pci_get_block (XenHostPCIDevice *d,int pos,uint8_t *buf, +int len); +int xen_host_pci_set_byte (XenHostPCIDevice *d,int pos,uint8_t data); +int xen_host_pci_set_word (XenHostPCIDevice *d,int pos,uint16_t data); +int xen_host_pci_set_long (XenHostPCIDevice *d,int pos,uint32_t data); +int xen_host_pci_set_block (XenHostPCIDevice *d,int pos,uint8_t *buf, +int len); + +int xen_host_pci_find_ext_cap_offset (XenHostPCIDevice *s,uint32_t cap); + +#endif /* !XEN_HOST_PCI_DEVICE_H_ */ Signature · 7 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v13 4/9 pci.c: Add opaque argument to pci_for_each_device.
In reply to Anthony PERARDThe purpose is to have a more generic pci_for_each_device by passing an extra argument to the function called on every device.
This patch will be used in a next patch.
--- hw/pci.c | 11 +++++++---- hw/pci.h | 4 +++- hw/xen_platform.c | 8 ++++---- 3 files changed, 14 insertions(+), 9 deletions(-)
hw/pci.c +7 -4
@@ -1127,7 +1127,9 @@ static const pci_class_desc pci_class_descriptions[] = };static void pci_for_each_device_under_bus (PCIBus *bus, -void (*fn)(PCIBus *b,PCIDevice *d)) +void (*fn)(PCIBus *b,PCIDevice *d, +void *opaque), +void *opaque) {PCIDevice *d;int devfn;
@@ -1135,18 +1137,19 @@ static void pci_for_each_device_under_bus(PCIBus *bus,for (devfn =0 ; devfn <ARRAY_SIZE (bus->devices); devfn++) { d = bus->devices[devfn];if (d) { -fn (bus, d); +fn (bus, d, opaque); } } }void pci_for_each_device (PCIBus *bus,int bus_num, -void (*fn)(PCIBus *b,PCIDevice *d)) +void (*fn)(PCIBus *b,PCIDevice *d,void *opaque), +void *opaque) { bus =pci_find_bus_nr (bus, bus_num);if (bus) { -pci_for_each_device_under_bus (bus, fn); +pci_for_each_device_under_bus (bus, fn, opaque); } }
hw/pci.h +3 -1
@@ -312,7 +312,9 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,PCIDevice *pci_nic_init_nofail (NICInfo *nd,const char *default_model,const char *default_devaddr);int pci_bus_num (PCIBus *s); -void pci_for_each_device (PCIBus *bus,int bus_num,void (*fn)(PCIBus *bus,PCIDevice *d)); +void pci_for_each_device (PCIBus *bus,int bus_num, +void (*fn)(PCIBus *bus,PCIDevice *d,void *opaque), +void *opaque);PCIBus *pci_find_root_bus (int domain);int pci_find_domain (const PCIBus *bus);PCIDevice *pci_find_device (PCIBus *bus,int bus_num,uint8_t devfn);
hw/xen_platform.c +4 -4
@@ -83,7 +83,7 @@ static void log_writeb(PCIXenPlatformState *s, char val)#define UNPLUG_ALL_NICS 2#define UNPLUG_AUX_IDE_DISKS 4 -static void unplug_nic (PCIBus *b,PCIDevice *d) +static void unplug_nic (PCIBus *b,PCIDevice *d,void *o) {if (pci_get_word (d->config +PCI_CLASS_DEVICE ) ==PCI_CLASS_NETWORK_ETHERNET ) {
@@ -96,10 +96,10 @@ static void unplug_nic(PCIBus *b, PCIDevice *d)static void pci_unplug_nics (PCIBus *bus) { -pci_for_each_device (bus,0 , unplug_nic); +pci_for_each_device (bus,0 , unplug_nic,NULL ); } -static void unplug_disks (PCIBus *b,PCIDevice *d) +static void unplug_disks (PCIBus *b,PCIDevice *d,void *o) {if (pci_get_word (d->config +PCI_CLASS_DEVICE ) ==PCI_CLASS_STORAGE_IDE ) {
@@ -109,7 +109,7 @@ static void unplug_disks(PCIBus *b, PCIDevice *d)static void pci_unplug_disks (PCIBus *bus) { -pci_for_each_device (bus,0 , unplug_disks); +pci_for_each_device (bus,0 , unplug_disks,NULL ); }static void platform_fixed_ioport_writew (void *opaque,uint32_t addr,uint32_t val)
Signature · 1 line
Anthony PERARD
PATCH v13 4/9 pci.c: Add opaque argument to pci_for_each_device.
In reply to Anthony PERARDThe purpose is to have a more generic pci_for_each_device by passing an extra argument to the function called on every device.
This patch will be used in a next patch.
--- hw/pci.c | 11 +++++++---- hw/pci.h | 4 +++- hw/xen_platform.c | 8 ++++---- 3 files changed, 14 insertions(+), 9 deletions(-)
hw/pci.c +7 -4
@@ -1127,7 +1127,9 @@ static const pci_class_desc pci_class_descriptions[] = };static void pci_for_each_device_under_bus (PCIBus *bus, -void (*fn)(PCIBus *b,PCIDevice *d)) +void (*fn)(PCIBus *b,PCIDevice *d, +void *opaque), +void *opaque) {PCIDevice *d;int devfn;
@@ -1135,18 +1137,19 @@ static void pci_for_each_device_under_bus(PCIBus *bus,for (devfn =0 ; devfn <ARRAY_SIZE (bus->devices); devfn++) { d = bus->devices[devfn];if (d) { -fn (bus, d); +fn (bus, d, opaque); } } }void pci_for_each_device (PCIBus *bus,int bus_num, -void (*fn)(PCIBus *b,PCIDevice *d)) +void (*fn)(PCIBus *b,PCIDevice *d,void *opaque), +void *opaque) { bus =pci_find_bus_nr (bus, bus_num);if (bus) { -pci_for_each_device_under_bus (bus, fn); +pci_for_each_device_under_bus (bus, fn, opaque); } }
hw/pci.h +3 -1
@@ -312,7 +312,9 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,PCIDevice *pci_nic_init_nofail (NICInfo *nd,const char *default_model,const char *default_devaddr);int pci_bus_num (PCIBus *s); -void pci_for_each_device (PCIBus *bus,int bus_num,void (*fn)(PCIBus *bus,PCIDevice *d)); +void pci_for_each_device (PCIBus *bus,int bus_num, +void (*fn)(PCIBus *bus,PCIDevice *d,void *opaque), +void *opaque);PCIBus *pci_find_root_bus (int domain);int pci_find_domain (const PCIBus *bus);PCIDevice *pci_find_device (PCIBus *bus,int bus_num,uint8_t devfn);
hw/xen_platform.c +4 -4
@@ -83,7 +83,7 @@ static void log_writeb(PCIXenPlatformState *s, char val)#define UNPLUG_ALL_NICS 2#define UNPLUG_AUX_IDE_DISKS 4 -static void unplug_nic (PCIBus *b,PCIDevice *d) +static void unplug_nic (PCIBus *b,PCIDevice *d,void *o) {if (pci_get_word (d->config +PCI_CLASS_DEVICE ) ==PCI_CLASS_NETWORK_ETHERNET ) {
@@ -96,10 +96,10 @@ static void unplug_nic(PCIBus *b, PCIDevice *d)static void pci_unplug_nics (PCIBus *bus) { -pci_for_each_device (bus,0 , unplug_nic); +pci_for_each_device (bus,0 , unplug_nic,NULL ); } -static void unplug_disks (PCIBus *b,PCIDevice *d) +static void unplug_disks (PCIBus *b,PCIDevice *d,void *o) {if (pci_get_word (d->config +PCI_CLASS_DEVICE ) ==PCI_CLASS_STORAGE_IDE ) {
@@ -109,7 +109,7 @@ static void unplug_disks(PCIBus *b, PCIDevice *d)static void pci_unplug_disks (PCIBus *bus) { -pci_for_each_device (bus,0 , unplug_disks); +pci_for_each_device (bus,0 , unplug_disks,NULL ); }static void platform_fixed_ioport_writew (void *opaque,uint32_t addr,uint32_t val)
Signature · 1 line
Anthony PERARD
Re: [Qemu-devel] [PATCH V13 4/9] pci.c: Add opaque argument to pci_for_each_device.
Quoted 7 lines · Anthony PERARD
The purpose is to have a more generic
pci_for_each_deviceby passing an extra argument to the function called on every device.This patch will be used in a next patch.
Signed-off-by Anthony PERARD <[email protected]>
Quoted 96 lines
--- hw/pci.c | 11 +++++++---- hw/pci.h | 4 +++- hw/xen_platform.c | 8 ++++---- 3 files changed, 14 insertions(+), 9 deletions(-)hw/pci.c +7
-4@@ -1127,7 +1127,9 @@ static const pci_class_desc pci_class_descriptions[] = };static void pci_for_each_device_under_bus (PCIBus *bus, -void (*fn)(PCIBus *b,PCIDevice *d)) +void (*fn)(PCIBus *b,PCIDevice *d, +void *opaque), +void *opaque) {PCIDevice *d;int devfn;@@ -1135,18 +1137,19 @@ static void pci_for_each_device_under_bus(PCIBus *bus,for (devfn =0 ; devfn <ARRAY_SIZE (bus->devices); devfn++) { d = bus->devices[devfn];if (d) { -fn (bus, d); +fn (bus, d, opaque); } } }void pci_for_each_device (PCIBus *bus,int bus_num, -void (*fn)(PCIBus *b,PCIDevice *d)) +void (*fn)(PCIBus *b,PCIDevice *d,void *opaque), +void *opaque) { bus =pci_find_bus_nr (bus, bus_num);if (bus) { -pci_for_each_device_under_bus (bus, fn); +pci_for_each_device_under_bus (bus, fn, opaque); } }hw/pci.h +3
-1@@ -312,7 +312,9 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,PCIDevice *pci_nic_init_nofail (NICInfo *nd,const char *default_model,const char *default_devaddr);int pci_bus_num (PCIBus *s); -void pci_for_each_device (PCIBus *bus,int bus_num,void (*fn)(PCIBus *bus,PCIDevice *d)); +void pci_for_each_device (PCIBus *bus,int bus_num, +void (*fn)(PCIBus *bus,PCIDevice *d,void *opaque), +void *opaque);PCIBus *pci_find_root_bus (int domain);int pci_find_domain (const PCIBus *bus);PCIDevice *pci_find_device (PCIBus *bus,int bus_num,uint8_t devfn);hw/xen_platform.c +4
-4@@ -83,7 +83,7 @@ static void log_writeb(PCIXenPlatformState *s, char val)#define UNPLUG_ALL_NICS 2#define UNPLUG_AUX_IDE_DISKS 4 -static void unplug_nic (PCIBus *b,PCIDevice *d) +static void unplug_nic (PCIBus *b,PCIDevice *d,void *o) {if (pci_get_word (d->config +PCI_CLASS_DEVICE ) ==PCI_CLASS_NETWORK_ETHERNET ) {@@ -96,10 +96,10 @@ static void unplug_nic(PCIBus *b, PCIDevice *d)static void pci_unplug_nics (PCIBus *bus) { -pci_for_each_device (bus,0 , unplug_nic); +pci_for_each_device (bus,0 , unplug_nic,NULL ); } -static void unplug_disks (PCIBus *b,PCIDevice *d) +static void unplug_disks (PCIBus *b,PCIDevice *d,void *o) {if (pci_get_word (d->config +PCI_CLASS_DEVICE ) ==PCI_CLASS_STORAGE_IDE ) {@@ -109,7 +109,7 @@ static void unplug_disks(PCIBus *b, PCIDevice *d)static void pci_unplug_disks (PCIBus *bus) { -pci_for_each_device (bus,0 , unplug_disks); +pci_for_each_device (bus,0 , unplug_disks,NULL ); }static void platform_fixed_ioport_writew (void *opaque,uint32_t addr,uint32_t val)Signature · 1 line
Anthony PERARD
Re: [PATCH V13 4/9] pci.c: Add opaque argument to pci_for_each_device.
In reply to Anthony PERARDQuoted 7 lines · Anthony PERARD
The purpose is to have a more generic
pci_for_each_deviceby passing an extra argument to the function called on every device.This patch will be used in a next patch.
Signed-off-by Anthony PERARD <[email protected]>
Quoted 96 lines
--- hw/pci.c | 11 +++++++---- hw/pci.h | 4 +++- hw/xen_platform.c | 8 ++++---- 3 files changed, 14 insertions(+), 9 deletions(-)hw/pci.c +7
-4@@ -1127,7 +1127,9 @@ static const pci_class_desc pci_class_descriptions[] = };static void pci_for_each_device_under_bus (PCIBus *bus, -void (*fn)(PCIBus *b,PCIDevice *d)) +void (*fn)(PCIBus *b,PCIDevice *d, +void *opaque), +void *opaque) {PCIDevice *d;int devfn;@@ -1135,18 +1137,19 @@ static void pci_for_each_device_under_bus(PCIBus *bus,for (devfn =0 ; devfn <ARRAY_SIZE (bus->devices); devfn++) { d = bus->devices[devfn];if (d) { -fn (bus, d); +fn (bus, d, opaque); } } }void pci_for_each_device (PCIBus *bus,int bus_num, -void (*fn)(PCIBus *b,PCIDevice *d)) +void (*fn)(PCIBus *b,PCIDevice *d,void *opaque), +void *opaque) { bus =pci_find_bus_nr (bus, bus_num);if (bus) { -pci_for_each_device_under_bus (bus, fn); +pci_for_each_device_under_bus (bus, fn, opaque); } }hw/pci.h +3
-1@@ -312,7 +312,9 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,PCIDevice *pci_nic_init_nofail (NICInfo *nd,const char *default_model,const char *default_devaddr);int pci_bus_num (PCIBus *s); -void pci_for_each_device (PCIBus *bus,int bus_num,void (*fn)(PCIBus *bus,PCIDevice *d)); +void pci_for_each_device (PCIBus *bus,int bus_num, +void (*fn)(PCIBus *bus,PCIDevice *d,void *opaque), +void *opaque);PCIBus *pci_find_root_bus (int domain);int pci_find_domain (const PCIBus *bus);PCIDevice *pci_find_device (PCIBus *bus,int bus_num,uint8_t devfn);hw/xen_platform.c +4
-4@@ -83,7 +83,7 @@ static void log_writeb(PCIXenPlatformState *s, char val)#define UNPLUG_ALL_NICS 2#define UNPLUG_AUX_IDE_DISKS 4 -static void unplug_nic (PCIBus *b,PCIDevice *d) +static void unplug_nic (PCIBus *b,PCIDevice *d,void *o) {if (pci_get_word (d->config +PCI_CLASS_DEVICE ) ==PCI_CLASS_NETWORK_ETHERNET ) {@@ -96,10 +96,10 @@ static void unplug_nic(PCIBus *b, PCIDevice *d)static void pci_unplug_nics (PCIBus *bus) { -pci_for_each_device (bus,0 , unplug_nic); +pci_for_each_device (bus,0 , unplug_nic,NULL ); } -static void unplug_disks (PCIBus *b,PCIDevice *d) +static void unplug_disks (PCIBus *b,PCIDevice *d,void *o) {if (pci_get_word (d->config +PCI_CLASS_DEVICE ) ==PCI_CLASS_STORAGE_IDE ) {@@ -109,7 +109,7 @@ static void unplug_disks(PCIBus *b, PCIDevice *d)static void pci_unplug_disks (PCIBus *bus) { -pci_for_each_device (bus,0 , unplug_disks); +pci_for_each_device (bus,0 , unplug_disks,NULL ); }static void platform_fixed_ioport_writew (void *opaque,uint32_t addr,uint32_t val)Signature · 1 line
Anthony PERARD
Re: [PATCH V13 4/9] pci.c: Add opaque argument to pci_for_each_device.
In reply to Anthony PERARDQuoted 7 lines · Anthony PERARD
The purpose is to have a more generic
pci_for_each_deviceby passing an extra argument to the function called on every device.This patch will be used in a next patch.
Signed-off-by Anthony PERARD <[email protected]>
Quoted 102 lines
--- hw/pci.c | 11 +++++++---- hw/pci.h | 4 +++- hw/xen_platform.c | 8 ++++---- 3 files changed, 14 insertions(+), 9 deletions(-)hw/pci.c +7
-4@@ -1127,7 +1127,9 @@ static const pci_class_desc pci_class_descriptions[] = };static void pci_for_each_device_under_bus (PCIBus *bus, -void (*fn)(PCIBus *b,PCIDevice *d)) +void (*fn)(PCIBus *b,PCIDevice *d, +void *opaque), +void *opaque) {PCIDevice *d;int devfn;@@ -1135,18 +1137,19 @@ static void pci_for_each_device_under_bus(PCIBus *bus,for (devfn =0 ; devfn <ARRAY_SIZE (bus->devices); devfn++) { d = bus->devices[devfn];if (d) { -fn (bus, d); +fn (bus, d, opaque); } } }void pci_for_each_device (PCIBus *bus,int bus_num, -void (*fn)(PCIBus *b,PCIDevice *d)) +void (*fn)(PCIBus *b,PCIDevice *d,void *opaque), +void *opaque) { bus =pci_find_bus_nr (bus, bus_num);if (bus) { -pci_for_each_device_under_bus (bus, fn); +pci_for_each_device_under_bus (bus, fn, opaque); } }hw/pci.h +3
-1@@ -312,7 +312,9 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,PCIDevice *pci_nic_init_nofail (NICInfo *nd,const char *default_model,const char *default_devaddr);int pci_bus_num (PCIBus *s); -void pci_for_each_device (PCIBus *bus,int bus_num,void (*fn)(PCIBus *bus,PCIDevice *d)); +void pci_for_each_device (PCIBus *bus,int bus_num, +void (*fn)(PCIBus *bus,PCIDevice *d,void *opaque), +void *opaque);PCIBus *pci_find_root_bus (int domain);int pci_find_domain (const PCIBus *bus);PCIDevice *pci_find_device (PCIBus *bus,int bus_num,uint8_t devfn);hw/xen_platform.c +4
-4@@ -83,7 +83,7 @@ static void log_writeb(PCIXenPlatformState *s, char val)#define UNPLUG_ALL_NICS 2#define UNPLUG_AUX_IDE_DISKS 4 -static void unplug_nic (PCIBus *b,PCIDevice *d) +static void unplug_nic (PCIBus *b,PCIDevice *d,void *o) {if (pci_get_word (d->config +PCI_CLASS_DEVICE ) ==PCI_CLASS_NETWORK_ETHERNET ) {@@ -96,10 +96,10 @@ static void unplug_nic(PCIBus *b, PCIDevice *d)static void pci_unplug_nics (PCIBus *bus) { -pci_for_each_device (bus,0 , unplug_nic); +pci_for_each_device (bus,0 , unplug_nic,NULL ); } -static void unplug_disks (PCIBus *b,PCIDevice *d) +static void unplug_disks (PCIBus *b,PCIDevice *d,void *o) {if (pci_get_word (d->config +PCI_CLASS_DEVICE ) ==PCI_CLASS_STORAGE_IDE ) {@@ -109,7 +109,7 @@ static void unplug_disks(PCIBus *b, PCIDevice *d)static void pci_unplug_disks (PCIBus *bus) { -pci_for_each_device (bus,0 , unplug_disks); +pci_for_each_device (bus,0 , unplug_disks,NULL ); }static void platform_fixed_ioport_writew (void *opaque,uint32_t addr,uint32_t val)Signature · 7 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [Qemu-devel] [Xen-devel] [PATCH V13 4/9] pci.c: Add opaque argument to pci_for_each_device.
In reply to Anthony PERARDQuoted 7 lines · Anthony PERARD
The purpose is to have a more generic
pci_for_each_deviceby passing an extra argument to the function called on every device.This patch will be used in a next patch.
Signed-off-by Anthony PERARD <[email protected]>
Quoted 102 lines
--- hw/pci.c | 11 +++++++---- hw/pci.h | 4 +++- hw/xen_platform.c | 8 ++++---- 3 files changed, 14 insertions(+), 9 deletions(-)hw/pci.c +7
-4@@ -1127,7 +1127,9 @@ static const pci_class_desc pci_class_descriptions[] = };static void pci_for_each_device_under_bus (PCIBus *bus, -void (*fn)(PCIBus *b,PCIDevice *d)) +void (*fn)(PCIBus *b,PCIDevice *d, +void *opaque), +void *opaque) {PCIDevice *d;int devfn;@@ -1135,18 +1137,19 @@ static void pci_for_each_device_under_bus(PCIBus *bus,for (devfn =0 ; devfn <ARRAY_SIZE (bus->devices); devfn++) { d = bus->devices[devfn];if (d) { -fn (bus, d); +fn (bus, d, opaque); } } }void pci_for_each_device (PCIBus *bus,int bus_num, -void (*fn)(PCIBus *b,PCIDevice *d)) +void (*fn)(PCIBus *b,PCIDevice *d,void *opaque), +void *opaque) { bus =pci_find_bus_nr (bus, bus_num);if (bus) { -pci_for_each_device_under_bus (bus, fn); +pci_for_each_device_under_bus (bus, fn, opaque); } }hw/pci.h +3
-1@@ -312,7 +312,9 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,PCIDevice *pci_nic_init_nofail (NICInfo *nd,const char *default_model,const char *default_devaddr);int pci_bus_num (PCIBus *s); -void pci_for_each_device (PCIBus *bus,int bus_num,void (*fn)(PCIBus *bus,PCIDevice *d)); +void pci_for_each_device (PCIBus *bus,int bus_num, +void (*fn)(PCIBus *bus,PCIDevice *d,void *opaque), +void *opaque);PCIBus *pci_find_root_bus (int domain);int pci_find_domain (const PCIBus *bus);PCIDevice *pci_find_device (PCIBus *bus,int bus_num,uint8_t devfn);hw/xen_platform.c +4
-4@@ -83,7 +83,7 @@ static void log_writeb(PCIXenPlatformState *s, char val)#define UNPLUG_ALL_NICS 2#define UNPLUG_AUX_IDE_DISKS 4 -static void unplug_nic (PCIBus *b,PCIDevice *d) +static void unplug_nic (PCIBus *b,PCIDevice *d,void *o) {if (pci_get_word (d->config +PCI_CLASS_DEVICE ) ==PCI_CLASS_NETWORK_ETHERNET ) {@@ -96,10 +96,10 @@ static void unplug_nic(PCIBus *b, PCIDevice *d)static void pci_unplug_nics (PCIBus *bus) { -pci_for_each_device (bus,0 , unplug_nic); +pci_for_each_device (bus,0 , unplug_nic,NULL ); } -static void unplug_disks (PCIBus *b,PCIDevice *d) +static void unplug_disks (PCIBus *b,PCIDevice *d,void *o) {if (pci_get_word (d->config +PCI_CLASS_DEVICE ) ==PCI_CLASS_STORAGE_IDE ) {@@ -109,7 +109,7 @@ static void unplug_disks(PCIBus *b, PCIDevice *d)static void pci_unplug_disks (PCIBus *bus) { -pci_for_each_device (bus,0 , unplug_disks); +pci_for_each_device (bus,0 , unplug_disks,NULL ); }static void platform_fixed_ioport_writew (void *opaque,uint32_t addr,uint32_t val)Signature · 7 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v13 5/9 qdev-properties: Introduce pci-host-devaddr.
In reply to Anthony PERARDThis new property will be used to specify a host pci device address.
--- hw/qdev-properties.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 3 + qemu-common.h | 7 +++ 3 files changed, 117 insertions(+), 0 deletions(-)
hw/qdev-properties.c +107 -0
@@ -899,6 +899,113 @@ PropertyInfo qdev_prop_blocksize = { .set = set_blocksize, }; +/* --- pci host address --- */ + +static void get_pci_host_devaddr (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +DeviceState *dev =DEVICE (obj); +Property *prop = opaque; +PCIHostDeviceAddress *addr =qdev_get_prop_ptr (dev, prop); +char buffer[] ="xxxx:xx:xx.x" ; +char *p = buffer; +int rc =0 ; + + rc =snprintf (buffer,sizeof (buffer),"%04x:%02x:%02x.%d" , + addr->domain, addr->bus, addr->slot, addr->function); +assert (rc ==sizeof (buffer) -1 ); + +visit_type_str (v, &p, name, errp); +} + +/* +* Parse [<domain>:]<bus>:<slot>.<func> +* if <domain> is not supplied, it's assumed to be 0. +*/ +static void set_pci_host_devaddr (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +DeviceState *dev =DEVICE (obj); +Property *prop = opaque; +PCIHostDeviceAddress *addr =qdev_get_prop_ptr (dev, prop); +Error *local_err =NULL ; +char *str, *p; +char *e; +unsigned long val; +unsigned long dom =0 , bus =0 ; +unsigned int slot =0 , func =0 ; + +if (dev->state !=DEV_STATE_CREATED ) { +error_set (errp,QERR_PERMISSION_DENIED ); +return ; + } + +visit_type_str (v, &str, name, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + + p = str; + val =strtoul (p, &e,16 ); +if (e == p || *e !=':' ) { + goto inval; + } + bus = val; + + p = e +1 ; + val =strtoul (p, &e,16 ); +if (e == p) { + goto inval; + } +if (*e ==':' ) { + dom = bus; + bus = val; + p = e +1 ; + val =strtoul (p, &e,16 ); +if (e == p) { + goto inval; + } + } + slot = val; + +if (*e !='.' ) { + goto inval; + } + p = e +1 ; + val =strtoul (p, &e,10 ); +if (e == p) { + goto inval; + } + func = val; + +if (dom >0xffff || bus >0xff || slot >0x1f || func >7 ) { + goto inval; + } + +if (*e) { + goto inval; + } + + addr->domain = dom; + addr->bus = bus; + addr->slot = slot; + addr->function = func; + +g_free (str); +return ; + +inval: +error_set_from_qdev_prop_error (errp,EINVAL , dev, prop, str); +g_free (str); +} + +PropertyInfo qdev_prop_pci_host_devaddr = { + .name ="pci-host-devaddr" , + .get = get_pci_host_devaddr, + .set = set_pci_host_devaddr, +}; +/* --- public helpers --- */ static Property *qdev_prop_walk (Property *props,const char *name)
hw/qdev.h +3 -0
@@ -223,6 +223,7 @@ extern PropertyInfo qdev_prop_netdev;extern PropertyInfo qdev_prop_vlan;extern PropertyInfo qdev_prop_pci_devfn;extern PropertyInfo qdev_prop_blocksize; +extern PropertyInfo qdev_prop_pci_host_devaddr;#define DEFINE_PROP (_name, _state, _field, _prop, _type) { \ .name = (_name), \
@@ -286,6 +287,8 @@ extern PropertyInfo qdev_prop_blocksize; LostTickPolicy)#define DEFINE_PROP_BLOCKSIZE (_n, _s, _f, _d) \ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_blocksize, uint16_t) +#define DEFINE_PROP_PCI_HOST_DEVADDR (_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)#define DEFINE_PROP_END_OF_LIST () \ {}
qemu-common.h +7 -0
@@ -274,6 +274,13 @@ typedef enum LostTickPolicy { LOST_TICK_MAX } LostTickPolicy; +typedef struct PCIHostDeviceAddress { +unsigned int domain; +unsigned int bus; +unsigned int slot; +unsigned int function; +}PCIHostDeviceAddress ; +void tcg_exec_init (unsigned long tb_size);bool tcg_enabled (void );
Signature · 1 line
Anthony PERARD
PATCH v13 5/9 qdev-properties: Introduce pci-host-devaddr.
In reply to Anthony PERARDThis new property will be used to specify a host pci device address.
--- hw/qdev-properties.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 3 + qemu-common.h | 7 +++ 3 files changed, 117 insertions(+), 0 deletions(-)
hw/qdev-properties.c +107 -0
@@ -899,6 +899,113 @@ PropertyInfo qdev_prop_blocksize = { .set = set_blocksize, }; +/* --- pci host address --- */ + +static void get_pci_host_devaddr (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +DeviceState *dev =DEVICE (obj); +Property *prop = opaque; +PCIHostDeviceAddress *addr =qdev_get_prop_ptr (dev, prop); +char buffer[] ="xxxx:xx:xx.x" ; +char *p = buffer; +int rc =0 ; + + rc =snprintf (buffer,sizeof (buffer),"%04x:%02x:%02x.%d" , + addr->domain, addr->bus, addr->slot, addr->function); +assert (rc ==sizeof (buffer) -1 ); + +visit_type_str (v, &p, name, errp); +} + +/* +* Parse [<domain>:]<bus>:<slot>.<func> +* if <domain> is not supplied, it's assumed to be 0. +*/ +static void set_pci_host_devaddr (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +DeviceState *dev =DEVICE (obj); +Property *prop = opaque; +PCIHostDeviceAddress *addr =qdev_get_prop_ptr (dev, prop); +Error *local_err =NULL ; +char *str, *p; +char *e; +unsigned long val; +unsigned long dom =0 , bus =0 ; +unsigned int slot =0 , func =0 ; + +if (dev->state !=DEV_STATE_CREATED ) { +error_set (errp,QERR_PERMISSION_DENIED ); +return ; + } + +visit_type_str (v, &str, name, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + + p = str; + val =strtoul (p, &e,16 ); +if (e == p || *e !=':' ) { + goto inval; + } + bus = val; + + p = e +1 ; + val =strtoul (p, &e,16 ); +if (e == p) { + goto inval; + } +if (*e ==':' ) { + dom = bus; + bus = val; + p = e +1 ; + val =strtoul (p, &e,16 ); +if (e == p) { + goto inval; + } + } + slot = val; + +if (*e !='.' ) { + goto inval; + } + p = e +1 ; + val =strtoul (p, &e,10 ); +if (e == p) { + goto inval; + } + func = val; + +if (dom >0xffff || bus >0xff || slot >0x1f || func >7 ) { + goto inval; + } + +if (*e) { + goto inval; + } + + addr->domain = dom; + addr->bus = bus; + addr->slot = slot; + addr->function = func; + +g_free (str); +return ; + +inval: +error_set_from_qdev_prop_error (errp,EINVAL , dev, prop, str); +g_free (str); +} + +PropertyInfo qdev_prop_pci_host_devaddr = { + .name ="pci-host-devaddr" , + .get = get_pci_host_devaddr, + .set = set_pci_host_devaddr, +}; +/* --- public helpers --- */ static Property *qdev_prop_walk (Property *props,const char *name)
hw/qdev.h +3 -0
@@ -223,6 +223,7 @@ extern PropertyInfo qdev_prop_netdev;extern PropertyInfo qdev_prop_vlan;extern PropertyInfo qdev_prop_pci_devfn;extern PropertyInfo qdev_prop_blocksize; +extern PropertyInfo qdev_prop_pci_host_devaddr;#define DEFINE_PROP (_name, _state, _field, _prop, _type) { \ .name = (_name), \
@@ -286,6 +287,8 @@ extern PropertyInfo qdev_prop_blocksize; LostTickPolicy)#define DEFINE_PROP_BLOCKSIZE (_n, _s, _f, _d) \ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_blocksize, uint16_t) +#define DEFINE_PROP_PCI_HOST_DEVADDR (_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)#define DEFINE_PROP_END_OF_LIST () \ {}
qemu-common.h +7 -0
@@ -274,6 +274,13 @@ typedef enum LostTickPolicy { LOST_TICK_MAX } LostTickPolicy; +typedef struct PCIHostDeviceAddress { +unsigned int domain; +unsigned int bus; +unsigned int slot; +unsigned int function; +}PCIHostDeviceAddress ; +void tcg_exec_init (unsigned long tb_size);bool tcg_enabled (void );
Signature · 1 line
Anthony PERARD
Re: [Qemu-devel] [PATCH V13 5/9] qdev-properties: Introduce pci-host-devaddr.
Quoted 3 lines · Anthony PERARD
This new property will be used to specify a host pci device address.
Signed-off-by Anthony PERARD <[email protected]>
Quoted 165 lines
--- hw/qdev-properties.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 3 + qemu-common.h | 7 +++ 3 files changed, 117 insertions(+), 0 deletions(-)hw/qdev-properties.c +107
-0@@ -899,6 +899,113 @@ PropertyInfo qdev_prop_blocksize = { .set = set_blocksize, }; +/* --- pci host address --- */ + +static void get_pci_host_devaddr (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +DeviceState *dev =DEVICE (obj); +Property *prop = opaque; +PCIHostDeviceAddress *addr =qdev_get_prop_ptr (dev, prop); +char buffer[] ="xxxx:xx:xx.x" ; +char *p = buffer; +int rc =0 ; + + rc =snprintf (buffer,sizeof (buffer),"%04x:%02x:%02x.%d" , + addr->domain, addr->bus, addr->slot, addr->function); +assert (rc ==sizeof (buffer) -1 ); + +visit_type_str (v, &p, name, errp); +} + +/* +* Parse [<domain>:]<bus>:<slot>.<func> +* if <domain> is not supplied, it's assumed to be 0. +*/ +static void set_pci_host_devaddr (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +DeviceState *dev =DEVICE (obj); +Property *prop = opaque; +PCIHostDeviceAddress *addr =qdev_get_prop_ptr (dev, prop); +Error *local_err =NULL ; +char *str, *p; +char *e; +unsigned long val; +unsigned long dom =0 , bus =0 ; +unsigned int slot =0 , func =0 ; + +if (dev->state !=DEV_STATE_CREATED ) { +error_set (errp,QERR_PERMISSION_DENIED ); +return ; + } + +visit_type_str (v, &str, name, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + + p = str; + val =strtoul (p, &e,16 ); +if (e == p || *e !=':' ) { + goto inval; + } + bus = val; + + p = e +1 ; + val =strtoul (p, &e,16 ); +if (e == p) { + goto inval; + } +if (*e ==':' ) { + dom = bus; + bus = val; + p = e +1 ; + val =strtoul (p, &e,16 ); +if (e == p) { + goto inval; + } + } + slot = val; + +if (*e !='.' ) { + goto inval; + } + p = e +1 ; + val =strtoul (p, &e,10 ); +if (e == p) { + goto inval; + } + func = val; + +if (dom >0xffff || bus >0xff || slot >0x1f || func >7 ) { + goto inval; + } + +if (*e) { + goto inval; + } + + addr->domain = dom; + addr->bus = bus; + addr->slot = slot; + addr->function = func; + +g_free (str); +return ; + +inval: +error_set_from_qdev_prop_error (errp,EINVAL , dev, prop, str); +g_free (str); +} + +PropertyInfo qdev_prop_pci_host_devaddr = { + .name ="pci-host-devaddr" , + .get = get_pci_host_devaddr, + .set = set_pci_host_devaddr, +}; +/* --- public helpers --- */ static Property *qdev_prop_walk (Property *props,const char *name)hw/qdev.h +3
-0@@ -223,6 +223,7 @@ extern PropertyInfo qdev_prop_netdev;extern PropertyInfo qdev_prop_vlan;extern PropertyInfo qdev_prop_pci_devfn;extern PropertyInfo qdev_prop_blocksize; +extern PropertyInfo qdev_prop_pci_host_devaddr;#define DEFINE_PROP (_name, _state, _field, _prop, _type) { \ .name = (_name), \@@ -286,6 +287,8 @@ extern PropertyInfo qdev_prop_blocksize; LostTickPolicy)#define DEFINE_PROP_BLOCKSIZE (_n, _s, _f, _d) \ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_blocksize, uint16_t) +#define DEFINE_PROP_PCI_HOST_DEVADDR (_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)#define DEFINE_PROP_END_OF_LIST () \ {}qemu-common.h +7
-0@@ -274,6 +274,13 @@ typedef enum LostTickPolicy { LOST_TICK_MAX } LostTickPolicy; +typedef struct PCIHostDeviceAddress { +unsigned int domain; +unsigned int bus; +unsigned int slot; +unsigned int function; +}PCIHostDeviceAddress ; +void tcg_exec_init (unsigned long tb_size);bool tcg_enabled (void );Signature · 1 line
Anthony PERARD
Re: [PATCH V13 5/9] qdev-properties: Introduce pci-host-devaddr.
In reply to Anthony PERARDQuoted 3 lines · Anthony PERARD
This new property will be used to specify a host pci device address.
Signed-off-by Anthony PERARD <[email protected]>
Quoted 165 lines
--- hw/qdev-properties.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 3 + qemu-common.h | 7 +++ 3 files changed, 117 insertions(+), 0 deletions(-)hw/qdev-properties.c +107
-0@@ -899,6 +899,113 @@ PropertyInfo qdev_prop_blocksize = { .set = set_blocksize, }; +/* --- pci host address --- */ + +static void get_pci_host_devaddr (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +DeviceState *dev =DEVICE (obj); +Property *prop = opaque; +PCIHostDeviceAddress *addr =qdev_get_prop_ptr (dev, prop); +char buffer[] ="xxxx:xx:xx.x" ; +char *p = buffer; +int rc =0 ; + + rc =snprintf (buffer,sizeof (buffer),"%04x:%02x:%02x.%d" , + addr->domain, addr->bus, addr->slot, addr->function); +assert (rc ==sizeof (buffer) -1 ); + +visit_type_str (v, &p, name, errp); +} + +/* +* Parse [<domain>:]<bus>:<slot>.<func> +* if <domain> is not supplied, it's assumed to be 0. +*/ +static void set_pci_host_devaddr (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +DeviceState *dev =DEVICE (obj); +Property *prop = opaque; +PCIHostDeviceAddress *addr =qdev_get_prop_ptr (dev, prop); +Error *local_err =NULL ; +char *str, *p; +char *e; +unsigned long val; +unsigned long dom =0 , bus =0 ; +unsigned int slot =0 , func =0 ; + +if (dev->state !=DEV_STATE_CREATED ) { +error_set (errp,QERR_PERMISSION_DENIED ); +return ; + } + +visit_type_str (v, &str, name, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + + p = str; + val =strtoul (p, &e,16 ); +if (e == p || *e !=':' ) { + goto inval; + } + bus = val; + + p = e +1 ; + val =strtoul (p, &e,16 ); +if (e == p) { + goto inval; + } +if (*e ==':' ) { + dom = bus; + bus = val; + p = e +1 ; + val =strtoul (p, &e,16 ); +if (e == p) { + goto inval; + } + } + slot = val; + +if (*e !='.' ) { + goto inval; + } + p = e +1 ; + val =strtoul (p, &e,10 ); +if (e == p) { + goto inval; + } + func = val; + +if (dom >0xffff || bus >0xff || slot >0x1f || func >7 ) { + goto inval; + } + +if (*e) { + goto inval; + } + + addr->domain = dom; + addr->bus = bus; + addr->slot = slot; + addr->function = func; + +g_free (str); +return ; + +inval: +error_set_from_qdev_prop_error (errp,EINVAL , dev, prop, str); +g_free (str); +} + +PropertyInfo qdev_prop_pci_host_devaddr = { + .name ="pci-host-devaddr" , + .get = get_pci_host_devaddr, + .set = set_pci_host_devaddr, +}; +/* --- public helpers --- */ static Property *qdev_prop_walk (Property *props,const char *name)hw/qdev.h +3
-0@@ -223,6 +223,7 @@ extern PropertyInfo qdev_prop_netdev;extern PropertyInfo qdev_prop_vlan;extern PropertyInfo qdev_prop_pci_devfn;extern PropertyInfo qdev_prop_blocksize; +extern PropertyInfo qdev_prop_pci_host_devaddr;#define DEFINE_PROP (_name, _state, _field, _prop, _type) { \ .name = (_name), \@@ -286,6 +287,8 @@ extern PropertyInfo qdev_prop_blocksize; LostTickPolicy)#define DEFINE_PROP_BLOCKSIZE (_n, _s, _f, _d) \ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_blocksize, uint16_t) +#define DEFINE_PROP_PCI_HOST_DEVADDR (_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)#define DEFINE_PROP_END_OF_LIST () \ {}qemu-common.h +7
-0@@ -274,6 +274,13 @@ typedef enum LostTickPolicy { LOST_TICK_MAX } LostTickPolicy; +typedef struct PCIHostDeviceAddress { +unsigned int domain; +unsigned int bus; +unsigned int slot; +unsigned int function; +}PCIHostDeviceAddress ; +void tcg_exec_init (unsigned long tb_size);bool tcg_enabled (void );Signature · 1 line
Anthony PERARD
PATCH v13 6/9 Introduce Xen PCI Passthrough, qdevice (1/3)
In reply to Anthony PERARDFrom: Allen Kay <[email protected]>
A more complete history can be found here:git://xenbits.xensource.com/qemu-xen-unstable.git
--- hw/i386/Makefile.objs | 1 + hw/xen_common.h | 3 + hw/xen_pt.c | 812 +++++++++++++++++++++++++++++++++++++++++++++++ hw/xen_pt.h | 248 +++++++++++++++ hw/xen_pt_config_init.c | 11 + xen-all.c | 12 + 6 files changed, 1087 insertions(+), 0 deletions(-) create mode 100644 hw/xen_pt.c create mode 100644 hw/xen_pt.h create mode 100644 hw/xen_pt_config_init.c
hw/i386/Makefile.objs +1 -0
@@ -8,6 +8,7 @@ obj-y += pc_piix.o obj-y += pc_sysfw.o obj-$(CONFIG_XEN) += xen_platform.o xen_apic.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o +obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o obj-$(CONFIG_KVM) += kvm/clock.o kvm/apic.o kvm/i8259.o kvm/ioapic.o kvm/i8254.o obj-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
hw/xen_common.h +3 -0
@@ -150,4 +150,7 @@ static inline int xen_xc_hvm_inject_msi(XenXC xen_xc, domid_t dom,void destroy_hvm_domain (bool reboot); +/* shutdown/destroy current domain because of an error */ +void xen_shutdown_fatal_error(const char *fmt, ...) GCC_FMT_ATTR(1, 2); +#endif /* QEMU_HW_XEN_COMMON_H */
hw/xen_pt.c new file +812 -0
812 lines not on this page · raw message
hw/xen_pt.h new file +248 -0
248 lines not on this page · raw message
hw/xen_pt_config_init.c new file +11 -0
@@ -0,0 +1,11 @@ +#include "xen_pt.h" + +XenPTRegGroup *xen_pt_find_reg_grp (XenPCIPassthroughState *s,uint32_t address) +{ +return NULL ; +} + +XenPTReg *xen_pt_find_reg (XenPTRegGroup *reg_grp,uint32_t address) +{ +return NULL ; +}
xen-all.c +12 -0
@@ -1191,3 +1191,15 @@ void xen_register_framebuffer(MemoryRegion *mr) { framebuffer = mr; } + +void xen_shutdown_fatal_error (const char *fmt, ...) +{ +va_list ap; + +va_start (ap, fmt); +vfprintf (stderr, fmt, ap); +va_end (ap); +fprintf (stderr,"Will destroy the domain.\n" ); +/* destroy the domain */ +qemu_system_shutdown_request (); +}
Signature · 1 line
Anthony PERARD
PATCH v13 7/9 Introduce Xen PCI Passthrough, PCI config space helpers (2/3)
In reply to Anthony PERARDFrom: Allen Kay <[email protected]>
A more complete history can be found here:git://xenbits.xensource.com/qemu-xen-unstable.git
--- hw/xen_pt.c | 10 + hw/xen_pt.h | 2 + hw/xen_pt_config_init.c | 1387 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1399 insertions(+), 0 deletions(-)
hw/xen_pt.c +10 -0
@@ -673,6 +673,13 @@ static int xen_pt_initfn(PCIDevice *d)/* Handle real device's MMIO/PIO BARs */ xen_pt_register_regions (s); +/* reinitialize each config register to be emulated */ +if (xen_pt_config_init (s)) { +XEN_PT_ERR (d,"PCI Config space initialisation failed.\n" ); +xen_host_pci_device_put (&s->real_device); +return -1 ; + } +/* Bind interrupt */ if (!s->dev.config[PCI_INTERRUPT_PIN ]) {XEN_PT_LOG (d,"no pin interrupt\n" );
@@ -771,6 +778,9 @@ static int xen_pt_unregister_device(PCIDevice *d) } } +/* delete all emulated config registers */ +xen_pt_config_delete (s); +xen_pt_unregister_regions (s);memory_listener_unregister (&s->memory_listener);
hw/xen_pt.h +2 -0
@@ -62,6 +62,8 @@ typedef int (*xen_pt_conf_byte_read)#define XEN_PT_BAR_ALLF 0xFFFFFFFF#define XEN_PT_BAR_UNMAPPED (-1) +#define PCI_CAP_MAX 48 + typedef enum { XEN_PT_GRP_TYPE_HARDWIRED = 0, /* 0 Hardwired reg group */
hw/xen_pt_config_init.c +1387 -0
1,398 lines not on this page · raw message
Signature · 1 line
Anthony PERARD
PATCH v13 8/9 Introduce apic-msidef.h
In reply to Anthony PERARDThis patch move the msi definition from apic.c to apic-msidef.h. So it can be used also by other .c files.
--- hw/apic-msidef.h | 30 ++++++++++++++++++++++++++++++ hw/apic.c | 11 +---------- 2 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 hw/apic-msidef.h
hw/apic-msidef.h new file +30 -0
@@ -0,0 +1,30 @@ +#ifndef HW_APIC_MSIDEF_H +#define HW_APIC_MSIDEF_H + +/* +* Intel APIC constants: from include/asm/msidef.h +*/ + +/* +* Shifts for MSI data +*/ + +#define MSI_DATA_VECTOR_SHIFT 0 +#define MSI_DATA_VECTOR_MASK 0x000000ff + +#define MSI_DATA_DELIVERY_MODE_SHIFT 8 +#define MSI_DATA_LEVEL_SHIFT 14 +#define MSI_DATA_TRIGGER_SHIFT 15 + +/* +* Shift/mask fields for msi address +*/ + +#define MSI_ADDR_DEST_MODE_SHIFT 2 + +#define MSI_ADDR_REDIRECTION_SHIFT 3 + +#define MSI_ADDR_DEST_ID_SHIFT 12 +#define MSI_ADDR_DEST_ID_MASK 0x00ffff0 + +#endif /* HW_APIC_MSIDEF_H */
hw/apic.c +1 -10
@@ -23,19 +23,10 @@#include "host-utils.h" #include "trace.h" #include "pc.h" +#include "apic-msidef.h" #define MAX_APIC_WORDS 8 -/* Intel APIC constants: from include/asm/msidef.h */ -#define MSI_DATA_VECTOR_SHIFT 0 -#define MSI_DATA_VECTOR_MASK 0x000000ff -#define MSI_DATA_DELIVERY_MODE_SHIFT 8 -#define MSI_DATA_TRIGGER_SHIFT 15 -#define MSI_DATA_LEVEL_SHIFT 14 -#define MSI_ADDR_DEST_MODE_SHIFT 2 -#define MSI_ADDR_DEST_ID_SHIFT 12 -#define MSI_ADDR_DEST_ID_MASK 0x00ffff0 -#define SYNC_FROM_VAPIC 0x1#define SYNC_TO_VAPIC 0x2#define SYNC_ISR_IRR_TO_VAPIC 0x4
Signature · 1 line
Anthony PERARD
PATCH v13 8/9 Introduce apic-msidef.h
In reply to Anthony PERARDThis patch move the msi definition from apic.c to apic-msidef.h. So it can be used also by other .c files.
--- hw/apic-msidef.h | 30 ++++++++++++++++++++++++++++++ hw/apic.c | 11 +---------- 2 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 hw/apic-msidef.h
hw/apic-msidef.h new file +30 -0
@@ -0,0 +1,30 @@ +#ifndef HW_APIC_MSIDEF_H +#define HW_APIC_MSIDEF_H + +/* +* Intel APIC constants: from include/asm/msidef.h +*/ + +/* +* Shifts for MSI data +*/ + +#define MSI_DATA_VECTOR_SHIFT 0 +#define MSI_DATA_VECTOR_MASK 0x000000ff + +#define MSI_DATA_DELIVERY_MODE_SHIFT 8 +#define MSI_DATA_LEVEL_SHIFT 14 +#define MSI_DATA_TRIGGER_SHIFT 15 + +/* +* Shift/mask fields for msi address +*/ + +#define MSI_ADDR_DEST_MODE_SHIFT 2 + +#define MSI_ADDR_REDIRECTION_SHIFT 3 + +#define MSI_ADDR_DEST_ID_SHIFT 12 +#define MSI_ADDR_DEST_ID_MASK 0x00ffff0 + +#endif /* HW_APIC_MSIDEF_H */
hw/apic.c +1 -10
@@ -23,19 +23,10 @@#include "host-utils.h" #include "trace.h" #include "pc.h" +#include "apic-msidef.h" #define MAX_APIC_WORDS 8 -/* Intel APIC constants: from include/asm/msidef.h */ -#define MSI_DATA_VECTOR_SHIFT 0 -#define MSI_DATA_VECTOR_MASK 0x000000ff -#define MSI_DATA_DELIVERY_MODE_SHIFT 8 -#define MSI_DATA_TRIGGER_SHIFT 15 -#define MSI_DATA_LEVEL_SHIFT 14 -#define MSI_ADDR_DEST_MODE_SHIFT 2 -#define MSI_ADDR_DEST_ID_SHIFT 12 -#define MSI_ADDR_DEST_ID_MASK 0x00ffff0 -#define SYNC_FROM_VAPIC 0x1#define SYNC_TO_VAPIC 0x2#define SYNC_ISR_IRR_TO_VAPIC 0x4
Signature · 1 line
Anthony PERARD
Re: [Qemu-devel] [PATCH V13 8/9] Introduce apic-msidef.h
Quoted 5 lines · Anthony PERARD
This patch move the msi definition from
apic.ctoapic-msidef.h. So it can be used also by other .c files.Signed-off-by Anthony PERARD <[email protected]>
Quoted 69 lines
--- hw/apic-msidef.h | 30 ++++++++++++++++++++++++++++++ hw/apic.c | 11 +---------- 2 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 hw/apic-msidef.hhw/apic-msidef.h new file +30
-0@@ -0,0 +1,30 @@ +#ifndef HW_APIC_MSIDEF_H +#define HW_APIC_MSIDEF_H + +/* +* Intel APIC constants: from include/asm/msidef.h +*/ + +/* +* Shifts for MSI data +*/ + +#define MSI_DATA_VECTOR_SHIFT 0 +#define MSI_DATA_VECTOR_MASK 0x000000ff + +#define MSI_DATA_DELIVERY_MODE_SHIFT 8 +#define MSI_DATA_LEVEL_SHIFT 14 +#define MSI_DATA_TRIGGER_SHIFT 15 + +/* +* Shift/mask fields for msi address +*/ + +#define MSI_ADDR_DEST_MODE_SHIFT 2 + +#define MSI_ADDR_REDIRECTION_SHIFT 3 + +#define MSI_ADDR_DEST_ID_SHIFT 12 +#define MSI_ADDR_DEST_ID_MASK 0x00ffff0 + +#endif /* HW_APIC_MSIDEF_H */ hw/apic.c +1
-10@@ -23,19 +23,10 @@#include "host-utils.h" #include "trace.h" #include "pc.h" +#include "apic-msidef.h" #define MAX_APIC_WORDS 8 -/* Intel APIC constants: from include/asm/msidef.h */ -#define MSI_DATA_VECTOR_SHIFT 0 -#define MSI_DATA_VECTOR_MASK 0x000000ff -#define MSI_DATA_DELIVERY_MODE_SHIFT 8 -#define MSI_DATA_TRIGGER_SHIFT 15 -#define MSI_DATA_LEVEL_SHIFT 14 -#define MSI_ADDR_DEST_MODE_SHIFT 2 -#define MSI_ADDR_DEST_ID_SHIFT 12 -#define MSI_ADDR_DEST_ID_MASK 0x00ffff0 -#define SYNC_FROM_VAPIC 0x1#define SYNC_TO_VAPIC 0x2#define SYNC_ISR_IRR_TO_VAPIC 0x4Signature · 1 line
Anthony PERARD
Re: [PATCH V13 8/9] Introduce apic-msidef.h
In reply to Anthony PERARDQuoted 5 lines · Anthony PERARD
This patch move the msi definition from
apic.ctoapic-msidef.h. So it can be used also by other .c files.Signed-off-by Anthony PERARD <[email protected]>
Quoted 69 lines
--- hw/apic-msidef.h | 30 ++++++++++++++++++++++++++++++ hw/apic.c | 11 +---------- 2 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 hw/apic-msidef.hhw/apic-msidef.h new file +30
-0@@ -0,0 +1,30 @@ +#ifndef HW_APIC_MSIDEF_H +#define HW_APIC_MSIDEF_H + +/* +* Intel APIC constants: from include/asm/msidef.h +*/ + +/* +* Shifts for MSI data +*/ + +#define MSI_DATA_VECTOR_SHIFT 0 +#define MSI_DATA_VECTOR_MASK 0x000000ff + +#define MSI_DATA_DELIVERY_MODE_SHIFT 8 +#define MSI_DATA_LEVEL_SHIFT 14 +#define MSI_DATA_TRIGGER_SHIFT 15 + +/* +* Shift/mask fields for msi address +*/ + +#define MSI_ADDR_DEST_MODE_SHIFT 2 + +#define MSI_ADDR_REDIRECTION_SHIFT 3 + +#define MSI_ADDR_DEST_ID_SHIFT 12 +#define MSI_ADDR_DEST_ID_MASK 0x00ffff0 + +#endif /* HW_APIC_MSIDEF_H */ hw/apic.c +1
-10@@ -23,19 +23,10 @@#include "host-utils.h" #include "trace.h" #include "pc.h" +#include "apic-msidef.h" #define MAX_APIC_WORDS 8 -/* Intel APIC constants: from include/asm/msidef.h */ -#define MSI_DATA_VECTOR_SHIFT 0 -#define MSI_DATA_VECTOR_MASK 0x000000ff -#define MSI_DATA_DELIVERY_MODE_SHIFT 8 -#define MSI_DATA_TRIGGER_SHIFT 15 -#define MSI_DATA_LEVEL_SHIFT 14 -#define MSI_ADDR_DEST_MODE_SHIFT 2 -#define MSI_ADDR_DEST_ID_SHIFT 12 -#define MSI_ADDR_DEST_ID_MASK 0x00ffff0 -#define SYNC_FROM_VAPIC 0x1#define SYNC_TO_VAPIC 0x2#define SYNC_ISR_IRR_TO_VAPIC 0x4Signature · 1 line
Anthony PERARD
PATCH v13 9/9 Introduce Xen PCI Passthrough, MSI (3/3)
In reply to Anthony PERARDFrom: Jiang Yunhong <[email protected]>
A more complete history can be found here:git://xenbits.xensource.com/qemu-xen-unstable.git
--- hw/i386/Makefile.objs | 2 +- hw/xen_pt.c | 31 +++- hw/xen_pt.h | 51 ++++ hw/xen_pt_config_init.c | 471 +++++++++++++++++++++++++++++++++++ hw/xen_pt_msi.c | 620 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1173 insertions(+), 2 deletions(-) create mode 100644 hw/xen_pt_msi.c
hw/i386/Makefile.objs +1 -1
@@ -8,7 +8,7 @@ obj-y += pc_piix.o obj-y += pc_sysfw.o obj-$(CONFIG_XEN) += xen_platform.o xen_apic.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o -obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o +obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_msi.o obj-$(CONFIG_KVM) += kvm/clock.o kvm/apic.o kvm/i8259.o kvm/ioapic.o kvm/i8254.o obj-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
hw/xen_pt.c +30 -1
@@ -36,6 +36,20 @@* * Write '1' * - Set real bit to '1'. +* +* MSI interrupt: +* Initialize MSI register(xen_pt_msi_setup, xen_pt_msi_update) +* Bind MSI(xc_domain_update_msi_irq) +* <fail> +* - Unmap MSI. +* - Set dev->msi->pirq to '-1'. +* +* MSI-X interrupt: +* Initialize MSI-X register(xen_pt_msix_update_one) +* Bind MSI-X(xc_domain_update_msi_irq) +* <fail> +* - Unmap MSI-X. +* - Set entry->pirq to '-1'. */ #include <sys/ioctl.h>
@@ -534,7 +548,15 @@ static void xen_pt_region_update(XenPCIPassthroughState *s, }; bar =xen_pt_bar_from_region (s, mr); -if (bar ==-1 ) { +if (bar ==-1 && (!s->msix || &s->msix->mmio != mr)) { +return ; + } + +if (s->msix && &s->msix->mmio == mr) { +if (adding) { + s->msix->mmio_base_addr = sec->offset_within_address_space; + rc =xen_pt_msix_update_remap (s, s->msix->bar_index); + }return ; }
@@ -764,6 +786,13 @@ static int xen_pt_unregister_device(PCIDevice *d) } } +if (s->msi) { +xen_pt_msi_disable (s); + } +if (s->msix) { +xen_pt_msix_disable (s); + } +if (machine_irq) { xen_pt_mapped_machine_irq[machine_irq]--;
hw/xen_pt.h +51 -0
67 lines not on this page · raw message
hw/xen_pt_config_init.c +471 -0
501 lines not on this page · raw message
hw/xen_pt_msi.c new file +620 -0
620 lines not on this page · raw message
Signature · 1 line
Anthony PERARD
PATCH v13 9/9 Introduce Xen PCI Passthrough, MSI (3/3)
In reply to Anthony PERARDFrom: Jiang Yunhong <[email protected]>
A more complete history can be found here:git://xenbits.xensource.com/qemu-xen-unstable.git
--- hw/i386/Makefile.objs | 2 +- hw/xen_pt.c | 31 +++- hw/xen_pt.h | 51 ++++ hw/xen_pt_config_init.c | 471 +++++++++++++++++++++++++++++++++++ hw/xen_pt_msi.c | 620 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1173 insertions(+), 2 deletions(-) create mode 100644 hw/xen_pt_msi.c
hw/i386/Makefile.objs +1 -1
@@ -8,7 +8,7 @@ obj-y += pc_piix.o obj-y += pc_sysfw.o obj-$(CONFIG_XEN) += xen_platform.o xen_apic.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o -obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o +obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_msi.o obj-$(CONFIG_KVM) += kvm/clock.o kvm/apic.o kvm/i8259.o kvm/ioapic.o kvm/i8254.o obj-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
hw/xen_pt.c +30 -1
@@ -36,6 +36,20 @@* * Write '1' * - Set real bit to '1'. +* +* MSI interrupt: +* Initialize MSI register(xen_pt_msi_setup, xen_pt_msi_update) +* Bind MSI(xc_domain_update_msi_irq) +* <fail> +* - Unmap MSI. +* - Set dev->msi->pirq to '-1'. +* +* MSI-X interrupt: +* Initialize MSI-X register(xen_pt_msix_update_one) +* Bind MSI-X(xc_domain_update_msi_irq) +* <fail> +* - Unmap MSI-X. +* - Set entry->pirq to '-1'. */ #include <sys/ioctl.h>
@@ -534,7 +548,15 @@ static void xen_pt_region_update(XenPCIPassthroughState *s, }; bar =xen_pt_bar_from_region (s, mr); -if (bar ==-1 ) { +if (bar ==-1 && (!s->msix || &s->msix->mmio != mr)) { +return ; + } + +if (s->msix && &s->msix->mmio == mr) { +if (adding) { + s->msix->mmio_base_addr = sec->offset_within_address_space; + rc =xen_pt_msix_update_remap (s, s->msix->bar_index); + }return ; }
@@ -764,6 +786,13 @@ static int xen_pt_unregister_device(PCIDevice *d) } } +if (s->msi) { +xen_pt_msi_disable (s); + } +if (s->msix) { +xen_pt_msix_disable (s); + } +if (machine_irq) { xen_pt_mapped_machine_irq[machine_irq]--;
hw/xen_pt.h +51 -0
67 lines not on this page · raw message
hw/xen_pt_config_init.c +471 -0
501 lines not on this page · raw message
hw/xen_pt_msi.c new file +620 -0
620 lines not on this page · raw message
Signature · 1 line
Anthony PERARD
Quoted 9 lines · Anthony PERARD
Hi all,
This patch series introduces the PCI passthrough for Xen.
Changes since the last version:
- New patch that introduce a new qdev-property pci-host-devaddr. => the "exportpci_parse_devaddr" patch is not anymore usefull.Thanks,
I reviewed some patches and Acked. Won't have the time to review the rest of the series short term.
If you need me to merge some of these patches myself pls let me know.
Quoted 45 lines
Allen Kay (2):
Introduce Xen PCI Passthrough, qdevice (1/3) Introduce Xen PCI Passthrough, PCI config space helpers (2/3)Anthony PERARD (6):
pci_ids: AddINTEL_82599_SFP_VFid.
configure: Introduce --enable-xen-pci-passthrough. Introduce XenHostPCIDevice to access a pci device on the host.pci.c: Add opaque argument topci_for_each_device.
qdev-properties: Introduce pci-host-devaddr. Introduceapic-msidef.hJiang Yunhong (1):
Introduce Xen PCI Passthrough, MSI (3/3)configure | 29 + hw/apic-msidef.h | 30 + hw/apic.c | 11 +- hw/i386/Makefile.objs | 2 + hw/pci.c | 11 +- hw/pci.h | 4 +- hw/pci_ids.h | 1 + hw/qdev-properties.c | 107 +++ hw/qdev.h | 3 + hw/xen-host-pci-device.c | 396 ++++++++++ hw/xen-host-pci-device.h | 55 ++ hw/xen_common.h | 3 + hw/xen_platform.c | 8 +- hw/xen_pt.c | 851 +++++++++++++++++++++ hw/xen_pt.h | 301 ++++++++ hw/xen_pt_config_init.c | 1869 ++++++++++++++++++++++++++++++++++++++++++++++ hw/xen_pt_msi.c | 620 +++++++++++++++ qemu-common.h | 7 + xen-all.c | 12 + 19 files changed, 4301 insertions(+), 19 deletions(-) create mode 100644 hw/apic-msidef.h create mode 100644 hw/xen-host-pci-device.c create mode 100644 hw/xen-host-pci-device.h create mode 100644 hw/xen_pt.c create mode 100644 hw/xen_pt.h create mode 100644 hw/xen_pt_config_init.c create mode 100644 hw/xen_pt_msi.cSignature · 1 line
Anthony PERARD
Quoted 9 lines · Michael S. Tsirkin
Quoted 8 lines · Anthony PERARD
Hi all,
This patch series introduces the PCI passthrough for Xen.
Changes since the last version:
- New patch that introduce a new qdev-property pci-host-devaddr. => the "exportpci_parse_devaddr" patch is not anymore usefull.
Quoted 6 lines
Quoted 1 line
Thanks,
I reviewed some patches and Acked. Won't have the time to review the rest of the series short term.
If you need me to merge some of these patches myself pls let me know.
Considering that you Acked all the non-Xen patches (apart from the configure patch), I think I'll just go ahead and submit a pull request to Anthony myself, if you are OK with it.
Quoted 9 lines · Michael S. Tsirkin
Quoted 8 lines · Anthony PERARD
Hi all,
This patch series introduces the PCI passthrough for Xen.
Changes since the last version:
- New patch that introduce a new qdev-property pci-host-devaddr. => the "exportpci_parse_devaddr" patch is not anymore usefull.
Quoted 6 lines
Quoted 1 line
Thanks,
I reviewed some patches and Acked. Won't have the time to review the rest of the series short term.
If you need me to merge some of these patches myself pls let me know.
Considering that you Acked all the non-Xen patches (apart from the configure patch), I think I'll just go ahead and submit a pull request to Anthony myself, if you are OK with it.
Quoted 9 lines · Anthony PERARD
Hi all,
This patch series introduces the PCI passthrough for Xen.
Changes since the last version:
- New patch that introduce a new qdev-property pci-host-devaddr. => the "exportpci_parse_devaddr" patch is not anymore usefull.Thanks,
I reviewed some patches and Acked. Won't have the time to review the rest of the series short term.
If you need me to merge some of these patches myself pls let me know.
Quoted 45 lines
Allen Kay (2):
Introduce Xen PCI Passthrough, qdevice (1/3) Introduce Xen PCI Passthrough, PCI config space helpers (2/3)Anthony PERARD (6):
pci_ids: AddINTEL_82599_SFP_VFid.
configure: Introduce --enable-xen-pci-passthrough. Introduce XenHostPCIDevice to access a pci device on the host.pci.c: Add opaque argument topci_for_each_device.
qdev-properties: Introduce pci-host-devaddr. Introduceapic-msidef.hJiang Yunhong (1):
Introduce Xen PCI Passthrough, MSI (3/3)configure | 29 + hw/apic-msidef.h | 30 + hw/apic.c | 11 +- hw/i386/Makefile.objs | 2 + hw/pci.c | 11 +- hw/pci.h | 4 +- hw/pci_ids.h | 1 + hw/qdev-properties.c | 107 +++ hw/qdev.h | 3 + hw/xen-host-pci-device.c | 396 ++++++++++ hw/xen-host-pci-device.h | 55 ++ hw/xen_common.h | 3 + hw/xen_platform.c | 8 +- hw/xen_pt.c | 851 +++++++++++++++++++++ hw/xen_pt.h | 301 ++++++++ hw/xen_pt_config_init.c | 1869 ++++++++++++++++++++++++++++++++++++++++++++++ hw/xen_pt_msi.c | 620 +++++++++++++++ qemu-common.h | 7 + xen-all.c | 12 + 19 files changed, 4301 insertions(+), 19 deletions(-) create mode 100644 hw/apic-msidef.h create mode 100644 hw/xen-host-pci-device.c create mode 100644 hw/xen-host-pci-device.h create mode 100644 hw/xen_pt.c create mode 100644 hw/xen_pt.h create mode 100644 hw/xen_pt_config_init.c create mode 100644 hw/xen_pt_msi.cSignature · 1 line
Anthony PERARD