mtd: nand: omap: Fix comment in platform data using wrong Kconfig symbol
[linux/fpc-iii.git] / arch / um / kernel / mem.c
blob99aa11bf53d108d9bb5878d70e7b762b07334b1d
1 /*
2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
6 #include <linux/stddef.h>
7 #include <linux/module.h>
8 #include <linux/memblock.h>
9 #include <linux/highmem.h>
10 #include <linux/mm.h>
11 #include <linux/swap.h>
12 #include <linux/slab.h>
13 #include <asm/fixmap.h>
14 #include <asm/page.h>
15 #include <as-layout.h>
16 #include <init.h>
17 #include <kern.h>
18 #include <kern_util.h>
19 #include <mem_user.h>
20 #include <os.h>
22 /* allocated in paging_init, zeroed in mem_init, and unchanged thereafter */
23 unsigned long *empty_zero_page = NULL;
24 EXPORT_SYMBOL(empty_zero_page);
27 * Initialized during boot, and readonly for initializing page tables
28 * afterwards
30 pgd_t swapper_pg_dir[PTRS_PER_PGD];
32 /* Initialized at boot time, and readonly after that */
33 unsigned long long highmem;
34 int kmalloc_ok = 0;
36 /* Used during early boot */
37 static unsigned long brk_end;
39 void __init mem_init(void)
41 /* clear the zero-page */
42 memset(empty_zero_page, 0, PAGE_SIZE);
44 /* Map in the area just after the brk now that kmalloc is about
45 * to be turned on.
47 brk_end = (unsigned long) UML_ROUND_UP(sbrk(0));
48 map_memory(brk_end, __pa(brk_end), uml_reserved - brk_end, 1, 1, 0);
49 memblock_free(__pa(brk_end), uml_reserved - brk_end);
50 uml_reserved = brk_end;
52 /* this will put all low memory onto the freelists */
53 memblock_free_all();
54 max_low_pfn = totalram_pages();
55 max_pfn = max_low_pfn;
56 mem_init_print_info(NULL);
57 kmalloc_ok = 1;
61 * Create a page table and place a pointer to it in a middle page
62 * directory entry.
64 static void __init one_page_table_init(pmd_t *pmd)
66 if (pmd_none(*pmd)) {
67 pte_t *pte = (pte_t *) memblock_alloc_low(PAGE_SIZE,
68 PAGE_SIZE);
69 if (!pte)
70 panic("%s: Failed to allocate %lu bytes align=%lx\n",
71 __func__, PAGE_SIZE, PAGE_SIZE);
73 set_pmd(pmd, __pmd(_KERNPG_TABLE +
74 (unsigned long) __pa(pte)));
75 if (pte != pte_offset_kernel(pmd, 0))
76 BUG();
80 static void __init one_md_table_init(pud_t *pud)
82 #ifdef CONFIG_3_LEVEL_PGTABLES
83 pmd_t *pmd_table = (pmd_t *) memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);
84 if (!pmd_table)
85 panic("%s: Failed to allocate %lu bytes align=%lx\n",
86 __func__, PAGE_SIZE, PAGE_SIZE);
88 set_pud(pud, __pud(_KERNPG_TABLE + (unsigned long) __pa(pmd_table)));
89 if (pmd_table != pmd_offset(pud, 0))
90 BUG();
91 #endif
94 static void __init fixrange_init(unsigned long start, unsigned long end,
95 pgd_t *pgd_base)
97 pgd_t *pgd;
98 pud_t *pud;
99 pmd_t *pmd;
100 int i, j;
101 unsigned long vaddr;
103 vaddr = start;
104 i = pgd_index(vaddr);
105 j = pmd_index(vaddr);
106 pgd = pgd_base + i;
108 for ( ; (i < PTRS_PER_PGD) && (vaddr < end); pgd++, i++) {
109 pud = pud_offset(pgd, vaddr);
110 if (pud_none(*pud))
111 one_md_table_init(pud);
112 pmd = pmd_offset(pud, vaddr);
113 for (; (j < PTRS_PER_PMD) && (vaddr < end); pmd++, j++) {
114 one_page_table_init(pmd);
115 vaddr += PMD_SIZE;
117 j = 0;
121 static void __init fixaddr_user_init( void)
123 #ifdef CONFIG_ARCH_REUSE_HOST_VSYSCALL_AREA
124 long size = FIXADDR_USER_END - FIXADDR_USER_START;
125 pgd_t *pgd;
126 pud_t *pud;
127 pmd_t *pmd;
128 pte_t *pte;
129 phys_t p;
130 unsigned long v, vaddr = FIXADDR_USER_START;
132 if (!size)
133 return;
135 fixrange_init( FIXADDR_USER_START, FIXADDR_USER_END, swapper_pg_dir);
136 v = (unsigned long) memblock_alloc_low(size, PAGE_SIZE);
137 if (!v)
138 panic("%s: Failed to allocate %lu bytes align=%lx\n",
139 __func__, size, PAGE_SIZE);
141 memcpy((void *) v , (void *) FIXADDR_USER_START, size);
142 p = __pa(v);
143 for ( ; size > 0; size -= PAGE_SIZE, vaddr += PAGE_SIZE,
144 p += PAGE_SIZE) {
145 pgd = swapper_pg_dir + pgd_index(vaddr);
146 pud = pud_offset(pgd, vaddr);
147 pmd = pmd_offset(pud, vaddr);
148 pte = pte_offset_kernel(pmd, vaddr);
149 pte_set_val(*pte, p, PAGE_READONLY);
151 #endif
154 void __init paging_init(void)
156 unsigned long zones_size[MAX_NR_ZONES], vaddr;
157 int i;
159 empty_zero_page = (unsigned long *) memblock_alloc_low(PAGE_SIZE,
160 PAGE_SIZE);
161 if (!empty_zero_page)
162 panic("%s: Failed to allocate %lu bytes align=%lx\n",
163 __func__, PAGE_SIZE, PAGE_SIZE);
165 for (i = 0; i < ARRAY_SIZE(zones_size); i++)
166 zones_size[i] = 0;
168 zones_size[ZONE_NORMAL] = (end_iomem >> PAGE_SHIFT) -
169 (uml_physmem >> PAGE_SHIFT);
170 free_area_init(zones_size);
173 * Fixed mappings, only the page table structure has to be
174 * created - mappings will be set by set_fixmap():
176 vaddr = __fix_to_virt(__end_of_fixed_addresses - 1) & PMD_MASK;
177 fixrange_init(vaddr, FIXADDR_TOP, swapper_pg_dir);
179 fixaddr_user_init();
183 * This can't do anything because nothing in the kernel image can be freed
184 * since it's not in kernel physical memory.
187 void free_initmem(void)
191 #ifdef CONFIG_BLK_DEV_INITRD
192 void free_initrd_mem(unsigned long start, unsigned long end)
194 free_reserved_area((void *)start, (void *)end, -1, "initrd");
196 #endif
198 /* Allocate and free page tables. */
200 pgd_t *pgd_alloc(struct mm_struct *mm)
202 pgd_t *pgd = (pgd_t *)__get_free_page(GFP_KERNEL);
204 if (pgd) {
205 memset(pgd, 0, USER_PTRS_PER_PGD * sizeof(pgd_t));
206 memcpy(pgd + USER_PTRS_PER_PGD,
207 swapper_pg_dir + USER_PTRS_PER_PGD,
208 (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
210 return pgd;
213 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
215 free_page((unsigned long) pgd);
218 pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
220 pte_t *pte;
222 pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
223 return pte;
226 pgtable_t pte_alloc_one(struct mm_struct *mm)
228 struct page *pte;
230 pte = alloc_page(GFP_KERNEL|__GFP_ZERO);
231 if (!pte)
232 return NULL;
233 if (!pgtable_page_ctor(pte)) {
234 __free_page(pte);
235 return NULL;
237 return pte;
240 #ifdef CONFIG_3_LEVEL_PGTABLES
241 pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
243 pmd_t *pmd = (pmd_t *) __get_free_page(GFP_KERNEL);
245 if (pmd)
246 memset(pmd, 0, PAGE_SIZE);
248 return pmd;
250 #endif
252 void *uml_kmalloc(int size, int flags)
254 return kmalloc(size, flags);