blob: ee331bbd8f8aa13c263b8aa31c6bfdbab75e1101 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 */
9#include <linux/init.h>
10#include <linux/mm.h>
Ralf Baechlef8829ca2006-10-21 23:17:35 +010011#include <asm/fixmap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <asm/pgtable.h>
Atsushi Nemoto6a1e5522007-02-19 01:27:34 +090013#include <asm/pgalloc.h>
Ralf Baechle970d0322012-10-18 13:54:15 +020014#include <asm/tlbflush.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16void pgd_init(unsigned long page)
17{
18 unsigned long *p, *end;
David Daney325f8a02009-12-04 13:52:36 -080019 unsigned long entry;
20
21#ifdef __PAGETABLE_PMD_FOLDED
22 entry = (unsigned long)invalid_pte_table;
23#else
24 entry = (unsigned long)invalid_pmd_table;
25#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27 p = (unsigned long *) page;
28 end = p + PTRS_PER_PGD;
29
David Daneyf59a2d22012-08-16 11:15:22 -070030 do {
David Daney325f8a02009-12-04 13:52:36 -080031 p[0] = entry;
32 p[1] = entry;
33 p[2] = entry;
34 p[3] = entry;
35 p[4] = entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 p += 8;
David Daneyf59a2d22012-08-16 11:15:22 -070037 p[-3] = entry;
38 p[-2] = entry;
39 p[-1] = entry;
40 } while (p != end);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041}
42
David Daney325f8a02009-12-04 13:52:36 -080043#ifndef __PAGETABLE_PMD_FOLDED
Linus Torvalds1da177e2005-04-16 15:20:36 -070044void pmd_init(unsigned long addr, unsigned long pagetable)
45{
46 unsigned long *p, *end;
47
48 p = (unsigned long *) addr;
49 end = p + PTRS_PER_PMD;
50
David Daneyf59a2d22012-08-16 11:15:22 -070051 do {
David Daney325f8a02009-12-04 13:52:36 -080052 p[0] = pagetable;
53 p[1] = pagetable;
54 p[2] = pagetable;
55 p[3] = pagetable;
56 p[4] = pagetable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 p += 8;
David Daneyf59a2d22012-08-16 11:15:22 -070058 p[-3] = pagetable;
59 p[-2] = pagetable;
60 p[-1] = pagetable;
61 } while (p != end);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062}
David Daney325f8a02009-12-04 13:52:36 -080063#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Ralf Baechle970d0322012-10-18 13:54:15 +020065#ifdef CONFIG_TRANSPARENT_HUGEPAGE
66
67void pmdp_splitting_flush(struct vm_area_struct *vma,
68 unsigned long address,
69 pmd_t *pmdp)
70{
71 if (!pmd_trans_splitting(*pmdp)) {
72 pmd_t pmd = pmd_mksplitting(*pmdp);
73 set_pmd_at(vma->vm_mm, address, pmdp, pmd);
74 }
75}
76
77#endif
78
79pmd_t mk_pmd(struct page *page, pgprot_t prot)
80{
81 pmd_t pmd;
82
83 pmd_val(pmd) = (page_to_pfn(page) << _PFN_SHIFT) | pgprot_val(prot);
84
85 return pmd;
86}
87
88void set_pmd_at(struct mm_struct *mm, unsigned long addr,
89 pmd_t *pmdp, pmd_t pmd)
90{
91 *pmdp = pmd;
92 flush_tlb_all();
93}
94
Linus Torvalds1da177e2005-04-16 15:20:36 -070095void __init pagetable_init(void)
96{
Ralf Baechlef8829ca2006-10-21 23:17:35 +010097 unsigned long vaddr;
98 pgd_t *pgd_base;
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 /* Initialize the entire pgd. */
101 pgd_init((unsigned long)swapper_pg_dir);
David Daney325f8a02009-12-04 13:52:36 -0800102#ifndef __PAGETABLE_PMD_FOLDED
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 pmd_init((unsigned long)invalid_pmd_table, (unsigned long)invalid_pte_table);
David Daney325f8a02009-12-04 13:52:36 -0800104#endif
Ralf Baechlef8829ca2006-10-21 23:17:35 +0100105 pgd_base = swapper_pg_dir;
106 /*
107 * Fixed mappings:
108 */
109 vaddr = __fix_to_virt(__end_of_fixed_addresses - 1) & PMD_MASK;
Kevin Cernekee464fd832011-01-05 23:31:30 -0800110 fixrange_init(vaddr, vaddr + FIXADDR_SIZE, pgd_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111}