hw/net/smc91c111: use qemu_configure_nic_device()

Some callers instantiate the device unconditionally, others will do so only
if there is a NICInfo to go with it. This appears to be fairly random, but
preserve the existing behaviour of each caller for now.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Thomas Huth <thuth@redhat.com>
This commit is contained in:
David Woodhouse 2023-10-23 09:37:35 +01:00
parent 8cef839c2d
commit cd53991de4
7 changed files with 22 additions and 37 deletions

View File

@ -73,8 +73,7 @@ static void connex_init(MachineState *machine)
FLASH_SECTOR_SIZE, 2, 0, 0, 0, 0, 0); FLASH_SECTOR_SIZE, 2, 0, 0, 0, 0, 0);
/* Interrupt line of NIC is connected to GPIO line 36 */ /* Interrupt line of NIC is connected to GPIO line 36 */
smc91c111_init(&nd_table[0], 0x04000300, smc91c111_init(0x04000300, qdev_get_gpio_in(cpu->gpio, 36));
qdev_get_gpio_in(cpu->gpio, 36));
} }
static void verdex_init(MachineState *machine) static void verdex_init(MachineState *machine)
@ -97,8 +96,7 @@ static void verdex_init(MachineState *machine)
FLASH_SECTOR_SIZE, 2, 0, 0, 0, 0, 0); FLASH_SECTOR_SIZE, 2, 0, 0, 0, 0, 0);
/* Interrupt line of NIC is connected to GPIO line 99 */ /* Interrupt line of NIC is connected to GPIO line 99 */
smc91c111_init(&nd_table[0], 0x04000300, smc91c111_init(0x04000300, qdev_get_gpio_in(cpu->gpio, 99));
qdev_get_gpio_in(cpu->gpio, 99));
} }
static void connex_class_init(ObjectClass *oc, void *data) static void connex_class_init(ObjectClass *oc, void *data)

View File

@ -666,8 +666,9 @@ static void integratorcp_init(MachineState *machine)
sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 0x1d000000); sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 0x1d000000);
sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, pic[25]); sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, pic[25]);
if (nd_table[0].used) if (qemu_find_nic_info("smc91c111", true, NULL)) {
smc91c111_init(&nd_table[0], 0xc8000000, pic[27]); smc91c111_init(0xc8000000, pic[27]);
}
sysbus_create_simple("pl110", 0xc0000000, pic[22]); sysbus_create_simple("pl110", 0xc0000000, pic[22]);

View File

@ -152,8 +152,7 @@ static void mainstone_common_init(MachineState *machine,
qdev_get_gpio_in(mst_irq, S1_IRQ), qdev_get_gpio_in(mst_irq, S1_IRQ),
qdev_get_gpio_in(mst_irq, S1_CD_IRQ)); qdev_get_gpio_in(mst_irq, S1_CD_IRQ));
smc91c111_init(&nd_table[0], MST_ETH_PHYS, smc91c111_init(MST_ETH_PHYS, qdev_get_gpio_in(mst_irq, ETHERNET_IRQ));
qdev_get_gpio_in(mst_irq, ETHERNET_IRQ));
mainstone_binfo.board_id = arm_id; mainstone_binfo.board_id = arm_id;
arm_load_kernel(mpu->cpu, machine, &mainstone_binfo); arm_load_kernel(mpu->cpu, machine, &mainstone_binfo);

View File

