]> xenbits.xensource.com Git - people/aperard/xen-unstable.git/commitdiff
xen/arm: Introduce choice to enable 64/32 bit physical addressing
authorAyan Kumar Halder <ayan.kumar.halder@amd.com>
Fri, 2 Jun 2023 12:07:51 +0000 (13:07 +0100)
committerJulien Grall <jgrall@amazon.com>
Fri, 16 Jun 2023 20:36:35 +0000 (21:36 +0100)
Some Arm based hardware platforms which does not support LPAE
(eg Cortex-R52), uses 32 bit physical addresses.
Also, users may choose to use 32 bits to represent physical addresses
for optimization.

To support the above use cases, we have introduced arch independent
config to choose if the physical address can be represented using
32 bits (PHYS_ADDR_T_32) or 64 bits (!PHYS_ADDR_T_32).
For now only ARM_32 provides support to enable 32 bit physical
addressing.

When PHYS_ADDR_T_32 is defined, PADDR_BITS is set to 32. Note that we
use "unsigned long" (not "uint32_t") to denote the datatype of physical
address. This is done to avoid using a cast each time PAGE_* macros are
used on paddr_t. For eg PAGE_SIZE is defined as unsigned long. Thus,
each time PAGE_SIZE is used with paddr_t, the result will be
"unsigned long".
On 32-bit architecture, "unsigned long" is 32-bit wide. Thus, it can be
used to denote physical address.

When PHYS_ADDR_T_32 is not defined for ARM_32, PADDR_BITS is set to 40.
For ARM_64, PADDR_BITS is set to 48.
The last two are same as the current configuration used today on Xen.

Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Acked-by: Julien Grall <jgrall@amazon.com>
xen/arch/Kconfig
xen/arch/arm/Kconfig
xen/arch/arm/include/asm/page-bits.h
xen/arch/arm/include/asm/types.h
xen/arch/arm/mm.c

index 7028f7b74f6a2a7d26822f902e6c7556417aef2d..67ba38f32f65457df2611be6325897b1c9b68c79 100644 (file)
@@ -1,6 +1,9 @@
 config 64BIT
        bool
 
+config PHYS_ADDR_T_32
+       bool
+
 config NR_CPUS
        int "Maximum number of CPUs"
        range 1 4095
index 41f45d8d12031eceb8fe6b916348c4d8006fcb0d..61e581b8c2b00f4dd98ee96baf2bd2f6f85c8b10 100644 (file)
@@ -26,6 +26,39 @@ config ARCH_DEFCONFIG
 
 menu "Architecture Features"
 
+choice
+       prompt "Physical address space size" if ARM_32
+       default ARM_PA_BITS_40 if ARM_32
+       help
+         User can choose to represent the width of physical address. This can
+         sometimes help in optimizing the size of image when user chooses a
+         smaller size to represent physical address.
+
+config ARM_PA_BITS_32
+       bool "32-bit"
+       depends on ARM_32
+       select PHYS_ADDR_T_32
+       help
+         On platforms where any physical address can be represented within 32 bits,
+         user should choose this option. This will help in reduced size of the
+         binary.
+         Xen uses "unsigned long" and not "uint32_t" to denote the datatype of
+         physical address. This is done to avoid using a cast each time PAGE_*
+         macros are used on paddr_t. For eg PAGE_SIZE is defined as unsigned long.
+         On 32-bit architecture, "unsigned long" is 32-bit wide. Thus, it can be
+         used to denote physical address.
+
+config ARM_PA_BITS_40
+       bool "40-bit"
+       depends on ARM_32
+endchoice
+
+config PADDR_BITS
+       int
+       default 32 if ARM_PA_BITS_32
+       default 40 if ARM_PA_BITS_40
+       default 48 if ARM_64
+
 source "arch/Kconfig"
 
 config ACPI
index 5d6477e5992691f03f2206f921c836a14505c749..deb381ceeb9b1595099026e67dd7deb22c4fb381 100644 (file)
@@ -3,10 +3,6 @@
 
 #define PAGE_SHIFT              12
 
-#ifdef CONFIG_ARM_64
-#define PADDR_BITS              48
-#else
-#define PADDR_BITS              40
-#endif
+#define PADDR_BITS              CONFIG_PADDR_BITS
 
 #endif /* __ARM_PAGE_SHIFT_H__ */
index e218ed77bd5846ee1f84e0253f5918c4082eb8ca..fb6618ef247fe8e3abe472e50b4877e11cc8a96c 100644 (file)
@@ -34,9 +34,23 @@ typedef signed long long s64;
 typedef unsigned long long u64;
 typedef u32 vaddr_t;
 #define PRIvaddr PRIx32
+#if defined(CONFIG_PHYS_ADDR_T_32)
+
+/*
+ * We use "unsigned long" and not "uint32_t" to denote the type. This is done
+ * to avoid having a cast each time PAGE_* macros are used on paddr_t. For eg
+ * PAGE_SIZE is defined as unsigned long.
+ * On 32-bit architecture, "unsigned long" is 32-bit wide. Thus, we can use it
+ * to denote physical address.
+ */
+typedef unsigned long paddr_t;
+#define INVALID_PADDR (~0UL)
+#define PRIpaddr "08lx"
+#else
 typedef u64 paddr_t;
 #define INVALID_PADDR (~0ULL)
 #define PRIpaddr "016llx"
+#endif
 typedef u32 register_t;
 #define PRIregister "08x"
 #elif defined (CONFIG_ARM_64)
index 74f6ff2c6f78c7de9fe7e3e95633a49042f8ad2b..5ef5fd8c49f623fc1c97ee9fbbf3398d857ea89e 100644 (file)
@@ -703,6 +703,11 @@ void __init setup_frametable_mappings(paddr_t ps, paddr_t pe)
     const unsigned long mapping_size = frametable_size < MB(32) ? MB(2) : MB(32);
     int rc;
 
+    /*
+     * The size of paddr_t should be sufficient for the complete range of
+     * physical address.
+     */
+    BUILD_BUG_ON((sizeof(paddr_t) * BITS_PER_BYTE) < PADDR_BITS);
     BUILD_BUG_ON(sizeof(struct page_info) != PAGE_INFO_SIZE);
 
     if ( frametable_size > FRAMETABLE_SIZE )