Skip to contentSkip to conversation

hw/riscv: riscv-server-ref refinements

PATCH Applied Daniel Henrique Barboza 3 participants 10 messages Nov 19 – Nov 20 RISC-V

lore
Share & tools
lore
#0 lore raw

v3 cover hw/riscv: riscv-server-ref refinements

Hi,

Sashiko pointed out that patch 1 was missing a Fixes tag. We're adding it in this version.

However, Sashiko wants the tag to point to a commit that introduced the riscv_create_iommu_sys() helper. This isn't accurate: that commit added the helper support and use in the 'virt' machine, an use that doesn't care about hpm counters, so I don't see that commit as being faulty. I pointed to the commit that introduced the riscv-server-ref emulation instead since this hpm counter setting should've been there from the start.

No other changes made. Patches based on master.

Changes in v3:
- patch 1: added "Fixes" tag.
- v2 link: https://lore.kernel.org/qemu-devel/[email protected]/

Daniel Henrique Barboza (5):
hw/riscv: allow machines to set 'hpm-counters' for riscv-iommu-sys hw/riscv: make UART FDT helper consider baud rate hw/riscv/server_platform_ref: fix UART baud rate hw/riscv/virt.c: fix base baud in serial_mm_init()
MAINTAINERS: add contact for the RISC-V server-ref machine

 MAINTAINERS                                 |  8 ++++++++
 hw/riscv/fdt-common.c                       | 19 +++++++++++++++++--
 hw/riscv/riscv-iommu-sys.c                  |  4 ++++
 hw/riscv/riscv-iommu.h                      |  1 +
 hw/riscv/server_platform_ref.c              |  9 +++++++--
 hw/riscv/virt.c                             | 17 ++++++++++-------
 include/hw/riscv/fdt-common.h               |  1 +
 include/hw/riscv/virt.h                     |  2 ++
 tests/functional/riscv64/test_server_ref.py |  3 +++
 9 files changed, 53 insertions(+), 11 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 1/5 hw/riscv: allow machines to set 'hpm-counters' for riscv-iommu-sys

The riscv server soc requirements [1] dictates in rule "IOM_200" that the IOMMU must have at least 4 event counters. As it stands today we're creating an iommu-sys device with RISCV_IOMMU_IOCOUNT_NUM (31) counters.

Following the design of setting just the minimal spec requirements, set hpm-counters to 4. We're doing that by adding a new argument in riscv_create_iommu_sys(). In case more IOMMU parameters need to tweaked in the device we might consider a different approach, but for now this suffices.

The hpm-counters value used in the 'virt' board is default val from riscv-iommu, i.e. there's no change in 'virt' board configuration with this patch.

Note that the 'Fixes' tag points to the riscv-server-ref initial commit because the IOM_200 rule should have been there from the start. There's nothing inherently wrong with the initial commit for riscv_create_iommu_sys().

[1] https://docs.riscv.org/reference/server-soc/v1.0/server_soc_requirements.html

Fixes c2fa4320803b ("hw/riscv: server platform reference machine")
---
 hw/riscv/riscv-iommu-sys.c     | 4 ++++
 hw/riscv/riscv-iommu.h         | 1 +
 hw/riscv/server_platform_ref.c | 2 ++
 hw/riscv/virt.c                | 3 ++-
 4 files changed, 9 insertions(+), 1 deletion(-)
hw/riscv/riscv-iommu-sys.c +4 -0
index 258c171efd..3a9e22080a 100644
@@ -219,6 +219,7 @@ static void riscv_iommu_sys_init(Object *obj)
 
 DeviceState *riscv_create_iommu_sys(DeviceState *mmio_irqchip,
                                     hwaddr addr, int base_irq,
+                                    int hpm_counters,
                                     bool is_32_bit)
 {
     DeviceState *iommu_sys = qdev_new(TYPE_RISCV_IOMMU_SYS);
@@ -237,6 +238,9 @@ DeviceState *riscv_create_iommu_sys(DeviceState *mmio_irqchip,
                              is_32_bit ? 34 : 56,
                              &error_fatal);
 
+    object_property_set_int(OBJECT(iommu_sys), "hpm-counters",
+                            hpm_counters, &error_abort);
+
     sysbus_realize_and_unref(SYS_BUS_DEVICE(iommu_sys), &error_fatal);
 
     return iommu_sys;
hw/riscv/riscv-iommu.h +1 -0
index 403d10b321..0f755b0992 100644
@@ -107,6 +107,7 @@ void riscv_iommu_notify(RISCVIOMMUState *s, int vec_type);
 void riscv_iommu_fault(RISCVIOMMUState *s, struct riscv_iommu_fq_record *ev);
 DeviceState *riscv_create_iommu_sys(DeviceState *mmio_irqchip,
                                     hwaddr addr, int base_irq,
+                                    int hpm_counters,
                                     bool is_32_bit);
 
 typedef struct RISCVIOMMUContext RISCVIOMMUContext;
hw/riscv/server_platform_ref.c +2 -0
index 22b3149ee8..fb770cf6fb 100644
@@ -67,6 +67,7 @@
 #define SYSCON_POWEROFF                        0x2
 
 #define RVSERVER_PLATFORM_BUS_NUM_IRQS         8
+#define RVSERVER_IOMMU_HPM_COUNTERS            4
 
 #define TYPE_RISCV_SERVER_REF_MACHINE MACHINE_TYPE_NAME("riscv-server-ref")
 OBJECT_DECLARE_SIMPLE_TYPE(RISCVServerRefMachineState, RISCV_SERVER_REF_MACHINE)
@@ -641,6 +642,7 @@ static void rvserver_ref_machine_init(MachineState *machine)
     }
 
     riscv_create_iommu_sys(mmio_irqchip, s->memmap[RVSERVER_IOMMU_SYS].base,
+                           RVSERVER_IOMMU_HPM_COUNTERS,
                            IOMMU_SYS_IRQ, false);
 
     s->machine_done.notify = rvserver_ref_machine_done;
