Skip to contentSkip to conversation

Drop compile time limit on number of serial ports

PATCH Applied Peter Maydell 5 participants 50 messages Apr 20, 2018 – Apr 26, 2018

Subsystems (11)
lore
Share & tools
lore
#0 lore raw

cover Drop compile time limit on number of serial ports

For many years, QEMU has had a compile time restriction on how many serial port devices you can create and configure with the -serial argument. This is 4, largely because for x86 PC the traditional number of ISA serial devices is 4, and nobody's ever changed the limit since.

This patchset drops the compile time limit.

The first patch removes an unnecessary check in hw/char/serial that insisted that it was not talking to a NULL chardev. Our newly set direction is that we want to allow NULL chardev pointers, rather than requiring UARTs and boards to create "null" backends, so drop the check. (I have looked at the code and it should all be fine with a NULL pointer here, including the tricky bit where qemu_chr_fe_add_watch() returns 0 and the required behaviour is "insta-drain the FIFO".)

The next 4 patches drop unnecessary creations of "null" chardevs. These have to go here because in most cases they were writing back to the serial_hds[] array, which is about to go away.

Patch 6 implements an accessor function serial_hd() which can be used to replace direct reads of serial_hds[].

Patch 7 is purely mechanical and replaces serial_hds[x] with serial_hd(x).

Patches 8 through 11 remove or rename various uses of the MAX_SERIAL_PORTS #define that shouldn't really be using it.

Patch 12 then makes the serial_hds array be dynamically reallocated.

Patch 13 adds a "what actually is the highest serial_hds entry" function for the benefit of spapr, which is the only remaining user of MAX_SERIAL_PORTS.

Testing: I tested mips-malta and imx6 by hand; others are only tested via 'make check' (which did find some bugs for me!)

thanks
-- PMM

Peter Maydell (13):
hw/char/serial: Allow disconnected chardevs hw/arm/fsl-imx*: Don't create "null" chardevs for serial devices hw/mips/boston.c: Don't create "null" chardevs for serial devices hw/mips/mips_malta: Don't create "null" chardevs for serial devices hw/xtensa/xtfpga.c: Don't create "null" chardevs for serial devices vl.c: Provide accessor function serial_hd() for serial_hds[] array Change references to serial_hds[] to serial_hd()
Remove checks on MAX_SERIAL_PORTS that are just bounds checks hw/char/exynos4210_uart.c: Remove unneeded handling of NULL chardev
serial-isa: Use MAX_ISA_SERIAL_PORTS instead of MAX_SERIAL_PORTS
superio: Don't use MAX_SERIAL_PORTS for serial port limit vl.c: Remove compile time limit on number of serial ports vl.c: new function max_serial_hds()

 include/hw/char/serial.h                 |  3 +++
 include/hw/isa/superio.h                 |  4 +++-
 include/sysemu/sysemu.h                  |  9 +++++---
 hw/arm/allwinner-a10.c                   |  4 ++--
 hw/arm/aspeed_soc.c                      |  4 ++--
 hw/arm/bcm2835_peripherals.c             |  4 ++--
 hw/arm/digic.c                           |  2 +-
 hw/arm/fsl-imx25.c                       | 14 +-----------
 hw/arm/fsl-imx31.c                       | 14 +-----------
 hw/arm/fsl-imx6.c                        | 17 ++-------------
 hw/arm/fsl-imx7.c                        |  4 +---
 hw/arm/highbank.c                        |  2 +-
 hw/arm/integratorcp.c                    |  4 ++--
 hw/arm/kzm.c                             |  4 ++--
 hw/arm/mps2-tz.c                         |  3 +--
 hw/arm/mps2.c                            |  6 ++----
 hw/arm/msf2-soc.c                        |  4 ++--
 hw/arm/musicpal.c                        |  8 +++----
 hw/arm/omap1.c                           |  6 +++---
 hw/arm/omap2.c                           | 10 ++++-----
 hw/arm/pxa2xx.c                          | 16 +++++++-------
 hw/arm/realview.c                        |  8 +++----
 hw/arm/stellaris.c                       |  2 +-
 hw/arm/stm32f205_soc.c                   |  3 +--
 hw/arm/strongarm.c                       |  2 +-
 hw/arm/versatilepb.c                     |  8 +++----
 hw/arm/vexpress.c                        |  8 +++----
 hw/arm/virt.c                            |  4 ++--
 hw/arm/xilinx_zynq.c                     |  4 ++--
 hw/arm/xlnx-zynqmp.c                     |  2 +-
 hw/char/exynos4210_uart.c                | 20 ------------------
 hw/char/serial-isa.c                     | 14 ++++++------
 hw/char/serial.c                         |  5 -----
 hw/char/xen_console.c                    |  2 +-
 hw/cris/axis_dev88.c                     |  2 +-
 hw/hppa/machine.c                        |  4 ++--
 hw/i386/pc.c                             |  2 +-
 hw/isa/isa-superio.c                     |  4 ++--
 hw/lm32/lm32_boards.c                    |  8 +++----
 hw/lm32/milkymist.c                      |  4 ++--
 hw/m68k/mcf5206.c                        |  4 ++--
 hw/m68k/mcf5208.c                        |  6 +++---
 hw/microblaze/petalogix_ml605_mmu.c      |  2 +-
 hw/microblaze/petalogix_s3adsp1800_mmu.c |  2 +-
 hw/mips/boston.c                         |  6 +-----
 hw/mips/mips_jazz.c                      |  8 +++----
 hw/mips/mips_malta.c                     |  7 +-----
 hw/mips/mips_mipssim.c                   |  4 ++--
 hw/mips/mips_r4k.c                       |  2 +-
 hw/misc/macio/macio.c                    |  4 ++--
 hw/moxie/moxiesim.c                      |  4 ++--
 hw/nios2/10m50_devboard.c                |  2 +-
 hw/openrisc/openrisc_sim.c               |  2 +-
 hw/ppc/e500.c                            | 12 +++++------
 hw/ppc/pnv.c                             |  2 +-
 hw/ppc/ppc405_uc.c                       | 16 +++++++-------
 hw/ppc/ppc440_bamboo.c                   |  8 +++----
 hw/ppc/sam460ex.c                        |  8 +++----
 hw/ppc/spapr.c                           |  6 +++---
 hw/ppc/virtex_ml507.c                    |  2 +-
 hw/riscv/sifive_e.c                      |  4 ++--
 hw/riscv/sifive_u.c                      |  4 ++--
 hw/riscv/spike.c                         |  4 ++--
 hw/riscv/virt.c                          |  2 +-
 hw/sh4/r2d.c                             |  2 +-
 hw/sh4/sh7750.c                          |  4 ++--
 hw/sparc/leon3.c                         |  4 ++--
 hw/sparc/sun4m.c                         |  4 ++--
 hw/sparc64/niagara.c                     |  4 ++--
 hw/sparc64/sun4u.c                       |  4 ++--
 hw/xtensa/sim.c                          |  4 ++--
 hw/xtensa/xtfpga.c                       |  6 +-----
 vl.c                                     | 27 ++++++++++++++++++------
 73 files changed, 184 insertions(+), 244 deletions(-)
Signature · 1 line
2.17.0
#1 lore raw

PATCH 1/13 hw/char/serial: Allow disconnected chardevs

Currently the serial.c realize code has an explicit check that it is not connected to a disconnected backend (ie one with a NULL chardev). This isn't what we want -- you should be able to create a serial device even if it isn't attached to anything. Remove the check.

---
 hw/char/serial.c | 5 -----
 1 file changed, 5 deletions(-)
hw/char/serial.c +0 -5
index eb72191ee7..2c080c9862 100644
@@ -923,11 +923,6 @@ static int serial_be_change(void *opaque)
 
 void serial_realize_core(SerialState *s, Error **errp)
 {
-    if (!qemu_chr_fe_backend_connected(&s->chr)) {
-        error_setg(errp, "Can't create serial device, empty char device");
-        return;
-    }
-
     s->modem_status_poll = timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerCB *) serial_update_msl, s);
 
     s->fifo_timeout_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerCB *) fifo_timeout_int, s);
Signature · 1 line
2.17.0
Reviewed-by Tested-by on v1 1/13
#2 lore raw

Re: [Qemu-devel] [PATCH 01/13] hw/char/serial: Allow disconnected chardevs

Quoted 6 lines · Peter Maydell

Currently the serial.c realize code has an explicit check that it is not connected to a disconnected backend (ie one with a NULL chardev). This isn't what we want -- you should be able to create a serial device even if it isn't attached to anything. Remove the check.

Quoted 21 lines
---
 hw/char/serial.c | 5 -----
 1 file changed, 5 deletions(-)
hw/char/serial.c +0 -5
index eb72191ee7..2c080c9862 100644
@@ -923,11 +923,6 @@ static int serial_be_change(void *opaque)
 
 void serial_realize_core(SerialState *s, Error **errp)
 {
-    if (!qemu_chr_fe_backend_connected(&s->chr)) {
-        error_setg(errp, "Can't create serial device, empty char device");
-        return;
-    }
-
     s->modem_status_poll = timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerCB *) serial_update_msl, s);
 
     s->fifo_timeout_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerCB *) fifo_timeout_int, s);
Acked-by on v1 1/13
#3 lore raw

Re: [Qemu-devel] [PATCH 01/13] hw/char/serial: Allow disconnected chardevs

In reply to Peter Maydell
Quoted 17 lines · Peter Maydell

Currently the serial.c realize code has an explicit check that it is not connected to a disconnected backend (ie one with a NULL chardev). This isn't what we want -- you should be able to create a serial device even if it isn't attached to anything. Remove the check.

---
 hw/char/serial.c | 5 -----
 1 file changed, 5 deletions(-)
hw/char/serial.c +0 -0
index eb72191ee7..2c080c9862 100644
@@ -923,11 +923,6 @@ static int serial_be_change(void *opaque)
 

hw/char/serial.c static int serial_be_change(void *opaque) · line 928

Quoted 10 lines
hw/char/serial.c +0 -5
 void serial_realize_core(SerialState *s, Error **errp)
 {
-    if (!qemu_chr_fe_backend_connected(&s->chr)) {
-        error_setg(errp, "Can't create serial device, empty char device");
-        return;
-    }
-
     s->modem_status_poll = timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerCB *) serial_update_msl, s);
 
     s->fifo_timeout_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerCB *) fifo_timeout_int, s);
#4 lore raw

PATCH 2/13 hw/arm/fsl-imx*: Don't create "null" chardevs for serial devices

In reply to Peter Maydell

Following commit 12051d82f004024, UART devices should handle being passed a NULL pointer chardev, so we don't need to create "null" backends in board code. Remove the code that does this and updates serial_hds[].

(fsl-imx7.c was already written this way.)

---
 hw/arm/fsl-imx25.c | 12 +-----------
 hw/arm/fsl-imx31.c | 12 +-----------
 hw/arm/fsl-imx6.c  | 13 +------------
 3 files changed, 3 insertions(+), 34 deletions(-)
hw/arm/fsl-imx25.c +1 -11
index cb988a6c25..d7d064e5ce 100644
@@ -118,17 +118,7 @@ static void fsl_imx25_realize(DeviceState *dev, Error **errp)
         };
 
         if (i < MAX_SERIAL_PORTS) {
-            Chardev *chr;
-
-            chr = serial_hds[i];
-
-            if (!chr) {
-                char label[20];
-                snprintf(label, sizeof(label), "imx31.uart%d", i);
-                chr = qemu_chr_new(label, "null");
-            }
-
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", chr);
+            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hds[i]);
         }
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);
hw/arm/fsl-imx31.c +1 -11
index 3eee83d547..e6c788049d 100644
@@ -107,17 +107,7 @@ static void fsl_imx31_realize(DeviceState *dev, Error **errp)
         };
 
         if (i < MAX_SERIAL_PORTS) {
-            Chardev *chr;
-
-            chr = serial_hds[i];
-
-            if (!chr) {
-                char label[20];
-                snprintf(label, sizeof(label), "imx31.uart%d", i);
-                chr = qemu_chr_new(label, "null");
-            }
-
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", chr);
+            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hds[i]);
         }
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);
hw/arm/fsl-imx6.c +1 -12
index 9dfbc9a8c4..ea14de33c6 100644
@@ -189,18 +189,7 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp)
         };
 
         if (i < MAX_SERIAL_PORTS) {
-            Chardev *chr;
-
-            chr = serial_hds[i];
-
-            if (!chr) {
-                char *label = g_strdup_printf("imx6.uart%d", i + 1);
-                chr = qemu_chr_new(label, "null");
-                g_free(label);
-                serial_hds[i] = chr;
-            }
-
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", chr);
+            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hds[i]);
         }
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);
Signature · 1 line
2.17.0
Reviewed-by on v1 2/13
#5 lore raw

Re: [Qemu-devel] [PATCH 02/13] hw/arm/fsl-imx*: Don't create "null" chardevs for serial devices

Quoted 74 lines · Peter Maydell

Following commit 12051d82f004024, UART devices should handle being passed a NULL pointer chardev, so we don't need to create "null" backends in board code. Remove the code that does this and updates serial_hds[].

(fsl-imx7.c was already written this way.)

---
 hw/arm/fsl-imx25.c | 12 +-----------
 hw/arm/fsl-imx31.c | 12 +-----------
 hw/arm/fsl-imx6.c  | 13 +------------
 3 files changed, 3 insertions(+), 34 deletions(-)
hw/arm/fsl-imx25.c +1 -11
index cb988a6c25..d7d064e5ce 100644
@@ -118,17 +118,7 @@ static void fsl_imx25_realize(DeviceState *dev, Error **errp)
         };
 
         if (i < MAX_SERIAL_PORTS) {
-            Chardev *chr;
-
-            chr = serial_hds[i];
-
-            if (!chr) {
-                char label[20];
-                snprintf(label, sizeof(label), "imx31.uart%d", i);
-                chr = qemu_chr_new(label, "null");
-            }
-
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", chr);
+            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hds[i]);
         }
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);
hw/arm/fsl-imx31.c +1 -11
index 3eee83d547..e6c788049d 100644
@@ -107,17 +107,7 @@ static void fsl_imx31_realize(DeviceState *dev, Error **errp)
         };
 
         if (i < MAX_SERIAL_PORTS) {
-            Chardev *chr;
-
-            chr = serial_hds[i];
-
-            if (!chr) {
-                char label[20];
-                snprintf(label, sizeof(label), "imx31.uart%d", i);
-                chr = qemu_chr_new(label, "null");
-            }
-
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", chr);
+            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hds[i]);
         }
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);
hw/arm/fsl-imx6.c +0 -6
index 9dfbc9a8c4..ea14de33c6 100644
@@ -189,18 +189,7 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp)
         };
 
         if (i < MAX_SERIAL_PORTS) {
-            Chardev *chr;
-
-            chr = serial_hds[i];
-
-            if (!chr) {
-                char *label = g_strdup_printf("imx6.uart%d", i + 1);

hw/arm/fsl-imx6.c static void fsl_imx6_realize(DeviceState *dev, Error **errp) · line 195

Quoted 10 lines
hw/arm/fsl-imx6.c +1 -6
-                chr = qemu_chr_new(label, "null");
-                g_free(label);
-                serial_hds[i] = chr;
-            }
-
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", chr);
+            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hds[i]);
         }
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);

Removing the now unneeded #include "chardev/char.h" from the 3 files:

Reviewed-by on v1 2/13
#6 lore raw

Re: [Qemu-devel] [PATCH 02/13] hw/arm/fsl-imx*: Don't create "null" chardevs for serial devices

In reply to Peter Maydell
Quoted 5 lines · Peter Maydell

Following commit 12051d82f004024, UART devices should handle being passed a NULL pointer chardev, so we don't need to create "null" backends in board code. Remove the code that does this and updates serial_hds[].

Quoted 8 lines

(fsl-imx7.c was already written this way.)

---
 hw/arm/fsl-imx25.c | 12 +-----------
 hw/arm/fsl-imx31.c | 12 +-----------
 hw/arm/fsl-imx6.c  | 13 +------------
 3 files changed, 3 insertions(+), 34 deletions(-)
#7 lore raw

Re: [Qemu-devel] [PATCH 02/13] hw/arm/fsl-imx*: Don't create "null" chardevs for serial devices

In reply to Peter Maydell
Quoted 4 lines · Peter Maydell

Following commit 12051d82f004024, UART devices should handle being passed a NULL pointer chardev, so we don't need to create "null" backends in board code. Remove the code that does this and updates serial_hds[].

... maybe drop the "updates serial_hds" in this patch description since serial_hds is not updated here?

Thomas

#8 lore raw

Re: [Qemu-devel] [PATCH 02/13] hw/arm/fsl-imx*: Don't create "null" chardevs for serial devices

Quoted 8 lines · Thomas Huth
Quoted 4 lines · Peter Maydell

Following commit 12051d82f004024, UART devices should handle being passed a NULL pointer chardev, so we don't need to create "null" backends in board code. Remove the code that does this and updates serial_hds[].

... maybe drop the "updates serial_hds" in this patch description since serial_hds is not updated here?

It is in the fsl-imx6 case:

- serial_hds[i] = chr;

thanks
-- PMM

#9 lore raw

PATCH 3/13 hw/mips/boston.c: Don't create "null" chardevs for serial devices

In reply to Peter Maydell

Following commit 12051d82f004024, UART devices should handle being passed a NULL pointer chardev, so we don't need to create "null" backends in board code. Remove the code that
does this and updates serial_hds[].

---
 hw/mips/boston.c | 4 ----
 1 file changed, 4 deletions(-)
hw/mips/boston.c +0 -4
index fb23161b33..14f0f6673b 100644
@@ -505,10 +505,6 @@ static void boston_mach_init(MachineState *machine)
                           "boston-platregs", 0x1000);
     memory_region_add_subregion_overlap(sys_mem, 0x17ffd000, platreg, 0);
 
-    if (!serial_hds[0]) {
-        serial_hds[0] = qemu_chr_new("serial0", "null");
-    }
-
     s->uart = serial_mm_init(sys_mem, 0x17ffe000, 2,
                              get_cps_irq(s->cps, 3), 10000000,
                              serial_hds[0], DEVICE_NATIVE_ENDIAN);
Signature · 1 line
2.17.0
Reviewed-by Tested-by on v1 3/13
#10 lore raw

Re: [Qemu-devel] [PATCH 03/13] hw/mips/boston.c: Don't create "null" chardevs for serial devices

Quoted 6 lines · Peter Maydell

Following commit 12051d82f004024, UART devices should handle being passed a NULL pointer chardev, so we don't need to create "null" backends in board code. Remove the code that
does this and updates serial_hds[].

Quoted 20 lines
---
 hw/mips/boston.c | 4 ----
 1 file changed, 4 deletions(-)
hw/mips/boston.c +0 -4
index fb23161b33..14f0f6673b 100644
@@ -505,10 +505,6 @@ static void boston_mach_init(MachineState *machine)
                           "boston-platregs", 0x1000);
     memory_region_add_subregion_overlap(sys_mem, 0x17ffd000, platreg, 0);
 
-    if (!serial_hds[0]) {
-        serial_hds[0] = qemu_chr_new("serial0", "null");
-    }
-
     s->uart = serial_mm_init(sys_mem, 0x17ffe000, 2,
                              get_cps_irq(s->cps, 3), 10000000,
                              serial_hds[0], DEVICE_NATIVE_ENDIAN);
Reviewed-by on v1 3/13
#11 lore raw

Re: [Qemu-devel] [PATCH 03/13] hw/mips/boston.c: Don't create "null" chardevs for serial devices

In reply to Peter Maydell
Quoted 16 lines · Peter Maydell

Following commit 12051d82f004024, UART devices should handle being passed a NULL pointer chardev, so we don't need to create "null" backends in board code. Remove the code that
does this and updates serial_hds[].

---
 hw/mips/boston.c | 4 ----
 1 file changed, 4 deletions(-)
hw/mips/boston.c +0 -0
index fb23161b33..14f0f6673b 100644

hw/mips/boston.c static void boston_mach_init(MachineState *machine) · line 510

Quoted 10 lines
hw/mips/boston.c +0 -4
@@ -505,10 +505,6 @@ static void boston_mach_init(MachineState *machine)
                           "boston-platregs", 0x1000);
     memory_region_add_subregion_overlap(sys_mem, 0x17ffd000, platreg, 0);
 
-    if (!serial_hds[0]) {
-        serial_hds[0] = qemu_chr_new("serial0", "null");
-    }
-
     s->uart = serial_mm_init(sys_mem, 0x17ffe000, 2,
                              get_cps_irq(s->cps, 3), 10000000,
                              serial_hds[0], DEVICE_NATIVE_ENDIAN);
#12 lore raw

PATCH 4/13 hw/mips/mips_malta: Don't create "null" chardevs for serial devices

In reply to Peter Maydell

Following commit 12051d82f004024, UART devices should handle being passed a NULL pointer chardev, so we don't need to create "null" backends in board code. Remove the code that does this and updates serial_hds[].

---
 hw/mips/mips_malta.c | 5 -----
 1 file changed, 5 deletions(-)
hw/mips/mips_malta.c +0 -5
index f6513a4fd5..49fe7a0a72 100644
@@ -1056,11 +1056,6 @@ void mips_malta_init(MachineState *machine)
 
     /* FPGA */
 
-    /* Make sure the second serial port is associated with a device. */
-    if (!serial_hds[2]) {
-        serial_hds[2] = qemu_chr_new("fpga-uart", "null");
-    }
-
     /* The CBUS UART is attached to the MIPS CPU INT2 pin, ie interrupt 4 */
     malta_fpga_init(system_memory, FPGA_ADDRESS, cbus_irq, serial_hds[2]);
 
Signature · 1 line
2.17.0
Reviewed-by Tested-by on v1 4/13
#13 lore raw

Re: [Qemu-devel] [PATCH 04/13] hw/mips/mips_malta: Don't create "null" chardevs for serial devices

Quoted 6 lines · Peter Maydell

Following commit 12051d82f004024, UART devices should handle being passed a NULL pointer chardev, so we don't need to create "null" backends in board code. Remove the code that does this and updates serial_hds[].

Quoted 21 lines
---
 hw/mips/mips_malta.c | 5 -----
 1 file changed, 5 deletions(-)
hw/mips/mips_malta.c +0 -5
index f6513a4fd5..49fe7a0a72 100644
@@ -1056,11 +1056,6 @@ void mips_malta_init(MachineState *machine)
 
     /* FPGA */
 
-    /* Make sure the second serial port is associated with a device. */
-    if (!serial_hds[2]) {
-        serial_hds[2] = qemu_chr_new("fpga-uart", "null");
-    }
-
     /* The CBUS UART is attached to the MIPS CPU INT2 pin, ie interrupt 4 */
     malta_fpga_init(system_memory, FPGA_ADDRESS, cbus_irq, serial_hds[2]);
 
Reviewed-by on v1 4/13
#14 lore raw

Re: [Qemu-devel] [PATCH 04/13] hw/mips/mips_malta: Don't create "null" chardevs for serial devices

In reply to Peter Maydell
Quoted 15 lines · Peter Maydell

Following commit 12051d82f004024, UART devices should handle being passed a NULL pointer chardev, so we don't need to create "null" backends in board code. Remove the code that does this and updates serial_hds[].

---
 hw/mips/mips_malta.c | 5 -----
 1 file changed, 5 deletions(-)
hw/mips/mips_malta.c +0 -0
index f6513a4fd5..49fe7a0a72 100644

hw/mips/mips_malta.c void mips_malta_init(MachineState *machine) · line 1060

Quoted 10 lines
hw/mips/mips_malta.c +0 -5
@@ -1056,11 +1056,6 @@ void mips_malta_init(MachineState *machine)
 
     /* FPGA */
 
-    /* Make sure the second serial port is associated with a device. */
-    if (!serial_hds[2]) {
-        serial_hds[2] = qemu_chr_new("fpga-uart", "null");
-    }
-
     /* The CBUS UART is attached to the MIPS CPU INT2 pin, ie interrupt 4 */
     malta_fpga_init(system_memory, FPGA_ADDRESS, cbus_irq, serial_hds[2]);
#15 lore raw

PATCH 5/13 hw/xtensa/xtfpga.c: Don't create "null" chardevs for serial devices

In reply to Peter Maydell

Following commit 12051d82f004024, UART devices should handle being passed a NULL pointer chardev, so we don't need to create "null" backends in board code. Remove the code that does this and updates serial_hds[].

---
 hw/xtensa/xtfpga.c | 4 ----
 1 file changed, 4 deletions(-)
hw/xtensa/xtfpga.c +0 -4
index 70686a2eb1..9db99e1f7e 100644
@@ -278,10 +278,6 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
                 xtensa_get_extint(env, 1), nd_table);
     }
 
-    if (!serial_hds[0]) {
-        serial_hds[0] = qemu_chr_new("serial0", "null");
-    }
-
     serial_mm_init(system_io, 0x0d050020, 2, xtensa_get_extint(env, 0),
             115200, serial_hds[0], DEVICE_NATIVE_ENDIAN);
 
Signature · 1 line
2.17.0
Reviewed-by Tested-by on v1 5/13
#16 lore raw

Re: [Qemu-devel] [PATCH 05/13] hw/xtensa/xtfpga.c: Don't create "null" chardevs for serial devices

Quoted 6 lines · Peter Maydell

Following commit 12051d82f004024, UART devices should handle being passed a NULL pointer chardev, so we don't need to create "null" backends in board code. Remove the code that does this and updates serial_hds[].

Quoted 20 lines
---
 hw/xtensa/xtfpga.c | 4 ----
 1 file changed, 4 deletions(-)
hw/xtensa/xtfpga.c +0 -4
index 70686a2eb1..9db99e1f7e 100644
@@ -278,10 +278,6 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
                 xtensa_get_extint(env, 1), nd_table);
     }
 
-    if (!serial_hds[0]) {
-        serial_hds[0] = qemu_chr_new("serial0", "null");
-    }
-
     serial_mm_init(system_io, 0x0d050020, 2, xtensa_get_extint(env, 0),
             115200, serial_hds[0], DEVICE_NATIVE_ENDIAN);
 
Reviewed-by on v1 5/13
#17 lore raw

Re: [Qemu-devel] [PATCH 05/13] hw/xtensa/xtfpga.c: Don't create "null" chardevs for serial devices

In reply to Peter Maydell
Quoted 15 lines · Peter Maydell

Following commit 12051d82f004024, UART devices should handle being passed a NULL pointer chardev, so we don't need to create "null" backends in board code. Remove the code that does this and updates serial_hds[].

---
 hw/xtensa/xtfpga.c | 4 ----
 1 file changed, 4 deletions(-)
hw/xtensa/xtfpga.c +0 -0
index 70686a2eb1..9db99e1f7e 100644

hw/xtensa/xtfpga.c static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine) · line 282

Quoted 9 lines
hw/xtensa/xtfpga.c +0 -4
@@ -278,10 +278,6 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
                 xtensa_get_extint(env, 1), nd_table);
     }
 
-    if (!serial_hds[0]) {
-        serial_hds[0] = qemu_chr_new("serial0", "null");
-    }
-
     serial_mm_init(system_io, 0x0d050020, 2, xtensa_get_extint(env, 0),
             115200, serial_hds[0], DEVICE_NATIVE_ENDIAN);
#18 lore raw

PATCH 6/13 vl.c: Provide accessor function serial_hd() for serial_hds[] array

In reply to Peter Maydell

Provide an accessor function serial_hd() to return the Chardev (if any) associated with the numbered serial port. This will be used to replace direct accesses to the serial_hds[] array, so that calling code doesn't need to care about the size of that array.

---
 include/sysemu/sysemu.h | 3 +++
 vl.c                    | 9 +++++++++
 2 files changed, 12 insertions(+)
include/sysemu/sysemu.h +3 -0
index 2b42151c63..bd5b55c514 100644
@@ -163,6 +163,9 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict);
 
 extern Chardev *serial_hds[MAX_SERIAL_PORTS];
 
+/* Return the Chardev for serial port i, or NULL if none */
+Chardev *serial_hd(int i);
+
 /* parallel ports */
 
 #define MAX_PARALLEL_PORTS 3
vl.c +9 -0
index fce1fd12d8..6daf026da6 100644
@@ -2516,6 +2516,15 @@ static int serial_parse(const char *devname)
     return 0;
 }
 
