hw/arm/virt: make second UART available
v2 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 systems (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.gnu.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.
v2 also updates the documentation in docs/system/arm/virt.rst
Axel Heider (1):
hw/arm/virt: make second UART available
docs/system/arm/virt.rst | 5 ++-- hw/arm/virt-acpi-build.c | 12 ++++----- hw/arm/virt.c | 57 ++++++++++++++++++++++++++++++---------- include/hw/arm/virt.h | 4 +-- 4 files changed, 54 insertions(+), 24 deletions(-)
Signature · 1 line
2.34.5
PATCH v2 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.
--- docs/system/arm/virt.rst | 5 ++-- hw/arm/virt-acpi-build.c | 12 ++++----- hw/arm/virt.c | 57 ++++++++++++++++++++++++++++++---------- include/hw/arm/virt.h | 4 +-- 4 files changed, 54 insertions(+), 24 deletions(-)
docs/system/arm/virt.rst +3 -2
@@ -26,7 +26,8 @@ The virt board supports: - PCI/PCIe devices - Flash memory -- One PL011 UART +- Two PL011 UARTs. The second UART only exists if a backend is configured + explicitly or TrustZone is enabled. - An RTC - The fw_cfg device that allows a guest to obtain data from QEMU - A PL061 GPIO controller
@@ -42,7 +43,7 @@ The virt board supports: - many CPUs (up to 512 if using a GICv3 and highmem) - Secure-World-only devices if the CPU has TrustZone: - - A second PL011 UART + - The second PL011 UART - A second PL061 GPIO controller, with GPIO lines for triggering a system reset or system poweroff - A secure flash memory
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 +43 -14
103 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
Quoted 11 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.
Quoted 1 line
Signed-off-by Axel Heider <[email protected]>
Hi; just wanted to say that this is still on my to-review list. As a preliminary note:
hw/arm/virt.c static void machvirt_init(MachineState *machine) · line 2255
Quoted 8 lines
hw/arm/virt.c +3
-1@@ -2222,11 +2250,12 @@ static void machvirt_init(MachineState *machine)fdt_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 ));
Creating the UARTs in this order in the code results in them appearing in the DTB in reverse order. (I forget why; I think dtb nodes put on a list in one order and then put into the dtb proper in the other, or something.) The result is that if you add an extra '-serial foo' argument then Linux decides that UART0 is ttyAMA1 and UART1 is ttyAMA0, which is a bit counter-intuitive.
This can be avoided by something like:
@@ -2289,9 +2289,20 @@ static void machvirt_init(MachineState *machine)
fdt_add_pmu_nodes(vms);
+ /*
+ * These end up in the DTB in reverse order of creation, so
+ * we must create UART0 last to ensure it appears as the
+ * first UART, ttyAMA0, for Linux.
+ * For back-compatibility with older QEMU versions, if UART1 is
+ * the secure UART and thus always created, we create it second.
+ */
+ if (!vms->secure) {
+ create_uart(vms, VIRT_UART1, sysmem, serial_hd(1));
+ }
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_uart(vms, VIRT_UART1, secure_sysmem, serial_hd(1));
+ }
if (vms->secure) {
create_secure_ram(vms, secure_sysmem, secure_tag_sysmem);I still need to:
* look at what UEFI does if presented with this DTB (may involve filing a bug report to see if they will change the enumeration order if it's still silly)
* check what happens when we boot Linux passing it the h/w info via ACPI
thanks
-- PMM