hw/riscv/virt.c +2 -1
index dceb3ff55e..016003d73d 100644
@@ -962,7 +962,8 @@ static void virt_machine_init(MachineState *machine)
 
     if (virt_is_iommu_sys_enabled(s)) {
         riscv_create_iommu_sys(mmio_irqchip, s->memmap[VIRT_IOMMU_SYS].base,
-                               IOMMU_SYS_IRQ, riscv_is_32bit(&s->soc[0]));
+                               IOMMU_SYS_IRQ, RISCV_IOMMU_IOCOUNT_NUM,
+                               riscv_is_32bit(&s->soc[0]));
     }
 
     s->machine_done.notify = virt_machine_done;
Signature · 1 line
2.43.0
Reviewed-by on v3 1/5
#2 lore raw

Re: [PATCH v3 1/5] hw/riscv: allow machines to set 'hpm-counters' for riscv-iommu-sys

Quoted 27 lines · Daniel Henrique Barboza

The riscv server soc requirements [1] dictates in rule "IOM_200" that the IOMMU must have at least 4 event counters.  As it stands today we're
creating an iommu-sys device with RISCV_IOMMU_IOCOUNT_NUM (31) counters.

Following the design of setting just the minimal spec requirements, set
hpm-counters to 4.  We're doing that by adding a new argument in riscv_create_iommu_sys().  In case more IOMMU parameters need to tweaked
in the device we might consider a different approach, but for now this
suffices.

The hpm-counters value used in the 'virt' board is default val from riscv-iommu, i.e. there's no change in 'virt' board configuration with
this patch.

Note that the 'Fixes' tag points to the riscv-server-ref initial commit
because the IOM_200 rule should have been there from the start. There's
nothing inherently wrong with the initial commit for riscv_create_iommu_sys().

Quoted 6 lines

[1]
https://docs.riscv.org/reference/server-soc/v1.0/server_soc_requirements.html

Fixes c2fa4320803b ("hw/riscv: server platform reference machine")
Signed-off-by Daniel Henrique Barboza

<[email protected]>

Alistair

Quoted 88 lines

---
 hw/riscv/riscv-iommu-sys.c     | 4 ++++
 hw/riscv/riscv-iommu.h         | 1 +
 hw/riscv/server_platform_ref.c | 2 ++
 hw/riscv/virt.c                | 3 ++-

 4 files changed, 9 insertions(+), 1 deletion(-)
hw/riscv/riscv-iommu-sys.c +0 -0
index 258c171efd..3a9e22080a 100644
@@ -219,6 +219,7 @@ static void riscv_iommu_sys_init(Object *obj)


 DeviceState *riscv_create_iommu_sys(DeviceState *mmio_irqchip, hwaddr addr, int base_irq, +                                    int hpm_counters, bool is_32_bit) {
     DeviceState *iommu_sys = qdev_new(TYPE_RISCV_IOMMU_SYS);

hw/riscv/riscv-iommu-sys.c +0 -0
@@ -237,6 +238,9 @@ DeviceState *riscv_create_iommu_sys(DeviceState
 *mmio_irqchip,
                               is_32_bit ? 34 : 56,
                               &error_fatal);


+    object_property_set_int(OBJECT(iommu_sys), "hpm-counters", +                            hpm_counters, &error_abort); +
     sysbus_realize_and_unref(SYS_BUS_DEVICE(iommu_sys), &error_fatal);

     return iommu_sys;

hw/riscv/riscv-iommu.h +0 -0
index 403d10b321..0f755b0992 100644
@@ -107,6 +107,7 @@ void riscv_iommu_notify(RISCVIOMMUState *s, int
 vec_type);

 void riscv_iommu_fault(RISCVIOMMUState *s, struct riscv_iommu_fq_record *ev);
 DeviceState *riscv_create_iommu_sys(DeviceState *mmio_irqchip, hwaddr addr, int base_irq, +                                    int hpm_counters, bool is_32_bit);
 typedef struct RISCVIOMMUContext RISCVIOMMUContext;

hw/riscv/server_platform_ref.c +0 -0
index 22b3149ee8..fb770cf6fb 100644
@@ -67,6 +67,7 @@
  #define SYSCON_POWEROFF                        0x2


 #define RVSERVER_PLATFORM_BUS_NUM_IRQS         8 +#define RVSERVER_IOMMU_HPM_COUNTERS            4

 #define TYPE_RISCV_SERVER_REF_MACHINE MACHINE_TYPE_NAME("riscv- server-ref") OBJECT_DECLARE_SIMPLE_TYPE(RISCVServerRefMachineState, RISCV_SERVER_REF_MACHINE)

hw/riscv/server_platform_ref.c +0 -0
@@ -641,6 +642,7 @@ static void
 rvserver_ref_machine_init(MachineState *machine)
      }


     riscv_create_iommu_sys(mmio_irqchip, s-

Quoted 1 line

memmap[RVSERVER_IOMMU_SYS].base,

+                           RVSERVER_IOMMU_HPM_COUNTERS, IOMMU_SYS_IRQ, false);
     s->machine_done.notify = rvserver_ref_machine_done;

hw/riscv/virt.c +0 -0
index dceb3ff55e..016003d73d 100644
@@ -962,7 +962,8 @@ static void virt_machine_init(MachineState
 *machine)


     if (virt_is_iommu_sys_enabled(s)) {
         riscv_create_iommu_sys(mmio_irqchip, s-

Quoted 1 line

memmap[VIRT_IOMMU_SYS].base,

-                               IOMMU_SYS_IRQ, riscv_is_32bit(&s-

Quoted 1 line

soc[0]));

+                               IOMMU_SYS_IRQ, RISCV_IOMMU_IOCOUNT_NUM,
+                               riscv_is_32bit(&s->soc[0])); }

     s->machine_done.notify = virt_machine_done;

Reviewed-by on v3 1/5
#3 lore raw

Re: [PATCH v3 1/5] hw/riscv: allow machines to set 'hpm-counters' for riscv-iommu-sys

In reply to Daniel Henrique Barboza
Quoted 19 lines · Daniel Henrique Barboza

The riscv server soc requirements [1] dictates in rule "IOM_200" that the IOMMU must have at least 4 event counters. As it stands today we're creating an iommu-sys device with RISCV_IOMMU_IOCOUNT_NUM (31) counters.

Following the design of setting just the minimal spec requirements, set hpm-counters to 4. We're doing that by adding a new argument in riscv_create_iommu_sys(). In case more IOMMU parameters need to tweaked in the device we might consider a different approach, but for now this suffices.

The hpm-counters value used in the 'virt' board is default val from riscv-iommu, i.e. there's no change in 'virt' board configuration with this patch.

Note that the 'Fixes' tag points to the riscv-server-ref initial commit because the IOM_200 rule should have been there from the start. There's nothing inherently wrong with the initial commit for riscv_create_iommu_sys().

Quoted 4 lines

[1] https://docs.riscv.org/reference/server-soc/v1.0/server_soc_requirements.html

Fixes c2fa4320803b ("hw/riscv: server platform reference machine")

Thanks,
Nutty

Quoted 75 lines
---
  hw/riscv/riscv-iommu-sys.c     | 4 ++++
  hw/riscv/riscv-iommu.h         | 1 +
  hw/riscv/server_platform_ref.c | 2 ++
  hw/riscv/virt.c                | 3 ++-
  4 files changed, 9 insertions(+), 1 deletion(-)