+Chardev *serial_hd(int i)
+{
+    assert(i >= 0);
+    if (i < ARRAY_SIZE(serial_hds)) {
+        return serial_hds[i];
+    }
+    return NULL;
+}
+
 static int parallel_parse(const char *devname)
 {
     static int index = 0;
Signature · 1 line
2.17.0
Reviewed-by Tested-by on v1 6/13
#19 lore raw

Re: [Qemu-devel] [PATCH 06/13] vl.c: Provide accessor function serial_hd() for serial_hds[] array

Quoted 7 lines · Peter Maydell

Provide an accessor function serial_hd() to return the Chardev (if any) associated with the numbered serial port. This will be used to replace direct accesses to the serial_hds[] array, so that calling code doesn't need to care about the size of that array.

Quoted 40 lines
---
 include/sysemu/sysemu.h | 3 +++
 vl.c                    | 9 +++++++++
 2 files changed, 12 insertions(+)
include/sysemu/sysemu.h +3 -0
index 2b42151c63..bd5b55c514 100644
@@ -163,6 +163,9 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict);
 
 extern Chardev *serial_hds[MAX_SERIAL_PORTS];
 
+/* Return the Chardev for serial port i, or NULL if none */
+Chardev *serial_hd(int i);
+
 /* parallel ports */
 
 #define MAX_PARALLEL_PORTS 3
vl.c +9 -0
index fce1fd12d8..6daf026da6 100644
@@ -2516,6 +2516,15 @@ static int serial_parse(const char *devname)
     return 0;
 }
 
+Chardev *serial_hd(int i)
+{
+    assert(i >= 0);
+    if (i < ARRAY_SIZE(serial_hds)) {
+        return serial_hds[i];
+    }
+    return NULL;
+}
+
 static int parallel_parse(const char *devname)
 {
     static int index = 0;
Reviewed-by on v1 6/13
#20 lore raw

Re: [Qemu-devel] [PATCH 06/13] vl.c: Provide accessor function serial_hd() for serial_hds[] array

In reply to Peter Maydell
Quoted 37 lines · Peter Maydell

Provide an accessor function serial_hd() to return the Chardev (if any) associated with the numbered serial port. This will be used to replace direct accesses to the serial_hds[] array, so that calling code doesn't need to care about the size of that array.

---
 include/sysemu/sysemu.h | 3 +++
 vl.c                    | 9 +++++++++
 2 files changed, 12 insertions(+)
include/sysemu/sysemu.h +3 -0
index 2b42151c63..bd5b55c514 100644
@@ -163,6 +163,9 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict);
 
 extern Chardev *serial_hds[MAX_SERIAL_PORTS];
 
+/* Return the Chardev for serial port i, or NULL if none */
+Chardev *serial_hd(int i);
+
 /* parallel ports */
 
 #define MAX_PARALLEL_PORTS 3
vl.c +2 -0
index fce1fd12d8..6daf026da6 100644
@@ -2516,6 +2516,15 @@ static int serial_parse(const char *devname)
     return 0;
 }
 
+Chardev *serial_hd(int i)
+{

vl.c static int serial_parse(const char *devname) · line 2530

Quoted 10 lines
vl.c +7 -0
+    assert(i >= 0);
+    if (i < ARRAY_SIZE(serial_hds)) {
+        return serial_hds[i];
+    }
+    return NULL;
+}
+
 static int parallel_parse(const char *devname)
 {
     static int index = 0;
#21 lore raw

PATCH 7/13 Change references to serial_hds[] to serial_hd()

In reply to Peter Maydell

Change all the uses of serial_hds[] to go via the new
serial_hd() function. Code change produced with:
find hw -name '*.[ch]' | xargs sed -i -e 's/serial_hds\[\([^]]*\)\]/serial_hd(\1)/g'

---
 hw/arm/allwinner-a10.c                   |  4 ++--
 hw/arm/aspeed_soc.c                      |  4 ++--
 hw/arm/bcm2835_peripherals.c             |  4 ++--
 hw/arm/digic.c                           |  2 +-
 hw/arm/fsl-imx25.c                       |  2 +-
 hw/arm/fsl-imx31.c                       |  2 +-
 hw/arm/fsl-imx6.c                        |  4 ++--
 hw/arm/fsl-imx7.c                        |  2 +-
 hw/arm/highbank.c                        |  2 +-
 hw/arm/integratorcp.c                    |  4 ++--
 hw/arm/kzm.c                             |  4 ++--
 hw/arm/mps2-tz.c                         |  2 +-
 hw/arm/mps2.c                            |  4 ++--
 hw/arm/msf2-soc.c                        |  4 ++--
 hw/arm/musicpal.c                        |  8 ++++----
 hw/arm/omap1.c                           |  6 +++---
 hw/arm/omap2.c                           | 10 +++++-----
 hw/arm/pxa2xx.c                          | 16 ++++++++--------
 hw/arm/realview.c                        |  8 ++++----
 hw/arm/stellaris.c                       |  2 +-
 hw/arm/stm32f205_soc.c                   |  2 +-
 hw/arm/strongarm.c                       |  2 +-
 hw/arm/versatilepb.c                     |  8 ++++----
 hw/arm/vexpress.c                        |  8 ++++----
 hw/arm/virt.c                            |  4 ++--
 hw/arm/xilinx_zynq.c                     |  4 ++--
 hw/arm/xlnx-zynqmp.c                     |  2 +-
 hw/char/exynos4210_uart.c                |  2 +-
 hw/char/serial-isa.c                     |  4 ++--
 hw/char/xen_console.c                    |  2 +-
 hw/cris/axis_dev88.c                     |  2 +-
 hw/hppa/machine.c                        |  4 ++--
 hw/isa/isa-superio.c                     |  4 ++--
 hw/lm32/lm32_boards.c                    |  8 ++++----
 hw/lm32/milkymist.c                      |  4 ++--
 hw/m68k/mcf5206.c                        |  4 ++--
 hw/m68k/mcf5208.c                        |  6 +++---
 hw/microblaze/petalogix_ml605_mmu.c      |  2 +-
 hw/microblaze/petalogix_s3adsp1800_mmu.c |  2 +-
 hw/mips/boston.c                         |  2 +-
 hw/mips/mips_jazz.c                      |  8 ++++----
 hw/mips/mips_malta.c                     |  2 +-
 hw/mips/mips_mipssim.c                   |  4 ++--
 hw/misc/macio/macio.c                    |  4 ++--
 hw/moxie/moxiesim.c                      |  4 ++--
 hw/nios2/10m50_devboard.c                |  2 +-
 hw/openrisc/openrisc_sim.c               |  2 +-
 hw/ppc/e500.c                            | 12 ++++++------
 hw/ppc/ppc405_uc.c                       | 16 ++++++++--------
 hw/ppc/ppc440_bamboo.c                   |  8 ++++----
 hw/ppc/sam460ex.c                        |  8 ++++----
 hw/ppc/spapr.c                           |  4 ++--
 hw/ppc/virtex_ml507.c                    |  2 +-
 hw/riscv/sifive_e.c                      |  4 ++--
 hw/riscv/sifive_u.c                      |  4 ++--
 hw/riscv/spike.c                         |  4 ++--
 hw/riscv/virt.c                          |  2 +-
 hw/sh4/r2d.c                             |  2 +-
 hw/sh4/sh7750.c                          |  4 ++--
 hw/sparc/leon3.c                         |  4 ++--
 hw/sparc/sun4m.c                         |  4 ++--
 hw/sparc64/niagara.c                     |  4 ++--
 hw/sparc64/sun4u.c                       |  2 +-
 hw/xtensa/sim.c                          |  4 ++--
 hw/xtensa/xtfpga.c                       |  2 +-
 65 files changed, 143 insertions(+), 143 deletions(-)
hw/arm/allwinner-a10.c +2 -2
index 5dbbacb7e8..c5fbc654f2 100644
@@ -108,9 +108,9 @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->sata), 0, AW_A10_SATA_BASE);
     sysbus_connect_irq(SYS_BUS_DEVICE(&s->sata), 0, s->irq[56]);
 
-    /* FIXME use a qdev chardev prop instead of serial_hds[] */
+    /* FIXME use a qdev chardev prop instead of serial_hd() */
     serial_mm_init(get_system_memory(), AW_A10_UART0_REG_BASE, 2, s->irq[1],
-                   115200, serial_hds[0], DEVICE_NATIVE_ENDIAN);
+                   115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);
 }
 
 static void aw_a10_class_init(ObjectClass *oc, void *data)
hw/arm/aspeed_soc.c +2 -2
index 30d25f8b06..1219167a5e 100644
@@ -229,11 +229,11 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->scu), 0, ASPEED_SOC_SCU_BASE);
 
     /* UART - attach an 8250 to the IO space as our UART5 */
-    if (serial_hds[0]) {
+    if (serial_hd(0)) {
         qemu_irq uart5 = qdev_get_gpio_in(DEVICE(&s->vic), uart_irqs[4]);
         serial_mm_init(get_system_memory(),
                        ASPEED_SOC_IOMEM_BASE + ASPEED_SOC_UART_5_BASE, 2,
-                       uart5, 38400, serial_hds[0], DEVICE_LITTLE_ENDIAN);
+                       uart5, 38400, serial_hd(0), DEVICE_LITTLE_ENDIAN);
     }
 
     /* I2C */
hw/arm/bcm2835_peripherals.c +2 -2
index 13b63970d7..6be7660e8c 100644
@@ -166,7 +166,7 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
     sysbus_pass_irq(SYS_BUS_DEVICE(s), SYS_BUS_DEVICE(&s->ic));
 
     /* UART0 */
-    qdev_prop_set_chr(DEVICE(s->uart0), "chardev", serial_hds[0]);
+    qdev_prop_set_chr(DEVICE(s->uart0), "chardev", serial_hd(0));
     object_property_set_bool(OBJECT(s->uart0), true, "realized", &err);
     if (err) {
         error_propagate(errp, err);
@@ -179,7 +179,7 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
         qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ,
                                INTERRUPT_UART));
     /* AUX / UART1 */
-    qdev_prop_set_chr(DEVICE(&s->aux), "chardev", serial_hds[1]);
+    qdev_prop_set_chr(DEVICE(&s->aux), "chardev", serial_hd(1));
 
     object_property_set_bool(OBJECT(&s->aux), true, "realized", &err);
     if (err) {
hw/arm/digic.c +1 -1
index 6184020985..726abb9b48 100644
@@ -85,7 +85,7 @@ static void digic_realize(DeviceState *dev, Error **errp)
         sysbus_mmio_map(sbd, 0, DIGIC4_TIMER_BASE(i));
     }
 
-    qdev_prop_set_chr(DEVICE(&s->uart), "chardev", serial_hds[0]);
+    qdev_prop_set_chr(DEVICE(&s->uart), "chardev", serial_hd(0));
     object_property_set_bool(OBJECT(&s->uart), true, "realized", &err);
     if (err != NULL) {
         error_propagate(errp, err);
hw/arm/fsl-imx25.c +1 -1
index d7d064e5ce..9731833fa5 100644
@@ -118,7 +118,7 @@ static void fsl_imx25_realize(DeviceState *dev, Error **errp)
         };
 
         if (i < MAX_SERIAL_PORTS) {
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hds[i]);
+            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
         }
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);
hw/arm/fsl-imx31.c +1 -1
index e6c788049d..8509915200 100644
@@ -107,7 +107,7 @@ static void fsl_imx31_realize(DeviceState *dev, Error **errp)
         };
 
         if (i < MAX_SERIAL_PORTS) {
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hds[i]);
+            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
         }
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);
hw/arm/fsl-imx6.c +2 -2
index ea14de33c6..535ad5888b 100644
@@ -189,7 +189,7 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp)
         };
 
         if (i < MAX_SERIAL_PORTS) {
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hds[i]);
+            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
         }
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);
@@ -438,7 +438,7 @@ static void fsl_imx6_class_init(ObjectClass *oc, void *data)
 
     dc->realize = fsl_imx6_realize;
     dc->desc = "i.MX6 SOC";
-    /* Reason: Uses serial_hds[] in the realize() function */
+    /* Reason: Uses serial_hd() in the realize() function */
     dc->user_creatable = false;
 }
 
hw/arm/fsl-imx7.c +1 -1
index 390b4310e6..2848d76d3c 100644
@@ -391,7 +391,7 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
 
 
         if (i < MAX_SERIAL_PORTS) {
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hds[i]);
+            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
         }
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized",
hw/arm/highbank.c +1 -1
index 1742cf6f6c..0851d3b28a 100644
@@ -342,7 +342,7 @@ static void calxeda_init(MachineState *machine, enum cxmachines machine_id)
     busdev = SYS_BUS_DEVICE(dev);
     sysbus_mmio_map(busdev, 0, 0xfff34000);
     sysbus_connect_irq(busdev, 0, pic[18]);
-    pl011_create(0xfff36000, pic[20], serial_hds[0]);
+    pl011_create(0xfff36000, pic[20], serial_hd(0));
 
     dev = qdev_create(NULL, TYPE_HIGHBANK_REGISTERS);
     qdev_init_nofail(dev);
hw/arm/integratorcp.c +2 -2
index 58b40efc19..4eceebb9ea 100644
@@ -631,8 +631,8 @@ static void integratorcp_init(MachineState *machine)
     sysbus_create_varargs("integrator_pit", 0x13000000,
                           pic[5], pic[6], pic[7], NULL);
     sysbus_create_simple("pl031", 0x15000000, pic[8]);
-    pl011_create(0x16000000, pic[1], serial_hds[0]);
-    pl011_create(0x17000000, pic[2], serial_hds[1]);
+    pl011_create(0x16000000, pic[1], serial_hd(0));
+    pl011_create(0x17000000, pic[2], serial_hd(1));
     icp = sysbus_create_simple(TYPE_ICP_CONTROL_REGS, 0xcb000000,
                                qdev_get_gpio_in(sic, 3));
     sysbus_create_simple("pl050_keyboard", 0x18000000, pic[3]);
hw/arm/kzm.c +2 -2
index f9c2228e31..864c7bd411 100644
@@ -121,10 +121,10 @@ static void kzm_init(MachineState *machine)
                      qdev_get_gpio_in(DEVICE(&s->soc.avic), 52));
     }
 
-    if (serial_hds[2]) { /* touchscreen */
+    if (serial_hd(2)) { /* touchscreen */
         serial_mm_init(get_system_memory(), KZM_FPGA_ADDR+0x10, 0,
                        qdev_get_gpio_in(DEVICE(&s->soc.avic), 52),
-                       14745600, serial_hds[2], DEVICE_NATIVE_ENDIAN);
+                       14745600, serial_hd(2), DEVICE_NATIVE_ENDIAN);
     }
 
     kzm_binfo.ram_size = machine->ram_size;
hw/arm/mps2-tz.c +1 -1
index 8c86cffa9e..4ae4a5cb2a 100644
@@ -172,7 +172,7 @@ static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
 {
     CMSDKAPBUART *uart = opaque;
     int i = uart - &mms->uart[0];
-    Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hds[i] : NULL;
+    Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hd(i) : NULL;
     int rxirqno = i * 2;
     int txirqno = i * 2 + 1;
     int combirqno = i + 10;
hw/arm/mps2.c +2 -2
index 694fb36866..eb550fad34 100644
@@ -230,7 +230,7 @@ static void mps2_common_init(MachineState *machine)
             static const hwaddr uartbase[] = {0x40004000, 0x40005000,
                                               0x40006000, 0x40007000,
                                               0x40009000};
-            Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hds[i] : NULL;
+            Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hd(i) : NULL;
             /* RX irq number; TX irq is always one greater */
             static const int uartirq[] = {0, 2, 4, 18, 20};
             qemu_irq txovrint = NULL, rxovrint = NULL;
@@ -270,7 +270,7 @@ static void mps2_common_init(MachineState *machine)
             static const hwaddr uartbase[] = {0x40004000, 0x40005000,
                                               0x4002c000, 0x4002d000,
                                               0x4002e000};
-            Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hds[i] : NULL;
+            Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hd(i) : NULL;
             Object *txrx_orgate;
             DeviceState *txrx_orgate_dev;
 
hw/arm/msf2-soc.c +2 -2
index f68df56b97..75c44adf7d 100644
@@ -138,10 +138,10 @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp)
     system_clock_scale = NANOSECONDS_PER_SECOND / s->m3clk;
 
     for (i = 0; i < MSF2_NUM_UARTS; i++) {
-        if (serial_hds[i]) {
+        if (serial_hd(i)) {
             serial_mm_init(get_system_memory(), uart_addr[i], 2,
                            qdev_get_gpio_in(armv7m, uart_irq[i]),
-                           115200, serial_hds[i], DEVICE_NATIVE_ENDIAN);
+                           115200, serial_hd(i), DEVICE_NATIVE_ENDIAN);
         }
     }
 
hw/arm/musicpal.c +4 -4
index 38d7322a19..c807010e83 100644
@@ -1610,13 +1610,13 @@ static void musicpal_init(MachineState *machine)
                           pic[MP_TIMER2_IRQ], pic[MP_TIMER3_IRQ],
                           pic[MP_TIMER4_IRQ], NULL);
 
-    if (serial_hds[0]) {
+    if (serial_hd(0)) {
         serial_mm_init(address_space_mem, MP_UART1_BASE, 2, pic[MP_UART1_IRQ],
-                       1825000, serial_hds[0], DEVICE_NATIVE_ENDIAN);
+                       1825000, serial_hd(0), DEVICE_NATIVE_ENDIAN);
     }
-    if (serial_hds[1]) {
+    if (serial_hd(1)) {
         serial_mm_init(address_space_mem, MP_UART2_BASE, 2, pic[MP_UART2_IRQ],
-                       1825000, serial_hds[1], DEVICE_NATIVE_ENDIAN);
+                       1825000, serial_hd(1), DEVICE_NATIVE_ENDIAN);
     }
 
     /* Register flash */
hw/arm/omap1.c +3 -3
index b3a23a83d1..24673abfca 100644
@@ -3963,21 +3963,21 @@ struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *system_memory,
                     omap_findclk(s, "uart1_ck"),
                     s->drq[OMAP_DMA_UART1_TX], s->drq[OMAP_DMA_UART1_RX],
                     "uart1",
-                    serial_hds[0]);
+                    serial_hd(0));
     s->uart[1] = omap_uart_init(0xfffb0800,
                                 qdev_get_gpio_in(s->ih[1], OMAP_INT_UART2),
                     omap_findclk(s, "uart2_ck"),
                     omap_findclk(s, "uart2_ck"),
                     s->drq[OMAP_DMA_UART2_TX], s->drq[OMAP_DMA_UART2_RX],
                     "uart2",
-                    serial_hds[0] ? serial_hds[1] : NULL);
+                    serial_hd(0) ? serial_hd(1) : NULL);
     s->uart[2] = omap_uart_init(0xfffb9800,
                                 qdev_get_gpio_in(s->ih[0], OMAP_INT_UART3),
                     omap_findclk(s, "uart3_ck"),
                     omap_findclk(s, "uart3_ck"),
                     s->drq[OMAP_DMA_UART3_TX], s->drq[OMAP_DMA_UART3_RX],
                     "uart3",
-                    serial_hds[0] && serial_hds[1] ? serial_hds[2] : NULL);
+                    serial_hd(0) && serial_hd(1) ? serial_hd(2) : NULL);
 
     s->dpll[0] = omap_dpll_init(system_memory, 0xfffecf00,
                                 omap_findclk(s, "dpll1"));
hw/arm/omap2.c +5 -5
index 647b119ba9..80663533e1 100644
@@ -2349,7 +2349,7 @@ struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion *sysmem,
                     s->drq[OMAP24XX_DMA_UART1_TX],
                     s->drq[OMAP24XX_DMA_UART1_RX],
                     "uart1",
-                    serial_hds[0]);
+                    serial_hd(0));
     s->uart[1] = omap2_uart_init(sysmem, omap_l4ta(s->l4, 20),
                                  qdev_get_gpio_in(s->ih[0],
                                                   OMAP_INT_24XX_UART2_IRQ),
@@ -2358,7 +2358,7 @@ struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion *sysmem,
                     s->drq[OMAP24XX_DMA_UART2_TX],
                     s->drq[OMAP24XX_DMA_UART2_RX],
                     "uart2",
-                    serial_hds[0] ? serial_hds[1] : NULL);
+                    serial_hd(0) ? serial_hd(1) : NULL);
     s->uart[2] = omap2_uart_init(sysmem, omap_l4ta(s->l4, 21),
                                  qdev_get_gpio_in(s->ih[0],
                                                   OMAP_INT_24XX_UART3_IRQ),
@@ -2367,7 +2367,7 @@ struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion *sysmem,
                     s->drq[OMAP24XX_DMA_UART3_TX],
                     s->drq[OMAP24XX_DMA_UART3_RX],
                     "uart3",
-                    serial_hds[0] && serial_hds[1] ? serial_hds[2] : NULL);
+                    serial_hd(0) && serial_hd(1) ? serial_hd(2) : NULL);
 
     s->gptimer[0] = omap_gp_timer_init(omap_l4ta(s->l4, 7),
                     qdev_get_gpio_in(s->ih[0], OMAP_INT_24XX_GPTIMER1),
@@ -2519,8 +2519,8 @@ struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion *sysmem,
     omap_sti_init(omap_l4ta(s->l4, 18), sysmem, 0x54000000,
                   qdev_get_gpio_in(s->ih[0], OMAP_INT_24XX_STI),
                   omap_findclk(s, "emul_ck"),
-                    serial_hds[0] && serial_hds[1] && serial_hds[2] ?
-                    serial_hds[3] : NULL);
+                    serial_hd(0) && serial_hd(1) && serial_hd(2) ?
+                    serial_hd(3) : NULL);
 
     s->eac = omap_eac_init(omap_l4ta(s->l4, 32),
                            qdev_get_gpio_in(s->ih[0], OMAP_INT_24XX_EAC_IRQ),
hw/arm/pxa2xx.c +8 -8
index 5805a2c858..928a0431d6 100644
@@ -2106,21 +2106,21 @@ PXA2xxState *pxa270_init(MemoryRegion *address_space,
                     qdev_get_gpio_in(s->dma, PXA2XX_TX_RQ_MMCI));
 
     for (i = 0; pxa270_serial[i].io_base; i++) {
-        if (serial_hds[i]) {
+        if (serial_hd(i)) {
             serial_mm_init(address_space, pxa270_serial[i].io_base, 2,
                            qdev_get_gpio_in(s->pic, pxa270_serial[i].irqn),
-                           14857000 / 16, serial_hds[i],
+                           14857000 / 16, serial_hd(i),
                            DEVICE_NATIVE_ENDIAN);
         } else {
             break;
         }
     }
-    if (serial_hds[i])
+    if (serial_hd(i))
         s->fir = pxa2xx_fir_init(address_space, 0x40800000,
                         qdev_get_gpio_in(s->pic, PXA2XX_PIC_ICP),
                         qdev_get_gpio_in(s->dma, PXA2XX_RX_RQ_ICP),
                         qdev_get_gpio_in(s->dma, PXA2XX_TX_RQ_ICP),
-                        serial_hds[i]);
+                        serial_hd(i));
 
     s->lcd = pxa2xx_lcdc_init(address_space, 0x44000000,
                     qdev_get_gpio_in(s->pic, PXA2XX_PIC_LCD));
@@ -2231,21 +2231,21 @@ PXA2xxState *pxa255_init(MemoryRegion *address_space, unsigned int sdram_size)
                     qdev_get_gpio_in(s->dma, PXA2XX_TX_RQ_MMCI));
 
     for (i = 0; pxa255_serial[i].io_base; i++) {
-        if (serial_hds[i]) {
+        if (serial_hd(i)) {
             serial_mm_init(address_space, pxa255_serial[i].io_base, 2,
                            qdev_get_gpio_in(s->pic, pxa255_serial[i].irqn),
-                           14745600 / 16, serial_hds[i],
+                           14745600 / 16, serial_hd(i),
                            DEVICE_NATIVE_ENDIAN);
         } else {
             break;
         }
     }
-    if (serial_hds[i])
+    if (serial_hd(i))
         s->fir = pxa2xx_fir_init(address_space, 0x40800000,
                         qdev_get_gpio_in(s->pic, PXA2XX_PIC_ICP),
                         qdev_get_gpio_in(s->dma, PXA2XX_RX_RQ_ICP),
                         qdev_get_gpio_in(s->dma, PXA2XX_TX_RQ_ICP),
-                        serial_hds[i]);
+                        serial_hd(i));
 
     s->lcd = pxa2xx_lcdc_init(address_space, 0x44000000,
                     qdev_get_gpio_in(s->pic, PXA2XX_PIC_LCD));
