hw/arm/virt: make second UART available
cover hw/arm/virt: make second UART available
This is a follow-up on older attempts to make a second UART available for the arm-virt machine in normal world. The use case is, that this give a simple I/O channel in addition to stdout, as this simplifies various test scenarios. Especially for non-Linux operating system,s (e.g. seL4) where arm-virt is handy as a generic machine for testing purposes.
There are existing discussions about this topic at:
- https://lists.gnu.org/archive/html/qemu-arm/2017-12/msg00063.html
- https://lists.nongnu.org/archive/html/qemu-
discuss/2018-11/msg00001.html
- https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg01613.html
This patch tries to address the concerns raised there and also avoid breaking compatibility with existing setups.
Axel Heider (1):
hw/arm/virt: make second UART available
hw/arm/virt-acpi-build.c | 12 ++++----- hw/arm/virt.c | 55 ++++++++++++++++++++++++++++++---------- include/hw/arm/virt.h | 4 +-- 3 files changed, 49 insertions(+), 22 deletions(-)
Signature · 1 line
2.34.5
PATCH 1/1 hw/arm/virt: make second UART available
From: Axel Heider <[email protected]>
The first UART always always exists. If the security extensions are enabled, the second UART also always exists. Otherwise, it only exists if a backend is configured explicitly via '-serial <backend>', where 'null' creates a dummy backend. This allows enabling the second UART explicitly on demand and does not interfere with any existing setup that just expect one (or two if security extensions are enabled) UARTs.
--- hw/arm/virt-acpi-build.c | 12 ++++----- hw/arm/virt.c | 55 ++++++++++++++++++++++++++++++---------- include/hw/arm/virt.h | 4 +-- 3 files changed, 49 insertions(+), 22 deletions(-)
hw/arm/virt-acpi-build.c +6 -6
@@ -482,14 +482,14 @@ build_spcr(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)build_append_int_noprefix (table_data,0 ,3 );/* Reserved */ /* Base Address */ build_append_gas (table_data,AML_AS_SYSTEM_MEMORY ,8 ,0 ,1 , - vms->memmap[VIRT_UART ].base); + vms->memmap[VIRT_UART0 ].base);/* Interrupt Type */ build_append_int_noprefix (table_data, (1 <<3 )/* Bit[3] ARMH GIC interrupt */ ,1 );build_append_int_noprefix (table_data,0 ,1 );/* IRQ */ /* Global System Interrupt */ build_append_int_noprefix (table_data, - vms->irqmap[VIRT_UART ] +ARM_SPI_BASE ,4 ); + vms->irqmap[VIRT_UART0 ] +ARM_SPI_BASE ,4 );build_append_int_noprefix (table_data,3 /* 9600 */ ,1 );/* Baud Rate */ build_append_int_noprefix (table_data,0 /* No Parity */ ,1 );/* Parity */ /* Stop Bits */
@@ -673,11 +673,11 @@ build_dbg2(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)/* BaseAddressRegister[] */ build_append_gas (table_data,AML_AS_SYSTEM_MEMORY ,8 ,0 ,1 , - vms->memmap[VIRT_UART ].base); + vms->memmap[VIRT_UART0 ].base);/* AddressSize[] */ build_append_int_noprefix (table_data, - vms->memmap[VIRT_UART ].size,4 ); + vms->memmap[VIRT_UART0 ].size,4 );/* NamespaceString[] */ g_array_append_vals (table_data, name, namespace_length);
@@ -858,8 +858,8 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)*/ scope =aml_scope ("\\_SB" );acpi_dsdt_add_cpus (scope, vms); -acpi_dsdt_add_uart (scope, &memmap[VIRT_UART ], - (irqmap[VIRT_UART ] +ARM_SPI_BASE )); +acpi_dsdt_add_uart (scope, &memmap[VIRT_UART0 ], + (irqmap[VIRT_UART0 ] +ARM_SPI_BASE ));if (vmc->acpi_expose_flash) {acpi_dsdt_add_flash (scope, &memmap[VIRT_FLASH ]); }
hw/arm/virt.c +41 -14
101 lines not on this page · raw message
include/hw/arm/virt.h +2 -2
@@ -69,7 +69,7 @@ enum {VIRT_GIC_ITS ,VIRT_GIC_REDIST ,VIRT_SMMU , -VIRT_UART , +VIRT_UART0 ,VIRT_MMIO ,VIRT_RTC , VIRT_FW_CFG,
@@ -79,7 +79,7 @@ enum {VIRT_PCIE_ECAM ,VIRT_PLATFORM_BUS ,VIRT_GPIO , -VIRT_SECURE_UART , +VIRT_UART1 ,/* secure UART if vms->secure */ VIRT_SECURE_MEM ,VIRT_SECURE_GPIO , VIRT_PCDIMM_ACPI,
Signature · 1 line
2.34.5
Hi Axel,
Quoted 24 lines · ~axelheider
From: Axel Heider <[email protected]>
The first UART always always exists. If the security extensions are enabled, the second UART also always exists. Otherwise, it only exists if a backend is configured explicitly via '-serial <backend>', where 'null' creates a dummy backend. This allows enabling the second UART explicitly on demand and does not interfere with any existing setup that just expect one (or two if security extensions are enabled) UARTs.
Signed-off-by Axel Heider <[email protected]>--- hw/arm/virt-acpi-build.c | 12 ++++----- hw/arm/virt.c | 55 ++++++++++++++++++++++++++++++---------- include/hw/arm/virt.h | 4 +-- 3 files changed, 49 insertions(+), 22 deletions(-)hw/arm/virt.c +2
-0@@ -843,6 +843,27 @@ static void create_uart(const VirtMachineState *vms, int uart, MemoryRegion *mem, Chardev *chr) {char *nodename; +/* +* The first UART always always exists. If the security extensions are
hw/arm/virt.c static void create_uart(const VirtMachineState *vms, int uart, · line 857
Quoted 10 lines
hw/arm/virt.c +10
-0+* enabled, the second UART also always exists. Otherwise, it only exists +* if a backend is configured explicitly via '-serial <backend>', where +* 'null' creates a dummy backend. This allows enabling the second UART +* explicitly on demand and does not interfere with any existing setup that +* just expect one (or two if security extensions are enabled) UARTs. +*/ +switch (uart) { +case VIRT_UART0 : +break ; +case VIRT_UART1 :
Maybe pass a 'is_secure' boolean?
Quoted 12 lines
hw/arm/virt.c +8
-0+if (!vms->secure && !chr) { +return ; + } +break ; +default : +error_report ("unsupported UART ID %d" , uart); +exit (1 ); + }@@ -2222,11 +2248,12 @@ static void machvirt_init(MachineState *machine)
hw/arm/virt.c static void machvirt_init(MachineState *machine) · line 2229
Quoted 10 lines
hw/arm/virt.c +3
-2fdt_add_pmu_nodes (vms); -create_uart (vms,VIRT_UART , sysmem,serial_hd (0 )); +create_uart (vms,VIRT_UART0 , sysmem,serial_hd (0 )); +create_uart (vms,VIRT_UART1 , vms->secure ? secure_sysmem : sysmem, +serial_hd (1 ));if (vms->secure) {create_secure_ram (vms, secure_sysmem, secure_tag_sysmem); -create_uart (vms,VIRT_SECURE_UART , secure_sysmem,serial_hd (1 ));
Correct.
Quoted 17 lines
hw/arm/virt.c +0
-0}if (tag_sysmem) {include/hw/arm/virt.h +1
-1@@ -69,7 +69,7 @@ enum {VIRT_GIC_ITS ,VIRT_GIC_REDIST ,VIRT_SMMU , -VIRT_UART , +VIRT_UART0 ,VIRT_MMIO ,VIRT_RTC , VIRT_FW_CFG,
include/hw/arm/virt.h enum { · line 82
Quoted 5 lines
include/hw/arm/virt.h +1
-1@@ -79,7 +79,7 @@ enum {VIRT_PCIE_ECAM ,VIRT_PLATFORM_BUS ,VIRT_GPIO , - VIRT_SECURE_UART, + VIRT_UART1, /* secure UART if vms->secure */
(I'm not sure changing the name is worth the churn).
Regards,
Phil.
Hi,
Quoted 6 lines
Quoted 5 lines
+ switch(uart) {
+ caseVIRT_UART0:
+ break;
+ caseVIRT_UART1:Maybe pass a '
is_secure' boolean?
I don't think this would really make things easier. I wanted to avoid too many changes in this patch. The price is, that there are two places where decisions about the configuration are made. But these are also two independent decisions: (a) which memory this belongs to and (b) if the UART exists at all. I think the code is easier to maintain this way, because more UARTs can be added with a small patch then. Note also, that a parameter 'is_secure' would still not avoid mis-usage, as we still need the 'mem' parameter for 'secure_sysmem' or 'sysmem', because this is no available from the 'vms' object.
Quoted 4 lines
Quoted 3 lines
-
VIRT_SECURE_UART,
+VIRT_UART1, /* secure UART ifvms->secure*/(I'm not sure changing the name is worth the churn).
After this patch is merged, we have two UARTs, so the naming is a bit more consistent. It's no longer a secure UART only. And when adding even more UARTs in further customization, it's easier to understand the order of the UARTs.
Axel
Quoted 16 lines · ~axelheider
This is a follow-up on older attempts to make a second UART available for the arm-virt machine in normal world. The use case is, that this give a simple I/O channel in addition to stdout, as this simplifies various test scenarios. Especially for non-Linux operating system,s (e.g. seL4) where arm-virt is handy as a generic machine for testing purposes.
There are existing discussions about this topic at:
- https://lists.gnu.org/archive/html/qemu-arm/2017-12/msg00063.html
- https://lists.nongnu.org/archive/html/qemu-
discuss/2018-11/msg00001.html
- https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg01613.htmlThis patch tries to address the concerns raised there and also avoid breaking compatibility with existing setups.
Quoted 7 lines
Axel Heider (1):
hw/arm/virt: make second UART availablehw/arm/virt-acpi-build.c | 12 ++++----- hw/arm/virt.c | 55 ++++++++++++++++++++++++++++++---------- include/hw/arm/virt.h | 4 +-- 3 files changed, 49 insertions(+), 22 deletions(-)
It would also be worth updating ./docs/system/arm/virt.rst to document this feature.
Signature · 1 line
Alex Bennée
Alex,
Quoted 2 lines
It would also be worth updating
./docs/system/arm/virt.rstto document this feature.
Good point. I will add this in the next iteration of the patch. Until then, the proposed doc changes can be found here:
https://gitlab.com/axel-h/qemu/-/merge_requests/1/diffs
Axel