2 * linux/arch/arm/mm/mm-armo.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>
14 #include <linux/init.h>
15 #include <linux/bootmem.h>
17 #include <asm/pgtable.h>
18 #include <asm/pgalloc.h>
20 #include <asm/arch/memory.h>
22 #include <asm/mach/map.h>
24 #define MEMC_TABLE_SIZE (256*sizeof(unsigned long))
26 kmem_cache_t *pte_cache, *pgd_cache;
30 * Allocate a page table. Note that we place the MEMC
31 * table before the page directory. This means we can
32 * easily get to both tightly-associated data structures
33 * with a single pointer.
35 static inline pgd_t *alloc_pgd_table(int priority)
37 void *pg2k = kmem_cache_alloc(pgd_cache, GFP_KERNEL);
40 pg2k += MEMC_TABLE_SIZE;
45 void free_pgd_slow(pgd_t *pgd)
47 unsigned long tbl = (unsigned long)pgd;
50 * CHECKME: are we leaking pte tables here???
53 tbl -= MEMC_TABLE_SIZE;
55 kmem_cache_free(pgd_cache, (void *)tbl);
58 pgd_t *get_pgd_slow(struct mm_struct *mm)
60 pgd_t *new_pgd, *init_pgd;
61 pmd_t *new_pmd, *init_pmd;
62 pte_t *new_pte, *init_pte;
64 new_pgd = alloc_pgd_table(GFP_KERNEL);
69 * This lock is here just to satisfy pmd_alloc and pte_lock
71 spin_lock(&mm->page_table_lock);
74 * On ARM, first page must always be allocated since it contains
75 * the machine vectors.
77 new_pmd = pmd_alloc(mm, new_pgd, 0);
81 new_pte = pte_alloc(mm, new_pmd, 0);
85 init_pgd = pgd_offset_k(0);
86 init_pmd = pmd_offset(init_pgd, 0);
87 init_pte = pte_offset(init_pmd, 0);
89 set_pte(new_pte, *init_pte);
92 * most of the page table entries are zeroed
93 * wne the table is created.
95 memcpy(new_pgd + USER_PTRS_PER_PGD, init_pgd + USER_PTRS_PER_PGD,
96 (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
98 spin_unlock(&mm->page_table_lock);
100 /* update MEMC tables */
101 cpu_memc_update_all(new_pgd);
105 spin_unlock(&mm->page_table_lock);
108 free_pgd_slow(new_pgd);
112 spin_unlock(&mm->page_table_lock);
113 free_pgd_slow(new_pgd);
121 * No special code is required here.
123 void setup_mm_for_reboot(char mode)
128 * This contains the code to setup the memory map on an ARM2/ARM250/ARM3
129 * machine. This is both processor & architecture specific, and requires
130 * some more work to get it to fit into our separate processor and
131 * architecture structure.
133 void __init memtable_init(struct meminfo *mi)
138 page_nr = max_low_pfn;
140 pte = alloc_bootmem_low_pages(PTRS_PER_PTE * sizeof(pte_t));
141 pte[0] = mk_pte_phys(PAGE_OFFSET + 491520, PAGE_READONLY);
142 pmd_populate(&init_mm, pmd_offset(swapper_pg_dir, 0), pte);
144 for (i = 1; i < PTRS_PER_PGD; i++)
145 pgd_val(swapper_pg_dir[i]) = 0;
148 void __init iotable_init(struct map_desc *io_desc)
154 * We never have holes in the memmap
156 void __init create_memmap_holes(struct meminfo *mi)
160 static void pte_cache_ctor(void *pte, kmem_cache_t *cache, unsigned long flags)
162 memzero(pte, sizeof(pte_t) * PTRS_PER_PTE);
165 static void pgd_cache_ctor(void *pte, kmem_cache_t *cache, unsigned long flags)
167 pgd_t *pgd = (pte + MEMC_TABLE_SIZE);
169 memzero(pgd, USER_PTRS_PER_PGD * sizeof(pgd_t));
172 void __init pgtable_cache_init(void)
174 pte_cache = kmem_cache_create("pte-cache",
175 sizeof(pte_t) * PTRS_PER_PTE,
176 0, 0, pte_cache_ctor, NULL);
180 pgd_cache = kmem_cache_create("pgd-cache", MEMC_TABLE_SIZE +
181 sizeof(pgd_t) * PTRS_PER_PGD,
182 0, 0, pgd_cache_ctor, NULL);