From patchwork Fri Jul 6 16:22:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 1166671 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 32CF140134 for ; Fri, 6 Jul 2012 16:22:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757904Ab2GFQWM (ORCPT ); Fri, 6 Jul 2012 12:22:12 -0400 Received: from goliath.siemens.de ([192.35.17.28]:34230 "EHLO goliath.siemens.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757679Ab2GFQWJ (ORCPT ); Fri, 6 Jul 2012 12:22:09 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by goliath.siemens.de (8.13.6/8.13.6) with ESMTP id q66GM6rT004632; Fri, 6 Jul 2012 18:22:06 +0200 Received: from mchn199C.mchp.siemens.de ([139.25.109.49]) by mail1.siemens.de (8.13.6/8.13.6) with ESMTP id q66GM6OI020974; Fri, 6 Jul 2012 18:22:06 +0200 Message-ID: <4FF710AE.2090408@siemens.com> Date: Fri, 06 Jul 2012 18:22:06 +0200 From: Jan Kiszka User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: Avi Kivity , Marcelo Tosatti CC: kvm , Alex Williamson Subject: [PATCH] pci-assign: Switch to PCI_HOST_DEVADDR property Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Replace the home-brewed qdev property for PCI host addresses with the new upstream version. Signed-off-by: Jan Kiszka Acked-by: Alex Williamson --- hw/device-assignment.c | 64 ++++++++++++--------------------------- hw/pci.c | 77 ------------------------------------------------ hw/pci.h | 3 -- 3 files changed, 20 insertions(+), 124 deletions(-) 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:]:. 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);