hw/riscv/riscv-iommu-sys.c +4 -0
index 258c171efd..3a9e22080a 100644
@@ -219,6 +219,7 @@ static void riscv_iommu_sys_init(Object *obj)
 
  DeviceState *riscv_create_iommu_sys(DeviceState *mmio_irqchip,
                                      hwaddr addr, int base_irq,
+                                    int hpm_counters,
                                      bool is_32_bit)
  {
      DeviceState *iommu_sys = qdev_new(TYPE_RISCV_IOMMU_SYS);
@@ -237,6 +238,9 @@ DeviceState *riscv_create_iommu_sys(DeviceState *mmio_irqchip,
                               is_32_bit ? 34 : 56,
                               &error_fatal);
 
+    object_property_set_int(OBJECT(iommu_sys), "hpm-counters",
+                            hpm_counters, &error_abort);
+
      sysbus_realize_and_unref(SYS_BUS_DEVICE(iommu_sys), &error_fatal);
 
      return iommu_sys;
hw/riscv/riscv-iommu.h +1 -0
index 403d10b321..0f755b0992 100644
@@ -107,6 +107,7 @@ void riscv_iommu_notify(RISCVIOMMUState *s, int vec_type);
  void riscv_iommu_fault(RISCVIOMMUState *s, struct riscv_iommu_fq_record *ev);
  DeviceState *riscv_create_iommu_sys(DeviceState *mmio_irqchip,
                                      hwaddr addr, int base_irq,
+                                    int hpm_counters,
                                      bool is_32_bit);
 
  typedef struct RISCVIOMMUContext RISCVIOMMUContext;
hw/riscv/server_platform_ref.c +2 -0
index 22b3149ee8..fb770cf6fb 100644
@@ -67,6 +67,7 @@
  #define SYSCON_POWEROFF                        0x2
 
  #define RVSERVER_PLATFORM_BUS_NUM_IRQS         8
+#define RVSERVER_IOMMU_HPM_COUNTERS            4
 
  #define TYPE_RISCV_SERVER_REF_MACHINE MACHINE_TYPE_NAME("riscv-server-ref")
  OBJECT_DECLARE_SIMPLE_TYPE(RISCVServerRefMachineState, RISCV_SERVER_REF_MACHINE)
@@ -641,6 +642,7 @@ static void rvserver_ref_machine_init(MachineState *machine)
      }
 
      riscv_create_iommu_sys(mmio_irqchip, s->memmap[RVSERVER_IOMMU_SYS].base,
+                           RVSERVER_IOMMU_HPM_COUNTERS,
                             IOMMU_SYS_IRQ, false);
 
      s->machine_done.notify = rvserver_ref_machine_done;
hw/riscv/virt.c +2 -1
index dceb3ff55e..016003d73d 100644
@@ -962,7 +962,8 @@ static void virt_machine_init(MachineState *machine)
 
      if (virt_is_iommu_sys_enabled(s)) {
          riscv_create_iommu_sys(mmio_irqchip, s->memmap[VIRT_IOMMU_SYS].base,
-                               IOMMU_SYS_IRQ, riscv_is_32bit(&s->soc[0]));
+                               IOMMU_SYS_IRQ, RISCV_IOMMU_IOCOUNT_NUM,
+                               riscv_is_32bit(&s->soc[0]));
      }
 
      s->machine_done.notify = virt_machine_done;
#4 lore raw

PATCH v3 2/5 hw/riscv: make UART FDT helper consider baud rate

In reply to Daniel Henrique Barboza

riscv_create_fdt_uart() is defaulting to a 3.6864 Mhz clock, which Linux will interpret as a 230400 base baud serial.

We need more flexibility to set a different baud rate for UART devices. Add an optional 'base_baud' parameter that allows callers to set a baud rate for the related device. We're keeping the existing default in case the caller does not care to provide a base baud.

---
 hw/riscv/fdt-common.c          | 19 +++++++++++++++++--
 hw/riscv/server_platform_ref.c |  1 +
 hw/riscv/virt.c                |  4 ++--
 include/hw/riscv/fdt-common.h  |  1 +
 4 files changed, 21 insertions(+), 4 deletions(-)
hw/riscv/fdt-common.c +17 -2
index e90502b1bc..685b64531b 100644
@@ -21,7 +21,11 @@
 #include "hw/pci/pcie_host.h"
 #include "hw/riscv/aia.h"
 
-#define UART_STD_CLOCK_FREQ 3686400 /* 3.6864 MHz */
+ /*
+  * This 3.6864 MHz default clock results in a base
+  * baud of 230400 symbols/second.
+  */
+#define UART_STD_CLOCK_FREQ 3686400
 
 void *riscv_create_board_device_tree(const char *model, const char *compatible,
                                      int *fdt_size)
@@ -798,11 +802,14 @@ char *riscv_fdt_get_uart_nodename(hwaddr addr)
     return g_strdup_printf("/soc/serial@%"HWADDR_PRIx, addr);
 }
 
