Skip to content

Commit 3fbd55e

Browse files
author
Russell King
committed
Merge branch 'for-rmk/lpae' of git://git.kernel.org/pub/scm/linux/kernel/git/will/linux into devel-stable
Conflicts: arch/arm/kernel/smp.c Please pull these miscellaneous LPAE fixes I've been collecting for a while now for 3.11. They've been tested and reviewed by quite a few people, and most of the patches are pretty trivial. -- Will Deacon.
2 parents b3f288d + a469abd commit 3fbd55e

13 files changed

Lines changed: 139 additions & 96 deletions

File tree

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <linux/types.h>
1919
#include <linux/sizes.h>
2020

21+
#include <asm/cache.h>
22+
2123
#ifdef CONFIG_NEED_MACH_MEMORY_H
2224
#include <mach/memory.h>
2325
#endif
@@ -141,6 +143,20 @@
141143
#define page_to_phys(page) (__pfn_to_phys(page_to_pfn(page)))
142144
#define phys_to_page(phys) (pfn_to_page(__phys_to_pfn(phys)))
143145

146+
/*
147+
* Minimum guaranted alignment in pgd_alloc(). The page table pointers passed
148+
* around in head.S and proc-*.S are shifted by this amount, in order to
149+
* leave spare high bits for systems with physical address extension. This
150+
* does not fully accomodate the 40-bit addressing capability of ARM LPAE, but
151+
* gives us about 38-bits or so.
152+
*/
153+
#ifdef CONFIG_ARM_LPAE
154+
#define ARCH_PGD_SHIFT L1_CACHE_SHIFT
155+
#else
156+
#define ARCH_PGD_SHIFT 0
157+
#endif
158+
#define ARCH_PGD_MASK ((1 << ARCH_PGD_SHIFT) - 1)
159+
144160
#ifndef __ASSEMBLY__
145161

146162
/*
@@ -207,7 +223,7 @@ static inline unsigned long __phys_to_virt(unsigned long x)
207223
* direct-mapped view. We assume this is the first page
208224
* of RAM in the mem_map as well.
209225
*/
210-
#define PHYS_PFN_OFFSET (PHYS_OFFSET >> PAGE_SHIFT)
226+
#define PHYS_PFN_OFFSET ((unsigned long)(PHYS_OFFSET >> PAGE_SHIFT))
211227

212228
/*
213229
* These are *only* valid on the kernel direct mapped RAM memory.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/* PAGE_SHIFT determines the page size */
1414
#define PAGE_SHIFT 12
1515
#define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT)
16-
#define PAGE_MASK (~(PAGE_SIZE-1))
16+
#define PAGE_MASK (~((1 << PAGE_SHIFT) - 1))
1717

1818
#ifndef __ASSEMBLY__
1919

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,24 @@
8383
#define PHYS_MASK_SHIFT (40)
8484
#define PHYS_MASK ((1ULL << PHYS_MASK_SHIFT) - 1)
8585

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

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#define PTRS_PER_PMD 512
3434
#define PTRS_PER_PGD 4
3535

36-
#define PTE_HWTABLE_PTRS (PTRS_PER_PTE)
36+
#define PTE_HWTABLE_PTRS (0)
3737
#define PTE_HWTABLE_OFF (0)
3838
#define PTE_HWTABLE_SIZE (PTRS_PER_PTE * sizeof(u64))
3939

@@ -48,16 +48,16 @@
4848
#define PMD_SHIFT 21
4949

5050
#define PMD_SIZE (1UL << PMD_SHIFT)
51-
#define PMD_MASK (~(PMD_SIZE-1))
51+
#define PMD_MASK (~((1 << PMD_SHIFT) - 1))
5252
#define PGDIR_SIZE (1UL << PGDIR_SHIFT)
53-
#define PGDIR_MASK (~(PGDIR_SIZE-1))
53+
#define PGDIR_MASK (~((1 << PGDIR_SHIFT) - 1))
5454

5555
/*
5656
* section address mask and size definitions.
5757
*/
5858
#define SECTION_SHIFT 21
5959
#define SECTION_SIZE (1UL << SECTION_SHIFT)
60-
#define SECTION_MASK (~(SECTION_SIZE-1))
60+
#define SECTION_MASK (~((1 << SECTION_SHIFT) - 1))
6161

