From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LQ5Gm-0001Nu-CE for qemu-devel@nongnu.org; Thu, 22 Jan 2009 14:31:16 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LQ5Gh-0001IT-Ri for qemu-devel@nongnu.org; Thu, 22 Jan 2009 14:31:12 -0500 Received: from [199.232.76.173] (port=38452 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LQ5Gh-0001IH-Kw for qemu-devel@nongnu.org; Thu, 22 Jan 2009 14:31:11 -0500 Received: from oxygen.pond.sub.org ([213.239.205.148]:60674) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LQ5Gg-0006J1-JC for qemu-devel@nongnu.org; Thu, 22 Jan 2009 14:31:11 -0500 Received: from pike.pond.sub.org (pD9E3B496.dip.t-dialin.net [217.227.180.150]) by oxygen.pond.sub.org (Postfix) with ESMTPA id B8416276D10 for ; Thu, 22 Jan 2009 20:31:05 +0100 (CET) From: Markus Armbruster Date: Thu, 22 Jan 2009 20:31:01 +0100 Message-Id: <1232652665-1710-5-git-send-email-armbru@redhat.com> In-Reply-To: <87ocxzrvqb.fsf@pike.pond.sub.org> References: <87ocxzrvqb.fsf@pike.pond.sub.org> Subject: [Qemu-devel] [PATCH 5/9] Support pci=... in option argument of -net nic 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 From: Markus Armbruster FIXME: the code registers two NICs with fixed device addresses. The patch preserves that, but it's a disgusting hack. --- hw/e1000.c | 6 +++--- hw/eepro100.c | 19 +++++++++---------- hw/mips_malta.c | 9 ++++----- hw/ne2000.c | 7 +++---- hw/pc.c | 2 +- hw/pci.c | 7 +++---- hw/pci.h | 17 ++++++++--------- hw/pcnet.c | 6 +++--- hw/ppc440_bamboo.c | 2 +- hw/ppc_chrp.c | 2 +- hw/ppc_oldworld.c | 2 +- hw/ppc_prep.c | 2 +- hw/r2d.c | 8 ++++---- hw/realview.c | 2 +- hw/rtl8139.c | 7 +++---- hw/sun4u.c | 2 +- hw/versatilepb.c | 2 +- hw/virtio-net.c | 4 ++-- hw/virtio-net.h | 2 +- net.c | 1 + net.h | 1 + 21 files changed, 53 insertions(+), 57 deletions(-) diff --git a/hw/e1000.c b/hw/e1000.c index ccf9bc0..06f8c49 100644 --- a/hw/e1000.c +++ b/hw/e1000.c @@ -1035,7 +1035,7 @@ e1000_mmio_map(PCIDevice *pci_dev, int region_num, } void -pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn) +pci_e1000_init(NICInfo *nd) { E1000State *d; uint8_t *pci_conf; @@ -1043,8 +1043,8 @@ pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn) static const char info_str[] = "e1000"; int i; - d = (E1000State *)pci_register_device(bus, "e1000", - sizeof(E1000State), devfn, NULL, NULL); + d = (E1000State *)pci_register_device_2("e1000", nd->opts, + sizeof(E1000State), NULL, NULL); pci_conf = d->dev.config; memset(pci_conf, 0, 256); diff --git a/hw/eepro100.c b/hw/eepro100.c index 5eca105..1784b7f 100644 --- a/hw/eepro100.c +++ b/hw/eepro100.c @@ -1736,16 +1736,15 @@ static void nic_save(QEMUFile * f, void *opaque) qemu_put_buffer(f, s->configuration, sizeof(s->configuration)); } -static void nic_init(PCIBus * bus, NICInfo * nd, - const char *name, uint32_t device) +static void nic_init(NICInfo * nd, const char *name, uint32_t device) { PCIEEPRO100State *d; EEPRO100State *s; logout("\n"); - d = (PCIEEPRO100State *) pci_register_device(bus, name, - sizeof(PCIEEPRO100State), -1, + d = (PCIEEPRO100State *) pci_register_device_2(name, nd->opts, + sizeof(PCIEEPRO100State), NULL, NULL); s = &d->eepro100; @@ -1786,20 +1785,20 @@ static void nic_init(PCIBus * bus, NICInfo * nd, register_savevm(name, -1, 3, nic_save, nic_load, s); } -void pci_i82551_init(PCIBus * bus, NICInfo * nd, int devfn) +void pci_i82551_init(NICInfo * nd) { - nic_init(bus, nd, "i82551", i82551); + nic_init(nd, "i82551", i82551); //~ uint8_t *pci_conf = d->dev.config; } -void pci_i82557b_init(PCIBus * bus, NICInfo * nd, int devfn) +void pci_i82557b_init(NICInfo * nd) { - nic_init(bus, nd, "i82557b", i82557B); + nic_init(nd, "i82557b", i82557B); } -void pci_i82559er_init(PCIBus * bus, NICInfo * nd, int devfn) +void pci_i82559er_init(NICInfo * nd) { - nic_init(bus, nd, "i82559er", i82559ER); + nic_init(nd, "i82559er", i82559ER); } /* eof */ diff --git a/hw/mips_malta.c b/hw/mips_malta.c index 466c303..bce141d 100644 --- a/hw/mips_malta.c +++ b/hw/mips_malta.c @@ -483,19 +483,18 @@ static void audio_init (PCIBus *pci_bus) #endif /* Network support */ -static void network_init (PCIBus *pci_bus) +static void network_init (void) { int i; for(i = 0; i < nb_nics; i++) { NICInfo *nd = &nd_table[i]; - int devfn = -1; if (i == 0 && (!nd->model || strcmp(nd->model, "pcnet") == 0)) /* The malta board has a PCNet card using PCI SLOT 11 */ - devfn = 88; + nd->opts = "pci=11"; /* FIXME disgusting hack */ - pci_nic_init(pci_bus, nd, devfn, "pcnet"); + pci_nic_init(nd, "pcnet"); } } @@ -932,7 +931,7 @@ void mips_malta_init (ram_addr_t ram_size, int vga_ram_size, #endif /* Network card */ - network_init(pci_bus); + network_init(); /* Optional PCI video card */ pci_cirrus_vga_init(phys_ram_base + ram_size, diff --git a/hw/ne2000.c b/hw/ne2000.c index a85730f..a59099e 100644 --- a/hw/ne2000.c +++ b/hw/ne2000.c @@ -779,15 +779,14 @@ static void ne2000_map(PCIDevice *pci_dev, int region_num, register_ioport_read(addr + 0x1f, 1, 1, ne2000_reset_ioport_read, s); } -void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn) +void pci_ne2000_init(NICInfo *nd) { PCINE2000State *d; NE2000State *s; uint8_t *pci_conf; - d = (PCINE2000State *)pci_register_device(bus, - "NE2000", sizeof(PCINE2000State), - devfn, + d = (PCINE2000State *)pci_register_device_2("NE2000", nd->opts, + sizeof(PCINE2000State), NULL, NULL); pci_conf = d->dev.config; pci_conf[0x00] = 0xec; // Realtek 8029 diff --git a/hw/pc.c b/hw/pc.c index 75b7374..5e70ca6 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -1006,7 +1006,7 @@ vga_bios_error: if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0)) pc_init_ne2k_isa(nd, i8259); else - pci_nic_init(pci_bus, nd, -1, "ne2k_pci"); + pci_nic_init(nd, "ne2k_pci"); } if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) { diff --git a/hw/pci.c b/hw/pci.c index a0e8562..ebfa5b7 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -756,7 +756,7 @@ static const char * const pci_nic_models[] = { NULL }; -typedef void (*PCINICInitFn)(PCIBus *, NICInfo *, int); +typedef void (*PCINICInitFn)(NICInfo *); static PCINICInitFn pci_nic_init_fns[] = { pci_ne2000_init, @@ -771,8 +771,7 @@ static PCINICInitFn pci_nic_init_fns[] = { }; /* Initialize a PCI NIC. */ -void pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn, - const char *default_model) +void pci_nic_init(NICInfo *nd, const char *default_model) { int i; @@ -780,7 +779,7 @@ void pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn, for (i = 0; pci_nic_models[i]; i++) if (strcmp(nd->model, pci_nic_models[i]) == 0) - pci_nic_init_fns[i](bus, nd, devfn); + pci_nic_init_fns[i](nd); } typedef struct { diff --git a/hw/pci.h b/hw/pci.h index fe72881..ae6a4dd 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -123,8 +123,7 @@ typedef int (*pci_map_irq_fn)(PCIDevice *pci_dev, int irq_num); PCIBus *pci_register_bus(pci_set_irq_fn set_irq, pci_map_irq_fn map_irq, qemu_irq *pic, int devfn_min, int nirq); -void pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn, - const char *default_model); +void pci_nic_init(NICInfo *nd, const char *default_model); void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len); uint32_t pci_data_read(void *opaque, uint32_t addr, int len); int pci_bus_num(PCIBus *s); @@ -153,23 +152,23 @@ void usb_ohci_init_pci(struct PCIBus *bus, int num_ports, int devfn); /* eepro100.c */ -void pci_i82551_init(PCIBus *bus, NICInfo *nd, int devfn); -void pci_i82557b_init(PCIBus *bus, NICInfo *nd, int devfn); -void pci_i82559er_init(PCIBus *bus, NICInfo *nd, int devfn); +void pci_i82551_init(NICInfo *nd); +void pci_i82557b_init(NICInfo *nd); +void pci_i82559er_init(NICInfo *nd); /* ne2000.c */ -void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn); +void pci_ne2000_init(NICInfo *nd); /* rtl8139.c */ -void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn); +void pci_rtl8139_init(NICInfo *nd); /* e1000.c */ -void pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn); +void pci_e1000_init(NICInfo *nd); /* pcnet.c */ -void pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn); +void pci_pcnet_init(NICInfo *nd); /* prep_pci.c */ PCIBus *pci_prep_init(qemu_irq *pic); diff --git a/hw/pcnet.c b/hw/pcnet.c index 4411f75..1dcaf03 100644 --- a/hw/pcnet.c +++ b/hw/pcnet.c @@ -1985,7 +1985,7 @@ static void pci_physical_memory_read(void *dma_opaque, target_phys_addr_t addr, cpu_physical_memory_read(addr, buf, len); } -void pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn) +void pci_pcnet_init(NICInfo *nd) { PCNetState *d; uint8_t *pci_conf; @@ -1995,8 +1995,8 @@ void pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn) sizeof(struct pcnet_RMD), sizeof(struct pcnet_TMD)); #endif - d = (PCNetState *)pci_register_device(bus, "PCNet", sizeof(PCNetState), - devfn, NULL, NULL); + d = (PCNetState *)pci_register_device_2("PCNet", nd->opts, + sizeof(PCNetState), NULL, NULL); pci_conf = d->dev.config; diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c index 5f03661..3520b14 100644 --- a/hw/ppc440_bamboo.c +++ b/hw/ppc440_bamboo.c @@ -126,7 +126,7 @@ static void bamboo_init(ram_addr_t ram_size, int vga_ram_size, 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(pcibus, &nd_table[i], -1, "e1000"); + pci_nic_init(&nd_table[i], "e1000"); } } diff --git a/hw/ppc_chrp.c b/hw/ppc_chrp.c index c15c4ae..af89d4e 100644 --- a/hw/ppc_chrp.c +++ b/hw/ppc_chrp.c @@ -267,7 +267,7 @@ static void ppc_core99_init (ram_addr_t ram_size, int vga_ram_size, serial_hds[0], serial_hds[1], ESCC_CLOCK, 4); for(i = 0; i < nb_nics; i++) - pci_nic_init(pci_bus, &nd_table[i], -1, "ne2k_pci"); + pci_nic_init(&nd_table[i], "ne2k_pci"); if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) { fprintf(stderr, "qemu: too many IDE bus\n"); diff --git a/hw/ppc_oldworld.c b/hw/ppc_oldworld.c index 882a523..93a91a8 100644 --- a/hw/ppc_oldworld.c +++ b/hw/ppc_oldworld.c @@ -304,7 +304,7 @@ static void ppc_heathrow_init (ram_addr_t ram_size, int vga_ram_size, serial_hds[1], ESCC_CLOCK, 4); for(i = 0; i < nb_nics; i++) - pci_nic_init(pci_bus, &nd_table[i], -1, "ne2k_pci"); + pci_nic_init(&nd_table[i], "ne2k_pci"); /* First IDE channel is a CMD646 on the PCI bus */ diff --git a/hw/ppc_prep.c b/hw/ppc_prep.c index bb692e3..ddd0b75 100644 --- a/hw/ppc_prep.c +++ b/hw/ppc_prep.c @@ -672,7 +672,7 @@ static void ppc_prep_init (ram_addr_t ram_size, int vga_ram_size, if (strcmp(nd_table[i].model, "ne2k_isa") == 0) { isa_ne2000_init(ne2000_io[i], i8259[ne2000_irq[i]], &nd_table[i]); } else { - pci_nic_init(pci_bus, &nd_table[i], -1, "ne2k_pci"); + pci_nic_init(&nd_table[i], "ne2k_pci"); } } diff --git a/hw/r2d.c b/hw/r2d.c index 09305f3..044049c 100644 --- a/hw/r2d.c +++ b/hw/r2d.c @@ -201,7 +201,6 @@ static void r2d_init(ram_addr_t ram_size, int vga_ram_size, struct SH7750State *s; ram_addr_t sdram_addr, sm501_vga_ram_addr; qemu_irq *irq; - PCIBus *pci; int i; if (!cpu_model) @@ -219,7 +218,7 @@ static void r2d_init(ram_addr_t ram_size, int vga_ram_size, /* Register peripherals */ s = sh7750_init(env); irq = r2d_fpga_init(0x04000000, sh7750_irl(s)); - pci = sh_pci_register_bus(r2d_pci_set_irq, r2d_pci_map_irq, irq, 0, 4); + sh_pci_register_bus(r2d_pci_set_irq, r2d_pci_map_irq, irq, 0, 4); sm501_vga_ram_addr = qemu_ram_alloc(SM501_VRAM_SIZE); sm501_init(0x10000000, sm501_vga_ram_addr, SM501_VRAM_SIZE, @@ -230,9 +229,10 @@ static void r2d_init(ram_addr_t ram_size, int vga_ram_size, drives_table[drive_get_index(IF_IDE, 0, 0)].bdrv, NULL); /* NIC: rtl8139 on-board, and 2 slots. */ - pci_nic_init(pci, &nd_table[0], 2 << 3, "rtl8139"); + nd_table[0].opts = "pci=2"; /* FIXME disgusting hack */ + pci_nic_init(&nd_table[0], "rtl8139"); for (i = 1; i < nb_nics; i++) - pci_nic_init(pci, &nd_table[i], -1, "ne2k_pci"); + pci_nic_init(&nd_table[i], "ne2k_pci"); /* Todo: register on board registers */ { diff --git a/hw/realview.c b/hw/realview.c index aae4b86..c341225 100644 --- a/hw/realview.c +++ b/hw/realview.c @@ -126,7 +126,7 @@ static void realview_init(ram_addr_t ram_size, int vga_ram_size, smc91c111_init(nd, 0x4e000000, pic[28]); done_smc = 1; } else { - pci_nic_init(pci_bus, nd, -1, "rtl8139"); + pci_nic_init(nd, "rtl8139"); } } diff --git a/hw/rtl8139.c b/hw/rtl8139.c index 70cb080..3a7c3ba 100644 --- a/hw/rtl8139.c +++ b/hw/rtl8139.c @@ -3414,15 +3414,14 @@ static void rtl8139_timer(void *opaque) } #endif /* RTL8139_ONBOARD_TIMER */ -void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn) +void pci_rtl8139_init(NICInfo *nd) { PCIRTL8139State *d; RTL8139State *s; uint8_t *pci_conf; - d = (PCIRTL8139State *)pci_register_device(bus, - "RTL8139", sizeof(PCIRTL8139State), - devfn, + d = (PCIRTL8139State *)pci_register_device_2("RTL8139", nd->opts, + sizeof(PCIRTL8139State), NULL, NULL); pci_conf = d->dev.config; pci_conf[0x00] = 0xec; /* Realtek 8139 */ diff --git a/hw/sun4u.c b/hw/sun4u.c index 5d209fb..f29d588 100644 --- a/hw/sun4u.c +++ b/hw/sun4u.c @@ -536,7 +536,7 @@ static void sun4uv_init(ram_addr_t RAM_size, int vga_ram_size, } for(i = 0; i < nb_nics; i++) - pci_nic_init(pci_bus, &nd_table[i], -1, "ne2k_pci"); + pci_nic_init(&nd_table[i], "ne2k_pci"); irq = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS); if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) { diff --git a/hw/versatilepb.c b/hw/versatilepb.c index f601e2f..c8e7e8c 100644 --- a/hw/versatilepb.c +++ b/hw/versatilepb.c @@ -199,7 +199,7 @@ static void versatile_init(ram_addr_t ram_size, int vga_ram_size, smc91c111_init(nd, 0x10010000, sic[25]); done_smc = 1; } else { - pci_nic_init(pci_bus, nd, -1, "rtl8139"); + pci_nic_init(nd, "rtl8139"); } } if (usb_enabled) { diff --git a/hw/virtio-net.c b/hw/virtio-net.c index 3c7afb6..0b03597 100644 --- a/hw/virtio-net.c +++ b/hw/virtio-net.c @@ -315,12 +315,12 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) return 0; } -void virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn) +void virtio_net_init(NICInfo *nd) { VirtIONet *n; static int virtio_net_id; - n = (VirtIONet *)virtio_init_pci("virtio-net", "", + n = (VirtIONet *)virtio_init_pci("virtio-net", nd->opts, 6900, 0x1000, 0, VIRTIO_ID_NET, 0x02, 0x00, 0x00, diff --git a/hw/virtio-net.h b/hw/virtio-net.h index 148ec47..4866ac9 100644 --- a/hw/virtio-net.h +++ b/hw/virtio-net.h @@ -80,6 +80,6 @@ struct virtio_net_hdr_mrg_rxbuf uint16_t num_buffers; /* Number of merged rx buffers */ }; -void virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn); +void virtio_net_init(NICInfo *nd); #endif diff --git a/net.c b/net.c index 86ee7d5..9f6b1e4 100644 --- a/net.c +++ b/net.c @@ -1581,6 +1581,7 @@ int net_client_init(const char *device, const char *p) } nd->vlan = vlan; nd->name = name; + nd->opts = p; name = NULL; nb_nics++; vlan->nb_guest_devs++; diff --git a/net.h b/net.h index 291807a..9e93dce 100644 --- a/net.h +++ b/net.h @@ -63,6 +63,7 @@ struct NICInfo { uint8_t macaddr[6]; const char *model; const char *name; + const char *opts; VLANState *vlan; }; -- 1.6.0.6