Skip to content

Commit 8ff97fa

Browse files
author
Russell King
committed
ARM: make the physical-relative calculation more obvious
The physical-relative calculation between the XIP text and data sections introduced by the previous patch was far from obvious. Let's simplify it by turning it into a macro which takes the two (virtual) addresses. This allows us to arrange the calculation in a more obvious manner - we can make it two sub-expressions which calculate the physical address for each symbol, and then takes the difference of those physical addresses. Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent d781145 commit 8ff97fa

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,18 @@
135135
#define PLAT_PHYS_OFFSET UL(CONFIG_PHYS_OFFSET)
136136

137137
#ifdef CONFIG_XIP_KERNEL
138-
#define PHYS_OFFSET_FIXUP \
139-
( XIP_VIRT_ADDR(CONFIG_XIP_PHYS_ADDR) - PAGE_OFFSET + \
140-
PLAT_PHYS_OFFSET - CONFIG_XIP_PHYS_ADDR )
138+
/*
139+
* When referencing data in RAM from the XIP region in a relative manner
140+
* with the MMU off, we need the relative offset between the two physical
141+
* addresses. The macro below achieves this, which is:
142+
* __pa(v_data) - __xip_pa(v_text)
143+
*/
144+
#define PHYS_RELATIVE(v_data, v_text) \
145+
(((v_data) - PAGE_OFFSET + PLAT_PHYS_OFFSET) - \
146+
((v_text) - XIP_VIRT_ADDR(CONFIG_XIP_PHYS_ADDR) + \
147+
CONFIG_XIP_PHYS_ADDR))
141148
#else
142-
#define PHYS_OFFSET_FIXUP 0
149+
#define PHYS_RELATIVE(v_data, v_text) ((v_data) - (v_text))
143150
#endif
144151

145152
#ifndef __ASSEMBLY__

‎arch/arm/mm/proc-v7.S‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ __errata_finish:
487487

488488
.align 2
489489
__v7_setup_stack_ptr:
490-
.word __v7_setup_stack - . + PHYS_OFFSET_FIXUP
490+
.word PHYS_RELATIVE(__v7_setup_stack, .)
491491
ENDPROC(__v7_setup)
492492

493493
.bss

0 commit comments

Comments
 (0)