Skip to contentSkip to conversation

Use MachineClass->default_nic in more machines

PATCH In review Thomas Huth 4 participants 9 messages May 23, 2023 – May 25, 2023

lore
Share & tools
lore
#0 lore raw

cover Use MachineClass->default_nic in more machines

These patches are required for running more tests with "make check" on builds that use "--without-default-devices". By marking the default NIC in the generic MachineClass, the main code can decide whether the NIC is available in the binary or not, so the instantiation can be skipped if it has not been compiled in.

See https://lore.kernel.org/qemu-devel/[email protected]/
and the other patches in that series for more information.

Thomas Huth (5):
hw/hppa: Use MachineClass->default_nic in the hppa machine hw/alpha: Use MachineClass->default_nic in the alpha machine hw/arm: Use MachineClass->default_nic in the virt machine hw/loongarch64: Use MachineClass->default_nic in the virt machine hw/xtensa: Use MachineClass->default_nic in the virt machine

 hw/alpha/dp264.c    | 4 +++-
 hw/arm/virt.c       | 4 +++-
 hw/hppa/machine.c   | 4 +++-
 hw/loongarch/virt.c | 4 +++-
 hw/xtensa/virt.c    | 9 ++++++---
 5 files changed, 18 insertions(+), 7 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/5 hw/hppa: Use MachineClass->default_nic in the hppa machine

Mark the default NIC via the new MachineClass->default_nic setting so that the machine-defaults code in vl.c can decide whether the default NIC is usable or not (for example when compiling with the "--without-default-devices" configure switch).

---
 hw/hppa/machine.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/hppa/machine.c +3 -1
index 8fea5fa6b8..b00a91ecfe 100644
@@ -177,6 +177,7 @@ static void machine_hppa_init(MachineState *machine)
     const char *kernel_filename = machine->kernel_filename;
     const char *kernel_cmdline = machine->kernel_cmdline;
     const char *initrd_filename = machine->initrd_filename;
+    MachineClass *mc = MACHINE_GET_CLASS(machine);
     DeviceState *dev, *dino_dev, *lasi_dev;
     PCIBus *pci_bus;
     ISABus *isa_bus;
@@ -272,7 +273,7 @@ static void machine_hppa_init(MachineState *machine)
 
     for (i = 0; i < nb_nics; i++) {
         if (!enable_lasi_lan()) {
-            pci_nic_init_nofail(&nd_table[i], pci_bus, "tulip", NULL);
+            pci_nic_init_nofail(&nd_table[i], pci_bus, mc->default_nic, NULL);
         }
     }
 
@@ -462,6 +463,7 @@ static void hppa_machine_init_class_init(ObjectClass *oc, void *data)
     mc->default_ram_size = 512 * MiB;
     mc->default_boot_order = "cd";
     mc->default_ram_id = "ram";
+    mc->default_nic = "tulip";
 
     nc->nmi_monitor_handler = hppa_nmi;
 }
Signature · 1 line
2.31.1
#2 lore raw

PATCH 2/5 hw/alpha: Use MachineClass->default_nic in the alpha machine

In reply to Thomas Huth

Mark the default NIC via the new MachineClass->default_nic setting so that the machine-defaults code in vl.c can decide whether the default NIC is usable or not (for example when compiling with the "--without-default-devices" configure switch).

---
 hw/alpha/dp264.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/alpha/dp264.c +3 -1
index 4161f559a7..03495e1e60 100644
@@ -49,6 +49,7 @@ static void clipper_init(MachineState *machine)
     const char *kernel_filename = machine->kernel_filename;
     const char *kernel_cmdline = machine->kernel_cmdline;
     const char *initrd_filename = machine->initrd_filename;
+    MachineClass *mc = MACHINE_GET_CLASS(machine);
     AlphaCPU *cpus[4];
     PCIBus *pci_bus;
     PCIDevice *pci_dev;
@@ -124,7 +125,7 @@ static void clipper_init(MachineState *machine)
 
     /* Network setup.  e1000 is good enough, failing Tulip support.  */
     for (i = 0; i < nb_nics; i++) {
-        pci_nic_init_nofail(&nd_table[i], pci_bus, "e1000", NULL);
+        pci_nic_init_nofail(&nd_table[i], pci_bus, mc->default_nic, NULL);
     }
 
     /* Super I/O */
@@ -213,6 +214,7 @@ static void clipper_machine_init(MachineClass *mc)
     mc->is_default = true;
     mc->default_cpu_type = ALPHA_CPU_TYPE_NAME("ev67");
     mc->default_ram_id = "ram";