hw/arm/realview.c +4 -4
index 2139a62e25..cd585d9469 100644
@@ -195,10 +195,10 @@ static void realview_init(MachineState *machine,
     sysbus_create_simple("pl050_keyboard", 0x10006000, pic[20]);
     sysbus_create_simple("pl050_mouse", 0x10007000, pic[21]);
 
-    pl011_create(0x10009000, pic[12], serial_hds[0]);
-    pl011_create(0x1000a000, pic[13], serial_hds[1]);
-    pl011_create(0x1000b000, pic[14], serial_hds[2]);
-    pl011_create(0x1000c000, pic[15], serial_hds[3]);
+    pl011_create(0x10009000, pic[12], serial_hd(0));
+    pl011_create(0x1000a000, pic[13], serial_hd(1));
+    pl011_create(0x1000b000, pic[14], serial_hd(2));
+    pl011_create(0x1000c000, pic[15], serial_hd(3));
 
     /* DMA controller is optional, apparently.  */
     sysbus_create_simple("pl081", 0x10030000, pic[24]);
hw/arm/stellaris.c +1 -1
index de7c0fc4a6..e886f54976 100644
@@ -1353,7 +1353,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
         if (board->dc2 & (1 << i)) {
             pl011_luminary_create(0x4000c000 + i * 0x1000,
                                   qdev_get_gpio_in(nvic, uart_irq[i]),
-                                  serial_hds[i]);
+                                  serial_hd(i));
         }
     }
     if (board->dc2 & (1 << 4)) {
hw/arm/stm32f205_soc.c +1 -1
index 1cd6374e07..f59418e7d0 100644
@@ -136,7 +136,7 @@ static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp)
     for (i = 0; i < STM_NUM_USARTS; i++) {
         dev = DEVICE(&(s->usart[i]));
         qdev_prop_set_chr(dev, "chardev",
-                          i < MAX_SERIAL_PORTS ? serial_hds[i] : NULL);
+                          i < MAX_SERIAL_PORTS ? serial_hd(i) : NULL);
         object_property_set_bool(OBJECT(&s->usart[i]), true, "realized", &err);
         if (err != NULL) {
             error_propagate(errp, err);
hw/arm/strongarm.c +1 -1
index 4cdb3a670b..ec2627374d 100644
@@ -1622,7 +1622,7 @@ StrongARMState *sa1110_init(MemoryRegion *sysmem,
 
     for (i = 0; sa_serial[i].io_base; i++) {
         DeviceState *dev = qdev_create(NULL, TYPE_STRONGARM_UART);
-        qdev_prop_set_chr(dev, "chardev", serial_hds[i]);
+        qdev_prop_set_chr(dev, "chardev", serial_hd(i));
         qdev_init_nofail(dev);
         sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0,
                 sa_serial[i].io_base);
hw/arm/versatilepb.c +4 -4
index 418792cd02..e01e3192ff 100644
@@ -283,10 +283,10 @@ static void versatile_init(MachineState *machine, int board_id)
         n--;
     }
 
-    pl011_create(0x101f1000, pic[12], serial_hds[0]);
-    pl011_create(0x101f2000, pic[13], serial_hds[1]);
-    pl011_create(0x101f3000, pic[14], serial_hds[2]);
-    pl011_create(0x10009000, sic[6], serial_hds[3]);
+    pl011_create(0x101f1000, pic[12], serial_hd(0));
+    pl011_create(0x101f2000, pic[13], serial_hd(1));
+    pl011_create(0x101f3000, pic[14], serial_hd(2));
+    pl011_create(0x10009000, sic[6], serial_hd(3));
 
     sysbus_create_simple("pl080", 0x10130000, pic[17]);
     sysbus_create_simple("sp804", 0x101e2000, pic[4]);
hw/arm/vexpress.c +4 -4
index 9fad79177a..f1e33c8a36 100644
@@ -622,10 +622,10 @@ static void vexpress_common_init(MachineState *machine)
     sysbus_create_simple("pl050_keyboard", map[VE_KMI0], pic[12]);
     sysbus_create_simple("pl050_mouse", map[VE_KMI1], pic[13]);
 
-    pl011_create(map[VE_UART0], pic[5], serial_hds[0]);
-    pl011_create(map[VE_UART1], pic[6], serial_hds[1]);
-    pl011_create(map[VE_UART2], pic[7], serial_hds[2]);
-    pl011_create(map[VE_UART3], pic[8], serial_hds[3]);
+    pl011_create(map[VE_UART0], pic[5], serial_hd(0));
+    pl011_create(map[VE_UART1], pic[6], serial_hd(1));
+    pl011_create(map[VE_UART2], pic[7], serial_hd(2));
+    pl011_create(map[VE_UART3], pic[8], serial_hd(3));
 
     sysbus_create_simple("sp804", map[VE_TIMER01], pic[2]);
     sysbus_create_simple("sp804", map[VE_TIMER23], pic[3]);
hw/arm/virt.c +2 -2
index 94dcb125d3..a18291c5d5 100644
@@ -1371,11 +1371,11 @@ static void machvirt_init(MachineState *machine)
 
     fdt_add_pmu_nodes(vms);
 
-    create_uart(vms, pic, VIRT_UART, sysmem, serial_hds[0]);
+    create_uart(vms, pic, VIRT_UART, sysmem, serial_hd(0));
 
     if (vms->secure) {
         create_secure_ram(vms, secure_sysmem);
-        create_uart(vms, pic, VIRT_SECURE_UART, secure_sysmem, serial_hds[1]);
+        create_uart(vms, pic, VIRT_SECURE_UART, secure_sysmem, serial_hd(1));
     }
 
     create_rtc(vms, pic);
hw/arm/xilinx_zynq.c +2 -2
index 0f76333770..899a26326f 100644
@@ -236,8 +236,8 @@ static void zynq_init(MachineState *machine)
     sysbus_create_simple("xlnx,ps7-usb", 0xE0002000, pic[53-IRQ_OFFSET]);
     sysbus_create_simple("xlnx,ps7-usb", 0xE0003000, pic[76-IRQ_OFFSET]);
 
-    cadence_uart_create(0xE0000000, pic[59 - IRQ_OFFSET], serial_hds[0]);
-    cadence_uart_create(0xE0001000, pic[82 - IRQ_OFFSET], serial_hds[1]);
+    cadence_uart_create(0xE0000000, pic[59 - IRQ_OFFSET], serial_hd(0));
+    cadence_uart_create(0xE0001000, pic[82 - IRQ_OFFSET], serial_hd(1));
 
     sysbus_create_varargs("cadence_ttc", 0xF8001000,
             pic[42-IRQ_OFFSET], pic[43-IRQ_OFFSET], pic[44-IRQ_OFFSET], NULL);
hw/arm/xlnx-zynqmp.c +1 -1
index 465796e97c..505253e0d2 100644
@@ -374,7 +374,7 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
     }
 
     for (i = 0; i < XLNX_ZYNQMP_NUM_UARTS; i++) {
-        qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hds[i]);
+        qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);
         if (err) {
             error_propagate(errp, err);
hw/char/exynos4210_uart.c +1 -1
index 3957e78abf..c2bba03362 100644
@@ -600,7 +600,7 @@ DeviceState *exynos4210_uart_create(hwaddr addr,
                          MAX_SERIAL_PORTS);
             exit(1);
         }
-        chr = serial_hds[channel];
+        chr = serial_hd(channel);
         if (!chr) {
             snprintf(label, ARRAY_SIZE(label), "%s%d", chr_name, channel);
             chr = qemu_chr_new(label, "null");
hw/char/serial-isa.c +2 -2
index d7c5cc11fe..eb5996159d 100644
@@ -141,8 +141,8 @@ void serial_hds_isa_init(ISABus *bus, int from, int to)
     assert(to <= MAX_SERIAL_PORTS);
 
     for (i = from; i < to; ++i) {
-        if (serial_hds[i]) {
-            serial_isa_init(bus, i, serial_hds[i]);
+        if (serial_hd(i)) {
+            serial_isa_init(bus, i, serial_hd(i));
         }
     }
 }
hw/char/xen_console.c +1 -1
index 5e68326c19..bdfaa40ed3 100644
@@ -201,7 +201,7 @@ static int con_init(struct XenDevice *xendev)
     /* no Xen override, use qemu output device */
     if (output == NULL) {
         if (con->xendev.dev) {
-            qemu_chr_fe_init(&con->chr, serial_hds[con->xendev.dev],
+            qemu_chr_fe_init(&con->chr, serial_hd(con->xendev.dev),
                              &error_abort);
         }
     } else {
hw/cris/axis_dev88.c +1 -1
index 9ccc4350a5..409f3d581a 100644
@@ -337,7 +337,7 @@ void axisdev88_init(MachineState *machine)
     sysbus_create_varargs("etraxfs,timer", 0x3005e000, irq[0x1b], nmi[1], NULL);
 
     for (i = 0; i < 4; i++) {
-        etraxfs_ser_create(0x30026000 + i * 0x2000, irq[0x14 + i], serial_hds[i]);
+        etraxfs_ser_create(0x30026000 + i * 0x2000, irq[0x14 + i], serial_hd(i));
     }
 
     if (kernel_filename) {
hw/hppa/machine.c +2 -2
index 19033e268d..a1d6b0ebfb 100644
@@ -108,10 +108,10 @@ static void machine_hppa_init(MachineState *machine)
     mc146818_rtc_init(isa_bus, 2000, rtc_irq);
 
     /* Serial code setup.  */
-    if (serial_hds[0]) {
+    if (serial_hd(0)) {
         uint32_t addr = DINO_UART_HPA + 0x800;
         serial_mm_init(addr_space, addr, 0, serial_irq,
-                       115200, serial_hds[0], DEVICE_BIG_ENDIAN);
+                       115200, serial_hd(0), DEVICE_BIG_ENDIAN);
     }
 
     /* SCSI disk setup. */
hw/isa/isa-superio.c +2 -2
index b95608a003..76286c81a1 100644
@@ -81,8 +81,8 @@ static void isa_superio_realize(DeviceState *dev, Error **errp)
             break;
         }
         if (!k->serial.is_enabled || k->serial.is_enabled(sio, i)) {
-            /* FIXME use a qdev chardev prop instead of serial_hds[] */
-            chr = serial_hds[i];
+            /* FIXME use a qdev chardev prop instead of serial_hd() */
+            chr = serial_hd(i);
             if (chr == NULL || chr->be) {
                 name = g_strdup_printf("discarding-serial%d", i);
                 chr = qemu_chr_new(name, "null");
hw/lm32/lm32_boards.c +4 -4
index 527bcc229c..907e875d02 100644
@@ -125,12 +125,12 @@ static void lm32_evr_init(MachineState *machine)
         irq[i] = qdev_get_gpio_in(env->pic_state, i);
     }
 
-    lm32_uart_create(uart0_base, irq[uart0_irq], serial_hds[0]);
+    lm32_uart_create(uart0_base, irq[uart0_irq], serial_hd(0));
     sysbus_create_simple("lm32-timer", timer0_base, irq[timer0_irq]);
     sysbus_create_simple("lm32-timer", timer1_base, irq[timer1_irq]);
 
     /* make sure juart isn't the first chardev */
-    env->juart_state = lm32_juart_init(serial_hds[1]);
+    env->juart_state = lm32_juart_init(serial_hd(1));
 
     reset_info->bootstrap_pc = flash_base;
 
@@ -217,13 +217,13 @@ static void lm32_uclinux_init(MachineState *machine)
         irq[i] = qdev_get_gpio_in(env->pic_state, i);
     }
 
-    lm32_uart_create(uart0_base, irq[uart0_irq], serial_hds[0]);
+    lm32_uart_create(uart0_base, irq[uart0_irq], serial_hd(0));
     sysbus_create_simple("lm32-timer", timer0_base, irq[timer0_irq]);
     sysbus_create_simple("lm32-timer", timer1_base, irq[timer1_irq]);
     sysbus_create_simple("lm32-timer", timer2_base, irq[timer2_irq]);
 
     /* make sure juart isn't the first chardev */
-    env->juart_state = lm32_juart_init(serial_hds[1]);
+    env->juart_state = lm32_juart_init(serial_hd(1));
 
     reset_info->bootstrap_pc = flash_base;
 
hw/lm32/milkymist.c +2 -2
index 85d64fe58d..f9688e059e 100644
@@ -151,7 +151,7 @@ milkymist_init(MachineState *machine)
     }
     g_free(bios_filename);
 
-    milkymist_uart_create(0x60000000, irq[0], serial_hds[0]);
+    milkymist_uart_create(0x60000000, irq[0], serial_hd(0));
     milkymist_sysctl_create(0x60001000, irq[1], irq[2], irq[3],
             80000000, 0x10014d31, 0x0000041f, 0x00000001);
     milkymist_hpdmc_create(0x60002000);
@@ -167,7 +167,7 @@ milkymist_init(MachineState *machine)
             0x20000000, 0x1000, 0x20020000, 0x2000);
 
     /* make sure juart isn't the first chardev */
-    env->juart_state = lm32_juart_init(serial_hds[1]);
+    env->juart_state = lm32_juart_init(serial_hd(1));
 
     if (kernel_filename) {
         uint64_t entry;
hw/m68k/mcf5206.c +2 -2
index bd8e993c58..6ad1e4bd2d 100644
@@ -543,8 +543,8 @@ qemu_irq *mcf5206_init(MemoryRegion *sysmem, uint32_t base, M68kCPU *cpu)
     pic = qemu_allocate_irqs(m5206_mbar_set_irq, s, 14);
     s->timer[0] = m5206_timer_init(pic[9]);
     s->timer[1] = m5206_timer_init(pic[10]);
-    s->uart[0] = mcf_uart_init(pic[12], serial_hds[0]);
-    s->uart[1] = mcf_uart_init(pic[13], serial_hds[1]);
+    s->uart[0] = mcf_uart_init(pic[12], serial_hd(0));
+    s->uart[1] = mcf_uart_init(pic[13], serial_hd(1));
     s->cpu = cpu;
 
     m5206_mbar_reset(s);
hw/m68k/mcf5208.c +3 -3
index fac0d09cbc..7aca58542e 100644
@@ -247,9 +247,9 @@ static void mcf5208evb_init(MachineState *machine)
     /* Internal peripherals.  */
     pic = mcf_intc_init(address_space_mem, 0xfc048000, cpu);
 
-    mcf_uart_mm_init(0xfc060000, pic[26], serial_hds[0]);
-    mcf_uart_mm_init(0xfc064000, pic[27], serial_hds[1]);
-    mcf_uart_mm_init(0xfc068000, pic[28], serial_hds[2]);
+    mcf_uart_mm_init(0xfc060000, pic[26], serial_hd(0));
+    mcf_uart_mm_init(0xfc064000, pic[27], serial_hd(1));
+    mcf_uart_mm_init(0xfc068000, pic[28], serial_hd(2));
 
     mcf5208_sys_init(address_space_mem, pic);
 
hw/microblaze/petalogix_ml605_mmu.c +1 -1
index b664dc0f9c..cf6bf3f32a 100644
@@ -125,7 +125,7 @@ petalogix_ml605_init(MachineState *machine)
     }
 
     serial_mm_init(address_space_mem, UART16550_BASEADDR + 0x1000, 2,
-                   irq[UART16550_IRQ], 115200, serial_hds[0],
+                   irq[UART16550_IRQ], 115200, serial_hd(0),
                    DEVICE_LITTLE_ENDIAN);
 
     /* 2 timers at irq 2 @ 100 Mhz.  */
hw/microblaze/petalogix_s3adsp1800_mmu.c +1 -1
index 5cb4deb69e..1186002a76 100644
@@ -103,7 +103,7 @@ petalogix_s3adsp1800_init(MachineState *machine)
     }
 
     xilinx_uartlite_create(UARTLITE_BASEADDR, irq[UARTLITE_IRQ],
-                           serial_hds[0]);
+                           serial_hd(0));
 
     /* 2 timers at irq 2 @ 62 Mhz.  */
     dev = qdev_create(NULL, "xlnx.xps-timer");
hw/mips/boston.c +1 -1
index 14f0f6673b..5302e5c885 100644
@@ -507,7 +507,7 @@ static void boston_mach_init(MachineState *machine)
 
     s->uart = serial_mm_init(sys_mem, 0x17ffe000, 2,
                              get_cps_irq(s->cps, 3), 10000000,
-                             serial_hds[0], DEVICE_NATIVE_ENDIAN);
+                             serial_hd(0), DEVICE_NATIVE_ENDIAN);
 
     lcd = g_new(MemoryRegion, 1);
     memory_region_init_io(lcd, NULL, &boston_lcd_ops, s, "boston-lcd", 0x8);
hw/mips/mips_jazz.c +4 -4
index 7223085547..90cb306f53 100644
@@ -303,15 +303,15 @@ static void mips_jazz_init(MachineState *machine,
     memory_region_add_subregion(address_space, 0x80005000, i8042);
 
     /* Serial ports */
-    if (serial_hds[0]) {
+    if (serial_hd(0)) {
         serial_mm_init(address_space, 0x80006000, 0,
                        qdev_get_gpio_in(rc4030, 8), 8000000/16,
-                       serial_hds[0], DEVICE_NATIVE_ENDIAN);
+                       serial_hd(0), DEVICE_NATIVE_ENDIAN);
     }
-    if (serial_hds[1]) {
+    if (serial_hd(1)) {
         serial_mm_init(address_space, 0x80007000, 0,
                        qdev_get_gpio_in(rc4030, 9), 8000000/16,
-                       serial_hds[1], DEVICE_NATIVE_ENDIAN);
+                       serial_hd(1), DEVICE_NATIVE_ENDIAN);
     }
 
     /* Parallel port */
hw/mips/mips_malta.c +1 -1
index 49fe7a0a72..af70ecffc0 100644
@@ -1057,7 +1057,7 @@ void mips_malta_init(MachineState *machine)
     /* FPGA */
 
     /* The CBUS UART is attached to the MIPS CPU INT2 pin, ie interrupt 4 */
-    malta_fpga_init(system_memory, FPGA_ADDRESS, cbus_irq, serial_hds[2]);
+    malta_fpga_init(system_memory, FPGA_ADDRESS, cbus_irq, serial_hd(2));
 
     /* Load firmware in flash / BIOS. */
     dinfo = drive_get(IF_PFLASH, 0, fl_idx);
hw/mips/mips_mipssim.c +2 -2
index e0ba5efc84..241faa1d0f 100644
@@ -213,8 +213,8 @@ mips_mipssim_init(MachineState *machine)
 
     /* A single 16450 sits at offset 0x3f8. It is attached to
        MIPS CPU INT2, which is interrupt 4. */
-    if (serial_hds[0])
-        serial_init(0x3f8, env->irq[4], 115200, serial_hds[0],
+    if (serial_hd(0))
+        serial_init(0x3f8, env->irq[4], 115200, serial_hd(0),
                     get_system_io());
 
     if (nd_table[0].used)
hw/misc/macio/macio.c +2 -2
index b74a6572b0..a0cefe5719 100644
@@ -118,8 +118,8 @@ static void macio_common_realize(PCIDevice *d, Error **errp)
     qdev_prop_set_uint32(DEVICE(&s->escc), "disabled", 0);
     qdev_prop_set_uint32(DEVICE(&s->escc), "frequency", ESCC_CLOCK);
     qdev_prop_set_uint32(DEVICE(&s->escc), "it_shift", 4);
-    qdev_prop_set_chr(DEVICE(&s->escc), "chrA", serial_hds[0]);
-    qdev_prop_set_chr(DEVICE(&s->escc), "chrB", serial_hds[1]);
+    qdev_prop_set_chr(DEVICE(&s->escc), "chrA", serial_hd(0));
+    qdev_prop_set_chr(DEVICE(&s->escc), "chrB", serial_hd(1));
     qdev_prop_set_uint32(DEVICE(&s->escc), "chnBtype", escc_serial);
     qdev_prop_set_uint32(DEVICE(&s->escc), "chnAtype", escc_serial);
     object_property_set_bool(OBJECT(&s->escc), true, "realized", &err);
hw/moxie/moxiesim.c +2 -2
index 0bbf770795..d41247dbdc 100644
@@ -141,9 +141,9 @@ static void moxiesim_init(MachineState *machine)
     }
 
     /* A single 16450 sits at offset 0x3f8.  */
-    if (serial_hds[0]) {
+    if (serial_hd(0)) {
         serial_mm_init(address_space_mem, 0x3f8, 0, env->irq[4],
-                       8000000/16, serial_hds[0], DEVICE_LITTLE_ENDIAN);
+                       8000000/16, serial_hd(0), DEVICE_LITTLE_ENDIAN);
     }
 }
 
hw/nios2/10m50_devboard.c +1 -1
index 42053b2ca9..36b49a420c 100644
@@ -92,7 +92,7 @@ static void nios2_10m50_ghrd_init(MachineState *machine)
 
     /* Register: Altera 16550 UART */
     serial_mm_init(address_space_mem, 0xf8001600, 2, irq[1], 115200,
-                   serial_hds[0], DEVICE_NATIVE_ENDIAN);
+                   serial_hd(0), DEVICE_NATIVE_ENDIAN);
 
     /* Register: Timer sys_clk_timer  */
     dev = qdev_create(NULL, "ALTR.timer");
hw/openrisc/openrisc_sim.c +1 -1
index c755f11efd..a495a84a41 100644
@@ -164,7 +164,7 @@ static void openrisc_sim_init(MachineState *machine)
     }
 
     serial_mm_init(get_system_memory(), 0x90000000, 0, serial_irq,
-                   115200, serial_hds[0], DEVICE_NATIVE_ENDIAN);
+                   115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);
 
     openrisc_load_kernel(ram_size, kernel_filename);
 }
