[ARM] Merge most of the PXA work for initial merge
[linux-2.6] / arch / x86 / mm / pgtable_32.c
1 #include <linux/sched.h>
2 #include <linux/kernel.h>
3 #include <linux/errno.h>
4 #include <linux/mm.h>
5 #include <linux/nmi.h>
6 #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>
12 #include <linux/module.h>
13 #include <linux/quicklist.h>
14
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
23 void show_mem(void)
24 {
25         int total = 0, reserved = 0;
26         int shared = 0, cached = 0;
27         int highmem = 0;
28         struct page *page;
29         pg_data_t *pgdat;
30         unsigned long i;
31         unsigned long flags;
32
33         printk(KERN_INFO "Mem-info:\n");
34         show_free_areas();
35         for_each_online_pgdat(pgdat) {
36                 pgdat_resize_lock(pgdat, &flags);
37                 for (i = 0; i < pgdat->node_spanned_pages; ++i) {
38                         if (unlikely(i % MAX_ORDER_NR_PAGES == 0))
39                                 touch_nmi_watchdog();
40                         page = pgdat_page_nr(pgdat, i);
41                         total++;
42                         if (PageHighMem(page))
43                                 highmem++;
44                         if (PageReserved(page))
45                                 reserved++;
46                         else if (PageSwapCache(page))
47                                 cached++;
48                         else if (page_count(page))
49                                 shared += page_count(page) - 1;
50                 }
51                 pgdat_resize_unlock(pgdat, &flags);
52         }
53         printk(KERN_INFO "%d pages of RAM\n", total);
54         printk(KERN_INFO "%d pages of HIGHMEM\n", highmem);
55         printk(KERN_INFO "%d reserved pages\n", reserved);
56         printk(KERN_INFO "%d pages shared\n", shared);
57         printk(KERN_INFO "%d pages swap cached\n", cached);
58
59         printk(KERN_INFO "%lu pages dirty\n", global_page_state(NR_FILE_DIRTY));
60         printk(KERN_INFO "%lu pages writeback\n",
61                                         global_page_state(NR_WRITEBACK));
62         printk(KERN_INFO "%lu pages mapped\n", global_page_state(NR_FILE_MAPPED));
63         printk(KERN_INFO "%lu pages slab\n",
64                 global_page_state(NR_SLAB_RECLAIMABLE) +
65                 global_page_state(NR_SLAB_UNRECLAIMABLE));
66         printk(KERN_INFO "%lu pages pagetables\n",
67                                         global_page_state(NR_PAGETABLE));
68 }
69
70 /*
71  * Associate a virtual page frame with a given physical page frame 
72  * and protection flags for that frame.
73  */ 
74 static void set_pte_pfn(unsigned long vaddr, unsigned long pfn, pgprot_t flags)
75 {
76         pgd_t *pgd;
77         pud_t *pud;
78         pmd_t *pmd;
79         pte_t *pte;
80
81         pgd = swapper_pg_dir + pgd_index(vaddr);
82         if (pgd_none(*pgd)) {
83                 BUG();
84                 return;
85         }
86         pud = pud_offset(pgd, vaddr);
87         if (pud_none(*pud)) {
88                 BUG();
89                 return;
90         }
91         pmd = pmd_offset(pud, vaddr);
92         if (pmd_none(*pmd)) {
93                 BUG();
94                 return;
95         }
96         pte = pte_offset_kernel(pmd, vaddr);
97         if (pgprot_val(flags))
98                 set_pte_present(&init_mm, vaddr, pte, pfn_pte(pfn, flags));
99         else
100                 pte_clear(&init_mm, vaddr, pte);
101
102         /*
103          * It's enough to flush this one mapping.
104          * (PGE mappings get flushed as well)
105          */
106         __flush_tlb_one(vaddr);
107 }
108
109 /*
110  * Associate a large virtual page frame with a given physical page frame 
111  * and protection flags for that frame. pfn is for the base of the page,
112  * vaddr is what the page gets mapped to - both must be properly aligned. 
113  * The pmd must already be instantiated. Assumes PAE mode.
114  */ 
115 void set_pmd_pfn(unsigned long vaddr, unsigned long pfn, pgprot_t flags)
116 {
117         pgd_t *pgd;
118         pud_t *pud;
119         pmd_t *pmd;
120
121         if (vaddr & (PMD_SIZE-1)) {             /* vaddr is misaligned */
122                 printk(KERN_WARNING "set_pmd_pfn: vaddr misaligned\n");
123                 return; /* BUG(); */
124         }
125         if (pfn & (PTRS_PER_PTE-1)) {           /* pfn is misaligned */
126                 printk(KERN_WARNING "set_pmd_pfn: pfn misaligned\n");
127                 return; /* BUG(); */
128         }
129         pgd = swapper_pg_dir + pgd_index(vaddr);
130         if (pgd_none(*pgd)) {
131                 printk(KERN_WARNING "set_pmd_pfn: pgd_none\n");
132                 return; /* BUG(); */
133         }
134         pud = pud_offset(pgd, vaddr);
135         pmd = pmd_offset(pud, vaddr);
136         set_pmd(pmd, pfn_pmd(pfn, flags));
137         /*
138          * It's enough to flush this one mapping.
139          * (PGE mappings get flushed as well)
140          */
141         __flush_tlb_one(vaddr);
142 }
143
144 static int fixmaps;
145 unsigned long __FIXADDR_TOP = 0xfffff000;
146 EXPORT_SYMBOL(__FIXADDR_TOP);
147
148 void __set_fixmap (enum fixed_addresses idx, unsigned long phys, pgprot_t flags)
149 {
150         unsigned long address = __fix_to_virt(idx);
151
152         if (idx >= __end_of_fixed_addresses) {
153                 BUG();
154                 return;
155         }
156         set_pte_pfn(address, phys >> PAGE_SHIFT, flags);
157         fixmaps++;
158 }
159
160 /**
161  * reserve_top_address - reserves a hole in the top of kernel address space
162  * @reserve - size of hole to reserve
163  *
164  * Can be used to relocate the fixmap area and poke a hole in the top
165  * of kernel address space to make room for a hypervisor.
166  */
167 void reserve_top_address(unsigned long reserve)
168 {
169         BUG_ON(fixmaps > 0);
170         printk(KERN_INFO "Reserving virtual address space above 0x%08x\n",
171                (int)-reserve);
172         __FIXADDR_TOP = -reserve - PAGE_SIZE;
173         __VMALLOC_RESERVE += reserve;
174 }