Skip to contentSkip to conversation

hppa: Fix serial port pass-through

PATCH Superseded Helge Deller 3 participants 7 messages May 26, 2022 – May 28, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover hppa: Fix serial port pass-through

This series fixes the SeaBIOS-hppa firmware and the serial ports setup code in qemu so that it reflects the real hardware and now allows serial port-passthrough from the host to guests.

Tested with Linux guests.

Helge Deller (2):
New SeaBIOS-hppa version 6
hppa: Fix serial port pass-through

 hw/hppa/hppa_hardware.h   |  10 ++++++++--
 hw/hppa/machine.c         |  17 +++++++----------
 pc-bios/hppa-firmware.img | Bin 719040 -> 719368 bytes
 roms/seabios-hppa         |   2 +-
 4 files changed, 16 insertions(+), 13 deletions(-)

--
2.35.3

#1 lore raw

PATCH 1/2 New SeaBIOS-hppa version 6

Staring with SEABIOS_HPPA_VERSION 6 the serial ports are now emulated as on physical hardware, with LASI UART being serial port #0 and DINO UART as serial port #1. On older versions those ports were swapped.

This SeaBIOS-hppa fix is needed to allow fixing the qemu serial pass-through from host to guest.

---
 pc-bios/hppa-firmware.img | Bin 719040 -> 719368 bytes
 roms/seabios-hppa         |   2 +-
 2 files changed, 1 insertion(+), 1 deletion(-)
pc-bios/hppa-firmware.img binary +0 -0
index 392bce072bad607b1baaff0136f35844fa5d439e..b2cbb71ee0f91623d038db04d6900a5ed17472a6 100644
GIT binary patch
roms/seabios-hppa +1 -1
index 17ca7a9998..458626c4c6 160000
@@ -1 +1 @@
-Subproject commit 17ca7a9998c1755d42321cfc0afb5f480f5a58ff
+Subproject commit 458626c4c6441045c0612f24313c7cf1f95e71c6

--
2.35.3

#2 lore raw

PATCH 2/2 hppa: Fix serial port pass-through

In reply to Helge Deller

This fixes the serial ports in the emulation to behave as on original hardware.

On the real hardware, the LASI UART is serial port #0 and the DINO UART is serial port #1. This is fixed in SEABIOS_HPPA_VERSION >= 6, which is why the latest firmware is required.

The serial port addresses in hppa/hppa_hardware.h are swapped and the file is synced with the version in SeaBIOS-hppa. Please note that this file is shared between qemu and SeaBIOS-hppa, which is why a comment was added at the top of the file.

When creating the virtual serial ports the correct port addresses are now used.

Finally, this patch now allows the user to give:
-serial mon:stdio -serial /dev/ttyS4
to use emulated ttyS0 in the guest for console output, and pass ttyS4 from the host to ttyS1 in the guest.

---
 hw/hppa/hppa_hardware.h | 10 ++++++++--
 hw/hppa/machine.c       | 17 +++++++----------
 2 files changed, 15 insertions(+), 12 deletions(-)
hw/hppa/hppa_hardware.h +8 -2
index 8b6b9222cb..c036d467f3 100644
@@ -1,4 +1,5 @@
 /* HPPA cores and system support chips.  */
+/* Be aware: This file is shared as-is with seabios-hppa. */
 
 #ifndef HW_HPPA_HPPA_HARDWARE_H
 #define HW_HPPA_HPPA_HARDWARE_H
@@ -30,13 +31,18 @@
 #define PCI_HPA         DINO_HPA        /* PCI bus */
 #define IDE_HPA         0xf9000000      /* Boot disc controller */
 
+/* offsets to DINO HPA: */
+#define DINO_PCI_ADDR           0x064
+#define DINO_CONFIG_DATA        0x068
+#define DINO_IO_DATA            0x06c
+
 #define PORT_PCI_CMD    (PCI_HPA + DINO_PCI_ADDR)
 #define PORT_PCI_DATA   (PCI_HPA + DINO_CONFIG_DATA)
 
 #define FW_CFG_IO_BASE  0xfffa0000
 