hw/ppc/e500.c +6 -6
index 9a85a41362..2ddab7ed24 100644
@@ -456,12 +456,12 @@ static int ppce500_load_device_tree(MachineState *machine,
      * device it finds in the dt as serial output device. And we generate
      * devices in reverse order to the dt.
      */
-    if (serial_hds[1]) {
+    if (serial_hd(1)) {
         dt_serial_create(fdt, MPC8544_SERIAL1_REGS_OFFSET,
                          soc, mpic, "serial1", 1, false);
     }
 
-    if (serial_hds[0]) {
+    if (serial_hd(0)) {
         dt_serial_create(fdt, MPC8544_SERIAL0_REGS_OFFSET,
                          soc, mpic, "serial0", 0, true);
     }
@@ -875,16 +875,16 @@ void ppce500_init(MachineState *machine, PPCE500Params *params)
     mpicdev = ppce500_init_mpic(machine, params, ccsr_addr_space, irqs);
 
     /* Serial */
-    if (serial_hds[0]) {
+    if (serial_hd(0)) {
         serial_mm_init(ccsr_addr_space, MPC8544_SERIAL0_REGS_OFFSET,
                        0, qdev_get_gpio_in(mpicdev, 42), 399193,
-                       serial_hds[0], DEVICE_BIG_ENDIAN);
+                       serial_hd(0), DEVICE_BIG_ENDIAN);
     }
 
-    if (serial_hds[1]) {
+    if (serial_hd(1)) {
         serial_mm_init(ccsr_addr_space, MPC8544_SERIAL1_REGS_OFFSET,
                        0, qdev_get_gpio_in(mpicdev, 42), 399193,
-                       serial_hds[1], DEVICE_BIG_ENDIAN);
+                       serial_hd(1), DEVICE_BIG_ENDIAN);
     }
 
     /* General Utility device */
hw/ppc/ppc405_uc.c +8 -8
index 205ebcea93..34f8d57b07 100644
@@ -1660,14 +1660,14 @@ CPUPPCState *ppc405cr_init(MemoryRegion *address_space_mem,
     dma_irqs[3] = pic[23];
     ppc405_dma_init(env, dma_irqs);
     /* Serial ports */
-    if (serial_hds[0] != NULL) {
+    if (serial_hd(0) != NULL) {
         serial_mm_init(address_space_mem, 0xef600300, 0, pic[0],
-                       PPC_SERIAL_MM_BAUDBASE, serial_hds[0],
+                       PPC_SERIAL_MM_BAUDBASE, serial_hd(0),
                        DEVICE_BIG_ENDIAN);
     }
-    if (serial_hds[1] != NULL) {
+    if (serial_hd(1) != NULL) {
         serial_mm_init(address_space_mem, 0xef600400, 0, pic[1],
-                       PPC_SERIAL_MM_BAUDBASE, serial_hds[1],
+                       PPC_SERIAL_MM_BAUDBASE, serial_hd(1),
                        DEVICE_BIG_ENDIAN);
     }
     /* IIC controller */
@@ -2023,14 +2023,14 @@ CPUPPCState *ppc405ep_init(MemoryRegion *address_space_mem,
     /* GPIO */
     ppc405_gpio_init(0xef600700);
     /* Serial ports */
-    if (serial_hds[0] != NULL) {
+    if (serial_hd(0) != NULL) {
         serial_mm_init(address_space_mem, 0xef600300, 0, pic[0],
-                       PPC_SERIAL_MM_BAUDBASE, serial_hds[0],
+                       PPC_SERIAL_MM_BAUDBASE, serial_hd(0),
                        DEVICE_BIG_ENDIAN);
     }
-    if (serial_hds[1] != NULL) {
+    if (serial_hd(1) != NULL) {
         serial_mm_init(address_space_mem, 0xef600400, 0, pic[1],
-                       PPC_SERIAL_MM_BAUDBASE, serial_hds[1],
+                       PPC_SERIAL_MM_BAUDBASE, serial_hd(1),
                        DEVICE_BIG_ENDIAN);
     }
     /* OCM */
hw/ppc/ppc440_bamboo.c +4 -4
index 8641986a71..44e6a0c21b 100644
@@ -238,14 +238,14 @@ static void bamboo_init(MachineState *machine)
                              get_system_io(), 0, PPC440EP_PCI_IOLEN);
     memory_region_add_subregion(get_system_memory(), PPC440EP_PCI_IO, isa);
 
-    if (serial_hds[0] != NULL) {
+    if (serial_hd(0) != NULL) {
         serial_mm_init(address_space_mem, 0xef600300, 0, pic[0],
-                       PPC_SERIAL_MM_BAUDBASE, serial_hds[0],
+                       PPC_SERIAL_MM_BAUDBASE, serial_hd(0),
                        DEVICE_BIG_ENDIAN);
     }
-    if (serial_hds[1] != NULL) {
+    if (serial_hd(1) != NULL) {
         serial_mm_init(address_space_mem, 0xef600400, 0, pic[1],
-                       PPC_SERIAL_MM_BAUDBASE, serial_hds[1],
+                       PPC_SERIAL_MM_BAUDBASE, serial_hd(1),
                        DEVICE_BIG_ENDIAN);
     }
 
hw/ppc/sam460ex.c +4 -4
index dfff262f96..a48e6e6fce 100644
@@ -522,14 +522,14 @@ static void sam460ex_init(MachineState *machine)
 
     /* SoC has 4 UARTs
      * but board has only one wired and two are present in fdt */
-    if (serial_hds[0] != NULL) {
+    if (serial_hd(0) != NULL) {
         serial_mm_init(address_space_mem, 0x4ef600300, 0, uic[1][1],
-                       PPC_SERIAL_MM_BAUDBASE, serial_hds[0],
+                       PPC_SERIAL_MM_BAUDBASE, serial_hd(0),
                        DEVICE_BIG_ENDIAN);
     }
-    if (serial_hds[1] != NULL) {
+    if (serial_hd(1) != NULL) {
         serial_mm_init(address_space_mem, 0x4ef600400, 0, uic[0][1],
-                       PPC_SERIAL_MM_BAUDBASE, serial_hds[1],
+                       PPC_SERIAL_MM_BAUDBASE, serial_hd(1),
                        DEVICE_BIG_ENDIAN);
     }
 
hw/ppc/spapr.c +2 -2
index a81570e7c8..b0ecfaca9e 100644
@@ -2590,8 +2590,8 @@ static void spapr_machine_init(MachineState *machine)
     spapr->vio_bus = spapr_vio_bus_init();
 
     for (i = 0; i < MAX_SERIAL_PORTS; i++) {
-        if (serial_hds[i]) {
-            spapr_vty_create(spapr->vio_bus, serial_hds[i]);
+        if (serial_hd(i)) {
+            spapr_vty_create(spapr->vio_bus, serial_hd(i));
         }
     }
 
hw/ppc/virtex_ml507.c +1 -1
index 77a1778e07..a80cbdd7ee 100644
@@ -251,7 +251,7 @@ static void virtex_init(MachineState *machine)
     }
 
     serial_mm_init(address_space_mem, UART16550_BASEADDR, 2, irq[UART16550_IRQ],
-                   115200, serial_hds[0], DEVICE_LITTLE_ENDIAN);
+                   115200, serial_hd(0), DEVICE_LITTLE_ENDIAN);
 
     /* 2 timers at irq 2 @ 62 Mhz.  */
     dev = qdev_create(NULL, "xlnx.xps-timer");
hw/riscv/sifive_e.c +2 -2
index 19eca36ff4..487244890e 100644
@@ -162,13 +162,13 @@ static void riscv_sifive_e_init(MachineState *machine)
     sifive_mmio_emulate(sys_mem, "riscv.sifive.e.gpio0",
         memmap[SIFIVE_E_GPIO0].base, memmap[SIFIVE_E_GPIO0].size);
     sifive_uart_create(sys_mem, memmap[SIFIVE_E_UART0].base,
-        serial_hds[0], SIFIVE_PLIC(s->plic)->irqs[SIFIVE_E_UART0_IRQ]);
+        serial_hd(0), SIFIVE_PLIC(s->plic)->irqs[SIFIVE_E_UART0_IRQ]);
     sifive_mmio_emulate(sys_mem, "riscv.sifive.e.qspi0",
         memmap[SIFIVE_E_QSPI0].base, memmap[SIFIVE_E_QSPI0].size);
     sifive_mmio_emulate(sys_mem, "riscv.sifive.e.pwm0",
         memmap[SIFIVE_E_PWM0].base, memmap[SIFIVE_E_PWM0].size);
     /* sifive_uart_create(sys_mem, memmap[SIFIVE_E_UART1].base,
-        serial_hds[1], SIFIVE_PLIC(s->plic)->irqs[SIFIVE_E_UART1_IRQ]); */
+        serial_hd(1), SIFIVE_PLIC(s->plic)->irqs[SIFIVE_E_UART1_IRQ]); */
     sifive_mmio_emulate(sys_mem, "riscv.sifive.e.qspi1",
         memmap[SIFIVE_E_QSPI1].base, memmap[SIFIVE_E_QSPI1].size);
     sifive_mmio_emulate(sys_mem, "riscv.sifive.e.pwm1",
hw/riscv/sifive_u.c +2 -2
index 1c2deefa6c..66616bacd7 100644
@@ -296,9 +296,9 @@ static void riscv_sifive_u_init(MachineState *machine)
         SIFIVE_U_PLIC_CONTEXT_STRIDE,
         memmap[SIFIVE_U_PLIC].size);
     sifive_uart_create(sys_memory, memmap[SIFIVE_U_UART0].base,
-        serial_hds[0], SIFIVE_PLIC(s->plic)->irqs[SIFIVE_U_UART0_IRQ]);
+        serial_hd(0), SIFIVE_PLIC(s->plic)->irqs[SIFIVE_U_UART0_IRQ]);
     /* sifive_uart_create(sys_memory, memmap[SIFIVE_U_UART1].base,
-        serial_hds[1], SIFIVE_PLIC(s->plic)->irqs[SIFIVE_U_UART1_IRQ]); */
+        serial_hd(1), SIFIVE_PLIC(s->plic)->irqs[SIFIVE_U_UART1_IRQ]); */
     sifive_clint_create(memmap[SIFIVE_U_CLINT].base,
         memmap[SIFIVE_U_CLINT].size, smp_cpus,
         SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE);
hw/riscv/spike.c +2 -2
index 2d1f114d40..62857e4fa0 100644
@@ -233,7 +233,7 @@ static void spike_v1_10_0_board_init(MachineState *machine)
         s->fdt, s->fdt_size);
 
     /* initialize HTIF using symbols found in load_kernel */
-    htif_mm_init(system_memory, boot_rom, &s->soc.harts[0].env, serial_hds[0]);
+    htif_mm_init(system_memory, boot_rom, &s->soc.harts[0].env, serial_hd(0));
 
     /* Core Local Interruptor (timer and IPI) */
     sifive_clint_create(memmap[SPIKE_CLINT].base, memmap[SPIKE_CLINT].size,
@@ -330,7 +330,7 @@ static void spike_v1_09_1_board_init(MachineState *machine)
         config_string, config_string_len);
 
     /* initialize HTIF using symbols found in load_kernel */
-    htif_mm_init(system_memory, boot_rom, &s->soc.harts[0].env, serial_hds[0]);
+    htif_mm_init(system_memory, boot_rom, &s->soc.harts[0].env, serial_hd(0));
 
     /* Core Local Interruptor (timer and IPI) */
     sifive_clint_create(memmap[SPIKE_CLINT].base, memmap[SPIKE_CLINT].size,
hw/riscv/virt.c +1 -1
index e2c214e86a..4f69eb2cff 100644
@@ -382,7 +382,7 @@ static void riscv_virt_board_init(MachineState *machine)
 
     serial_mm_init(system_memory, memmap[VIRT_UART0].base,
         0, SIFIVE_PLIC(s->plic)->irqs[UART0_IRQ], 399193,
-        serial_hds[0], DEVICE_LITTLE_ENDIAN);
+        serial_hd(0), DEVICE_LITTLE_ENDIAN);
 }
 
 static int riscv_virt_board_sysbus_device_init(SysBusDevice *sysbusdev)
hw/sh4/r2d.c +1 -1
index 458ed83297..6b01d6eed8 100644
@@ -271,7 +271,7 @@ static void r2d_init(MachineState *machine)
     busdev = SYS_BUS_DEVICE(dev);
     qdev_prop_set_uint32(dev, "vram-size", SM501_VRAM_SIZE);
     qdev_prop_set_uint32(dev, "base", 0x10000000);
-    qdev_prop_set_ptr(dev, "chr-state", serial_hds[2]);
+    qdev_prop_set_ptr(dev, "chr-state", serial_hd(2));
     qdev_init_nofail(dev);
     sysbus_mmio_map(busdev, 0, 0x10000000);
     sysbus_mmio_map(busdev, 1, 0x13e00000);
hw/sh4/sh7750.c +2 -2
index 166e4bd947..5a7d47d31e 100644
@@ -773,7 +773,7 @@ SH7750State *sh7750_init(SuperHCPU *cpu, MemoryRegion *sysmem)
     cpu->env.intc_handle = &s->intc;
 
     sh_serial_init(sysmem, 0x1fe00000,
-                   0, s->periph_freq, serial_hds[0],
+                   0, s->periph_freq, serial_hd(0),
                    s->intc.irqs[SCI1_ERI],
                    s->intc.irqs[SCI1_RXI],
                    s->intc.irqs[SCI1_TXI],
@@ -781,7 +781,7 @@ SH7750State *sh7750_init(SuperHCPU *cpu, MemoryRegion *sysmem)
                    NULL);
     sh_serial_init(sysmem, 0x1fe80000,
                    SH_SERIAL_FEAT_SCIF,
-                   s->periph_freq, serial_hds[1],
+                   s->periph_freq, serial_hd(1),
                    s->intc.irqs[SCIF_ERI],
                    s->intc.irqs[SCIF_RXI],
                    s->intc.irqs[SCIF_TXI],
hw/sparc/leon3.c +2 -2
index bba3aa3dee..98fa6adae0 100644
@@ -206,8 +206,8 @@ static void leon3_generic_hw_init(MachineState *machine)
     grlib_gptimer_create(0x80000300, 2, CPU_CLK, cpu_irqs, 6);
 
     /* Allocate uart */
-    if (serial_hds[0]) {
-        grlib_apbuart_create(0x80000100, serial_hds[0], cpu_irqs[3]);
+    if (serial_hd(0)) {
+        grlib_apbuart_create(0x80000100, serial_hd(0), cpu_irqs[3]);
     }
 }
 
hw/sparc/sun4m.c +2 -2
index 6471aca25d..0ee779fafe 100644
@@ -943,8 +943,8 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
     qdev_prop_set_uint32(dev, "disabled", 0);
     qdev_prop_set_uint32(dev, "frequency", ESCC_CLOCK);
     qdev_prop_set_uint32(dev, "it_shift", 1);
-    qdev_prop_set_chr(dev, "chrB", serial_hds[1]);
-    qdev_prop_set_chr(dev, "chrA", serial_hds[0]);
+    qdev_prop_set_chr(dev, "chrB", serial_hd(1));
+    qdev_prop_set_chr(dev, "chrA", serial_hd(0));
     qdev_prop_set_uint32(dev, "chnBtype", escc_serial);
     qdev_prop_set_uint32(dev, "chnAtype", escc_serial);
     qdev_init_nofail(dev);
hw/sparc64/niagara.c +2 -2
index 1874477ef6..22c4655fde 100644
@@ -156,9 +156,9 @@ static void niagara_init(MachineState *machine)
             exit(1);
         }
     }
-    if (serial_hds[0]) {
+    if (serial_hd(0)) {
         serial_mm_init(sysmem, NIAGARA_UART_BASE, 0, NULL, 115200,
-                       serial_hds[0], DEVICE_BIG_ENDIAN);
+                       serial_hd(0), DEVICE_BIG_ENDIAN);
     }
     empty_slot_init(NIAGARA_IOBBASE, NIAGARA_IOBSIZE);
     sun4v_rtc_init(NIAGARA_RTC_BASE);
hw/sparc64/sun4u.c +1 -1
index 2044a52ded..9b441f704b 100644
@@ -295,7 +295,7 @@ static void ebus_realize(PCIDevice *pci_dev, Error **errp)
     i = 0;
     if (s->console_serial_base) {
         serial_mm_init(pci_address_space(pci_dev), s->console_serial_base,
-                       0, NULL, 115200, serial_hds[i], DEVICE_BIG_ENDIAN);
+                       0, NULL, 115200, serial_hd(i), DEVICE_BIG_ENDIAN);
         i++;
     }
     serial_hds_isa_init(s->isa_bus, i, MAX_SERIAL_PORTS);
hw/xtensa/sim.c +2 -2
index 5c0ba231d1..b6ccb3cd4a 100644
@@ -90,8 +90,8 @@ static void xtensa_sim_init(MachineState *machine)
                                      get_system_memory());
     }
 
-    if (serial_hds[0]) {
-        xtensa_sim_open_console(serial_hds[0]);
+    if (serial_hd(0)) {
+        xtensa_sim_open_console(serial_hd(0));
     }
     if (kernel_filename) {
         uint64_t elf_entry;
hw/xtensa/xtfpga.c +1 -1
index 9db99e1f7e..63734c70ec 100644
@@ -279,7 +279,7 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
     }
 
     serial_mm_init(system_io, 0x0d050020, 2, xtensa_get_extint(env, 0),
-            115200, serial_hds[0], DEVICE_NATIVE_ENDIAN);
+            115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);
 
     dinfo = drive_get(IF_PFLASH, 0, 0);
     if (dinfo) {
Signature · 1 line
2.17.0
Reviewed-by on v1 7/13
#22 lore raw

Re: [Qemu-devel] [PATCH 07/13] Change references to serial_hds[] to serial_hd()

Quoted 63 lines · Peter Maydell

Change all the uses of serial_hds[] to go via the new
serial_hd() function. Code change produced with:
find hw -name '*.[ch]' | xargs sed -i -e 's/serial_hds\[\([^]]*\)\]/serial_hd(\1)/g'

---
 hw/arm/allwinner-a10.c                   |  4 ++--
 hw/arm/aspeed_soc.c                      |  4 ++--
 hw/arm/bcm2835_peripherals.c             |  4 ++--
 hw/arm/digic.c                           |  2 +-
 hw/arm/fsl-imx25.c                       |  2 +-
 hw/arm/fsl-imx31.c                       |  2 +-
 hw/arm/fsl-imx6.c                        |  4 ++--
 hw/arm/fsl-imx7.c                        |  2 +-
 hw/arm/highbank.c                        |  2 +-
 hw/arm/integratorcp.c                    |  4 ++--
 hw/arm/kzm.c                             |  4 ++--
 hw/arm/mps2-tz.c                         |  2 +-
 hw/arm/mps2.c                            |  4 ++--
 hw/arm/msf2-soc.c                        |  4 ++--
 hw/arm/musicpal.c                        |  8 ++++----
 hw/arm/omap1.c                           |  6 +++---
 hw/arm/omap2.c                           | 10 +++++-----
 hw/arm/pxa2xx.c                          | 16 ++++++++--------
 hw/arm/realview.c                        |  8 ++++----
 hw/arm/stellaris.c                       |  2 +-
 hw/arm/stm32f205_soc.c                   |  2 +-
 hw/arm/strongarm.c                       |  2 +-
 hw/arm/versatilepb.c                     |  8 ++++----
 hw/arm/vexpress.c                        |  8 ++++----
 hw/arm/virt.c                            |  4 ++--
 hw/arm/xilinx_zynq.c                     |  4 ++--
 hw/arm/xlnx-zynqmp.c                     |  2 +-
 hw/char/exynos4210_uart.c                |  2 +-
 hw/char/serial-isa.c                     |  4 ++--
 hw/char/xen_console.c                    |  2 +-
 hw/cris/axis_dev88.c                     |  2 +-
 hw/hppa/machine.c                        |  4 ++--
 hw/isa/isa-superio.c                     |  4 ++--
 hw/lm32/lm32_boards.c                    |  8 ++++----
 hw/lm32/milkymist.c                      |  4 ++--
 hw/m68k/mcf5206.c                        |  4 ++--
 hw/m68k/mcf5208.c                        |  6 +++---
 hw/microblaze/petalogix_ml605_mmu.c      |  2 +-
 hw/microblaze/petalogix_s3adsp1800_mmu.c |  2 +-
 hw/mips/boston.c                         |  2 +-
 hw/mips/mips_jazz.c                      |  8 ++++----
 hw/mips/mips_malta.c                     |  2 +-
 hw/mips/mips_mipssim.c                   |  4 ++--
 hw/misc/macio/macio.c                    |  4 ++--
 hw/moxie/moxiesim.c                      |  4 ++--
 hw/nios2/10m50_devboard.c                |  2 +-
 hw/openrisc/openrisc_sim.c               |  2 +-
 hw/ppc/e500.c                            | 12 ++++++------
 hw/ppc/ppc405_uc.c                       | 16 ++++++++--------
 hw/ppc/ppc440_bamboo.c                   |  8 ++++----
 hw/ppc/sam460ex.c                        |  8 ++++----
 hw/ppc/spapr.c                           |  4 ++--
 hw/ppc/virtex_ml507.c                    |  2 +-
 hw/riscv/sifive_e.c                      |  4 ++--
 hw/riscv/sifive_u.c                      |  4 ++--
 hw/riscv/spike.c                         |  4 ++--
 hw/riscv/virt.c                          |  2 +-
Quoted 8 lines
 hw/sh4/r2d.c                             |  2 +-
 hw/sh4/sh7750.c                          |  4 ++--
 hw/sparc/leon3.c                         |  4 ++--
 hw/sparc/sun4m.c                         |  4 ++--
 hw/sparc64/niagara.c                     |  4 ++--
 hw/sparc64/sun4u.c                       |  2 +-
 hw/xtensa/sim.c                          |  4 ++--
 hw/xtensa/xtfpga.c                       |  2 +-

Phew, that was a big patch, but looks good as far as I can see:

#23 lore raw

Re: [Qemu-devel] [PATCH 07/13] Change references to serial_hds[] to serial_hd()

In reply to Peter Maydell

Hi Peter,

Quoted 253 lines · Peter Maydell

Change all the uses of serial_hds[] to go via the new
serial_hd() function. Code change produced with:
find hw -name '*.[ch]' | xargs sed -i -e 's/serial_hds\[\([^]]*\)\]/serial_hd(\1)/g'

---
 hw/arm/allwinner-a10.c                   |  4 ++--
 hw/arm/aspeed_soc.c                      |  4 ++--
 hw/arm/bcm2835_peripherals.c             |  4 ++--
 hw/arm/digic.c                           |  2 +-
 hw/arm/fsl-imx25.c                       |  2 +-
 hw/arm/fsl-imx31.c                       |  2 +-
 hw/arm/fsl-imx6.c                        |  4 ++--
 hw/arm/fsl-imx7.c                        |  2 +-
 hw/arm/highbank.c                        |  2 +-
 hw/arm/integratorcp.c                    |  4 ++--
 hw/arm/kzm.c                             |  4 ++--
 hw/arm/mps2-tz.c                         |  2 +-
 hw/arm/mps2.c                            |  4 ++--
 hw/arm/msf2-soc.c                        |  4 ++--
 hw/arm/musicpal.c                        |  8 ++++----
 hw/arm/omap1.c                           |  6 +++---
 hw/arm/omap2.c                           | 10 +++++-----
 hw/arm/pxa2xx.c                          | 16 ++++++++--------
 hw/arm/realview.c                        |  8 ++++----
 hw/arm/stellaris.c                       |  2 +-
 hw/arm/stm32f205_soc.c                   |  2 +-
 hw/arm/strongarm.c                       |  2 +-
 hw/arm/versatilepb.c                     |  8 ++++----
 hw/arm/vexpress.c                        |  8 ++++----
 hw/arm/virt.c                            |  4 ++--
 hw/arm/xilinx_zynq.c                     |  4 ++--
 hw/arm/xlnx-zynqmp.c                     |  2 +-
 hw/char/exynos4210_uart.c                |  2 +-
 hw/char/serial-isa.c                     |  4 ++--
 hw/char/xen_console.c                    |  2 +-
 hw/cris/axis_dev88.c                     |  2 +-
 hw/hppa/machine.c                        |  4 ++--
 hw/isa/isa-superio.c                     |  4 ++--
 hw/lm32/lm32_boards.c                    |  8 ++++----
 hw/lm32/milkymist.c                      |  4 ++--
 hw/m68k/mcf5206.c                        |  4 ++--
 hw/m68k/mcf5208.c                        |  6 +++---
 hw/microblaze/petalogix_ml605_mmu.c      |  2 +-
 hw/microblaze/petalogix_s3adsp1800_mmu.c |  2 +-
 hw/mips/boston.c                         |  2 +-
 hw/mips/mips_jazz.c                      |  8 ++++----
 hw/mips/mips_malta.c                     |  2 +-
 hw/mips/mips_mipssim.c                   |  4 ++--
 hw/misc/macio/macio.c                    |  4 ++--
 hw/moxie/moxiesim.c                      |  4 ++--
 hw/nios2/10m50_devboard.c                |  2 +-
 hw/openrisc/openrisc_sim.c               |  2 +-
 hw/ppc/e500.c                            | 12 ++++++------
 hw/ppc/ppc405_uc.c                       | 16 ++++++++--------
 hw/ppc/ppc440_bamboo.c                   |  8 ++++----
 hw/ppc/sam460ex.c                        |  8 ++++----
 hw/ppc/spapr.c                           |  4 ++--
 hw/ppc/virtex_ml507.c                    |  2 +-
 hw/riscv/sifive_e.c                      |  4 ++--
 hw/riscv/sifive_u.c                      |  4 ++--
 hw/riscv/spike.c                         |  4 ++--
 hw/riscv/virt.c                          |  2 +-
 hw/sh4/r2d.c                             |  2 +-
 hw/sh4/sh7750.c                          |  4 ++--
 hw/sparc/leon3.c                         |  4 ++--
 hw/sparc/sun4m.c                         |  4 ++--
 hw/sparc64/niagara.c                     |  4 ++--
 hw/sparc64/sun4u.c                       |  2 +-
 hw/xtensa/sim.c                          |  4 ++--
 hw/xtensa/xtfpga.c                       |  2 +-
 65 files changed, 143 insertions(+), 143 deletions(-)
hw/arm/allwinner-a10.c +2 -2
index 5dbbacb7e8..c5fbc654f2 100644
@@ -108,9 +108,9 @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->sata), 0, AW_A10_SATA_BASE);
     sysbus_connect_irq(SYS_BUS_DEVICE(&s->sata), 0, s->irq[56]);
 
-    /* FIXME use a qdev chardev prop instead of serial_hds[] */
+    /* FIXME use a qdev chardev prop instead of serial_hd() */
     serial_mm_init(get_system_memory(), AW_A10_UART0_REG_BASE, 2, s->irq[1],
-                   115200, serial_hds[0], DEVICE_NATIVE_ENDIAN);
+                   115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);
 }
 
 static void aw_a10_class_init(ObjectClass *oc, void *data)
hw/arm/aspeed_soc.c +2 -2
index 30d25f8b06..1219167a5e 100644
@@ -229,11 +229,11 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->scu), 0, ASPEED_SOC_SCU_BASE);
 
     /* UART - attach an 8250 to the IO space as our UART5 */
-    if (serial_hds[0]) {
+    if (serial_hd(0)) {
         qemu_irq uart5 = qdev_get_gpio_in(DEVICE(&s->vic), uart_irqs[4]);
         serial_mm_init(get_system_memory(),
                        ASPEED_SOC_IOMEM_BASE + ASPEED_SOC_UART_5_BASE, 2,
-                       uart5, 38400, serial_hds[0], DEVICE_LITTLE_ENDIAN);
+                       uart5, 38400, serial_hd(0), DEVICE_LITTLE_ENDIAN);
     }
 
     /* I2C */
hw/arm/bcm2835_peripherals.c +2 -2
index 13b63970d7..6be7660e8c 100644
@@ -166,7 +166,7 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
     sysbus_pass_irq(SYS_BUS_DEVICE(s), SYS_BUS_DEVICE(&s->ic));
 
     /* UART0 */
-    qdev_prop_set_chr(DEVICE(s->uart0), "chardev", serial_hds[0]);
+    qdev_prop_set_chr(DEVICE(s->uart0), "chardev", serial_hd(0));
     object_property_set_bool(OBJECT(s->uart0), true, "realized", &err);
     if (err) {
         error_propagate(errp, err);
@@ -179,7 +179,7 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
         qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ,
                                INTERRUPT_UART));
     /* AUX / UART1 */
-    qdev_prop_set_chr(DEVICE(&s->aux), "chardev", serial_hds[1]);
+    qdev_prop_set_chr(DEVICE(&s->aux), "chardev", serial_hd(1));
 
     object_property_set_bool(OBJECT(&s->aux), true, "realized", &err);
     if (err) {
hw/arm/digic.c +1 -1
index 6184020985..726abb9b48 100644
@@ -85,7 +85,7 @@ static void digic_realize(DeviceState *dev, Error **errp)
         sysbus_mmio_map(sbd, 0, DIGIC4_TIMER_BASE(i));
     }
 
-    qdev_prop_set_chr(DEVICE(&s->uart), "chardev", serial_hds[0]);
+    qdev_prop_set_chr(DEVICE(&s->uart), "chardev", serial_hd(0));
     object_property_set_bool(OBJECT(&s->uart), true, "realized", &err);
     if (err != NULL) {
         error_propagate(errp, err);
hw/arm/fsl-imx25.c +1 -1
index d7d064e5ce..9731833fa5 100644
@@ -118,7 +118,7 @@ static void fsl_imx25_realize(DeviceState *dev, Error **errp)
         };
 
         if (i < MAX_SERIAL_PORTS) {
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hds[i]);
+            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
         }
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);
hw/arm/fsl-imx31.c +1 -1
index e6c788049d..8509915200 100644
@@ -107,7 +107,7 @@ static void fsl_imx31_realize(DeviceState *dev, Error **errp)
         };
 
         if (i < MAX_SERIAL_PORTS) {
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hds[i]);
+            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
         }
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);
hw/arm/fsl-imx6.c +2 -2
index ea14de33c6..535ad5888b 100644
@@ -189,7 +189,7 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp)
         };
 
         if (i < MAX_SERIAL_PORTS) {
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hds[i]);
+            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
         }
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);
@@ -438,7 +438,7 @@ static void fsl_imx6_class_init(ObjectClass *oc, void *data)
 
     dc->realize = fsl_imx6_realize;
     dc->desc = "i.MX6 SOC";
-    /* Reason: Uses serial_hds[] in the realize() function */
+    /* Reason: Uses serial_hd() in the realize() function */
     dc->user_creatable = false;
 }
 
hw/arm/fsl-imx7.c +1 -1
index 390b4310e6..2848d76d3c 100644
@@ -391,7 +391,7 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
 
 
         if (i < MAX_SERIAL_PORTS) {
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hds[i]);
+            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
         }
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized",
hw/arm/highbank.c +1 -1
index 1742cf6f6c..0851d3b28a 100644
@@ -342,7 +342,7 @@ static void calxeda_init(MachineState *machine, enum cxmachines machine_id)
     busdev = SYS_BUS_DEVICE(dev);
     sysbus_mmio_map(busdev, 0, 0xfff34000);
     sysbus_connect_irq(busdev, 0, pic[18]);
-    pl011_create(0xfff36000, pic[20], serial_hds[0]);
+    pl011_create(0xfff36000, pic[20], serial_hd(0));
 
     dev = qdev_create(NULL, TYPE_HIGHBANK_REGISTERS);
     qdev_init_nofail(dev);
hw/arm/integratorcp.c +2 -2
index 58b40efc19..4eceebb9ea 100644
@@ -631,8 +631,8 @@ static void integratorcp_init(MachineState *machine)
     sysbus_create_varargs("integrator_pit", 0x13000000,
                           pic[5], pic[6], pic[7], NULL);
     sysbus_create_simple("pl031", 0x15000000, pic[8]);
-    pl011_create(0x16000000, pic[1], serial_hds[0]);
-    pl011_create(0x17000000, pic[2], serial_hds[1]);
+    pl011_create(0x16000000, pic[1], serial_hd(0));
+    pl011_create(0x17000000, pic[2], serial_hd(1));
     icp = sysbus_create_simple(TYPE_ICP_CONTROL_REGS, 0xcb000000,
                                qdev_get_gpio_in(sic, 3));
     sysbus_create_simple("pl050_keyboard", 0x18000000, pic[3]);
hw/arm/kzm.c +2 -2
index f9c2228e31..864c7bd411 100644
@@ -121,10 +121,10 @@ static void kzm_init(MachineState *machine)
                      qdev_get_gpio_in(DEVICE(&s->soc.avic), 52));
     }
 
-    if (serial_hds[2]) { /* touchscreen */
+    if (serial_hd(2)) { /* touchscreen */
         serial_mm_init(get_system_memory(), KZM_FPGA_ADDR+0x10, 0,
                        qdev_get_gpio_in(DEVICE(&s->soc.avic), 52),
-                       14745600, serial_hds[2], DEVICE_NATIVE_ENDIAN);
+                       14745600, serial_hd(2), DEVICE_NATIVE_ENDIAN);
     }
 
     kzm_binfo.ram_size = machine->ram_size;
hw/arm/mps2-tz.c +0 -0
index 8c86cffa9e..4ae4a5cb2a 100644

hw/arm/mps2-tz.c static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque, · line 175

Quoted 5 lines
hw/arm/mps2-tz.c +1 -1
@@ -172,7 +172,7 @@ static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
 {
     CMSDKAPBUART *uart = opaque;
     int i = uart - &mms->uart[0];
-    Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hds[i] : NULL;
+    Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hd(i) : NULL;

You can remove uartchr and directly use serial_hd(i).

hw/arm/mps2.c static void mps2_common_init(MachineState *machine) · line 233

Quoted 13 lines
hw/arm/mps2-tz.c +0 -0
     int rxirqno = i * 2;
     int txirqno = i * 2 + 1;
     int combirqno = i + 10;
hw/arm/mps2.c +1 -1
index 694fb36866..eb550fad34 100644
@@ -230,7 +230,7 @@ static void mps2_common_init(MachineState *machine)
             static const hwaddr uartbase[] = {0x40004000, 0x40005000,
                                               0x40006000, 0x40007000,
                                               0x40009000};
-            Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hds[i] : NULL;
+            Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hd(i) : NULL;

Ditto.

hw/arm/mps2.c static void mps2_common_init(MachineState *machine) · line 273

Quoted 9 lines
hw/arm/mps2.c +1 -1
             /* RX irq number; TX irq is always one greater */
             static const int uartirq[] = {0, 2, 4, 18, 20};
             qemu_irq txovrint = NULL, rxovrint = NULL;
@@ -270,7 +270,7 @@ static void mps2_common_init(MachineState *machine)
             static const hwaddr uartbase[] = {0x40004000, 0x40005000,
                                               0x4002c000, 0x4002d000,
                                               0x4002e000};
-            Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hds[i] : NULL;
+            Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hd(i) : NULL;

Ditto.

hw/arm/msf2-soc.c static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp) · line 141

Quoted 13 lines
hw/arm/mps2.c +0 -0
             Object *txrx_orgate;
             DeviceState *txrx_orgate_dev;
 
hw/arm/msf2-soc.c +1 -1
index f68df56b97..75c44adf7d 100644
@@ -138,10 +138,10 @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp)
     system_clock_scale = NANOSECONDS_PER_SECOND / s->m3clk;
 
     for (i = 0; i < MSF2_NUM_UARTS; i++) {
-        if (serial_hds[i]) {
+        if (serial_hd(i)) {

We can now remove this check, but maybe another series...

Quoted 12 lines
hw/arm/msf2-soc.c +1 -1
             serial_mm_init(get_system_memory(), uart_addr[i], 2,
                            qdev_get_gpio_in(armv7m, uart_irq[i]),
-                           115200, serial_hds[i], DEVICE_NATIVE_ENDIAN);
+                           115200, serial_hd(i), DEVICE_NATIVE_ENDIAN);
         }
     }
 
hw/arm/musicpal.c +0 -0
index 38d7322a19..c807010e83 100644

hw/arm/musicpal.c static void musicpal_init(MachineState *machine) · line 1613

Quoted 5 lines
hw/arm/musicpal.c +1 -1
@@ -1610,13 +1610,13 @@ static void musicpal_init(MachineState *machine)
                           pic[MP_TIMER2_IRQ], pic[MP_TIMER3_IRQ],
                           pic[MP_TIMER4_IRQ], NULL);
 
-    if (serial_hds[0]) {
+    if (serial_hd(0)) {

Ditto.

hw/arm/musicpal.c static void musicpal_init(MachineState *machine) · line 1617

Quoted 6 lines
hw/arm/musicpal.c +2 -2
         serial_mm_init(address_space_mem, MP_UART1_BASE, 2, pic[MP_UART1_IRQ],
-                       1825000, serial_hds[0], DEVICE_NATIVE_ENDIAN);
+                       1825000, serial_hd(0), DEVICE_NATIVE_ENDIAN);
     }
-    if (serial_hds[1]) {
+    if (serial_hd(1)) {

Ditto.

Quoted 14 lines
hw/arm/musicpal.c +1 -1
         serial_mm_init(address_space_mem, MP_UART2_BASE, 2, pic[MP_UART2_IRQ],
-                       1825000, serial_hds[1], DEVICE_NATIVE_ENDIAN);
+                       1825000, serial_hd(1), DEVICE_NATIVE_ENDIAN);
     }
 
     /* Register flash */
hw/arm/omap1.c +0 -0
index b3a23a83d1..24673abfca 100644
@@ -3963,21 +3963,21 @@ struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *system_memory,
                     omap_findclk(s, "uart1_ck"),
                     s->drq[OMAP_DMA_UART1_TX], s->drq[OMAP_DMA_UART1_RX],
                     "uart1",

hw/arm/omap1.c struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *system_memory, · line 3973

