Skip to content

Commit

Permalink
hw/arm/stellaris: use qemu_find_nic_info()
Browse files Browse the repository at this point in the history
Rather than just using qemu_configure_nic_device(), populate the MAC
address in the system-registers device by peeking at the NICInfo before
it's assigned to the device.

Generate the MAC address early, if there is no matching -nic option.
Otherwise the MAC address wouldn't be generated until net_client_init1()
runs.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Thomas Huth <thuth@redhat.com>
  • Loading branch information
dwmw2 committed Feb 2, 2024
1 parent 707a42e commit 1328084
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions hw/arm/stellaris.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,8 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
DeviceState *ssys_dev;
int i;
int j;
const uint8_t *macaddr;
NICInfo *nd;
MACAddr mac;

MemoryRegion *sram = g_new(MemoryRegion, 1);
MemoryRegion *flash = g_new(MemoryRegion, 1);
Expand All @@ -1051,12 +1052,22 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
* need its sysclk output.
*/
ssys_dev = qdev_new(TYPE_STELLARIS_SYS);
/* Most devices come preprogrammed with a MAC address in the user data. */
macaddr = nd_table[0].macaddr.a;

/*
* Most devices come preprogrammed with a MAC address in the user data.
* Generate a MAC address now, if there isn't a matching -nic for it.
*/
nd = qemu_find_nic_info("stellaris_enet", true, "stellaris");
if (nd) {
memcpy(mac.a, nd->macaddr.a, sizeof(mac.a));
} else {
qemu_macaddr_default_if_unset(&mac);
}

qdev_prop_set_uint32(ssys_dev, "user0",
macaddr[0] | (macaddr[1] << 8) | (macaddr[2] << 16));
mac.a[0] | (mac.a[1] << 8) | (mac.a[2] << 16));
qdev_prop_set_uint32(ssys_dev, "user1",
macaddr[3] | (macaddr[4] << 8) | (macaddr[5] << 16));
mac.a[3] | (mac.a[4] << 8) | (mac.a[5] << 16));
qdev_prop_set_uint32(ssys_dev, "did0", board->did0);
qdev_prop_set_uint32(ssys_dev, "did1", board->did1);
qdev_prop_set_uint32(ssys_dev, "dc0", board->dc0);
Expand Down Expand Up @@ -1269,10 +1280,13 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
if (board->dc4 & (1 << 28)) {
DeviceState *enet;

qemu_check_nic_model(&nd_table[0], "stellaris");

enet = qdev_new("stellaris_enet");
qdev_set_nic_properties(enet, &nd_table[0]);
if (nd) {
qdev_set_nic_properties(enet, nd);
} else {
qdev_prop_set_macaddr(enet, "mac", mac.a);
}

sysbus_realize_and_unref(SYS_BUS_DEVICE(enet), &error_fatal);
sysbus_mmio_map(SYS_BUS_DEVICE(enet), 0, 0x40048000);
sysbus_connect_irq(SYS_BUS_DEVICE(enet), 0, qdev_get_gpio_in(nvic, 42));
Expand Down

0 comments on commit 1328084

Please sign in to comment.