-#define PORT_SERIAL1    (DINO_UART_HPA + 0x800)
-#define PORT_SERIAL2    (LASI_UART_HPA + 0x800)
+#define PORT_SERIAL1    (LASI_UART_HPA + 0x800)
+#define PORT_SERIAL2    (DINO_UART_HPA + 0x800)
 
 #define HPPA_MAX_CPUS   16      /* max. number of SMP CPUs */
 #define CPU_CLOCK_MHZ   250     /* emulate a 250 MHz CPU */
hw/hppa/machine.c +7 -10
index d1e174b1f4..5d23b9e528 100644
@@ -32,7 +32,7 @@
 
 #define MAX_IDE_BUS 2
 
-#define MIN_SEABIOS_HPPA_VERSION 1 /* require at least this fw version */
+#define MIN_SEABIOS_HPPA_VERSION 6 /* require at least this fw version */
 
 #define HPA_POWER_BUTTON (FIRMWARE_END - 0x10)
 
@@ -236,18 +236,15 @@ static void machine_hppa_init(MachineState *machine)
     /* Realtime clock, used by firmware for PDC_TOD call. */
     mc146818_rtc_init(isa_bus, 2000, NULL);
 
-    /* Serial code setup.  */
+    /* Serial ports - Lasi and Dino use a 7.272727 MHz clock. */
     if (serial_hd(0)) {
-        uint32_t addr = DINO_UART_HPA + 0x800;
-        serial_mm_init(addr_space, addr, 0,
-                       qdev_get_gpio_in(dino_dev, DINO_IRQ_RS232INT),
-                       115200, serial_hd(0), DEVICE_BIG_ENDIAN);
+        serial_mm_init(addr_space, LASI_UART_HPA + 0x800, 0,
+                qdev_get_gpio_in(lasi_dev, LASI_IRQ_UART_HPA), 7272727 / 16,
+                serial_hd(0), DEVICE_BIG_ENDIAN);
     }
