Skip to contentSkip to conversation

hw/riscv/virt: Add a second UART for secure world

PATCH In review Yong Li 2 participants 3 messages Apr 24, 2023 RISC-V

lore
Share & tools
lore

Yong Li

author
#0 lore raw

PATCH 1/1 hw/riscv/virt: Add a second UART for secure world

The virt machine can have two UARTs and the second UART can be used when host secure-mode support is enabled.

---
 hw/riscv/virt.c         | 4 ++++
 include/hw/riscv/virt.h | 2 ++
 2 files changed, 6 insertions(+)
hw/riscv/virt.c +4 -0
index b38b41e685..02475e1678 100644
@@ -88,6 +88,7 @@ static const MemMapEntry virt_memmap[] = {
     [VIRT_APLIC_S] =      {  0xd000000, APLIC_SIZE(VIRT_CPUS_MAX) },
     [VIRT_UART0] =        { 0x10000000,         0x100 },
     [VIRT_VIRTIO] =       { 0x10001000,        0x1000 },
+    [VIRT_UART1] =        { 0x10002000,         0x100 },
     [VIRT_FW_CFG] =       { 0x10100000,          0x18 },
     [VIRT_FLASH] =        { 0x20000000,     0x4000000 },
     [VIRT_IMSIC_M] =      { 0x24000000, VIRT_IMSIC_MAX_SIZE },
@@ -1508,6 +1509,9 @@ static void virt_machine_init(MachineState *machine)
     serial_mm_init(system_memory, memmap[VIRT_UART0].base,
         0, qdev_get_gpio_in(DEVICE(mmio_irqchip), UART0_IRQ), 399193,
         serial_hd(0), DEVICE_LITTLE_ENDIAN);
+    serial_mm_init(system_memory, memmap[VIRT_UART1].base,
+        0, qdev_get_gpio_in(DEVICE(mmio_irqchip), UART1_IRQ), 399193,
+        serial_hd(1), DEVICE_LITTLE_ENDIAN);
 
     sysbus_create_simple("goldfish_rtc", memmap[VIRT_RTC].base,
         qdev_get_gpio_in(DEVICE(mmio_irqchip), RTC_IRQ));
include/hw/riscv/virt.h +2 -0
index e5c474b26e..8d2f8f225d 100644
@@ -74,6 +74,7 @@ enum {
     VIRT_APLIC_S,
     VIRT_UART0,
     VIRT_VIRTIO,
+    VIRT_UART1,
     VIRT_FW_CFG,
     VIRT_IMSIC_M,
     VIRT_IMSIC_S,
@@ -88,6 +89,7 @@ enum {
 enum {
     UART0_IRQ = 10,
     RTC_IRQ = 11,
+    UART1_IRQ = 12,
     VIRTIO_IRQ = 1, /* 1 to 8 */
     VIRTIO_COUNT = 8,
     PCIE_IRQ = 0x20, /* 32 to 35 */
Signature · 1 line
2.25.1
#1 lore raw
Quoted 3 lines · Yong Li

The virt machine can have two UARTs and the second UART can be used when host secure-mode support is enabled.

Do you mean "host" here, or "guest" ?

Quoted 19 lines
---
 hw/riscv/virt.c         | 4 ++++
 include/hw/riscv/virt.h | 2 ++
 2 files changed, 6 insertions(+)
hw/riscv/virt.c +1 -0
index b38b41e685..02475e1678 100644
@@ -88,6 +88,7 @@ static const MemMapEntry virt_memmap[] = {
     [VIRT_APLIC_S] =      {  0xd000000, APLIC_SIZE(VIRT_CPUS_MAX) },
     [VIRT_UART0] =        { 0x10000000,         0x100 },
     [VIRT_VIRTIO] =       { 0x10001000,        0x1000 },
+    [VIRT_UART1] =        { 0x10002000,         0x100 },
     [VIRT_FW_CFG] =       { 0x10100000,          0x18 },
     [VIRT_FLASH] =        { 0x20000000,     0x4000000 },
     [VIRT_IMSIC_M] =      { 0x24000000, VIRT_IMSIC_MAX_SIZE },

hw/riscv/virt.c static void virt_machine_init(MachineState *machine) · line 1517

Quoted 9 lines
hw/riscv/virt.c +3 -0
@@ -1508,6 +1509,9 @@ static void virt_machine_init(MachineState *machine)
     serial_mm_init(system_memory, memmap[VIRT_UART0].base,
         0, qdev_get_gpio_in(DEVICE(mmio_irqchip), UART0_IRQ), 399193,
         serial_hd(0), DEVICE_LITTLE_ENDIAN);
+    serial_mm_init(system_memory, memmap[VIRT_UART1].base,
+        0, qdev_get_gpio_in(DEVICE(mmio_irqchip), UART1_IRQ), 399193,
+        serial_hd(1), DEVICE_LITTLE_ENDIAN);
 
     sysbus_create_simple("goldfish_rtc", memmap[VIRT_RTC].base,
         qdev_get_gpio_in(DEVICE(mmio_irqchip), RTC_IRQ));

Is it intentional that you only create the UART device and do not add it to the FDT ? (UART0 doesn't seem to be in the ACPI table generation code so I guess that part is OK.)

You probably also want to test for compatibility:
for arm we found that different bits of software (firmware, Linux kernel) annoyingly iterated through the dtb in different orders.

thanks
-- PMM

author
#2 lore raw
Quoted 4 lines · Peter Maydell
Quoted 2 lines · Yong Li

The virt machine can have two UARTs and the second UART can be used when host secure-mode support is enabled.

Do you mean "host" here, or "guest" ?

Currently, it is an UEFI secure firmware residing in a secure partition.  Let me update the message with a v2 patch

Quoted 33 lines
Quoted 19 lines
---
  hw/riscv/virt.c         | 4 ++++
  include/hw/riscv/virt.h | 2 ++
  2 files changed, 6 insertions(+)
hw/riscv/virt.c +1 -0
index b38b41e685..02475e1678 100644
@@ -88,6 +88,7 @@ static const MemMapEntry virt_memmap[] = {
      [VIRT_APLIC_S] =      {  0xd000000, APLIC_SIZE(VIRT_CPUS_MAX) },
      [VIRT_UART0] =        { 0x10000000,         0x100 },
      [VIRT_VIRTIO] =       { 0x10001000,        0x1000 },
+    [VIRT_UART1] =        { 0x10002000,         0x100 },
      [VIRT_FW_CFG] =       { 0x10100000,          0x18 },
      [VIRT_FLASH] =        { 0x20000000,     0x4000000 },
      [VIRT_IMSIC_M] =      { 0x24000000, VIRT_IMSIC_MAX_SIZE },

hw/riscv/virt.c static void virt_machine_init(MachineState *machine) · line 1517

Quoted 9 lines
hw/riscv/virt.c +3 -0
@@ -1508,6 +1509,9 @@ static void virt_machine_init(MachineState *machine)
      serial_mm_init(system_memory, memmap[VIRT_UART0].base,
          0, qdev_get_gpio_in(DEVICE(mmio_irqchip), UART0_IRQ), 399193,
          serial_hd(0), DEVICE_LITTLE_ENDIAN);
+    serial_mm_init(system_memory, memmap[VIRT_UART1].base,
+        0, qdev_get_gpio_in(DEVICE(mmio_irqchip), UART1_IRQ), 399193,
+        serial_hd(1), DEVICE_LITTLE_ENDIAN);
 
      sysbus_create_simple("goldfish_rtc", memmap[VIRT_RTC].base,
          qdev_get_gpio_in(DEVICE(mmio_irqchip), RTC_IRQ));

Is it intentional that you only create the UART device and do not add it to the FDT ? (UART0 doesn't seem to be in the ACPI table generation code so I guess that part is OK.)

Quoted 4 lines

You probably also want to test for compatibility:
for arm we found that different bits of software (firmware, Linux kernel) annoyingly iterated through the dtb in different orders.

Thanks for the comments.

Yes, tested with our software stack which has edk2 , u-boot firmware,  and also linux/debian os.  No compatibility issue.

Quoted 3 lines

thanks
-- PMM