use SLAB_PANIC flag cleanup
[linux-2.6/mini2440.git] / arch / arm26 / mm / memc.c
blob42505541a9b17836f8c30fbad66a19026b072a52
1 /*
2 * linux/arch/arm26/mm/memc.c
4 * Copyright (C) 1998-2000 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Page table sludge for older ARM processor architectures.
12 #include <linux/sched.h>
13 #include <linux/mm.h>
14 #include <linux/init.h>
15 #include <linux/bootmem.h>
17 #include <asm/pgtable.h>
18 #include <asm/pgalloc.h>
19 #include <asm/page.h>
20 #include <asm/memory.h>
21 #include <asm/hardware.h>
23 #include <asm/map.h>
25 #define MEMC_TABLE_SIZE (256*sizeof(unsigned long))
27 struct kmem_cache *pte_cache, *pgd_cache;
28 int page_nr;
31 * Allocate space for a page table and a MEMC table.
32 * Note that we place the MEMC
33 * table before the page directory. This means we can
34 * easily get to both tightly-associated data structures
35 * with a single pointer.
37 static inline pgd_t *alloc_pgd_table(void)
39 void *pg2k = kmem_cache_alloc(pgd_cache, GFP_KERNEL);
41 if (pg2k)
42 pg2k += MEMC_TABLE_SIZE;
44 return (pgd_t *)pg2k;
48 * Free a page table. this function is the counterpart to get_pgd_slow
49 * below, not alloc_pgd_table above.
51 void free_pgd_slow(pgd_t *pgd)
53 unsigned long tbl = (unsigned long)pgd;
55 tbl -= MEMC_TABLE_SIZE;
57 kmem_cache_free(pgd_cache, (void *)tbl);
61 * Allocate a new pgd and fill it in ready for use
63 * A new tasks pgd is completely empty (all pages !present) except for:
65 * o The machine vectors at virtual address 0x0
66 * o The vmalloc region at the top of address space
69 #define FIRST_KERNEL_PGD_NR (FIRST_USER_PGD_NR + USER_PTRS_PER_PGD)
71 pgd_t *get_pgd_slow(struct mm_struct *mm)
73 pgd_t *new_pgd, *init_pgd;
74 pmd_t *new_pmd, *init_pmd;
75 pte_t *new_pte, *init_pte;
77 new_pgd = alloc_pgd_table();
78 if (!new_pgd)
79 goto no_pgd;
82 * On ARM, first page must always be allocated since it contains
83 * the machine vectors.
85 new_pmd = pmd_alloc(mm, new_pgd, 0);
86 if (!new_pmd)
87 goto no_pmd;
89 new_pte = pte_alloc_map(mm, new_pmd, 0);
90 if (!new_pte)
91 goto no_pte;
93 init_pgd = pgd_offset(&init_mm, 0);
94 init_pmd = pmd_offset(init_pgd, 0);
95 init_pte = pte_offset(init_pmd, 0);
97 set_pte(new_pte, *init_pte);
98 pte_unmap(new_pte);
101 * the page table entries are zeroed
102 * when the table is created. (see the cache_ctor functions below)
103 * Now we need to plonk the kernel (vmalloc) area at the end of
104 * the address space. We copy this from the init thread, just like
105 * the init_pte we copied above...
107 memcpy(new_pgd + FIRST_KERNEL_PGD_NR, init_pgd + FIRST_KERNEL_PGD_NR,
108 (PTRS_PER_PGD - FIRST_KERNEL_PGD_NR) * sizeof(pgd_t));
110 /* update MEMC tables */
111 cpu_memc_update_all(new_pgd);
112 return new_pgd;
114 no_pte:
115 pmd_free(new_pmd);
116 no_pmd:
117 free_pgd_slow(new_pgd);
118 no_pgd:
119 return NULL;
123 * No special code is required here.
125 void setup_mm_for_reboot(char mode)
130 * This contains the code to setup the memory map on an ARM2/ARM250/ARM3
131 * o swapper_pg_dir = 0x0207d000
132 * o kernel proper starts at 0x0208000
133 * o create (allocate) a pte to contain the machine vectors
134 * o populate the pte (points to 0x02078000) (FIXME - is it zeroed?)
135 * o populate the init tasks page directory (pgd) with the new pte
136 * o zero the rest of the init tasks pgdir (FIXME - what about vmalloc?!)
138 void __init memtable_init(struct meminfo *mi)
140 pte_t *pte;
141 int i;
143 page_nr = max_low_pfn;
145 pte = alloc_bootmem_low_pages(PTRS_PER_PTE * sizeof(pte_t));
146 pte[0] = mk_pte_phys(PAGE_OFFSET + SCREEN_SIZE, PAGE_READONLY);
147 pmd_populate(&init_mm, pmd_offset(swapper_pg_dir, 0), pte);
149 for (i = 1; i < PTRS_PER_PGD; i++)
150 pgd_val(swapper_pg_dir[i]) = 0;
153 void __init iotable_init(struct map_desc *io_desc)
155 /* nothing to do */
159 * We never have holes in the memmap
161 void __init create_memmap_holes(struct meminfo *mi)
165 static void pte_cache_ctor(void *pte, struct kmem_cache *cache, unsigned long flags)
167 memzero(pte, sizeof(pte_t) * PTRS_PER_PTE);
170 static void pgd_cache_ctor(void *pgd, struct kmem_cache *cache, unsigned long flags)
172 memzero(pgd + MEMC_TABLE_SIZE, USER_PTRS_PER_PGD * sizeof(pgd_t));
175 void __init pgtable_cache_init(void)
177 pte_cache = kmem_cache_create("pte-cache",
178 sizeof(pte_t) * PTRS_PER_PTE,
179 0, SLAB_PANIC, pte_cache_ctor, NULL);
181 pgd_cache = kmem_cache_create("pgd-cache", MEMC_TABLE_SIZE +
182 sizeof(pgd_t) * PTRS_PER_PGD,
183 0, SLAB_PANIC, pgd_cache_ctor, NULL);