-
     if (serial_hd(1)) {
-        /* Serial port */
-        serial_mm_init(addr_space, LASI_UART_HPA + 0x800, 0,
-                qdev_get_gpio_in(lasi_dev, LASI_IRQ_UART_HPA), 8000000 / 16,
+        serial_mm_init(addr_space, DINO_UART_HPA + 0x800, 0,
+                qdev_get_gpio_in(dino_dev, DINO_IRQ_RS232INT), 7272727 / 16,
                 serial_hd(1), DEVICE_BIG_ENDIAN);
     }
 

--
2.35.3

#3 lore raw
Quoted 31 lines · Helge Deller

This fixes the serial ports in the emulation to behave as on original hardware.

On the real hardware, the LASI UART is serial port #0 and the DINO UART is serial port #1. This is fixed in SEABIOS_HPPA_VERSION >= 6, which is why the latest firmware is required.

The serial port addresses in hppa/hppa_hardware.h are swapped and the file is synced with the version in SeaBIOS-hppa. Please note that this file is shared between qemu and SeaBIOS-hppa, which is why a comment was added at the top of the file.

When creating the virtual serial ports the correct port addresses are now used.

Finally, this patch now allows the user to give:
-serial mon:stdio -serial /dev/ttyS4
to use emulated ttyS0 in the guest for console output, and pass ttyS4 from the host to ttyS1 in the guest.

---
  hw/hppa/hppa_hardware.h | 10 ++++++++--
  hw/hppa/machine.c       | 17 +++++++----------
  2 files changed, 15 insertions(+), 12 deletions(-)
hw/hppa/hppa_hardware.h +0 -0
index 8b6b9222cb..c036d467f3 100644

hw/hppa/hppa_hardware.h line 2

Quoted 2 lines
hw/hppa/hppa_hardware.h +1 -0
@@ -1,4 +1,5 @@
  /* HPPA cores and system support chips.  */
+/* Be aware: This file is shared as-is with seabios-hppa. */

Ah thanks for the comment - I didn't realise that when I did the last set of changes, but presumably everything is in sync now? It would be nice for this to be done as a separate commit, since even with the PORT_SERIAL1 and PORT_SERIAL2 changes, there would be no regression if the serial ports are currently broken.

Quoted 50 lines
hw/hppa/hppa_hardware.h +7 -2
  #ifndef HW_HPPA_HPPA_HARDWARE_H
  #define HW_HPPA_HPPA_HARDWARE_H
@@ -30,13 +31,18 @@
  #define PCI_HPA         DINO_HPA        /* PCI bus */
  #define IDE_HPA         0xf9000000      /* Boot disc controller */
 
+/* offsets to DINO HPA: */
+#define DINO_PCI_ADDR           0x064
+#define DINO_CONFIG_DATA        0x068
+#define DINO_IO_DATA            0x06c
+
  #define PORT_PCI_CMD    (PCI_HPA + DINO_PCI_ADDR)
  #define PORT_PCI_DATA   (PCI_HPA + DINO_CONFIG_DATA)
 
  #define FW_CFG_IO_BASE  0xfffa0000
 
-#define PORT_SERIAL1    (DINO_UART_HPA + 0x800)
-#define PORT_SERIAL2    (LASI_UART_HPA + 0x800)
+#define PORT_SERIAL1    (LASI_UART_HPA + 0x800)
+#define PORT_SERIAL2    (DINO_UART_HPA + 0x800)
 
  #define HPPA_MAX_CPUS   16      /* max. number of SMP CPUs */
  #define CPU_CLOCK_MHZ   250     /* emulate a 250 MHz CPU */
hw/hppa/machine.c +5 -6
index d1e174b1f4..5d23b9e528 100644
@@ -32,7 +32,7 @@
 
  #define MAX_IDE_BUS 2
 
-#define MIN_SEABIOS_HPPA_VERSION 1 /* require at least this fw version */
+#define MIN_SEABIOS_HPPA_VERSION 6 /* require at least this fw version */
 
  #define HPA_POWER_BUTTON (FIRMWARE_END - 0x10)
 
@@ -236,18 +236,15 @@ static void machine_hppa_init(MachineState *machine)
      /* Realtime clock, used by firmware for PDC_TOD call. */
      mc146818_rtc_init(isa_bus, 2000, NULL);
 
-    /* Serial code setup.  */
+    /* Serial ports - Lasi and Dino use a 7.272727 MHz clock. */
      if (serial_hd(0)) {
-        uint32_t addr = DINO_UART_HPA + 0x800;
-        serial_mm_init(addr_space, addr, 0,
-                       qdev_get_gpio_in(dino_dev, DINO_IRQ_RS232INT),
-                       115200, serial_hd(0), DEVICE_BIG_ENDIAN);
+        serial_mm_init(addr_space, LASI_UART_HPA + 0x800, 0,
+                qdev_get_gpio_in(lasi_dev, LASI_IRQ_UART_HPA), 7272727 / 16,
+                serial_hd(0), DEVICE_BIG_ENDIAN);

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

Quoted 10 lines
hw/hppa/machine.c +2 -4
      }
-
      if (serial_hd(1)) {
-        /* Serial port */
-        serial_mm_init(addr_space, LASI_UART_HPA + 0x800, 0,
-                qdev_get_gpio_in(lasi_dev, LASI_IRQ_UART_HPA), 8000000 / 16,
+        serial_mm_init(addr_space, DINO_UART_HPA + 0x800, 0,
+                qdev_get_gpio_in(dino_dev, DINO_IRQ_RS232INT), 7272727 / 16,
                  serial_hd(1), DEVICE_BIG_ENDIAN);
      }

You can remove both of the "if (serial_hd(x)) { ... }" wrappers here: for some time now the chardev code assumes that NULL == not connected. This is also better since it means that even if you haven't connected anything to the guest serial port, the port is still mapped in the guest's address space which can be useful if the firmware unconditionally outputs debugging information on the serial port.

ATB,

Mark.

#4 lore raw
In reply to Helge Deller
Quoted 36 lines · Helge Deller

This fixes the serial ports in the emulation to behave as on original hardware.

On the real hardware, the LASI UART is serial port #0 and the DINO UART is serial port #1. This is fixed in SEABIOS_HPPA_VERSION >= 6, which is why the latest firmware is required.

The serial port addresses in hppa/hppa_hardware.h are swapped and the file is synced with the version in SeaBIOS-hppa. Please note that this file is shared between qemu and SeaBIOS-hppa, which is why a comment was added at the top of the file.

When creating the virtual serial ports the correct port addresses are now used.

Finally, this patch now allows the user to give:
-serial mon:stdio -serial /dev/ttyS4
to use emulated ttyS0 in the guest for console output, and pass ttyS4 from the host to ttyS1 in the guest.

hw/hppa/machine.c +4 -5
@@ -236,18 +236,15 @@ static void machine_hppa_init(MachineState *machine)
     /* Realtime clock, used by firmware for PDC_TOD call. */
     mc146818_rtc_init(isa_bus, 2000, NULL);
 
-    /* Serial code setup.  */
+    /* Serial ports - Lasi and Dino use a 7.272727 MHz clock. */
     if (serial_hd(0)) {
-        uint32_t addr = DINO_UART_HPA + 0x800;
-        serial_mm_init(addr_space, addr, 0,
-                       qdev_get_gpio_in(dino_dev, DINO_IRQ_RS232INT),
-                       115200, serial_hd(0), DEVICE_BIG_ENDIAN);
+        serial_mm_init(addr_space, LASI_UART_HPA + 0x800, 0,
+                qdev_get_gpio_in(lasi_dev, LASI_IRQ_UART_HPA), 7272727 / 16,
+                serial_hd(0), DEVICE_BIG_ENDIAN);

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

Quoted 10 lines
hw/hppa/machine.c +2 -4
     }
-
     if (serial_hd(1)) {
-        /* Serial port */
-        serial_mm_init(addr_space, LASI_UART_HPA + 0x800, 0,
-                qdev_get_gpio_in(lasi_dev, LASI_IRQ_UART_HPA), 8000000 / 16,
+        serial_mm_init(addr_space, DINO_UART_HPA + 0x800, 0,
+                qdev_get_gpio_in(dino_dev, DINO_IRQ_RS232INT), 7272727 / 16,
                 serial_hd(1), DEVICE_BIG_ENDIAN);
     }

Not related to this change, but you should consider removing these "if (serial_hd(n))" conditionals. They used to be necessary because the chardev backend infrastructure couldn't cope with being handed a NULL pointer, but these days that is guaranteed to work (with a NULL pointer being equivalent to the 'throw everything away' null chardev), so the if()s are no longer necessary. They also mean that the guest sees the hardware it expects, ie the UARTs are always there and programmable whether there's an RS232 cable plugged in the back of the machine or not.

thanks
-- PMM

#5 lore raw
Quoted 2 lines · Peter Maydell

Not related to this change, but you should consider removing these "if (serial_hd(n))" conditionals.

...oops, I just saw the 3/3 patch in your pullreq which does exactly that, so ignore my email :-)

-- PMM

#6 lore raw
Quoted 6 lines · Peter Maydell
Quoted 2 lines · Peter Maydell

Not related to this change, but you should consider removing these "if (serial_hd(n))" conditionals.

...oops, I just saw the 3/3 patch in your pullreq which does exactly that, so ignore my email :-)

Yes, in v3 (and the pull request) I fixed that since Mark had the same suggestion as you.

Helge