Quoted 10 lines
hw/arm/omap1.c +2 -2
-                    serial_hds[0]);
+                    serial_hd(0));
     s->uart[1] = omap_uart_init(0xfffb0800,
                                 qdev_get_gpio_in(s->ih[1], OMAP_INT_UART2),
                     omap_findclk(s, "uart2_ck"),
                     omap_findclk(s, "uart2_ck"),
                     s->drq[OMAP_DMA_UART2_TX], s->drq[OMAP_DMA_UART2_RX],
                     "uart2",
-                    serial_hds[0] ? serial_hds[1] : NULL);
+                    serial_hd(0) ? serial_hd(1) : NULL);

This will need cleanup later...

Quoted 58 lines
hw/arm/omap1.c +1 -1
     s->uart[2] = omap_uart_init(0xfffb9800,
                                 qdev_get_gpio_in(s->ih[0], OMAP_INT_UART3),
                     omap_findclk(s, "uart3_ck"),
                     omap_findclk(s, "uart3_ck"),
                     s->drq[OMAP_DMA_UART3_TX], s->drq[OMAP_DMA_UART3_RX],
                     "uart3",
-                    serial_hds[0] && serial_hds[1] ? serial_hds[2] : NULL);
+                    serial_hd(0) && serial_hd(1) ? serial_hd(2) : NULL);
 
     s->dpll[0] = omap_dpll_init(system_memory, 0xfffecf00,
                                 omap_findclk(s, "dpll1"));
hw/arm/omap2.c +5 -5
index 647b119ba9..80663533e1 100644
@@ -2349,7 +2349,7 @@ struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion *sysmem,
                     s->drq[OMAP24XX_DMA_UART1_TX],
                     s->drq[OMAP24XX_DMA_UART1_RX],
                     "uart1",
-                    serial_hds[0]);
+                    serial_hd(0));
     s->uart[1] = omap2_uart_init(sysmem, omap_l4ta(s->l4, 20),
                                  qdev_get_gpio_in(s->ih[0],
                                                   OMAP_INT_24XX_UART2_IRQ),
@@ -2358,7 +2358,7 @@ struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion *sysmem,
                     s->drq[OMAP24XX_DMA_UART2_TX],
                     s->drq[OMAP24XX_DMA_UART2_RX],
                     "uart2",
-                    serial_hds[0] ? serial_hds[1] : NULL);
+                    serial_hd(0) ? serial_hd(1) : NULL);
     s->uart[2] = omap2_uart_init(sysmem, omap_l4ta(s->l4, 21),
                                  qdev_get_gpio_in(s->ih[0],
                                                   OMAP_INT_24XX_UART3_IRQ),
@@ -2367,7 +2367,7 @@ struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion *sysmem,
                     s->drq[OMAP24XX_DMA_UART3_TX],
                     s->drq[OMAP24XX_DMA_UART3_RX],
                     "uart3",
-                    serial_hds[0] && serial_hds[1] ? serial_hds[2] : NULL);
+                    serial_hd(0) && serial_hd(1) ? serial_hd(2) : NULL);
 
     s->gptimer[0] = omap_gp_timer_init(omap_l4ta(s->l4, 7),
                     qdev_get_gpio_in(s->ih[0], OMAP_INT_24XX_GPTIMER1),
@@ -2519,8 +2519,8 @@ struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion *sysmem,
     omap_sti_init(omap_l4ta(s->l4, 18), sysmem, 0x54000000,
                   qdev_get_gpio_in(s->ih[0], OMAP_INT_24XX_STI),
                   omap_findclk(s, "emul_ck"),
-                    serial_hds[0] && serial_hds[1] && serial_hds[2] ?
-                    serial_hds[3] : NULL);
+                    serial_hd(0) && serial_hd(1) && serial_hd(2) ?
+                    serial_hd(3) : NULL);
 
     s->eac = omap_eac_init(omap_l4ta(s->l4, 32),
                            qdev_get_gpio_in(s->ih[0], OMAP_INT_24XX_EAC_IRQ),
hw/arm/pxa2xx.c +0 -0
index 5805a2c858..928a0431d6 100644

hw/arm/pxa2xx.c PXA2xxState *pxa270_init(MemoryRegion *address_space, · line 2109

Quoted 5 lines
hw/arm/pxa2xx.c +1 -1
@@ -2106,21 +2106,21 @@ PXA2xxState *pxa270_init(MemoryRegion *address_space,
                     qdev_get_gpio_in(s->dma, PXA2XX_TX_RQ_MMCI));
 
     for (i = 0; pxa270_serial[i].io_base; i++) {
-        if (serial_hds[i]) {
+        if (serial_hd(i)) {

Later cleanup.

hw/arm/pxa2xx.c PXA2xxState *pxa270_init(MemoryRegion *address_space, · line 2118

Quoted 11 lines
hw/arm/pxa2xx.c +2 -2
             serial_mm_init(address_space, pxa270_serial[i].io_base, 2,
                            qdev_get_gpio_in(s->pic, pxa270_serial[i].irqn),
-                           14857000 / 16, serial_hds[i],
+                           14857000 / 16, serial_hd(i),
                            DEVICE_NATIVE_ENDIAN);
         } else {
             break;
         }
     }
-    if (serial_hds[i])
+    if (serial_hd(i))

Later cleanup.

Quoted 10 lines
hw/arm/pxa2xx.c +1 -1
         s->fir = pxa2xx_fir_init(address_space, 0x40800000,
                         qdev_get_gpio_in(s->pic, PXA2XX_PIC_ICP),
                         qdev_get_gpio_in(s->dma, PXA2XX_RX_RQ_ICP),
                         qdev_get_gpio_in(s->dma, PXA2XX_TX_RQ_ICP),
-                        serial_hds[i]);
+                        serial_hd(i));
 
     s->lcd = pxa2xx_lcdc_init(address_space, 0x44000000,
                     qdev_get_gpio_in(s->pic, PXA2XX_PIC_LCD));

hw/arm/pxa2xx.c PXA2xxState *pxa255_init(MemoryRegion *address_space, unsigned int sdram_size) · line 2234

Quoted 5 lines
hw/arm/pxa2xx.c +1 -1
@@ -2231,21 +2231,21 @@ PXA2xxState *pxa255_init(MemoryRegion *address_space, unsigned int sdram_size)
                     qdev_get_gpio_in(s->dma, PXA2XX_TX_RQ_MMCI));
 
     for (i = 0; pxa255_serial[i].io_base; i++) {
-        if (serial_hds[i]) {
+        if (serial_hd(i)) {

Later cleanup.

hw/arm/pxa2xx.c PXA2xxState *pxa255_init(MemoryRegion *address_space, unsigned int sdram_size) · line 2243

Quoted 11 lines
hw/arm/pxa2xx.c +2 -2
             serial_mm_init(address_space, pxa255_serial[i].io_base, 2,
                            qdev_get_gpio_in(s->pic, pxa255_serial[i].irqn),
-                           14745600 / 16, serial_hds[i],
+                           14745600 / 16, serial_hd(i),
                            DEVICE_NATIVE_ENDIAN);
         } else {
             break;
         }
     }
-    if (serial_hds[i])
+    if (serial_hd(i))

Later cleanup.

Quoted 46 lines
hw/arm/pxa2xx.c +1 -1
         s->fir = pxa2xx_fir_init(address_space, 0x40800000,
                         qdev_get_gpio_in(s->pic, PXA2XX_PIC_ICP),
                         qdev_get_gpio_in(s->dma, PXA2XX_RX_RQ_ICP),
                         qdev_get_gpio_in(s->dma, PXA2XX_TX_RQ_ICP),
-                        serial_hds[i]);
+                        serial_hd(i));
 
     s->lcd = pxa2xx_lcdc_init(address_space, 0x44000000,
                     qdev_get_gpio_in(s->pic, PXA2XX_PIC_LCD));
hw/arm/realview.c +4 -4
index 2139a62e25..cd585d9469 100644
@@ -195,10 +195,10 @@ static void realview_init(MachineState *machine,
     sysbus_create_simple("pl050_keyboard", 0x10006000, pic[20]);
     sysbus_create_simple("pl050_mouse", 0x10007000, pic[21]);
 
-    pl011_create(0x10009000, pic[12], serial_hds[0]);
-    pl011_create(0x1000a000, pic[13], serial_hds[1]);
-    pl011_create(0x1000b000, pic[14], serial_hds[2]);
-    pl011_create(0x1000c000, pic[15], serial_hds[3]);
+    pl011_create(0x10009000, pic[12], serial_hd(0));
+    pl011_create(0x1000a000, pic[13], serial_hd(1));
+    pl011_create(0x1000b000, pic[14], serial_hd(2));
+    pl011_create(0x1000c000, pic[15], serial_hd(3));
 
     /* DMA controller is optional, apparently.  */
     sysbus_create_simple("pl081", 0x10030000, pic[24]);
hw/arm/stellaris.c +1 -1
index de7c0fc4a6..e886f54976 100644
@@ -1353,7 +1353,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
         if (board->dc2 & (1 << i)) {
             pl011_luminary_create(0x4000c000 + i * 0x1000,
                                   qdev_get_gpio_in(nvic, uart_irq[i]),
-                                  serial_hds[i]);
+                                  serial_hd(i));
         }
     }
     if (board->dc2 & (1 << 4)) {
hw/arm/stm32f205_soc.c +0 -0
index 1cd6374e07..f59418e7d0 100644

hw/arm/stm32f205_soc.c static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp) · line 139

Quoted 5 lines
hw/arm/stm32f205_soc.c +1 -1
@@ -136,7 +136,7 @@ static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp)
     for (i = 0; i < STM_NUM_USARTS; i++) {
         dev = DEVICE(&(s->usart[i]));
         qdev_prop_set_chr(dev, "chardev",
-                          i < MAX_SERIAL_PORTS ? serial_hds[i] : NULL);
+                          i < MAX_SERIAL_PORTS ? serial_hd(i) : NULL);

You can now use serial_hd(i) directly.

Quoted 159 lines
hw/arm/stm32f205_soc.c +0 -0
         object_property_set_bool(OBJECT(&s->usart[i]), true, "realized", &err);
         if (err != NULL) {
             error_propagate(errp, err);
hw/arm/strongarm.c +1 -1
index 4cdb3a670b..ec2627374d 100644
@@ -1622,7 +1622,7 @@ StrongARMState *sa1110_init(MemoryRegion *sysmem,
 
     for (i = 0; sa_serial[i].io_base; i++) {
         DeviceState *dev = qdev_create(NULL, TYPE_STRONGARM_UART);
-        qdev_prop_set_chr(dev, "chardev", serial_hds[i]);
+        qdev_prop_set_chr(dev, "chardev", serial_hd(i));
         qdev_init_nofail(dev);
         sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0,
                 sa_serial[i].io_base);
hw/arm/versatilepb.c +4 -4
index 418792cd02..e01e3192ff 100644
@@ -283,10 +283,10 @@ static void versatile_init(MachineState *machine, int board_id)
         n--;
     }
 
-    pl011_create(0x101f1000, pic[12], serial_hds[0]);
-    pl011_create(0x101f2000, pic[13], serial_hds[1]);
-    pl011_create(0x101f3000, pic[14], serial_hds[2]);
-    pl011_create(0x10009000, sic[6], serial_hds[3]);
+    pl011_create(0x101f1000, pic[12], serial_hd(0));
+    pl011_create(0x101f2000, pic[13], serial_hd(1));
+    pl011_create(0x101f3000, pic[14], serial_hd(2));
+    pl011_create(0x10009000, sic[6], serial_hd(3));
 
     sysbus_create_simple("pl080", 0x10130000, pic[17]);
     sysbus_create_simple("sp804", 0x101e2000, pic[4]);
hw/arm/vexpress.c +4 -4
index 9fad79177a..f1e33c8a36 100644
@@ -622,10 +622,10 @@ static void vexpress_common_init(MachineState *machine)
     sysbus_create_simple("pl050_keyboard", map[VE_KMI0], pic[12]);
     sysbus_create_simple("pl050_mouse", map[VE_KMI1], pic[13]);
 
-    pl011_create(map[VE_UART0], pic[5], serial_hds[0]);
-    pl011_create(map[VE_UART1], pic[6], serial_hds[1]);
-    pl011_create(map[VE_UART2], pic[7], serial_hds[2]);
-    pl011_create(map[VE_UART3], pic[8], serial_hds[3]);
+    pl011_create(map[VE_UART0], pic[5], serial_hd(0));
+    pl011_create(map[VE_UART1], pic[6], serial_hd(1));
+    pl011_create(map[VE_UART2], pic[7], serial_hd(2));
+    pl011_create(map[VE_UART3], pic[8], serial_hd(3));
 
     sysbus_create_simple("sp804", map[VE_TIMER01], pic[2]);
     sysbus_create_simple("sp804", map[VE_TIMER23], pic[3]);
hw/arm/virt.c +2 -2
index 94dcb125d3..a18291c5d5 100644
@@ -1371,11 +1371,11 @@ static void machvirt_init(MachineState *machine)
 
     fdt_add_pmu_nodes(vms);
 
-    create_uart(vms, pic, VIRT_UART, sysmem, serial_hds[0]);
+    create_uart(vms, pic, VIRT_UART, sysmem, serial_hd(0));
 
     if (vms->secure) {
         create_secure_ram(vms, secure_sysmem);
-        create_uart(vms, pic, VIRT_SECURE_UART, secure_sysmem, serial_hds[1]);
+        create_uart(vms, pic, VIRT_SECURE_UART, secure_sysmem, serial_hd(1));
     }
 
     create_rtc(vms, pic);
hw/arm/xilinx_zynq.c +2 -2
index 0f76333770..899a26326f 100644
@@ -236,8 +236,8 @@ static void zynq_init(MachineState *machine)
     sysbus_create_simple("xlnx,ps7-usb", 0xE0002000, pic[53-IRQ_OFFSET]);
     sysbus_create_simple("xlnx,ps7-usb", 0xE0003000, pic[76-IRQ_OFFSET]);
 
-    cadence_uart_create(0xE0000000, pic[59 - IRQ_OFFSET], serial_hds[0]);
-    cadence_uart_create(0xE0001000, pic[82 - IRQ_OFFSET], serial_hds[1]);
+    cadence_uart_create(0xE0000000, pic[59 - IRQ_OFFSET], serial_hd(0));
+    cadence_uart_create(0xE0001000, pic[82 - IRQ_OFFSET], serial_hd(1));
 
     sysbus_create_varargs("cadence_ttc", 0xF8001000,
             pic[42-IRQ_OFFSET], pic[43-IRQ_OFFSET], pic[44-IRQ_OFFSET], NULL);
hw/arm/xlnx-zynqmp.c +1 -1
index 465796e97c..505253e0d2 100644
@@ -374,7 +374,7 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
     }
 
     for (i = 0; i < XLNX_ZYNQMP_NUM_UARTS; i++) {
-        qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hds[i]);
+        qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);
         if (err) {
             error_propagate(errp, err);
hw/char/exynos4210_uart.c +1 -1
index 3957e78abf..c2bba03362 100644
@@ -600,7 +600,7 @@ DeviceState *exynos4210_uart_create(hwaddr addr,
                          MAX_SERIAL_PORTS);
             exit(1);
         }
-        chr = serial_hds[channel];
+        chr = serial_hd(channel);
         if (!chr) {
             snprintf(label, ARRAY_SIZE(label), "%s%d", chr_name, channel);
             chr = qemu_chr_new(label, "null");
hw/char/serial-isa.c +2 -2
index d7c5cc11fe..eb5996159d 100644
@@ -141,8 +141,8 @@ void serial_hds_isa_init(ISABus *bus, int from, int to)
     assert(to <= MAX_SERIAL_PORTS);
 
     for (i = from; i < to; ++i) {
-        if (serial_hds[i]) {
-            serial_isa_init(bus, i, serial_hds[i]);
+        if (serial_hd(i)) {
+            serial_isa_init(bus, i, serial_hd(i));
         }
     }
 }
hw/char/xen_console.c +1 -1
index 5e68326c19..bdfaa40ed3 100644
@@ -201,7 +201,7 @@ static int con_init(struct XenDevice *xendev)
     /* no Xen override, use qemu output device */
     if (output == NULL) {
         if (con->xendev.dev) {
-            qemu_chr_fe_init(&con->chr, serial_hds[con->xendev.dev],
+            qemu_chr_fe_init(&con->chr, serial_hd(con->xendev.dev),
                              &error_abort);
         }
     } else {
hw/cris/axis_dev88.c +1 -1
index 9ccc4350a5..409f3d581a 100644
@@ -337,7 +337,7 @@ void axisdev88_init(MachineState *machine)
     sysbus_create_varargs("etraxfs,timer", 0x3005e000, irq[0x1b], nmi[1], NULL);
 
     for (i = 0; i < 4; i++) {
-        etraxfs_ser_create(0x30026000 + i * 0x2000, irq[0x14 + i], serial_hds[i]);
+        etraxfs_ser_create(0x30026000 + i * 0x2000, irq[0x14 + i], serial_hd(i));
     }
 
     if (kernel_filename) {
hw/hppa/machine.c +0 -0
index 19033e268d..a1d6b0ebfb 100644

hw/hppa/machine.c static void machine_hppa_init(MachineState *machine) · line 111

Quoted 5 lines
hw/hppa/machine.c +1 -1
@@ -108,10 +108,10 @@ static void machine_hppa_init(MachineState *machine)
     mc146818_rtc_init(isa_bus, 2000, rtc_irq);
 
     /* Serial code setup.  */
-    if (serial_hds[0]) {
+    if (serial_hd(0)) {

Later cleanup.

Quoted 12 lines
hw/hppa/machine.c +1 -1
         uint32_t addr = DINO_UART_HPA + 0x800;
         serial_mm_init(addr_space, addr, 0, serial_irq,
-                       115200, serial_hds[0], DEVICE_BIG_ENDIAN);
+                       115200, serial_hd(0), DEVICE_BIG_ENDIAN);
     }
 
     /* SCSI disk setup. */
hw/isa/isa-superio.c +0 -0
index b95608a003..76286c81a1 100644

hw/isa/isa-superio.c static void isa_superio_realize(DeviceState *dev, Error **errp) · line 86

Quoted 8 lines
hw/isa/isa-superio.c +2 -2
@@ -81,8 +81,8 @@ static void isa_superio_realize(DeviceState *dev, Error **errp)
             break;
         }
         if (!k->serial.is_enabled || k->serial.is_enabled(sio, i)) {
-            /* FIXME use a qdev chardev prop instead of serial_hds[] */
-            chr = serial_hds[i];
+            /* FIXME use a qdev chardev prop instead of serial_hd() */
+            chr = serial_hd(i);
             if (chr == NULL || chr->be) {

I'll clean this on top of your series.

Quoted 135 lines
hw/isa/isa-superio.c +0 -0
                 name = g_strdup_printf("discarding-serial%d", i);
                 chr = qemu_chr_new(name, "null");
hw/lm32/lm32_boards.c +4 -4
index 527bcc229c..907e875d02 100644
@@ -125,12 +125,12 @@ static void lm32_evr_init(MachineState *machine)
         irq[i] = qdev_get_gpio_in(env->pic_state, i);
     }
 
-    lm32_uart_create(uart0_base, irq[uart0_irq], serial_hds[0]);
+    lm32_uart_create(uart0_base, irq[uart0_irq], serial_hd(0));
     sysbus_create_simple("lm32-timer", timer0_base, irq[timer0_irq]);
     sysbus_create_simple("lm32-timer", timer1_base, irq[timer1_irq]);
 
     /* make sure juart isn't the first chardev */
-    env->juart_state = lm32_juart_init(serial_hds[1]);
+    env->juart_state = lm32_juart_init(serial_hd(1));
 
     reset_info->bootstrap_pc = flash_base;
 
@@ -217,13 +217,13 @@ static void lm32_uclinux_init(MachineState *machine)
         irq[i] = qdev_get_gpio_in(env->pic_state, i);
     }
 
-    lm32_uart_create(uart0_base, irq[uart0_irq], serial_hds[0]);
+    lm32_uart_create(uart0_base, irq[uart0_irq], serial_hd(0));
     sysbus_create_simple("lm32-timer", timer0_base, irq[timer0_irq]);
     sysbus_create_simple("lm32-timer", timer1_base, irq[timer1_irq]);
     sysbus_create_simple("lm32-timer", timer2_base, irq[timer2_irq]);
 
     /* make sure juart isn't the first chardev */
-    env->juart_state = lm32_juart_init(serial_hds[1]);
+    env->juart_state = lm32_juart_init(serial_hd(1));
 
     reset_info->bootstrap_pc = flash_base;
 
hw/lm32/milkymist.c +2 -2
index 85d64fe58d..f9688e059e 100644
@@ -151,7 +151,7 @@ milkymist_init(MachineState *machine)
     }
     g_free(bios_filename);
 
-    milkymist_uart_create(0x60000000, irq[0], serial_hds[0]);
+    milkymist_uart_create(0x60000000, irq[0], serial_hd(0));
     milkymist_sysctl_create(0x60001000, irq[1], irq[2], irq[3],
             80000000, 0x10014d31, 0x0000041f, 0x00000001);
     milkymist_hpdmc_create(0x60002000);
@@ -167,7 +167,7 @@ milkymist_init(MachineState *machine)
             0x20000000, 0x1000, 0x20020000, 0x2000);
 
     /* make sure juart isn't the first chardev */
-    env->juart_state = lm32_juart_init(serial_hds[1]);
+    env->juart_state = lm32_juart_init(serial_hd(1));
 
     if (kernel_filename) {
         uint64_t entry;
hw/m68k/mcf5206.c +2 -2
index bd8e993c58..6ad1e4bd2d 100644
@@ -543,8 +543,8 @@ qemu_irq *mcf5206_init(MemoryRegion *sysmem, uint32_t base, M68kCPU *cpu)
     pic = qemu_allocate_irqs(m5206_mbar_set_irq, s, 14);
     s->timer[0] = m5206_timer_init(pic[9]);
     s->timer[1] = m5206_timer_init(pic[10]);
-    s->uart[0] = mcf_uart_init(pic[12], serial_hds[0]);
-    s->uart[1] = mcf_uart_init(pic[13], serial_hds[1]);
+    s->uart[0] = mcf_uart_init(pic[12], serial_hd(0));
+    s->uart[1] = mcf_uart_init(pic[13], serial_hd(1));
     s->cpu = cpu;
 
     m5206_mbar_reset(s);
hw/m68k/mcf5208.c +3 -3
index fac0d09cbc..7aca58542e 100644
@@ -247,9 +247,9 @@ static void mcf5208evb_init(MachineState *machine)
     /* Internal peripherals.  */
     pic = mcf_intc_init(address_space_mem, 0xfc048000, cpu);
 
-    mcf_uart_mm_init(0xfc060000, pic[26], serial_hds[0]);
-    mcf_uart_mm_init(0xfc064000, pic[27], serial_hds[1]);
-    mcf_uart_mm_init(0xfc068000, pic[28], serial_hds[2]);
+    mcf_uart_mm_init(0xfc060000, pic[26], serial_hd(0));
+    mcf_uart_mm_init(0xfc064000, pic[27], serial_hd(1));
+    mcf_uart_mm_init(0xfc068000, pic[28], serial_hd(2));
 
     mcf5208_sys_init(address_space_mem, pic);
 
hw/microblaze/petalogix_ml605_mmu.c +1 -1
index b664dc0f9c..cf6bf3f32a 100644
@@ -125,7 +125,7 @@ petalogix_ml605_init(MachineState *machine)
     }
 
     serial_mm_init(address_space_mem, UART16550_BASEADDR + 0x1000, 2,
-                   irq[UART16550_IRQ], 115200, serial_hds[0],
+                   irq[UART16550_IRQ], 115200, serial_hd(0),
                    DEVICE_LITTLE_ENDIAN);
 
     /* 2 timers at irq 2 @ 100 Mhz.  */
hw/microblaze/petalogix_s3adsp1800_mmu.c +1 -1
index 5cb4deb69e..1186002a76 100644
@@ -103,7 +103,7 @@ petalogix_s3adsp1800_init(MachineState *machine)
     }
 
     xilinx_uartlite_create(UARTLITE_BASEADDR, irq[UARTLITE_IRQ],
-                           serial_hds[0]);
+                           serial_hd(0));
 
     /* 2 timers at irq 2 @ 62 Mhz.  */
     dev = qdev_create(NULL, "xlnx.xps-timer");
hw/mips/boston.c +1 -1
index 14f0f6673b..5302e5c885 100644
@@ -507,7 +507,7 @@ static void boston_mach_init(MachineState *machine)
 
     s->uart = serial_mm_init(sys_mem, 0x17ffe000, 2,
                              get_cps_irq(s->cps, 3), 10000000,
-                             serial_hds[0], DEVICE_NATIVE_ENDIAN);
+                             serial_hd(0), DEVICE_NATIVE_ENDIAN);
 
     lcd = g_new(MemoryRegion, 1);
     memory_region_init_io(lcd, NULL, &boston_lcd_ops, s, "boston-lcd", 0x8);
hw/mips/mips_jazz.c +0 -0
index 7223085547..90cb306f53 100644

hw/mips/mips_jazz.c static void mips_jazz_init(MachineState *machine, · line 306

Quoted 5 lines
hw/mips/mips_jazz.c +1 -1
@@ -303,15 +303,15 @@ static void mips_jazz_init(MachineState *machine,
     memory_region_add_subregion(address_space, 0x80005000, i8042);
 
     /* Serial ports */
-    if (serial_hds[0]) {
+    if (serial_hd(0)) {

Later cleanup.

hw/mips/mips_jazz.c static void mips_jazz_init(MachineState *machine, · line 311

Quoted 7 lines
hw/mips/mips_jazz.c +2 -2
         serial_mm_init(address_space, 0x80006000, 0,
                        qdev_get_gpio_in(rc4030, 8), 8000000/16,
-                       serial_hds[0], DEVICE_NATIVE_ENDIAN);
+                       serial_hd(0), DEVICE_NATIVE_ENDIAN);
     }
-    if (serial_hds[1]) {
+    if (serial_hd(1)) {

Later cleanup.

Quoted 25 lines
hw/mips/mips_jazz.c +1 -1
         serial_mm_init(address_space, 0x80007000, 0,
                        qdev_get_gpio_in(rc4030, 9), 8000000/16,
-                       serial_hds[1], DEVICE_NATIVE_ENDIAN);
+                       serial_hd(1), DEVICE_NATIVE_ENDIAN);
     }
 
     /* Parallel port */
hw/mips/mips_malta.c +1 -1
index 49fe7a0a72..af70ecffc0 100644
@@ -1057,7 +1057,7 @@ void mips_malta_init(MachineState *machine)
     /* FPGA */
 
     /* The CBUS UART is attached to the MIPS CPU INT2 pin, ie interrupt 4 */
-    malta_fpga_init(system_memory, FPGA_ADDRESS, cbus_irq, serial_hds[2]);
+    malta_fpga_init(system_memory, FPGA_ADDRESS, cbus_irq, serial_hd(2));
 
     /* Load firmware in flash / BIOS. */
     dinfo = drive_get(IF_PFLASH, 0, fl_idx);
hw/mips/mips_mipssim.c +0 -0
index e0ba5efc84..241faa1d0f 100644

hw/mips/mips_mipssim.c mips_mipssim_init(MachineState *machine) · line 216

Quoted 6 lines
hw/mips/mips_mipssim.c +1 -2
@@ -213,8 +213,8 @@ mips_mipssim_init(MachineState *machine)
 
     /* A single 16450 sits at offset 0x3f8. It is attached to
        MIPS CPU INT2, which is interrupt 4. */
-    if (serial_hds[0])
-        serial_init(0x3f8, env->irq[4], 115200, serial_hds[0],
+    if (serial_hd(0))

We will drop this if () later... This now misses brackets :/

Quoted 24 lines
hw/mips/mips_mipssim.c +1 -0
+        serial_init(0x3f8, env->irq[4], 115200, serial_hd(0),
                     get_system_io());
 
     if (nd_table[0].used)
hw/misc/macio/macio.c +2 -2
index b74a6572b0..a0cefe5719 100644
@@ -118,8 +118,8 @@ static void macio_common_realize(PCIDevice *d, Error **errp)
     qdev_prop_set_uint32(DEVICE(&s->escc), "disabled", 0);
     qdev_prop_set_uint32(DEVICE(&s->escc), "frequency", ESCC_CLOCK);
     qdev_prop_set_uint32(DEVICE(&s->escc), "it_shift", 4);
-    qdev_prop_set_chr(DEVICE(&s->escc), "chrA", serial_hds[0]);
-    qdev_prop_set_chr(DEVICE(&s->escc), "chrB", serial_hds[1]);
+    qdev_prop_set_chr(DEVICE(&s->escc), "chrA", serial_hd(0));
+    qdev_prop_set_chr(DEVICE(&s->escc), "chrB", serial_hd(1));
     qdev_prop_set_uint32(DEVICE(&s->escc), "chnBtype", escc_serial);
     qdev_prop_set_uint32(DEVICE(&s->escc), "chnAtype", escc_serial);
     object_property_set_bool(OBJECT(&s->escc), true, "realized", &err);
hw/moxie/moxiesim.c +0 -0
index 0bbf770795..d41247dbdc 100644

hw/moxie/moxiesim.c static void moxiesim_init(MachineState *machine) · line 144

Quoted 5 lines
hw/moxie/moxiesim.c +1 -1
@@ -141,9 +141,9 @@ static void moxiesim_init(MachineState *machine)
     }
 
     /* A single 16450 sits at offset 0x3f8.  */
-    if (serial_hds[0]) {
+    if (serial_hd(0)) {

Later cleanup.

Quoted 37 lines
hw/moxie/moxiesim.c +1 -1
         serial_mm_init(address_space_mem, 0x3f8, 0, env->irq[4],
-                       8000000/16, serial_hds[0], DEVICE_LITTLE_ENDIAN);
+                       8000000/16, serial_hd(0), DEVICE_LITTLE_ENDIAN);
     }
 }
 
hw/nios2/10m50_devboard.c +1 -1
index 42053b2ca9..36b49a420c 100644
@@ -92,7 +92,7 @@ static void nios2_10m50_ghrd_init(MachineState *machine)
 
     /* Register: Altera 16550 UART */
     serial_mm_init(address_space_mem, 0xf8001600, 2, irq[1], 115200,
-                   serial_hds[0], DEVICE_NATIVE_ENDIAN);
+                   serial_hd(0), DEVICE_NATIVE_ENDIAN);
 
     /* Register: Timer sys_clk_timer  */
     dev = qdev_create(NULL, "ALTR.timer");
hw/openrisc/openrisc_sim.c +1 -1
index c755f11efd..a495a84a41 100644
@@ -164,7 +164,7 @@ static void openrisc_sim_init(MachineState *machine)
     }
 
     serial_mm_init(get_system_memory(), 0x90000000, 0, serial_irq,
-                   115200, serial_hds[0], DEVICE_NATIVE_ENDIAN);
+                   115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);
 
     openrisc_load_kernel(ram_size, kernel_filename);
 }
