[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 1/2] xen/mpu: Map early uart when earlyprintk on


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>
  • Date: Wed, 27 Nov 2024 18:39:05 +0000
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4y0rqKXx3iOgUdFHLMYjo9xQCZSV35vv3Q1T2p0SOFI=; b=vkE3hW1Ea7kmwUb3kUqNeEimOiiyvYSZMVv4SnQgCD6UQGRYeOERcwgPI0ncufAW3OCq2e/lmxgaQLhwJagfNfdV85bi4xodyDtCqAo1JfcYxPIioIv1gGSsxpq8iA5FtimrywUFzGw4Ryf5kxQRo9OQQRKVPHfbDJqaBuy+O8NLkBKJnjFvkD7Zf4PyIFR/3O10oTMZ1Ft4KVmeoJHtLBFcwnPF+qveznmDf3NDDRJK8K00C8QQ/Nr8ojT0zfTvFZ3SNdfndGbOHUfiRWdWTa+YhsvCa797Jtm5tp5yFjpy1SpNCpGXarHPsoLM5iQBzgQ8WW4Pq76eIJyZQObcXw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=j2RbwfX6xTpf5R/kORNeu+o6nLlj4GEySUirxPFdtf2BM52Meyb3crdvkD6YQOGMAmv9c+OY78Xf2S350Zn8IgsUEY9Gtr0CjBWrHNFK8zgz9Rkt/udxM67wcjOJaoSXA+4mY6EszQSYUQvsbH0ho+ISUa4iz91vONAs2ylMNA2a9AX3I6wzbGmFYYmb0gt466JU6Emu2X+VjpF0iEuQUS9kM4xhg+k/nCyo0pNyDFN3trnU3F0HAbQt5dqlfACoC+kU0TXKhr88BKrHIMLXzkX7Kn6gjKKwphJhJf6JXM0OTUd3Yk4o5n4yUelf8t+r5vt6o8JW6ObC0CuYoC4HRw==
  • Cc: Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, "Volodymyr Babchuk" <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Wed, 27 Nov 2024 18:39:35 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

CONFIG_EARLY_UART_SIZE is introduced to let user provide physical size of
early UART. Unlike MMU where we map a page in the virtual address space,
here we need to know the exact physical size to be mapped.
As VA == PA in case of MPU, the memory layout follows exactly the hardware
configuration. As a consequence, we set  EARLY_UART_VIRTUAL_ADDRESS as physical
address.

EARLY_UART_BASE_ADDRESS and EARLY_UART_SIZE should be aligned to the minimum
size of MPU region (ie 64 bits) as per the hardware restrictions. Refer ARM
DDI 0600A.d ID120821 A1.3 "A minimum protection region size of 64 bytes.".

UART is mapped as nGnRE region (as specified by ATTR=100 , refer G1.3.13,
MAIR_EL2, "---0100 Device memory nGnRE") and Doc ID - 102670_0101_02_en
Table 4-3, Armv8 architecture memory types (nGnRE - Corresponds to Device in
Armv7 architecture). Also, it is mapped as outer shareable, RW at EL2 only
and execution of instructions from the region is not permitted.

Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>
---
Changes from :-

v1 - 1. UART base address and size should be aligned to the minimum size of MPU
region (and not PAGE_SIZE).

 xen/arch/arm/Kconfig.debug              |  7 +++++++
 xen/arch/arm/arm64/mpu/head.S           |  9 ++++++++
 xen/arch/arm/include/asm/early_printk.h | 28 ++++++++++++++++++++++++-
 3 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/xen/arch/arm/Kconfig.debug b/xen/arch/arm/Kconfig.debug
index 7660e599c0..84a0616102 100644
--- a/xen/arch/arm/Kconfig.debug
+++ b/xen/arch/arm/Kconfig.debug
@@ -121,6 +121,13 @@ config EARLY_UART_BASE_ADDRESS
        hex "Early printk, physical base address of debug UART"
        range 0x0 0xffffffff if ARM_32
 