@ -90,7 +90,6 @@ static void realview_init(MachineState *machine,
I2CBus *i2c; I2CBus *i2c;
int n; int n;
unsigned int smp_cpus = machine->smp.cpus; unsigned int smp_cpus = machine->smp.cpus;
int done_nic = 0;
qemu_irq cpu_irq[4]; qemu_irq cpu_irq[4];
int is_mpcore = 0; int is_mpcore = 0;
int is_pb = 0; int is_pb = 0;
@ -296,24 +295,20 @@ static void realview_init(MachineState *machine,
n--; n--;
} }
} }
for(n = 0; n < nb_nics; n++) {
nd = &nd_table[n];
if (!done_nic && (!nd->model || nd = qemu_find_nic_info(is_pb ? "lan9118" : "smc91c111", true, NULL);
strcmp(nd->model, is_pb ? "lan9118" : "smc91c111") == 0)) { if (nd) {
if (is_pb) { if (is_pb) {
lan9118_init(nd, 0x4e000000, pic[28]); lan9118_init(nd, 0x4e000000, pic[28]);
} else {
smc91c111_init(nd, 0x4e000000, pic[28]);
}
done_nic = 1;
} else { } else {
if (pci_bus) { smc91c111_init(0x4e000000, pic[28]);
pci_nic_init_nofail(nd, pci_bus, "rtl8139", NULL);
}
} }
} }
if (pci_bus) {
pci_init_nic_devices(pci_bus, "rtl8139");
}
dev = sysbus_create_simple(TYPE_ARM_SBCON_I2C, 0x10002000, NULL); dev = sysbus_create_simple(TYPE_ARM_SBCON_I2C, 0x10002000, NULL);
i2c = (I2CBus *)qdev_get_child_bus(dev, "i2c"); i2c = (I2CBus *)qdev_get_child_bus(dev, "i2c");
i2c_slave_create_simple(i2c, "ds1338", 0x68); i2c_slave_create_simple(i2c, "ds1338", 0x68);

View File

@ -192,10 +192,8 @@ static void versatile_init(MachineState *machine, int board_id)
SysBusDevice *busdev; SysBusDevice *busdev;
DeviceState *pl041; DeviceState *pl041;
PCIBus *pci_bus; PCIBus *pci_bus;
NICInfo *nd;
I2CBus *i2c; I2CBus *i2c;
int n; int n;
int done_smc = 0;
DriveInfo *dinfo; DriveInfo *dinfo;
if (machine->ram_size > 0x10000000) { if (machine->ram_size > 0x10000000) {
@ -263,16 +261,11 @@ static void versatile_init(MachineState *machine, int board_id)
sysbus_connect_irq(busdev, 3, sic[30]); sysbus_connect_irq(busdev, 3, sic[30]);
pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci"); pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci");
for(n = 0; n < nb_nics; n++) { if (qemu_find_nic_info("smc91c111", true, NULL)) {
nd = &nd_table[n]; smc91c111_init(0x10010000, sic[25]);
if (!done_smc && (!nd->model || strcmp(nd->model, "smc91c111") == 0)) {
smc91c111_init(nd, 0x10010000, sic[25]);
done_smc = 1;
} else {
pci_nic_init_nofail(nd, pci_bus, "rtl8139", NULL);
}
} }
pci_init_nic_devices(pci_bus, "rtl8139");
if (machine_usb(machine)) { if (machine_usb(machine)) {
pci_create_simple(pci_bus, -1, "pci-ohci"); pci_create_simple(pci_bus, -1, "pci-ohci");
} }

View File

@ -818,14 +818,13 @@ static void smc91c111_register_types(void)
/* Legacy helper function. Should go away when machine config files are /* Legacy helper function. Should go away when machine config files are
implemented. */ implemented. */
void smc91c111_init(NICInfo *nd, uint32_t base, qemu_irq irq) void smc91c111_init(uint32_t base, qemu_irq irq)
{ {
DeviceState *dev; DeviceState *dev;
SysBusDevice *s; SysBusDevice *s;
qemu_check_nic_model(nd, "smc91c111");
dev = qdev_new(TYPE_SMC91C111); dev = qdev_new(TYPE_SMC91C111);
qdev_set_nic_properties(dev, nd); qemu_configure_nic_device(dev, true, NULL);
s = SYS_BUS_DEVICE(dev); s = SYS_BUS_DEVICE(dev);
sysbus_realize_and_unref(s, &error_fatal); sysbus_realize_and_unref(s, &error_fatal);
sysbus_mmio_map(s, 0, base); sysbus_mmio_map(s, 0, base);

View File

@ -13,6 +13,6 @@
#include "net/net.h" #include "net/net.h"
void smc91c111_init(NICInfo *, uint32_t, qemu_irq); void smc91c111_init(uint32_t, qemu_irq);
#endif #endif