blob: e4032c886c39eb5ce5d33c9678fe8d3f0c607629 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/sched.h>
2#include <linux/kernel.h>
3#include <linux/errno.h>
4#include <linux/mm.h>
Prarit Bhargava27eb0b22007-10-17 18:04:34 +02005#include <linux/nmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <linux/swap.h>
7#include <linux/smp.h>
8#include <linux/highmem.h>
9#include <linux/slab.h>
10#include <linux/pagemap.h>
11#include <linux/spinlock.h>
Jeremy Fitzhardinge052e7992006-09-25 23:32:25 -070012#include <linux/module.h>
Christoph Lameterf1d1a842007-05-12 11:15:24 -070013#include <linux/quicklist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15#include <asm/system.h>
16#include <asm/pgtable.h>
17#include <asm/pgalloc.h>
18#include <asm/fixmap.h>
19#include <asm/e820.h>
20#include <asm/tlb.h>
21#include <asm/tlbflush.h>
22
Pekka Enberg2b688df2009-03-03 12:55:04 +020023unsigned int __VMALLOC_RESERVE = 128 << 20;
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025/*
26 * Associate a virtual page frame with a given physical page frame
27 * and protection flags for that frame.
28 */
Jeremy Fitzhardinged494a962008-06-17 11:41:59 -070029void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030{
31 pgd_t *pgd;
32 pud_t *pud;
33 pmd_t *pmd;
34 pte_t *pte;
35
36 pgd = swapper_pg_dir + pgd_index(vaddr);
37 if (pgd_none(*pgd)) {
38 BUG();
39 return;
40 }
41 pud = pud_offset(pgd, vaddr);
42 if (pud_none(*pud)) {
43 BUG();
44 return;
45 }
46 pmd = pmd_offset(pud, vaddr);
47 if (pmd_none(*pmd)) {
48 BUG();
49 return;
50 }
51 pte = pte_offset_kernel(pmd, vaddr);
Jeremy Fitzhardinged494a962008-06-17 11:41:59 -070052 if (pte_val(pteval))
53 set_pte_present(&init_mm, vaddr, pte, pteval);
Jan Beulichb0bfece2006-12-07 02:14:09 +010054 else
55 pte_clear(&init_mm, vaddr, pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57 /*
58 * It's enough to flush this one mapping.
59 * (PGE mappings get flushed as well)
60 */
61 __flush_tlb_one(vaddr);
62}
63
64/*
65 * Associate a large virtual page frame with a given physical page frame
66 * and protection flags for that frame. pfn is for the base of the page,
67 * vaddr is what the page gets mapped to - both must be properly aligned.
68 * The pmd must already be instantiated. Assumes PAE mode.
69 */
70void set_pmd_pfn(unsigned long vaddr, unsigned long pfn, pgprot_t flags)
71{
72 pgd_t *pgd;
73 pud_t *pud;
74 pmd_t *pmd;
75
76 if (vaddr & (PMD_SIZE-1)) { /* vaddr is misaligned */
Christophe Lucasf90e7182005-06-25 14:59:24 -070077 printk(KERN_WARNING "set_pmd_pfn: vaddr misaligned\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 return; /* BUG(); */
79 }
80 if (pfn & (PTRS_PER_PTE-1)) { /* pfn is misaligned */
Christophe Lucasf90e7182005-06-25 14:59:24 -070081 printk(KERN_WARNING "set_pmd_pfn: pfn misaligned\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 return; /* BUG(); */
83 }
84 pgd = swapper_pg_dir + pgd_index(vaddr);
85 if (pgd_none(*pgd)) {
Christophe Lucasf90e7182005-06-25 14:59:24 -070086 printk(KERN_WARNING "set_pmd_pfn: pgd_none\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 return; /* BUG(); */
88 }
89 pud = pud_offset(pgd, vaddr);
90 pmd = pmd_offset(pud, vaddr);
91 set_pmd(pmd, pfn_pmd(pfn, flags));
92 /*
93 * It's enough to flush this one mapping.
94 * (PGE mappings get flushed as well)
95 */
96 __flush_tlb_one(vaddr);
97}
98
Jeremy Fitzhardinge052e7992006-09-25 23:32:25 -070099unsigned long __FIXADDR_TOP = 0xfffff000;
100EXPORT_SYMBOL(__FIXADDR_TOP);
Jeremy Fitzhardinge052e7992006-09-25 23:32:25 -0700101
Jeremy Fitzhardinge052e7992006-09-25 23:32:25 -0700102/**
103 * reserve_top_address - reserves a hole in the top of kernel address space
104 * @reserve - size of hole to reserve
105 *
106 * Can be used to relocate the fixmap area and poke a hole in the top
107 * of kernel address space to make room for a hypervisor.
108 */
Yinghai Lubef15682008-06-22 17:40:10 -0700109void __init reserve_top_address(unsigned long reserve)
Jeremy Fitzhardinge052e7992006-09-25 23:32:25 -0700110{
Jeremy Fitzhardinge7c7e6e02008-06-17 11:41:54 -0700111 BUG_ON(fixmaps_set > 0);
Zachary Amsden7ce0bcf2007-02-13 13:26:21 +0100112 printk(KERN_INFO "Reserving virtual address space above 0x%08x\n",
113 (int)-reserve);
Jeremy Fitzhardinge052e7992006-09-25 23:32:25 -0700114 __FIXADDR_TOP = -reserve - PAGE_SIZE;
115 __VMALLOC_RESERVE += reserve;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116}
Yinghai Lubef15682008-06-22 17:40:10 -0700117
118/*
119 * vmalloc=size forces the vmalloc area to be exactly 'size'
120 * bytes. This can be used to increase (or decrease) the
121 * vmalloc area - the default is 128m.
122 */
123static int __init parse_vmalloc(char *arg)
124{
125 if (!arg)
126 return -EINVAL;
127
Dave Younge621bd12008-08-20 16:43:03 -0700128 /* Add VMALLOC_OFFSET to the parsed value due to vm area guard hole*/
129 __VMALLOC_RESERVE = memparse(arg, &arg) + VMALLOC_OFFSET;
Yinghai Lubef15682008-06-22 17:40:10 -0700130 return 0;
131}
132early_param("vmalloc", parse_vmalloc);
133
134/*
135 * reservetop=size reserves a hole at the top of the kernel address space which
136 * a hypervisor can load into later. Needed for dynamically loaded hypervisors,
137 * so relocating the fixmap can be done before paging initialization.
138 */
139static int __init parse_reservetop(char *arg)
140{
141 unsigned long address;
142
143 if (!arg)
144 return -EINVAL;
145
146 address = memparse(arg, &arg);
147 reserve_top_address(address);
148 return 0;
149}
150early_param("reservetop", parse_reservetop);