qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Mark McLoughlin <markmc@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: Mark McLoughlin <markmc@redhat.com>, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 1/5] Re-factor nic model listing
Date: Thu, 13 Nov 2008 16:45:59 +0000	[thread overview]
Message-ID: <1226594763-2304-2-git-send-email-markmc@redhat.com> (raw)
In-Reply-To: <1226594763-2304-1-git-send-email-markmc@redhat.com>

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 <markmc@redhat.com>
---
 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

  reply	other threads:[~2008-11-13 16:47 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-13 16:45 [Qemu-devel] [PATCH 0/5] Add "info capabilities" monitor command Mark McLoughlin
2008-11-13 16:45 ` Mark McLoughlin [this message]
2008-11-13 16:46   ` [Qemu-devel] [PATCH 2/5] Add cpu_list() for any targets that don't already have it Mark McLoughlin
2008-11-13 16:46     ` [Qemu-devel] [PATCH 3/5] Rename xxx_cpu_list() to cpu_xxx_list() Mark McLoughlin
2008-11-13 16:46       ` [Qemu-devel] [PATCH 4/5] Add new cpu_names() function Mark McLoughlin
2008-11-13 16:46         ` [Qemu-devel] [PATCH 5/5] monitor: add "info capabilities" command Mark McLoughlin
2008-11-13 19:50           ` [Qemu-devel] " Anthony Liguori
2008-11-14 16:02             ` Mark McLoughlin
2008-11-14 10:07           ` [Qemu-devel] " Avi Kivity
2008-11-14 15:58             ` Mark McLoughlin
2008-11-16  7:17               ` Avi Kivity
2008-11-14 10:13           ` Daniel P. Berrange
2008-11-13 19:47         ` [Qemu-devel] Re: [PATCH 4/5] Add new cpu_names() function Anthony Liguori
2008-11-14 15:36           ` Mark McLoughlin
2008-11-13 18:35   ` [Qemu-devel] [PATCH 1/5] Re-factor nic model listing Paul Brook
2008-11-13 19:45     ` Anthony Liguori
2008-11-13 22:50       ` Paul Brook
2008-11-14  2:31         ` Jamie Lokier
2008-11-14  2:49           ` Anthony Liguori
2008-11-13 19:44   ` [Qemu-devel] " Anthony Liguori
2008-11-14 15:34     ` Mark McLoughlin
2008-11-13 17:49 ` [Qemu-devel] [PATCH 0/5] Add "info capabilities" monitor command Blue Swirl
2008-11-14  2:50   ` Jamie Lokier
2008-11-14 16:09     ` Mark McLoughlin
2008-11-14  3:28 ` [Qemu-devel] " Anthony Liguori
2008-11-14  3:51   ` Jamie Lokier
2008-11-14 15:56     ` Mark McLoughlin
2008-11-14 22:54       ` Jamie Lokier
2008-11-14 15:51   ` Mark McLoughlin
2008-11-14 22:52     ` Jamie Lokier
2008-11-14 10:16 ` [Qemu-devel] " Daniel P. Berrange

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1226594763-2304-2-git-send-email-markmc@redhat.com \
    --to=markmc@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).