+/* If base_baud = 0 this function assumes a base baud of 230400.  */
 void riscv_create_fdt_uart(void *fdt, const MemMapEntry *uart_mem,
                            int uart_irq, int aia_type,
+                           int base_baud,
                            uint32_t irq_phandle)
 {
     g_autofree char *name = riscv_fdt_get_uart_nodename(uart_mem->base);
+    uint64_t clock_freq = UART_STD_CLOCK_FREQ;
 
     qemu_fdt_add_subnode(fdt, name);
     qemu_fdt_setprop_string(fdt, name, "compatible", "ns16550a");
@@ -810,7 +817,15 @@ void riscv_create_fdt_uart(void *fdt, const MemMapEntry *uart_mem,
                                  2, uart_mem->base,
                                  2, uart_mem->size);
 
-    qemu_fdt_setprop_cell(fdt, name, "clock-frequency", UART_STD_CLOCK_FREQ);
+    if (base_baud != 0) {
+        /*
+         * The base baud formula is base_baud = clock_freq / 16,
+         * ergo clock_freq = base_baud * 16.
+         */
+        clock_freq = base_baud * 16;
+    }
+
+    qemu_fdt_setprop_cell(fdt, name, "clock-frequency", clock_freq);
     qemu_fdt_setprop_cell(fdt, name, "interrupt-parent", irq_phandle);
 
     if (aia_type == AIA_TYPE_NONE) {
hw/riscv/server_platform_ref.c +1 -0
index fb770cf6fb..5cb55a43a8 100644
@@ -320,6 +320,7 @@ static void finalize_fdt(RISCVServerRefMachineState *s)
 
     riscv_create_fdt_uart(ms->fdt, &rvserver_ref_memmap[RVSERVER_UART0],
                           RVSERVER_UART0_IRQ, AIA_TYPE_APLIC_IMSIC,
+                          0,
                           irq_mmio_phandle);
     name = riscv_fdt_get_uart_nodename(rvserver_ref_memmap[RVSERVER_UART0].base);
     qemu_fdt_setprop_string(ms->fdt, "/chosen", "stdout-path", name);
hw/riscv/virt.c +2 -2
index 016003d73d..9eccf62d4f 100644
@@ -398,11 +398,11 @@ static void create_fdt_uarts(RISCVVirtState *s, uint32_t irq_mmio_phandle)
 
     if (s->uart1_present) {
         riscv_create_fdt_uart(ms->fdt, &s->memmap[VIRT_UART1],
-                              UART1_IRQ, s->aia_type, irq_mmio_phandle);
+                              UART1_IRQ, 0, s->aia_type, irq_mmio_phandle);
     }
 
     riscv_create_fdt_uart(ms->fdt, &s->memmap[VIRT_UART0], UART0_IRQ,
-                          s->aia_type, irq_mmio_phandle);
+                          s->aia_type, 0, irq_mmio_phandle);
 
     name = riscv_fdt_get_uart_nodename(s->memmap[VIRT_UART0].base);
     qemu_fdt_setprop_string(ms->fdt, "/chosen", "stdout-path", name);
include/hw/riscv/fdt-common.h +1 -0
index b3b14ada0a..2a06aedb61 100644
@@ -131,6 +131,7 @@ char *riscv_fdt_get_aplic_nodename(hwaddr addr);
 char *riscv_fdt_get_uart_nodename(hwaddr addr);
 void riscv_create_fdt_uart(void *fdt, const MemMapEntry *uart_mem,
                            int uart_irq, int aia_type,
+                           int base_baud,
                            uint32_t irq_phandle);
 void riscv_create_fdt_rtc(void *fdt, const MemMapEntry *rtc_mem,
                           int rtc_irq, int aia_type,
Signature · 1 line
2.43.0
Reviewed-by on v3 2/5
#5 lore raw

Re: [PATCH v3 2/5] hw/riscv: make UART FDT helper consider baud rate

Quoted 83 lines · Daniel Henrique Barboza

riscv_create_fdt_uart() is defaulting to a 3.6864 Mhz clock, which Linux will interpret as a 230400 base baud serial.

We need more flexibility to set a different baud rate for UART devices. Add an optional 'base_baud' parameter that allows callers to set a baud rate for the related device. We're keeping the existing default in case the caller does not care to provide a base baud.

---
  hw/riscv/fdt-common.c          | 19 +++++++++++++++++--
  hw/riscv/server_platform_ref.c |  1 +
  hw/riscv/virt.c                |  4 ++--
  include/hw/riscv/fdt-common.h  |  1 +
  4 files changed, 21 insertions(+), 4 deletions(-)
hw/riscv/fdt-common.c +17 -2
index e90502b1bc..685b64531b 100644
@@ -21,7 +21,11 @@
  #include "hw/pci/pcie_host.h"
  #include "hw/riscv/aia.h"
 
-#define UART_STD_CLOCK_FREQ 3686400 /* 3.6864 MHz */
+ /*
+  * This 3.6864 MHz default clock results in a base
+  * baud of 230400 symbols/second.
+  */
+#define UART_STD_CLOCK_FREQ 3686400
 
  void *riscv_create_board_device_tree(const char *model, const char *compatible,
                                       int *fdt_size)
@@ -798,11 +802,14 @@ char *riscv_fdt_get_uart_nodename(hwaddr addr)
      return g_strdup_printf("/soc/serial@%"HWADDR_PRIx, addr);
  }
 