+    mc->default_nic = "e1000";
 }
 
 DEFINE_MACHINE("clipper", clipper_machine_init)
Signature · 1 line
2.31.1
#3 lore raw

PATCH 3/5 hw/arm: Use MachineClass->default_nic in the virt machine

In reply to Thomas Huth

Mark the default NIC via the new MachineClass->default_nic setting so that the machine-defaults code in vl.c can decide whether the default NIC is usable or not (for example when compiling with the "--without-default-devices" configure switch).

---
 hw/arm/virt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/arm/virt.c +3 -1
index b99ae18501..9b9f7d9c68 100644
@@ -1426,6 +1426,7 @@ static void create_pcie(VirtMachineState *vms)
     int i, ecam_id;
     PCIHostState *pci;
     MachineState *ms = MACHINE(vms);
+    MachineClass *mc = MACHINE_GET_CLASS(ms);
 
     dev = qdev_new(TYPE_GPEX_HOST);
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
@@ -1479,7 +1480,7 @@ static void create_pcie(VirtMachineState *vms)
             NICInfo *nd = &nd_table[i];
 
             if (!nd->model) {
-                nd->model = g_strdup("virtio");
+                nd->model = g_strdup(mc->default_nic);
             }
 
             pci_nic_init_nofail(nd, pci->bus, nd->model, NULL);
@@ -3033,6 +3034,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data)
     mc->auto_enable_numa_with_memhp = true;
     mc->auto_enable_numa_with_memdev = true;
     mc->default_ram_id = "mach-virt.ram";
