hw/riscv: riscv-server-ref refinements
cover hw/riscv: riscv-server-ref refinements
Hello,
This is a small and trivial follow-up after the upstreaming of the base model for the riscv-server-ref board.
Patch 5 contains a fix for the virt machine similar to what was done in the riscv-server-ref machine in patch 4. Note that there were no test changes for the virt change, in contrast to the equivalent riscv-server-ref patch, because there were no Linux/userspace visible changes in the baud rate for the virt case.
Patches based on alistair/riscv-to-apply.next.
Daniel Henrique Barboza (6):
hw/riscv: do not realize the device in riscv_create_iommu_sys() hw/riscv/server_platform_ref: set iommu hpm counters to 4 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 | 3 +-- hw/riscv/server_platform_ref.c | 18 ++++++++++++---- hw/riscv/virt.c | 23 ++++++++++++++------- include/hw/riscv/fdt-common.h | 1 + include/hw/riscv/virt.h | 2 ++ tests/functional/riscv64/test_server_ref.py | 3 +++ 8 files changed, 61 insertions(+), 16 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/6 hw/riscv: do not realize the device in riscv_create_iommu_sys()
The riscv-iommu-sys device inherits all properties from its associated riscv-iommu device via qdev_alias_all_properties() during sys_init().
We're also providing riscv_create_iommu_sys(), a helper to instantiate the device and avoid duplicating code between boards. In its current state the helper is realizing the device before returning it to the caller, prevents any additional setup of the device (we can't change device props after realize).
Split the realization code from the helper and make the boards realize the device manually. It's a small inconvenience to pay to be able to config the iommu-sys device.
--- hw/riscv/riscv-iommu-sys.c | 3 +-- hw/riscv/server_platform_ref.c | 7 +++++-- hw/riscv/virt.c | 9 +++++++-- 3 files changed, 13 insertions(+), 6 deletions(-)
hw/riscv/riscv-iommu-sys.c +1 -2
@@ -217,6 +217,7 @@ static void riscv_iommu_sys_init(Object *obj)riscv_iommu_set_cap_igs (iommu,RISCV_IOMMU_CAP_IGS_BOTH ); } +/* Note: the returned iommu_sys device needs to be realized. */ DeviceState *riscv_create_iommu_sys (DeviceState *mmio_irqchip,hwaddr addr,int base_irq,bool is_32_bit)
@@ -237,8 +238,6 @@ DeviceState *riscv_create_iommu_sys(DeviceState *mmio_irqchip, is_32_bit ?34 :56 , &error_fatal); -sysbus_realize_and_unref (SYS_BUS_DEVICE (iommu_sys), &error_fatal); -return iommu_sys; }
hw/riscv/server_platform_ref.c +5 -2
@@ -481,6 +481,7 @@ static void rvserver_ref_machine_init(MachineState *machine)MemoryRegion *mask_rom =g_new (MemoryRegion,1 );MemoryRegion *reset_syscon_io =g_new (MemoryRegion,1 );DeviceState *mmio_irqchip, *pcie_irqchip; +DeviceState *iommu_sys;int i, base_hartid, hart_count;int socket_count =riscv_socket_count (machine);int imsic_bits;
@@ -635,8 +636,10 @@ static void rvserver_ref_machine_init(MachineState *machine)create_fdt (s, memmap); } -riscv_create_iommu_sys (mmio_irqchip, s->memmap[RVSERVER_IOMMU_SYS ].base, -IOMMU_SYS_IRQ , false); + iommu_sys =riscv_create_iommu_sys (mmio_irqchip, + s->memmap[RVSERVER_IOMMU_SYS ].base, +IOMMU_SYS_IRQ , false); +sysbus_realize_and_unref (SYS_BUS_DEVICE (iommu_sys), &error_fatal); s->machine_done.notify = rvserver_ref_machine_done;qemu_add_machine_init_done_notifier (&s->machine_done);
hw/riscv/virt.c +7 -2
@@ -940,8 +940,13 @@ 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 ])); +DeviceState *iommu_sys; + + iommu_sys =riscv_create_iommu_sys (mmio_irqchip, + s->memmap[VIRT_IOMMU_SYS ].base, +IOMMU_SYS_IRQ , +riscv_is_32bit (&s->soc[0 ])); +sysbus_realize_and_unref (SYS_BUS_DEVICE (iommu_sys), &error_fatal); } s->machine_done.notify = virt_machine_done;
Signature · 1 line
2.43.0
Re: [PATCH 1/6] hw/riscv: do not realize the device in riscv_create_iommu_sys()
Quoted 31 lines · Daniel Henrique Barboza
The riscv-iommu-sys device inherits all properties from its associated
riscv-iommu device viaqdev_alias_all_properties()duringsys_init().We're also providing
riscv_create_iommu_sys(), a helper to instantiate
the device and avoid duplicating code between boards. In its current state the helper is realizing the device before returning it to the caller, prevents any additional setup of the device (we can't change device props after realize).Split the realization code from the helper and make the boards realize
the device manually. It's a small inconvenience to pay to be able to config the iommu-sys device.Signed-off-by: Daniel Henrique Barboza
<[email protected]>
---
hw/riscv/riscv-iommu-sys.c | 3 +--
hw/riscv/server_platform_ref.c | 7 +++++--
hw/riscv/virt.c | 9 +++++++--3 files changed, 13 insertions(+), 6 deletions(-)hw/riscv/riscv-iommu-sys.c +0
-0@@ -217,6 +217,7 @@ static void riscv_iommu_sys_init(Object *obj) riscv_iommu_set_cap_igs(iommu, RISCV_IOMMU_CAP_IGS_BOTH); }
Quoted 2 lines
+/* Note: the returnediommu_sysdevice needs to be realized. */
Is this really necessary just to set hpm-counters?
It seems like this is a bit brittle for one property
Alistair
Quoted 71 lines
DeviceState *riscv_create_iommu_sys(DeviceState
*mmio_irqchip, hwaddr addr, intbase_irq, boolis_32_bit)hw/riscv/riscv-iommu-sys.c +0
-0@@ -237,8 +238,6 @@ DeviceState *riscv_create_iommu_sys(DeviceState *mmio_irqchip, is_32_bit ? 34 : 56, &error_fatal);
-sysbus_realize_and_unref(SYS_BUS_DEVICE(iommu_sys), &error_fatal);
-
returniommu_sys;
}hw/riscv/server_platform_ref.c +1
-0@@ -481,6 +481,7 @@ static voidrvserver_ref_machine_init (MachineState *machine) MemoryRegion *mask_rom = g_new(MemoryRegion, 1); MemoryRegion *reset_syscon_io = g_new(MemoryRegion, 1); DeviceState *mmio_irqchip, *pcie_irqchip; + DeviceState *iommu_sys; int i, base_hartid, hart_count; int socket_count = riscv_socket_count(machine);int
imsic_bits;hw/riscv/server_platform_ref.c +0
-0@@ -635,8 +636,10 @@ static void rvserver_ref_machine_init(MachineState *machine) create_fdt(s, memmap); }
- riscv_create_iommu_sys(mmio_irqchip, s-Quoted 1 line
memmap[RVSERVER_IOMMU_SYS].base,
-
IOMMU_SYS_IRQ, false); +iommu_sys= riscv_create_iommu_sys(mmio_irqchip, + s-Quoted 1 line
memmap[RVSERVER_IOMMU_SYS].base,
+
IOMMU_SYS_IRQ, false); +sysbus_realize_and_unref(SYS_BUS_DEVICE(iommu_sys), &error_fatal);
s->machine_done.notify=rvserver_ref_machine_done;qemu_add_machine_init_done_notifier(&s->machine_done);hw/riscv/virt.c +0
-0@@ -940,8 +940,13 @@ 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]));
+ DeviceState
*iommu_sys;
+
+iommu_sys= 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]));
+
sysbus_realize_and_unref(SYS_BUS_DEVICE(iommu_sys), &error_fatal);
}
s->machine_done.notify=virt_machine_done;
Re: [PATCH 1/6] hw/riscv: do not realize the device in riscv_create_iommu_sys()
Quoted 33 lines · Alistair Francis
Quoted 32 lines · Daniel Henrique Barboza
The riscv-iommu-sys device inherits all properties from its associated
riscv-iommu device viaqdev_alias_all_properties()duringsys_init().We're also providing
riscv_create_iommu_sys(), a helper to instantiate
the device and avoid duplicating code between boards. In its current state the helper is realizing the device before returning it to the caller, prevents any additional setup of the device (we can't change device props after realize).Split the realization code from the helper and make the boards realize
the device manually. It's a small inconvenience to pay to be able to config the iommu-sys device.Signed-off-by: Daniel Henrique Barboza
<[email protected]>--- hw/riscv/riscv-iommu-sys.c | 3 +-- hw/riscv/server_platform_ref.c | 7 +++++-- hw/riscv/virt.c | 9 +++++++-- 3 files changed, 13 insertions(+), 6 deletions(-)hw/riscv/riscv-iommu-sys.c +0
-0@@ -217,6 +217,7 @@ static void riscv_iommu_sys_init(Object *obj) riscv_iommu_set_cap_igs(iommu, RISCV_IOMMU_CAP_IGS_BOTH); }
Quoted 5 lines
hw/riscv/riscv-iommu-sys.c static void riscv_iommu_sys_init(Object *obj) · line 220
Quoted 1 line
hw/riscv/riscv-iommu-sys.c +1
-0+/* Note: the returned iommu_sys device needs to be realized. */ Is this really necessary just to set hpm-counters?
It seems like this is a bit brittle for one property
If we want to just set 'hpm_counters' we can add a parameter in riscv_create_iommu_sys() and be done with it. In case we have the need to set other things in the future we can add additional parameters, even an 'IOMMUProps' struct like we do with the FDT stuff.
Or we can do what we're doing here and let the board set whatever they want by splitting init() and realize() of the device. Both are fine to me.
Thanks,
Daniel
Quoted 74 lines
Alistair
Quoted 71 lines
hw/riscv/riscv-iommu-sys.c +0
-2DeviceState *riscv_create_iommu_sys(DeviceState *mmio_irqchip, hwaddr addr, int base_irq, bool is_32_bit)@@ -237,8 +238,6 @@ DeviceState *riscv_create_iommu_sys(DeviceState *mmio_irqchip, is_32_bit ? 34 : 56, &error_fatal); - sysbus_realize_and_unref(SYS_BUS_DEVICE(iommu_sys), &error_fatal); - return iommu_sys;}
hw/riscv/server_platform_ref.c +1
-0@@ -481,6 +481,7 @@ static voidrvserver_ref_machine_init (MachineState *machine) MemoryRegion *mask_rom = g_new(MemoryRegion, 1); MemoryRegion *reset_syscon_io = g_new(MemoryRegion, 1); DeviceState *mmio_irqchip, *pcie_irqchip; + DeviceState *iommu_sys; int i, base_hartid, hart_count; int socket_count = riscv_socket_count(machine);int
imsic_bits;hw/riscv/server_platform_ref.c +4
-2@@ -635,8 +636,10 @@ static void rvserver_ref_machine_init(MachineState *machine) create_fdt(s, memmap); } - riscv_create_iommu_sys(mmio_irqchip, s- > memmap[RVSERVER_IOMMU_SYS].base, - IOMMU_SYS_IRQ, false); + iommu_sys = riscv_create_iommu_sys(mmio_irqchip, + s- > memmap[RVSERVER_IOMMU_SYS].base, + IOMMU_SYS_IRQ, false); + sysbus_realize_and_unref(SYS_BUS_DEVICE(iommu_sys),
&error_fatal);
s->machine_done.notify=rvserver_ref_machine_done;qemu_add_machine_init_done_notifier(&s->machine_done);hw/riscv/virt.c +4
-2@@ -940,8 +940,13 @@ 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])); + DeviceState *iommu_sys; + + iommu_sys = 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]));
+
sysbus_realize_and_unref(SYS_BUS_DEVICE(iommu_sys), &error_fatal);
}
s->machine_done.notify=virt_machine_done;
PATCH 2/6 hw/riscv/server_platform_ref: set iommu hpm counters to 4
In reply to Daniel Henrique BarbozaThe 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.
[1] https://docs.riscv.org/reference/server-soc/v1.0/server_soc_requirements.html
--- hw/riscv/server_platform_ref.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/riscv/server_platform_ref.c +4 -0
@@ -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 )
@@ -639,6 +640,9 @@ static void rvserver_ref_machine_init(MachineState *machine) iommu_sys =riscv_create_iommu_sys (mmio_irqchip, s->memmap[RVSERVER_IOMMU_SYS ].base,IOMMU_SYS_IRQ , false); + +object_property_set_int (OBJECT (iommu_sys),"hpm-counters" , +RVSERVER_IOMMU_HPM_COUNTERS , &error_abort);sysbus_realize_and_unref (SYS_BUS_DEVICE (iommu_sys), &error_fatal); s->machine_done.notify = rvserver_ref_machine_done;
Signature · 1 line
2.43.0
PATCH 3/6 hw/riscv: make UART FDT helper consider baud rate
In reply to Daniel Henrique Barbozariscv_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
@@ -22,7 +22,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 3686400void *riscv_create_board_device_tree (const char *model,const char *compatible,int *fdt_size)
@@ -807,11 +811,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" );
@@ -819,7 +826,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
@@ -315,6 +315,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
@@ -385,11 +385,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
@@ -132,6 +132,7 @@ void riscv_create_fdt_socket_aclint(void *fdt, ACLINTFdtProps *props,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
Re: [PATCH 3/6] hw/riscv: make UART FDT helper consider baud rate
Quoted 12 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.
Quoted 2 lines
Signed-off-by: Daniel Henrique Barboza
<[email protected]>
Alistair
Quoted 116 lines
---
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 +0
-0@@ -22,7 +22,11 @@ #include "hw/pci/pcie_host.h" #include "hw/riscv/aia.h"hw/riscv/fdt-common.c +5
-1-#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)hw/riscv/fdt-common.c +0
-0@@ -807,11 +811,14 @@ char *riscv_fdt_get_uart_nodename(hwaddr addr) return g_strdup_printf("/soc/serial@%"HWADDR_PRIx, addr); }
+/* Ifbase_baud= 0 this function assumes a base baud of 230400. */ void riscv_create_fdt_uart(void *fdt, const MemMapEntry*uart_mem, intuart_irq, intaia_type,
+ intbase_baud,
uint32_tirq_phandle)
{
g_autofreechar *name = riscv_fdt_get_uart_nodename(uart_mem-Quoted 1 line
base);
+
uint64_tclock_freq=UART_STD_CLOCK_FREQ;
qemu_fdt_add_subnode(fdt, name);qemu_fdt_setprop_string(fdt, name, "compatible", "ns16550a");hw/riscv/fdt-common.c +0
-0@@ -819,7 +826,15 @@ void riscv_create_fdt_uart(void *fdt, constMemMapEntry *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 isbase_baud=clock_freq/ 16, + * ergoclock_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 +0
-0@@ -315,6 +315,7 @@ static voidfinalize_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@@ -385,11 +385,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- renamed from include/hw/riscv/fdt-common.h +0
-0
common.h
indexeb9db8278d..ee664983f4100644include/hw/riscv/fdt-common.h +1
-0@@ -132,6 +132,7 @@ void riscv_create_fdt_socket_aclint(void *fdt,ACLINTFdtProps *props, 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, intaia_type,
PATCH 4/6 hw/riscv/server_platform_ref: fix UART baud rate
In reply to Daniel Henrique BarbozaThe 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
--- 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
@@ -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 )
@@ -315,7 +316,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);
@@ -614,8 +615,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
@@ -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
Re: [PATCH 4/6] hw/riscv/server_platform_ref: fix UART baud rate
Quoted 19 lines · 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.
Quoted 6 lines
[1]
https://docs.riscv.org/reference/server-soc/v1.0/server_soc_requirements.htmlFixes c2fa4320803b ("hw/riscv: server platform reference machine")Signed-off-by Daniel Henrique Barboza
Alistair
Quoted 67 lines
---
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 +0
-0@@ -68,6 +68,7 @@
#define RVSERVER_PLATFORM_BUS_NUM_IRQS 8 #define RVSERVER_IOMMU_HPM_COUNTERS 4 +#define RVSERVER_UART_BASE_BAUD 115200
#defineTYPE_RISCV_SERVER_REF_MACHINEMACHINE_TYPE_NAME("riscv- server-ref")OBJECT_DECLARE_SIMPLE_TYPE(RISCVServerRefMachineState, RISCV_SERVER_REF_MACHINE)hw/riscv/server_platform_ref.c +0
-0@@ -315,7 +316,7 @@ static voidfinalize_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);hw/riscv/server_platform_ref.c +0
-0@@ -614,8 +615,9 @@ static voidrvserver_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 +0
-0@@ -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 functionalitywait_for_console_pattern(self, 'e1000e')wait_for_console_pattern(self, 'Network Connection')
PATCH 5/6 hw/riscv/virt.c: fix base baud in serial_mm_init()
In reply to Daniel Henrique BarbozaWe'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.
--- hw/riscv/virt.c | 10 ++++++---- include/hw/riscv/virt.h | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-)
hw/riscv/virt.c +6 -4
@@ -908,13 +908,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
@@ -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_acpi_enabled (RISCVVirtState *s);bool virt_is_iommu_sys_enabled (RISCVVirtState *s);void virt_acpi_setup (RISCVVirtState *vms);
Signature · 1 line
2.43.0
Re: [PATCH 5/6] hw/riscv/virt.c: fix base baud in serial_mm_init()
Quoted 10 lines · 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.
Quoted 6 lines
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")Signed-off-by Daniel Henrique Barboza
Alistair
Quoted 44 lines
---
hw/riscv/virt.c | 10 ++++++----
include/hw/riscv/virt.h | 2 ++2 files changed, 8 insertions(+), 4 deletions(-)hw/riscv/virt.c +0
-0@@ -908,13 +908,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 +0
-0@@ -121,6 +121,8 @@ enum { #define VIRT_PLIC_SIZE(__num_context) \(
VIRT_PLIC_CONTEXT_BASE+ (__num_context) *VIRT_PLIC_CONTEXT_STRIDE)include/hw/riscv/virt.h +2
-0+#define RISCV_VIRT_UART_BASE_BAUD 230400 +bool
virt_is_acpi_enabled(RISCVVirtState *s); boolvirt_is_iommu_sys_enabled(RISCVVirtState *s); voidvirt_acpi_setup(RISCVVirtState *vms);
PATCH 6/6 MAINTAINERS: add contact for the RISC-V server-ref machine
In reply to Daniel Henrique BarbozaMake it clearer that this is a board that is actively maintained.
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -1897,6 +1897,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
Re: [PATCH 6/6] MAINTAINERS: add contact for the RISC-V server-ref machine
Quoted 4 lines · Daniel Henrique Barboza
Make it clearer that this is a board that is actively maintained.
Signed-off-by: Daniel Henrique Barboza
<[email protected]>
Alistair
Quoted 23 lines
---
MAINTAINERS | 8 ++++++++1 file changed, 8 insertions(+)MAINTAINERS +0
-0@@ -1897,6 +1897,14 @@ F: include/hw/riscv/cv1800b.hF:
tests/functional/riscv64/test_milkv_duo.py
F:tests/qtest/milkv-duo-test.cMAINTAINERS +8
-0+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
Re: [PATCH 6/6] MAINTAINERS: add contact for the RISC-V server-ref machine
In reply to Daniel Henrique BarbozaQuoted 3 lines · On Fri, 23 Oct 2026 13:09:13 -0300 Daniel Henrique Barboza…
Make it clearer that this is a board that is actively maintained.
Signed-off-by Daniel Henrique Barboza <[email protected]>
Thanks,
Chao
Quoted 25 lines
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)MAINTAINERS +8
-0@@ -1897,6 +1897,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-gdbsimSignature · 1 line
2.43.0
Sent using hkml (https://github.com/sjp38/hackermail)