+/* If base_baud = 0 this function assumes a base baud of 230400.  */
  void riscv_create_fdt_uart(void *fdt, const MemMapEntry *uart_mem,
                             int uart_irq, int aia_type,
+                           int base_baud,
                             uint32_t irq_phandle)
  {
      g_autofree char *name = riscv_fdt_get_uart_nodename(uart_mem->base);
+    uint64_t clock_freq = UART_STD_CLOCK_FREQ;
 
      qemu_fdt_add_subnode(fdt, name);
      qemu_fdt_setprop_string(fdt, name, "compatible", "ns16550a");
@@ -810,7 +817,15 @@ void riscv_create_fdt_uart(void *fdt, const MemMapEntry *uart_mem,
                                   2, uart_mem->base,
                                   2, uart_mem->size);
 
-    qemu_fdt_setprop_cell(fdt, name, "clock-frequency", UART_STD_CLOCK_FREQ);
+    if (base_baud != 0) {
+        /*
+         * The base baud formula is base_baud = clock_freq / 16,
+         * ergo clock_freq = base_baud * 16.
+         */
+        clock_freq = base_baud * 16;
+    }
+
+    qemu_fdt_setprop_cell(fdt, name, "clock-frequency", clock_freq);
      qemu_fdt_setprop_cell(fdt, name, "interrupt-parent", irq_phandle);
 
      if (aia_type == AIA_TYPE_NONE) {
hw/riscv/server_platform_ref.c +1 -0
index fb770cf6fb..5cb55a43a8 100644
@@ -320,6 +320,7 @@ static void finalize_fdt(RISCVServerRefMachineState *s)
 
      riscv_create_fdt_uart(ms->fdt, &rvserver_ref_memmap[RVSERVER_UART0],
                            RVSERVER_UART0_IRQ, AIA_TYPE_APLIC_IMSIC,
+                          0,
                            irq_mmio_phandle);
      name = riscv_fdt_get_uart_nodename(rvserver_ref_memmap[RVSERVER_UART0].base);
      qemu_fdt_setprop_string(ms->fdt, "/chosen", "stdout-path", name);
hw/riscv/virt.c +0 -0
index 016003d73d..9eccf62d4f 100644

hw/riscv/virt.c static void create_fdt_uarts(RISCVVirtState *s, uint32_t irq_mmio_phandle) · line 401

Quoted 5 lines
hw/riscv/virt.c +1 -1
@@ -398,11 +398,11 @@ static void create_fdt_uarts(RISCVVirtState *s, uint32_t irq_mmio_phandle)
 
      if (s->uart1_present) {
          riscv_create_fdt_uart(ms->fdt, &s->memmap[VIRT_UART1],
-                              UART1_IRQ, s->aia_type, irq_mmio_phandle);
+                              UART1_IRQ, 0, s->aia_type, irq_mmio_phandle);

Seems the above should be as follows:

+ UART1_IRQ, s->aia_type, 0, irq_mmio_phandle);

Otherwise,

Thanks,
Nutty

Quoted 20 lines
hw/riscv/virt.c +1 -1
      }
 
      riscv_create_fdt_uart(ms->fdt, &s->memmap[VIRT_UART0], UART0_IRQ,
-                          s->aia_type, irq_mmio_phandle);
+                          s->aia_type, 0, irq_mmio_phandle);
 
      name = riscv_fdt_get_uart_nodename(s->memmap[VIRT_UART0].base);
      qemu_fdt_setprop_string(ms->fdt, "/chosen", "stdout-path", name);
