Commit 7094e6ac authored by Alexandre Ghiti's avatar Alexandre Ghiti Committed by Palmer Dabbelt

riscv: Simplify xip and !xip kernel address conversion macros

To simplify the kernel address conversion code, make the same definition of
kernel_mapping_pa_to_va and kernel_mapping_va_to_pa compatible for both xip
and !xip kernel by defining XIP_OFFSET to 0 in !xip kernel.
Signed-off-by: default avatarAlexandre Ghiti <alex@ghiti.fr>
Reviewed-by: default avatarAnup Patel <anup@brainfault.org>
Signed-off-by: default avatarPalmer Dabbelt <palmerdabbelt@google.com>
parent 9b79878c
...@@ -93,9 +93,7 @@ extern unsigned long va_pa_offset; ...@@ -93,9 +93,7 @@ extern unsigned long va_pa_offset;
#ifdef CONFIG_64BIT #ifdef CONFIG_64BIT
extern unsigned long va_kernel_pa_offset; extern unsigned long va_kernel_pa_offset;
#endif #endif
#ifdef CONFIG_XIP_KERNEL
extern unsigned long va_kernel_xip_pa_offset; extern unsigned long va_kernel_xip_pa_offset;
#endif
extern unsigned long pfn_base; extern unsigned long pfn_base;
#define ARCH_PFN_OFFSET (pfn_base) #define ARCH_PFN_OFFSET (pfn_base)
#else #else
...@@ -103,6 +101,7 @@ extern unsigned long pfn_base; ...@@ -103,6 +101,7 @@ extern unsigned long pfn_base;
#ifdef CONFIG_64BIT #ifdef CONFIG_64BIT
#define va_kernel_pa_offset 0 #define va_kernel_pa_offset 0
#endif #endif
#define va_kernel_xip_pa_offset 0
#define ARCH_PFN_OFFSET (PAGE_OFFSET >> PAGE_SHIFT) #define ARCH_PFN_OFFSET (PAGE_OFFSET >> PAGE_SHIFT)
#endif /* CONFIG_MMU */ #endif /* CONFIG_MMU */
...@@ -110,29 +109,22 @@ extern unsigned long kernel_virt_addr; ...@@ -110,29 +109,22 @@ extern unsigned long kernel_virt_addr;
#ifdef CONFIG_64BIT #ifdef CONFIG_64BIT
#define linear_mapping_pa_to_va(x) ((void *)((unsigned long)(x) + va_pa_offset)) #define linear_mapping_pa_to_va(x) ((void *)((unsigned long)(x) + va_pa_offset))
#ifdef CONFIG_XIP_KERNEL
#define kernel_mapping_pa_to_va(y) ({ \ #define kernel_mapping_pa_to_va(y) ({ \
unsigned long _y = y; \ unsigned long _y = y; \
(_y >= CONFIG_PHYS_RAM_BASE) ? \ (_y >= CONFIG_PHYS_RAM_BASE) ? \
(void *)((unsigned long)(_y) + va_kernel_pa_offset + XIP_OFFSET) : \ (void *)((unsigned long)(_y) + va_kernel_pa_offset + XIP_OFFSET) : \
(void *)((unsigned long)(_y) + va_kernel_xip_pa_offset); \ (void *)((unsigned long)(_y) + va_kernel_xip_pa_offset); \
}) })
#else
#define kernel_mapping_pa_to_va(x) ((void *)((unsigned long)(x) + va_kernel_pa_offset))
#endif
#define __pa_to_va_nodebug(x) linear_mapping_pa_to_va(x) #define __pa_to_va_nodebug(x) linear_mapping_pa_to_va(x)
#define linear_mapping_va_to_pa(x) ((unsigned long)(x) - va_pa_offset) #define linear_mapping_va_to_pa(x) ((unsigned long)(x) - va_pa_offset)
#ifdef CONFIG_XIP_KERNEL
#define kernel_mapping_va_to_pa(y) ({ \ #define kernel_mapping_va_to_pa(y) ({ \
unsigned long _y = y; \ unsigned long _y = y; \
(_y < kernel_virt_addr + XIP_OFFSET) ? \ (_y < kernel_virt_addr + XIP_OFFSET) ? \
((unsigned long)(_y) - va_kernel_xip_pa_offset) : \ ((unsigned long)(_y) - va_kernel_xip_pa_offset) : \
((unsigned long)(_y) - va_kernel_pa_offset - XIP_OFFSET); \ ((unsigned long)(_y) - va_kernel_pa_offset - XIP_OFFSET); \
}) })
#else
#define kernel_mapping_va_to_pa(x) ((unsigned long)(x) - va_kernel_pa_offset)
#endif
#define __va_to_pa_nodebug(x) ({ \ #define __va_to_pa_nodebug(x) ({ \
unsigned long _x = x; \ unsigned long _x = x; \
(_x < kernel_virt_addr) ? \ (_x < kernel_virt_addr) ? \
...@@ -141,7 +133,7 @@ extern unsigned long kernel_virt_addr; ...@@ -141,7 +133,7 @@ extern unsigned long kernel_virt_addr;
#else #else
#define __pa_to_va_nodebug(x) ((void *)((unsigned long) (x) + va_pa_offset)) #define __pa_to_va_nodebug(x) ((void *)((unsigned long) (x) + va_pa_offset))
#define __va_to_pa_nodebug(x) ((unsigned long)(x) - va_pa_offset) #define __va_to_pa_nodebug(x) ((unsigned long)(x) - va_pa_offset)
#endif #endif /* CONFIG_64BIT */
#ifdef CONFIG_DEBUG_VIRTUAL #ifdef CONFIG_DEBUG_VIRTUAL
extern phys_addr_t __virt_to_phys(unsigned long x); extern phys_addr_t __virt_to_phys(unsigned long x);
......
...@@ -77,6 +77,8 @@ ...@@ -77,6 +77,8 @@
#ifdef CONFIG_XIP_KERNEL #ifdef CONFIG_XIP_KERNEL
#define XIP_OFFSET SZ_8M #define XIP_OFFSET SZ_8M
#else
#define XIP_OFFSET 0
#endif #endif
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment