We will some use this function also for property parsing, so move it over unmodified and rename it.
Signed-off-by: Jan Kiszka <jan.kis...@siemens.com> --- hw/pci-hotplug.c | 2 +- hw/pci.c | 67 +------------------------------------------------- hw/pci.h | 5 --- hw/qdev-properties.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 5 +++ 5 files changed, 72 insertions(+), 72 deletions(-) diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c index aff4d85..60c8989 100644 --- a/hw/pci-hotplug.c +++ b/hw/pci-hotplug.c @@ -41,7 +41,7 @@ static int read_pci_devaddr(Monitor *mon, const char *addrstr, if (!strncmp(addrstr, "pci_addr=", 9)) { addrstr += 9; } - if (pci_parse_devaddr(addrstr, addr, 0)) { + if (qemu_parse_pci_devaddr(addrstr, addr, 0)) { monitor_printf(mon, "Invalid pci address\n"); return -1; } diff --git a/hw/pci.c b/hw/pci.c index 62ad61c..5056fc4 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -508,71 +508,6 @@ static void pci_set_default_subsystem_id(PCIDevice *pci_dev) pci_default_sub_device_id); } -/* - * Parse [[<domain>:]<bus>:]<slot>, return -1 on error if !PCI_DEVADDR_WITH_FUNC - * [[<domain>:]<bus>:]<slot>.<func>, return -1 on error - */ -int pci_parse_devaddr(const char *addrstr, PCIDeviceAddress *addr, - unsigned int flags) -{ - const char *p; - char *e; - unsigned long val; - unsigned long dom = 0, bus = 0; - unsigned int slot; - unsigned int func = 0; - - p = addrstr; - 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 == ':') { - dom = bus; - bus = val; - p = e + 1; - val = strtoul(p, &e, 16); - if (e == p) { - return -1; - } - } - } - - slot = val; - - if (flags & PCI_DEVADDR_WITH_FUNC) { - if (*e != '.') { - return -1; - } - p = e + 1; - val = strtoul(p, &e, 16); - if (e == p) { - return -1; - } - func = val; - } - - if (dom > 0xffff || bus > 0xff || slot > 0x1f || func > 7) { - return -1; - } - if (*e) { - return -1; - } - - addr->domain = dom; - addr->bus = bus; - addr->slot = slot; - addr->function = func; - return 0; -} - PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr) { PCIDeviceAddress addr; @@ -582,7 +517,7 @@ PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr) return pci_find_bus_nr(pci_find_root_bus(0), 0); } - if (pci_parse_devaddr(devaddr, &addr, 0) < 0) { + if (qemu_parse_pci_devaddr(devaddr, &addr, 0) < 0) { return NULL; } diff --git a/hw/pci.h b/hw/pci.h index 6c48ffa..a3e5ad9 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -340,11 +340,6 @@ PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn); int pci_qdev_find_device(const char *id, PCIDevice **pdev); PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr); -#define PCI_DEVADDR_WITH_FUNC 2 - -int pci_parse_devaddr(const char *addrstr, PCIDeviceAddress *addr, - unsigned int flags); - void pci_device_deassert_intx(PCIDevice *dev); static inline void diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index b7b5597..14ea394 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -817,6 +817,71 @@ PropertyInfo qdev_prop_losttickpolicy = { /* --- pci address --- */ /* + * Parse [[<domain>:]<bus>:]<slot>, return -1 on error if !PCI_DEVADDR_WITH_FUNC + * [[<domain>:]<bus>:]<slot>.<func>, return -1 on error + */ +int qemu_parse_pci_devaddr(const char *addrstr, PCIDeviceAddress *addr, + unsigned int flags) +{ + const char *p; + char *e; + unsigned long val; + unsigned long dom = 0, bus = 0; + unsigned int slot; + unsigned int func = 0; + + p = addrstr; + 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 == ':') { + dom = bus; + bus = val; + p = e + 1; + val = strtoul(p, &e, 16); + if (e == p) { + return -1; + } + } + } + + slot = val; + + if (flags & PCI_DEVADDR_WITH_FUNC) { + if (*e != '.') { + return -1; + } + p = e + 1; + val = strtoul(p, &e, 16); + if (e == p) { + return -1; + } + func = val; + } + + if (dom > 0xffff || bus > 0xff || slot > 0x1f || func > 7) { + return -1; + } + if (*e) { + return -1; + } + + addr->domain = dom; + addr->bus = bus; + addr->slot = slot; + addr->function = func; + return 0; +} + +/* * bus-local address, i.e. "$slot" or "$slot.$fn" */ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque, diff --git a/hw/qdev.h b/hw/qdev.h index 4e90119..102550b 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -360,4 +360,9 @@ void qdev_set_parent_bus(DeviceState *dev, BusState *bus); extern int qdev_hotplug; +#define PCI_DEVADDR_WITH_FUNC 2 + +int qemu_parse_pci_devaddr(const char *addrstr, PCIDeviceAddress *addr, + unsigned int flags); + #endif -- 1.7.3.4