include/hw/riscv/fdt-common.h +1 -0
index b3b14ada0a..2a06aedb61 100644
@@ -131,6 +131,7 @@ char *riscv_fdt_get_aplic_nodename(hwaddr addr);
  char *riscv_fdt_get_uart_nodename(hwaddr addr);
  void riscv_create_fdt_uart(void *fdt, const MemMapEntry *uart_mem,
                             int uart_irq, int aia_type,
+                           int base_baud,
                             uint32_t irq_phandle);
  void riscv_create_fdt_rtc(void *fdt, const MemMapEntry *rtc_mem,
                            int rtc_irq, int aia_type,
#6 lore raw

PATCH v3 3/5 hw/riscv/server_platform_ref: fix UART baud rate

In reply to Daniel Henrique Barboza

The riscv-server 1.0 spec requires an UART with 115200 baud, per rule "HPER_020" described in [1].

At this moment we're doing two things: the FDT is being created using the default UART base baud of 230400, and the device itself is being created using a baud of 399193. This odd value was inherited from the RISC-V 'virt' machine when implementing the first interaction of the riscv-server-ref board. Linux doesn't seem to care: dmesg reports a base baud of 230400, a value derived from what we're writing in the DT, and the serial seems to work fine.

Straight everything up by setting the required base baud of 115200 everywhere applicable. And for good measure let's also change the boot test to be sure that userpace is reading the intended serial base baud.

[1] https://docs.riscv.org/reference/server-soc/v1.0/server_soc_requirements.html

Fixes c2fa4320803b ("hw/riscv: server platform reference machine")
---
 hw/riscv/server_platform_ref.c              | 8 +++++---
 tests/functional/riscv64/test_server_ref.py | 3 +++
 2 files changed, 8 insertions(+), 3 deletions(-)
hw/riscv/server_platform_ref.c +5 -3
index 5cb55a43a8..5fa3130a25 100644
@@ -68,6 +68,7 @@
 
 #define RVSERVER_PLATFORM_BUS_NUM_IRQS         8
 #define RVSERVER_IOMMU_HPM_COUNTERS            4
+#define RVSERVER_UART_BASE_BAUD                115200
 
 #define TYPE_RISCV_SERVER_REF_MACHINE MACHINE_TYPE_NAME("riscv-server-ref")
 OBJECT_DECLARE_SIMPLE_TYPE(RISCVServerRefMachineState, RISCV_SERVER_REF_MACHINE)
@@ -320,7 +321,7 @@ static void finalize_fdt(RISCVServerRefMachineState *s)
 
     riscv_create_fdt_uart(ms->fdt, &rvserver_ref_memmap[RVSERVER_UART0],
                           RVSERVER_UART0_IRQ, AIA_TYPE_APLIC_IMSIC,
-                          0,
+                          RVSERVER_UART_BASE_BAUD,
                           irq_mmio_phandle);
     name = riscv_fdt_get_uart_nodename(rvserver_ref_memmap[RVSERVER_UART0].base);
     qemu_fdt_setprop_string(ms->fdt, "/chosen", "stdout-path", name);
@@ -618,8 +619,9 @@ static void rvserver_ref_machine_init(MachineState *machine)
                                                     RVSERVER_PLATFORM_BUS_NUM_IRQS);
 
     serial_mm_init(system_memory, memmap[RVSERVER_UART0].base,
-        0, qdev_get_gpio_in(mmio_irqchip, RVSERVER_UART0_IRQ), 399193,
-        serial_hd(0), DEVICE_LITTLE_ENDIAN);
+                   0, qdev_get_gpio_in(mmio_irqchip, RVSERVER_UART0_IRQ),
+                   RVSERVER_UART_BASE_BAUD,
+                   serial_hd(0), DEVICE_LITTLE_ENDIAN);
 
     sysbus_create_simple("goldfish_rtc", memmap[RVSERVER_RTC].base,
         qdev_get_gpio_in(mmio_irqchip, RVSERVER_RTC_IRQ));
tests/functional/riscv64/test_server_ref.py +3 -0
index ad29094dbe..fa7225ccc1 100755
@@ -71,6 +71,9 @@ def do_test_boot_linux_test(self, tpmstate_dir=None):
         wait_for_console_pattern(self, 'Linux version')
         wait_for_console_pattern(self, 'Machine model: RISC-V Server Platform')
 
+        # Check that we have the intended base baud for the serial
+        wait_for_console_pattern(self, 'base_baud = 115200')
+
         # Test e1000e network card functionality
         wait_for_console_pattern(self, 'e1000e')
         wait_for_console_pattern(self, 'Network Connection')
Signature · 1 line
2.43.0
#7 lore raw

PATCH v3 4/5 hw/riscv/virt.c: fix base baud in serial_mm_init()

In reply to Daniel Henrique Barboza

We've been using a base baud of 399193 to create the UART devices while, at the same time, reporting a clock frequency that represents a 230400 baud rate.

This pattern dates back to the initial RISC-V port and so far seems to be doing okay. Linux thinks that we have a 230400 baud serials and nothing seems of. Or better yet: no one has complained about a potential bug in the UART devices since 2018.

All this said, set the UARTs baud rate in serial_mm_init() to match what Linux has been seeing all this time.

Fixes 04331d0b56a0 ("RISC-V VirtIO Machine")
---
 hw/riscv/virt.c         | 10 ++++++----
 include/hw/riscv/virt.h |  2 ++
 2 files changed, 8 insertions(+), 4 deletions(-)
