From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Subject: [PULL 5/7] hw/mips/jazz: Move the NIC init code into a separate function
Date: Mon, 25 Sep 2023 11:00:58 +0200 [thread overview]
Message-ID: <20230925090100.45632-6-thuth@redhat.com> (raw)
In-Reply-To: <20230925090100.45632-1-thuth@redhat.com>
The mips_jazz_init() function is already quite big, so moving
away some code here can help to make it more understandable.
Additionally, by moving this code into a separate function, the
next patch (that will refactor the for-loop around the NIC init
code) will be much shorter and easier to understand.
Message-ID: <20230913160922.355640-2-thuth@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
hw/mips/jazz.c | 62 ++++++++++++++++++++++++++++----------------------
1 file changed, 35 insertions(+), 27 deletions(-)
diff --git a/hw/mips/jazz.c b/hw/mips/jazz.c
index 0081dcf921..829c9248e5 100644
--- a/hw/mips/jazz.c
+++ b/hw/mips/jazz.c
@@ -114,6 +114,40 @@ static const MemoryRegionOps dma_dummy_ops = {
.endianness = DEVICE_NATIVE_ENDIAN,
};
+static void mips_jazz_init_net(NICInfo *nd, IOMMUMemoryRegion *rc4030_dma_mr,
+ DeviceState *rc4030, MemoryRegion *dp8393x_prom)
+{
+ DeviceState *dev;
+ SysBusDevice *sysbus;
+ int checksum, i;
+ uint8_t *prom;
+
+ qemu_check_nic_model(nd, "dp83932");
+
+ dev = qdev_new("dp8393x");
+ qdev_set_nic_properties(dev, nd);
+ qdev_prop_set_uint8(dev, "it_shift", 2);
+ qdev_prop_set_bit(dev, "big_endian", TARGET_BIG_ENDIAN);
+ object_property_set_link(OBJECT(dev), "dma_mr",
+ OBJECT(rc4030_dma_mr), &error_abort);
+ sysbus = SYS_BUS_DEVICE(dev);
+ sysbus_realize_and_unref(sysbus, &error_fatal);
+ sysbus_mmio_map(sysbus, 0, 0x80001000);
+ sysbus_connect_irq(sysbus, 0, qdev_get_gpio_in(rc4030, 4));
+
+ /* Add MAC address with valid checksum to PROM */
+ prom = memory_region_get_ram_ptr(dp8393x_prom);
+ checksum = 0;
+ for (i = 0; i < 6; i++) {
+ prom[i] = nd->macaddr.a[i];
+ checksum += prom[i];
+ if (checksum > 0xff) {
+ checksum = (checksum + 1) & 0xff;
+ }
+ }
+ prom[7] = 0xff - checksum;
+}
+
#define MAGNUM_BIOS_SIZE_MAX 0x7e000
#define MAGNUM_BIOS_SIZE \
(BIOS_SIZE < MAGNUM_BIOS_SIZE_MAX ? BIOS_SIZE : MAGNUM_BIOS_SIZE_MAX)
@@ -287,33 +321,7 @@ static void mips_jazz_init(MachineState *machine,
nd->model = g_strdup("dp83932");
}
if (strcmp(nd->model, "dp83932") == 0) {
- int checksum, i;
- uint8_t *prom;
-
- qemu_check_nic_model(nd, "dp83932");
-
- dev = qdev_new("dp8393x");
- qdev_set_nic_properties(dev, nd);
- qdev_prop_set_uint8(dev, "it_shift", 2);
- qdev_prop_set_bit(dev, "big_endian", TARGET_BIG_ENDIAN);
- object_property_set_link(OBJECT(dev), "dma_mr",
- OBJECT(rc4030_dma_mr), &error_abort);
- sysbus = SYS_BUS_DEVICE(dev);
- sysbus_realize_and_unref(sysbus, &error_fatal);
- sysbus_mmio_map(sysbus, 0, 0x80001000);
- sysbus_connect_irq(sysbus, 0, qdev_get_gpio_in(rc4030, 4));
-
- /* Add MAC address with valid checksum to PROM */
- prom = memory_region_get_ram_ptr(dp8393x_prom);
- checksum = 0;
- for (i = 0; i < 6; i++) {
- prom[i] = nd->macaddr.a[i];
- checksum += prom[i];
- if (checksum > 0xff) {
- checksum = (checksum + 1) & 0xff;
- }
- }
- prom[7] = 0xff - checksum;
+ mips_jazz_init_net(nd, rc4030_dma_mr, rc4030, dp8393x_prom);
break;
} else if (is_help_option(nd->model)) {
error_report("Supported NICs: dp83932");
--
2.41.0
next prev parent reply other threads:[~2023-09-25 9:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-25 9:00 [PULL 0/7] qtest and misc patches Thomas Huth
2023-09-25 9:00 ` [PULL 1/7] meson.build: Make keyutils independent from keyring Thomas Huth
2023-09-25 9:00 ` [PULL 2/7] tests/qtest/netdev-socket: Raise connection timeout to 120 seconds Thomas Huth
2023-09-25 9:00 ` [PULL 3/7] tests/qtest/m48t59-test: Silence compiler warning with -Wshadow Thomas Huth
2023-09-25 9:00 ` [PULL 4/7] tests/qtest/netdev-socket: Do not test multicast on Darwin Thomas Huth
2023-09-25 9:00 ` Thomas Huth [this message]
2023-09-25 9:00 ` [PULL 6/7] hw/mips/jazz: Simplify the NIC setup code Thomas Huth
2023-09-25 9:01 ` [PULL 7/7] tests/avocado: fix waiting for vm shutdown in replay_linux Thomas Huth
2023-09-25 15:36 ` [PULL 0/7] qtest and misc patches Stefan Hajnoczi
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=20230925090100.45632-6-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.