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/module.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>
22 #include <asm/setup.h>
23 #include <asm/uaccess.h>
25 #include <asm/pgalloc.h>
26 #include <asm/system.h>
27 #include <asm/machdep.h>
31 #include <asm/atari_stram.h>
38 * Bits to add to page descriptors for "normal" caching mode.
39 * For 68020/030 this is 0.
40 * For 68040, this is _PAGE_CACHE040 (cachable, copyback)
42 unsigned long mm_cachebits
;
43 EXPORT_SYMBOL(mm_cachebits
);
46 static pte_t
* __init
kernel_page_table(void)
50 ptablep
= (pte_t
*)alloc_bootmem_low_pages(PAGE_SIZE
);
53 __flush_page_to_ram(ptablep
);
54 flush_tlb_kernel_page(ptablep
);
55 nocache_page(ptablep
);
60 static pmd_t
*last_pgtable __initdata
= NULL
;
61 pmd_t
*zero_pgtable __initdata
= NULL
;
63 static pmd_t
* __init
kernel_ptr_table(void)
66 unsigned long pmd
, last
;
69 /* Find the last ptr table that was used in head.S and
70 * reuse the remaining space in that page for further
73 last
= (unsigned long)kernel_pg_dir
;
74 for (i
= 0; i
< PTRS_PER_PGD
; i
++) {
75 if (!pgd_present(kernel_pg_dir
[i
]))
77 pmd
= __pgd_page(kernel_pg_dir
[i
]);
82 last_pgtable
= (pmd_t
*)last
;
84 printk("kernel_ptr_init: %p\n", last_pgtable
);
88 last_pgtable
+= PTRS_PER_PMD
;
89 if (((unsigned long)last_pgtable
& ~PAGE_MASK
) == 0) {
90 last_pgtable
= (pmd_t
*)alloc_bootmem_low_pages(PAGE_SIZE
);
92 clear_page(last_pgtable
);
93 __flush_page_to_ram(last_pgtable
);
94 flush_tlb_kernel_page(last_pgtable
);
95 nocache_page(last_pgtable
);
101 static unsigned long __init
102 map_chunk (unsigned long addr
, long size
)
104 #define PTRTREESIZE (256*1024)
105 #define ROOTTREESIZE (32*1024*1024)
106 static unsigned long virtaddr
= PAGE_OFFSET
;
107 unsigned long physaddr
;
112 physaddr
= (addr
| m68k_supervisor_cachemode
|
113 _PAGE_PRESENT
| _PAGE_ACCESSED
| _PAGE_DIRTY
);
114 if (CPU_IS_040_OR_060
)
115 physaddr
|= _PAGE_GLOBAL040
;
119 if (!(virtaddr
& (PTRTREESIZE
-1)))
120 printk ("\npa=%#lx va=%#lx ", physaddr
& PAGE_MASK
,
123 pgd_dir
= pgd_offset_k(virtaddr
);
124 if (virtaddr
&& CPU_IS_020_OR_030
) {
125 if (!(virtaddr
& (ROOTTREESIZE
-1)) &&
126 size
>= ROOTTREESIZE
) {
128 printk ("[very early term]");
130 pgd_val(*pgd_dir
) = physaddr
;
131 size
-= ROOTTREESIZE
;
132 virtaddr
+= ROOTTREESIZE
;
133 physaddr
+= ROOTTREESIZE
;
137 if (!pgd_present(*pgd_dir
)) {
138 pmd_dir
= kernel_ptr_table();
140 printk ("[new pointer %p]", pmd_dir
);
142 pgd_set(pgd_dir
, pmd_dir
);
144 pmd_dir
= pmd_offset(pgd_dir
, virtaddr
);
146 if (CPU_IS_020_OR_030
) {
149 printk ("[early term]");
151 pmd_dir
->pmd
[(virtaddr
/PTRTREESIZE
) & 15] = physaddr
;
152 physaddr
+= PTRTREESIZE
;
156 printk ("[zero map]");
158 zero_pgtable
= kernel_ptr_table();
159 pte_dir
= (pte_t
*)zero_pgtable
;
160 pmd_dir
->pmd
[0] = virt_to_phys(pte_dir
) |
161 _PAGE_TABLE
| _PAGE_ACCESSED
;
162 pte_val(*pte_dir
++) = 0;
163 physaddr
+= PAGE_SIZE
;
164 for (i
= 1; i
< 64; physaddr
+= PAGE_SIZE
, i
++)
165 pte_val(*pte_dir
++) = physaddr
;
168 virtaddr
+= PTRTREESIZE
;
170 if (!pmd_present(*pmd_dir
)) {
172 printk ("[new table]");
174 pte_dir
= kernel_page_table();
175 pmd_set(pmd_dir
, pte_dir
);
177 pte_dir
= pte_offset_kernel(pmd_dir
, virtaddr
);
180 if (!pte_present(*pte_dir
))
181 pte_val(*pte_dir
) = physaddr
;
183 pte_val(*pte_dir
) = 0;
185 virtaddr
+= PAGE_SIZE
;
186 physaddr
+= PAGE_SIZE
;
198 * paging_init() continues the virtual memory environment setup which
199 * was begun by the code in arch/head.S.
201 void __init
paging_init(void)
204 unsigned long mem_avail
= 0;
205 unsigned long zones_size
[MAX_NR_ZONES
] = { 0, };
209 extern unsigned long availmem
;
210 printk ("start of paging_init (%p, %lx, %lx, %lx)\n",
211 kernel_pg_dir
, availmem
, start_mem
, end_mem
);
215 /* Fix the cache mode in the page descriptors for the 680[46]0. */
216 if (CPU_IS_040_OR_060
) {
219 mm_cachebits
= _PAGE_CACHE040
;
221 for (i
= 0; i
< 16; i
++)
222 pgprot_val(protection_map
[i
]) |= _PAGE_CACHE040
;
226 * Map the physical memory available into the kernel virtual
227 * address space. It may allocate some memory for page
228 * tables and thus modify availmem.
231 for (chunk
= 0; chunk
< m68k_num_memory
; chunk
++) {
232 mem_avail
= map_chunk (m68k_memory
[chunk
].addr
,
233 m68k_memory
[chunk
].size
);
239 printk ("memory available is %ldKB\n", mem_avail
>> 10);
240 printk ("start_mem is %#lx\nvirtual_end is %#lx\n",
245 * initialize the bad page table and bad page to point
246 * to a couple of allocated pages
248 empty_zero_page
= alloc_bootmem_pages(PAGE_SIZE
);
249 memset(empty_zero_page
, 0, PAGE_SIZE
);
252 * Set up SFC/DFC registers
257 printk ("before free_area_init\n");
259 zones_size
[ZONE_DMA
] = (mach_max_dma_address
< (unsigned long)high_memory
?
260 (mach_max_dma_address
+1) : (unsigned long)high_memory
);
261 zones_size
[ZONE_NORMAL
] = (unsigned long)high_memory
- zones_size
[0];
263 zones_size
[ZONE_DMA
] = (zones_size
[ZONE_DMA
] - PAGE_OFFSET
) >> PAGE_SHIFT
;
264 zones_size
[ZONE_NORMAL
] >>= PAGE_SHIFT
;
266 free_area_init(zones_size
);
269 extern char __init_begin
, __init_end
;
271 void free_initmem(void)
275 addr
= (unsigned long)&__init_begin
;
276 for (; addr
< (unsigned long)&__init_end
; addr
+= PAGE_SIZE
) {
277 virt_to_page(addr
)->flags
&= ~(1 << PG_reserved
);
278 init_page_count(virt_to_page(addr
));