From patchwork Thu Jun 6 08:48:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 249330 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 26A8A2C0087 for ; Thu, 6 Jun 2013 18:54:27 +1000 (EST) Received: from localhost ([::1]:60169 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkVxh-0005mS-BD for incoming@patchwork.ozlabs.org; Thu, 06 Jun 2013 04:54:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45610) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkVsh-0006VH-FZ for qemu-devel@nongnu.org; Thu, 06 Jun 2013 04:49:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UkVsT-0000pk-Kw for qemu-devel@nongnu.org; Thu, 06 Jun 2013 04:49:15 -0400 Received: from ozlabs.org ([2402:b800:7003:1:1::1]:55987) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkVsS-0000p1-V7 for qemu-devel@nongnu.org; Thu, 06 Jun 2013 04:49:01 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 090FE2C0174; Thu, 6 Jun 2013 18:48:58 +1000 (EST) From: David Gibson To: aliguori@us.ibm.com, mst@redhat.com Date: Thu, 6 Jun 2013 18:48:51 +1000 Message-Id: <1370508534-12335-8-git-send-email-david@gibson.dropbear.id.au> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1370508534-12335-1-git-send-email-david@gibson.dropbear.id.au> References: <1370508534-12335-1-git-send-email-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2402:b800:7003:1:1::1 Cc: bonzini@redhat.com, qemu-devel@nongnu.org, David Gibson Subject: [Qemu-devel] [PATCH 07/10] pci: Add root bus parameter to pci_nic_init() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org At present, pci_nic_init() and pci_nic_init_nofail() assume that they will only create a NIC under the primary PCI root. As we add support for multiple PCI roots, that may no longer be the case. This patch adds a root bus parameter to pci_nic_init() (and updates callers accordingly) to allow the machine init code using it to specify the right PCI root for NICs created by old-style -net nic parameters. NICs created new-style, with -device can of course be put anywhere. Signed-off-by: David Gibson --- hw/alpha/dp264.c | 2 +- hw/arm/realview.c | 6 ++++-- hw/arm/versatilepb.c | 2 +- hw/i386/pc.c | 2 +- hw/mips/mips_fulong2e.c | 6 +++--- hw/mips/mips_malta.c | 6 +++--- hw/pci/pci-hotplug-old.c | 3 ++- hw/pci/pci.c | 10 ++++++---- hw/ppc/e500.c | 2 +- hw/ppc/mac_newworld.c | 2 +- hw/ppc/mac_oldworld.c | 2 +- hw/ppc/ppc440_bamboo.c | 2 +- hw/ppc/prep.c | 2 +- hw/ppc/spapr.c | 2 +- hw/sh4/r2d.c | 5 ++++- hw/sparc64/sun4u.c | 2 +- include/hw/pci/pci.h | 6 ++++-- 17 files changed, 36 insertions(+), 26 deletions(-) diff --git a/hw/alpha/dp264.c b/hw/alpha/dp264.c index 8695efb..8dad08f 100644 --- a/hw/alpha/dp264.c +++ b/hw/alpha/dp264.c @@ -89,7 +89,7 @@ static void clipper_init(QEMUMachineInitArgs *args) /* Network setup. e1000 is good enough, failing Tulip support. */ for (i = 0; i < nb_nics; i++) { - pci_nic_init_nofail(&nd_table[i], "e1000", NULL); + pci_nic_init_nofail(&nd_table[i], pci_bus, "e1000", NULL); } /* IDE disk setup. */ diff --git a/hw/arm/realview.c b/hw/arm/realview.c index d6f47bf..036a188 100644 --- a/hw/arm/realview.c +++ b/hw/arm/realview.c @@ -59,7 +59,7 @@ static void realview_init(QEMUMachineInitArgs *args, qemu_irq *irqp; qemu_irq pic[64]; qemu_irq mmc_irq[2]; - PCIBus *pci_bus; + PCIBus *pci_bus = NULL; NICInfo *nd; i2c_bus *i2c; int n; @@ -250,7 +250,9 @@ static void realview_init(QEMUMachineInitArgs *args, } done_nic = 1; } else { - pci_nic_init_nofail(nd, "rtl8139", NULL); + if (pci_bus) { + pci_nic_init_nofail(nd, pci_bus, "rtl8139", NULL); + } } } diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c index 753757e..15eb086 100644 --- a/hw/arm/versatilepb.c +++ b/hw/arm/versatilepb.c @@ -244,7 +244,7 @@ static void versatile_init(QEMUMachineInitArgs *args, int board_id) smc91c111_init(nd, 0x10010000, sic[25]); done_smc = 1; } else { - pci_nic_init_nofail(nd, "rtl8139", NULL); + pci_nic_init_nofail(nd, pci_bus, "rtl8139", NULL); } } if (usb_enabled(false)) { diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 4844a6b..61f5ac2 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1228,7 +1228,7 @@ void pc_nic_init(ISABus *isa_bus, PCIBus *pci_bus) if (!pci_bus || (nd->model && strcmp(nd->model, "ne2k_isa") == 0)) { pc_init_ne2k_isa(isa_bus, nd); } else { - pci_nic_init_nofail(nd, "e1000", NULL); + pci_nic_init_nofail(nd, pci_bus, "e1000", NULL); } } } diff --git a/hw/mips/mips_fulong2e.c b/hw/mips/mips_fulong2e.c index 1aac93a..cf2bd62 100644 --- a/hw/mips/mips_fulong2e.c +++ b/hw/mips/mips_fulong2e.c @@ -231,7 +231,7 @@ static void audio_init (PCIBus *pci_bus) } /* Network support */ -static void network_init (void) +static void network_init (PCIBus *pci_bus) { int i; @@ -244,7 +244,7 @@ static void network_init (void) default_devaddr = "07"; } - pci_nic_init_nofail(nd, "rtl8139", default_devaddr); + pci_nic_init_nofail(nd, pci_bus, "rtl8139", default_devaddr); } } @@ -393,7 +393,7 @@ static void mips_fulong2e_init(QEMUMachineInitArgs *args) /* Sound card */ audio_init(pci_bus); /* Network card */ - network_init(); + network_init(pci_bus); } static QEMUMachine mips_fulong2e_machine = { diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c index 5033d51..05e59b4 100644 --- a/hw/mips/mips_malta.c +++ b/hw/mips/mips_malta.c @@ -468,7 +468,7 @@ static MaltaFPGAState *malta_fpga_init(MemoryRegion *address_space, } /* Network support */ -static void network_init(void) +static void network_init(PCIBus *pci_bus) { int i; @@ -480,7 +480,7 @@ static void network_init(void) /* The malta board has a PCNet card using PCI SLOT 11 */ default_devaddr = "0b"; - pci_nic_init_nofail(nd, "pcnet", default_devaddr); + pci_nic_init_nofail(nd, pci_bus, "pcnet", default_devaddr); } } @@ -985,7 +985,7 @@ void mips_malta_init(QEMUMachineInitArgs *args) fdctrl_init_isa(isa_bus, fd); /* Network card */ - network_init(); + network_init(pci_bus); /* Optional PCI video card */ pci_vga_init(pci_bus); diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c index e92d646..807260c 100644 --- a/hw/pci/pci-hotplug-old.c +++ b/hw/pci/pci-hotplug-old.c @@ -92,7 +92,8 @@ static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, monitor_printf(mon, "Parameter addr not supported\n"); return NULL; } - return pci_nic_init(&nd_table[ret], "rtl8139", devaddr); + return pci_nic_init(&nd_table[ret], pci_find_primary_bus(), + "rtl8139", devaddr); } static int scsi_hot_add(Monitor *mon, DeviceState *adapter, diff --git a/hw/pci/pci.c b/hw/pci/pci.c index fb92061..abdd45b 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1578,7 +1578,8 @@ static const char * const pci_nic_names[] = { /* Initialize a PCI NIC. */ /* FIXME callers should check for failure, but don't */ -PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model, +PCIDevice *pci_nic_init(NICInfo *nd, PCIBus *rootbus, + const char *default_model, const char *default_devaddr) { const char *devaddr = nd->devaddr ? nd->devaddr : default_devaddr; @@ -1592,7 +1593,7 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model, if (i < 0) return NULL; - bus = pci_get_bus_devfn(&devfn, pci_find_primary_bus(), devaddr); + bus = pci_get_bus_devfn(&devfn, rootbus, devaddr); if (!bus) { error_report("Invalid PCI device address %s for device %s", devaddr, pci_nic_names[i]); @@ -1607,7 +1608,8 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model, return pci_dev; } -PCIDevice *pci_nic_init_nofail(NICInfo *nd, const char *default_model, +PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus, + const char *default_model, const char *default_devaddr) { PCIDevice *res; @@ -1615,7 +1617,7 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, const char *default_model, if (qemu_show_nic_models(nd->model, pci_nic_models)) exit(0); - res = pci_nic_init(nd, default_model, default_devaddr); + res = pci_nic_init(nd, rootbus, default_model, default_devaddr); if (!res) exit(1); return res; diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c index c9ae512..302f608 100644 --- a/hw/ppc/e500.c +++ b/hw/ppc/e500.c @@ -626,7 +626,7 @@ void ppce500_init(PPCE500Params *params) if (pci_bus) { /* Register network interfaces. */ for (i = 0; i < nb_nics; i++) { - pci_nic_init_nofail(&nd_table[i], "virtio", NULL); + pci_nic_init_nofail(&nd_table[i], pci_bus, "virtio", NULL); } } diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c index ce44e95..af5b077 100644 --- a/hw/ppc/mac_newworld.c +++ b/hw/ppc/mac_newworld.c @@ -362,7 +362,7 @@ static void ppc_core99_init(QEMUMachineInitArgs *args) escc_mem, 0, memory_region_size(escc_mem)); for(i = 0; i < nb_nics; i++) - pci_nic_init_nofail(&nd_table[i], "ne2k_pci", NULL); + pci_nic_init_nofail(&nd_table[i], pci_bus, "ne2k_pci", NULL); ide_drive_get(hd, MAX_IDE_BUS); diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c index 3acca94..2a43027 100644 --- a/hw/ppc/mac_oldworld.c +++ b/hw/ppc/mac_oldworld.c @@ -259,7 +259,7 @@ static void ppc_heathrow_init(QEMUMachineInitArgs *args) escc_mem, 0, memory_region_size(escc_mem)); for(i = 0; i < nb_nics; i++) - pci_nic_init_nofail(&nd_table[i], "ne2k_pci", NULL); + pci_nic_init_nofail(&nd_table[i], pci_bus, "ne2k_pci", NULL); ide_drive_get(hd, MAX_IDE_BUS); diff --git a/hw/ppc/ppc440_bamboo.c b/hw/ppc/ppc440_bamboo.c index a55e717..8bb9343 100644 --- a/hw/ppc/ppc440_bamboo.c +++ b/hw/ppc/ppc440_bamboo.c @@ -245,7 +245,7 @@ static void bamboo_init(QEMUMachineInitArgs *args) for (i = 0; i < nb_nics; i++) { /* There are no PCI NICs on the Bamboo board, but there are * PCI slots, so we can pick whatever default model we want. */ - pci_nic_init_nofail(&nd_table[i], "e1000", NULL); + pci_nic_init_nofail(&nd_table[i], pcibus, "e1000", NULL); } } diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c index be8a50e..4691fc1 100644 --- a/hw/ppc/prep.c +++ b/hw/ppc/prep.c @@ -627,7 +627,7 @@ static void ppc_prep_init(QEMUMachineInitArgs *args) isa_ne2000_init(isa_bus, ne2000_io[i], ne2000_irq[i], &nd_table[i]); } else { - pci_nic_init_nofail(&nd_table[i], "ne2k_pci", NULL); + pci_nic_init_nofail(&nd_table[i], pci_bus, "ne2k_pci", NULL); } } diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 218ea23..41a2e49 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -887,7 +887,7 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args) if (strcmp(nd->model, "ibmveth") == 0) { spapr_vlan_create(spapr->vio_bus, nd); } else { - pci_nic_init_nofail(&nd_table[i], nd->model, NULL); + pci_nic_init_nofail(&nd_table[i], phb->bus, nd->model, NULL); } } diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c index 3e4818e..dd81d75 100644 --- a/hw/sh4/r2d.c +++ b/hw/sh4/r2d.c @@ -236,6 +236,7 @@ static void r2d_init(QEMUMachineInitArgs *args) DeviceState *dev; SysBusDevice *busdev; MemoryRegion *address_space_mem = get_system_memory(); + PCIBus *pci_bus; if (cpu_model == NULL) { cpu_model = "SH7751R"; @@ -264,6 +265,7 @@ static void r2d_init(QEMUMachineInitArgs *args) dev = qdev_create(NULL, "sh_pci"); busdev = SYS_BUS_DEVICE(dev); qdev_init_nofail(dev); + pci_bus = PCI_BUS(qdev_get_child_bus(dev, "pci")); sysbus_mmio_map(busdev, 0, P4ADDR(0x1e200000)); sysbus_mmio_map(busdev, 1, A7ADDR(0x1e200000)); sysbus_connect_irq(busdev, 0, irq[PCI_INTA]); @@ -295,7 +297,8 @@ static void r2d_init(QEMUMachineInitArgs *args) /* NIC: rtl8139 on-board, and 2 slots. */ for (i = 0; i < nb_nics; i++) - pci_nic_init_nofail(&nd_table[i], "rtl8139", i==0 ? "2" : NULL); + pci_nic_init_nofail(&nd_table[i], pci_bus, + "rtl8139", i==0 ? "2" : NULL); /* USB keyboard */ usbdevice_create("keyboard"); diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c index 2c2a111..df975f9 100644 --- a/hw/sparc64/sun4u.c +++ b/hw/sparc64/sun4u.c @@ -855,7 +855,7 @@ static void sun4uv_init(MemoryRegion *address_space_mem, } for(i = 0; i < nb_nics; i++) - pci_nic_init_nofail(&nd_table[i], "ne2k_pci", NULL); + pci_nic_init_nofail(&nd_table[i], pci_bus, "ne2k_pci", NULL); ide_drive_get(hd, MAX_IDE_BUS); diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 3b22898..ecceeba 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -379,9 +379,11 @@ void pci_device_set_intx_routing_notifier(PCIDevice *dev, void pci_device_reset(PCIDevice *dev); void pci_bus_reset(PCIBus *bus); -PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model, +PCIDevice *pci_nic_init(NICInfo *nd, PCIBus *rootbus, + const char *default_model, const char *default_devaddr); -PCIDevice *pci_nic_init_nofail(NICInfo *nd, const char *default_model, +PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus, + const char *default_model, const char *default_devaddr); PCIDevice *pci_vga_init(PCIBus *bus);