Commit 28cdac66 authored by Russell King's avatar Russell King

Merge branch 'pgt' (early part) into devel

parents 4073723a 36bb94ba
...@@ -151,13 +151,15 @@ extern void __cpu_copy_user_highpage(struct page *to, struct page *from, ...@@ -151,13 +151,15 @@ extern void __cpu_copy_user_highpage(struct page *to, struct page *from,
#define clear_page(page) memset((void *)(page), 0, PAGE_SIZE) #define clear_page(page) memset((void *)(page), 0, PAGE_SIZE)
extern void copy_page(void *to, const void *from); extern void copy_page(void *to, const void *from);
typedef unsigned long pteval_t;
#undef STRICT_MM_TYPECHECKS #undef STRICT_MM_TYPECHECKS
#ifdef STRICT_MM_TYPECHECKS #ifdef STRICT_MM_TYPECHECKS
/* /*
* These are used to make use of C type-checking.. * These are used to make use of C type-checking..
*/ */
typedef struct { unsigned long pte; } pte_t; typedef struct { pteval_t pte; } pte_t;
typedef struct { unsigned long pmd; } pmd_t; typedef struct { unsigned long pmd; } pmd_t;
typedef struct { unsigned long pgd[2]; } pgd_t; typedef struct { unsigned long pgd[2]; } pgd_t;
typedef struct { unsigned long pgprot; } pgprot_t; typedef struct { unsigned long pgprot; } pgprot_t;
...@@ -175,7 +177,7 @@ typedef struct { unsigned long pgprot; } pgprot_t; ...@@ -175,7 +177,7 @@ typedef struct { unsigned long pgprot; } pgprot_t;
/* /*
* .. while these make it easier on the compiler * .. while these make it easier on the compiler
*/ */
typedef unsigned long pte_t; typedef pteval_t pte_t;
typedef unsigned long pmd_t; typedef unsigned long pmd_t;
typedef unsigned long pgd_t[2]; typedef unsigned long pgd_t[2];
typedef unsigned long pgprot_t; typedef unsigned long pgprot_t;
......
...@@ -30,14 +30,16 @@ ...@@ -30,14 +30,16 @@
#define pmd_free(mm, pmd) do { } while (0) #define pmd_free(mm, pmd) do { } while (0)
#define pgd_populate(mm,pmd,pte) BUG() #define pgd_populate(mm,pmd,pte) BUG()
extern pgd_t *get_pgd_slow(struct mm_struct *mm); extern pgd_t *pgd_alloc(struct mm_struct *mm);
extern void free_pgd_slow(struct mm_struct *mm, pgd_t *pgd); extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
#define pgd_alloc(mm) get_pgd_slow(mm)
#define pgd_free(mm, pgd) free_pgd_slow(mm, pgd)
#define PGALLOC_GFP (GFP_KERNEL | __GFP_NOTRACK | __GFP_REPEAT | __GFP_ZERO) #define PGALLOC_GFP (GFP_KERNEL | __GFP_NOTRACK | __GFP_REPEAT | __GFP_ZERO)
static inline void clean_pte_table(pte_t *pte)
{
clean_dcache_area(pte + PTE_HWTABLE_PTRS, PTE_HWTABLE_SIZE);
}
/* /*
* Allocate one PTE table. * Allocate one PTE table.
* *
...@@ -45,14 +47,14 @@ extern void free_pgd_slow(struct mm_struct *mm, pgd_t *pgd); ...@@ -45,14 +47,14 @@ extern void free_pgd_slow(struct mm_struct *mm, pgd_t *pgd);
* into one table thus: * into one table thus:
* *
* +------------+ * +------------+
* | h/w pt 0 |
* +------------+
* | h/w pt 1 |
* +------------+
* | Linux pt 0 | * | Linux pt 0 |
* +------------+ * +------------+
* | Linux pt 1 | * | Linux pt 1 |
* +------------+ * +------------+
* | h/w pt 0 |
* +------------+
* | h/w pt 1 |
* +------------+
*/ */
static inline pte_t * static inline pte_t *
pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr) pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr)
...@@ -60,10 +62,8 @@ pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr) ...@@ -60,10 +62,8 @@ pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr)
pte_t *pte; pte_t *pte;
pte = (pte_t *)__get_free_page(PGALLOC_GFP); pte = (pte_t *)__get_free_page(PGALLOC_GFP);
if (pte) { if (pte)
clean_dcache_area(pte, sizeof(pte_t) * PTRS_PER_PTE); clean_pte_table(pte);
pte += PTRS_PER_PTE;
}
return pte; return pte;
} }
...@@ -79,10 +79,8 @@ pte_alloc_one(struct mm_struct *mm, unsigned long addr) ...@@ -79,10 +79,8 @@ pte_alloc_one(struct mm_struct *mm, unsigned long addr)
pte = alloc_pages(PGALLOC_GFP, 0); pte = alloc_pages(PGALLOC_GFP, 0);
#endif #endif
if (pte) { if (pte) {
if (!PageHighMem(pte)) { if (!PageHighMem(pte))
void *page = page_address(pte); clean_pte_table(page_address(pte));
clean_dcache_area(page, sizeof(pte_t) * PTRS_PER_PTE);
}
pgtable_page_ctor(pte); pgtable_page_ctor(pte);
} }
...@@ -94,10 +92,8 @@ pte_alloc_one(struct mm_struct *mm, unsigned long addr) ...@@ -94,10 +92,8 @@ pte_alloc_one(struct mm_struct *mm, unsigned long addr)
*/ */
static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte) static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
{ {
if (pte) { if (pte)
pte -= PTRS_PER_PTE;
free_page((unsigned long)pte); free_page((unsigned long)pte);
}
} }
static inline void pte_free(struct mm_struct *mm, pgtable_t pte) static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
...@@ -106,8 +102,10 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte) ...@@ -106,8 +102,10 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
__free_page(pte); __free_page(pte);
} }
static inline void __pmd_populate(pmd_t *pmdp, unsigned long pmdval) static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
unsigned long prot)
{ {
unsigned long pmdval = (pte + PTE_HWTABLE_OFF) | prot;
pmdp[0] = __pmd(pmdval); pmdp[0] = __pmd(pmdval);
pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t)); pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
flush_pmd_entry(pmdp); flush_pmd_entry(pmdp);
...@@ -122,20 +120,16 @@ static inline void __pmd_populate(pmd_t *pmdp, unsigned long pmdval) ...@@ -122,20 +120,16 @@ static inline void __pmd_populate(pmd_t *pmdp, unsigned long pmdval)
static inline void static inline void
pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep) pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
{ {
unsigned long pte_ptr = (unsigned long)ptep;
/* /*
* The pmd must be loaded with the physical * The pmd must be loaded with the physical address of the PTE table
* address of the PTE table
*/ */
pte_ptr -= PTRS_PER_PTE * sizeof(void *); __pmd_populate(pmdp, __pa(ptep), _PAGE_KERNEL_TABLE);
__pmd_populate(pmdp, __pa(pte_ptr) | _PAGE_KERNEL_TABLE);
} }
static inline void static inline void
pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep) pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
{ {
__pmd_populate(pmdp, page_to_pfn(ptep) << PAGE_SHIFT | _PAGE_USER_TABLE); __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
} }
#define pmd_pgtable(pmd) pmd_page(pmd) #define pmd_pgtable(pmd) pmd_page(pmd)
......
This diff is collapsed.
...@@ -55,42 +55,6 @@ enum ipi_msg_type { ...@@ -55,42 +55,6 @@ enum ipi_msg_type {
IPI_CPU_STOP, IPI_CPU_STOP,
}; };
static inline void identity_mapping_add(pgd_t *pgd, unsigned long start,
unsigned long end)
{
unsigned long addr, prot;
pmd_t *pmd;
prot = PMD_TYPE_SECT | PMD_SECT_AP_WRITE;
if (cpu_architecture() <= CPU_ARCH_ARMv5TEJ && !cpu_is_xscale())
prot |= PMD_BIT4;
for (addr = start & PGDIR_MASK; addr < end;) {
pmd = pmd_offset(pgd + pgd_index(addr), addr);
pmd[0] = __pmd(addr | prot);
addr += SECTION_SIZE;
pmd[1] = __pmd(addr | prot);
addr += SECTION_SIZE;
flush_pmd_entry(pmd);
outer_clean_range(__pa(pmd), __pa(pmd + 1));
}
}
static inline void identity_mapping_del(pgd_t *pgd, unsigned long start,
unsigned long end)
{
unsigned long addr;
pmd_t *pmd;
for (addr = start & PGDIR_MASK; addr < end; addr += PGDIR_SIZE) {
pmd = pmd_offset(pgd + pgd_index(addr), addr);
pmd[0] = __pmd(0);
pmd[1] = __pmd(0);
clean_pmd_entry(pmd);
outer_clean_range(__pa(pmd), __pa(pmd + 1));
}
}
int __cpuinit __cpu_up(unsigned int cpu) int __cpuinit __cpu_up(unsigned int cpu)
{ {
struct cpuinfo_arm *ci = &per_cpu(cpu_data, cpu); struct cpuinfo_arm *ci = &per_cpu(cpu_data, cpu);
......
...@@ -710,19 +710,19 @@ void __readwrite_bug(const char *fn) ...@@ -710,19 +710,19 @@ void __readwrite_bug(const char *fn)
} }
EXPORT_SYMBOL(__readwrite_bug); EXPORT_SYMBOL(__readwrite_bug);
void __pte_error(const char *file, int line, unsigned long val) void __pte_error(const char *file, int line, pte_t pte)
{ {
printk("%s:%d: bad pte %08lx.\n", file, line, val); printk("%s:%d: bad pte %08lx.\n", file, line, pte_val(pte));
} }
void __pmd_error(const char *file, int line, unsigned long val) void __pmd_error(const char *file, int line, pmd_t pmd)
{ {
printk("%s:%d: bad pmd %08lx.\n", file, line, val); printk("%s:%d: bad pmd %08lx.\n", file, line, pmd_val(pmd));
} }
void __pgd_error(const char *file, int line, unsigned long val) void __pgd_error(const char *file, int line, pgd_t pgd)
{ {
printk("%s:%d: bad pgd %08lx.\n", file, line, val); printk("%s:%d: bad pgd %08lx.\n", file, line, pgd_val(pgd));
} }
asmlinkage void __div0(void) asmlinkage void __div0(void)
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
obj-y := dma-mapping.o extable.o fault.o init.o \ obj-y := dma-mapping.o extable.o fault.o init.o \
iomap.o iomap.o
obj-$(CONFIG_MMU) += fault-armv.o flush.o ioremap.o mmap.o \ obj-$(CONFIG_MMU) += fault-armv.o flush.o idmap.o ioremap.o \
pgd.o mmu.o vmregion.o mmap.o pgd.o mmu.o vmregion.o
ifneq ($(CONFIG_MMU),y) ifneq ($(CONFIG_MMU),y)
obj-y += nommu.o obj-y += nommu.o
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "mm.h" #include "mm.h"
static unsigned long shared_pte_mask = L_PTE_MT_BUFFERABLE; static pteval_t shared_pte_mask = L_PTE_MT_BUFFERABLE;
#if __LINUX_ARM_ARCH__ < 6 #if __LINUX_ARM_ARCH__ < 6
/* /*
......
...@@ -108,7 +108,7 @@ void show_pte(struct mm_struct *mm, unsigned long addr) ...@@ -108,7 +108,7 @@ void show_pte(struct mm_struct *mm, unsigned long addr)
pte = pte_offset_map(pmd, addr); pte = pte_offset_map(pmd, addr);
printk(", *pte=%08lx", pte_val(*pte)); printk(", *pte=%08lx", pte_val(*pte));
printk(", *ppte=%08lx", pte_val(pte[-PTRS_PER_PTE])); printk(", *ppte=%08lx", pte_val(pte[PTE_HWTABLE_PTRS]));
pte_unmap(pte); pte_unmap(pte);
} while(0); } while(0);
......
#include <linux/kernel.h>
#include <asm/cputype.h>
#include <asm/pgalloc.h>
#include <asm/pgtable.h>
static void idmap_add_pmd(pgd_t *pgd, unsigned long addr, unsigned long end,
unsigned long prot)
{
pmd_t *pmd = pmd_offset(pgd, addr);
addr = (addr & PMD_MASK) | prot;
pmd[0] = __pmd(addr);
addr += SECTION_SIZE;
pmd[1] = __pmd(addr);
flush_pmd_entry(pmd);
}
void identity_mapping_add(pgd_t *pgd, unsigned long addr, unsigned long end)
{
unsigned long prot, next;
prot = PMD_TYPE_SECT | PMD_SECT_AP_WRITE;
if (cpu_architecture() <= CPU_ARCH_ARMv5TEJ && !cpu_is_xscale())
prot |= PMD_BIT4;
pgd += pgd_index(addr);
do {
next = pgd_addr_end(addr, end);
idmap_add_pmd(pgd, addr, next, prot);
} while (pgd++, addr = next, addr != end);
}
#ifdef CONFIG_SMP
static void idmap_del_pmd(pgd_t *pgd, unsigned long addr, unsigned long end)
{
pmd_t *pmd = pmd_offset(pgd, addr);
pmd_clear(pmd);
}
void identity_mapping_del(pgd_t *pgd, unsigned long addr, unsigned long end)
{
unsigned long next;
pgd += pgd_index(addr);
do {
next = pgd_addr_end(addr, end);
idmap_del_pmd(pgd, addr, next);
} while (pgd++, addr = next, addr != end);
}
#endif
/*
* In order to soft-boot, we need to insert a 1:1 mapping in place of
* the user-mode pages. This will then ensure that we have predictable
* results when turning the mmu off
*/
void setup_mm_for_reboot(char mode)
{
/*
* We need to access to user-mode page tables here. For kernel threads
* we don't have any user-mode mappings so we use the context that we
* "borrowed".
*/
identity_mapping_add(current->active_mm->pgd, 0, TASK_SIZE);
local_flush_tlb_all();
}
...@@ -16,7 +16,7 @@ static inline pmd_t *pmd_off_k(unsigned long virt) ...@@ -16,7 +16,7 @@ static inline pmd_t *pmd_off_k(unsigned long virt)
} }
struct mem_type { struct mem_type {
unsigned int prot_pte; pteval_t prot_pte;
unsigned int prot_l1; unsigned int prot_l1;
unsigned int prot_sect; unsigned int prot_sect;
unsigned int domain; unsigned int domain;
......
...@@ -63,7 +63,7 @@ struct cachepolicy { ...@@ -63,7 +63,7 @@ struct cachepolicy {
const char policy[16]; const char policy[16];
unsigned int cr_mask; unsigned int cr_mask;
unsigned int pmd; unsigned int pmd;
unsigned int pte; pteval_t pte;
}; };
static struct cachepolicy cache_policies[] __initdata = { static struct cachepolicy cache_policies[] __initdata = {
...@@ -191,7 +191,7 @@ void adjust_cr(unsigned long mask, unsigned long set) ...@@ -191,7 +191,7 @@ void adjust_cr(unsigned long mask, unsigned long set)
} }
#endif #endif
#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_WRITE #define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
#define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
static struct mem_type mem_types[] = { static struct mem_type mem_types[] = {
...@@ -236,19 +236,18 @@ static struct mem_type mem_types[] = { ...@@ -236,19 +236,18 @@ static struct mem_type mem_types[] = {
}, },
[MT_LOW_VECTORS] = { [MT_LOW_VECTORS] = {
.prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
L_PTE_EXEC, L_PTE_RDONLY,
.prot_l1 = PMD_TYPE_TABLE, .prot_l1 = PMD_TYPE_TABLE,
.domain = DOMAIN_USER, .domain = DOMAIN_USER,
}, },
[MT_HIGH_VECTORS] = { [MT_HIGH_VECTORS] = {
.prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
L_PTE_USER | L_PTE_EXEC, L_PTE_USER | L_PTE_RDONLY,
.prot_l1 = PMD_TYPE_TABLE, .prot_l1 = PMD_TYPE_TABLE,
.domain = DOMAIN_USER, .domain = DOMAIN_USER,
}, },
[MT_MEMORY] = { [MT_MEMORY] = {
.prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
L_PTE_WRITE | L_PTE_EXEC,
.prot_l1 = PMD_TYPE_TABLE, .prot_l1 = PMD_TYPE_TABLE,
.prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE, .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
.domain = DOMAIN_KERNEL, .domain = DOMAIN_KERNEL,
...@@ -259,21 +258,20 @@ static struct mem_type mem_types[] = { ...@@ -259,21 +258,20 @@ static struct mem_type mem_types[] = {
}, },
[MT_MEMORY_NONCACHED] = { [MT_MEMORY_NONCACHED] = {
.prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
L_PTE_WRITE | L_PTE_EXEC | L_PTE_MT_BUFFERABLE, L_PTE_MT_BUFFERABLE,
.prot_l1 = PMD_TYPE_TABLE, .prot_l1 = PMD_TYPE_TABLE,
.prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE, .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
.domain = DOMAIN_KERNEL, .domain = DOMAIN_KERNEL,
}, },
[MT_MEMORY_DTCM] = { [MT_MEMORY_DTCM] = {
.prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
L_PTE_WRITE, L_PTE_XN,
.prot_l1 = PMD_TYPE_TABLE, .prot_l1 = PMD_TYPE_TABLE,
.prot_sect = PMD_TYPE_SECT | PMD_SECT_XN, .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
.domain = DOMAIN_KERNEL, .domain = DOMAIN_KERNEL,
}, },
[MT_MEMORY_ITCM] = { [MT_MEMORY_ITCM] = {
.prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
L_PTE_WRITE | L_PTE_EXEC,
.prot_l1 = PMD_TYPE_TABLE, .prot_l1 = PMD_TYPE_TABLE,
.domain = DOMAIN_KERNEL, .domain = DOMAIN_KERNEL,
}, },
...@@ -480,7 +478,7 @@ static void __init build_mem_type_table(void) ...@@ -480,7 +478,7 @@ static void __init build_mem_type_table(void)
pgprot_user = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG | user_pgprot); pgprot_user = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG | user_pgprot);
pgprot_kernel = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG | pgprot_kernel = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG |
L_PTE_DIRTY | L_PTE_WRITE | kern_pgprot); L_PTE_DIRTY | kern_pgprot);
mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask; mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask; mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
...@@ -536,7 +534,7 @@ static pte_t * __init early_pte_alloc(pmd_t *pmd, unsigned long addr, unsigned l ...@@ -536,7 +534,7 @@ static pte_t * __init early_pte_alloc(pmd_t *pmd, unsigned long addr, unsigned l
{ {
if (pmd_none(*pmd)) { if (pmd_none(*pmd)) {
pte_t *pte = early_alloc(2 * PTRS_PER_PTE * sizeof(pte_t)); pte_t *pte = early_alloc(2 * PTRS_PER_PTE * sizeof(pte_t));
__pmd_populate(pmd, __pa(pte) | prot); __pmd_populate(pmd, __pa(pte), prot);
} }
BUG_ON(pmd_bad(*pmd)); BUG_ON(pmd_bad(*pmd));
return pte_offset_kernel(pmd, addr); return pte_offset_kernel(pmd, addr);
...@@ -554,7 +552,7 @@ static void __init alloc_init_pte(pmd_t *pmd, unsigned long addr, ...@@ -554,7 +552,7 @@ static void __init alloc_init_pte(pmd_t *pmd, unsigned long addr,
} }
static void __init alloc_init_section(pgd_t *pgd, unsigned long addr, static void __init alloc_init_section(pgd_t *pgd, unsigned long addr,
unsigned long end, unsigned long phys, unsigned long end, phys_addr_t phys,
const struct mem_type *type) const struct mem_type *type)
{ {
pmd_t *pmd = pmd_offset(pgd, addr); pmd_t *pmd = pmd_offset(pgd, addr);
...@@ -589,7 +587,8 @@ static void __init alloc_init_section(pgd_t *pgd, unsigned long addr, ...@@ -589,7 +587,8 @@ static void __init alloc_init_section(pgd_t *pgd, unsigned long addr,
static void __init create_36bit_mapping(struct map_desc *md, static void __init create_36bit_mapping(struct map_desc *md,
const struct mem_type *type) const struct mem_type *type)
{ {
unsigned long phys, addr, length, end; unsigned long addr, length, end;
phys_addr_t phys;
pgd_t *pgd; pgd_t *pgd;
addr = md->virtual; addr = md->virtual;
...@@ -1044,38 +1043,3 @@ void __init paging_init(struct machine_desc *mdesc) ...@@ -1044,38 +1043,3 @@ void __init paging_init(struct machine_desc *mdesc)
empty_zero_page = virt_to_page(zero_page); empty_zero_page = virt_to_page(zero_page);
__flush_dcache_page(NULL, empty_zero_page); __flush_dcache_page(NULL, empty_zero_page);
} }
/*
* In order to soft-boot, we need to insert a 1:1 mapping in place of
* the user-mode pages. This will then ensure that we have predictable
* results when turning the mmu off
*/
void setup_mm_for_reboot(char mode)
{
unsigned long base_pmdval;
pgd_t *pgd;
int i;
/*
* We need to access to user-mode page tables here. For kernel threads
* we don't have any user-mode mappings so we use the context that we
* "borrowed".
*/
pgd = current->active_mm->pgd;
base_pmdval = PMD_SECT_AP_WRITE | PMD_SECT_AP_READ | PMD_TYPE_SECT;
if (cpu_architecture() <= CPU_ARCH_ARMv5TEJ && !cpu_is_xscale())
base_pmdval |= PMD_BIT4;
for (i = 0; i < FIRST_USER_PGD_NR + USER_PTRS_PER_PGD; i++, pgd++) {
unsigned long pmdval = (i << PGDIR_SHIFT) | base_pmdval;
pmd_t *pmd;
pmd = pmd_off(pgd, i << PGDIR_SHIFT);
pmd[0] = __pmd(pmdval);
pmd[1] = __pmd(pmdval + (1 << (PGDIR_SHIFT - 1)));
flush_pmd_entry(pmd);
}
local_flush_tlb_all();
}
...@@ -17,12 +17,10 @@ ...@@ -17,12 +17,10 @@
#include "mm.h" #include "mm.h"
#define FIRST_KERNEL_PGD_NR (FIRST_USER_PGD_NR + USER_PTRS_PER_PGD)
/* /*
* need to get a 16k page for level 1 * need to get a 16k page for level 1
*/ */
pgd_t *get_pgd_slow(struct mm_struct *mm) pgd_t *pgd_alloc(struct mm_struct *mm)
{ {
pgd_t *new_pgd, *init_pgd; pgd_t *new_pgd, *init_pgd;
pmd_t *new_pmd, *init_pmd; pmd_t *new_pmd, *init_pmd;
...@@ -32,14 +30,14 @@ pgd_t *get_pgd_slow(struct mm_struct *mm) ...@@ -32,14 +30,14 @@ pgd_t *get_pgd_slow(struct mm_struct *mm)
if (!new_pgd) if (!new_pgd)
goto no_pgd; goto no_pgd;
memset(new_pgd, 0, FIRST_KERNEL_PGD_NR * sizeof(pgd_t)); memset(new_pgd, 0, USER_PTRS_PER_PGD * sizeof(pgd_t));
/* /*
* Copy over the kernel and IO PGD entries * Copy over the kernel and IO PGD entries
*/ */
init_pgd = pgd_offset_k(0); init_pgd = pgd_offset_k(0);
memcpy(new_pgd + FIRST_KERNEL_PGD_NR, init_pgd + FIRST_KERNEL_PGD_NR, memcpy(new_pgd + USER_PTRS_PER_PGD, init_pgd + USER_PTRS_PER_PGD,
(PTRS_PER_PGD - FIRST_KERNEL_PGD_NR) * sizeof(pgd_t)); (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
clean_dcache_area(new_pgd, PTRS_PER_PGD * sizeof(pgd_t)); clean_dcache_area(new_pgd, PTRS_PER_PGD * sizeof(pgd_t));
...@@ -73,28 +71,29 @@ pgd_t *get_pgd_slow(struct mm_struct *mm) ...@@ -73,28 +71,29 @@ pgd_t *get_pgd_slow(struct mm_struct *mm)
return NULL; return NULL;
} }
void free_pgd_slow(struct mm_struct *mm, pgd_t *pgd) void pgd_free(struct mm_struct *mm, pgd_t *pgd_base)
{ {
pgd_t *pgd;
pmd_t *pmd; pmd_t *pmd;
pgtable_t pte; pgtable_t pte;
if (!pgd) if (!pgd_base)
return; return;
/* pgd is always present and good */ pgd = pgd_base + pgd_index(0);
pmd = pmd_off(pgd, 0); if (pgd_none_or_clear_bad(pgd))
if (pmd_none(*pmd)) goto no_pgd;
goto free;
if (pmd_bad(*pmd)) { pmd = pmd_offset(pgd, 0);
pmd_ERROR(*pmd); if (pmd_none_or_clear_bad(pmd))
pmd_clear(pmd); goto no_pmd;
goto free;
}
pte = pmd_pgtable(*pmd); pte = pmd_pgtable(*pmd);
pmd_clear(pmd); pmd_clear(pmd);
pte_free(mm, pte); pte_free(mm, pte);
no_pmd:
pgd_clear(pgd);
pmd_free(mm, pmd); pmd_free(mm, pmd);
free: no_pgd:
free_pages((unsigned long) pgd, 2); free_pages((unsigned long) pgd_base, 2);
} }
...@@ -91,7 +91,7 @@ ...@@ -91,7 +91,7 @@
#if L_PTE_SHARED != PTE_EXT_SHARED #if L_PTE_SHARED != PTE_EXT_SHARED
#error PTE shared bit mismatch #error PTE shared bit mismatch
#endif #endif
#if (L_PTE_EXEC+L_PTE_USER+L_PTE_WRITE+L_PTE_DIRTY+L_PTE_YOUNG+\ #if (L_PTE_XN+L_PTE_USER+L_PTE_RDONLY+L_PTE_DIRTY+L_PTE_YOUNG+\
L_PTE_FILE+L_PTE_PRESENT) > L_PTE_SHARED L_PTE_FILE+L_PTE_PRESENT) > L_PTE_SHARED
#error Invalid Linux PTE bit settings #error Invalid Linux PTE bit settings
#endif #endif
...@@ -135,7 +135,7 @@ ...@@ -135,7 +135,7 @@
.endm .endm
.macro armv6_set_pte_ext pfx .macro armv6_set_pte_ext pfx
str r1, [r0], #-2048 @ linux version str r1, [r0], #2048 @ linux version
bic r3, r1, #0x000003fc bic r3, r1, #0x000003fc
bic r3, r3, #PTE_TYPE_MASK bic r3, r3, #PTE_TYPE_MASK
...@@ -146,9 +146,9 @@ ...@@ -146,9 +146,9 @@
and r2, r1, #L_PTE_MT_MASK and r2, r1, #L_PTE_MT_MASK
ldr r2, [ip, r2] ldr r2, [ip, r2]
tst r1, #L_PTE_WRITE eor r1, r1, #L_PTE_DIRTY
tstne r1, #L_PTE_DIRTY tst r1, #L_PTE_DIRTY|L_PTE_RDONLY
orreq r3, r3, #PTE_EXT_APX orrne r3, r3, #PTE_EXT_APX
tst r1, #L_PTE_USER tst r1, #L_PTE_USER
orrne r3, r3, #PTE_EXT_AP1 orrne r3, r3, #PTE_EXT_AP1
...@@ -158,8 +158,8 @@ ...@@ -158,8 +158,8 @@
bicne r3, r3, #PTE_EXT_APX | PTE_EXT_AP0 bicne r3, r3, #PTE_EXT_APX | PTE_EXT_AP0
#endif #endif
tst r1, #L_PTE_EXEC tst r1, #L_PTE_XN
orreq r3, r3, #PTE_EXT_XN orrne r3, r3, #PTE_EXT_XN
orr r3, r3, r2 orr r3, r3, r2
...@@ -187,9 +187,9 @@ ...@@ -187,9 +187,9 @@
* 1111 0xff r/w r/w * 1111 0xff r/w r/w
*/ */
.macro armv3_set_pte_ext wc_disable=1 .macro armv3_set_pte_ext wc_disable=1
str r1, [r0], #-2048 @ linux version str r1, [r0], #2048 @ linux version
eor r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY eor r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY
bic r2, r1, #PTE_SMALL_AP_MASK @ keep C, B bits bic r2, r1, #PTE_SMALL_AP_MASK @ keep C, B bits
bic r2, r2, #PTE_TYPE_MASK bic r2, r2, #PTE_TYPE_MASK
...@@ -198,7 +198,7 @@ ...@@ -198,7 +198,7 @@
tst r3, #L_PTE_USER @ user? tst r3, #L_PTE_USER @ user?
orrne r2, r2, #PTE_SMALL_AP_URO_SRW orrne r2, r2, #PTE_SMALL_AP_URO_SRW
tst r3, #L_PTE_WRITE | L_PTE_DIRTY @ write and dirty? tst r3, #L_PTE_RDONLY | L_PTE_DIRTY @ write and dirty?
orreq r2, r2, #PTE_SMALL_AP_UNO_SRW orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
tst r3, #L_PTE_PRESENT | L_PTE_YOUNG @ present and young? tst r3, #L_PTE_PRESENT | L_PTE_YOUNG @ present and young?
...@@ -210,7 +210,7 @@ ...@@ -210,7 +210,7 @@
bicne r2, r2, #PTE_BUFFERABLE bicne r2, r2, #PTE_BUFFERABLE
#endif #endif
.endif .endif
str r2, [r0] @ hardware version str r2, [r0] @ hardware version
.endm .endm
...@@ -230,9 +230,9 @@ ...@@ -230,9 +230,9 @@
* 1111 11 r/w r/w * 1111 11 r/w r/w
*/ */
.macro xscale_set_pte_ext_prologue .macro xscale_set_pte_ext_prologue
str r1, [r0], #-2048 @ linux version str r1, [r0] @ linux version
eor r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY eor r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY
bic r2, r1, #PTE_SMALL_AP_MASK @ keep C, B bits bic r2, r1, #PTE_SMALL_AP_MASK @ keep C, B bits
orr r2, r2, #PTE_TYPE_EXT @ extended page orr r2, r2, #PTE_TYPE_EXT @ extended page
...@@ -240,7 +240,7 @@ ...@@ -240,7 +240,7 @@
tst r3, #L_PTE_USER @ user? tst r3, #L_PTE_USER @ user?
orrne r2, r2, #PTE_EXT_AP_URO_SRW @ yes -> user r/o, system r/w orrne r2, r2, #PTE_EXT_AP_URO_SRW @ yes -> user r/o, system r/w
tst r3, #L_PTE_WRITE | L_PTE_DIRTY @ write and dirty? tst r3, #L_PTE_RDONLY | L_PTE_DIRTY @ write and dirty?
orreq r2, r2, #PTE_EXT_AP_UNO_SRW @ yes -> user n/a, system r/w orreq r2, r2, #PTE_EXT_AP_UNO_SRW @ yes -> user n/a, system r/w
@ combined with user -> user r/w @ combined with user -> user r/w
.endm .endm
...@@ -249,7 +249,7 @@ ...@@ -249,7 +249,7 @@
tst r3, #L_PTE_PRESENT | L_PTE_YOUNG @ present and young? tst r3, #L_PTE_PRESENT | L_PTE_YOUNG @ present and young?
movne r2, #0 @ no -> fault movne r2, #0 @ no -> fault
str r2, [r0] @ hardware version str r2, [r0, #2048]! @ hardware version
mov ip, #0 mov ip, #0
mcr p15, 0, r0, c7, c10, 1 @ clean L1 D line mcr p15, 0, r0, c7, c10, 1 @ clean L1 D line
mcr p15, 0, ip, c7, c10, 4 @ data write barrier mcr p15, 0, ip, c7, c10, 4 @ data write barrier
......
...@@ -124,15 +124,13 @@ ENDPROC(cpu_v7_switch_mm) ...@@ -124,15 +124,13 @@ ENDPROC(cpu_v7_switch_mm)
* Set a level 2 translation table entry. * Set a level 2 translation table entry.
* *
* - ptep - pointer to level 2 translation table entry * - ptep - pointer to level 2 translation table entry
* (hardware version is stored at -1024 bytes) * (hardware version is stored at +2048 bytes)
* - pte - PTE value to store * - pte - PTE value to store
* - ext - value for extended PTE bits * - ext - value for extended PTE bits
*/ */
ENTRY(cpu_v7_set_pte_ext) ENTRY(cpu_v7_set_pte_ext)
#ifdef CONFIG_MMU #ifdef CONFIG_MMU
ARM( str r1, [r0], #-2048 ) @ linux version str r1, [r0] @ linux version
THUMB( str r1, [r0] ) @ linux version
THUMB( sub r0, r0, #2048 )
bic r3, r1, #0x000003f0 bic r3, r1, #0x000003f0
bic r3, r3, #PTE_TYPE_MASK bic r3, r3, #PTE_TYPE_MASK
...@@ -142,9 +140,9 @@ ENTRY(cpu_v7_set_pte_ext) ...@@ -142,9 +140,9 @@ ENTRY(cpu_v7_set_pte_ext)
tst r1, #1 << 4 tst r1, #1 << 4
orrne r3, r3, #PTE_EXT_TEX(1) orrne r3, r3, #PTE_EXT_TEX(1)
tst r1, #L_PTE_WRITE eor r1, r1, #L_PTE_DIRTY
tstne r1, #L_PTE_DIRTY tst r1, #L_PTE_RDONLY | L_PTE_DIRTY
orreq r3, r3, #PTE_EXT_APX orrne r3, r3, #PTE_EXT_APX
tst r1, #L_PTE_USER tst r1, #L_PTE_USER
orrne r3, r3, #PTE_EXT_AP1 orrne r3, r3, #PTE_EXT_AP1
...@@ -154,14 +152,14 @@ ENTRY(cpu_v7_set_pte_ext) ...@@ -154,14 +152,14 @@ ENTRY(cpu_v7_set_pte_ext)
bicne r3, r3, #PTE_EXT_APX | PTE_EXT_AP0 bicne r3, r3, #PTE_EXT_APX | PTE_EXT_AP0
#endif #endif
tst r1, #L_PTE_EXEC tst r1, #L_PTE_XN
orreq r3, r3, #PTE_EXT_XN orrne r3, r3, #PTE_EXT_XN
tst r1, #L_PTE_YOUNG tst r1, #L_PTE_YOUNG
tstne r1, #L_PTE_PRESENT tstne r1, #L_PTE_PRESENT
moveq r3, #0 moveq r3, #0
str r3, [r0] str r3, [r0, #2048]!
mcr p15, 0, r0, c7, c10, 1 @ flush_pte mcr p15, 0, r0, c7, c10, 1 @ flush_pte
#endif #endif
mov pc, lr mov pc, lr
......
...@@ -500,8 +500,8 @@ ENTRY(cpu_xscale_set_pte_ext) ...@@ -500,8 +500,8 @@ ENTRY(cpu_xscale_set_pte_ext)
@ @
@ Erratum 40: must set memory to write-through for user read-only pages @ Erratum 40: must set memory to write-through for user read-only pages
@ @
and ip, r1, #(L_PTE_MT_MASK | L_PTE_USER | L_PTE_WRITE) & ~(4 << 2) and ip, r1, #(L_PTE_MT_MASK | L_PTE_USER | L_PTE_RDONLY) & ~(4 << 2)
teq ip, #L_PTE_MT_WRITEBACK | L_PTE_USER teq ip, #L_PTE_MT_WRITEBACK | L_PTE_USER | L_PTE_RDONLY
moveq r1, #L_PTE_MT_WRITETHROUGH moveq r1, #L_PTE_MT_WRITETHROUGH
and r1, r1, #L_PTE_MT_MASK and r1, r1, #L_PTE_MT_MASK
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment