Skip to content

Commit cada3c0

Browse files
author
Russell King
committed
ARM: P2V: extend to 16-bit translation offsets
MSM's memory is aligned to 2MB, which is more than we can do with our existing method as we're limited to the upper 8 bits. Extend this by using two instructions to 16 bits, automatically selected when MSM is enabled. Acked-by: Tony Lindgren <tony@atomide.com> Reviewed-by: Nicolas Pitre <nicolas.pitre@linaro.org> Tested-by: Nicolas Pitre <nicolas.pitre@linaro.org> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent dc21af9 commit cada3c0

4 files changed

Lines changed: 39 additions & 6 deletions

File tree

‎arch/arm/Kconfig‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ config ARM_PATCH_PHYS_VIRT
195195
bool "Patch physical to virtual translations at runtime (EXPERIMENTAL)"
196196
depends on EXPERIMENTAL
197197
depends on !XIP_KERNEL && !THUMB2_KERNEL && MMU
198-
depends on !ARCH_MSM
199198
depends on !ARCH_REALVIEW || !SPARSEMEM
200199
help
201200
Patch phys-to-virt translation functions at runtime according to
@@ -204,6 +203,10 @@ config ARM_PATCH_PHYS_VIRT
204203
This can only be used with non-XIP, non-Thumb2, MMU kernels where
205204
the base of physical memory is at a 16MB boundary.
206205

206+
config ARM_PATCH_PHYS_VIRT_16BIT
207+
def_bool y
208+
depends on ARM_PATCH_PHYS_VIRT && ARCH_MSM
209+
207210
source "init/Kconfig"
208211

209212
source "kernel/Kconfig.freezer"

‎arch/arm/include/asm/memory.h‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,29 +154,42 @@
154154
#ifndef __virt_to_phys
155155
#ifdef CONFIG_ARM_PATCH_PHYS_VIRT
156156

157+
/*
158+
* Constants used to force the right instruction encodings and shifts
159+
* so that all we need to do is modify the 8-bit constant field.
160+
*/
161+
#define __PV_BITS_31_24 0x81000000
162+
#define __PV_BITS_23_16 0x00810000
163+
157164
extern unsigned long __pv_phys_offset;
158165
#define PHYS_OFFSET __pv_phys_offset
159166

160-
#define __pv_stub(from,to,instr) \
167+
#define __pv_stub(from,to,instr,type) \
161168
__asm__("@ __pv_stub\n" \
162169
"1: " instr " %0, %1, %2\n" \
163170
" .pushsection .pv_table,\"a\"\n" \
164171
" .long 1b\n" \
165172
" .popsection\n" \
166173
: "=r" (to) \
167-
: "r" (from), "I" (0x81000000))
174+
: "r" (from), "I" (type))
168175

169176
static inline unsigned long __virt_to_phys(unsigned long x)
170177
{
171178
unsigned long t;
172-
__pv_stub(x, t, "add");
179+
__pv_stub(x, t, "add", __PV_BITS_31_24);
180+
#ifdef CONFIG_ARM_PATCH_PHYS_VIRT_16BIT
181+
__pv_stub(t, t, "add", __PV_BITS_23_16);
182+
#endif
173183
return t;
174184
}
175185

176186
static inline unsigned long __phys_to_virt(unsigned long x)
177187
{
178188
unsigned long t;
179-
__pv_stub(x, t, "sub");
189+
__pv_stub(x, t, "sub", __PV_BITS_31_24);
190+
#ifdef CONFIG_ARM_PATCH_PHYS_VIRT_16BIT
191+
__pv_stub(t, t, "sub", __PV_BITS_23_16);
192+
#endif
180193
return t;
181194
}
182195
#else

‎arch/arm/include/asm/module.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ struct mod_arch_specific {
3131

3232
/* Add __virt_to_phys patching state as well */
3333
#ifdef CONFIG_ARM_PATCH_PHYS_VIRT
34+
#ifdef CONFIG_ARM_PATCH_PHYS_VIRT_16BIT
35+
#define MODULE_ARCH_VERMAGIC_P2V "p2v16 "
36+
#else
3437
#define MODULE_ARCH_VERMAGIC_P2V "p2v8 "
38+
#endif
3539
#else
3640
#define MODULE_ARCH_VERMAGIC_P2V ""
3741
#endif

‎arch/arm/kernel/head.S‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,13 @@ __fixup_pv_table:
456456
add r4, r4, r3 @ adjust table start address
457457
add r5, r5, r3 @ adjust table end address
458458
str r8, [r7, r3]! @ save computed PHYS_OFFSET to __pv_phys_offset
459+
#ifndef CONFIG_ARM_PATCH_PHYS_VIRT_16BIT
459460
mov r6, r3, lsr #24 @ constant for add/sub instructions
460461
teq r3, r6, lsl #24 @ must be 16MiB aligned
462+
#else
463+
mov r6, r3, lsr #16 @ constant for add/sub instructions
464+
teq r3, r6, lsl #16 @ must be 64kiB aligned
465+
#endif
461466
bne __error
462467
str r6, [r7, #4] @ save to __pv_offset
463468
b __fixup_a_pv_table
@@ -471,10 +476,18 @@ ENDPROC(__fixup_pv_table)
471476

472477
.text
473478
__fixup_a_pv_table:
479+
#ifdef CONFIG_ARM_PATCH_PHYS_VIRT_16BIT
480+
and r0, r6, #255 @ offset bits 23-16
481+
mov r6, r6, lsr #8 @ offset bits 31-24
482+
#else
483+
mov r0, #0 @ just in case...
484+
#endif
474485
b 3f
475486
2: ldr ip, [r7, r3]
476487
bic ip, ip, #0x000000ff
477-
orr ip, ip, r6
488+
tst ip, #0x400 @ rotate shift tells us LS or MS byte
489+
orrne ip, ip, r6 @ mask in offset bits 31-24
490+
orreq ip, ip, r0 @ mask in offset bits 23-16
478491
str ip, [r7, r3]
479492
3: cmp r4, r5
480493
ldrcc r7, [r4], #4 @ use branch for delay slot

0 commit comments

Comments
 (0)