xref: /openbmc/linux/arch/x86/mm/pgtable_32.c (revision 4b4193256c8d3bc3a5397b5cd9494c2ad386317d)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2ad757b6aSThomas Gleixner #include <linux/sched.h>
3ad757b6aSThomas Gleixner #include <linux/kernel.h>
4ad757b6aSThomas Gleixner #include <linux/errno.h>
5ad757b6aSThomas Gleixner #include <linux/mm.h>
627eb0b28SPrarit Bhargava #include <linux/nmi.h>
7ad757b6aSThomas Gleixner #include <linux/swap.h>
8ad757b6aSThomas Gleixner #include <linux/smp.h>
9ad757b6aSThomas Gleixner #include <linux/highmem.h>
10ad757b6aSThomas Gleixner #include <linux/pagemap.h>
11ad757b6aSThomas Gleixner #include <linux/spinlock.h>
12ad757b6aSThomas Gleixner 
1392a0f81dSThomas Gleixner #include <asm/cpu_entry_area.h>
14ad757b6aSThomas Gleixner #include <asm/fixmap.h>
1566441bd3SIngo Molnar #include <asm/e820/api.h>
16ad757b6aSThomas Gleixner #include <asm/tlb.h>
17ad757b6aSThomas Gleixner #include <asm/tlbflush.h>
1856f0e74cSIngo Molnar #include <asm/io.h>
19186525bdSIngo Molnar #include <linux/vmalloc.h>
20ad757b6aSThomas Gleixner 
212b688dfdSPekka Enberg unsigned int __VMALLOC_RESERVE = 128 << 20;
222b688dfdSPekka Enberg 
23ad757b6aSThomas Gleixner /*
24ad757b6aSThomas Gleixner  * Associate a virtual page frame with a given physical page frame
25ad757b6aSThomas Gleixner  * and protection flags for that frame.
26ad757b6aSThomas Gleixner  */
set_pte_vaddr(unsigned long vaddr,pte_t pteval)27d494a961SJeremy Fitzhardinge void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
28ad757b6aSThomas Gleixner {
29ad757b6aSThomas Gleixner 	pgd_t *pgd;
30e0c4f675SKirill A. Shutemov 	p4d_t *p4d;
31ad757b6aSThomas Gleixner 	pud_t *pud;
32ad757b6aSThomas Gleixner 	pmd_t *pmd;
33ad757b6aSThomas Gleixner 	pte_t *pte;
34ad757b6aSThomas Gleixner 
35ad757b6aSThomas Gleixner 	pgd = swapper_pg_dir + pgd_index(vaddr);
36ad757b6aSThomas Gleixner 	if (pgd_none(*pgd)) {
37ad757b6aSThomas Gleixner 		BUG();
38ad757b6aSThomas Gleixner 		return;
39ad757b6aSThomas Gleixner 	}
40e0c4f675SKirill A. Shutemov 	p4d = p4d_offset(pgd, vaddr);
41e0c4f675SKirill A. Shutemov 	if (p4d_none(*p4d)) {
42e0c4f675SKirill A. Shutemov 		BUG();
43e0c4f675SKirill A. Shutemov 		return;
44e0c4f675SKirill A. Shutemov 	}
45e0c4f675SKirill A. Shutemov 	pud = pud_offset(p4d, vaddr);
46ad757b6aSThomas Gleixner 	if (pud_none(*pud)) {
47ad757b6aSThomas Gleixner 		BUG();
48ad757b6aSThomas Gleixner 		return;
49ad757b6aSThomas Gleixner 	}
50ad757b6aSThomas Gleixner 	pmd = pmd_offset(pud, vaddr);
51ad757b6aSThomas Gleixner 	if (pmd_none(*pmd)) {
52ad757b6aSThomas Gleixner 		BUG();
53ad757b6aSThomas Gleixner 		return;
54ad757b6aSThomas Gleixner 	}
55ad757b6aSThomas Gleixner 	pte = pte_offset_kernel(pmd, vaddr);
56dcb32d99SDave Hansen 	if (!pte_none(pteval))
57b40c7579SJeremy Fitzhardinge 		set_pte_at(&init_mm, vaddr, pte, pteval);
58ad757b6aSThomas Gleixner 	else
59ad757b6aSThomas Gleixner 		pte_clear(&init_mm, vaddr, pte);
60ad757b6aSThomas Gleixner 
61ad757b6aSThomas Gleixner 	/*
62ad757b6aSThomas Gleixner 	 * It's enough to flush this one mapping.
63ad757b6aSThomas Gleixner 	 * (PGE mappings get flushed as well)
64ad757b6aSThomas Gleixner 	 */
65*58430c5dSThomas Gleixner 	flush_tlb_one_kernel(vaddr);
66ad757b6aSThomas Gleixner }
67ad757b6aSThomas Gleixner 
68ad757b6aSThomas Gleixner unsigned long __FIXADDR_TOP = 0xfffff000;
69ad757b6aSThomas Gleixner EXPORT_SYMBOL(__FIXADDR_TOP);
70ad757b6aSThomas Gleixner 
71bef1568dSYinghai Lu /*
72bef1568dSYinghai Lu  * vmalloc=size forces the vmalloc area to be exactly 'size'
73bef1568dSYinghai Lu  * bytes. This can be used to increase (or decrease) the
74bef1568dSYinghai Lu  * vmalloc area - the default is 128m.
75bef1568dSYinghai Lu  */
parse_vmalloc(char * arg)76bef1568dSYinghai Lu static int __init parse_vmalloc(char *arg)
77bef1568dSYinghai Lu {
78bef1568dSYinghai Lu 	if (!arg)
79bef1568dSYinghai Lu 		return -EINVAL;
80bef1568dSYinghai Lu 
81e621bd18SDave Young 	/* Add VMALLOC_OFFSET to the parsed value due to vm area guard hole*/
82e621bd18SDave Young 	__VMALLOC_RESERVE = memparse(arg, &arg) + VMALLOC_OFFSET;
83bef1568dSYinghai Lu 	return 0;
84bef1568dSYinghai Lu }
85bef1568dSYinghai Lu early_param("vmalloc", parse_vmalloc);
86bef1568dSYinghai Lu 
87bef1568dSYinghai Lu /*
88bef1568dSYinghai Lu  * reservetop=size reserves a hole at the top of the kernel address space which
89bef1568dSYinghai Lu  * a hypervisor can load into later.  Needed for dynamically loaded hypervisors,
90bef1568dSYinghai Lu  * so relocating the fixmap can be done before paging initialization.
91bef1568dSYinghai Lu  */
parse_reservetop(char * arg)92bef1568dSYinghai Lu static int __init parse_reservetop(char *arg)
93bef1568dSYinghai Lu {
94bef1568dSYinghai Lu 	unsigned long address;
95bef1568dSYinghai Lu 
96bef1568dSYinghai Lu 	if (!arg)
97bef1568dSYinghai Lu 		return -EINVAL;
98bef1568dSYinghai Lu 
99bef1568dSYinghai Lu 	address = memparse(arg, &arg);
100bef1568dSYinghai Lu 	reserve_top_address(address);
1015b7c73e0SMark Salter 	early_ioremap_init();
102bef1568dSYinghai Lu 	return 0;
103bef1568dSYinghai Lu }
104bef1568dSYinghai Lu early_param("reservetop", parse_reservetop);
105