From nobody Thu Oct 23 00:40:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1687750828006176.80137984482963; Sun, 25 Jun 2023 20:40:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.555024.866622 (Exim 4.92) (envelope-from ) id 1qDd4y-0007WH-5C; Mon, 26 Jun 2023 03:39:52 +0000 Received: by outflank-mailman (output) from mailman id 555024.866622; Mon, 26 Jun 2023 03:39:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qDd4w-0007Qy-Rc; Mon, 26 Jun 2023 03:39:50 +0000 Received: by outflank-mailman (input) for mailman id 555024; Mon, 26 Jun 2023 03:39:49 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qDd1k-0000HH-NE for xen-devel@lists.xenproject.org; Mon, 26 Jun 2023 03:36:32 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id a36624b4-13d2-11ee-8611-37d641c3527e; Mon, 26 Jun 2023 05:36:30 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C80F51FB; Sun, 25 Jun 2023 20:37:13 -0700 (PDT) Received: from a011292.shanghai.arm.com (a011292.shanghai.arm.com [10.169.190.94]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2C3F73F64C; Sun, 25 Jun 2023 20:36:26 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a36624b4-13d2-11ee-8611-37d641c3527e From: Penny Zheng To: xen-devel@lists.xenproject.org Cc: Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Penny Zheng , Wei Chen Subject: [PATCH v3 26/52] xen/mpu: map early uart when earlyprintk on Date: Mon, 26 Jun 2023 11:34:17 +0800 Message-Id: <20230626033443.2943270-27-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230626033443.2943270-1-Penny.Zheng@arm.com> References: <20230626033443.2943270-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1687750829960100001 Content-Type: text/plain; charset="utf-8" We map the early UART with a hardcoded MPU memory region at slot(#REGION_DEVICE_SEL), right after Xen image binary. CONFIG_EARLY_UART_SIZE is introduced, to let user provide physical size of early UART. It is necessary in MPU system. We also check whether user-defined EARLY_UART_SIZE is aligned to PAGE_SIZE, or we may map more than necessary in MPU system. Signed-off-by: Penny Zheng Signed-off-by: Wei Chen --- v3: - map the early UART with a hardcoded MPU memory region - error when uart size doesn't align with PAGE_SIZE --- xen/arch/arm/Kconfig.debug | 7 +++++++ xen/arch/arm/arm64/mpu/head.S | 25 +++++++++++++++++++++++++ xen/arch/arm/include/asm/arm64/mpu.h | 8 ++++++++ xen/arch/arm/include/asm/early_printk.h | 8 ++++++++ 4 files changed, 48 insertions(+) diff --git a/xen/arch/arm/Kconfig.debug b/xen/arch/arm/Kconfig.debug index eec860e88e..a3b0cb9daa 100644 --- a/xen/arch/arm/Kconfig.debug +++ b/xen/arch/arm/Kconfig.debug @@ -239,6 +239,13 @@ config EARLY_UART_BASE_ADDRESS default 0x1c020000 if EARLY_PRINTK_XGENE_STORM default 0xff000000 if EARLY_PRINTK_ZYNQMP =20 +config EARLY_UART_SIZE + depends on EARLY_PRINTK + depends on HAS_MPU + hex "Early printk, physical size of debug UART" + range 0x0 0xffffffff if ARM_32 + default 0x10000 if EARLY_PRINTK_FASTMODEL + config EARLY_UART_PL011_BAUD_RATE depends on EARLY_UART_PL011 int "Early printk UART baud rate for pl011" diff --git a/xen/arch/arm/arm64/mpu/head.S b/xen/arch/arm/arm64/mpu/head.S index 3cfce126d5..147a01e977 100644 --- a/xen/arch/arm/arm64/mpu/head.S +++ b/xen/arch/arm/arm64/mpu/head.S @@ -18,6 +18,7 @@ */ =20 #include +#include #include =20 /* @@ -29,8 +30,10 @@ #define REGION_TEXT_PRBAR 0x38 /* SH=3D11 AP=3D10 XN=3D00 */ #define REGION_RO_PRBAR 0x3A /* SH=3D11 AP=3D10 XN=3D10 */ #define REGION_DATA_PRBAR 0x32 /* SH=3D11 AP=3D00 XN=3D10 */ +#define REGION_DEVICE_PRBAR 0x22 /* SH=3D10 AP=3D00 XN=3D10 */ =20 #define REGION_NORMAL_PRLAR 0x0f /* NS=3D0 ATTR=3D111 EN=3D1 */ +#define REGION_DEVICE_PRLAR 0x09 /* NS=3D0 ATTR=3D100 EN=3D1 */ =20 /* * Macro to round up the section address to be PAGE_SIZE aligned @@ -216,6 +219,28 @@ ENTRY(enable_boot_mm) ret ENDPROC(enable_boot_mm) =20 +/* + * Map the early UART with a dedicated MPU memory region at + * slot(#REGION_DEVICE_SEL), right after Xen image binary. + * + * Clobbers x0 - x6 + * + */ +ENTRY(setup_early_uart) +#ifdef CONFIG_EARLY_PRINTK + mov x0, #REGION_UART_SEL + + /* Xen early UART section. */ + ldr x1, =3DCONFIG_EARLY_UART_BASE_ADDRESS + ldr x2, =3D(CONFIG_EARLY_UART_BASE_ADDRESS + CONFIG_EARLY_UART_SIZE) + prepare_xen_region x0, x1, x2, x3, x4, x5, x6, attr_prbar=3DREGION_DEV= ICE_PRBAR, attr_prlar=3DREGION_DEVICE_PRLAR + + /* Ensure any MPU memory mapping table updates made above have occurre= d. */ + dsb nshst + ret +#endif +ENDPROC(setup_early_uart) + /* * Local variables: * mode: ASM diff --git a/xen/arch/arm/include/asm/arm64/mpu.h b/xen/arch/arm/include/as= m/arm64/mpu.h index 0c479086f4..6ec2c10b14 100644 --- a/xen/arch/arm/include/asm/arm64/mpu.h +++ b/xen/arch/arm/include/asm/arm64/mpu.h @@ -12,6 +12,14 @@ */ #define ARM_MAX_MPU_MEMORY_REGIONS 255 =20 +/* + * REGION_UART_SEL defines MPU region selector value for early UART, when + * earlyuart printk is enabled. + * #REGION_DEVICE_SEL shall be compliant with what describes in xen.lds.S, + * or it needs adjustment. + */ +#define REGION_UART_SEL 0x07 + #ifndef __ASSEMBLY__ =20 /* Protection Region Base Address Register */ diff --git a/xen/arch/arm/include/asm/early_printk.h b/xen/arch/arm/include= /asm/early_printk.h index ec5bcc343c..445a3fb7de 100644 --- a/xen/arch/arm/include/asm/early_printk.h +++ b/xen/arch/arm/include/asm/early_printk.h @@ -23,6 +23,14 @@ */ #define EARLY_UART_VIRTUAL_ADDRESS CONFIG_EARLY_UART_BASE_ADDRESS =20 +/* + * User-defined EARLY_UART_SIZE must be aligned to a PAGE_SIZE, or + * we may map more than necessary in MPU system. + */ +#if (EARLY_UART_SIZE % PAGE_SIZE) !=3D 0 +#error "EARLY_UART_SIZE must be aligned to PAGE_SIZE" +#endif + #else =20 /* need to add the uart address offset in page to the fixmap address */ --=20 2.25.1