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/signal.h>
13 #include <linux/sched.h>
15 #include <linux/swap.h>
16 #include <linux/kernel.h>
17 #include <linux/string.h>
18 #include <linux/types.h>
19 #include <linux/init.h>
20 #include <linux/bootmem.h>
21 #ifdef CONFIG_BLK_DEV_RAM
22 #include <linux/blk.h>
25 #include <asm/setup.h>
26 #include <asm/uaccess.h>
28 #include <asm/pgalloc.h>
29 #include <asm/system.h>
30 #include <asm/machdep.h>
34 #include <asm/atari_stram.h>
41 * Bits to add to page descriptors for "normal" caching mode.
42 * For 68020/030 this is 0.
43 * For 68040, this is _PAGE_CACHE040 (cachable, copyback)
45 unsigned long mm_cachebits
= 0;
48 static pte_t
* __init
kernel_page_table(void)
52 ptablep
= (pte_t
*)alloc_bootmem_low_pages(PAGE_SIZE
);
55 __flush_page_to_ram((unsigned long) ptablep
);
56 flush_tlb_kernel_page((unsigned long) ptablep
);
57 nocache_page ((unsigned long)ptablep
);
62 static pmd_t
*last_pgtable __initdata
= NULL
;
63 pmd_t
*zero_pgtable __initdata
= NULL
;
65 static pmd_t
* __init
kernel_ptr_table(void)
68 unsigned long pmd
, last
;
71 /* Find the last ptr table that was used in head.S and
72 * reuse the remaining space in that page for further
75 last
= (unsigned long)kernel_pg_dir
;
76 for (i
= 0; i
< PTRS_PER_PGD
; i
++) {
77 if (!pgd_present(kernel_pg_dir
[i
]))
79 pmd
= __pgd_page(kernel_pg_dir
[i
]);
84 last_pgtable
= (pmd_t
*)last
;
86 printk("kernel_ptr_init: %p\n", last_pgtable
);
90 if (((unsigned long)(last_pgtable
+ PTRS_PER_PMD
) & ~PAGE_MASK
) == 0) {
91 last_pgtable
= (pmd_t
*)alloc_bootmem_low_pages(PAGE_SIZE
);
93 clear_page(last_pgtable
);
94 __flush_page_to_ram((unsigned long)last_pgtable
);
95 flush_tlb_kernel_page((unsigned long)last_pgtable
);
96 nocache_page((unsigned long)last_pgtable
);
98 last_pgtable
+= PTRS_PER_PMD
;
103 static unsigned long __init
104 map_chunk (unsigned long addr
, long size
)
106 #define PTRTREESIZE (256*1024)
107 #define ROOTTREESIZE (32*1024*1024)
108 static unsigned long virtaddr
= PAGE_OFFSET
;
109 unsigned long physaddr
;
114 physaddr
= (addr
| m68k_supervisor_cachemode
|
115 _PAGE_PRESENT
| _PAGE_ACCESSED
| _PAGE_DIRTY
);
116 if (CPU_IS_040_OR_060
)
117 physaddr
|= _PAGE_GLOBAL040
;
121 if (!(virtaddr
& (PTRTREESIZE
-1)))
122 printk ("\npa=%#lx va=%#lx ", physaddr
& PAGE_MASK
,
125 pgd_dir
= pgd_offset_k(virtaddr
);
126 if (virtaddr
&& CPU_IS_020_OR_030
) {
127 if (!(virtaddr
& (ROOTTREESIZE
-1)) &&
128 size
>= ROOTTREESIZE
) {
130 printk ("[very early term]");
132 pgd_val(*pgd_dir
) = physaddr
;
133 size
-= ROOTTREESIZE
;
134 virtaddr
+= ROOTTREESIZE
;
135 physaddr
+= ROOTTREESIZE
;
139 if (!pgd_present(*pgd_dir
)) {
140 pmd_dir
= kernel_ptr_table();
142 printk ("[new pointer %p]", pmd_dir
);
144 pgd_set(pgd_dir
, pmd_dir
);
146 pmd_dir
= pmd_offset(pgd_dir
, virtaddr
);
148 if (CPU_IS_020_OR_030
) {
151 printk ("[early term]");
153 pmd_dir
->pmd
[(virtaddr
/PTRTREESIZE
) & 15] = physaddr
;
154 physaddr
+= PTRTREESIZE
;
158 printk ("[zero map]");
160 zero_pgtable
= kernel_ptr_table();
161 pte_dir
= (pte_t
*)zero_pgtable
;
162 pmd_dir
->pmd
[0] = virt_to_phys(pte_dir
) |
163 _PAGE_TABLE
| _PAGE_ACCESSED
;
164 pte_val(*pte_dir
++) = 0;
165 physaddr
+= PAGE_SIZE
;
166 for (i
= 1; i
< 64; physaddr
+= PAGE_SIZE
, i
++)
167 pte_val(*pte_dir
++) = physaddr
;
170 virtaddr
+= PTRTREESIZE
;
172 if (!pmd_present(*pmd_dir
)) {
174 printk ("[new table]");
176 pte_dir
= kernel_page_table();
177 pmd_set(pmd_dir
, pte_dir
);
179 pte_dir
= pte_offset(pmd_dir
, virtaddr
);
182 if (!pte_present(*pte_dir
))
183 pte_val(*pte_dir
) = physaddr
;
185 pte_val(*pte_dir
) = 0;
187 virtaddr
+= PAGE_SIZE
;
188 physaddr
+= PAGE_SIZE
;
199 extern unsigned long empty_bad_page_table
;
200 extern unsigned long empty_bad_page
;
203 * paging_init() continues the virtual memory environment setup which
204 * was begun by the code in arch/head.S.
206 void __init
paging_init(void)
209 unsigned long mem_avail
= 0;
210 unsigned long zones_size
[3] = { 0, };
214 extern unsigned long availmem
;
215 printk ("start of paging_init (%p, %lx, %lx, %lx)\n",
216 kernel_pg_dir
, availmem
, start_mem
, end_mem
);
220 /* Fix the cache mode in the page descriptors for the 680[46]0. */
221 if (CPU_IS_040_OR_060
) {
224 mm_cachebits
= _PAGE_CACHE040
;
226 for (i
= 0; i
< 16; i
++)
227 pgprot_val(protection_map
[i
]) |= _PAGE_CACHE040
;
229 /* Fix the PAGE_NONE value. */
230 if (CPU_IS_040_OR_060
) {
231 /* On the 680[46]0 we can use the _PAGE_SUPER bit. */
232 pgprot_val(protection_map
[0]) |= _PAGE_SUPER
;
233 pgprot_val(protection_map
[VM_SHARED
]) |= _PAGE_SUPER
;
235 /* Otherwise we must fake it. */
236 pgprot_val(protection_map
[0]) &= ~_PAGE_PRESENT
;
237 pgprot_val(protection_map
[0]) |= _PAGE_FAKE_SUPER
;
238 pgprot_val(protection_map
[VM_SHARED
]) &= ~_PAGE_PRESENT
;
239 pgprot_val(protection_map
[VM_SHARED
]) |= _PAGE_FAKE_SUPER
;
243 * Map the physical memory available into the kernel virtual
244 * address space. It may allocate some memory for page
245 * tables and thus modify availmem.
248 for (chunk
= 0; chunk
< m68k_num_memory
; chunk
++) {
249 mem_avail
= map_chunk (m68k_memory
[chunk
].addr
,
250 m68k_memory
[chunk
].size
);
256 printk ("memory available is %ldKB\n", mem_avail
>> 10);
257 printk ("start_mem is %#lx\nvirtual_end is %#lx\n",
262 * initialize the bad page table and bad page to point
263 * to a couple of allocated pages
265 empty_bad_page_table
= (unsigned long)alloc_bootmem_pages(PAGE_SIZE
);
266 empty_bad_page
= (unsigned long)alloc_bootmem_pages(PAGE_SIZE
);
267 empty_zero_page
= (unsigned long)alloc_bootmem_pages(PAGE_SIZE
);
268 memset((void *)empty_zero_page
, 0, PAGE_SIZE
);
271 * Set up SFC/DFC registers (user data space)
276 printk ("before free_area_init\n");
278 zones_size
[0] = (mach_max_dma_address
< (unsigned long)high_memory
?
279 mach_max_dma_address
: (unsigned long)high_memory
);
280 zones_size
[1] = (unsigned long)high_memory
- zones_size
[0];
282 zones_size
[0] = (zones_size
[0] - PAGE_OFFSET
) >> PAGE_SHIFT
;
283 zones_size
[1] >>= PAGE_SHIFT
;
285 free_area_init(zones_size
);
288 extern char __init_begin
, __init_end
;
290 void free_initmem(void)
294 addr
= (unsigned long)&__init_begin
;
295 for (; addr
< (unsigned long)&__init_end
; addr
+= PAGE_SIZE
) {
296 virt_to_page(addr
)->flags
&= ~(1 << PG_reserved
);
297 set_page_count(virt_to_page(addr
), 1);