Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
| 6 | * Copyright (C) 1999, 2000 by Silicon Graphics |
| 7 | * Copyright (C) 2003 by Ralf Baechle |
| 8 | */ |
James Hogan | ccf0151 | 2015-10-16 16:33:13 +0100 | [diff] [blame] | 9 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/init.h> |
| 11 | #include <linux/mm.h> |
Ralf Baechle | f8829ca | 2006-10-21 23:17:35 +0100 | [diff] [blame] | 12 | #include <asm/fixmap.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <asm/pgtable.h> |
Atsushi Nemoto | 6a1e552 | 2007-02-19 01:27:34 +0900 | [diff] [blame] | 14 | #include <asm/pgalloc.h> |
Ralf Baechle | 970d032 | 2012-10-18 13:54:15 +0200 | [diff] [blame] | 15 | #include <asm/tlbflush.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | void pgd_init(unsigned long page) |
| 18 | { |
| 19 | unsigned long *p, *end; |
David Daney | 325f8a0 | 2009-12-04 13:52:36 -0800 | [diff] [blame] | 20 | unsigned long entry; |
| 21 | |
Alex Belits | 3377e22 | 2017-02-16 17:27:34 -0800 | [diff] [blame] | 22 | #if !defined(__PAGETABLE_PUD_FOLDED) |
| 23 | entry = (unsigned long)invalid_pud_table; |
| 24 | #elif !defined(__PAGETABLE_PMD_FOLDED) |
David Daney | 325f8a0 | 2009-12-04 13:52:36 -0800 | [diff] [blame] | 25 | entry = (unsigned long)invalid_pmd_table; |
Alex Belits | 3377e22 | 2017-02-16 17:27:34 -0800 | [diff] [blame] | 26 | #else |
| 27 | entry = (unsigned long)invalid_pte_table; |
David Daney | 325f8a0 | 2009-12-04 13:52:36 -0800 | [diff] [blame] | 28 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 30 | p = (unsigned long *) page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | end = p + PTRS_PER_PGD; |
| 32 | |
David Daney | f59a2d2 | 2012-08-16 11:15:22 -0700 | [diff] [blame] | 33 | do { |
David Daney | 325f8a0 | 2009-12-04 13:52:36 -0800 | [diff] [blame] | 34 | p[0] = entry; |
| 35 | p[1] = entry; |
| 36 | p[2] = entry; |
| 37 | p[3] = entry; |
| 38 | p[4] = entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | p += 8; |
David Daney | f59a2d2 | 2012-08-16 11:15:22 -0700 | [diff] [blame] | 40 | p[-3] = entry; |
| 41 | p[-2] = entry; |
| 42 | p[-1] = entry; |
| 43 | } while (p != end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | } |
| 45 | |
David Daney | 325f8a0 | 2009-12-04 13:52:36 -0800 | [diff] [blame] | 46 | #ifndef __PAGETABLE_PMD_FOLDED |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | void pmd_init(unsigned long addr, unsigned long pagetable) |
| 48 | { |
| 49 | unsigned long *p, *end; |
| 50 | |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 51 | p = (unsigned long *) addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | end = p + PTRS_PER_PMD; |
| 53 | |
David Daney | f59a2d2 | 2012-08-16 11:15:22 -0700 | [diff] [blame] | 54 | do { |
David Daney | 325f8a0 | 2009-12-04 13:52:36 -0800 | [diff] [blame] | 55 | p[0] = pagetable; |
| 56 | p[1] = pagetable; |
| 57 | p[2] = pagetable; |
| 58 | p[3] = pagetable; |
| 59 | p[4] = pagetable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | p += 8; |
David Daney | f59a2d2 | 2012-08-16 11:15:22 -0700 | [diff] [blame] | 61 | p[-3] = pagetable; |
| 62 | p[-2] = pagetable; |
| 63 | p[-1] = pagetable; |
| 64 | } while (p != end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | } |
James Hogan | ccf0151 | 2015-10-16 16:33:13 +0100 | [diff] [blame] | 66 | EXPORT_SYMBOL_GPL(pmd_init); |
David Daney | 325f8a0 | 2009-12-04 13:52:36 -0800 | [diff] [blame] | 67 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Alex Belits | 3377e22 | 2017-02-16 17:27:34 -0800 | [diff] [blame] | 69 | #ifndef __PAGETABLE_PUD_FOLDED |
| 70 | void pud_init(unsigned long addr, unsigned long pagetable) |
| 71 | { |
| 72 | unsigned long *p, *end; |
| 73 | |
| 74 | p = (unsigned long *)addr; |
| 75 | end = p + PTRS_PER_PUD; |
| 76 | |
| 77 | do { |
| 78 | p[0] = pagetable; |
| 79 | p[1] = pagetable; |
| 80 | p[2] = pagetable; |
| 81 | p[3] = pagetable; |
| 82 | p[4] = pagetable; |
| 83 | p += 8; |
| 84 | p[-3] = pagetable; |
| 85 | p[-2] = pagetable; |
| 86 | p[-1] = pagetable; |
| 87 | } while (p != end); |
| 88 | } |
| 89 | #endif |
| 90 | |
Ralf Baechle | 970d032 | 2012-10-18 13:54:15 +0200 | [diff] [blame] | 91 | pmd_t mk_pmd(struct page *page, pgprot_t prot) |
| 92 | { |
| 93 | pmd_t pmd; |
| 94 | |
| 95 | pmd_val(pmd) = (page_to_pfn(page) << _PFN_SHIFT) | pgprot_val(prot); |
| 96 | |
| 97 | return pmd; |
| 98 | } |
| 99 | |
| 100 | void set_pmd_at(struct mm_struct *mm, unsigned long addr, |
| 101 | pmd_t *pmdp, pmd_t pmd) |
| 102 | { |
| 103 | *pmdp = pmd; |
| 104 | flush_tlb_all(); |
| 105 | } |
| 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | void __init pagetable_init(void) |
| 108 | { |
Ralf Baechle | f8829ca | 2006-10-21 23:17:35 +0100 | [diff] [blame] | 109 | unsigned long vaddr; |
| 110 | pgd_t *pgd_base; |
| 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | /* Initialize the entire pgd. */ |
| 113 | pgd_init((unsigned long)swapper_pg_dir); |
Alex Belits | 3377e22 | 2017-02-16 17:27:34 -0800 | [diff] [blame] | 114 | #ifndef __PAGETABLE_PUD_FOLDED |
| 115 | pud_init((unsigned long)invalid_pud_table, (unsigned long)invalid_pmd_table); |
| 116 | #endif |
David Daney | 325f8a0 | 2009-12-04 13:52:36 -0800 | [diff] [blame] | 117 | #ifndef __PAGETABLE_PMD_FOLDED |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | pmd_init((unsigned long)invalid_pmd_table, (unsigned long)invalid_pte_table); |
David Daney | 325f8a0 | 2009-12-04 13:52:36 -0800 | [diff] [blame] | 119 | #endif |
Ralf Baechle | f8829ca | 2006-10-21 23:17:35 +0100 | [diff] [blame] | 120 | pgd_base = swapper_pg_dir; |
| 121 | /* |
| 122 | * Fixed mappings: |
| 123 | */ |
| 124 | vaddr = __fix_to_virt(__end_of_fixed_addresses - 1) & PMD_MASK; |
Kevin Cernekee | 464fd83 | 2011-01-05 23:31:30 -0800 | [diff] [blame] | 125 | fixrange_init(vaddr, vaddr + FIXADDR_SIZE, pgd_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | } |