From 49721fc44e4be75561358d462e4c96f046b61009 Mon Sep 17 00:00:00 2001 From: skrll Date: Sat, 25 Feb 2023 08:19:35 +0000 Subject: [PATCH] Restore the ability to have EARLYCONS work for the QEMU virt after SOC_VIRT got removed. --- sys/arch/arm/fdt/arm_platform.c | 36 ++++++++++++++++++++++++++++++--- sys/arch/evbarm/conf/GENERIC | 6 ++++-- sys/arch/evbarm/conf/GENERIC64 | 6 ++++-- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/sys/arch/arm/fdt/arm_platform.c b/sys/arch/arm/fdt/arm_platform.c index 012a701172a9..b1965bb90df2 100644 --- a/sys/arch/arm/fdt/arm_platform.c +++ b/sys/arch/arm/fdt/arm_platform.c @@ -1,4 +1,4 @@ -/* $NetBSD: arm_platform.c,v 1.5 2021/04/24 23:36:26 thorpej Exp $ */ +/* $NetBSD: arm_platform.c,v 1.6 2023/02/25 08:19:35 skrll Exp $ */ /*- * Copyright (c) 2020 Jared McNeill @@ -35,8 +35,10 @@ * - Console UART is pre-configured by firmware */ +#include "opt_console.h" + #include -__KERNEL_RCSID(0, "$NetBSD: arm_platform.c,v 1.5 2021/04/24 23:36:26 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: arm_platform.c,v 1.6 2023/02/25 08:19:35 skrll Exp $"); #include #include @@ -58,6 +60,9 @@ __KERNEL_RCSID(0, "$NetBSD: arm_platform.c,v 1.5 2021/04/24 23:36:26 thorpej Exp #include #include +#include +#include + #include #include @@ -65,6 +70,31 @@ __KERNEL_RCSID(0, "$NetBSD: arm_platform.c,v 1.5 2021/04/24 23:36:26 thorpej Exp extern struct arm32_bus_dma_tag arm_generic_dma_tag; extern struct bus_space arm_generic_bs_tag; +void plcom_platform_early_putchar(char); + +#define ARM_PTOV(p) (((p) - DEVMAP_ALIGN(uart_base)) + KERNEL_IO_VBASE) + +void __noasan +plcom_platform_early_putchar(char c) +{ +#ifdef CONSADDR + bus_addr_t uart_base = CONSADDR; + + volatile uint32_t *uartaddr = cpu_earlydevice_va_p() ? + (volatile uint32_t *)ARM_PTOV(uart_base): + (volatile uint32_t *)uart_base; + + while ((le32toh(uartaddr[PL01XCOM_FR / 4]) & PL01X_FR_TXFF) != 0) + continue; + + uartaddr[PL01XCOM_DR / 4] = htole32(c); + dsb(sy); + + while ((le32toh(uartaddr[PL01XCOM_FR / 4]) & PL01X_FR_TXFE) == 0) + continue; +#endif +} + static void arm_platform_init_attach_args(struct fdt_attach_args *faa) { @@ -87,12 +117,12 @@ arm_platform_devmap(void) DEVMAP_ENTRY(KERNEL_IO_VBASE, 0, PAGE_SIZE), DEVMAP_ENTRY_END }; - bus_addr_t uart_base; const int phandle = fdtbus_get_stdout_phandle(); if (phandle <= 0) return devmap_empty; + bus_addr_t uart_base; if (fdtbus_get_reg(phandle, 0, &uart_base, NULL) != 0) return devmap_empty; diff --git a/sys/arch/evbarm/conf/GENERIC b/sys/arch/evbarm/conf/GENERIC index 017bbb8b5ec9..61f312973e52 100644 --- a/sys/arch/evbarm/conf/GENERIC +++ b/sys/arch/evbarm/conf/GENERIC @@ -1,5 +1,5 @@ # -# $NetBSD: GENERIC,v 1.117 2023/02/09 14:09:48 abs Exp $ +# $NetBSD: GENERIC,v 1.118 2023/02/25 08:19:35 skrll Exp $ # # GENERIC ARM (aarch32) kernel # @@ -78,10 +78,12 @@ options MSGBUFSIZE=32768 #options EARLYCONS=tegra, CONSADDR=0x70006300 #options EARLYCONS=vexpress, CONSADDR=0x1c090000 -#options EARLYCONS=virt, CONSADDR=0x09000000 #options EARLYCONS=zynq, CONSADDR=0xe0001000 #options EARLYCONS=rk3288, CONSADDR=0xff690000 +# The QEMU virt machine +#options EARLYCONS=plcom, CONSADDR=0x09000000 + # Kernel Undefined Behavior Sanitizer (kUBSan). Use UBSAN_ALWAYS_FATAL # if you want panics instead of warnings. #options KUBSAN # mandatory diff --git a/sys/arch/evbarm/conf/GENERIC64 b/sys/arch/evbarm/conf/GENERIC64 index e86ea0557233..5d5f1db6e2a0 100644 --- a/sys/arch/evbarm/conf/GENERIC64 +++ b/sys/arch/evbarm/conf/GENERIC64 @@ -1,5 +1,5 @@ # -# $NetBSD: GENERIC64,v 1.209 2023/02/11 07:01:32 mrg Exp $ +# $NetBSD: GENERIC64,v 1.210 2023/02/25 08:19:35 skrll Exp $ # # GENERIC ARM (aarch64) kernel # @@ -47,7 +47,9 @@ options INCLUDE_CONFIG_FILE #options EARLYCONS=sunxi, CONSADDR=0x01c28000 #options EARLYCONS=tegra, CONSADDR=0x70006000 #options EARLYCONS=thunderx, CONSADDR=0x87e024000000 -#options EARLYCONS=virt, CONSADDR=0x09000000 + +# The QEMU virt machine +#options EARLYCONS=plcom, CONSADDR=0x09000000 # Hardware management of the Access flag and dirty state (HAFDBS). options ARMV81_HAFDBS