···11+/*22+ * OpenRISC Linux33+ *44+ * Linux architectural port borrowing liberally from similar works of55+ * others. All original copyrights apply as per the original source66+ * declaration.77+ *88+ * OpenRISC implementation:99+ * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>1010+ * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>1111+ * et al.1212+ *1313+ * This program is free software; you can redistribute it and/or modify1414+ * it under the terms of the GNU General Public License as published by1515+ * the Free Software Foundation; either version 2 of the License, or1616+ * (at your option) any later version.1717+ */1818+1919+#ifndef __ASM_OPENRISC_CACHE_H2020+#define __ASM_OPENRISC_CACHE_H2121+2222+/* FIXME: How can we replace these with values from the CPU...2323+ * they shouldn't be hard-coded!2424+ */2525+2626+#define L1_CACHE_BYTES 162727+#define L1_CACHE_SHIFT 42828+2929+#endif /* __ASM_OPENRISC_CACHE_H */
+87
arch/openrisc/include/asm/fixmap.h
···11+/*22+ * OpenRISC Linux33+ *44+ * Linux architectural port borrowing liberally from similar works of55+ * others. All original copyrights apply as per the original source66+ * declaration.77+ *88+ * OpenRISC implementation:99+ * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>1010+ * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>1111+ * et al.1212+ *1313+ * This program is free software; you can redistribute it and/or modify1414+ * it under the terms of the GNU General Public License as published by1515+ * the Free Software Foundation; either version 2 of the License, or1616+ * (at your option) any later version.1717+ */1818+1919+#ifndef __ASM_OPENRISC_FIXMAP_H2020+#define __ASM_OPENRISC_FIXMAP_H2121+2222+/* Why exactly do we need 2 empty pages between the top of the fixed2323+ * addresses and the top of virtual memory? Something is using that2424+ * memory space but not sure what right now... If you find it, leave2525+ * a comment here.2626+ */2727+#define FIXADDR_TOP ((unsigned long) (-2*PAGE_SIZE))2828+2929+#include <linux/kernel.h>3030+#include <asm/page.h>3131+3232+/*3333+ * On OpenRISC we use these special fixed_addresses for doing ioremap3434+ * early in the boot process before memory initialization is complete.3535+ * This is used, in particular, by the early serial console code.3636+ *3737+ * It's not really 'fixmap', per se, but fits loosely into the same3838+ * paradigm.3939+ */4040+enum fixed_addresses {4141+ /*4242+ * FIX_IOREMAP entries are useful for mapping physical address4343+ * space before ioremap() is useable, e.g. really early in boot4444+ * before kmalloc() is working.4545+ */4646+#define FIX_N_IOREMAPS 324747+ FIX_IOREMAP_BEGIN,4848+ FIX_IOREMAP_END = FIX_IOREMAP_BEGIN + FIX_N_IOREMAPS - 1,4949+ __end_of_fixed_addresses5050+};5151+5252+#define FIXADDR_SIZE (__end_of_fixed_addresses << PAGE_SHIFT)5353+/* FIXADDR_BOTTOM might be a better name here... */5454+#define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE)5555+5656+#define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))5757+#define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)5858+5959+/*6060+ * 'index to address' translation. If anyone tries to use the idx6161+ * directly without tranlation, we catch the bug with a NULL-deference6262+ * kernel oops. Illegal ranges of incoming indices are caught too.6363+ */6464+static __always_inline unsigned long fix_to_virt(const unsigned int idx)6565+{6666+ /*6767+ * this branch gets completely eliminated after inlining,6868+ * except when someone tries to use fixaddr indices in an6969+ * illegal way. (such as mixing up address types or using7070+ * out-of-range indices).7171+ *7272+ * If it doesn't get removed, the linker will complain7373+ * loudly with a reasonably clear error message..7474+ */7575+ if (idx >= __end_of_fixed_addresses)7676+ BUG();7777+7878+ return __fix_to_virt(idx);7979+}8080+8181+static inline unsigned long virt_to_fix(const unsigned long vaddr)8282+{8383+ BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);8484+ return __virt_to_fix(vaddr);8585+}8686+8787+#endif
+24
arch/openrisc/include/asm/memblock.h
···11+/*22+ * OpenRISC Linux33+ *44+ * Linux architectural port borrowing liberally from similar works of55+ * others. All original copyrights apply as per the original source66+ * declaration.77+ *88+ * OpenRISC implementation:99+ * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>1010+ * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>1111+ * et al.1212+ *1313+ * This program is free software; you can redistribute it and/or modify1414+ * it under the terms of the GNU General Public License as published by1515+ * the Free Software Foundation; either version 2 of the License, or1616+ * (at your option) any later version.1717+ */1818+1919+#ifndef __ASM_OPENRISC_MEMBLOCK_H2020+#define __ASM_OPENRISC_MEMBLOCK_H2121+2222+/* empty */2323+2424+#endif /* __ASM_OPENRISC_MEMBLOCK_H */
+26
arch/openrisc/include/asm/mmu.h
···11+/*22+ * OpenRISC Linux33+ *44+ * Linux architectural port borrowing liberally from similar works of55+ * others. All original copyrights apply as per the original source66+ * declaration.77+ *88+ * OpenRISC implementation:99+ * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>1010+ * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>1111+ * et al.1212+ *1313+ * This program is free software; you can redistribute it and/or modify1414+ * it under the terms of the GNU General Public License as published by1515+ * the Free Software Foundation; either version 2 of the License, or1616+ * (at your option) any later version.1717+ */1818+1919+#ifndef __ASM_OPENRISC_MMU_H2020+#define __ASM_OPENRISC_MMU_H2121+2222+#ifndef __ASSEMBLY__2323+typedef unsigned long mm_context_t;2424+#endif2525+2626+#endif
+43
arch/openrisc/include/asm/mmu_context.h
···11+/*22+ * OpenRISC Linux33+ *44+ * Linux architectural port borrowing liberally from similar works of55+ * others. All original copyrights apply as per the original source66+ * declaration.77+ *88+ * OpenRISC implementation:99+ * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>1010+ * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>1111+ * et al.1212+ *1313+ * This program is free software; you can redistribute it and/or modify1414+ * it under the terms of the GNU General Public License as published by1515+ * the Free Software Foundation; either version 2 of the License, or1616+ * (at your option) any later version.1717+ */1818+1919+#ifndef __ASM_OPENRISC_MMU_CONTEXT_H2020+#define __ASM_OPENRISC_MMU_CONTEXT_H2121+2222+#include <asm-generic/mm_hooks.h>2323+2424+extern int init_new_context(struct task_struct *tsk, struct mm_struct *mm);2525+extern void destroy_context(struct mm_struct *mm);2626+extern void switch_mm(struct mm_struct *prev, struct mm_struct *next,2727+ struct task_struct *tsk);2828+2929+#define deactivate_mm(tsk, mm) do { } while (0)3030+3131+#define activate_mm(prev, next) switch_mm((prev), (next), NULL)3232+3333+/* current active pgd - this is similar to other processors pgd3434+ * registers like cr3 on the i3863535+ */3636+3737+extern volatile pgd_t *current_pgd; /* defined in arch/openrisc/mm/fault.c */3838+3939+static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)4040+{4141+}4242+4343+#endif
+110
arch/openrisc/include/asm/page.h
···11+/*22+ * OpenRISC Linux33+ *44+ * Linux architectural port borrowing liberally from similar works of55+ * others. All original copyrights apply as per the original source66+ * declaration.77+ *88+ * OpenRISC implementation:99+ * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>1010+ * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>1111+ * et al.1212+ *1313+ * This program is free software; you can redistribute it and/or modify1414+ * it under the terms of the GNU General Public License as published by1515+ * the Free Software Foundation; either version 2 of the License, or1616+ * (at your option) any later version.1717+ */1818+1919+#ifndef __ASM_OPENRISC_PAGE_H2020+#define __ASM_OPENRISC_PAGE_H2121+2222+2323+/* PAGE_SHIFT determines the page size */2424+2525+#define PAGE_SHIFT 132626+#ifdef __ASSEMBLY__2727+#define PAGE_SIZE (1 << PAGE_SHIFT)2828+#else2929+#define PAGE_SIZE (1UL << PAGE_SHIFT)3030+#endif3131+#define PAGE_MASK (~(PAGE_SIZE-1))3232+3333+#define PAGE_OFFSET 0xc00000003434+#define KERNELBASE PAGE_OFFSET3535+3636+/* This is not necessarily the right place for this, but it's needed by3737+ * drivers/of/fdt.c3838+ */3939+#include <asm/setup.h>4040+4141+#ifndef __ASSEMBLY__4242+4343+#define get_user_page(vaddr) __get_free_page(GFP_KERNEL)4444+#define free_user_page(page, addr) free_page(addr)4545+4646+#define clear_page(page) memset((page), 0, PAGE_SIZE)4747+#define copy_page(to, from) memcpy((to), (from), PAGE_SIZE)4848+4949+#define clear_user_page(page, vaddr, pg) clear_page(page)5050+#define copy_user_page(to, from, vaddr, pg) copy_page(to, from)5151+5252+/*5353+ * These are used to make use of C type-checking..5454+ */5555+typedef struct {5656+ unsigned long pte;5757+} pte_t;5858+typedef struct {5959+ unsigned long pgd;6060+} pgd_t;6161+typedef struct {6262+ unsigned long pgprot;6363+} pgprot_t;6464+typedef struct page *pgtable_t;6565+6666+#define pte_val(x) ((x).pte)6767+#define pgd_val(x) ((x).pgd)6868+#define pgprot_val(x) ((x).pgprot)6969+7070+#define __pte(x) ((pte_t) { (x) })7171+#define __pgd(x) ((pgd_t) { (x) })7272+#define __pgprot(x) ((pgprot_t) { (x) })7373+7474+extern unsigned long memory_start;7575+extern unsigned long memory_end;7676+7777+#endif /* !__ASSEMBLY__ */7878+7979+8080+#ifndef __ASSEMBLY__8181+8282+#define __va(x) ((void *)((unsigned long)(x) + PAGE_OFFSET))8383+#define __pa(x) ((unsigned long) (x) - PAGE_OFFSET)8484+8585+#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT)8686+#define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT)8787+8888+#define virt_to_page(addr) \8989+ (mem_map + (((unsigned long)(addr)-PAGE_OFFSET) >> PAGE_SHIFT))9090+#define page_to_virt(page) \9191+ ((((page) - mem_map) << PAGE_SHIFT) + PAGE_OFFSET)9292+9393+#define page_to_phys(page) ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT)9494+9595+#define pfn_valid(pfn) ((pfn) < max_mapnr)9696+9797+#define virt_addr_valid(kaddr) (((void *)(kaddr) >= (void *)PAGE_OFFSET) && \9898+ ((void *)(kaddr) < (void *)memory_end))9999+100100+#endif /* __ASSEMBLY__ */101101+102102+103103+#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \104104+ VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)105105+106106+107107+#include <asm-generic/memory_model.h>108108+#include <asm-generic/getorder.h>109109+110110+#endif /* __ASM_OPENRISC_PAGE_H */
+102
arch/openrisc/include/asm/pgalloc.h
···11+/*22+ * OpenRISC Linux33+ *44+ * Linux architectural port borrowing liberally from similar works of55+ * others. All original copyrights apply as per the original source66+ * declaration.77+ *88+ * OpenRISC implementation:99+ * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>1010+ * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>1111+ * et al.1212+ *1313+ * This program is free software; you can redistribute it and/or modify1414+ * it under the terms of the GNU General Public License as published by1515+ * the Free Software Foundation; either version 2 of the License, or1616+ * (at your option) any later version.1717+ */1818+1919+#ifndef __ASM_OPENRISC_PGALLOC_H2020+#define __ASM_OPENRISC_PGALLOC_H2121+2222+#include <asm/page.h>2323+#include <linux/threads.h>2424+#include <linux/mm.h>2525+#include <linux/memblock.h>2626+#include <linux/bootmem.h>2727+2828+extern int mem_init_done;2929+3030+#define pmd_populate_kernel(mm, pmd, pte) \3131+ set_pmd(pmd, __pmd(_KERNPG_TABLE + __pa(pte)))3232+3333+static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,3434+ struct page *pte)3535+{3636+ set_pmd(pmd, __pmd(_KERNPG_TABLE +3737+ ((unsigned long)page_to_pfn(pte) <<3838+ (unsigned long) PAGE_SHIFT)));3939+}4040+4141+/*4242+ * Allocate and free page tables.4343+ */4444+static inline pgd_t *pgd_alloc(struct mm_struct *mm)4545+{4646+ pgd_t *ret = (pgd_t *)__get_free_page(GFP_KERNEL);4747+4848+ if (ret) {4949+ memset(ret, 0, USER_PTRS_PER_PGD * sizeof(pgd_t));5050+ memcpy(ret + USER_PTRS_PER_PGD,5151+ swapper_pg_dir + USER_PTRS_PER_PGD,5252+ (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));5353+5454+ }5555+ return ret;5656+}5757+5858+#if 05959+/* FIXME: This seems to be the preferred style, but we are using6060+ * current_pgd (from mm->pgd) to load kernel pages so we need it6161+ * initialized. This needs to be looked into.6262+ */6363+extern inline pgd_t *pgd_alloc(struct mm_struct *mm)6464+{6565+ return (pgd_t *)get_zeroed_page(GFP_KERNEL);6666+}6767+#endif6868+6969+static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)7070+{7171+ free_page((unsigned long)pgd);7272+}7373+7474+extern pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address);7575+7676+static inline struct page *pte_alloc_one(struct mm_struct *mm,7777+ unsigned long address)7878+{7979+ struct page *pte;8080+ pte = alloc_pages(GFP_KERNEL|__GFP_REPEAT, 0);8181+ if (pte)8282+ clear_page(page_address(pte));8383+ return pte;8484+}8585+8686+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)8787+{8888+ free_page((unsigned long)pte);8989+}9090+9191+static inline void pte_free(struct mm_struct *mm, struct page *pte)9292+{9393+ __free_page(pte);9494+}9595+9696+9797+#define __pte_free_tlb(tlb, pte, addr) tlb_remove_page((tlb), (pte))9898+#define pmd_pgtable(pmd) pmd_page(pmd)9999+100100+#define check_pgt_cache() do { } while (0)101101+102102+#endif
+463
arch/openrisc/include/asm/pgtable.h
···11+/*22+ * OpenRISC Linux33+ *44+ * Linux architectural port borrowing liberally from similar works of55+ * others. All original copyrights apply as per the original source66+ * declaration.77+ *88+ * OpenRISC implementation:99+ * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>1010+ * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>1111+ * et al.1212+ *1313+ * This program is free software; you can redistribute it and/or modify1414+ * it under the terms of the GNU General Public License as published by1515+ * the Free Software Foundation; either version 2 of the License, or1616+ * (at your option) any later version.1717+ */1818+1919+/* or32 pgtable.h - macros and functions to manipulate page tables2020+ *2121+ * Based on:2222+ * include/asm-cris/pgtable.h2323+ */2424+2525+#ifndef __ASM_OPENRISC_PGTABLE_H2626+#define __ASM_OPENRISC_PGTABLE_H2727+2828+#include <asm-generic/pgtable-nopmd.h>2929+3030+#ifndef __ASSEMBLY__3131+#include <asm/mmu.h>3232+#include <asm/fixmap.h>3333+3434+/*3535+ * The Linux memory management assumes a three-level page table setup. On3636+ * or32, we use that, but "fold" the mid level into the top-level page3737+ * table. Since the MMU TLB is software loaded through an interrupt, it3838+ * supports any page table structure, so we could have used a three-level3939+ * setup, but for the amounts of memory we normally use, a two-level is4040+ * probably more efficient.4141+ *4242+ * This file contains the functions and defines necessary to modify and use4343+ * the or32 page table tree.4444+ */4545+4646+extern void paging_init(void);4747+4848+/* Certain architectures need to do special things when pte's4949+ * within a page table are directly modified. Thus, the following5050+ * hook is made available.5151+ */5252+#define set_pte(pteptr, pteval) ((*(pteptr)) = (pteval))5353+#define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval)5454+/*5555+ * (pmds are folded into pgds so this doesn't get actually called,5656+ * but the define is needed for a generic inline function.)5757+ */5858+#define set_pmd(pmdptr, pmdval) (*(pmdptr) = pmdval)5959+6060+#define PGDIR_SHIFT (PAGE_SHIFT + (PAGE_SHIFT-2))6161+#define PGDIR_SIZE (1UL << PGDIR_SHIFT)6262+#define PGDIR_MASK (~(PGDIR_SIZE-1))6363+6464+/*6565+ * entries per page directory level: we use a two-level, so6666+ * we don't really have any PMD directory physically.6767+ * pointers are 4 bytes so we can use the page size and6868+ * divide it by 4 (shift by 2).6969+ */7070+#define PTRS_PER_PTE (1UL << (PAGE_SHIFT-2))7171+7272+#define PTRS_PER_PGD (1UL << (PAGE_SHIFT-2))7373+7474+/* calculate how many PGD entries a user-level program can use7575+ * the first mappable virtual address is 07676+ * (TASK_SIZE is the maximum virtual address space)7777+ */7878+7979+#define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE)8080+#define FIRST_USER_ADDRESS 08181+8282+/*8383+ * Kernels own virtual memory area.8484+ */8585+8686+/*8787+ * The size and location of the vmalloc area are chosen so that modules8888+ * placed in this area aren't more than a 28-bit signed offset from any8989+ * kernel functions that they may need. This greatly simplifies handling9090+ * of the relocations for l.j and l.jal instructions as we don't need to9191+ * introduce any trampolines for reaching "distant" code.9292+ *9393+ * 64 MB of vmalloc area is comparable to what's available on other arches.9494+ */9595+9696+#define VMALLOC_START (PAGE_OFFSET-0x04000000)9797+#define VMALLOC_END (PAGE_OFFSET)9898+#define VMALLOC_VMADDR(x) ((unsigned long)(x))9999+100100+/* Define some higher level generic page attributes.101101+ *102102+ * If you change _PAGE_CI definition be sure to change it in103103+ * io.h for ioremap_nocache() too.104104+ */105105+106106+/*107107+ * An OR32 PTE looks like this:108108+ *109109+ * | 31 ... 10 | 9 | 8 ... 6 | 5 | 4 | 3 | 2 | 1 | 0 |110110+ * Phys pg.num L PP Index D A WOM WBC CI CC111111+ *112112+ * L : link113113+ * PPI: Page protection index114114+ * D : Dirty115115+ * A : Accessed116116+ * WOM: Weakly ordered memory117117+ * WBC: Write-back cache118118+ * CI : Cache inhibit119119+ * CC : Cache coherent120120+ *121121+ * The protection bits below should correspond to the layout of the actual122122+ * PTE as per above123123+ */124124+125125+#define _PAGE_CC 0x001 /* software: pte contains a translation */126126+#define _PAGE_CI 0x002 /* cache inhibit */127127+#define _PAGE_WBC 0x004 /* write back cache */128128+#define _PAGE_FILE 0x004 /* set: pagecache, unset: swap (when !PRESENT) */129129+#define _PAGE_WOM 0x008 /* weakly ordered memory */130130+131131+#define _PAGE_A 0x010 /* accessed */132132+#define _PAGE_D 0x020 /* dirty */133133+#define _PAGE_URE 0x040 /* user read enable */134134+#define _PAGE_UWE 0x080 /* user write enable */135135+136136+#define _PAGE_SRE 0x100 /* superuser read enable */137137+#define _PAGE_SWE 0x200 /* superuser write enable */138138+#define _PAGE_EXEC 0x400 /* software: page is executable */139139+#define _PAGE_U_SHARED 0x800 /* software: page is shared in user space */140140+141141+/* 0x001 is cache coherency bit, which should always be set to142142+ * 1 - for SMP (when we support it)143143+ * 0 - otherwise144144+ *145145+ * we just reuse this bit in software for _PAGE_PRESENT and146146+ * force it to 0 when loading it into TLB.147147+ */148148+#define _PAGE_PRESENT _PAGE_CC149149+#define _PAGE_USER _PAGE_URE150150+#define _PAGE_WRITE (_PAGE_UWE | _PAGE_SWE)151151+#define _PAGE_DIRTY _PAGE_D152152+#define _PAGE_ACCESSED _PAGE_A153153+#define _PAGE_NO_CACHE _PAGE_CI154154+#define _PAGE_SHARED _PAGE_U_SHARED155155+#define _PAGE_READ (_PAGE_URE | _PAGE_SRE)156156+157157+#define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)158158+#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)159159+#define _PAGE_ALL (_PAGE_PRESENT | _PAGE_ACCESSED)160160+#define _KERNPG_TABLE \161161+ (_PAGE_BASE | _PAGE_SRE | _PAGE_SWE | _PAGE_ACCESSED | _PAGE_DIRTY)162162+163163+#define PAGE_NONE __pgprot(_PAGE_ALL)164164+#define PAGE_READONLY __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE)165165+#define PAGE_READONLY_X __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE | _PAGE_EXEC)166166+#define PAGE_SHARED \167167+ __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE | _PAGE_UWE | _PAGE_SWE \168168+ | _PAGE_SHARED)169169+#define PAGE_SHARED_X \170170+ __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE | _PAGE_UWE | _PAGE_SWE \171171+ | _PAGE_SHARED | _PAGE_EXEC)172172+#define PAGE_COPY __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE)173173+#define PAGE_COPY_X __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE | _PAGE_EXEC)174174+175175+#define PAGE_KERNEL \176176+ __pgprot(_PAGE_ALL | _PAGE_SRE | _PAGE_SWE \177177+ | _PAGE_SHARED | _PAGE_DIRTY | _PAGE_EXEC)178178+#define PAGE_KERNEL_RO \179179+ __pgprot(_PAGE_ALL | _PAGE_SRE \180180+ | _PAGE_SHARED | _PAGE_DIRTY | _PAGE_EXEC)181181+#define PAGE_KERNEL_NOCACHE \182182+ __pgprot(_PAGE_ALL | _PAGE_SRE | _PAGE_SWE \183183+ | _PAGE_SHARED | _PAGE_DIRTY | _PAGE_EXEC | _PAGE_CI)184184+185185+#define __P000 PAGE_NONE186186+#define __P001 PAGE_READONLY_X187187+#define __P010 PAGE_COPY188188+#define __P011 PAGE_COPY_X189189+#define __P100 PAGE_READONLY190190+#define __P101 PAGE_READONLY_X191191+#define __P110 PAGE_COPY192192+#define __P111 PAGE_COPY_X193193+194194+#define __S000 PAGE_NONE195195+#define __S001 PAGE_READONLY_X196196+#define __S010 PAGE_SHARED197197+#define __S011 PAGE_SHARED_X198198+#define __S100 PAGE_READONLY199199+#define __S101 PAGE_READONLY_X200200+#define __S110 PAGE_SHARED201201+#define __S111 PAGE_SHARED_X202202+203203+/* zero page used for uninitialized stuff */204204+extern unsigned long empty_zero_page[2048];205205+#define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))206206+207207+/* number of bits that fit into a memory pointer */208208+#define BITS_PER_PTR (8*sizeof(unsigned long))209209+210210+/* to align the pointer to a pointer address */211211+#define PTR_MASK (~(sizeof(void *)-1))212212+213213+/* sizeof(void*)==1<<SIZEOF_PTR_LOG2 */214214+/* 64-bit machines, beware! SRB. */215215+#define SIZEOF_PTR_LOG2 2216216+217217+/* to find an entry in a page-table */218218+#define PAGE_PTR(address) \219219+((unsigned long)(address)>>(PAGE_SHIFT-SIZEOF_PTR_LOG2)&PTR_MASK&~PAGE_MASK)220220+221221+/* to set the page-dir */222222+#define SET_PAGE_DIR(tsk, pgdir)223223+224224+#define pte_none(x) (!pte_val(x))225225+#define pte_present(x) (pte_val(x) & _PAGE_PRESENT)226226+#define pte_clear(mm, addr, xp) do { pte_val(*(xp)) = 0; } while (0)227227+228228+#define pmd_none(x) (!pmd_val(x))229229+#define pmd_bad(x) ((pmd_val(x) & (~PAGE_MASK)) != _KERNPG_TABLE)230230+#define pmd_present(x) (pmd_val(x) & _PAGE_PRESENT)231231+#define pmd_clear(xp) do { pmd_val(*(xp)) = 0; } while (0)232232+233233+/*234234+ * The following only work if pte_present() is true.235235+ * Undefined behaviour if not..236236+ */237237+238238+static inline int pte_read(pte_t pte) { return pte_val(pte) & _PAGE_READ; }239239+static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_WRITE; }240240+static inline int pte_exec(pte_t pte) { return pte_val(pte) & _PAGE_EXEC; }241241+static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; }242242+static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }243243+static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; }244244+static inline int pte_special(pte_t pte) { return 0; }245245+static inline pte_t pte_mkspecial(pte_t pte) { return pte; }246246+247247+static inline pte_t pte_wrprotect(pte_t pte)248248+{249249+ pte_val(pte) &= ~(_PAGE_WRITE);250250+ return pte;251251+}252252+253253+static inline pte_t pte_rdprotect(pte_t pte)254254+{255255+ pte_val(pte) &= ~(_PAGE_READ);256256+ return pte;257257+}258258+259259+static inline pte_t pte_exprotect(pte_t pte)260260+{261261+ pte_val(pte) &= ~(_PAGE_EXEC);262262+ return pte;263263+}264264+265265+static inline pte_t pte_mkclean(pte_t pte)266266+{267267+ pte_val(pte) &= ~(_PAGE_DIRTY);268268+ return pte;269269+}270270+271271+static inline pte_t pte_mkold(pte_t pte)272272+{273273+ pte_val(pte) &= ~(_PAGE_ACCESSED);274274+ return pte;275275+}276276+277277+static inline pte_t pte_mkwrite(pte_t pte)278278+{279279+ pte_val(pte) |= _PAGE_WRITE;280280+ return pte;281281+}282282+283283+static inline pte_t pte_mkread(pte_t pte)284284+{285285+ pte_val(pte) |= _PAGE_READ;286286+ return pte;287287+}288288+289289+static inline pte_t pte_mkexec(pte_t pte)290290+{291291+ pte_val(pte) |= _PAGE_EXEC;292292+ return pte;293293+}294294+295295+static inline pte_t pte_mkdirty(pte_t pte)296296+{297297+ pte_val(pte) |= _PAGE_DIRTY;298298+ return pte;299299+}300300+301301+static inline pte_t pte_mkyoung(pte_t pte)302302+{303303+ pte_val(pte) |= _PAGE_ACCESSED;304304+ return pte;305305+}306306+307307+/*308308+ * Conversion functions: convert a page and protection to a page entry,309309+ * and a page entry and page directory to the page they refer to.310310+ */311311+312312+/* What actually goes as arguments to the various functions is less than313313+ * obvious, but a rule of thumb is that struct page's goes as struct page *,314314+ * really physical DRAM addresses are unsigned long's, and DRAM "virtual"315315+ * addresses (the 0xc0xxxxxx's) goes as void *'s.316316+ */317317+318318+static inline pte_t __mk_pte(void *page, pgprot_t pgprot)319319+{320320+ pte_t pte;321321+ /* the PTE needs a physical address */322322+ pte_val(pte) = __pa(page) | pgprot_val(pgprot);323323+ return pte;324324+}325325+326326+#define mk_pte(page, pgprot) __mk_pte(page_address(page), (pgprot))327327+328328+#define mk_pte_phys(physpage, pgprot) \329329+({ \330330+ pte_t __pte; \331331+ \332332+ pte_val(__pte) = (physpage) + pgprot_val(pgprot); \333333+ __pte; \334334+})335335+336336+static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)337337+{338338+ pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot);339339+ return pte;340340+}341341+342342+343343+/*344344+ * pte_val refers to a page in the 0x0xxxxxxx physical DRAM interval345345+ * __pte_page(pte_val) refers to the "virtual" DRAM interval346346+ * pte_pagenr refers to the page-number counted starting from the virtual347347+ * DRAM start348348+ */349349+350350+static inline unsigned long __pte_page(pte_t pte)351351+{352352+ /* the PTE contains a physical address */353353+ return (unsigned long)__va(pte_val(pte) & PAGE_MASK);354354+}355355+356356+#define pte_pagenr(pte) ((__pte_page(pte) - PAGE_OFFSET) >> PAGE_SHIFT)357357+358358+/* permanent address of a page */359359+360360+#define __page_address(page) (PAGE_OFFSET + (((page) - mem_map) << PAGE_SHIFT))361361+#define pte_page(pte) (mem_map+pte_pagenr(pte))362362+363363+/*364364+ * only the pte's themselves need to point to physical DRAM (see above)365365+ * the pagetable links are purely handled within the kernel SW and thus366366+ * don't need the __pa and __va transformations.367367+ */368368+static inline void pmd_set(pmd_t *pmdp, pte_t *ptep)369369+{370370+ pmd_val(*pmdp) = _KERNPG_TABLE | (unsigned long) ptep;371371+}372372+373373+#define pmd_page(pmd) (pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT))374374+#define pmd_page_kernel(pmd) ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))375375+376376+/* to find an entry in a page-table-directory. */377377+#define pgd_index(address) ((address >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))378378+379379+#define __pgd_offset(address) pgd_index(address)380380+381381+#define pgd_offset(mm, address) ((mm)->pgd+pgd_index(address))382382+383383+/* to find an entry in a kernel page-table-directory */384384+#define pgd_offset_k(address) pgd_offset(&init_mm, address)385385+386386+#define __pmd_offset(address) \387387+ (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))388388+389389+/*390390+ * the pte page can be thought of an array like this: pte_t[PTRS_PER_PTE]391391+ *392392+ * this macro returns the index of the entry in the pte page which would393393+ * control the given virtual address394394+ */395395+#define __pte_offset(address) \396396+ (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))397397+#define pte_offset_kernel(dir, address) \398398+ ((pte_t *) pmd_page_kernel(*(dir)) + __pte_offset(address))399399+#define pte_offset_map(dir, address) \400400+ ((pte_t *)page_address(pmd_page(*(dir))) + __pte_offset(address))401401+#define pte_offset_map_nested(dir, address) \402402+ pte_offset_map(dir, address)403403+404404+#define pte_unmap(pte) do { } while (0)405405+#define pte_unmap_nested(pte) do { } while (0)406406+#define pte_pfn(x) ((unsigned long)(((x).pte)) >> PAGE_SHIFT)407407+#define pfn_pte(pfn, prot) __pte((((pfn) << PAGE_SHIFT)) | pgprot_val(prot))408408+409409+#define pte_ERROR(e) \410410+ printk(KERN_ERR "%s:%d: bad pte %p(%08lx).\n", \411411+ __FILE__, __LINE__, &(e), pte_val(e))412412+#define pgd_ERROR(e) \413413+ printk(KERN_ERR "%s:%d: bad pgd %p(%08lx).\n", \414414+ __FILE__, __LINE__, &(e), pgd_val(e))415415+416416+extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; /* defined in head.S */417417+418418+/*419419+ * or32 doesn't have any external MMU info: the kernel page420420+ * tables contain all the necessary information.421421+ *422422+ * Actually I am not sure on what this could be used for.423423+ */424424+static inline void update_mmu_cache(struct vm_area_struct *vma,425425+ unsigned long address, pte_t *pte)426426+{427427+}428428+429429+/* __PHX__ FIXME, SWAP, this probably doesn't work */430430+431431+/* Encode and de-code a swap entry (must be !pte_none(e) && !pte_present(e)) */432432+/* Since the PAGE_PRESENT bit is bit 4, we can use the bits above */433433+434434+#define __swp_type(x) (((x).val >> 5) & 0x7f)435435+#define __swp_offset(x) ((x).val >> 12)436436+#define __swp_entry(type, offset) \437437+ ((swp_entry_t) { ((type) << 5) | ((offset) << 12) })438438+#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })439439+#define __swp_entry_to_pte(x) ((pte_t) { (x).val })440440+441441+/* Encode and decode a nonlinear file mapping entry */442442+443443+#define PTE_FILE_MAX_BITS 26444444+#define pte_to_pgoff(x) (pte_val(x) >> 6)445445+#define pgoff_to_pte(x) __pte(((x) << 6) | _PAGE_FILE)446446+447447+#define kern_addr_valid(addr) (1)448448+449449+#define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \450450+ remap_pfn_range(vma, vaddr, pfn, size, prot)451451+452452+#include <asm-generic/pgtable.h>453453+454454+/*455455+ * No page table caches to initialise456456+ */457457+#define pgtable_cache_init() do { } while (0)458458+#define io_remap_page_range remap_page_range459459+460460+typedef pte_t *pte_addr_t;461461+462462+#endif /* __ASSEMBLY__ */463463+#endif /* __ASM_OPENRISC_PGTABLE_H */
+34
arch/openrisc/include/asm/tlb.h
···11+/*22+ * OpenRISC Linux33+ *44+ * Linux architectural port borrowing liberally from similar works of55+ * others. All original copyrights apply as per the original source66+ * declaration.77+ *88+ * OpenRISC implementation:99+ * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>1010+ * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>1111+ * et al.1212+ *1313+ * This program is free software; you can redistribute it and/or modify1414+ * it under the terms of the GNU General Public License as published by1515+ * the Free Software Foundation; either version 2 of the License, or1616+ * (at your option) any later version.1717+ */1818+1919+#ifndef __ASM_OPENRISC_TLB_H__2020+#define __ASM_OPENRISC_TLB_H__2121+2222+/*2323+ * or32 doesn't need any special per-pte or2424+ * per-vma handling..2525+ */2626+#define tlb_start_vma(tlb, vma) do { } while (0)2727+#define tlb_end_vma(tlb, vma) do { } while (0)2828+#define __tlb_remove_tlb_entry(tlb, ptep, address) do { } while (0)2929+3030+#define tlb_flush(tlb) flush_tlb_mm((tlb)->mm)3131+#include <linux/pagemap.h>3232+#include <asm-generic/tlb.h>3333+3434+#endif /* __ASM_OPENRISC_TLB_H__ */
+55
arch/openrisc/include/asm/tlbflush.h
···11+/*22+ * OpenRISC Linux33+ *44+ * Linux architectural port borrowing liberally from similar works of55+ * others. All original copyrights apply as per the original source66+ * declaration.77+ *88+ * OpenRISC implementation:99+ * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>1010+ * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>1111+ * et al.1212+ *1313+ * This program is free software; you can redistribute it and/or modify1414+ * it under the terms of the GNU General Public License as published by1515+ * the Free Software Foundation; either version 2 of the License, or1616+ * (at your option) any later version.1717+ */1818+1919+#ifndef __ASM_OPENRISC_TLBFLUSH_H2020+#define __ASM_OPENRISC_TLBFLUSH_H2121+2222+#include <linux/mm.h>2323+#include <asm/processor.h>2424+#include <asm/pgtable.h>2525+#include <asm/pgalloc.h>2626+#include <asm/current.h>2727+#include <linux/sched.h>2828+2929+/*3030+ * - flush_tlb() flushes the current mm struct TLBs3131+ * - flush_tlb_all() flushes all processes TLBs3232+ * - flush_tlb_mm(mm) flushes the specified mm context TLB's3333+ * - flush_tlb_page(vma, vmaddr) flushes one page3434+ * - flush_tlb_range(mm, start, end) flushes a range of pages3535+ */3636+3737+void flush_tlb_all(void);3838+void flush_tlb_mm(struct mm_struct *mm);3939+void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr);4040+void flush_tlb_range(struct vm_area_struct *vma,4141+ unsigned long start,4242+ unsigned long end);4343+4444+static inline void flush_tlb(void)4545+{4646+ flush_tlb_mm(current->mm);4747+}4848+4949+static inline void flush_tlb_kernel_range(unsigned long start,5050+ unsigned long end)5151+{5252+ flush_tlb_range(NULL, start, end);5353+}5454+5555+#endif /* __ASM_OPENRISC_TLBFLUSH_H */
+355
arch/openrisc/include/asm/uaccess.h
···11+/*22+ * OpenRISC Linux33+ *44+ * Linux architectural port borrowing liberally from similar works of55+ * others. All original copyrights apply as per the original source66+ * declaration.77+ *88+ * OpenRISC implementation:99+ * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>1010+ * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>1111+ * et al.1212+ *1313+ * This program is free software; you can redistribute it and/or modify1414+ * it under the terms of the GNU General Public License as published by1515+ * the Free Software Foundation; either version 2 of the License, or1616+ * (at your option) any later version.1717+ */1818+1919+#ifndef __ASM_OPENRISC_UACCESS_H2020+#define __ASM_OPENRISC_UACCESS_H2121+2222+/*2323+ * User space memory access functions2424+ */2525+#include <linux/errno.h>2626+#include <linux/thread_info.h>2727+#include <linux/prefetch.h>2828+#include <linux/string.h>2929+#include <linux/thread_info.h>3030+#include <asm/page.h>3131+3232+#define VERIFY_READ 03333+#define VERIFY_WRITE 13434+3535+/*3636+ * The fs value determines whether argument validity checking should be3737+ * performed or not. If get_fs() == USER_DS, checking is performed, with3838+ * get_fs() == KERNEL_DS, checking is bypassed.3939+ *4040+ * For historical reasons, these macros are grossly misnamed.4141+ */4242+4343+/* addr_limit is the maximum accessible address for the task. we misuse4444+ * the KERNEL_DS and USER_DS values to both assign and compare the4545+ * addr_limit values through the equally misnamed get/set_fs macros.4646+ * (see above)4747+ */4848+4949+#define KERNEL_DS (~0UL)5050+#define get_ds() (KERNEL_DS)5151+5252+#define USER_DS (TASK_SIZE)5353+#define get_fs() (current_thread_info()->addr_limit)5454+#define set_fs(x) (current_thread_info()->addr_limit = (x))5555+5656+#define segment_eq(a, b) ((a) == (b))5757+5858+/* Ensure that the range from addr to addr+size is all within the process'5959+ * address space6060+ */6161+#define __range_ok(addr, size) (size <= get_fs() && addr <= (get_fs()-size))6262+6363+/* Ensure that addr is below task's addr_limit */6464+#define __addr_ok(addr) ((unsigned long) addr < get_fs())6565+6666+#define access_ok(type, addr, size) \6767+ __range_ok((unsigned long)addr, (unsigned long)size)6868+6969+/*7070+ * The exception table consists of pairs of addresses: the first is the7171+ * address of an instruction that is allowed to fault, and the second is7272+ * the address at which the program should continue. No registers are7373+ * modified, so it is entirely up to the continuation code to figure out7474+ * what to do.7575+ *7676+ * All the routines below use bits of fixup code that are out of line7777+ * with the main instruction path. This means when everything is well,7878+ * we don't even have to jump over them. Further, they do not intrude7979+ * on our cache or tlb entries.8080+ */8181+8282+struct exception_table_entry {8383+ unsigned long insn, fixup;8484+};8585+8686+/* Returns 0 if exception not found and fixup otherwise. */8787+extern unsigned long search_exception_table(unsigned long);8888+extern void sort_exception_table(void);8989+9090+/*9191+ * These are the main single-value transfer routines. They automatically9292+ * use the right size if we just have the right pointer type.9393+ *9494+ * This gets kind of ugly. We want to return _two_ values in "get_user()"9595+ * and yet we don't want to do any pointers, because that is too much9696+ * of a performance impact. Thus we have a few rather ugly macros here,9797+ * and hide all the uglyness from the user.9898+ *9999+ * The "__xxx" versions of the user access functions are versions that100100+ * do not verify the address space, that must have been done previously101101+ * with a separate "access_ok()" call (this is used when we do multiple102102+ * accesses to the same area of user memory).103103+ *104104+ * As we use the same address space for kernel and user data on the105105+ * PowerPC, we can just do these as direct assignments. (Of course, the106106+ * exception handling means that it's no longer "just"...)107107+ */108108+#define get_user(x, ptr) \109109+ __get_user_check((x), (ptr), sizeof(*(ptr)))110110+#define put_user(x, ptr) \111111+ __put_user_check((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))112112+113113+#define __get_user(x, ptr) \114114+ __get_user_nocheck((x), (ptr), sizeof(*(ptr)))115115+#define __put_user(x, ptr) \116116+ __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))117117+118118+extern long __put_user_bad(void);119119+120120+#define __put_user_nocheck(x, ptr, size) \121121+({ \122122+ long __pu_err; \123123+ __put_user_size((x), (ptr), (size), __pu_err); \124124+ __pu_err; \125125+})126126+127127+#define __put_user_check(x, ptr, size) \128128+({ \129129+ long __pu_err = -EFAULT; \130130+ __typeof__(*(ptr)) *__pu_addr = (ptr); \131131+ if (access_ok(VERIFY_WRITE, __pu_addr, size)) \132132+ __put_user_size((x), __pu_addr, (size), __pu_err); \133133+ __pu_err; \134134+})135135+136136+#define __put_user_size(x, ptr, size, retval) \137137+do { \138138+ retval = 0; \139139+ switch (size) { \140140+ case 1: __put_user_asm(x, ptr, retval, "l.sb"); break; \141141+ case 2: __put_user_asm(x, ptr, retval, "l.sh"); break; \142142+ case 4: __put_user_asm(x, ptr, retval, "l.sw"); break; \143143+ case 8: __put_user_asm2(x, ptr, retval); break; \144144+ default: __put_user_bad(); \145145+ } \146146+} while (0)147147+148148+struct __large_struct {149149+ unsigned long buf[100];150150+};151151+#define __m(x) (*(struct __large_struct *)(x))152152+153153+/*154154+ * We don't tell gcc that we are accessing memory, but this is OK155155+ * because we do not write to any memory gcc knows about, so there156156+ * are no aliasing issues.157157+ */158158+#define __put_user_asm(x, addr, err, op) \159159+ __asm__ __volatile__( \160160+ "1: "op" 0(%2),%1\n" \161161+ "2:\n" \162162+ ".section .fixup,\"ax\"\n" \163163+ "3: l.addi %0,r0,%3\n" \164164+ " l.j 2b\n" \165165+ " l.nop\n" \166166+ ".previous\n" \167167+ ".section __ex_table,\"a\"\n" \168168+ " .align 2\n" \169169+ " .long 1b,3b\n" \170170+ ".previous" \171171+ : "=r"(err) \172172+ : "r"(x), "r"(addr), "i"(-EFAULT), "0"(err))173173+174174+#define __put_user_asm2(x, addr, err) \175175+ __asm__ __volatile__( \176176+ "1: l.sw 0(%2),%1\n" \177177+ "2: l.sw 4(%2),%H1\n" \178178+ "3:\n" \179179+ ".section .fixup,\"ax\"\n" \180180+ "4: l.addi %0,r0,%3\n" \181181+ " l.j 3b\n" \182182+ " l.nop\n" \183183+ ".previous\n" \184184+ ".section __ex_table,\"a\"\n" \185185+ " .align 2\n" \186186+ " .long 1b,4b\n" \187187+ " .long 2b,4b\n" \188188+ ".previous" \189189+ : "=r"(err) \190190+ : "r"(x), "r"(addr), "i"(-EFAULT), "0"(err))191191+192192+#define __get_user_nocheck(x, ptr, size) \193193+({ \194194+ long __gu_err, __gu_val; \195195+ __get_user_size(__gu_val, (ptr), (size), __gu_err); \196196+ (x) = (__typeof__(*(ptr)))__gu_val; \197197+ __gu_err; \198198+})199199+200200+#define __get_user_check(x, ptr, size) \201201+({ \202202+ long __gu_err = -EFAULT, __gu_val = 0; \203203+ const __typeof__(*(ptr)) * __gu_addr = (ptr); \204204+ if (access_ok(VERIFY_READ, __gu_addr, size)) \205205+ __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \206206+ (x) = (__typeof__(*(ptr)))__gu_val; \207207+ __gu_err; \208208+})209209+210210+extern long __get_user_bad(void);211211+212212+#define __get_user_size(x, ptr, size, retval) \213213+do { \214214+ retval = 0; \215215+ switch (size) { \216216+ case 1: __get_user_asm(x, ptr, retval, "l.lbz"); break; \217217+ case 2: __get_user_asm(x, ptr, retval, "l.lhz"); break; \218218+ case 4: __get_user_asm(x, ptr, retval, "l.lwz"); break; \219219+ case 8: __get_user_asm2(x, ptr, retval); \220220+ default: (x) = __get_user_bad(); \221221+ } \222222+} while (0)223223+224224+#define __get_user_asm(x, addr, err, op) \225225+ __asm__ __volatile__( \226226+ "1: "op" %1,0(%2)\n" \227227+ "2:\n" \228228+ ".section .fixup,\"ax\"\n" \229229+ "3: l.addi %0,r0,%3\n" \230230+ " l.addi %1,r0,0\n" \231231+ " l.j 2b\n" \232232+ " l.nop\n" \233233+ ".previous\n" \234234+ ".section __ex_table,\"a\"\n" \235235+ " .align 2\n" \236236+ " .long 1b,3b\n" \237237+ ".previous" \238238+ : "=r"(err), "=r"(x) \239239+ : "r"(addr), "i"(-EFAULT), "0"(err))240240+241241+#define __get_user_asm2(x, addr, err) \242242+ __asm__ __volatile__( \243243+ "1: l.lwz %1,0(%2)\n" \244244+ "2: l.lwz %H1,4(%2)\n" \245245+ "3:\n" \246246+ ".section .fixup,\"ax\"\n" \247247+ "4: l.addi %0,r0,%3\n" \248248+ " l.addi %1,r0,0\n" \249249+ " l.addi %H1,r0,0\n" \250250+ " l.j 3b\n" \251251+ " l.nop\n" \252252+ ".previous\n" \253253+ ".section __ex_table,\"a\"\n" \254254+ " .align 2\n" \255255+ " .long 1b,4b\n" \256256+ " .long 2b,4b\n" \257257+ ".previous" \258258+ : "=r"(err), "=&r"(x) \259259+ : "r"(addr), "i"(-EFAULT), "0"(err))260260+261261+/* more complex routines */262262+263263+extern unsigned long __must_check264264+__copy_tofrom_user(void *to, const void *from, unsigned long size);265265+266266+#define __copy_from_user(to, from, size) \267267+ __copy_tofrom_user(to, from, size)268268+#define __copy_to_user(to, from, size) \269269+ __copy_tofrom_user(to, from, size)270270+271271+#define __copy_to_user_inatomic __copy_to_user272272+#define __copy_from_user_inatomic __copy_from_user273273+274274+static inline unsigned long275275+copy_from_user(void *to, const void *from, unsigned long n)276276+{277277+ unsigned long over;278278+279279+ if (access_ok(VERIFY_READ, from, n))280280+ return __copy_tofrom_user(to, from, n);281281+ if ((unsigned long)from < TASK_SIZE) {282282+ over = (unsigned long)from + n - TASK_SIZE;283283+ return __copy_tofrom_user(to, from, n - over) + over;284284+ }285285+ return n;286286+}287287+288288+static inline unsigned long289289+copy_to_user(void *to, const void *from, unsigned long n)290290+{291291+ unsigned long over;292292+293293+ if (access_ok(VERIFY_WRITE, to, n))294294+ return __copy_tofrom_user(to, from, n);295295+ if ((unsigned long)to < TASK_SIZE) {296296+ over = (unsigned long)to + n - TASK_SIZE;297297+ return __copy_tofrom_user(to, from, n - over) + over;298298+ }299299+ return n;300300+}301301+302302+extern unsigned long __clear_user(void *addr, unsigned long size);303303+304304+static inline __must_check unsigned long305305+clear_user(void *addr, unsigned long size)306306+{307307+308308+ if (access_ok(VERIFY_WRITE, addr, size))309309+ return __clear_user(addr, size);310310+ if ((unsigned long)addr < TASK_SIZE) {311311+ unsigned long over = (unsigned long)addr + size - TASK_SIZE;312312+ return __clear_user(addr, size - over) + over;313313+ }314314+ return size;315315+}316316+317317+extern int __strncpy_from_user(char *dst, const char *src, long count);318318+319319+static inline long strncpy_from_user(char *dst, const char *src, long count)320320+{321321+ if (access_ok(VERIFY_READ, src, 1))322322+ return __strncpy_from_user(dst, src, count);323323+ return -EFAULT;324324+}325325+326326+/*327327+ * Return the size of a string (including the ending 0)328328+ *329329+ * Return 0 for error330330+ */331331+332332+extern int __strnlen_user(const char *str, long len, unsigned long top);333333+334334+/*335335+ * Returns the length of the string at str (including the null byte),336336+ * or 0 if we hit a page we can't access,337337+ * or something > len if we didn't find a null byte.338338+ *339339+ * The `top' parameter to __strnlen_user is to make sure that340340+ * we can never overflow from the user area into kernel space.341341+ */342342+static inline long strnlen_user(const char __user *str, long len)343343+{344344+ unsigned long top = (unsigned long)get_fs();345345+ unsigned long res = 0;346346+347347+ if (__addr_ok(str))348348+ res = __strnlen_user(str, len, top);349349+350350+ return res;351351+}352352+353353+#define strlen_user(str) strnlen_user(str, TASK_SIZE-1)354354+355355+#endif /* __ASM_OPENRISC_UACCESS_H */
+338
arch/openrisc/mm/fault.c
···11+/*22+ * OpenRISC fault.c33+ *44+ * Linux architectural port borrowing liberally from similar works of55+ * others. All original copyrights apply as per the original source66+ * declaration.77+ *88+ * Modifications for the OpenRISC architecture:99+ * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>1010+ * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>1111+ *1212+ * This program is free software; you can redistribute it and/or1313+ * modify it under the terms of the GNU General Public License1414+ * as published by the Free Software Foundation; either version1515+ * 2 of the License, or (at your option) any later version.1616+ */1717+1818+#include <linux/mm.h>1919+#include <linux/interrupt.h>2020+#include <linux/module.h>2121+#include <linux/sched.h>2222+2323+#include <asm/uaccess.h>2424+#include <asm/siginfo.h>2525+#include <asm/signal.h>2626+2727+#define NUM_TLB_ENTRIES 642828+#define TLB_OFFSET(add) (((add) >> PAGE_SHIFT) & (NUM_TLB_ENTRIES-1))2929+3030+unsigned long pte_misses; /* updated by do_page_fault() */3131+unsigned long pte_errors; /* updated by do_page_fault() */3232+3333+/* __PHX__ :: - check the vmalloc_fault in do_page_fault()3434+ * - also look into include/asm-or32/mmu_context.h3535+ */3636+volatile pgd_t *current_pgd;3737+3838+extern void die(char *, struct pt_regs *, long);3939+4040+/*4141+ * This routine handles page faults. It determines the address,4242+ * and the problem, and then passes it off to one of the appropriate4343+ * routines.4444+ *4545+ * If this routine detects a bad access, it returns 1, otherwise it4646+ * returns 0.4747+ */4848+4949+asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long address,5050+ unsigned long vector, int write_acc)5151+{5252+ struct task_struct *tsk;5353+ struct mm_struct *mm;5454+ struct vm_area_struct *vma;5555+ siginfo_t info;5656+ int fault;5757+5858+ tsk = current;5959+6060+ /*6161+ * We fault-in kernel-space virtual memory on-demand. The6262+ * 'reference' page table is init_mm.pgd.6363+ *6464+ * NOTE! We MUST NOT take any locks for this case. We may6565+ * be in an interrupt or a critical region, and should6666+ * only copy the information from the master page table,6767+ * nothing more.6868+ *6969+ * NOTE2: This is done so that, when updating the vmalloc7070+ * mappings we don't have to walk all processes pgdirs and7171+ * add the high mappings all at once. Instead we do it as they7272+ * are used. However vmalloc'ed page entries have the PAGE_GLOBAL7373+ * bit set so sometimes the TLB can use a lingering entry.7474+ *7575+ * This verifies that the fault happens in kernel space7676+ * and that the fault was not a protection error.7777+ */7878+7979+ if (address >= VMALLOC_START &&8080+ (vector != 0x300 && vector != 0x400) &&8181+ !user_mode(regs))8282+ goto vmalloc_fault;8383+8484+ /* If exceptions were enabled, we can reenable them here */8585+ if (user_mode(regs)) {8686+ /* Exception was in userspace: reenable interrupts */8787+ local_irq_enable();8888+ } else {8989+ /* If exception was in a syscall, then IRQ's may have9090+ * been enabled or disabled. If they were enabled,9191+ * reenable them.9292+ */9393+ if (regs->sr && (SPR_SR_IEE | SPR_SR_TEE))9494+ local_irq_enable();9595+ }9696+9797+ mm = tsk->mm;9898+ info.si_code = SEGV_MAPERR;9999+100100+ /*101101+ * If we're in an interrupt or have no user102102+ * context, we must not take the fault..103103+ */104104+105105+ if (in_interrupt() || !mm)106106+ goto no_context;107107+108108+ down_read(&mm->mmap_sem);109109+ vma = find_vma(mm, address);110110+111111+ if (!vma)112112+ goto bad_area;113113+114114+ if (vma->vm_start <= address)115115+ goto good_area;116116+117117+ if (!(vma->vm_flags & VM_GROWSDOWN))118118+ goto bad_area;119119+120120+ if (user_mode(regs)) {121121+ /*122122+ * accessing the stack below usp is always a bug.123123+ * we get page-aligned addresses so we can only check124124+ * if we're within a page from usp, but that might be125125+ * enough to catch brutal errors at least.126126+ */127127+ if (address + PAGE_SIZE < regs->sp)128128+ goto bad_area;129129+ }130130+ if (expand_stack(vma, address))131131+ goto bad_area;132132+133133+ /*134134+ * Ok, we have a good vm_area for this memory access, so135135+ * we can handle it..136136+ */137137+138138+good_area:139139+ info.si_code = SEGV_ACCERR;140140+141141+ /* first do some preliminary protection checks */142142+143143+ if (write_acc) {144144+ if (!(vma->vm_flags & VM_WRITE))145145+ goto bad_area;146146+ } else {147147+ /* not present */148148+ if (!(vma->vm_flags & (VM_READ | VM_EXEC)))149149+ goto bad_area;150150+ }151151+152152+ /* are we trying to execute nonexecutable area */153153+ if ((vector == 0x400) && !(vma->vm_page_prot.pgprot & _PAGE_EXEC))154154+ goto bad_area;155155+156156+ /*157157+ * If for any reason at all we couldn't handle the fault,158158+ * make sure we exit gracefully rather than endlessly redo159159+ * the fault.160160+ */161161+162162+ fault = handle_mm_fault(mm, vma, address, write_acc);163163+ if (unlikely(fault & VM_FAULT_ERROR)) {164164+ if (fault & VM_FAULT_OOM)165165+ goto out_of_memory;166166+ else if (fault & VM_FAULT_SIGBUS)167167+ goto do_sigbus;168168+ BUG();169169+ }170170+ /*RGD modeled on Cris */171171+ if (fault & VM_FAULT_MAJOR)172172+ tsk->maj_flt++;173173+ else174174+ tsk->min_flt++;175175+176176+ up_read(&mm->mmap_sem);177177+ return;178178+179179+ /*180180+ * Something tried to access memory that isn't in our memory map..181181+ * Fix it, but check if it's kernel or user first..182182+ */183183+184184+bad_area:185185+ up_read(&mm->mmap_sem);186186+187187+bad_area_nosemaphore:188188+189189+ /* User mode accesses just cause a SIGSEGV */190190+191191+ if (user_mode(regs)) {192192+ info.si_signo = SIGSEGV;193193+ info.si_errno = 0;194194+ /* info.si_code has been set above */195195+ info.si_addr = (void *)address;196196+ force_sig_info(SIGSEGV, &info, tsk);197197+ return;198198+ }199199+200200+no_context:201201+202202+ /* Are we prepared to handle this kernel fault?203203+ *204204+ * (The kernel has valid exception-points in the source205205+ * when it acesses user-memory. When it fails in one206206+ * of those points, we find it in a table and do a jump207207+ * to some fixup code that loads an appropriate error208208+ * code)209209+ */210210+211211+ {212212+ const struct exception_table_entry *entry;213213+214214+ __asm__ __volatile__("l.nop 42");215215+216216+ if ((entry = search_exception_tables(regs->pc)) != NULL) {217217+ /* Adjust the instruction pointer in the stackframe */218218+ regs->pc = entry->fixup;219219+ return;220220+ }221221+ }222222+223223+ /*224224+ * Oops. The kernel tried to access some bad page. We'll have to225225+ * terminate things with extreme prejudice.226226+ */227227+228228+ if ((unsigned long)(address) < PAGE_SIZE)229229+ printk(KERN_ALERT230230+ "Unable to handle kernel NULL pointer dereference");231231+ else232232+ printk(KERN_ALERT "Unable to handle kernel access");233233+ printk(" at virtual address 0x%08lx\n", address);234234+235235+ die("Oops", regs, write_acc);236236+237237+ do_exit(SIGKILL);238238+239239+ /*240240+ * We ran out of memory, or some other thing happened to us that made241241+ * us unable to handle the page fault gracefully.242242+ */243243+244244+out_of_memory:245245+ __asm__ __volatile__("l.nop 42");246246+ __asm__ __volatile__("l.nop 1");247247+248248+ up_read(&mm->mmap_sem);249249+ printk("VM: killing process %s\n", tsk->comm);250250+ if (user_mode(regs))251251+ do_exit(SIGKILL);252252+ goto no_context;253253+254254+do_sigbus:255255+ up_read(&mm->mmap_sem);256256+257257+ /*258258+ * Send a sigbus, regardless of whether we were in kernel259259+ * or user mode.260260+ */261261+ info.si_signo = SIGBUS;262262+ info.si_errno = 0;263263+ info.si_code = BUS_ADRERR;264264+ info.si_addr = (void *)address;265265+ force_sig_info(SIGBUS, &info, tsk);266266+267267+ /* Kernel mode? Handle exceptions or die */268268+ if (!user_mode(regs))269269+ goto no_context;270270+ return;271271+272272+vmalloc_fault:273273+ {274274+ /*275275+ * Synchronize this task's top level page-table276276+ * with the 'reference' page table.277277+ *278278+ * Use current_pgd instead of tsk->active_mm->pgd279279+ * since the latter might be unavailable if this280280+ * code is executed in a misfortunately run irq281281+ * (like inside schedule() between switch_mm and282282+ * switch_to...).283283+ */284284+285285+ int offset = pgd_index(address);286286+ pgd_t *pgd, *pgd_k;287287+ pud_t *pud, *pud_k;288288+ pmd_t *pmd, *pmd_k;289289+ pte_t *pte_k;290290+291291+/*292292+ phx_warn("do_page_fault(): vmalloc_fault will not work, "293293+ "since current_pgd assign a proper value somewhere\n"294294+ "anyhow we don't need this at the moment\n");295295+296296+ phx_mmu("vmalloc_fault");297297+*/298298+ pgd = (pgd_t *)current_pgd + offset;299299+ pgd_k = init_mm.pgd + offset;300300+301301+ /* Since we're two-level, we don't need to do both302302+ * set_pgd and set_pmd (they do the same thing). If303303+ * we go three-level at some point, do the right thing304304+ * with pgd_present and set_pgd here.305305+ *306306+ * Also, since the vmalloc area is global, we don't307307+ * need to copy individual PTE's, it is enough to308308+ * copy the pgd pointer into the pte page of the309309+ * root task. If that is there, we'll find our pte if310310+ * it exists.311311+ */312312+313313+ pud = pud_offset(pgd, address);314314+ pud_k = pud_offset(pgd_k, address);315315+ if (!pud_present(*pud_k))316316+ goto no_context;317317+318318+ pmd = pmd_offset(pud, address);319319+ pmd_k = pmd_offset(pud_k, address);320320+321321+ if (!pmd_present(*pmd_k))322322+ goto bad_area_nosemaphore;323323+324324+ set_pmd(pmd, *pmd_k);325325+326326+ /* Make sure the actual PTE exists as well to327327+ * catch kernel vmalloc-area accesses to non-mapped328328+ * addresses. If we don't do this, this will just329329+ * silently loop forever.330330+ */331331+332332+ pte_k = pte_offset_kernel(pmd_k, address);333333+ if (!pte_present(*pte_k))334334+ goto no_context;335335+336336+ return;337337+ }338338+}
+283
arch/openrisc/mm/init.c
···11+/*22+ * OpenRISC idle.c33+ *44+ * Linux architectural port borrowing liberally from similar works of55+ * others. All original copyrights apply as per the original source66+ * declaration.77+ *88+ * Modifications for the OpenRISC architecture:99+ * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>1010+ * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>1111+ *1212+ * This program is free software; you can redistribute it and/or1313+ * modify it under the terms of the GNU General Public License1414+ * as published by the Free Software Foundation; either version1515+ * 2 of the License, or (at your option) any later version.1616+ */1717+1818+#include <linux/signal.h>1919+#include <linux/sched.h>2020+#include <linux/kernel.h>2121+#include <linux/errno.h>2222+#include <linux/string.h>2323+#include <linux/types.h>2424+#include <linux/ptrace.h>2525+#include <linux/mman.h>2626+#include <linux/mm.h>2727+#include <linux/swap.h>2828+#include <linux/smp.h>2929+#include <linux/bootmem.h>3030+#include <linux/init.h>3131+#include <linux/delay.h>3232+#include <linux/blkdev.h> /* for initrd_* */3333+#include <linux/pagemap.h>3434+#include <linux/memblock.h>3535+3636+#include <asm/system.h>3737+#include <asm/segment.h>3838+#include <asm/pgalloc.h>3939+#include <asm/pgtable.h>4040+#include <asm/dma.h>4141+#include <asm/io.h>4242+#include <asm/tlb.h>4343+#include <asm/mmu_context.h>4444+#include <asm/kmap_types.h>4545+#include <asm/fixmap.h>4646+#include <asm/tlbflush.h>4747+4848+int mem_init_done;4949+5050+DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);5151+5252+static void __init zone_sizes_init(void)5353+{5454+ unsigned long zones_size[MAX_NR_ZONES];5555+5656+ /* Clear the zone sizes */5757+ memset(zones_size, 0, sizeof(zones_size));5858+5959+ /*6060+ * We use only ZONE_NORMAL6161+ */6262+ zones_size[ZONE_NORMAL] = max_low_pfn;6363+6464+ free_area_init(zones_size);6565+}6666+6767+extern const char _s_kernel_ro[], _e_kernel_ro[];6868+6969+/*7070+ * Map all physical memory into kernel's address space.7171+ *7272+ * This is explicitly coded for two-level page tables, so if you need7373+ * something else then this needs to change.7474+ */7575+static void __init map_ram(void)7676+{7777+ unsigned long v, p, e;7878+ pgprot_t prot;7979+ pgd_t *pge;8080+ pud_t *pue;8181+ pmd_t *pme;8282+ pte_t *pte;8383+ /* These mark extents of read-only kernel pages...8484+ * ...from vmlinux.lds.S8585+ */8686+ struct memblock_region *region;8787+8888+ v = PAGE_OFFSET;8989+9090+ for_each_memblock(memory, region) {9191+ p = (u32) region->base & PAGE_MASK;9292+ e = p + (u32) region->size;9393+9494+ v = (u32) __va(p);9595+ pge = pgd_offset_k(v);9696+9797+ while (p < e) {9898+ int j;9999+ pue = pud_offset(pge, v);100100+ pme = pmd_offset(pue, v);101101+102102+ if ((u32) pue != (u32) pge || (u32) pme != (u32) pge) {103103+ panic("%s: OR1K kernel hardcoded for "104104+ "two-level page tables",105105+ __func__);106106+ }107107+108108+ /* Alloc one page for holding PTE's... */109109+ pte = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE);110110+ set_pmd(pme, __pmd(_KERNPG_TABLE + __pa(pte)));111111+112112+ /* Fill the newly allocated page with PTE'S */113113+ for (j = 0; p < e && j < PTRS_PER_PGD;114114+ v += PAGE_SIZE, p += PAGE_SIZE, j++, pte++) {115115+ if (v >= (u32) _e_kernel_ro ||116116+ v < (u32) _s_kernel_ro)117117+ prot = PAGE_KERNEL;118118+ else119119+ prot = PAGE_KERNEL_RO;120120+121121+ set_pte(pte, mk_pte_phys(p, prot));122122+ }123123+124124+ pge++;125125+ }126126+127127+ printk(KERN_INFO "%s: Memory: 0x%x-0x%x\n", __func__,128128+ region->base, region->base + region->size);129129+ }130130+}131131+132132+void __init paging_init(void)133133+{134134+ extern void tlb_init(void);135135+136136+ unsigned long end;137137+ int i;138138+139139+ printk(KERN_INFO "Setting up paging and PTEs.\n");140140+141141+ /* clear out the init_mm.pgd that will contain the kernel's mappings */142142+143143+ for (i = 0; i < PTRS_PER_PGD; i++)144144+ swapper_pg_dir[i] = __pgd(0);145145+146146+ /* make sure the current pgd table points to something sane147147+ * (even if it is most probably not used until the next148148+ * switch_mm)149149+ */150150+ current_pgd = init_mm.pgd;151151+152152+ end = (unsigned long)__va(max_low_pfn * PAGE_SIZE);153153+154154+ map_ram();155155+156156+ zone_sizes_init();157157+158158+ /* self modifying code ;) */159159+ /* Since the old TLB miss handler has been running up until now,160160+ * the kernel pages are still all RW, so we can still modify the161161+ * text directly... after this change and a TLB flush, the kernel162162+ * pages will become RO.163163+ */164164+ {165165+ extern unsigned long dtlb_miss_handler;166166+ extern unsigned long itlb_miss_handler;167167+168168+ unsigned long *dtlb_vector = __va(0x900);169169+ unsigned long *itlb_vector = __va(0xa00);170170+171171+ printk(KERN_INFO "dtlb_miss_handler %p\n", &dtlb_miss_handler);172172+ *dtlb_vector = ((unsigned long)&dtlb_miss_handler -173173+ (unsigned long)dtlb_vector) >> 2;174174+175175+ printk(KERN_INFO "itlb_miss_handler %p\n", &itlb_miss_handler);176176+ *itlb_vector = ((unsigned long)&itlb_miss_handler -177177+ (unsigned long)itlb_vector) >> 2;178178+ }179179+180180+ /* Invalidate instruction caches after code modification */181181+ mtspr(SPR_ICBIR, 0x900);182182+ mtspr(SPR_ICBIR, 0xa00);183183+184184+ /* New TLB miss handlers and kernel page tables are in now place.185185+ * Make sure that page flags get updated for all pages in TLB by186186+ * flushing the TLB and forcing all TLB entries to be recreated187187+ * from their page table flags.188188+ */189189+ flush_tlb_all();190190+}191191+192192+/* References to section boundaries */193193+194194+extern char _stext, _etext, _edata, __bss_start, _end;195195+extern char __init_begin, __init_end;196196+197197+static int __init free_pages_init(void)198198+{199199+ int reservedpages, pfn;200200+201201+ /* this will put all low memory onto the freelists */202202+ totalram_pages = free_all_bootmem();203203+204204+ reservedpages = 0;205205+ for (pfn = 0; pfn < max_low_pfn; pfn++) {206206+ /*207207+ * Only count reserved RAM pages208208+ */209209+ if (PageReserved(mem_map + pfn))210210+ reservedpages++;211211+ }212212+213213+ return reservedpages;214214+}215215+216216+static void __init set_max_mapnr_init(void)217217+{218218+ max_mapnr = num_physpages = max_low_pfn;219219+}220220+221221+void __init mem_init(void)222222+{223223+ int codesize, reservedpages, datasize, initsize;224224+225225+ if (!mem_map)226226+ BUG();227227+228228+ set_max_mapnr_init();229229+230230+ high_memory = (void *)__va(max_low_pfn * PAGE_SIZE);231231+232232+ /* clear the zero-page */233233+ memset((void *)empty_zero_page, 0, PAGE_SIZE);234234+235235+ reservedpages = free_pages_init();236236+237237+ codesize = (unsigned long)&_etext - (unsigned long)&_stext;238238+ datasize = (unsigned long)&_edata - (unsigned long)&_etext;239239+ initsize = (unsigned long)&__init_end - (unsigned long)&__init_begin;240240+241241+ printk(KERN_INFO242242+ "Memory: %luk/%luk available (%dk kernel code, %dk reserved, %dk data, %dk init, %ldk highmem)\n",243243+ (unsigned long)nr_free_pages() << (PAGE_SHIFT - 10),244244+ max_mapnr << (PAGE_SHIFT - 10), codesize >> 10,245245+ reservedpages << (PAGE_SHIFT - 10), datasize >> 10,246246+ initsize >> 10, (unsigned long)(0 << (PAGE_SHIFT - 10))247247+ );248248+249249+ printk("mem_init_done ...........................................\n");250250+ mem_init_done = 1;251251+ return;252252+}253253+254254+#ifdef CONFIG_BLK_DEV_INITRD255255+void free_initrd_mem(unsigned long start, unsigned long end)256256+{257257+ printk(KERN_INFO "Freeing initrd memory: %ldk freed\n",258258+ (end - start) >> 10);259259+260260+ for (; start < end; start += PAGE_SIZE) {261261+ ClearPageReserved(virt_to_page(start));262262+ init_page_count(virt_to_page(start));263263+ free_page(start);264264+ totalram_pages++;265265+ }266266+}267267+#endif268268+269269+void free_initmem(void)270270+{271271+ unsigned long addr;272272+273273+ addr = (unsigned long)(&__init_begin);274274+ for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) {275275+ ClearPageReserved(virt_to_page(addr));276276+ init_page_count(virt_to_page(addr));277277+ free_page(addr);278278+ totalram_pages++;279279+ }280280+ printk(KERN_INFO "Freeing unused kernel memory: %luk freed\n",281281+ ((unsigned long)&__init_end -282282+ (unsigned long)&__init_begin) >> 10);283283+}
+137
arch/openrisc/mm/ioremap.c
···11+/*22+ * OpenRISC ioremap.c33+ *44+ * Linux architectural port borrowing liberally from similar works of55+ * others. All original copyrights apply as per the original source66+ * declaration.77+ *88+ * Modifications for the OpenRISC architecture:99+ * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>1010+ * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>1111+ *1212+ * This program is free software; you can redistribute it and/or1313+ * modify it under the terms of the GNU General Public License1414+ * as published by the Free Software Foundation; either version1515+ * 2 of the License, or (at your option) any later version.1616+ */1717+1818+#include <linux/vmalloc.h>1919+#include <linux/io.h>2020+#include <asm/pgalloc.h>2121+#include <asm/kmap_types.h>2222+#include <asm/fixmap.h>2323+#include <asm/bug.h>2424+#include <asm/pgtable.h>2525+#include <linux/sched.h>2626+#include <asm/tlbflush.h>2727+2828+extern int mem_init_done;2929+3030+static unsigned int fixmaps_used __initdata;3131+3232+/*3333+ * Remap an arbitrary physical address space into the kernel virtual3434+ * address space. Needed when the kernel wants to access high addresses3535+ * directly.3636+ *3737+ * NOTE! We need to allow non-page-aligned mappings too: we will obviously3838+ * have to convert them into an offset in a page-aligned mapping, but the3939+ * caller shouldn't need to know that small detail.4040+ */4141+void __iomem *__init_refok4242+__ioremap(phys_addr_t addr, unsigned long size, pgprot_t prot)4343+{4444+ phys_addr_t p;4545+ unsigned long v;4646+ unsigned long offset, last_addr;4747+ struct vm_struct *area = NULL;4848+4949+ /* Don't allow wraparound or zero size */5050+ last_addr = addr + size - 1;5151+ if (!size || last_addr < addr)5252+ return NULL;5353+5454+ /*5555+ * Mappings have to be page-aligned5656+ */5757+ offset = addr & ~PAGE_MASK;5858+ p = addr & PAGE_MASK;5959+ size = PAGE_ALIGN(last_addr + 1) - p;6060+6161+ if (likely(mem_init_done)) {6262+ area = get_vm_area(size, VM_IOREMAP);6363+ if (!area)6464+ return NULL;6565+ v = (unsigned long)area->addr;6666+ } else {6767+ if ((fixmaps_used + (size >> PAGE_SHIFT)) > FIX_N_IOREMAPS)6868+ return NULL;6969+ v = fix_to_virt(FIX_IOREMAP_BEGIN + fixmaps_used);7070+ fixmaps_used += (size >> PAGE_SHIFT);7171+ }7272+7373+ if (ioremap_page_range(v, v + size, p, prot)) {7474+ if (likely(mem_init_done))7575+ vfree(area->addr);7676+ else7777+ fixmaps_used -= (size >> PAGE_SHIFT);7878+ return NULL;7979+ }8080+8181+ return (void __iomem *)(offset + (char *)v);8282+}8383+8484+void iounmap(void *addr)8585+{8686+ /* If the page is from the fixmap pool then we just clear out8787+ * the fixmap mapping.8888+ */8989+ if (unlikely((unsigned long)addr > FIXADDR_START)) {9090+ /* This is a bit broken... we don't really know9191+ * how big the area is so it's difficult to know9292+ * how many fixed pages to invalidate...9393+ * just flush tlb and hope for the best...9494+ * consider this a FIXME9595+ *9696+ * Really we should be clearing out one or more page9797+ * table entries for these virtual addresses so that9898+ * future references cause a page fault... for now, we9999+ * rely on two things:100100+ * i) this code never gets called on known boards101101+ * ii) invalid accesses to the freed areas aren't made102102+ */103103+ flush_tlb_all();104104+ return;105105+ }106106+107107+ return vfree((void *)(PAGE_MASK & (unsigned long)addr));108108+}109109+110110+/**111111+ * OK, this one's a bit tricky... ioremap can get called before memory is112112+ * initialized (early serial console does this) and will want to alloc a page113113+ * for its mapping. No userspace pages will ever get allocated before memory114114+ * is initialized so this applies only to kernel pages. In the event that115115+ * this is called before memory is initialized we allocate the page using116116+ * the memblock infrastructure.117117+ */118118+119119+pte_t __init_refok *pte_alloc_one_kernel(struct mm_struct *mm,120120+ unsigned long address)121121+{122122+ pte_t *pte;123123+124124+ if (likely(mem_init_done)) {125125+ pte = (pte_t *) __get_free_page(GFP_KERNEL | __GFP_REPEAT);126126+ } else {127127+ pte = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE);128128+#if 0129129+ /* FIXME: use memblock... */130130+ pte = (pte_t *) __va(memblock_alloc(PAGE_SIZE, PAGE_SIZE));131131+#endif132132+ }133133+134134+ if (pte)135135+ clear_page(pte);136136+ return pte;137137+}
+193
arch/openrisc/mm/tlb.c
···11+/*22+ * OpenRISC tlb.c33+ *44+ * Linux architectural port borrowing liberally from similar works of55+ * others. All original copyrights apply as per the original source66+ * declaration.77+ *88+ * Modifications for the OpenRISC architecture:99+ * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>1010+ * Copyright (C) 2010-2011 Julius Baxter <julius.baxter@orsoc.se>1111+ * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>1212+ *1313+ * This program is free software; you can redistribute it and/or1414+ * modify it under the terms of the GNU General Public License1515+ * as published by the Free Software Foundation; either version1616+ * 2 of the License, or (at your option) any later version.1717+ */1818+1919+#include <linux/sched.h>2020+#include <linux/kernel.h>2121+#include <linux/errno.h>2222+#include <linux/string.h>2323+#include <linux/types.h>2424+#include <linux/ptrace.h>2525+#include <linux/mman.h>2626+#include <linux/mm.h>2727+#include <linux/init.h>2828+2929+#include <asm/system.h>3030+#include <asm/segment.h>3131+#include <asm/tlbflush.h>3232+#include <asm/pgtable.h>3333+#include <asm/mmu_context.h>3434+#include <asm/spr_defs.h>3535+3636+#define NO_CONTEXT -13737+3838+#define NUM_DTLB_SETS (1 << ((mfspr(SPR_IMMUCFGR) & SPR_IMMUCFGR_NTS) >> \3939+ SPR_DMMUCFGR_NTS_OFF))4040+#define NUM_ITLB_SETS (1 << ((mfspr(SPR_IMMUCFGR) & SPR_IMMUCFGR_NTS) >> \4141+ SPR_IMMUCFGR_NTS_OFF))4242+#define DTLB_OFFSET(addr) (((addr) >> PAGE_SHIFT) & (NUM_DTLB_SETS-1))4343+#define ITLB_OFFSET(addr) (((addr) >> PAGE_SHIFT) & (NUM_ITLB_SETS-1))4444+/*4545+ * Invalidate all TLB entries.4646+ *4747+ * This comes down to setting the 'valid' bit for all xTLBMR registers to 0.4848+ * Easiest way to accomplish this is to just zero out the xTLBMR register4949+ * completely.5050+ *5151+ */5252+5353+void flush_tlb_all(void)5454+{5555+ int i;5656+ unsigned long num_tlb_sets;5757+5858+ /* Determine number of sets for IMMU. */5959+ /* FIXME: Assumption is I & D nsets equal. */6060+ num_tlb_sets = NUM_ITLB_SETS;6161+6262+ for (i = 0; i < num_tlb_sets; i++) {6363+ mtspr_off(SPR_DTLBMR_BASE(0), i, 0);6464+ mtspr_off(SPR_ITLBMR_BASE(0), i, 0);6565+ }6666+}6767+6868+#define have_dtlbeir (mfspr(SPR_DMMUCFGR) & SPR_DMMUCFGR_TEIRI)6969+#define have_itlbeir (mfspr(SPR_IMMUCFGR) & SPR_IMMUCFGR_TEIRI)7070+7171+/*7272+ * Invalidate a single page. This is what the xTLBEIR register is for.7373+ *7474+ * There's no point in checking the vma for PAGE_EXEC to determine whether it's7575+ * the data or instruction TLB that should be flushed... that would take more7676+ * than the few instructions that the following compiles down to!7777+ *7878+ * The case where we don't have the xTLBEIR register really only works for7979+ * MMU's with a single way and is hard-coded that way.8080+ */8181+8282+#define flush_dtlb_page_eir(addr) mtspr(SPR_DTLBEIR, addr)8383+#define flush_dtlb_page_no_eir(addr) \8484+ mtspr_off(SPR_DTLBMR_BASE(0), DTLB_OFFSET(addr), 0);8585+8686+#define flush_itlb_page_eir(addr) mtspr(SPR_ITLBEIR, addr)8787+#define flush_itlb_page_no_eir(addr) \8888+ mtspr_off(SPR_ITLBMR_BASE(0), ITLB_OFFSET(addr), 0);8989+9090+void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)9191+{9292+ if (have_dtlbeir)9393+ flush_dtlb_page_eir(addr);9494+ else9595+ flush_dtlb_page_no_eir(addr);9696+9797+ if (have_itlbeir)9898+ flush_itlb_page_eir(addr);9999+ else100100+ flush_itlb_page_no_eir(addr);101101+}102102+103103+void flush_tlb_range(struct vm_area_struct *vma,104104+ unsigned long start, unsigned long end)105105+{106106+ int addr;107107+ bool dtlbeir;108108+ bool itlbeir;109109+110110+ dtlbeir = have_dtlbeir;111111+ itlbeir = have_itlbeir;112112+113113+ for (addr = start; addr < end; addr += PAGE_SIZE) {114114+ if (dtlbeir)115115+ flush_dtlb_page_eir(addr);116116+ else117117+ flush_dtlb_page_no_eir(addr);118118+119119+ if (itlbeir)120120+ flush_itlb_page_eir(addr);121121+ else122122+ flush_itlb_page_no_eir(addr);123123+ }124124+}125125+126126+/*127127+ * Invalidate the selected mm context only.128128+ *129129+ * FIXME: Due to some bug here, we're flushing everything for now.130130+ * This should be changed to loop over over mm and call flush_tlb_range.131131+ */132132+133133+void flush_tlb_mm(struct mm_struct *mm)134134+{135135+136136+ /* Was seeing bugs with the mm struct passed to us. Scrapped most of137137+ this function. */138138+ /* Several architctures do this */139139+ flush_tlb_all();140140+}141141+142142+/* called in schedule() just before actually doing the switch_to */143143+144144+void switch_mm(struct mm_struct *prev, struct mm_struct *next,145145+ struct task_struct *next_tsk)146146+{147147+ /* remember the pgd for the fault handlers148148+ * this is similar to the pgd register in some other CPU's.149149+ * we need our own copy of it because current and active_mm150150+ * might be invalid at points where we still need to derefer151151+ * the pgd.152152+ */153153+ current_pgd = next->pgd;154154+155155+ /* We don't have context support implemented, so flush all156156+ * entries belonging to previous map157157+ */158158+159159+ if (prev != next)160160+ flush_tlb_mm(prev);161161+162162+}163163+164164+/*165165+ * Initialize the context related info for a new mm_struct166166+ * instance.167167+ */168168+169169+int init_new_context(struct task_struct *tsk, struct mm_struct *mm)170170+{171171+ mm->context = NO_CONTEXT;172172+ return 0;173173+}174174+175175+/* called by __exit_mm to destroy the used MMU context if any before176176+ * destroying the mm itself. this is only called when the last user of the mm177177+ * drops it.178178+ */179179+180180+void destroy_context(struct mm_struct *mm)181181+{182182+ flush_tlb_mm(mm);183183+184184+}185185+186186+/* called once during VM initialization, from init.c */187187+188188+void __init tlb_init(void)189189+{190190+ /* Do nothing... */191191+ /* invalidate the entire TLB */192192+ /* flush_tlb_all(); */193193+}