@@ -165,11 +165,11 @@ static const MemMapEntry base_memmap[] = {
165165 [VIRT_GIC_ITS ] = { 0x08080000 , 0x00020000 },
166166 /* This redistributor space allows up to 2*64kB*123 CPUs */
167167 [VIRT_GIC_REDIST ] = { 0x080A0000 , 0x00F60000 },
168- [VIRT_UART ] = { 0x09000000 , 0x00001000 },
168+ [VIRT_UART0 ] = { 0x09000000 , 0x00001000 },
169169 [VIRT_RTC ] = { 0x09010000 , 0x00001000 },
170170 [VIRT_FW_CFG ] = { 0x09020000 , 0x00000018 },
171171 [VIRT_GPIO ] = { 0x09030000 , 0x00001000 },
172- [VIRT_SECURE_UART ] = { 0x09040000 , 0x00001000 },
172+ [VIRT_UART1 ] = { 0x09040000 , 0x00001000 },
173173 [VIRT_SMMU ] = { 0x09050000 , 0x00020000 },
174174 [VIRT_PCDIMM_ACPI ] = { 0x09070000 , MEMORY_HOTPLUG_IO_LEN },
175175 [VIRT_ACPI_GED ] = { 0x09080000 , ACPI_GED_EVT_SEL_LEN },
@@ -212,11 +212,11 @@ static MemMapEntry extended_memmap[] = {
212212};
213213
214214static const int a15irqmap [] = {
215- [VIRT_UART ] = 1 ,
215+ [VIRT_UART0 ] = 1 ,
216216 [VIRT_RTC ] = 2 ,
217217 [VIRT_PCIE ] = 3 , /* ... to 6 */
218218 [VIRT_GPIO ] = 7 ,
219- [VIRT_SECURE_UART ] = 8 ,
219+ [VIRT_UART1 ] = 8 ,
220220 [VIRT_ACPI_GED ] = 9 ,
221221 [VIRT_MMIO ] = 16 , /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */
222222 [VIRT_GIC_V2M ] = 48 , /* ...to 48 + NUM_GICV2M_SPIS - 1 */
@@ -271,6 +271,17 @@ static void create_fdt(VirtMachineState *vms)
271271 qemu_fdt_setprop_cell (fdt , "/" , "#size-cells" , 0x2 );
272272 qemu_fdt_setprop_string (fdt , "/" , "model" , "linux,dummy-virt" );
273273
274+ /*
275+ * For QEMU, all DMA is coherent. Advertising this in the root node
276+ * has two benefits:
277+ *
278+ * - It avoids potential bugs where we forget to mark a DMA
279+ * capable device as being dma-coherent
280+ * - It avoids spurious warnings from the Linux kernel about
281+ * devices which can't do DMA at all
282+ */
283+ qemu_fdt_setprop (fdt , "/" , "dma-coherent" , NULL , 0 );
284+
274285 /* /chosen must exist for load_dtb to fill in necessary properties later */
275286 qemu_fdt_add_subnode (fdt , "/chosen" );
276287 if (vms -> dtb_randomness ) {
@@ -284,6 +295,8 @@ static void create_fdt(VirtMachineState *vms)
284295 }
285296 }
286297
298+ qemu_fdt_add_subnode (fdt , "/aliases" );
299+
287300 /* Clock node, for the benefit of the UART. The kernel device tree
288301 * binding documentation claims the PL011 node clock properties are
289302 * optional but in practice if you omit them the kernel refuses to
@@ -904,7 +917,7 @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem)
904917}
905918
906919static void create_uart (const VirtMachineState * vms , int uart ,
907- MemoryRegion * mem , Chardev * chr )
920+ MemoryRegion * mem , Chardev * chr , bool secure )
908921{
909922 char * nodename ;
910923 hwaddr base = vms -> memmap [uart ].base ;
@@ -937,9 +950,13 @@ static void create_uart(const VirtMachineState *vms, int uart,
937950 qemu_fdt_setprop (ms -> fdt , nodename , "clock-names" ,
938951 clocknames , sizeof (clocknames ));
939952
940- if (uart == VIRT_UART ) {
953+ if (uart == VIRT_UART0 ) {
941954 qemu_fdt_setprop_string (ms -> fdt , "/chosen" , "stdout-path" , nodename );
955+ qemu_fdt_setprop_string (ms -> fdt , "/aliases" , "serial0" , nodename );
942956 } else {
957+ qemu_fdt_setprop_string (ms -> fdt , "/aliases" , "serial1" , nodename );
958+ }
959+ if (secure ) {
943960 /* Mark as not usable by the normal world */
944961 qemu_fdt_setprop_string (ms -> fdt , nodename , "status" , "disabled" );
945962 qemu_fdt_setprop_string (ms -> fdt , nodename , "secure-status" , "okay" );
@@ -2313,11 +2330,41 @@ static void machvirt_init(MachineState *machine)
23132330
23142331 fdt_add_pmu_nodes (vms );
23152332
2316- create_uart (vms , VIRT_UART , sysmem , serial_hd (0 ));
2333+ /*
2334+ * The first UART always exists. If the security extensions are
2335+ * enabled, the second UART also always exists. Otherwise, it only exists
2336+ * if a backend is configured explicitly via '-serial <backend>'.
2337+ * This avoids potentially breaking existing user setups that expect
2338+ * only one NonSecure UART to be present (for instance, older EDK2
2339+ * binaries).
2340+ *
2341+ * The nodes end up in the DTB in reverse order of creation, so we must
2342+ * create UART0 last to ensure it appears as the first node in the DTB,
2343+ * for compatibility with guest software that just iterates through the
2344+ * DTB to find the first UART, as older versions of EDK2 do.
2345+ * DTB readers that follow the spec, as Linux does, should honour the
2346+ * aliases node information and /chosen/stdout-path regardless of
2347+ * the order that nodes appear in the DTB.
2348+ *
2349+ * For similar back-compatibility reasons, if UART1 is the secure UART
2350+ * we create it second (and so it appears first in the DTB), because
2351+ * that's what QEMU has always done.
2352+ */
2353+ if (!vms -> secure ) {
2354+ Chardev * serial1 = serial_hd (1 );
2355+
2356+ if (serial1 ) {
2357+ vms -> second_ns_uart_present = true;
2358+ create_uart (vms , VIRT_UART1 , sysmem , serial1 , false);
2359+ }
2360+ }
2361+ create_uart (vms , VIRT_UART0 , sysmem , serial_hd (0 ), false);
2362+ if (vms -> secure ) {
2363+ create_uart (vms , VIRT_UART1 , secure_sysmem , serial_hd (1 ), true);
2364+ }
23172365
23182366 if (vms -> secure ) {
23192367 create_secure_ram (vms , secure_sysmem , secure_tag_sysmem );
2320- create_uart (vms , VIRT_SECURE_UART , secure_sysmem , serial_hd (1 ));
23212368 }
23222369
23232370 if (tag_sysmem ) {
0 commit comments