Skip to content

Commit 7094e6a

Browse files
AlexGhitipalmer-dabbelt
authored andcommitted
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: Alexandre Ghiti <[email protected]> Reviewed-by: Anup Patel <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 9b79878 commit 7094e6a

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

arch/riscv/include/asm/page.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,46 +93,38 @@ extern unsigned long va_pa_offset;
9393
#ifdef CONFIG_64BIT
9494
extern unsigned long va_kernel_pa_offset;
9595
#endif
96-
#ifdef CONFIG_XIP_KERNEL
9796
extern unsigned long va_kernel_xip_pa_offset;
98-
#endif
9997
extern unsigned long pfn_base;
10098
#define ARCH_PFN_OFFSET (pfn_base)
10199
#else
102100
#define va_pa_offset 0
103101
#ifdef CONFIG_64BIT
104102
#define va_kernel_pa_offset 0
105103
#endif
104+
#define va_kernel_xip_pa_offset 0
106105
#define ARCH_PFN_OFFSET (PAGE_OFFSET >> PAGE_SHIFT)
107106
#endif /* CONFIG_MMU */
108107

109108
extern unsigned long kernel_virt_addr;
110109

111110
#ifdef CONFIG_64BIT
112111
#define linear_mapping_pa_to_va(x) ((void *)((unsigned long)(x) + va_pa_offset))
113-
#ifdef CONFIG_XIP_KERNEL
114112
#define kernel_mapping_pa_to_va(y) ({ \
115113
unsigned long _y = y; \
116114
(_y >= CONFIG_PHYS_RAM_BASE) ? \
117115
(void *)((unsigned long)(_y) + va_kernel_pa_offset + XIP_OFFSET) : \
118116
(void *)((unsigned long)(_y) + va_kernel_xip_pa_offset); \
119117
})
120-
#else
121-
#define kernel_mapping_pa_to_va(x) ((void *)((unsigned long)(x) + va_kernel_pa_offset))
122-
#endif
123118
#define __pa_to_va_nodebug(x) linear_mapping_pa_to_va(x)
124119

125120
#define linear_mapping_va_to_pa(x) ((unsigned long)(x) - va_pa_offset)
126-
#ifdef CONFIG_XIP_KERNEL
127121
#define kernel_mapping_va_to_pa(y) ({ \
128122
unsigned long _y = y; \
129123
(_y < kernel_virt_addr + XIP_OFFSET) ? \
130124
((unsigned long)(_y) - va_kernel_xip_pa_offset) : \
131125
((unsigned long)(_y) - va_kernel_pa_offset - XIP_OFFSET); \
132126
})
133-
#else
134-
#define kernel_mapping_va_to_pa(x) ((unsigned long)(x) - va_kernel_pa_offset)
135-
#endif
127+
136128
#define __va_to_pa_nodebug(x) ({ \
137129
unsigned long _x = x; \
138130
(_x < kernel_virt_addr) ? \
@@ -141,7 +133,7 @@ extern unsigned long kernel_virt_addr;
141133
#else
142134
#define __pa_to_va_nodebug(x) ((void *)((unsigned long) (x) + va_pa_offset))
143135
#define __va_to_pa_nodebug(x) ((unsigned long)(x) - va_pa_offset)
144-
#endif
136+
#endif /* CONFIG_64BIT */
145137

146138
#ifdef CONFIG_DEBUG_VIRTUAL
147139
extern phys_addr_t __virt_to_phys(unsigned long x);

arch/riscv/include/asm/pgtable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777

7878
#ifdef CONFIG_XIP_KERNEL
7979
#define XIP_OFFSET SZ_8M
80+
#else
81+
#define XIP_OFFSET 0
8082
#endif
8183

8284
#ifndef __ASSEMBLY__

0 commit comments

Comments
 (0)