blob: 37c7a01427d2e5b4c6f68fd9d81116c9ca71c1d2 [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) 2003 by Ralf Baechle
7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/init.h>
9#include <linux/mm.h>
Mike Rapoport57c8a662018-10-30 15:09:49 -070010#include <linux/memblock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/highmem.h>
Ralf Baechle84fd0892005-02-07 16:13:07 +000012#include <asm/fixmap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <asm/pgtable.h>
Atsushi Nemoto6a1e5522007-02-19 01:27:34 +090014#include <asm/pgalloc.h>
Daniel Silsby35476312019-07-15 17:40:00 -040015#include <asm/tlbflush.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17void pgd_init(unsigned long page)
18{
19 unsigned long *p = (unsigned long *) page;
20 int i;
21
22 for (i = 0; i < USER_PTRS_PER_PGD; i+=8) {
23 p[i + 0] = (unsigned long) invalid_pte_table;
24 p[i + 1] = (unsigned long) invalid_pte_table;
25 p[i + 2] = (unsigned long) invalid_pte_table;
26 p[i + 3] = (unsigned long) invalid_pte_table;
27 p[i + 4] = (unsigned long) invalid_pte_table;
28 p[i + 5] = (unsigned long) invalid_pte_table;
29 p[i + 6] = (unsigned long) invalid_pte_table;
30 p[i + 7] = (unsigned long) invalid_pte_table;
31 }
32}
33
Daniel Silsby35476312019-07-15 17:40:00 -040034#if defined(CONFIG_TRANSPARENT_HUGEPAGE)
35pmd_t mk_pmd(struct page *page, pgprot_t prot)
36{
37 pmd_t pmd;
38
39 pmd_val(pmd) = (page_to_pfn(page) << _PFN_SHIFT) | pgprot_val(prot);
40
41 return pmd;
42}
43
44
45void set_pmd_at(struct mm_struct *mm, unsigned long addr,
46 pmd_t *pmdp, pmd_t pmd)
47{
48 *pmdp = pmd;
49 flush_tlb_all();
50}
51#endif /* defined(CONFIG_TRANSPARENT_HUGEPAGE) */
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053void __init pagetable_init(void)
54{
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 unsigned long vaddr;
Ralf Baechlef8829ca2006-10-21 23:17:35 +010056 pgd_t *pgd_base;
57#ifdef CONFIG_HIGHMEM
58 pgd_t *pgd;
Mike Rapoport2bee1b52019-11-21 18:21:33 +020059 p4d_t *p4d;
Ralf Baechlec6e8b582005-02-10 12:19:59 +000060 pud_t *pud;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 pmd_t *pmd;
62 pte_t *pte;
63#endif
64
65 /* Initialize the entire pgd. */
66 pgd_init((unsigned long)swapper_pg_dir);
67 pgd_init((unsigned long)swapper_pg_dir
68 + sizeof(pgd_t) * USER_PTRS_PER_PGD);
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 pgd_base = swapper_pg_dir;
71
72 /*
73 * Fixed mappings:
74 */
Marcin Nowakowski71eb9892017-04-11 09:00:34 +020075 vaddr = __fix_to_virt(__end_of_fixed_addresses - 1);
76 fixrange_init(vaddr & PMD_MASK, vaddr + FIXADDR_SIZE, pgd_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Ralf Baechlef8829ca2006-10-21 23:17:35 +010078#ifdef CONFIG_HIGHMEM
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 /*
80 * Permanent kmaps:
81 */
82 vaddr = PKMAP_BASE;
Marcin Nowakowski71eb9892017-04-11 09:00:34 +020083 fixrange_init(vaddr & PMD_MASK, vaddr + PAGE_SIZE*LAST_PKMAP, pgd_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Mike Rapoport31168f02019-11-21 18:21:32 +020085 pgd = swapper_pg_dir + pgd_index(vaddr);
Mike Rapoport2bee1b52019-11-21 18:21:33 +020086 p4d = p4d_offset(pgd, vaddr);
87 pud = pud_offset(p4d, vaddr);
Ralf Baechlec6e8b582005-02-10 12:19:59 +000088 pmd = pmd_offset(pud, vaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 pte = pte_offset_kernel(pmd, vaddr);
90 pkmap_page_table = pte;
91#endif
92}