2 * linux/arch/m68k/motorola.c
4 * Routines specific to the Motorola MMU, originally from:
5 * linux/arch/m68k/init.c
6 * which are Copyright (C) 1995 Hamish Macdonald
8 * Moved 8/20/1999 Sam Creasey
11 #include <linux/config.h>
12 #include <linux/module.h>
13 #include <linux/signal.h>
14 #include <linux/sched.h>
16 #include <linux/swap.h>
17 #include <linux/kernel.h>
18 #include <linux/string.h>
19 #include <linux/types.h>
20 #include <linux/init.h>
21 #include <linux/bootmem.h>
23 #include <asm/setup.h>
24 #include <asm/uaccess.h>
26 #include <asm/pgalloc.h>
27 #include <asm/system.h>
28 #include <asm/machdep.h>
32 #include <asm/atari_stram.h>
39 * Bits to add to page descriptors for "normal" caching mode.
40 * For 68020/030 this is 0.
41 * For 68040, this is _PAGE_CACHE040 (cachable, copyback)
43 unsigned long mm_cachebits;
44 EXPORT_SYMBOL(mm_cachebits);
47 static pte_t * __init kernel_page_table(void)
51 ptablep = (pte_t *)alloc_bootmem_low_pages(PAGE_SIZE);
54 __flush_page_to_ram(ptablep);
55 flush_tlb_kernel_page(ptablep);
56 nocache_page(ptablep);
61 static pmd_t *last_pgtable __initdata = NULL;
62 pmd_t *zero_pgtable __initdata = NULL;
64 static pmd_t * __init kernel_ptr_table(void)
67 unsigned long pmd, last;
70 /* Find the last ptr table that was used in head.S and
71 * reuse the remaining space in that page for further
74 last = (unsigned long)kernel_pg_dir;
75 for (i = 0; i < PTRS_PER_PGD; i++) {
76 if (!pgd_present(kernel_pg_dir[i]))
78 pmd = __pgd_page(kernel_pg_dir[i]);
83 last_pgtable = (pmd_t *)last;
85 printk("kernel_ptr_init: %p\n", last_pgtable);
89 last_pgtable += PTRS_PER_PMD;
90 if (((unsigned long)last_pgtable & ~PAGE_MASK) == 0) {
91 last_pgtable = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
93 clear_page(last_pgtable);
94 __flush_page_to_ram(last_pgtable);
95 flush_tlb_kernel_page(last_pgtable);
96 nocache_page(last_pgtable);
102 static unsigned long __init
103 map_chunk (unsigned long addr, long size)
105 #define PTRTREESIZE (256*1024)
106 #define ROOTTREESIZE (32*1024*1024)
107 static unsigned long virtaddr = PAGE_OFFSET;
108 unsigned long physaddr;
113 physaddr = (addr | m68k_supervisor_cachemode |
114 _PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_DIRTY);
115 if (CPU_IS_040_OR_060)
116 physaddr |= _PAGE_GLOBAL040;
120 if (!(virtaddr & (PTRTREESIZE-1)))
121 printk ("\npa=%#lx va=%#lx ", physaddr & PAGE_MASK,
124 pgd_dir = pgd_offset_k(virtaddr);
125 if (virtaddr && CPU_IS_020_OR_030) {
126 if (!(virtaddr & (ROOTTREESIZE-1)) &&
127 size >= ROOTTREESIZE) {
129 printk ("[very early term]");
131 pgd_val(*pgd_dir) = physaddr;
132 size -= ROOTTREESIZE;
133 virtaddr += ROOTTREESIZE;
134 physaddr += ROOTTREESIZE;
138 if (!pgd_present(*pgd_dir)) {
139 pmd_dir = kernel_ptr_table();
141 printk ("[new pointer %p]", pmd_dir);
143 pgd_set(pgd_dir, pmd_dir);
145 pmd_dir = pmd_offset(pgd_dir, virtaddr);
147 if (CPU_IS_020_OR_030) {
150 printk ("[early term]");
152 pmd_dir->pmd[(virtaddr/PTRTREESIZE) & 15] = physaddr;
153 physaddr += PTRTREESIZE;
157 printk ("[zero map]");
159 zero_pgtable = kernel_ptr_table();
160 pte_dir = (pte_t *)zero_pgtable;
161 pmd_dir->pmd[0] = virt_to_phys(pte_dir) |
162 _PAGE_TABLE | _PAGE_ACCESSED;
163 pte_val(*pte_dir++) = 0;
164 physaddr += PAGE_SIZE;
165 for (i = 1; i < 64; physaddr += PAGE_SIZE, i++)
166 pte_val(*pte_dir++) = physaddr;
169 virtaddr += PTRTREESIZE;
171 if (!pmd_present(*pmd_dir)) {
173 printk ("[new table]");
175 pte_dir = kernel_page_table();
176 pmd_set(pmd_dir, pte_dir);
178 pte_dir = pte_offset_kernel(pmd_dir, virtaddr);
181 if (!pte_present(*pte_dir))
182 pte_val(*pte_dir) = physaddr;
184 pte_val(*pte_dir) = 0;
186 virtaddr += PAGE_SIZE;
187 physaddr += PAGE_SIZE;
199 * paging_init() continues the virtual memory environment setup which
200 * was begun by the code in arch/head.S.
202 void __init paging_init(void)
205 unsigned long mem_avail = 0;
206 unsigned long zones_size[3] = { 0, };
210 extern unsigned long availmem;
211 printk ("start of paging_init (%p, %lx, %lx, %lx)\n",
212 kernel_pg_dir, availmem, start_mem, end_mem);
216 /* Fix the cache mode in the page descriptors for the 680[46]0. */
217 if (CPU_IS_040_OR_060) {
220 mm_cachebits = _PAGE_CACHE040;
222 for (i = 0; i < 16; i++)
223 pgprot_val(protection_map[i]) |= _PAGE_CACHE040;
227 * Map the physical memory available into the kernel virtual
228 * address space. It may allocate some memory for page
229 * tables and thus modify availmem.
232 for (chunk = 0; chunk < m68k_num_memory; chunk++) {
233 mem_avail = map_chunk (m68k_memory[chunk].addr,
234 m68k_memory[chunk].size);
240 printk ("memory available is %ldKB\n", mem_avail >> 10);
241 printk ("start_mem is %#lx\nvirtual_end is %#lx\n",
246 * initialize the bad page table and bad page to point
247 * to a couple of allocated pages
249 empty_zero_page = alloc_bootmem_pages(PAGE_SIZE);
250 memset(empty_zero_page, 0, PAGE_SIZE);
253 * Set up SFC/DFC registers
258 printk ("before free_area_init\n");
260 zones_size[0] = (mach_max_dma_address < (unsigned long)high_memory ?
261 (mach_max_dma_address+1) : (unsigned long)high_memory);
262 zones_size[1] = (unsigned long)high_memory - zones_size[0];
264 zones_size[0] = (zones_size[0] - PAGE_OFFSET) >> PAGE_SHIFT;
265 zones_size[1] >>= PAGE_SHIFT;
267 free_area_init(zones_size);
270 extern char __init_begin, __init_end;
272 void free_initmem(void)
276 addr = (unsigned long)&__init_begin;
277 for (; addr < (unsigned long)&__init_end; addr += PAGE_SIZE) {
278 virt_to_page(addr)->flags &= ~(1 << PG_reserved);
279 init_page_count(virt_to_page(addr));