ia64/linux-2.6.18-xen.hg

view arch/arm26/mm/memc.c @ 647:a5bb490065f6

Fix the build after public header sync.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Aug 13 14:01:49 2008 +0100 (2008-08-13)
parents 831230e53067
children
line source
1 /*
2 * linux/arch/arm26/mm/memc.c
3 *
4 * Copyright (C) 1998-2000 Russell King
5 *
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.
9 *
10 * Page table sludge for older ARM processor architectures.
11 */
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 kmem_cache_t *pte_cache, *pgd_cache;
28 int page_nr;
30 /*
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.
36 */
37 static inline pgd_t *alloc_pgd_table(void)
38 {
39 void *pg2k = kmem_cache_alloc(pgd_cache, GFP_KERNEL);
41 if (pg2k)
42 pg2k += MEMC_TABLE_SIZE;
44 return (pgd_t *)pg2k;
45 }
47 /*
48 * Free a page table. this function is the counterpart to get_pgd_slow
49 * below, not alloc_pgd_table above.
50 */
51 void free_pgd_slow(pgd_t *pgd)
52 {
53 unsigned long tbl = (unsigned long)pgd;
55 tbl -= MEMC_TABLE_SIZE;
57 kmem_cache_free(pgd_cache, (void *)tbl);
58 }
60 /*
61 * Allocate a new pgd and fill it in ready for use
62 *
63 * A new tasks pgd is completely empty (all pages !present) except for:
64 *
65 * o The machine vectors at virtual address 0x0
66 * o The vmalloc region at the top of address space
67 *
68 */
69 #define FIRST_KERNEL_PGD_NR (FIRST_USER_PGD_NR + USER_PTRS_PER_PGD)
71 pgd_t *get_pgd_slow(struct mm_struct *mm)
72 {
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;
81 /*
82 * On ARM, first page must always be allocated since it contains
83 * the machine vectors.
84 */
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);
100 /*
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...
106 */
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;
120 }
122 /*
123 * No special code is required here.
124 */
125 void setup_mm_for_reboot(char mode)
126 {
127 }
129 /*
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?!)
137 */
138 void __init memtable_init(struct meminfo *mi)
139 {
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;
151 }
153 void __init iotable_init(struct map_desc *io_desc)
154 {
155 /* nothing to do */
156 }
158 /*
159 * We never have holes in the memmap
160 */
161 void __init create_memmap_holes(struct meminfo *mi)
162 {
163 }
165 static void pte_cache_ctor(void *pte, kmem_cache_t *cache, unsigned long flags)
166 {
167 memzero(pte, sizeof(pte_t) * PTRS_PER_PTE);
168 }
170 static void pgd_cache_ctor(void *pgd, kmem_cache_t *cache, unsigned long flags)
171 {
172 memzero(pgd + MEMC_TABLE_SIZE, USER_PTRS_PER_PGD * sizeof(pgd_t));
173 }
175 void __init pgtable_cache_init(void)
176 {
177 pte_cache = kmem_cache_create("pte-cache",
178 sizeof(pte_t) * PTRS_PER_PTE,
179 0, 0, pte_cache_ctor, NULL);
180 if (!pte_cache)
181 BUG();
183 pgd_cache = kmem_cache_create("pgd-cache", MEMC_TABLE_SIZE +
184 sizeof(pgd_t) * PTRS_PER_PGD,
185 0, 0, pgd_cache_ctor, NULL);
186 if (!pgd_cache)
187 BUG();
188 }