6262
#define USER_PTRS_PER_PGD (PAGE_OFFSET / PGDIR_SIZE)
6363

‎arch/arm/include/asm/proc-fns.h‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ extern struct processor {
6060
/*
6161
* Set the page table
6262
*/
63-
void (*switch_mm)(unsigned long pgd_phys, struct mm_struct *mm);
63+
void (*switch_mm)(phys_addr_t pgd_phys, struct mm_struct *mm);
6464
/*
6565
* Set a possibly extended PTE. Non-extended PTEs should
6666
* ignore 'ext'.
@@ -82,7 +82,7 @@ extern void cpu_proc_init(void);
8282
extern void cpu_proc_fin(void);
8383
extern int cpu_do_idle(void);
8484
extern void cpu_dcache_clean_area(void *, int);
85-
extern void cpu_do_switch_mm(unsigned long pgd_phys, struct mm_struct *mm);
85+
extern void cpu_do_switch_mm(phys_addr_t pgd_phys, struct mm_struct *mm);
8686
#ifdef CONFIG_ARM_LPAE
8787
extern void cpu_set_pte_ext(pte_t *ptep, pte_t pte);
8888
#else
@@ -116,13 +116,25 @@ extern void cpu_resume(void);
116116
#define cpu_switch_mm(pgd,mm) cpu_do_switch_mm(virt_to_phys(pgd),mm)
117117

118118
#ifdef CONFIG_ARM_LPAE
119+
120+
#define cpu_get_ttbr(nr) \
121+
({ \
122+
u64 ttbr; \
123+
__asm__("mrrc p15, " #nr ", %Q0, %R0, c2" \
124+
: "=r" (ttbr)); \
125+
ttbr; \
126+
})
127+
128+
#define cpu_set_ttbr(nr, val) \
129+
do { \
130+
u64 ttbr = val; \
131+
__asm__("mcrr p15, " #nr ", %Q0, %R0, c2" \
132+
: : "r" (ttbr)); \
133+
} while (0)
134+
119135
#define cpu_get_pgd() \
120136
({ \
121-
unsigned long pg, pg2; \
122-
__asm__("mrrc p15, 0, %0, %1, c2" \
123-
: "=r" (pg), "=r" (pg2) \
124-
: \
125-
: "cc"); \
137+
u64 pg = cpu_get_ttbr(0); \
126138
pg &= ~(PTRS_PER_PGD*sizeof(pgd_t)-1); \
127139
(pgd_t *)phys_to_virt(pg); \
128140
})

‎arch/arm/include/uapi/asm/hwcap.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
#define HWCAP_IDIVT (1 << 18)
2626
#define HWCAP_VFPD32 (1 << 19) /* set if VFP has 32 regs (not 16) */
2727
#define HWCAP_IDIV (HWCAP_IDIVA | HWCAP_IDIVT)
28-
28+
#define HWCAP_LPAE (1 << 20)
2929

3030
#endif /* _UAPI__ASMARM_HWCAP_H */

‎arch/arm/kernel/head.S‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ ENDPROC(stext)
156156
*
157157
* Returns:
158158
* r0, r3, r5-r7 corrupted
159-
* r4 = physical page table address
159+
* r4 = page table (see ARCH_PGD_SHIFT in asm/memory.h)
160160
*/
161161
__create_page_tables:
162162
pgtbl r4, r8 @ page table address
@@ -331,6 +331,7 @@ __create_page_tables:
331331
#endif
332332
#ifdef CONFIG_ARM_LPAE
333333
sub r4, r4, #0x1000 @ point to the PGD table
334+
mov r4, r4, lsr #ARCH_PGD_SHIFT
334335
#endif
335336
mov pc, lr
336337
ENDPROC(__create_page_tables)
@@ -408,7 +409,7 @@ __secondary_data:
408409
* r0 = cp#15 control register
409410
* r1 = machine ID
410411
* r2 = atags or dtb pointer
411-
* r4 = page table pointer
412+
* r4 = page table (see ARCH_PGD_SHIFT in asm/memory.h)
412413
* r9 = processor ID
413414
* r13 = *virtual* address to jump to upon completion
414415
*/
@@ -427,10 +428,7 @@ __enable_mmu:
427428
#ifdef CONFIG_CPU_ICACHE_DISABLE
428429
bic r0, r0, #CR_I
429430
#endif
430-
#ifdef CONFIG_ARM_LPAE
431-
mov r5, #0
432-
mcrr p15, 0, r4, r5, c2 @ load TTBR0
433-
#else
431+
#ifndef CONFIG_ARM_LPAE
434432
mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
435433
domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
436434
domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \

‎arch/arm/kernel/setup.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ void __init early_print(const char *str, ...)
367367

368368
static void __init cpuid_init_hwcaps(void)
369369
{
370-
unsigned int divide_instrs;
370+
unsigned int divide_instrs, vmsa;
371371

372372
if (cpu_architecture() < CPU_ARCH_ARMv7)
373373
return;
@@ -380,6 +380,11 @@ static void __init cpuid_init_hwcaps(void)
380380
case 1:
381381
elf_hwcap |= HWCAP_IDIVT;
382382
}
383+
384+
/* LPAE implies atomic ldrd/strd instructions */
385+
vmsa = (read_cpuid_ext(CPUID_EXT_MMFR0) & 0xf) >> 0;
386+
if (vmsa >= 5)
387+
elf_hwcap |= HWCAP_LPAE;
383388
}
384389

