riscv: Introduce va_kernel_pa_offset for 32-bit kernel
authorAlexandre Ghiti <alex@ghiti.fr>
Fri, 23 Jul 2021 13:01:24 +0000 (15:01 +0200)
committerPalmer Dabbelt <palmerdabbelt@google.com>
Thu, 12 Aug 2021 05:41:11 +0000 (22:41 -0700)
va_kernel_pa_offset was only used for 64-bit as the kernel mapping lies
in the linear mapping for 32-bit kernel and then only the offset between
the PAGE_OFFSET and the kernel load address is needed.

But this distinction complexifies the code with #ifdefs and especially
with a separate definition of the address conversions macros.

Simplify the code by defining this variable for both 32-bit and 64-bit.

Signed-off-by: Alexandre Ghiti <alex@ghiti.fr>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
arch/riscv/include/asm/page.h
arch/riscv/mm/init.c

index d40d77d..4da92cf 100644 (file)
@@ -91,10 +91,8 @@ struct kernel_mapping {
        uintptr_t size;
        /* Offset between linear mapping virtual address and kernel load address */
        unsigned long va_pa_offset;
-#ifdef CONFIG_64BIT
        /* Offset between kernel mapping virtual address and kernel load address */
        unsigned long va_kernel_pa_offset;
-#endif
        unsigned long va_kernel_xip_pa_offset;
 #ifdef CONFIG_XIP_KERNEL
        uintptr_t xiprom;
@@ -104,11 +102,11 @@ struct kernel_mapping {
 
 extern struct kernel_mapping kernel_map;
 
-#ifdef CONFIG_64BIT
 #define is_kernel_mapping(x)   \
        ((x) >= kernel_map.virt_addr && (x) < (kernel_map.virt_addr + kernel_map.size))
+
 #define is_linear_mapping(x)   \
-       ((x) >= PAGE_OFFSET && (x) < kernel_map.virt_addr)
+       ((x) >= PAGE_OFFSET && (!IS_ENABLED(CONFIG_64BIT) || (x) < kernel_map.virt_addr))
 
 #define linear_mapping_pa_to_va(x)     ((void *)((unsigned long)(x) + kernel_map.va_pa_offset))
 #define kernel_mapping_pa_to_va(y)     ({                                              \
@@ -132,15 +130,6 @@ extern struct kernel_mapping kernel_map;
        is_linear_mapping(_x) ?                                                 \
                linear_mapping_va_to_pa(_x) : kernel_mapping_va_to_pa(_x);      \
        })
-#else
-#define is_kernel_mapping(x)   \
-       ((x) >= kernel_map.virt_addr && (x) < (kernel_map.virt_addr + kernel_map.size))
-#define is_linear_mapping(x)   \
-       ((x) >= PAGE_OFFSET)
-
-#define __pa_to_va_nodebug(x)  ((void *)((unsigned long) (x) + kernel_map.va_pa_offset))
-#define __va_to_pa_nodebug(x)  ((unsigned long)(x) - kernel_map.va_pa_offset)
-#endif /* CONFIG_64BIT */
 
 #ifdef CONFIG_DEBUG_VIRTUAL
 extern phys_addr_t __virt_to_phys(unsigned long x);
index 269fc64..263ae05 100644 (file)
@@ -552,11 +552,8 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
        kernel_map.phys_addr = (uintptr_t)(&_start);
        kernel_map.size = (uintptr_t)(&_end) - kernel_map.phys_addr;
 #endif
-
        kernel_map.va_pa_offset = PAGE_OFFSET - kernel_map.phys_addr;
-#ifdef CONFIG_64BIT
        kernel_map.va_kernel_pa_offset = kernel_map.virt_addr - kernel_map.phys_addr;
-#endif
 
        pfn_base = PFN_DOWN(kernel_map.phys_addr);