hw/ppc/e500.c +0 -0
index 9a85a41362..2ddab7ed24 100644

hw/ppc/e500.c static int ppce500_load_device_tree(MachineState *machine, · line 459

Quoted 5 lines
hw/ppc/e500.c +1 -1
@@ -456,12 +456,12 @@ static int ppce500_load_device_tree(MachineState *machine,
      * device it finds in the dt as serial output device. And we generate
      * devices in reverse order to the dt.
      */
-    if (serial_hds[1]) {
+    if (serial_hd(1)) {

Later cleanup.

hw/ppc/e500.c static int ppce500_load_device_tree(MachineState *machine, · line 464

Quoted 6 lines
hw/ppc/e500.c +1 -1
         dt_serial_create(fdt, MPC8544_SERIAL1_REGS_OFFSET,
                          soc, mpic, "serial1", 1, false);
     }
 
-    if (serial_hds[0]) {
+    if (serial_hd(0)) {

Later cleanup.

hw/ppc/e500.c void ppce500_init(MachineState *machine, PPCE500Params *params) · line 878

Quoted 9 lines
hw/ppc/e500.c +1 -1
         dt_serial_create(fdt, MPC8544_SERIAL0_REGS_OFFSET,
                          soc, mpic, "serial0", 0, true);
     }
@@ -875,16 +875,16 @@ void ppce500_init(MachineState *machine, PPCE500Params *params)
     mpicdev = ppce500_init_mpic(machine, params, ccsr_addr_space, irqs);
 
     /* Serial */
-    if (serial_hds[0]) {
+    if (serial_hd(0)) {

Later cleanup.

hw/ppc/e500.c void ppce500_init(MachineState *machine, PPCE500Params *params) · line 884

Quoted 8 lines
hw/ppc/e500.c +2 -2
         serial_mm_init(ccsr_addr_space, MPC8544_SERIAL0_REGS_OFFSET,
                        0, qdev_get_gpio_in(mpicdev, 42), 399193,
-                       serial_hds[0], DEVICE_BIG_ENDIAN);
+                       serial_hd(0), DEVICE_BIG_ENDIAN);
     }
 
-    if (serial_hds[1]) {
+    if (serial_hd(1)) {

Later cleanup.

Quoted 12 lines
hw/ppc/e500.c +1 -1
         serial_mm_init(ccsr_addr_space, MPC8544_SERIAL1_REGS_OFFSET,
                        0, qdev_get_gpio_in(mpicdev, 42), 399193,
-                       serial_hds[1], DEVICE_BIG_ENDIAN);
+                       serial_hd(1), DEVICE_BIG_ENDIAN);
     }
 
     /* General Utility device */
hw/ppc/ppc405_uc.c +0 -0
index 205ebcea93..34f8d57b07 100644

hw/ppc/ppc405_uc.c CPUPPCState *ppc405cr_init(MemoryRegion *address_space_mem, · line 1663

Quoted 5 lines
hw/ppc/ppc405_uc.c +1 -1
@@ -1660,14 +1660,14 @@ CPUPPCState *ppc405cr_init(MemoryRegion *address_space_mem,
     dma_irqs[3] = pic[23];
     ppc405_dma_init(env, dma_irqs);
     /* Serial ports */
-    if (serial_hds[0] != NULL) {
+    if (serial_hd(0) != NULL) {

Later cleanup....

Quoted 300 lines
hw/ppc/ppc405_uc.c +7 -7
         serial_mm_init(address_space_mem, 0xef600300, 0, pic[0],
-                       PPC_SERIAL_MM_BAUDBASE, serial_hds[0],
+                       PPC_SERIAL_MM_BAUDBASE, serial_hd(0),
                        DEVICE_BIG_ENDIAN);
     }
-    if (serial_hds[1] != NULL) {
+    if (serial_hd(1) != NULL) {
         serial_mm_init(address_space_mem, 0xef600400, 0, pic[1],
-                       PPC_SERIAL_MM_BAUDBASE, serial_hds[1],
+                       PPC_SERIAL_MM_BAUDBASE, serial_hd(1),
                        DEVICE_BIG_ENDIAN);
     }
     /* IIC controller */
@@ -2023,14 +2023,14 @@ CPUPPCState *ppc405ep_init(MemoryRegion *address_space_mem,
     /* GPIO */
     ppc405_gpio_init(0xef600700);
     /* Serial ports */
-    if (serial_hds[0] != NULL) {
+    if (serial_hd(0) != NULL) {
         serial_mm_init(address_space_mem, 0xef600300, 0, pic[0],
-                       PPC_SERIAL_MM_BAUDBASE, serial_hds[0],
+                       PPC_SERIAL_MM_BAUDBASE, serial_hd(0),
                        DEVICE_BIG_ENDIAN);
     }
-    if (serial_hds[1] != NULL) {
+    if (serial_hd(1) != NULL) {
         serial_mm_init(address_space_mem, 0xef600400, 0, pic[1],
-                       PPC_SERIAL_MM_BAUDBASE, serial_hds[1],
+                       PPC_SERIAL_MM_BAUDBASE, serial_hd(1),
                        DEVICE_BIG_ENDIAN);
     }
     /* OCM */
hw/ppc/ppc440_bamboo.c +4 -4
index 8641986a71..44e6a0c21b 100644
@@ -238,14 +238,14 @@ static void bamboo_init(MachineState *machine)
                              get_system_io(), 0, PPC440EP_PCI_IOLEN);
     memory_region_add_subregion(get_system_memory(), PPC440EP_PCI_IO, isa);
 
-    if (serial_hds[0] != NULL) {
+    if (serial_hd(0) != NULL) {
         serial_mm_init(address_space_mem, 0xef600300, 0, pic[0],
-                       PPC_SERIAL_MM_BAUDBASE, serial_hds[0],
+                       PPC_SERIAL_MM_BAUDBASE, serial_hd(0),
                        DEVICE_BIG_ENDIAN);
     }
-    if (serial_hds[1] != NULL) {
+    if (serial_hd(1) != NULL) {
         serial_mm_init(address_space_mem, 0xef600400, 0, pic[1],
-                       PPC_SERIAL_MM_BAUDBASE, serial_hds[1],
+                       PPC_SERIAL_MM_BAUDBASE, serial_hd(1),
                        DEVICE_BIG_ENDIAN);
     }
 
hw/ppc/sam460ex.c +4 -4
index dfff262f96..a48e6e6fce 100644
@@ -522,14 +522,14 @@ static void sam460ex_init(MachineState *machine)
 
     /* SoC has 4 UARTs
      * but board has only one wired and two are present in fdt */
-    if (serial_hds[0] != NULL) {
+    if (serial_hd(0) != NULL) {
         serial_mm_init(address_space_mem, 0x4ef600300, 0, uic[1][1],
-                       PPC_SERIAL_MM_BAUDBASE, serial_hds[0],
+                       PPC_SERIAL_MM_BAUDBASE, serial_hd(0),
                        DEVICE_BIG_ENDIAN);
     }
-    if (serial_hds[1] != NULL) {
+    if (serial_hd(1) != NULL) {
         serial_mm_init(address_space_mem, 0x4ef600400, 0, uic[0][1],
-                       PPC_SERIAL_MM_BAUDBASE, serial_hds[1],
+                       PPC_SERIAL_MM_BAUDBASE, serial_hd(1),
                        DEVICE_BIG_ENDIAN);
     }
 
hw/ppc/spapr.c +2 -2
index a81570e7c8..b0ecfaca9e 100644
@@ -2590,8 +2590,8 @@ static void spapr_machine_init(MachineState *machine)
     spapr->vio_bus = spapr_vio_bus_init();
 
     for (i = 0; i < MAX_SERIAL_PORTS; i++) {
-        if (serial_hds[i]) {
-            spapr_vty_create(spapr->vio_bus, serial_hds[i]);
+        if (serial_hd(i)) {
+            spapr_vty_create(spapr->vio_bus, serial_hd(i));
         }
     }
 
hw/ppc/virtex_ml507.c +1 -1
index 77a1778e07..a80cbdd7ee 100644
@@ -251,7 +251,7 @@ static void virtex_init(MachineState *machine)
     }
 
     serial_mm_init(address_space_mem, UART16550_BASEADDR, 2, irq[UART16550_IRQ],
-                   115200, serial_hds[0], DEVICE_LITTLE_ENDIAN);
+                   115200, serial_hd(0), DEVICE_LITTLE_ENDIAN);
 
     /* 2 timers at irq 2 @ 62 Mhz.  */
     dev = qdev_create(NULL, "xlnx.xps-timer");
hw/riscv/sifive_e.c +2 -2
index 19eca36ff4..487244890e 100644
@@ -162,13 +162,13 @@ static void riscv_sifive_e_init(MachineState *machine)
     sifive_mmio_emulate(sys_mem, "riscv.sifive.e.gpio0",
         memmap[SIFIVE_E_GPIO0].base, memmap[SIFIVE_E_GPIO0].size);
     sifive_uart_create(sys_mem, memmap[SIFIVE_E_UART0].base,
-        serial_hds[0], SIFIVE_PLIC(s->plic)->irqs[SIFIVE_E_UART0_IRQ]);
+        serial_hd(0), SIFIVE_PLIC(s->plic)->irqs[SIFIVE_E_UART0_IRQ]);
     sifive_mmio_emulate(sys_mem, "riscv.sifive.e.qspi0",
         memmap[SIFIVE_E_QSPI0].base, memmap[SIFIVE_E_QSPI0].size);
     sifive_mmio_emulate(sys_mem, "riscv.sifive.e.pwm0",
         memmap[SIFIVE_E_PWM0].base, memmap[SIFIVE_E_PWM0].size);
     /* sifive_uart_create(sys_mem, memmap[SIFIVE_E_UART1].base,
-        serial_hds[1], SIFIVE_PLIC(s->plic)->irqs[SIFIVE_E_UART1_IRQ]); */
+        serial_hd(1), SIFIVE_PLIC(s->plic)->irqs[SIFIVE_E_UART1_IRQ]); */
     sifive_mmio_emulate(sys_mem, "riscv.sifive.e.qspi1",
         memmap[SIFIVE_E_QSPI1].base, memmap[SIFIVE_E_QSPI1].size);
     sifive_mmio_emulate(sys_mem, "riscv.sifive.e.pwm1",
hw/riscv/sifive_u.c +2 -2
index 1c2deefa6c..66616bacd7 100644
@@ -296,9 +296,9 @@ static void riscv_sifive_u_init(MachineState *machine)
         SIFIVE_U_PLIC_CONTEXT_STRIDE,
         memmap[SIFIVE_U_PLIC].size);
     sifive_uart_create(sys_memory, memmap[SIFIVE_U_UART0].base,
-        serial_hds[0], SIFIVE_PLIC(s->plic)->irqs[SIFIVE_U_UART0_IRQ]);
+        serial_hd(0), SIFIVE_PLIC(s->plic)->irqs[SIFIVE_U_UART0_IRQ]);
     /* sifive_uart_create(sys_memory, memmap[SIFIVE_U_UART1].base,
-        serial_hds[1], SIFIVE_PLIC(s->plic)->irqs[SIFIVE_U_UART1_IRQ]); */
+        serial_hd(1), SIFIVE_PLIC(s->plic)->irqs[SIFIVE_U_UART1_IRQ]); */
     sifive_clint_create(memmap[SIFIVE_U_CLINT].base,
         memmap[SIFIVE_U_CLINT].size, smp_cpus,
         SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE);
hw/riscv/spike.c +2 -2
index 2d1f114d40..62857e4fa0 100644
@@ -233,7 +233,7 @@ static void spike_v1_10_0_board_init(MachineState *machine)
         s->fdt, s->fdt_size);
 
     /* initialize HTIF using symbols found in load_kernel */
-    htif_mm_init(system_memory, boot_rom, &s->soc.harts[0].env, serial_hds[0]);
+    htif_mm_init(system_memory, boot_rom, &s->soc.harts[0].env, serial_hd(0));
 
     /* Core Local Interruptor (timer and IPI) */
     sifive_clint_create(memmap[SPIKE_CLINT].base, memmap[SPIKE_CLINT].size,
@@ -330,7 +330,7 @@ static void spike_v1_09_1_board_init(MachineState *machine)
         config_string, config_string_len);
 
     /* initialize HTIF using symbols found in load_kernel */
-    htif_mm_init(system_memory, boot_rom, &s->soc.harts[0].env, serial_hds[0]);
+    htif_mm_init(system_memory, boot_rom, &s->soc.harts[0].env, serial_hd(0));
 
     /* Core Local Interruptor (timer and IPI) */
     sifive_clint_create(memmap[SPIKE_CLINT].base, memmap[SPIKE_CLINT].size,
hw/riscv/virt.c +1 -1
index e2c214e86a..4f69eb2cff 100644
@@ -382,7 +382,7 @@ static void riscv_virt_board_init(MachineState *machine)
 
     serial_mm_init(system_memory, memmap[VIRT_UART0].base,
         0, SIFIVE_PLIC(s->plic)->irqs[UART0_IRQ], 399193,
-        serial_hds[0], DEVICE_LITTLE_ENDIAN);
+        serial_hd(0), DEVICE_LITTLE_ENDIAN);
 }
 
 static int riscv_virt_board_sysbus_device_init(SysBusDevice *sysbusdev)
hw/sh4/r2d.c +1 -1
index 458ed83297..6b01d6eed8 100644
@@ -271,7 +271,7 @@ static void r2d_init(MachineState *machine)
     busdev = SYS_BUS_DEVICE(dev);
     qdev_prop_set_uint32(dev, "vram-size", SM501_VRAM_SIZE);
     qdev_prop_set_uint32(dev, "base", 0x10000000);
-    qdev_prop_set_ptr(dev, "chr-state", serial_hds[2]);
+    qdev_prop_set_ptr(dev, "chr-state", serial_hd(2));
     qdev_init_nofail(dev);
     sysbus_mmio_map(busdev, 0, 0x10000000);
     sysbus_mmio_map(busdev, 1, 0x13e00000);
hw/sh4/sh7750.c +2 -2
index 166e4bd947..5a7d47d31e 100644
@@ -773,7 +773,7 @@ SH7750State *sh7750_init(SuperHCPU *cpu, MemoryRegion *sysmem)
     cpu->env.intc_handle = &s->intc;
 
     sh_serial_init(sysmem, 0x1fe00000,
-                   0, s->periph_freq, serial_hds[0],
+                   0, s->periph_freq, serial_hd(0),
                    s->intc.irqs[SCI1_ERI],
                    s->intc.irqs[SCI1_RXI],
                    s->intc.irqs[SCI1_TXI],
@@ -781,7 +781,7 @@ SH7750State *sh7750_init(SuperHCPU *cpu, MemoryRegion *sysmem)
                    NULL);
     sh_serial_init(sysmem, 0x1fe80000,
                    SH_SERIAL_FEAT_SCIF,
-                   s->periph_freq, serial_hds[1],
+                   s->periph_freq, serial_hd(1),
                    s->intc.irqs[SCIF_ERI],
                    s->intc.irqs[SCIF_RXI],
                    s->intc.irqs[SCIF_TXI],
hw/sparc/leon3.c +2 -2
index bba3aa3dee..98fa6adae0 100644
@@ -206,8 +206,8 @@ static void leon3_generic_hw_init(MachineState *machine)
     grlib_gptimer_create(0x80000300, 2, CPU_CLK, cpu_irqs, 6);
 
     /* Allocate uart */
-    if (serial_hds[0]) {
-        grlib_apbuart_create(0x80000100, serial_hds[0], cpu_irqs[3]);
+    if (serial_hd(0)) {
+        grlib_apbuart_create(0x80000100, serial_hd(0), cpu_irqs[3]);
     }
 }
 
hw/sparc/sun4m.c +2 -2
index 6471aca25d..0ee779fafe 100644
@@ -943,8 +943,8 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
     qdev_prop_set_uint32(dev, "disabled", 0);
     qdev_prop_set_uint32(dev, "frequency", ESCC_CLOCK);
     qdev_prop_set_uint32(dev, "it_shift", 1);
-    qdev_prop_set_chr(dev, "chrB", serial_hds[1]);
-    qdev_prop_set_chr(dev, "chrA", serial_hds[0]);
+    qdev_prop_set_chr(dev, "chrB", serial_hd(1));
+    qdev_prop_set_chr(dev, "chrA", serial_hd(0));
     qdev_prop_set_uint32(dev, "chnBtype", escc_serial);
     qdev_prop_set_uint32(dev, "chnAtype", escc_serial);
     qdev_init_nofail(dev);
hw/sparc64/niagara.c +2 -2
index 1874477ef6..22c4655fde 100644
@@ -156,9 +156,9 @@ static void niagara_init(MachineState *machine)
             exit(1);
         }
     }
-    if (serial_hds[0]) {
+    if (serial_hd(0)) {
         serial_mm_init(sysmem, NIAGARA_UART_BASE, 0, NULL, 115200,
-                       serial_hds[0], DEVICE_BIG_ENDIAN);
+                       serial_hd(0), DEVICE_BIG_ENDIAN);
     }
     empty_slot_init(NIAGARA_IOBBASE, NIAGARA_IOBSIZE);
     sun4v_rtc_init(NIAGARA_RTC_BASE);
hw/sparc64/sun4u.c +1 -1
index 2044a52ded..9b441f704b 100644
@@ -295,7 +295,7 @@ static void ebus_realize(PCIDevice *pci_dev, Error **errp)
     i = 0;
     if (s->console_serial_base) {
         serial_mm_init(pci_address_space(pci_dev), s->console_serial_base,
-                       0, NULL, 115200, serial_hds[i], DEVICE_BIG_ENDIAN);
+                       0, NULL, 115200, serial_hd(i), DEVICE_BIG_ENDIAN);
         i++;
     }
     serial_hds_isa_init(s->isa_bus, i, MAX_SERIAL_PORTS);
hw/xtensa/sim.c +2 -2
index 5c0ba231d1..b6ccb3cd4a 100644
@@ -90,8 +90,8 @@ static void xtensa_sim_init(MachineState *machine)
                                      get_system_memory());
     }
 
-    if (serial_hds[0]) {
-        xtensa_sim_open_console(serial_hds[0]);
+    if (serial_hd(0)) {
+        xtensa_sim_open_console(serial_hd(0));
     }
     if (kernel_filename) {
         uint64_t elf_entry;
hw/xtensa/xtfpga.c +1 -1
index 9db99e1f7e..63734c70ec 100644
@@ -279,7 +279,7 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
     }
 
     serial_mm_init(system_io, 0x0d050020, 2, xtensa_get_extint(env, 0),
-            115200, serial_hds[0], DEVICE_NATIVE_ENDIAN);
+            115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);
 
     dinfo = drive_get(IF_PFLASH, 0, 0);
     if (dinfo) {
#24 lore raw

Re: [Qemu-devel] [PATCH 07/13] Change references to serial_hds[] to serial_hd()

Quoted 9 lines · Philippe Mathieu-Daudé

Hi Peter,

Quoted 5 lines · Peter Maydell

Change all the uses of serial_hds[] to go via the new
serial_hd() function. Code change produced with:
find hw -name '*.[ch]' | xargs sed -i -e 's/serial_hds\[\([^]]*\)\]/serial_hd(\1)/g'

Quoted 10 lines

hw/arm/mps2-tz.c static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque, · line 175

Quoted 8 lines
hw/arm/mps2-tz.c +1 -1
@@ -172,7 +172,7 @@ static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
 {
     CMSDKAPBUART *uart = opaque;
     int i = uart - &mms->uart[0];
-    Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hds[i] : NULL;
+    Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hd(i) : NULL;

You can remove uartchr and directly use serial_hd(i).

These kinds of cleanup are in later patches in the series -- this one is kept strictly to the purely-mechanical sed change, as otherwise it would be a bit awkward to review I thought.

Quoted 7 lines
Quoted 7 lines
hw/arm/msf2-soc.c +0 -0
index f68df56b97..75c44adf7d 100644
@@ -138,10 +138,10 @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp)
     system_clock_scale = NANOSECONDS_PER_SECOND / s->m3clk;
 
Quoted 11 lines

hw/arm/msf2-soc.c static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp) · line 141

Quoted 3 lines
hw/arm/msf2-soc.c +1 -1
     for (i = 0; i < MSF2_NUM_UARTS; i++) {
-        if (serial_hds[i]) {
+        if (serial_hd(i)) {

We can now remove this check, but maybe another series...

Quoted 5 lines
hw/arm/msf2-soc.c +1 -1
             serial_mm_init(get_system_memory(), uart_addr[i], 2,
                            qdev_get_gpio_in(armv7m, uart_irq[i]),
-                           115200, serial_hds[i], DEVICE_NATIVE_ENDIAN);
+                           115200, serial_hd(i), DEVICE_NATIVE_ENDIAN);
         }

I agree that's probably a good change to make, but it's also a behavioural change (we would go from only creating serial devices where -serial args are given, to always creating them). I wanted to generally avoid having any behavioural changes in this series.

Quoted 8 lines
Quoted 8 lines
hw/arm/msf2-soc.c +1 -1
@@ -3963,21 +3963,21 @@ struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *system_memory,
                     omap_findclk(s, "uart1_ck"),
                     s->drq[OMAP_DMA_UART1_TX], s->drq[OMAP_DMA_UART1_RX],
                     "uart1",
-                    serial_hds[0]);
+                    serial_hd(0));
     s->uart[1] = omap_uart_init(0xfffb0800,
                                 qdev_get_gpio_in(s->ih[1], OMAP_INT_UART2),
Quoted 8 lines

hw/arm/msf2-soc.c struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *system_memory, · line 3973

Quoted 6 lines
hw/arm/msf2-soc.c +1 -1
                     omap_findclk(s, "uart2_ck"),
                     omap_findclk(s, "uart2_ck"),
                     s->drq[OMAP_DMA_UART2_TX], s->drq[OMAP_DMA_UART2_RX],
                     "uart2",
-                    serial_hds[0] ? serial_hds[1] : NULL);
+                    serial_hd(0) ? serial_hd(1) : NULL);

This will need cleanup later...

It's a bit weird, but I don't think it's specifically wrong.

Quoted 11 lines

hw/mips/mips_mipssim.c mips_mipssim_init(MachineState *machine) · line 216

Quoted 9 lines
hw/mips/mips_mipssim.c +1 -2
@@ -213,8 +213,8 @@ mips_mipssim_init(MachineState *machine)
 
     /* A single 16450 sits at offset 0x3f8. It is attached to
        MIPS CPU INT2, which is interrupt 4. */
-    if (serial_hds[0])
-        serial_init(0x3f8, env->irq[4], 115200, serial_hds[0],
+    if (serial_hd(0))

We will drop this if () later... This now misses brackets :/

Hazard of pure-mechanical-change cleanup is that it doesn't include coding-style fixes, but it's no worse than it was before.

thanks
-- PMM

#25 lore raw

PATCH 8/13 Remove checks on MAX_SERIAL_PORTS that are just bounds checks

In reply to Peter Maydell

Remove checks on MAX_SERIAL_PORTS that were just checking whether they were within bounds for the serial_hds[] array and falling back to NULL if not. This isn't needed with the serial_hd() function, which returns NULL for all indexes beyond what the user set up.

---
 hw/arm/fsl-imx25.c     | 4 +---
 hw/arm/fsl-imx31.c     | 4 +---
 hw/arm/fsl-imx6.c      | 4 +---
 hw/arm/fsl-imx7.c      | 4 +---
 hw/arm/mps2-tz.c       | 3 +--
 hw/arm/mps2.c          | 6 ++----
 hw/arm/stm32f205_soc.c | 3 +--
 7 files changed, 8 insertions(+), 20 deletions(-)
hw/arm/fsl-imx25.c +1 -3
index 9731833fa5..37056f9e34 100644
@@ -117,9 +117,7 @@ static void fsl_imx25_realize(DeviceState *dev, Error **errp)
             { FSL_IMX25_UART5_ADDR, FSL_IMX25_UART5_IRQ }
         };
 
-        if (i < MAX_SERIAL_PORTS) {
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
-        }
+        qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);
         if (err) {
hw/arm/fsl-imx31.c +1 -3
index 8509915200..891850cf18 100644
@@ -106,9 +106,7 @@ static void fsl_imx31_realize(DeviceState *dev, Error **errp)
             { FSL_IMX31_UART2_ADDR, FSL_IMX31_UART2_IRQ },
         };
 
-        if (i < MAX_SERIAL_PORTS) {
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
-        }
+        qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);
         if (err) {
hw/arm/fsl-imx6.c +1 -3
index 535ad5888b..4f51bd9eb5 100644
@@ -188,9 +188,7 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp)
             { FSL_IMX6_UART5_ADDR, FSL_IMX6_UART5_IRQ },
         };
 
-        if (i < MAX_SERIAL_PORTS) {
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
-        }
+        qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);
         if (err) {
hw/arm/fsl-imx7.c +1 -3
index 2848d76d3c..26c1d27f7c 100644
@@ -390,9 +390,7 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
         };
 
 
-        if (i < MAX_SERIAL_PORTS) {
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
-        }
+        qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized",
                                  &error_abort);