385390
static void __init feat_v6_fixup(void)
@@ -892,6 +897,7 @@ static const char *hwcap_str[] = {
892897
"vfpv4",
893898
"idiva",
894899
"idivt",
900+
"lpae",
895901
NULL
896902
};
897903

‎arch/arm/kernel/smp.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ void __init smp_set_ops(struct smp_operations *ops)
7979
smp_ops = *ops;
8080
};
8181

82+
static unsigned long get_arch_pgd(pgd_t *pgd)
83+
{
84+
phys_addr_t pgdir = virt_to_phys(pgd);
85+
BUG_ON(pgdir & ARCH_PGD_MASK);
86+
return pgdir >> ARCH_PGD_SHIFT;
87+
}
88+
8289
int __cpuinit __cpu_up(unsigned int cpu, struct task_struct *idle)
8390
{
8491
int ret;
@@ -93,8 +100,8 @@ int __cpuinit __cpu_up(unsigned int cpu, struct task_struct *idle)
93100
#endif
94101

95102
#ifdef CONFIG_MMU
96-
secondary_data.pgdir = virt_to_phys(idmap_pgd);
97-
secondary_data.swapper_pg_dir = virt_to_phys(swapper_pg_dir);
103+
secondary_data.pgdir = get_arch_pgd(idmap_pgd);
104+
secondary_data.swapper_pg_dir = get_arch_pgd(swapper_pg_dir);
98105
#endif
99106
__cpuc_flush_dcache_area(&secondary_data, sizeof(secondary_data));
100107
outer_clean_range(__pa(&secondary_data), __pa(&secondary_data + 1));

‎arch/arm/mm/context.c‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <asm/smp_plat.h>
2121
#include <asm/thread_notify.h>
2222
#include <asm/tlbflush.h>
23+
#include <asm/proc-fns.h>
2324

2425
/*
2526
* On ARMv6, we have the following structure in the Context ID:
@@ -55,17 +56,11 @@ static cpumask_t tlb_flush_pending;
5556
#ifdef CONFIG_ARM_LPAE
5657
static void cpu_set_reserved_ttbr0(void)
5758
{
58-
unsigned long ttbl = __pa(swapper_pg_dir);
59-
unsigned long ttbh = 0;
60-
6159
/*
6260
* Set TTBR0 to swapper_pg_dir which contains only global entries. The
6361
* ASID is set to 0.
6462
*/
65-
asm volatile(
66-
" mcrr p15, 0, %0, %1, c2 @ set TTBR0\n"
67-
:
68-
: "r" (ttbl), "r" (ttbh));
63+
cpu_set_ttbr(0, __pa(swapper_pg_dir));
6964
isb();
7065
}
7166
#else

0 commit comments

Comments
 (0)