hw/riscv/virt.c +6 -4
index 9eccf62d4f..9c621b5939 100644
@@ -929,13 +929,15 @@ static void virt_machine_init(MachineState *machine)
         VIRT_PLATFORM_BUS_NUM_IRQS);
 
     serial_mm_init(system_memory, s->memmap[VIRT_UART0].base,
-        0, qdev_get_gpio_in(mmio_irqchip, UART0_IRQ), 399193,
-        serial_hd(0), DEVICE_LITTLE_ENDIAN);
+                   0, qdev_get_gpio_in(mmio_irqchip, UART0_IRQ),
+                   RISCV_VIRT_UART_BASE_BAUD,
+                   serial_hd(0), DEVICE_LITTLE_ENDIAN);
 
     if (serial_hd(1)) {
         serial_mm_init(system_memory, s->memmap[VIRT_UART1].base,
-            0, qdev_get_gpio_in(mmio_irqchip, UART1_IRQ), 399193,
-            serial_hd(1), DEVICE_LITTLE_ENDIAN);
+                       0, qdev_get_gpio_in(mmio_irqchip, UART1_IRQ),
+                       RISCV_VIRT_UART_BASE_BAUD,
+                       serial_hd(1), DEVICE_LITTLE_ENDIAN);
         s->uart1_present = true;
     }
 
include/hw/riscv/virt.h +2 -0
index 6e4fbf4b64..63907d7362 100644
@@ -121,6 +121,8 @@ enum {
 #define VIRT_PLIC_SIZE(__num_context) \
     (VIRT_PLIC_CONTEXT_BASE + (__num_context) * VIRT_PLIC_CONTEXT_STRIDE)
 
+#define RISCV_VIRT_UART_BASE_BAUD  230400
+
 bool virt_is_iommu_sys_enabled(RISCVVirtState *s);
 void riscv_virt_acpi_setup(RISCVVirtState *vms);
 
Signature · 1 line
2.43.0
#8 lore raw

PATCH v3 5/5 MAINTAINERS: add contact for the RISC-V server-ref machine

In reply to Daniel Henrique Barboza

Make it clearer that this is a board that is actively maintained.

---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index 15942aaba3..ba026ded6e 100644
@@ -1914,6 +1914,14 @@ F: include/hw/riscv/cv1800b.h
 F: tests/functional/riscv64/test_milkv_duo.py
 F: tests/qtest/milkv-duo-test.c
 
+RISC-V Server Reference Platform (riscv-server-ref) machines
+M: Daniel Henrique Barboza <[email protected]>
+L: [email protected]
+S: Maintained
+F: docs/system/riscv/riscv-server-ref.rst
+F: hw/riscv/server_platform_ref.c
+F: tests/functional/riscv64/test_server_ref.py
+
 RX Machines
 -----------
 rx-gdbsim
Signature · 1 line
2.43.0
#9 lore raw
In reply to Daniel Henrique Barboza
Quoted 24 lines · Daniel Henrique Barboza

Hi,

Sashiko pointed out that patch 1 was missing a Fixes tag.  We're adding
it in this version.

However, Sashiko wants the tag to point to a commit that introduced the
riscv_create_iommu_sys() helper.  This isn't accurate: that commit added
the helper support and use in the 'virt' machine, an use that doesn't care about hpm counters, so I don't see that commit as being faulty. I
pointed to the commit that introduced the riscv-server-ref emulation instead since this hpm counter setting should've been there from the start.

No other changes made.  Patches based on master.

Changes in v3:
- patch 1: added "Fixes" tag.
- v2 link:
https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 6 lines

Daniel Henrique Barboza (5):
  hw/riscv: allow machines to set 'hpm-counters' for riscv-iommu-sys hw/riscv: make UART FDT helper consider baud rate hw/riscv/server_platform_ref: fix UART baud rate hw/riscv/virt.c: fix base baud in serial_mm_init()
  MAINTAINERS: add contact for the RISC-V server-ref machine

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 11 lines

 MAINTAINERS                                 |  8 ++++++++ hw/riscv/fdt-common.c                       | 19 +++++++++++++++++-- hw/riscv/riscv-iommu-sys.c                  |  4 ++++ hw/riscv/riscv-iommu.h                      |  1 + hw/riscv/server_platform_ref.c              |  9 +++++++-- hw/riscv/virt.c                             | 17 ++++++++++------- include/hw/riscv/fdt-common.h               |  1 + include/hw/riscv/virt.h                     |  2 ++ tests/functional/riscv64/test_server_ref.py |  3 +++

 9 files changed, 53 insertions(+), 11 deletions(-)