Re: [PATCH] pci-assign: Switch to PCI_HOST_DEVADDR property

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2012-07-06 at 18:22 +0200, Jan Kiszka wrote:
> Replace the home-brewed qdev property for PCI host addresses with the
> new upstream version.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@xxxxxxxxxxx>
> ---
>  hw/device-assignment.c |   64 ++++++++++++---------------------------
>  hw/pci.c               |   77 ------------------------------------------------
>  hw/pci.h               |    3 --
>  3 files changed, 20 insertions(+), 124 deletions(-)

Looks good

Acked-by: Alex Williamson <alex.williamson@xxxxxxxxxx>



> diff --git a/hw/device-assignment.c b/hw/device-assignment.c
> index 1336689..34593ab 100644
> --- a/hw/device-assignment.c
> +++ b/hw/device-assignment.c
> @@ -63,13 +63,6 @@
>  #define DEBUG(fmt, ...) do { } while(0)
>  #endif
>  
> -typedef struct PCIHostDevice {
> -    int seg;
> -    int bus;
> -    int dev;
> -    int func;
> -} PCIHostDevice;
> -
>  typedef struct {
>      int type;           /* Memory or port I/O */
>      int valid;
> @@ -115,7 +108,7 @@ typedef struct {
>  
>  typedef struct AssignedDevice {
>      PCIDevice dev;
> -    PCIHostDevice host;
> +    PCIHostDeviceAddress host;
>      uint32_t features;
>      int intpin;
>      uint8_t debug_flags;
> @@ -778,7 +771,8 @@ static void assign_failed_examine(AssignedDevice *dev)
>      int r;
>  
>      sprintf(dir, "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/",
> -            dev->host.seg, dev->host.bus, dev->host.dev, dev->host.func);
> +            dev->host.domain, dev->host.bus, dev->host.slot,
> +            dev->host.function);
>  
>      sprintf(name, "%sdriver", dir);
>  
> @@ -796,7 +790,8 @@ static void assign_failed_examine(AssignedDevice *dev)
>  
>      fprintf(stderr, "*** The driver '%s' is occupying your device "
>                      "%04x:%02x:%02x.%x.\n",
> -            ns, dev->host.seg, dev->host.bus, dev->host.dev, dev->host.func);
> +            ns, dev->host.domain, dev->host.bus, dev->host.slot,
> +            dev->host.function);
>      fprintf(stderr, "***\n");
>      fprintf(stderr, "*** You can try the following commands to free it:\n");
>      fprintf(stderr, "***\n");
> @@ -804,10 +799,12 @@ static void assign_failed_examine(AssignedDevice *dev)
>                      "new_id\n", vendor_id, device_id);
>      fprintf(stderr, "*** $ echo \"%04x:%02x:%02x.%x\" > /sys/bus/pci/drivers/"
>                      "%s/unbind\n",
> -            dev->host.seg, dev->host.bus, dev->host.dev, dev->host.func, ns);
> +            dev->host.domain, dev->host.bus, dev->host.slot,
> +            dev->host.function, ns);
>      fprintf(stderr, "*** $ echo \"%04x:%02x:%02x.%x\" > /sys/bus/pci/drivers/"
>                      "pci-stub/bind\n",
> -            dev->host.seg, dev->host.bus, dev->host.dev, dev->host.func);
> +            dev->host.domain, dev->host.bus, dev->host.slot,
> +            dev->host.function);
>      fprintf(stderr, "*** $ echo \"%04x %04x\" > /sys/bus/pci/drivers/pci-stub"
>                      "/remove_id\n", vendor_id, device_id);
>      fprintf(stderr, "***\n");
> @@ -1699,7 +1696,8 @@ static void reset_assigned_device(DeviceState *dev)
>  
>      snprintf(reset_file, sizeof(reset_file),
>               "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/reset",
> -             adev->host.seg, adev->host.bus, adev->host.dev, adev->host.func);
> +             adev->host.domain, adev->host.bus, adev->host.slot,
> +             adev->host.function);
>  
>      /*
>       * Issue a device reset via pci-sysfs.  Note that we use write(2) here
> @@ -1732,7 +1730,8 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
>          return -1;
>      }
>  
> -    if (!dev->host.seg && !dev->host.bus && !dev->host.dev && !dev->host.func) {
> +    if (!dev->host.domain && !dev->host.bus && !dev->host.slot &&
> +        !dev->host.function) {
>          error_report("pci-assign: error: no host device specified");
>          return -1;
>      }
> @@ -1757,8 +1756,8 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
>      memcpy(dev->emulate_config_write, dev->emulate_config_read,
>             sizeof(dev->emulate_config_read));
>  
> -    if (get_real_device(dev, dev->host.seg, dev->host.bus,
> -                        dev->host.dev, dev->host.func)) {
> +    if (get_real_device(dev, dev->host.domain, dev->host.bus,
> +                        dev->host.slot, dev->host.function)) {
>          error_report("pci-assign: Error: Couldn't get real device (%s)!",
>                       dev->dev.qdev.id);
>          goto out;
> @@ -1786,9 +1785,9 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
>      dev->intpin = e_intx;
>      dev->run = 0;
>      dev->girq = -1;
> -    dev->h_segnr = dev->host.seg;
> +    dev->h_segnr = dev->host.domain;
>      dev->h_busnr = dev->host.bus;
> -    dev->h_devfn = PCI_DEVFN(dev->host.dev, dev->host.func);
> +    dev->h_devfn = PCI_DEVFN(dev->host.slot, dev->host.function);
>  
>      /* assign device to guest */
>      r = assign_device(dev);
> @@ -1824,33 +1823,9 @@ static int assigned_exitfn(struct PCIDevice *pci_dev)
>      return 0;
>  }
>  
> -static int parse_hostaddr(DeviceState *dev, Property *prop, const char *str)
> -{
> -    PCIHostDevice *ptr = qdev_get_prop_ptr(dev, prop);
> -    int rc;
> -
> -    rc = pci_parse_host_devaddr(str, &ptr->seg, &ptr->bus, &ptr->dev, &ptr->func);
> -    if (rc != 0)
> -        return -1;
> -    return 0;
> -}
> -
> -static int print_hostaddr(DeviceState *dev, Property *prop, char *dest, size_t len)
> -{
> -    PCIHostDevice *ptr = qdev_get_prop_ptr(dev, prop);
> -
> -    return snprintf(dest, len, "%02x:%02x.%x", ptr->bus, ptr->dev, ptr->func);
> -}
> -
> -PropertyInfo qdev_prop_hostaddr = {
> -    .name  = "pci-hostaddr",
> -    .parse = parse_hostaddr,
> -    .print = print_hostaddr,
> -};
> -
>  static Property da_properties[] =
>  {
> -    DEFINE_PROP("host", AssignedDevice, host, qdev_prop_hostaddr, PCIHostDevice),
> +    DEFINE_PROP_PCI_HOST_DEVADDR("host", AssignedDevice, host),
>      DEFINE_PROP_BIT("prefer_msi", AssignedDevice, features,
>                      ASSIGNED_DEVICE_PREFER_MSI_BIT, false),
>      DEFINE_PROP_BIT("share_intx", AssignedDevice, features,
> @@ -1907,7 +1882,8 @@ static void assigned_dev_load_option_rom(AssignedDevice *dev)
>  
>      snprintf(rom_file, sizeof(rom_file),
>               "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/rom",
> -             dev->host.seg, dev->host.bus, dev->host.dev, dev->host.func);
> +             dev->host.domain, dev->host.bus, dev->host.slot,
> +             dev->host.function);
>  
>      if (stat(rom_file, &st)) {
>          return;
> diff --git a/hw/pci.c b/hw/pci.c
> index ef73761..8d7de02 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -555,83 +555,6 @@ static int pci_parse_devaddr(const char *addr, int *domp, int *busp,
>      return 0;
>  }
>  
> -/*
> - * Parse device seg and bdf in device assignment command:
> - *
> - * -pcidevice host=[seg:]bus:dev.func
> - *
> - * Parse [seg:]<bus>:<slot>.<func> return -1 on error
> - */
> -int pci_parse_host_devaddr(const char *addr, int *segp, int *busp,
> -                           int *slotp, int *funcp)
> -{
> -    const char *p;
> -    char *e;
> -    int val;
> -    int seg = 0, bus = 0, slot = 0, func = 0;
> -
> -    /* parse optional seg */
> -    p = addr;
> -    val = 0;
> -    while (1) {
> -        p = strchr(p, ':');
> -        if (p) {
> -            val++;
> -            p++;
> -        } else
> -            break;
> -    }
> -    if (val <= 0 || val > 2)
> -        return -1;
> -
> -    p = addr;
> -    if (val == 2) {
> -        val = strtoul(p, &e, 16);
> -        if (e == p)
> -            return -1;
> -        if (*e == ':') {
> -            seg = val;
> -            p = e + 1;
> -        }
> -    } else
> -        seg = 0;
> -
> -
> -    /* parse bdf */
> -    val = strtoul(p, &e, 16);
> -    if (e == p)
> -	return -1;
> -    if (*e == ':') {
> -	bus = val;
> -	p = e + 1;
> -	val = strtoul(p, &e, 16);
> -	if (e == p)
> -	    return -1;
> -	if (*e == '.') {
> -	    slot = val;
> -	    p = e + 1;
> -	    val = strtoul(p, &e, 16);
> -	    if (e == p)
> -		return -1;
> -	    func = val;
> -	} else
> -	    return -1;
> -    } else
> -	return -1;
> -
> -    if (seg > 0xffff || bus > 0xff || slot > 0x1f || func > 0x7)
> -	return -1;
> -
> -    if (*e)
> -	return -1;
> -
> -    *segp = seg;
> -    *busp = bus;
> -    *slotp = slot;
> -    *funcp = func;
> -    return 0;
> -}
> -
>  int pci_read_devaddr(Monitor *mon, const char *addr, int *domp, int *busp,
>                       unsigned *slotp)
>  {
> diff --git a/hw/pci.h b/hw/pci.h
> index fb84e40..62cf685 100644
> --- a/hw/pci.h
> +++ b/hw/pci.h
> @@ -328,9 +328,6 @@ PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr);
>  int pci_read_devaddr(Monitor *mon, const char *addr, int *domp, int *busp,
>                       unsigned *slotp);
>  
> -int pci_parse_host_devaddr(const char *addr, int *segp, int *busp,
> -                           int *slotp, int *funcp);
> -
>  void pci_device_deassert_intx(PCIDevice *dev);
>  
>  typedef DMAContext *(*PCIDMAContextFunc)(PCIBus *, void *, int);



--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux