Skip to content

Commit a7fbc0d

Browse files
cchemparathywildea01
authored andcommitted
ARM: LPAE: factor out T1SZ and TTBR1 computations
This patch moves the TTBR1 offset calculation and the T1SZ calculation out of the TTB setup assembly code. This should not affect functionality in any way, but improves code readability as well as readability of subsequent patches in this series. Signed-off-by: Cyril Chemparathy <[email protected]> Signed-off-by: Vitaly Andrianov <[email protected]> Acked-by: Nicolas Pitre <[email protected]> Tested-by: Santosh Shilimkar <[email protected]> Tested-by: Subash Patel <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent 1fc84ae commit a7fbc0d

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

arch/arm/include/asm/pgtable-3level-hwdef.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,24 @@
7979
#define PHYS_MASK_SHIFT (40)
8080
#define PHYS_MASK ((1ULL << PHYS_MASK_SHIFT) - 1)
8181

82+
/*
83+
* TTBR0/TTBR1 split (PAGE_OFFSET):
84+
* 0x40000000: T0SZ = 2, T1SZ = 0 (not used)
85+
* 0x80000000: T0SZ = 0, T1SZ = 1
86+
* 0xc0000000: T0SZ = 0, T1SZ = 2
87+
*
88+
* Only use this feature if PHYS_OFFSET <= PAGE_OFFSET, otherwise
89+
* booting secondary CPUs would end up using TTBR1 for the identity
90+
* mapping set up in TTBR0.
91+
*/
92+
#if defined CONFIG_VMSPLIT_2G
93+
#define TTBR1_OFFSET 16 /* skip two L1 entries */
94+
#elif defined CONFIG_VMSPLIT_3G
95+
#define TTBR1_OFFSET (4096 * (1 + 3)) /* only L2, skip pgd + 3*pmd */
96+
#else
97+
#define TTBR1_OFFSET 0
98+
#endif
99+
100+
#define TTBR1_SIZE (((PAGE_OFFSET >> 30) - 1) << 16)
101+
82102
#endif

arch/arm/mm/proc-v7-3level.S

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -114,35 +114,22 @@ ENDPROC(cpu_v7_set_pte_ext)
114114
*/
115115
.macro v7_ttb_setup, zero, ttbr0, ttbr1, tmp
116116
ldr \tmp, =swapper_pg_dir @ swapper_pg_dir virtual address
117-
cmp \ttbr1, \tmp @ PHYS_OFFSET > PAGE_OFFSET? (branch below)
117+
cmp \ttbr1, \tmp @ PHYS_OFFSET > PAGE_OFFSET?
118118
mrc p15, 0, \tmp, c2, c0, 2 @ TTB control register
119119
orr \tmp, \tmp, #TTB_EAE
120120
ALT_SMP(orr \tmp, \tmp, #TTB_FLAGS_SMP)
121121
ALT_UP(orr \tmp, \tmp, #TTB_FLAGS_UP)
122122
ALT_SMP(orr \tmp, \tmp, #TTB_FLAGS_SMP << 16)
123123
ALT_UP(orr \tmp, \tmp, #TTB_FLAGS_UP << 16)
124124
/*
125-
* TTBR0/TTBR1 split (PAGE_OFFSET):
126-
* 0x40000000: T0SZ = 2, T1SZ = 0 (not used)
127-
* 0x80000000: T0SZ = 0, T1SZ = 1
128-
* 0xc0000000: T0SZ = 0, T1SZ = 2
129-
*
130-
* Only use this feature if PHYS_OFFSET <= PAGE_OFFSET, otherwise
131-
* booting secondary CPUs would end up using TTBR1 for the identity
132-
* mapping set up in TTBR0.
125+
* Only use split TTBRs if PHYS_OFFSET <= PAGE_OFFSET (cmp above),
126+
* otherwise booting secondary CPUs would end up using TTBR1 for the
127+
* identity mapping set up in TTBR0.
133128
*/
134-
bhi 9001f @ PHYS_OFFSET > PAGE_OFFSET?
135-
orr \tmp, \tmp, #(((PAGE_OFFSET >> 30) - 1) << 16) @ TTBCR.T1SZ
136-
#if defined CONFIG_VMSPLIT_2G
137-
/* PAGE_OFFSET == 0x80000000, T1SZ == 1 */
138-
add \ttbr1, \ttbr1, #1 << 4 @ skip two L1 entries
139-
#elif defined CONFIG_VMSPLIT_3G
140-
/* PAGE_OFFSET == 0xc0000000, T1SZ == 2 */
141-
add \ttbr1, \ttbr1, #4096 * (1 + 3) @ only L2 used, skip pgd+3*pmd
142-
#endif
143-
/* CONFIG_VMSPLIT_1G does not need TTBR1 adjustment */
144-
9001: mcr p15, 0, \tmp, c2, c0, 2 @ TTB control register
145-
mcrr p15, 1, \ttbr1, \zero, c2 @ load TTBR1
129+
orrls \tmp, \tmp, #TTBR1_SIZE @ TTBCR.T1SZ
130+
mcr p15, 0, \tmp, c2, c0, 2 @ TTBCR
131+
addls \ttbr1, \ttbr1, #TTBR1_OFFSET
132+
mcrr p15, 1, \ttbr1, \zero, c2 @ load TTBR1
146133
.endm
147134

148135
__CPUINIT

0 commit comments

Comments
 (0)