From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LWROK-0007Wn-M7 for qemu-devel@nongnu.org; Mon, 09 Feb 2009 03:21:20 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LWROI-0007WT-Vq for qemu-devel@nongnu.org; Mon, 09 Feb 2009 03:21:20 -0500 Received: from [199.232.76.173] (port=38133 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LWROI-0007W7-PQ for qemu-devel@nongnu.org; Mon, 09 Feb 2009 03:21:18 -0500 Received: from mx20.gnu.org ([199.232.41.8]:6003) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LWROI-0001sJ-7V for qemu-devel@nongnu.org; Mon, 09 Feb 2009 03:21:18 -0500 Received: from mx2.redhat.com ([66.187.237.31]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LWROH-0003JQ-15 for qemu-devel@nongnu.org; Mon, 09 Feb 2009 03:21:17 -0500 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n198LBXv000759 for ; Mon, 9 Feb 2009 03:21:13 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n198LBnC030703 for ; Mon, 9 Feb 2009 03:21:11 -0500 Received: from pike.pond.sub.org (vpn-10-75.str.redhat.com [10.32.10.75]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n198LAvV002857 for ; Mon, 9 Feb 2009 03:21:11 -0500 Subject: Re: [Qemu-devel] [patch 1/2] PCI: full device address parsing References: <20090206184849.068718581@amt.cnet> <20090206185138.543006723@amt.cnet> From: Markus Armbruster Date: Mon, 09 Feb 2009 09:21:09 +0100 In-Reply-To: <20090206185138.543006723@amt.cnet> (Marcelo Tosatti's message of "Fri\, 06 Feb 2009 16\:48\:50 -0200") Message-ID: <87skmokolm.fsf@pike.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Marcelo Tosatti Marcelo Tosatti writes: > From: Markus Armbruster > > This code parses full PCI device addresses. It then rejects domains > other than zero, because these are not supported in QEMU. > > Signed-off-by: Marcelo Tosatti Patch has issues with reporting errors. > Index: trunk/hw/pci.c > =================================================================== > --- trunk.orig/hw/pci.c > +++ trunk/hw/pci.c > @@ -26,6 +26,7 @@ > #include "console.h" > #include "net.h" > #include "virtio-net.h" > +#include "sysemu.h" > > //#define DEBUG_PCI > > @@ -158,6 +159,89 @@ static int pci_set_default_subsystem_id( > return 0; > } > > +/* > + * Parse [[:]:], return -1 on error > + */ > +static int pci_parse_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp) > +{ > + const char *p; > + char *e; > + unsigned long val; > + unsigned long dom = 0, bus = 0; > + unsigned slot = 0; > + > + p = addr; > + 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; > + } > + } > + > + if (dom > 0xffff || bus > 0xff || val > 0x1f) { > + fprintf(stderr, "PCI device address %s out of range", addr); > + return -1; Funny indentation. > + } > + slot = val; > + > + if (*e) > + return -1; > + > + /* Note: QEMU doesn't implement domains other than 0 */ > + if (dom != 0 || pci_find_bus(bus) == NULL) { > + fprintf(stderr, "PCI device address %s not supported", addr); > + return -1; > + } > + > + *domp = dom; > + *busp = bus; > + *slotp = slot; > + return 0; > +} Some failures print to stderr, some are silent. > + > +int pci_read_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp) > +{ > + char devaddr[32]; > + > + if (!get_param_value(devaddr, sizeof(devaddr), "pci_addr", addr)) { > + term_printf("Missing pci_addr=\n"); > + return -1; > + } > + > + return pci_parse_devaddr(devaddr, domp, busp, slotp); > +} Some failures print to stderr, some are silent, and some print to the monitor. > + > +int pci_assign_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp) > +{ > + char devaddr[32]; > + > + if (!get_param_value(devaddr, sizeof(devaddr), "pci_addr", addr)) { > + term_printf("Missing pci_addr=\n"); > + return -1; > + } > + > + if (!strcmp(devaddr, "auto")) { > + *domp = *busp = 0; > + *slotp = -1; > + /* want to support dom/bus auto-assign at some point */ > + return 0; > + } > + > + return pci_parse_devaddr(devaddr, domp, busp, slotp); > +} > + Same here. > /* -1 for devfn means auto assign */ > PCIDevice *pci_register_device(PCIBus *bus, const char *name, > int instance_size, int devfn, > Index: trunk/hw/pci.h > =================================================================== > --- trunk.orig/hw/pci.h > +++ trunk/hw/pci.h > @@ -232,6 +232,9 @@ void pci_for_each_device(int bus_num, vo > PCIBus *pci_find_bus(int bus_num); > PCIDevice *pci_find_device(int bus_num, int slot, int function); > > +int pci_read_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp); > +int pci_assign_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp); > + > void pci_info(void); > PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did, > pci_map_irq_fn map_irq, const char *name);