hw/arm/mps2-tz.c +1 -2
index 4ae4a5cb2a..8dc8bfd4ab 100644
@@ -172,7 +172,6 @@ static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
 {
     CMSDKAPBUART *uart = opaque;
     int i = uart - &mms->uart[0];
-    Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hd(i) : NULL;
     int rxirqno = i * 2;
     int txirqno = i * 2 + 1;
     int combirqno = i + 10;
@@ -182,7 +181,7 @@ static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
 
     init_sysbus_child(OBJECT(mms), name, uart,
                       sizeof(mms->uart[0]), TYPE_CMSDK_APB_UART);
-    qdev_prop_set_chr(DEVICE(uart), "chardev", uartchr);
+    qdev_prop_set_chr(DEVICE(uart), "chardev", serial_hd(i));
     qdev_prop_set_uint32(DEVICE(uart), "pclk-frq", SYSCLK_FRQ);
     object_property_set_bool(OBJECT(uart), true, "realized", &error_fatal);
     s = SYS_BUS_DEVICE(uart);
hw/arm/mps2.c +2 -4
index eb550fad34..c3946da317 100644
@@ -230,7 +230,6 @@ static void mps2_common_init(MachineState *machine)
             static const hwaddr uartbase[] = {0x40004000, 0x40005000,
                                               0x40006000, 0x40007000,
                                               0x40009000};
-            Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hd(i) : NULL;
             /* RX irq number; TX irq is always one greater */
             static const int uartirq[] = {0, 2, 4, 18, 20};
             qemu_irq txovrint = NULL, rxovrint = NULL;
@@ -245,7 +244,7 @@ static void mps2_common_init(MachineState *machine)
                                   qdev_get_gpio_in(armv7m, uartirq[i]),
                                   txovrint, rxovrint,
                                   NULL,
-                                  uartchr, SYSCLK_FRQ);
+                                  serial_hd(i), SYSCLK_FRQ);
         }
         break;
     }
@@ -270,7 +269,6 @@ static void mps2_common_init(MachineState *machine)
             static const hwaddr uartbase[] = {0x40004000, 0x40005000,
                                               0x4002c000, 0x4002d000,
                                               0x4002e000};
-            Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hd(i) : NULL;
             Object *txrx_orgate;
             DeviceState *txrx_orgate_dev;
 
@@ -287,7 +285,7 @@ static void mps2_common_init(MachineState *machine)
                                   qdev_get_gpio_in(orgate_dev, i * 2),
                                   qdev_get_gpio_in(orgate_dev, i * 2 + 1),
                                   NULL,
-                                  uartchr, SYSCLK_FRQ);
+                                  serial_hd(i), SYSCLK_FRQ);
         }
         break;
     }
hw/arm/stm32f205_soc.c +1 -2
index f59418e7d0..2b2135d382 100644
@@ -135,8 +135,7 @@ static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp)
     /* Attach UART (uses USART registers) and USART controllers */
     for (i = 0; i < STM_NUM_USARTS; i++) {
         dev = DEVICE(&(s->usart[i]));
-        qdev_prop_set_chr(dev, "chardev",
-                          i < MAX_SERIAL_PORTS ? serial_hd(i) : NULL);
+        qdev_prop_set_chr(dev, "chardev", serial_hd(i));
         object_property_set_bool(OBJECT(&s->usart[i]), true, "realized", &err);
         if (err != NULL) {
             error_propagate(errp, err);
Signature · 1 line
2.17.0
Reviewed-by on v1 8/13
#26 lore raw

Re: [Qemu-devel] [PATCH 08/13] Remove checks on MAX_SERIAL_PORTS that are just bounds checks

Quoted 7 lines · Peter Maydell

Remove checks on MAX_SERIAL_PORTS that were just checking whether they were within bounds for the serial_hds[] array and falling back to NULL if not. This isn't needed with the serial_hd() function, which returns NULL for all indexes beyond what the user set up.

Quoted 9 lines
---
 hw/arm/fsl-imx25.c     | 4 +---
 hw/arm/fsl-imx31.c     | 4 +---
 hw/arm/fsl-imx6.c      | 4 +---
 hw/arm/fsl-imx7.c      | 4 +---
 hw/arm/mps2-tz.c       | 3 +--
 hw/arm/mps2.c          | 6 ++----
 hw/arm/stm32f205_soc.c | 3 +--
 7 files changed, 8 insertions(+), 20 deletions(-)
Reviewed-by on v1 8/13
#27 lore raw

Re: [Qemu-devel] [PATCH 08/13] Remove checks on MAX_SERIAL_PORTS that are just bounds checks

In reply to Peter Maydell
Quoted 82 lines · Peter Maydell

Remove checks on MAX_SERIAL_PORTS that were just checking whether they were within bounds for the serial_hds[] array and falling back to NULL if not. This isn't needed with the serial_hd() function, which returns NULL for all indexes beyond what the user set up.

---
 hw/arm/fsl-imx25.c     | 4 +---
 hw/arm/fsl-imx31.c     | 4 +---
 hw/arm/fsl-imx6.c      | 4 +---
 hw/arm/fsl-imx7.c      | 4 +---
 hw/arm/mps2-tz.c       | 3 +--
 hw/arm/mps2.c          | 6 ++----
 hw/arm/stm32f205_soc.c | 3 +--
 7 files changed, 8 insertions(+), 20 deletions(-)
hw/arm/fsl-imx25.c +1 -3
index 9731833fa5..37056f9e34 100644
@@ -117,9 +117,7 @@ static void fsl_imx25_realize(DeviceState *dev, Error **errp)
             { FSL_IMX25_UART5_ADDR, FSL_IMX25_UART5_IRQ }
         };
 
-        if (i < MAX_SERIAL_PORTS) {
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
-        }
+        qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);
         if (err) {
hw/arm/fsl-imx31.c +1 -3
index 8509915200..891850cf18 100644
@@ -106,9 +106,7 @@ static void fsl_imx31_realize(DeviceState *dev, Error **errp)
             { FSL_IMX31_UART2_ADDR, FSL_IMX31_UART2_IRQ },
         };
 
-        if (i < MAX_SERIAL_PORTS) {
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
-        }
+        qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);
         if (err) {
hw/arm/fsl-imx6.c +1 -3
index 535ad5888b..4f51bd9eb5 100644
@@ -188,9 +188,7 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp)
             { FSL_IMX6_UART5_ADDR, FSL_IMX6_UART5_IRQ },
         };
 
-        if (i < MAX_SERIAL_PORTS) {
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
-        }
+        qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);
         if (err) {
hw/arm/fsl-imx7.c +1 -3
index 2848d76d3c..26c1d27f7c 100644
@@ -390,9 +390,7 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
         };
 
 
-        if (i < MAX_SERIAL_PORTS) {
-            qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
-        }
+        qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
 
         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized",
                                  &error_abort);
hw/arm/mps2-tz.c +0 -0
index 4ae4a5cb2a..8dc8bfd4ab 100644

hw/arm/mps2-tz.c static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque, · line 175

Quoted 4 lines
hw/arm/mps2-tz.c +0 -1
@@ -172,7 +172,6 @@ static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
 {
     CMSDKAPBUART *uart = opaque;
     int i = uart - &mms->uart[0];
-    Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hd(i) : NULL;

Oh you cleaned this :) So disregard my comment in patch 7/13 of this series.

Quoted 65 lines
hw/arm/mps2-tz.c +1 -1
     int rxirqno = i * 2;
     int txirqno = i * 2 + 1;
     int combirqno = i + 10;
@@ -182,7 +181,7 @@ static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
 
     init_sysbus_child(OBJECT(mms), name, uart,
                       sizeof(mms->uart[0]), TYPE_CMSDK_APB_UART);
-    qdev_prop_set_chr(DEVICE(uart), "chardev", uartchr);
+    qdev_prop_set_chr(DEVICE(uart), "chardev", serial_hd(i));
     qdev_prop_set_uint32(DEVICE(uart), "pclk-frq", SYSCLK_FRQ);
     object_property_set_bool(OBJECT(uart), true, "realized", &error_fatal);
     s = SYS_BUS_DEVICE(uart);
hw/arm/mps2.c +2 -4
index eb550fad34..c3946da317 100644
@@ -230,7 +230,6 @@ static void mps2_common_init(MachineState *machine)
             static const hwaddr uartbase[] = {0x40004000, 0x40005000,
                                               0x40006000, 0x40007000,
                                               0x40009000};
-            Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hd(i) : NULL;
             /* RX irq number; TX irq is always one greater */
             static const int uartirq[] = {0, 2, 4, 18, 20};
             qemu_irq txovrint = NULL, rxovrint = NULL;
@@ -245,7 +244,7 @@ static void mps2_common_init(MachineState *machine)
                                   qdev_get_gpio_in(armv7m, uartirq[i]),
                                   txovrint, rxovrint,
                                   NULL,
-                                  uartchr, SYSCLK_FRQ);
+                                  serial_hd(i), SYSCLK_FRQ);
         }
         break;
     }
@@ -270,7 +269,6 @@ static void mps2_common_init(MachineState *machine)
             static const hwaddr uartbase[] = {0x40004000, 0x40005000,
                                               0x4002c000, 0x4002d000,
                                               0x4002e000};
-            Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hd(i) : NULL;
             Object *txrx_orgate;
             DeviceState *txrx_orgate_dev;
 
@@ -287,7 +285,7 @@ static void mps2_common_init(MachineState *machine)
                                   qdev_get_gpio_in(orgate_dev, i * 2),
                                   qdev_get_gpio_in(orgate_dev, i * 2 + 1),
                                   NULL,
-                                  uartchr, SYSCLK_FRQ);
+                                  serial_hd(i), SYSCLK_FRQ);
         }
         break;
     }
