From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L0fLc-00042c-PE for qemu-devel@nongnu.org; Thu, 13 Nov 2008 11:47:12 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L0fLa-00040H-8e for qemu-devel@nongnu.org; Thu, 13 Nov 2008 11:47:10 -0500 Received: from [199.232.76.173] (port=36052 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L0fLZ-0003zs-Ez for qemu-devel@nongnu.org; Thu, 13 Nov 2008 11:47:09 -0500 Received: from mail04.svc.cra.dublin.eircom.net ([159.134.118.20]:40549) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1L0fLZ-0000AL-8x for qemu-devel@nongnu.org; Thu, 13 Nov 2008 11:47:09 -0500 From: Mark McLoughlin Date: Thu, 13 Nov 2008 16:45:59 +0000 Message-Id: <1226594763-2304-2-git-send-email-markmc@redhat.com> In-Reply-To: <1226594763-2304-1-git-send-email-markmc@redhat.com> References: <> <1226594763-2304-1-git-send-email-markmc@redhat.com> Subject: [Qemu-devel] [PATCH 1/5] Re-factor nic model listing Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Mark McLoughlin , qemu-devel@nongnu.org Add a nic_models() method to QEMUMachine and move the nic model listing from hw/pc.c to vl.c. pci_nic_models() is hooked up to all machines which use pci_nic_init(). The isapc machine is the only one which is slightly different since it only supports the ne2k_isa model. Signed-off-by: Mark McLoughlin --- hw/boards.h | 3 +++ hw/mips_malta.c | 1 + hw/pc.c | 35 +++++++++++++++++++---------------- hw/pci.c | 14 ++++++++++---- hw/pci.h | 1 + hw/ppc_chrp.c | 1 + hw/ppc_oldworld.c | 1 + hw/ppc_prep.c | 1 + hw/realview.c | 1 + hw/sun4u.c | 3 +++ hw/versatilepb.c | 2 ++ vl.c | 18 ++++++++++++++++++ 12 files changed, 61 insertions(+), 20 deletions(-) diff --git a/hw/boards.h b/hw/boards.h index d30c0fc..0097b4b 100644 --- a/hw/boards.h +++ b/hw/boards.h @@ -10,6 +10,8 @@ typedef void QEMUMachineInitFunc(ram_addr_t ram_size, int vga_ram_size, const char *initrd_filename, const char *cpu_model); +typedef const char * const *QEMUMachineNicModelsFunc(void); + typedef struct QEMUMachine { const char *name; const char *desc; @@ -19,6 +21,7 @@ typedef struct QEMUMachine { int nodisk_ok; int use_scsi; int max_cpus; + QEMUMachineNicModelsFunc *nic_models; struct QEMUMachine *next; } QEMUMachine; diff --git a/hw/mips_malta.c b/hw/mips_malta.c index 5027f8d..4b164f9 100644 --- a/hw/mips_malta.c +++ b/hw/mips_malta.c @@ -950,4 +950,5 @@ QEMUMachine mips_malta_machine = { .init = mips_malta_init, .ram_require = VGA_RAM_SIZE + BIOS_SIZE, .nodisk_ok = 1, + .nic_models = pci_nic_models, }; diff --git a/hw/pc.c b/hw/pc.c index 1486b68..23eac26 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -746,6 +746,13 @@ static void pc_init_ne2k_isa(NICInfo *nd, qemu_irq *pic) nb_ne2k++; } +static const char * const *isa_nic_models(void) +{ + static const char * const models[] = { "ne2k_isa", NULL }; + + return models; +} + /* PC hardware initialisation */ static void pc_init1(ram_addr_t ram_size, int vga_ram_size, const char *boot_device, DisplayState *ds, @@ -995,25 +1002,19 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size, for(i = 0; i < nb_nics; i++) { nd = &nd_table[i]; - if (!nd->model) { - if (pci_enabled) { + if (pci_enabled) { + if (!nd->model) nd->model = "ne2k_pci"; - } else { - nd->model = "ne2k_isa"; - } - } - if (strcmp(nd->model, "ne2k_isa") == 0) { - pc_init_ne2k_isa(nd, i8259); - } else if (pci_enabled) { - if (strcmp(nd->model, "?") == 0) - fprintf(stderr, "qemu: Supported ISA NICs: ne2k_isa\n"); pci_nic_init(pci_bus, nd, -1); - } else if (strcmp(nd->model, "?") == 0) { - fprintf(stderr, "qemu: Supported ISA NICs: ne2k_isa\n"); - exit(1); } else { - fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd->model); - exit(1); + if (!nd->model) + nd->model = "ne2k_isa"; + if (strcmp(nd->model, "ne2k_isa") == 0) + pc_init_ne2k_isa(nd, i8259); + else { + fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd->model); + exit(1); + } } } @@ -1124,6 +1125,7 @@ QEMUMachine pc_machine = { .init = pc_init_pci, .ram_require = VGA_RAM_SIZE + PC_MAX_BIOS_SIZE, .max_cpus = 255, + .nic_models = pci_nic_models, }; QEMUMachine isapc_machine = { @@ -1132,4 +1134,5 @@ QEMUMachine isapc_machine = { .init = pc_init_isa, .ram_require = VGA_RAM_SIZE + PC_MAX_BIOS_SIZE, .max_cpus = 1, + .nic_models = isa_nic_models, }; diff --git a/hw/pci.c b/hw/pci.c index a0f91a8..9eca1e5 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -640,16 +640,22 @@ void pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn) pci_e1000_init(bus, nd, devfn); } else if (strcmp(nd->model, "pcnet") == 0) { pci_pcnet_init(bus, nd, devfn); - } else if (strcmp(nd->model, "?") == 0) { - fprintf(stderr, "qemu: Supported PCI NICs: i82551 i82557b i82559er" - " ne2k_pci pcnet rtl8139 e1000\n"); - exit (1); } else { fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd->model); exit (1); } } +const char * const *pci_nic_models(void) +{ + static const char * const models[] = { + "ne2k_pci", "i82551", "i82557b", "i82559er", + "rtl8139", "e1000", "pcnet", NULL + }; + + return models; +} + typedef struct { PCIDevice dev; PCIBus *bus; diff --git a/hw/pci.h b/hw/pci.h index e870987..c48b31d 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -86,6 +86,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); +const char * const *pci_nic_models(void); void pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn); 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); diff --git a/hw/ppc_chrp.c b/hw/ppc_chrp.c index 5bdb805..5a5f2c1 100644 --- a/hw/ppc_chrp.c +++ b/hw/ppc_chrp.c @@ -336,4 +336,5 @@ QEMUMachine core99_machine = { .init = ppc_core99_init, .ram_require = BIOS_SIZE + VGA_RAM_SIZE, .max_cpus = MAX_CPUS, + .nic_models = pci_nic_models, }; diff --git a/hw/ppc_oldworld.c b/hw/ppc_oldworld.c index 0265596..188c987 100644 --- a/hw/ppc_oldworld.c +++ b/hw/ppc_oldworld.c @@ -371,4 +371,5 @@ QEMUMachine heathrow_machine = { .init = ppc_heathrow_init, .ram_require = BIOS_SIZE + VGA_RAM_SIZE, .max_cpus = MAX_CPUS, + .nic_models = pci_nic_models, }; diff --git a/hw/ppc_prep.c b/hw/ppc_prep.c index 8b5f85c..f061f71 100644 --- a/hw/ppc_prep.c +++ b/hw/ppc_prep.c @@ -765,4 +765,5 @@ QEMUMachine prep_machine = { .init = ppc_prep_init, .ram_require = BIOS_SIZE + VGA_RAM_SIZE, .max_cpus = MAX_CPUS, + .nic_models = pci_nic_models, }; diff --git a/hw/realview.c b/hw/realview.c index a9d20ed..cf18bb1 100644 --- a/hw/realview.c +++ b/hw/realview.c @@ -202,4 +202,5 @@ QEMUMachine realview_machine = { .init = realview_init, .ram_require = 0x1000, .use_scsi = 1, + .nic_models = pci_nic_models, }; diff --git a/hw/sun4u.c b/hw/sun4u.c index 48c1f2c..ce46378 100644 --- a/hw/sun4u.c +++ b/hw/sun4u.c @@ -592,6 +592,7 @@ QEMUMachine sun4u_machine = { .ram_require = PROM_SIZE_MAX + VGA_RAM_SIZE, .nodisk_ok = 1, .max_cpus = 1, // XXX for now + .nic_models = pci_nic_models, }; QEMUMachine sun4v_machine = { @@ -601,6 +602,7 @@ QEMUMachine sun4v_machine = { .ram_require = PROM_SIZE_MAX + VGA_RAM_SIZE, .nodisk_ok = 1, .max_cpus = 1, // XXX for now + .nic_models = pci_nic_models, }; QEMUMachine niagara_machine = { @@ -610,4 +612,5 @@ QEMUMachine niagara_machine = { .ram_require = PROM_SIZE_MAX + VGA_RAM_SIZE, .nodisk_ok = 1, .max_cpus = 1, // XXX for now + .nic_models = pci_nic_models, }; diff --git a/hw/versatilepb.c b/hw/versatilepb.c index f9e9988..caf3536 100644 --- a/hw/versatilepb.c +++ b/hw/versatilepb.c @@ -320,6 +320,7 @@ QEMUMachine versatilepb_machine = { .desc = "ARM Versatile/PB (ARM926EJ-S)", .init = vpb_init, .use_scsi = 1, + .nic_models = pci_nic_models, }; QEMUMachine versatileab_machine = { @@ -327,4 +328,5 @@ QEMUMachine versatileab_machine = { .desc = "ARM Versatile/AB (ARM926EJ-S)", .init = vab_init, .use_scsi = 1, + .nic_models = pci_nic_models, }; diff --git a/vl.c b/vl.c index 5f747cf..b53dfda 100644 --- a/vl.c +++ b/vl.c @@ -5226,6 +5226,24 @@ int main(int argc, char **argv) } net_client_check(); + for (i = 0; i < nb_nics; i++) { + const char * const *model; + + if (!nd_table[i].model || strcmp(nd_table[i].model, "?") != 0) + continue; + + fprintf(stderr, "qemu: Supported %s NICs:", machine->name); + + model = machine->nic_models ? machine->nic_models() : NULL; + while (model && *model) { + fprintf(stderr, "%c%s", i ? ',' : ' ', *model); + model++; + } + fprintf(stderr, "\n"); + + exit(0); + } + #ifdef TARGET_I386 /* XXX: this should be moved in the PC machine instantiation code */ if (net_boot != 0) { -- 1.5.4.3