+config EARLY_UART_SIZE
+       depends on EARLY_PRINTK
+       depends on MPU
+       hex "Early printk, physical size of debug UART"
+       range 0x0 0xffffffff if ARM_32
+       default 0x1000
+
 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 f692fc7443..86e4019a0c 100644
--- a/xen/arch/arm/arm64/mpu/head.S
+++ b/xen/arch/arm/arm64/mpu/head.S
@@ -11,8 +11,10 @@
 #define REGION_TEXT_PRBAR       0x38    /* SH=11 AP=10 XN=00 */
 #define REGION_RO_PRBAR         0x3A    /* SH=11 AP=10 XN=10 */
 #define REGION_DATA_PRBAR       0x32    /* SH=11 AP=00 XN=10 */
+#define REGION_DEVICE_PRBAR     0x22    /* SH=10 AP=00 XN=10 */
 
 #define REGION_NORMAL_PRLAR     0x0f    /* NS=0 ATTR=111 EN=1 */
+#define REGION_DEVICE_PRLAR     0x09    /* NS=0 ATTR=100 EN=1 */
 
 /*
  * Macro to prepare and set a EL2 MPU memory region.
@@ -138,6 +140,13 @@ FUNC(enable_boot_cpu_mm)
     ldr   x2, =__bss_end
     prepare_xen_region x0, x1, x2, x3, x4, x5
 
+#ifdef CONFIG_EARLY_PRINTK
+    /* Xen early UART section. */
+    ldr   x1, =CONFIG_EARLY_UART_BASE_ADDRESS
+    ldr   x2, =(CONFIG_EARLY_UART_BASE_ADDRESS + CONFIG_EARLY_UART_SIZE)
+    prepare_xen_region x0, x1, x2, x3, x4, x5, attr_prbar=REGION_DEVICE_PRBAR, 
attr_prlar=REGION_DEVICE_PRLAR
+#endif
+
     b    enable_mpu
     ret
 END(enable_boot_cpu_mm)
diff --git a/xen/arch/arm/include/asm/early_printk.h 
b/xen/arch/arm/include/asm/early_printk.h
index 46a5e562dd..606aaedd6e 100644
--- a/xen/arch/arm/include/asm/early_printk.h
+++ b/xen/arch/arm/include/asm/early_printk.h
@@ -15,6 +15,29 @@
 
 #ifdef CONFIG_EARLY_PRINTK
 
+#if defined(CONFIG_MPU)
+
+/*
+ * For MPU systems, there is no VMSA support in EL2, so we use VA == PA
+ * for EARLY_UART_VIRTUAL_ADDRESS.
+ */
+#define EARLY_UART_VIRTUAL_ADDRESS CONFIG_EARLY_UART_BASE_ADDRESS
+
+/*
+ * User-defined EARLY_UART_BASE_ADDRESS and EARLY_UART_SIZE must be aligned to
+ * minimum size of MPU region.
+ */
+
+#if (EARLY_UART_BASE_ADDRESS % MPU_REGION_ALIGN) != 0
+#error "EARLY_UART_BASE_ADDRESS must be aligned to minimum MPU region size"
+#endif
+
+#if (EARLY_UART_SIZE % MPU_REGION_ALIGN) != 0
+#error "EARLY_UART_SIZE must be aligned to minimum MPU region size"
+#endif
+
+#elif defined(CONFIG_MMU)
+
 /* need to add the uart address offset in page to the fixmap address */
 #define EARLY_UART_VIRTUAL_ADDRESS \
     (FIXMAP_ADDR(FIX_CONSOLE) + (CONFIG_EARLY_UART_BASE_ADDRESS & ~PAGE_MASK))
@@ -22,6 +45,9 @@
 #define TEMPORARY_EARLY_UART_VIRTUAL_ADDRESS \
     (TEMPORARY_FIXMAP_ADDR(FIX_CONSOLE) + (CONFIG_EARLY_UART_BASE_ADDRESS & 
~PAGE_MASK))
 
-#endif /* !CONFIG_EARLY_PRINTK */
+#else
+#error "Unknown Memory management system"
+#endif
 
+#endif /* !CONFIG_EARLY_PRINTK */
 #endif
-- 
2.25.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.