hw/arm/stm32f205_soc.c +1 -2
index f59418e7d0..2b2135d382 100644
@@ -135,8 +135,7 @@ static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp)
     /* Attach UART (uses USART registers) and USART controllers */
     for (i = 0; i < STM_NUM_USARTS; i++) {
         dev = DEVICE(&(s->usart[i]));
-        qdev_prop_set_chr(dev, "chardev",
-                          i < MAX_SERIAL_PORTS ? serial_hd(i) : NULL);
+        qdev_prop_set_chr(dev, "chardev", serial_hd(i));
         object_property_set_bool(OBJECT(&s->usart[i]), true, "realized", &err);
         if (err != NULL) {
             error_propagate(errp, err);
#28 lore raw

PATCH 9/13 hw/char/exynos4210_uart.c: Remove unneeded handling of NULL chardev

In reply to Peter Maydell

The handling of NULL chardevs in exynos4210_uart_create() is now all unnecessary: we don't need to create 'null' chardevs, and we don't need to enforce a bounds check on serial_hd().

---
 hw/char/exynos4210_uart.c | 20 --------------------
 1 file changed, 20 deletions(-)
hw/char/exynos4210_uart.c +0 -20
index c2bba03362..a5a285655f 100644
@@ -589,28 +589,8 @@ DeviceState *exynos4210_uart_create(hwaddr addr,
     DeviceState  *dev;
     SysBusDevice *bus;
 
-    const char chr_name[] = "serial";
-    char label[ARRAY_SIZE(chr_name) + 1];
-
     dev = qdev_create(NULL, TYPE_EXYNOS4210_UART);
 
-    if (!chr) {
-        if (channel >= MAX_SERIAL_PORTS) {
-            error_report("Only %d serial ports are supported by QEMU",
-                         MAX_SERIAL_PORTS);
-            exit(1);
-        }
-        chr = serial_hd(channel);
-        if (!chr) {
-            snprintf(label, ARRAY_SIZE(label), "%s%d", chr_name, channel);
-            chr = qemu_chr_new(label, "null");
-            if (!(chr)) {
-                error_report("Can't assign serial port to UART%d", channel);
-                exit(1);
-            }
-        }
-    }
-
     qdev_prop_set_chr(dev, "chardev", chr);
     qdev_prop_set_uint32(dev, "channel", channel);
     qdev_prop_set_uint32(dev, "rx-size", fifo_size);
Signature · 1 line
2.17.0
Reviewed-by on v1 9/13
#29 lore raw

Re: [Qemu-devel] [PATCH 09/13] hw/char/exynos4210_uart.c: Remove unneeded handling of NULL chardev

Quoted 5 lines · Peter Maydell

The handling of NULL chardevs in exynos4210_uart_create() is now all unnecessary: we don't need to create 'null' chardevs, and we don't need to enforce a bounds check on serial_hd().

Quoted 38 lines
---
 hw/char/exynos4210_uart.c | 20 --------------------
 1 file changed, 20 deletions(-)
hw/char/exynos4210_uart.c +0 -20
index c2bba03362..a5a285655f 100644
@@ -589,28 +589,8 @@ DeviceState *exynos4210_uart_create(hwaddr addr,
     DeviceState  *dev;
     SysBusDevice *bus;
 
-    const char chr_name[] = "serial";
-    char label[ARRAY_SIZE(chr_name) + 1];
-
     dev = qdev_create(NULL, TYPE_EXYNOS4210_UART);
 
-    if (!chr) {
-        if (channel >= MAX_SERIAL_PORTS) {
-            error_report("Only %d serial ports are supported by QEMU",
-                         MAX_SERIAL_PORTS);
-            exit(1);
-        }
-        chr = serial_hd(channel);
-        if (!chr) {
-            snprintf(label, ARRAY_SIZE(label), "%s%d", chr_name, channel);
-            chr = qemu_chr_new(label, "null");
-            if (!(chr)) {
-                error_report("Can't assign serial port to UART%d", channel);
-                exit(1);
-            }
-        }
-    }
-
     qdev_prop_set_chr(dev, "chardev", chr);
     qdev_prop_set_uint32(dev, "channel", channel);
     qdev_prop_set_uint32(dev, "rx-size", fifo_size);
Reviewed-by on v1 9/13
#30 lore raw

Re: [Qemu-devel] [PATCH 09/13] hw/char/exynos4210_uart.c: Remove unneeded handling of NULL chardev

In reply to Peter Maydell
Quoted 18 lines · Peter Maydell

The handling of NULL chardevs in exynos4210_uart_create() is now all unnecessary: we don't need to create 'null' chardevs, and we don't need to enforce a bounds check on serial_hd().

---
 hw/char/exynos4210_uart.c | 20 --------------------
 1 file changed, 20 deletions(-)
hw/char/exynos4210_uart.c +0 -1
index c2bba03362..a5a285655f 100644
@@ -589,28 +589,8 @@ DeviceState *exynos4210_uart_create(hwaddr addr,
     DeviceState  *dev;
     SysBusDevice *bus;
 
-    const char chr_name[] = "serial";

hw/char/exynos4210_uart.c DeviceState *exynos4210_uart_create(hwaddr addr, · line 602

Quoted 10 lines
hw/char/exynos4210_uart.c +0 -8
-    char label[ARRAY_SIZE(chr_name) + 1];
-
     dev = qdev_create(NULL, TYPE_EXYNOS4210_UART);
 
-    if (!chr) {
-        if (channel >= MAX_SERIAL_PORTS) {
-            error_report("Only %d serial ports are supported by QEMU",
-                         MAX_SERIAL_PORTS);
-            exit(1);
-        }

If I get the EXYNOS 4210 data sheet right, this chip has only 4 channels indeed:

http://www.samsung.com/global/business/semiconductor/file/product/Exynos_4_Dual_45nm_User_Manaul_Public_REV1.00-0.pdf

So I think you should at least keep an "assert(channel < 4)" in here?

Apart from that, the patch looks sane to me, so when you add that assert():

#31 lore raw

Re: [Qemu-devel] [PATCH 09/13] hw/char/exynos4210_uart.c: Remove unneeded handling of NULL chardev

Hi Thomas,

Quoted 33 lines · Thomas Huth
Quoted 18 lines · Peter Maydell

The handling of NULL chardevs in exynos4210_uart_create() is now all unnecessary: we don't need to create 'null' chardevs, and we don't need to enforce a bounds check on serial_hd().

---
 hw/char/exynos4210_uart.c | 20 --------------------
 1 file changed, 20 deletions(-)
hw/char/exynos4210_uart.c +0 -1
index c2bba03362..a5a285655f 100644
@@ -589,28 +589,8 @@ DeviceState *exynos4210_uart_create(hwaddr addr,
     DeviceState  *dev;
     SysBusDevice *bus;
 
-    const char chr_name[] = "serial";

hw/char/exynos4210_uart.c DeviceState *exynos4210_uart_create(hwaddr addr, · line 602

Quoted 10 lines
hw/char/exynos4210_uart.c +0 -8
-    char label[ARRAY_SIZE(chr_name) + 1];
-
     dev = qdev_create(NULL, TYPE_EXYNOS4210_UART);
 
-    if (!chr) {
-        if (channel >= MAX_SERIAL_PORTS) {
-            error_report("Only %d serial ports are supported by QEMU",
-                         MAX_SERIAL_PORTS);
-            exit(1);
-        }

If I get the EXYNOS 4210 data sheet right, this chip has only 4 channels indeed:

Quoted 3 lines

http://www.samsung.com/global/business/semiconductor/file/product/Exynos_4_Dual_45nm_User_Manaul_Public_REV1.00-0.pdf

So I think you should at least keep an "assert(channel < 4)" in here?

This file models a single UART, I don't think a such assert belongs here.

Although it is named EXYNOS4210, I'm pretty sure it should works to model UARTs from other SoCs from the Exynos4xxx series.

There are no restriction on newer SoCs to have > 4 UARTs.

For this particular Exynos4210 SoC, the 4 channels are correctly limited in exynos4210_init().

Regards,

Phil.

Quoted 4 lines

Apart from that, the patch looks sane to me, so when you add that assert():

#32 lore raw

PATCH 10/13 serial-isa: Use MAX_ISA_SERIAL_PORTS instead of MAX_SERIAL_PORTS

In reply to Peter Maydell

The ISA serial port handling in serial-isa.c imposes a limit of 4 serial ports. This is because we only know of 4 IO port and IRQ settings for them, and is unrelated to the generic MAX_SERIAL_PORTS limit, though they happen to both be set at 4 currently.

Use a new MAX_ISA_SERIAL_PORTS wherever that is the correct limit to be checking against.

---
 include/hw/char/serial.h |  3 +++
 hw/char/serial-isa.c     | 10 +++++-----
 hw/i386/pc.c             |  2 +-
 hw/mips/mips_r4k.c       |  2 +-
 hw/ppc/pnv.c             |  2 +-
 hw/sparc64/sun4u.c       |  2 +-
 6 files changed, 12 insertions(+), 9 deletions(-)
include/hw/char/serial.h +3 -0
index c4daf11a14..0acfbbc382 100644
@@ -95,6 +95,9 @@ SerialState *serial_mm_init(MemoryRegion *address_space,
                             Chardev *chr, enum device_endian end);
 
 /* serial-isa.c */
+
+#define MAX_ISA_SERIAL_PORTS 4
+
 #define TYPE_ISA_SERIAL "isa-serial"
 void serial_hds_isa_init(ISABus *bus, int from, int to);
 
hw/char/serial-isa.c +5 -5
index eb5996159d..116b7b2e69 100644
@@ -39,10 +39,10 @@ typedef struct ISASerialState {
     SerialState state;
 } ISASerialState;
 
-static const int isa_serial_io[MAX_SERIAL_PORTS] = {
+static const int isa_serial_io[MAX_ISA_SERIAL_PORTS] = {
     0x3f8, 0x2f8, 0x3e8, 0x2e8
 };
-static const int isa_serial_irq[MAX_SERIAL_PORTS] = {
+static const int isa_serial_irq[MAX_ISA_SERIAL_PORTS] = {
     4, 3, 4, 3
 };
 
@@ -56,9 +56,9 @@ static void serial_isa_realizefn(DeviceState *dev, Error **errp)
     if (isa->index == -1) {
         isa->index = index;
     }
-    if (isa->index >= MAX_SERIAL_PORTS) {
+    if (isa->index >= MAX_ISA_SERIAL_PORTS) {
         error_setg(errp, "Max. supported number of ISA serial ports is %d.",
-                   MAX_SERIAL_PORTS);
+                   MAX_ISA_SERIAL_PORTS);
         return;
     }
     if (isa->iobase == -1) {
@@ -138,7 +138,7 @@ void serial_hds_isa_init(ISABus *bus, int from, int to)
     int i;
 
     assert(from >= 0);
-    assert(to <= MAX_SERIAL_PORTS);
+    assert(to <= MAX_ISA_SERIAL_PORTS);
 
     for (i = from; i < to; ++i) {
         if (serial_hd(i)) {
hw/i386/pc.c +1 -1
index d36bac8c89..b297a5d63b 100644
@@ -1524,7 +1524,7 @@ static void pc_superio_init(ISABus *isa_bus, bool create_fdctrl, bool no_vmport)
     qemu_irq *a20_line;
     ISADevice *i8042, *port92, *vmmouse;
 
-    serial_hds_isa_init(isa_bus, 0, MAX_SERIAL_PORTS);
+    serial_hds_isa_init(isa_bus, 0, MAX_ISA_SERIAL_PORTS);
     parallel_hds_isa_init(isa_bus, MAX_PARALLEL_PORTS);
 
     for (i = 0; i < MAX_FD; i++) {
hw/mips/mips_r4k.c +1 -1
index aeadc4a340..e04b49d3c5 100644
@@ -274,7 +274,7 @@ void mips_r4k_init(MachineState *machine)
 
     pit = i8254_pit_init(isa_bus, 0x40, 0, NULL);
 
-    serial_hds_isa_init(isa_bus, 0, MAX_SERIAL_PORTS);
+    serial_hds_isa_init(isa_bus, 0, MAX_ISA_SERIAL_PORTS);
 
     isa_vga_init(isa_bus);
 
hw/ppc/pnv.c +1 -1
index 98ee3c607a..549cfccdcb 100644
@@ -648,7 +648,7 @@ static void pnv_init(MachineState *machine)
     pnv->isa_bus = pnv_isa_create(pnv->chips[0]);
 
     /* Create serial port */
-    serial_hds_isa_init(pnv->isa_bus, 0, MAX_SERIAL_PORTS);
+    serial_hds_isa_init(pnv->isa_bus, 0, MAX_ISA_SERIAL_PORTS);
 
     /* Create an RTC ISA device too */
     mc146818_rtc_init(pnv->isa_bus, 2000, NULL);
hw/sparc64/sun4u.c +1 -1
index 9b441f704b..1bede85370 100644
@@ -298,7 +298,7 @@ static void ebus_realize(PCIDevice *pci_dev, Error **errp)
                        0, NULL, 115200, serial_hd(i), DEVICE_BIG_ENDIAN);
         i++;
     }
-    serial_hds_isa_init(s->isa_bus, i, MAX_SERIAL_PORTS);
+    serial_hds_isa_init(s->isa_bus, i, MAX_ISA_SERIAL_PORTS);
 
     /* Parallel ports */
     parallel_hds_isa_init(s->isa_bus, MAX_PARALLEL_PORTS);
Signature · 1 line
2.17.0
Reviewed-by Tested-by on v1 10/13
#33 lore raw

Re: [Qemu-devel] [PATCH 10/13] serial-isa: Use MAX_ISA_SERIAL_PORTS instead of MAX_SERIAL_PORTS

Quoted 10 lines · Peter Maydell

The ISA serial port handling in serial-isa.c imposes a limit of 4 serial ports. This is because we only know of 4 IO port and IRQ settings for them, and is unrelated to the generic MAX_SERIAL_PORTS limit, though they happen to both be set at 4 currently.

Use a new MAX_ISA_SERIAL_PORTS wherever that is the correct limit to be checking against.

Except PNV:

Quoted 114 lines
---
 include/hw/char/serial.h |  3 +++
 hw/char/serial-isa.c     | 10 +++++-----
 hw/i386/pc.c             |  2 +-
 hw/mips/mips_r4k.c       |  2 +-
 hw/ppc/pnv.c             |  2 +-
 hw/sparc64/sun4u.c       |  2 +-
 6 files changed, 12 insertions(+), 9 deletions(-)
include/hw/char/serial.h +3 -0
index c4daf11a14..0acfbbc382 100644
@@ -95,6 +95,9 @@ SerialState *serial_mm_init(MemoryRegion *address_space,
                             Chardev *chr, enum device_endian end);
 
 /* serial-isa.c */
+
+#define MAX_ISA_SERIAL_PORTS 4
+
 #define TYPE_ISA_SERIAL "isa-serial"
 void serial_hds_isa_init(ISABus *bus, int from, int to);
 
hw/char/serial-isa.c +5 -5
index eb5996159d..116b7b2e69 100644
@@ -39,10 +39,10 @@ typedef struct ISASerialState {
     SerialState state;
 } ISASerialState;
 
-static const int isa_serial_io[MAX_SERIAL_PORTS] = {
+static const int isa_serial_io[MAX_ISA_SERIAL_PORTS] = {
     0x3f8, 0x2f8, 0x3e8, 0x2e8
 };
-static const int isa_serial_irq[MAX_SERIAL_PORTS] = {
+static const int isa_serial_irq[MAX_ISA_SERIAL_PORTS] = {
     4, 3, 4, 3
 };
 
@@ -56,9 +56,9 @@ static void serial_isa_realizefn(DeviceState *dev, Error **errp)
     if (isa->index == -1) {
         isa->index = index;
     }
-    if (isa->index >= MAX_SERIAL_PORTS) {
+    if (isa->index >= MAX_ISA_SERIAL_PORTS) {
         error_setg(errp, "Max. supported number of ISA serial ports is %d.",
-                   MAX_SERIAL_PORTS);
+                   MAX_ISA_SERIAL_PORTS);
         return;
     }
     if (isa->iobase == -1) {
@@ -138,7 +138,7 @@ void serial_hds_isa_init(ISABus *bus, int from, int to)
     int i;
 
     assert(from >= 0);
-    assert(to <= MAX_SERIAL_PORTS);
+    assert(to <= MAX_ISA_SERIAL_PORTS);
 
     for (i = from; i < to; ++i) {
         if (serial_hd(i)) {
hw/i386/pc.c +1 -1
index d36bac8c89..b297a5d63b 100644
@@ -1524,7 +1524,7 @@ static void pc_superio_init(ISABus *isa_bus, bool create_fdctrl, bool no_vmport)
     qemu_irq *a20_line;
     ISADevice *i8042, *port92, *vmmouse;
 
-    serial_hds_isa_init(isa_bus, 0, MAX_SERIAL_PORTS);
+    serial_hds_isa_init(isa_bus, 0, MAX_ISA_SERIAL_PORTS);
     parallel_hds_isa_init(isa_bus, MAX_PARALLEL_PORTS);
 
     for (i = 0; i < MAX_FD; i++) {
hw/mips/mips_r4k.c +1 -1
index aeadc4a340..e04b49d3c5 100644
@@ -274,7 +274,7 @@ void mips_r4k_init(MachineState *machine)
 
     pit = i8254_pit_init(isa_bus, 0x40, 0, NULL);
 
-    serial_hds_isa_init(isa_bus, 0, MAX_SERIAL_PORTS);
+    serial_hds_isa_init(isa_bus, 0, MAX_ISA_SERIAL_PORTS);
 
     isa_vga_init(isa_bus);
 
hw/ppc/pnv.c +1 -1
index 98ee3c607a..549cfccdcb 100644
@@ -648,7 +648,7 @@ static void pnv_init(MachineState *machine)
     pnv->isa_bus = pnv_isa_create(pnv->chips[0]);
 
     /* Create serial port */
-    serial_hds_isa_init(pnv->isa_bus, 0, MAX_SERIAL_PORTS);
+    serial_hds_isa_init(pnv->isa_bus, 0, MAX_ISA_SERIAL_PORTS);
 
     /* Create an RTC ISA device too */
     mc146818_rtc_init(pnv->isa_bus, 2000, NULL);
hw/sparc64/sun4u.c +1 -1
index 9b441f704b..1bede85370 100644
@@ -298,7 +298,7 @@ static void ebus_realize(PCIDevice *pci_dev, Error **errp)
                        0, NULL, 115200, serial_hd(i), DEVICE_BIG_ENDIAN);
         i++;
     }
-    serial_hds_isa_init(s->isa_bus, i, MAX_SERIAL_PORTS);
+    serial_hds_isa_init(s->isa_bus, i, MAX_ISA_SERIAL_PORTS);
 
     /* Parallel ports */
     parallel_hds_isa_init(s->isa_bus, MAX_PARALLEL_PORTS);
Reviewed-by on v1 10/13
#34 lore raw

Re: [Qemu-devel] [PATCH 10/13] serial-isa: Use MAX_ISA_SERIAL_PORTS instead of MAX_SERIAL_PORTS

In reply to Peter Maydell
Quoted 10 lines · Peter Maydell

The ISA serial port handling in serial-isa.c imposes a limit of 4 serial ports. This is because we only know of 4 IO port and IRQ settings for them, and is unrelated to the generic MAX_SERIAL_PORTS limit, though they happen to both be set at 4 currently.

Use a new MAX_ISA_SERIAL_PORTS wherever that is the correct limit to be checking against.

Quoted 8 lines
---
 include/hw/char/serial.h |  3 +++
 hw/char/serial-isa.c     | 10 +++++-----
 hw/i386/pc.c             |  2 +-
 hw/mips/mips_r4k.c       |  2 +-
 hw/ppc/pnv.c             |  2 +-
 hw/sparc64/sun4u.c       |  2 +-
 6 files changed, 12 insertions(+), 9 deletions(-)
#35 lore raw

PATCH 11/13 superio: Don't use MAX_SERIAL_PORTS for serial port limit

In reply to Peter Maydell

The superio device has a limit on the number of serial ports it supports which is really only there because it has a fixed-size array serial[]. This limit isn't related particularly to the global MAX_SERIAL_PORTS limit, so use a different #define for it.

(In practice the users of superio only ever want 2 serial ports.)

---
 include/hw/isa/superio.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
include/hw/isa/superio.h +3 -1
index f9ba29aa30..345f006081 100644
@@ -22,13 +22,15 @@
 #define ISA_SUPERIO_CLASS(klass) \
     OBJECT_CLASS_CHECK(ISASuperIOClass, (klass), TYPE_ISA_SUPERIO)
 
+#define SUPERIO_MAX_SERIAL_PORTS 4
+
 typedef struct ISASuperIODevice {
     /*< private >*/
     ISADevice parent_obj;
     /*< public >*/
 
     ISADevice *parallel[MAX_PARALLEL_PORTS];
-    ISADevice *serial[MAX_SERIAL_PORTS];
+    ISADevice *serial[SUPERIO_MAX_SERIAL_PORTS];
     ISADevice *floppy;
     ISADevice *kbc;
     ISADevice *ide;
Signature · 1 line
2.17.0
Reviewed-by Tested-by on v1 11/13
#36 lore raw

Re: [Qemu-devel] [PATCH 11/13] superio: Don't use MAX_SERIAL_PORTS for serial port limit

Quoted 7 lines · Peter Maydell

The superio device has a limit on the number of serial ports it supports which is really only there because it has a fixed-size array serial[]. This limit isn't related particularly to the global MAX_SERIAL_PORTS limit, so use a different #define for it.

(In practice the users of superio only ever want 2 serial ports.)

The F81866A and IT8783 have 6 uarts :)

For this reason I'd prefer to dynamically allocate ISASuperIODevice->serial, I might add that later on top of your series.

Quoted 1 line
Quoted 26 lines
---
 include/hw/isa/superio.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
include/hw/isa/superio.h +3 -1
index f9ba29aa30..345f006081 100644
@@ -22,13 +22,15 @@
 #define ISA_SUPERIO_CLASS(klass) \
     OBJECT_CLASS_CHECK(ISASuperIOClass, (klass), TYPE_ISA_SUPERIO)
 
+#define SUPERIO_MAX_SERIAL_PORTS 4
+
 typedef struct ISASuperIODevice {
     /*< private >*/
     ISADevice parent_obj;
     /*< public >*/
 
     ISADevice *parallel[MAX_PARALLEL_PORTS];
-    ISADevice *serial[MAX_SERIAL_PORTS];
+    ISADevice *serial[SUPERIO_MAX_SERIAL_PORTS];
     ISADevice *floppy;
     ISADevice *kbc;
     ISADevice *ide;
#37 lore raw

PATCH 12/13 vl.c: Remove compile time limit on number of serial ports

In reply to Peter Maydell

Instead of having a fixed sized global serial_hds[] array, use a local dynamically reallocated one, so we don't have a compile time limit on how many serial ports a system has.

---
 include/sysemu/sysemu.h |  2 --
 vl.c                    | 15 +++++++--------
 2 files changed, 7 insertions(+), 10 deletions(-)
include/sysemu/sysemu.h +0 -2
index bd5b55c514..989cbc2b7b 100644
@@ -161,8 +161,6 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict);
 
 #define MAX_SERIAL_PORTS 4
 
-extern Chardev *serial_hds[MAX_SERIAL_PORTS];
-
 /* Return the Chardev for serial port i, or NULL if none */
 Chardev *serial_hd(int i);
 
vl.c +7 -8
index 6daf026da6..a8a98c5a37 100644
@@ -154,7 +154,8 @@ QEMUClockType rtc_clock;
 int vga_interface_type = VGA_NONE;
 static DisplayOptions dpy;
 int no_frame;
-Chardev *serial_hds[MAX_SERIAL_PORTS];
+static int num_serial_hds = 0;
+static Chardev **serial_hds = NULL;
 Chardev *parallel_hds[MAX_PARALLEL_PORTS];
 Chardev *virtcon_hds[MAX_VIRTIO_CONSOLES];
 Chardev *sclp_hds[MAX_SCLP_CONSOLES];
@@ -2496,30 +2497,28 @@ static int foreach_device_config(int type, int (*func)(const char *cmdline))
 
 static int serial_parse(const char *devname)
 {
-    static int index = 0;
+    int index = num_serial_hds;
     char label[32];
 
     if (strcmp(devname, "none") == 0)
         return 0;
-    if (index == MAX_SERIAL_PORTS) {
-        error_report("too many serial ports");
-        exit(1);
-    }
     snprintf(label, sizeof(label), "serial%d", index);
+    serial_hds = g_renew(Chardev *, serial_hds, index + 1);
+
     serial_hds[index] = qemu_chr_new(label, devname);
     if (!serial_hds[index]) {
         error_report("could not connect serial device"
                      " to character backend '%s'", devname);
         return -1;
     }
-    index++;
+    num_serial_hds++;
     return 0;
 }
 
 Chardev *serial_hd(int i)
 {
     assert(i >= 0);
-    if (i < ARRAY_SIZE(serial_hds)) {
+    if (i < num_serial_hds) {
         return serial_hds[i];
     }
     return NULL;
Signature · 1 line
2.17.0
#38 lore raw

Re: [Qemu-devel] [PATCH 12/13] vl.c: Remove compile time limit on number of serial ports

Quoted 5 lines · Peter Maydell

Instead of having a fixed sized global serial_hds[] array, use a local dynamically reallocated one, so we don't have a compile time limit on how many serial ports a system has.

Just one question, would it make sense to use a GPtrArray instead?

Thanks,

Paolo

Quoted 69 lines
---
 include/sysemu/sysemu.h |  2 --
 vl.c                    | 15 +++++++--------
 2 files changed, 7 insertions(+), 10 deletions(-)
include/sysemu/sysemu.h +0 -2
index bd5b55c514..989cbc2b7b 100644
@@ -161,8 +161,6 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict);
 
 #define MAX_SERIAL_PORTS 4
 
-extern Chardev *serial_hds[MAX_SERIAL_PORTS];
-
 /* Return the Chardev for serial port i, or NULL if none */
 Chardev *serial_hd(int i);
 
vl.c +7 -8
index 6daf026da6..a8a98c5a37 100644
@@ -154,7 +154,8 @@ QEMUClockType rtc_clock;
 int vga_interface_type = VGA_NONE;
 static DisplayOptions dpy;
 int no_frame;
-Chardev *serial_hds[MAX_SERIAL_PORTS];
+static int num_serial_hds = 0;
+static Chardev **serial_hds = NULL;
 Chardev *parallel_hds[MAX_PARALLEL_PORTS];
 Chardev *virtcon_hds[MAX_VIRTIO_CONSOLES];
 Chardev *sclp_hds[MAX_SCLP_CONSOLES];
@@ -2496,30 +2497,28 @@ static int foreach_device_config(int type, int (*func)(const char *cmdline))
 
 static int serial_parse(const char *devname)
 {
-    static int index = 0;
+    int index = num_serial_hds;
     char label[32];
 
     if (strcmp(devname, "none") == 0)
         return 0;
-    if (index == MAX_SERIAL_PORTS) {
-        error_report("too many serial ports");
-        exit(1);
-    }
     snprintf(label, sizeof(label), "serial%d", index);
+    serial_hds = g_renew(Chardev *, serial_hds, index + 1);
+
     serial_hds[index] = qemu_chr_new(label, devname);
     if (!serial_hds[index]) {
         error_report("could not connect serial device"
                      " to character backend '%s'", devname);
         return -1;
     }
-    index++;
+    num_serial_hds++;
     return 0;
 }
 
 Chardev *serial_hd(int i)
 {
     assert(i >= 0);
-    if (i < ARRAY_SIZE(serial_hds)) {
+    if (i < num_serial_hds) {
         return serial_hds[i];
     }
     return NULL;
#39 lore raw

Re: [Qemu-devel] [PATCH 12/13] vl.c: Remove compile time limit on number of serial ports

Quoted 8 lines · Paolo Bonzini
Quoted 5 lines · Peter Maydell

Instead of having a fixed sized global serial_hds[] array, use a local dynamically reallocated one, so we don't have a compile time limit on how many serial ports a system has.

Just one question, would it make sense to use a GPtrArray instead?

Hmm. Looking at the GPtrArray API there's no API for "tell me the length of this pointer array", so we'd still have to do the manual bookkeeping for that. And we don't need most of the functionality it provides. So it doesn't really seem like it gains us much over g_renew() to me.

thanks
-- PMM

#40 lore raw

Re: [Qemu-devel] [PATCH 12/13] vl.c: Remove compile time limit on number of serial ports

Quoted 8 lines · Peter Maydell
Quoted 7 lines · Paolo Bonzini
Quoted 5 lines · Peter Maydell

Instead of having a fixed sized global serial_hds[] array, use a local dynamically reallocated one, so we don't have a compile time limit on how many serial ports a system has.

Quoted 7 lines
Quoted 1 line

Just one question, would it make sense to use a GPtrArray instead?

Hmm. Looking at the GPtrArray API there's no API for "tell me the length of this pointer array", so we'd still have to do the manual bookkeeping for that. And we don't need most of the functionality it provides. So it doesn't really seem like it gains us much over g_renew() to me.

GPtrArray is a public struct, so you can use array->pdata and array->len. There is a disadvantage, which is that you lose type-safety on dereference.

Paolo

Reviewed-by Tested-by on v1 12/13
#41 lore raw

Re: [Qemu-devel] [PATCH 12/13] vl.c: Remove compile time limit on number of serial ports

In reply to Peter Maydell
Quoted 15 lines · Peter Maydell

Instead of having a fixed sized global serial_hds[] array, use a local dynamically reallocated one, so we don't have a compile time limit on how many serial ports a system has.

---
 include/sysemu/sysemu.h |  2 --
 vl.c                    | 15 +++++++--------
 2 files changed, 7 insertions(+), 10 deletions(-)
include/sysemu/sysemu.h +0 -0
index bd5b55c514..989cbc2b7b 100644

include/sysemu/sysemu.h void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict); · line 165

Quoted 5 lines
include/sysemu/sysemu.h +0 -2
@@ -161,8 +161,6 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict);
 
 #define MAX_SERIAL_PORTS 4
 
-extern Chardev *serial_hds[MAX_SERIAL_PORTS];
-

Finally :)))

Quoted 54 lines
include/sysemu/sysemu.h +0 -0
 /* Return the Chardev for serial port i, or NULL if none */
 Chardev *serial_hd(int i);
 
vl.c +7 -8
index 6daf026da6..a8a98c5a37 100644
@@ -154,7 +154,8 @@ QEMUClockType rtc_clock;
 int vga_interface_type = VGA_NONE;
 static DisplayOptions dpy;
 int no_frame;
-Chardev *serial_hds[MAX_SERIAL_PORTS];
+static int num_serial_hds = 0;
+static Chardev **serial_hds = NULL;
 Chardev *parallel_hds[MAX_PARALLEL_PORTS];
 Chardev *virtcon_hds[MAX_VIRTIO_CONSOLES];
 Chardev *sclp_hds[MAX_SCLP_CONSOLES];
@@ -2496,30 +2497,28 @@ static int foreach_device_config(int type, int (*func)(const char *cmdline))
 
 static int serial_parse(const char *devname)
 {
-    static int index = 0;
+    int index = num_serial_hds;
     char label[32];
 
     if (strcmp(devname, "none") == 0)
         return 0;
-    if (index == MAX_SERIAL_PORTS) {
-        error_report("too many serial ports");
-        exit(1);
-    }
     snprintf(label, sizeof(label), "serial%d", index);
+    serial_hds = g_renew(Chardev *, serial_hds, index + 1);
+
     serial_hds[index] = qemu_chr_new(label, devname);
     if (!serial_hds[index]) {
         error_report("could not connect serial device"
                      " to character backend '%s'", devname);
         return -1;
     }
-    index++;
+    num_serial_hds++;
     return 0;
 }
 
 Chardev *serial_hd(int i)
 {
     assert(i >= 0);
-    if (i < ARRAY_SIZE(serial_hds)) {
+    if (i < num_serial_hds) {
         return serial_hds[i];
     }
     return NULL;
Reviewed-by on v1 12/13
#42 lore raw

Re: [Qemu-devel] [PATCH 12/13] vl.c: Remove compile time limit on number of serial ports

In reply to Peter Maydell
Quoted 46 lines · Peter Maydell

Instead of having a fixed sized global serial_hds[] array, use a local dynamically reallocated one, so we don't have a compile time limit on how many serial ports a system has.

---
 include/sysemu/sysemu.h |  2 --
 vl.c                    | 15 +++++++--------
 2 files changed, 7 insertions(+), 10 deletions(-)
include/sysemu/sysemu.h +0 -2
index bd5b55c514..989cbc2b7b 100644
@@ -161,8 +161,6 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict);
 
 #define MAX_SERIAL_PORTS 4
 
-extern Chardev *serial_hds[MAX_SERIAL_PORTS];
-
 /* Return the Chardev for serial port i, or NULL if none */
 Chardev *serial_hd(int i);
 
vl.c +3 -2
index 6daf026da6..a8a98c5a37 100644
@@ -154,7 +154,8 @@ QEMUClockType rtc_clock;
 int vga_interface_type = VGA_NONE;
 static DisplayOptions dpy;
 int no_frame;
-Chardev *serial_hds[MAX_SERIAL_PORTS];
+static int num_serial_hds = 0;
+static Chardev **serial_hds = NULL;
 Chardev *parallel_hds[MAX_PARALLEL_PORTS];
 Chardev *virtcon_hds[MAX_VIRTIO_CONSOLES];
 Chardev *sclp_hds[MAX_SCLP_CONSOLES];
@@ -2496,30 +2497,28 @@ static int foreach_device_config(int type, int (*func)(const char *cmdline))
 
 static int serial_parse(const char *devname)
 {
-    static int index = 0;
+    int index = num_serial_hds;
     char label[32];
 
     if (strcmp(devname, "none") == 0)

vl.c static int foreach_device_config(int type, int (*func)(const char *cmdline)) · line 2509

Quoted 10 lines
vl.c +2 -4
         return 0;
-    if (index == MAX_SERIAL_PORTS) {
-        error_report("too many serial ports");
-        exit(1);
-    }
     snprintf(label, sizeof(label), "serial%d", index);
+    serial_hds = g_renew(Chardev *, serial_hds, index + 1);
+
     serial_hds[index] = qemu_chr_new(label, devname);
     if (!serial_hds[index]) {

In case you respin: I think you could do this without the index variable and just use num_serial_hds directly instead (just a matter of taste, though).

#43 lore raw

PATCH 13/13 vl.c: new function max_serial_hds()

In reply to Peter Maydell

Create a new function max_serial_hds() which returns the number of serial ports defined by the user. This is needed only by spapr.

This allows us to remove the MAX_SERIAL_PORTS define.

---
 include/sysemu/sysemu.h | 6 ++++--
 hw/ppc/spapr.c          | 2 +-
 vl.c                    | 5 +++++
 3 files changed, 10 insertions(+), 3 deletions(-)
include/sysemu/sysemu.h +4 -2
index 989cbc2b7b..612659a718 100644
@@ -159,10 +159,12 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict);
 
 /* serial ports */
 
-#define MAX_SERIAL_PORTS 4
-
 /* Return the Chardev for serial port i, or NULL if none */
 Chardev *serial_hd(int i);
+/* return the number of serial ports defined by the user. serial_hd(i)
+ * will always return NULL for any i which is greater than or equal to this.
+ */
+int max_serial_hds(void);
 
 /* parallel ports */
 
hw/ppc/spapr.c +1 -1
index b0ecfaca9e..8d2d36a606 100644
@@ -2589,7 +2589,7 @@ static void spapr_machine_init(MachineState *machine)
     /* Set up VIO bus */
     spapr->vio_bus = spapr_vio_bus_init();
 
-    for (i = 0; i < MAX_SERIAL_PORTS; i++) {
+    for (i = 0; i < max_serial_hds(); i++) {
         if (serial_hd(i)) {
             spapr_vty_create(spapr->vio_bus, serial_hd(i));
         }
vl.c +5 -0
index a8a98c5a37..b587187052 100644
@@ -2524,6 +2524,11 @@ Chardev *serial_hd(int i)
     return NULL;
 }
 
+int max_serial_hds(void)
+{
+    return num_serial_hds;
+}
+
 static int parallel_parse(const char *devname)
 {
     static int index = 0;
Signature · 1 line
2.17.0
Reviewed-by Tested-by on v1 13/13
#44 lore raw

Re: [Qemu-devel] [PATCH 13/13] vl.c: new function max_serial_hds()

Quoted 17 lines · Peter Maydell

Create a new function max_serial_hds() which returns the number of serial ports defined by the user. This is needed only by spapr. This allows us to remove the MAX_SERIAL_PORTS define.

---
 include/sysemu/sysemu.h | 6 ++++--
 hw/ppc/spapr.c          | 2 +-
 vl.c                    | 5 +++++
 3 files changed, 10 insertions(+), 3 deletions(-)
include/sysemu/sysemu.h +0 -0
index 989cbc2b7b..612659a718 100644
@@ -159,10 +159,12 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict);
 

include/sysemu/sysemu.h void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict); · line 167

Quoted 10 lines
include/sysemu/sysemu.h +4 -2
 /* serial ports */
 
-#define MAX_SERIAL_PORTS 4
-
 /* Return the Chardev for serial port i, or NULL if none */
 Chardev *serial_hd(int i);
+/* return the number of serial ports defined by the user. serial_hd(i)
+ * will always return NULL for any i which is greater than or equal to this.
+ */
+int max_serial_hds(void);

What about naming it serial_hds_count() to keep this under the serial_ namespace? And about using a size_t for num_serial_hds?

Quoted 33 lines
include/sysemu/sysemu.h +0 -0
 /* parallel ports */
 
hw/ppc/spapr.c +1 -1
index b0ecfaca9e..8d2d36a606 100644
@@ -2589,7 +2589,7 @@ static void spapr_machine_init(MachineState *machine)
     /* Set up VIO bus */
     spapr->vio_bus = spapr_vio_bus_init();
 
-    for (i = 0; i < MAX_SERIAL_PORTS; i++) {
+    for (i = 0; i < max_serial_hds(); i++) {
         if (serial_hd(i)) {
             spapr_vty_create(spapr->vio_bus, serial_hd(i));
         }
vl.c +5 -0
index a8a98c5a37..b587187052 100644
@@ -2524,6 +2524,11 @@ Chardev *serial_hd(int i)
     return NULL;
 }
 
+int max_serial_hds(void)
+{
+    return num_serial_hds;
+}
+
 static int parallel_parse(const char *devname)
 {
     static int index = 0;
#45 lore raw

Re: [Qemu-devel] [PATCH 13/13] vl.c: new function max_serial_hds()

Quoted 20 lines · Philippe Mathieu-Daudé
Quoted 19 lines · Peter Maydell

Create a new function max_serial_hds() which returns the number of serial ports defined by the user. This is needed only by spapr. This allows us to remove the MAX_SERIAL_PORTS define.

---
 include/sysemu/sysemu.h | 6 ++++--
 hw/ppc/spapr.c          | 2 +-
 vl.c                    | 5 +++++
 3 files changed, 10 insertions(+), 3 deletions(-)
include/sysemu/sysemu.h +0 -0
index 989cbc2b7b..612659a718 100644
@@ -159,10 +159,12 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict);
 
 /* serial ports */
 
Quoted 11 lines

include/sysemu/sysemu.h void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict); · line 167

Quoted 8 lines
include/sysemu/sysemu.h +4 -2
-#define MAX_SERIAL_PORTS 4
-
 /* Return the Chardev for serial port i, or NULL if none */
 Chardev *serial_hd(int i);
+/* return the number of serial ports defined by the user. serial_hd(i)
+ * will always return NULL for any i which is greater than or equal to this.
+ */
+int max_serial_hds(void);

What about naming it serial_hds_count() to keep this under the serial_ namespace?

OK, makes sense.

Quoted 1 line

And about using a size_t for num_serial_hds?

This doesn't seem worthwhile though.

Since the rename of max_serial_hds is the only change here, I propose to apply this to master (fixing up the function name in this patch in the process), to reduce the number of conflicts with other changes currently in-flight.

thanks
-- PMM

Reviewed-by on v1 13/13
#46 lore raw

Re: [Qemu-devel] [PATCH 13/13] vl.c: new function max_serial_hds()

In reply to Peter Maydell
Quoted 51 lines · Peter Maydell

Create a new function max_serial_hds() which returns the number of serial ports defined by the user. This is needed only by spapr.

This allows us to remove the MAX_SERIAL_PORTS define.

---
 include/sysemu/sysemu.h | 6 ++++--
 hw/ppc/spapr.c          | 2 +-
 vl.c                    | 5 +++++
 3 files changed, 10 insertions(+), 3 deletions(-)
include/sysemu/sysemu.h +4 -2
index 989cbc2b7b..612659a718 100644
@@ -159,10 +159,12 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict);
 
 /* serial ports */
 
-#define MAX_SERIAL_PORTS 4
-
 /* Return the Chardev for serial port i, or NULL if none */
 Chardev *serial_hd(int i);
+/* return the number of serial ports defined by the user. serial_hd(i)
+ * will always return NULL for any i which is greater than or equal to this.
+ */
+int max_serial_hds(void);
 
 /* parallel ports */
 
hw/ppc/spapr.c +1 -1
index b0ecfaca9e..8d2d36a606 100644
@@ -2589,7 +2589,7 @@ static void spapr_machine_init(MachineState *machine)
     /* Set up VIO bus */
     spapr->vio_bus = spapr_vio_bus_init();
 
-    for (i = 0; i < MAX_SERIAL_PORTS; i++) {
+    for (i = 0; i < max_serial_hds(); i++) {
         if (serial_hd(i)) {
             spapr_vty_create(spapr->vio_bus, serial_hd(i));
         }
vl.c +0 -0
index a8a98c5a37..b587187052 100644
@@ -2524,6 +2524,11 @@ Chardev *serial_hd(int i)
     return NULL;

vl.c Chardev *serial_hd(int i) · line 2534

Quoted 10 lines
vl.c +5 -0
 }
 
+int max_serial_hds(void)
+{
+    return num_serial_hds;
+}
+
 static int parallel_parse(const char *devname)
 {
     static int index = 0;
#47 lore raw
In reply to Peter Maydell
This series seems to have some coding style problems. See output below for more information:

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH 00/13] Drop compile time limit on number of serial ports

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
96dfccb00b vl.c: new function max_serial_hds()
3e71fd34eb vl.c: Remove compile time limit on number of serial ports c43b9fdfc2 superio: Don't use MAX_SERIAL_PORTS for serial port limit b770c540a9 serial-isa: Use MAX_ISA_SERIAL_PORTS instead of MAX_SERIAL_PORTS 038ffe574e hw/char/exynos4210_uart.c: Remove unneeded handling of NULL chardev 813b6d6287 Remove checks on MAX_SERIAL_PORTS that are just bounds checks 066f676d66 Change references to serial_hds[] to serial_hd() ede9de0c27 vl.c: Provide accessor function serial_hd() for serial_hds[] array bfbf0f20cb hw/xtensa/xtfpga.c: Don't create "null" chardevs for serial devices d31d02cbd8 hw/mips/mips_malta: Don't create "null" chardevs for serial devices 32216ce5e5 hw/mips/boston.c: Don't create "null" chardevs for serial devices 364918ebd9 hw/arm/fsl-imx*: Don't create "null" chardevs for serial devices 4a5a612b77 hw/char/serial: Allow disconnected chardevs

=== OUTPUT BEGIN ===
Checking PATCH 1/13: hw/char/serial: Allow disconnected chardevs...
Checking PATCH 2/13: hw/arm/fsl-imx*: Don't create "null" chardevs for serial devices... Checking PATCH 3/13: hw/mips/boston.c: Don't create "null" chardevs for serial devices... Checking PATCH 4/13: hw/mips/mips_malta: Don't create "null" chardevs for serial devices... Checking PATCH 5/13: hw/xtensa/xtfpga.c: Don't create "null" chardevs for serial devices... Checking PATCH 6/13: vl.c: Provide accessor function serial_hd() for serial_hds[] array... Checking PATCH 7/13: Change references to serial_hds[] to serial_hd()...
WARNING: line over 80 characters
#581: FILE: hw/cris/axis_dev88.c:340:
+ etraxfs_ser_create(0x30026000 + i * 0x2000, irq[0x14 + i], serial_hd(i));

ERROR: spaces required around that '/' (ctx:VxV)
#824: FILE: hw/moxie/moxiesim.c:146:

+                       8000000/16, serial_hd(0), DEVICE_LITTLE_ENDIAN);
                               ^

total: 1 errors, 1 warnings, 852 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

Checking PATCH 8/13: Remove checks on MAX_SERIAL_PORTS that are just bounds checks... Checking PATCH 9/13: hw/char/exynos4210_uart.c: Remove unneeded handling of NULL chardev... Checking PATCH 10/13: serial-isa: Use MAX_ISA_SERIAL_PORTS instead of MAX_SERIAL_PORTS... Checking PATCH 11/13: superio: Don't use MAX_SERIAL_PORTS for serial port limit... Checking PATCH 12/13: vl.c: Remove compile time limit on number of serial ports...
ERROR: do not initialise statics to 0 or NULL
#35: FILE: vl.c:157:
+static int num_serial_hds = 0;

ERROR: do not initialise statics to 0 or NULL
#36: FILE: vl.c:158:
+static Chardev **serial_hds = NULL;

total: 2 errors, 0 warnings, 52 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

Checking PATCH 13/13: vl.c: new function max_serial_hds()... === OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]

#48 lore raw
Quoted 11 lines · On 20 April 2018 at 16:10, <[email protected]> wrote:

Checking PATCH 7/13: Change references to serial_hds[] to serial_hd()...
WARNING: line over 80 characters
#581: FILE: hw/cris/axis_dev88.c:340:
+ etraxfs_ser_create(0x30026000 + i * 0x2000, irq[0x14 + i], serial_hd(i));

ERROR: spaces required around that '/' (ctx:VxV)
#824: FILE: hw/moxie/moxiesim.c:146:

+                       8000000/16, serial_hd(0), DEVICE_LITTLE_ENDIAN);
                               ^

total: 1 errors, 1 warnings, 852 lines checked

These are in the "mechanical change only" patch, so I didn't want to change anything else there.

Quoted 8 lines

Checking PATCH 12/13: vl.c: Remove compile time limit on number of serial ports...
ERROR: do not initialise statics to 0 or NULL
#35: FILE: vl.c:157:
+static int num_serial_hds = 0;

ERROR: do not initialise statics to 0 or NULL
#36: FILE: vl.c:158:
+static Chardev **serial_hds = NULL;

I'd forgotten checkpatch had this requirement; easy to fix.

thanks
-- PMM

author Applied
#49 lore raw
In reply to Peter Maydell
Quoted 7 lines · Peter Maydell

For many years, QEMU has had a compile time restriction on how many serial port devices you can create and configure with the -serial argument. This is 4, largely because for x86 PC the traditional number of ISA serial devices is 4, and nobody's ever changed the limit since.

This patchset drops the compile time limit.

Applied to master, with minor tweak in patch 13.

I only realised when I came back to here that I'd forgotten about checkpatch's preference for not zero-initializing static globals; I'll send a fixup patch for that.

thanks
-- PMM