+    mc->default_nic = "virtio-net-pci";
 
     object_class_property_add(oc, "acpi", "OnOffAuto",
         virt_get_acpi, virt_set_acpi,
Signature · 1 line
2.31.1
#4 lore raw

PATCH 4/5 hw/loongarch64: Use MachineClass->default_nic in the virt machine

In reply to Thomas Huth

Mark the default NIC via the new MachineClass->default_nic setting so that the machine-defaults code in vl.c can decide whether the default NIC is usable or not (for example when compiling with the "--without-default-devices" configure switch).

---
 hw/loongarch/virt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/loongarch/virt.c +3 -1
index 2b7588e32a..ceddec1b23 100644
@@ -474,6 +474,7 @@ static DeviceState *create_platform_bus(DeviceState *pch_pic)
 
 static void loongarch_devices_init(DeviceState *pch_pic, LoongArchMachineState *lams)
 {
+    MachineClass *mc = MACHINE_GET_CLASS(lams);
     DeviceState *gpex_dev;
     SysBusDevice *d;
     PCIBus *pci_bus;
@@ -528,7 +529,7 @@ static void loongarch_devices_init(DeviceState *pch_pic, LoongArchMachineState *
         NICInfo *nd = &nd_table[i];
 
         if (!nd->model) {
-            nd->model = g_strdup("virtio");
+            nd->model = g_strdup(mc->default_nic);
         }
 
         pci_nic_init_nofail(nd, pci_bus, nd->model, NULL);
@@ -1038,6 +1039,7 @@ static void loongarch_class_init(ObjectClass *oc, void *data)
     mc->default_boot_order = "c";
     mc->no_cdrom = 1;
     mc->get_hotplug_handler = virt_machine_get_hotplug_handler;
+    mc->default_nic = "virtio-net-pci";
     hc->plug = loongarch_machine_device_plug_cb;
     hc->pre_plug = virt_machine_device_pre_plug;
     hc->unplug_request = virt_machine_device_unplug_request;
Signature · 1 line
2.31.1
Tested-by Reviewed-by on v1 4/5
#5 lore raw

Re: [PATCH 4/5] hw/loongarch64: Use MachineClass->default_nic in the virt machine

Quoted 9 lines · Thomas Huth

Mark the default NIC via the new MachineClass->default_nic setting so that the machine-defaults code in vl.c can decide whether the default NIC is usable or not (for example when compiling with the "--without-default-devices" configure switch).

---
  hw/loongarch/virt.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

Thanks.
Song Gao

Quoted 29 lines
hw/loongarch/virt.c +3 -1
index 2b7588e32a..ceddec1b23 100644
@@ -474,6 +474,7 @@ static DeviceState *create_platform_bus(DeviceState *pch_pic)
 
  static void loongarch_devices_init(DeviceState *pch_pic, LoongArchMachineState *lams)
  {
+    MachineClass *mc = MACHINE_GET_CLASS(lams);
      DeviceState *gpex_dev;
      SysBusDevice *d;
      PCIBus *pci_bus;
@@ -528,7 +529,7 @@ static void loongarch_devices_init(DeviceState *pch_pic, LoongArchMachineState *
          NICInfo *nd = &nd_table[i];
 
          if (!nd->model) {
-            nd->model = g_strdup("virtio");
+            nd->model = g_strdup(mc->default_nic);
          }
 
          pci_nic_init_nofail(nd, pci_bus, nd->model, NULL);
@@ -1038,6 +1039,7 @@ static void loongarch_class_init(ObjectClass *oc, void *data)
      mc->default_boot_order = "c";
      mc->no_cdrom = 1;
      mc->get_hotplug_handler = virt_machine_get_hotplug_handler;
+    mc->default_nic = "virtio-net-pci";
      hc->plug = loongarch_machine_device_plug_cb;
      hc->pre_plug = virt_machine_device_pre_plug;
      hc->unplug_request = virt_machine_device_unplug_request;
#6 lore raw

PATCH 5/5 hw/xtensa: Use MachineClass->default_nic in the virt machine

In reply to Thomas Huth

Mark the default NIC via the new MachineClass->default_nic setting so that the machine-defaults code in vl.c can decide whether the default NIC is usable or not (for example when compiling with the "--without-default-devices" configure switch).

---
 hw/xtensa/virt.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
hw/xtensa/virt.c +6 -3
index a18e3fc910..b87f842e74 100644
@@ -38,7 +38,8 @@
 #include "xtensa_memory.h"
 #include "xtensa_sim.h"
 
-static void create_pcie(CPUXtensaState *env, int irq_base, hwaddr addr_base)
+static void create_pcie(MachineState *ms, CPUXtensaState *env, int irq_base,
+                        hwaddr addr_base)
 {
     hwaddr base_ecam = addr_base + 0x00100000;
     hwaddr size_ecam =             0x03f00000;
@@ -54,6 +55,7 @@ static void create_pcie(CPUXtensaState *env, int irq_base, hwaddr addr_base)
     MemoryRegion *mmio_alias;
     MemoryRegion *mmio_reg;
 
+    MachineClass *mc = MACHINE_GET_CLASS(ms);
     DeviceState *dev;
     PCIHostState *pci;
     qemu_irq *extints;
@@ -104,7 +106,7 @@ static void create_pcie(CPUXtensaState *env, int irq_base, hwaddr addr_base)
             NICInfo *nd = &nd_table[i];
 
             if (!nd->model) {
-                nd->model = g_strdup("virtio");
+                nd->model = g_strdup(mc->default_nic);
             }
 
             pci_nic_init_nofail(nd, pci->bus, nd->model, NULL);
@@ -117,7 +119,7 @@ static void xtensa_virt_init(MachineState *machine)
     XtensaCPU *cpu = xtensa_sim_common_init(machine);
     CPUXtensaState *env = &cpu->env;
 
-    create_pcie(env, 0, 0xf0000000);
+    create_pcie(machine, env, 0, 0xf0000000);
     xtensa_sim_load_kernel(cpu, machine);
 }
 
@@ -127,6 +129,7 @@ static void xtensa_virt_machine_init(MachineClass *mc)
     mc->init = xtensa_virt_init;
     mc->max_cpus = 32;
     mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
+    mc->default_nic = "virtio-net-pci";
 }
 
 DEFINE_MACHINE("virt", xtensa_virt_machine_init)
Signature · 1 line
2.31.1
Reviewed-by on the v1 series
#7 lore raw
In reply to Thomas Huth
Quoted 8 lines · Thomas Huth

These patches are required for running more tests with "make check" on builds that use "--without-default-devices". By marking the default NIC in the generic MachineClass, the main code can decide whether the NIC is available in the binary or not, so the instantiation can be skipped if it has not been compiled in.

Seehttps://lore.kernel.org/qemu-devel/[email protected]/ and the other patches in that series for more information.

r~

Reviewed-by Tested-by on the v1 series
#8 lore raw
In reply to Thomas Huth
Quoted 9 lines · Thomas Huth

These patches are required for running more tests with "make check" on builds that use "--without-default-devices". By marking the default NIC in the generic MachineClass, the main code can decide whether the NIC is available in the binary or not, so the instantiation can be skipped if it has not been compiled in.

See https://lore.kernel.org/qemu-devel/[email protected]/
and the other patches in that series for more information.

Quoted 6 lines

Thomas Huth (5):
hw/hppa: Use MachineClass->default_nic in the hppa machine hw/alpha: Use MachineClass->default_nic in the alpha machine hw/arm: Use MachineClass->default_nic in the virt machine hw/loongarch64: Use MachineClass->default_nic in the virt machine hw/xtensa: Use MachineClass->default_nic in the virt machine