2 * linux/arch/m68k/mm/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>
21 #include <linux/gfp.h>
23 #include <asm/setup.h>
24 #include <asm/uaccess.h>
26 #include <asm/pgalloc.h>
27 #include <asm/machdep.h>
31 #include <asm/atari_stram.h>
33 #include <asm/sections.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 /* size of memory already mapped in head.S */
48 extern __initdata
unsigned long m68k_init_mapped_size
;
50 extern unsigned long availmem
;
52 static pte_t
* __init
kernel_page_table(void)
56 ptablep
= (pte_t
*)alloc_bootmem_low_pages(PAGE_SIZE
);
59 __flush_page_to_ram(ptablep
);
60 flush_tlb_kernel_page(ptablep
);
61 nocache_page(ptablep
);
66 static pmd_t
*last_pgtable __initdata
= NULL
;
67 pmd_t
*zero_pgtable __initdata
= NULL
;
69 static pmd_t
* __init
kernel_ptr_table(void)
72 unsigned long pmd
, last
;
75 /* Find the last ptr table that was used in head.S and
76 * reuse the remaining space in that page for further
79 last
= (unsigned long)kernel_pg_dir
;
80 for (i
= 0; i
< PTRS_PER_PGD
; i
++) {
81 if (!pgd_present(kernel_pg_dir
[i
]))
83 pmd
= __pgd_page(kernel_pg_dir
[i
]);
88 last_pgtable
= (pmd_t
*)last
;
90 printk("kernel_ptr_init: %p\n", last_pgtable
);
94 last_pgtable
+= PTRS_PER_PMD
;
95 if (((unsigned long)last_pgtable
& ~PAGE_MASK
) == 0) {
96 last_pgtable
= (pmd_t
*)alloc_bootmem_low_pages(PAGE_SIZE
);
98 clear_page(last_pgtable
);
99 __flush_page_to_ram(last_pgtable
);
100 flush_tlb_kernel_page(last_pgtable
);
101 nocache_page(last_pgtable
);
107 static void __init
map_node(int node
)
109 #define PTRTREESIZE (256*1024)
110 #define ROOTTREESIZE (32*1024*1024)
111 unsigned long physaddr
, virtaddr
, size
;
116 size
= m68k_memory
[node
].size
;
117 physaddr
= m68k_memory
[node
].addr
;
118 virtaddr
= (unsigned long)phys_to_virt(physaddr
);
119 physaddr
|= m68k_supervisor_cachemode
|
120 _PAGE_PRESENT
| _PAGE_ACCESSED
| _PAGE_DIRTY
;
121 if (CPU_IS_040_OR_060
)
122 physaddr
|= _PAGE_GLOBAL040
;
126 if (!(virtaddr
& (PTRTREESIZE
-1)))
127 printk ("\npa=%#lx va=%#lx ", physaddr
& PAGE_MASK
,
130 pgd_dir
= pgd_offset_k(virtaddr
);
131 if (virtaddr
&& CPU_IS_020_OR_030
) {
132 if (!(virtaddr
& (ROOTTREESIZE
-1)) &&
133 size
>= ROOTTREESIZE
) {
135 printk ("[very early term]");
137 pgd_val(*pgd_dir
) = physaddr
;
138 size
-= ROOTTREESIZE
;
139 virtaddr
+= ROOTTREESIZE
;
140 physaddr
+= ROOTTREESIZE
;
144 if (!pgd_present(*pgd_dir
)) {
145 pmd_dir
= kernel_ptr_table();
147 printk ("[new pointer %p]", pmd_dir
);
149 pgd_set(pgd_dir
, pmd_dir
);
151 pmd_dir
= pmd_offset(pgd_dir
, virtaddr
);
153 if (CPU_IS_020_OR_030
) {
156 printk ("[early term]");
158 pmd_dir
->pmd
[(virtaddr
/PTRTREESIZE
) & 15] = physaddr
;
159 physaddr
+= PTRTREESIZE
;
163 printk ("[zero map]");
165 zero_pgtable
= kernel_ptr_table();
166 pte_dir
= (pte_t
*)zero_pgtable
;
167 pmd_dir
->pmd
[0] = virt_to_phys(pte_dir
) |
168 _PAGE_TABLE
| _PAGE_ACCESSED
;
169 pte_val(*pte_dir
++) = 0;
170 physaddr
+= PAGE_SIZE
;
171 for (i
= 1; i
< 64; physaddr
+= PAGE_SIZE
, i
++)
172 pte_val(*pte_dir
++) = physaddr
;
175 virtaddr
+= PTRTREESIZE
;
177 if (!pmd_present(*pmd_dir
)) {
179 printk ("[new table]");
181 pte_dir
= kernel_page_table();
182 pmd_set(pmd_dir
, pte_dir
);
184 pte_dir
= pte_offset_kernel(pmd_dir
, virtaddr
);
187 if (!pte_present(*pte_dir
))
188 pte_val(*pte_dir
) = physaddr
;
190 pte_val(*pte_dir
) = 0;
192 virtaddr
+= PAGE_SIZE
;
193 physaddr
+= PAGE_SIZE
;
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)
208 unsigned long zones_size
[MAX_NR_ZONES
] = { 0, };
209 unsigned long min_addr
, max_addr
;
210 unsigned long addr
, size
, end
;
214 printk ("start of paging_init (%p, %lx)\n", kernel_pg_dir
, availmem
);
217 /* Fix the cache mode in the page descriptors for the 680[46]0. */
218 if (CPU_IS_040_OR_060
) {
221 mm_cachebits
= _PAGE_CACHE040
;
223 for (i
= 0; i
< 16; i
++)
224 pgprot_val(protection_map
[i
]) |= _PAGE_CACHE040
;
227 min_addr
= m68k_memory
[0].addr
;
228 max_addr
= min_addr
+ m68k_memory
[0].size
;
229 for (i
= 1; i
< m68k_num_memory
;) {
230 if (m68k_memory
[i
].addr
< min_addr
) {
231 printk("Ignoring memory chunk at 0x%lx:0x%lx before the first chunk\n",
232 m68k_memory
[i
].addr
, m68k_memory
[i
].size
);
233 printk("Fix your bootloader or use a memfile to make use of this area!\n");
235 memmove(m68k_memory
+ i
, m68k_memory
+ i
+ 1,
236 (m68k_num_memory
- i
) * sizeof(struct m68k_mem_info
));
239 addr
= m68k_memory
[i
].addr
+ m68k_memory
[i
].size
;
244 m68k_memoffset
= min_addr
- PAGE_OFFSET
;
245 m68k_virt_to_node_shift
= fls(max_addr
- min_addr
- 1) - 6;
247 module_fixup(NULL
, __start_fixup
, __stop_fixup
);
250 high_memory
= phys_to_virt(max_addr
);
252 min_low_pfn
= availmem
>> PAGE_SHIFT
;
253 max_pfn
= max_low_pfn
= max_addr
>> PAGE_SHIFT
;
255 for (i
= 0; i
< m68k_num_memory
; i
++) {
256 addr
= m68k_memory
[i
].addr
;
257 end
= addr
+ m68k_memory
[i
].size
;
259 availmem
= PAGE_ALIGN(availmem
);
260 availmem
+= init_bootmem_node(NODE_DATA(i
),
261 availmem
>> PAGE_SHIFT
,
267 * Map the physical memory available into the kernel virtual
268 * address space. First initialize the bootmem allocator with
269 * the memory we already mapped, so map_node() has something
272 addr
= m68k_memory
[0].addr
;
273 size
= m68k_memory
[0].size
;
274 free_bootmem_node(NODE_DATA(0), availmem
,
275 min(m68k_init_mapped_size
, size
) - (availmem
- addr
));
277 if (size
> m68k_init_mapped_size
)
278 free_bootmem_node(NODE_DATA(0), addr
+ m68k_init_mapped_size
,
279 size
- m68k_init_mapped_size
);
281 for (i
= 1; i
< m68k_num_memory
; i
++)
287 * initialize the bad page table and bad page to point
288 * to a couple of allocated pages
290 empty_zero_page
= alloc_bootmem_pages(PAGE_SIZE
);
293 * Set up SFC/DFC registers
298 printk ("before free_area_init\n");
300 for (i
= 0; i
< m68k_num_memory
; i
++) {
301 zones_size
[ZONE_DMA
] = m68k_memory
[i
].size
>> PAGE_SHIFT
;
302 free_area_init_node(i
, zones_size
,
303 m68k_memory
[i
].addr
>> PAGE_SHIFT
, NULL
);
304 if (node_present_pages(i
))
305 node_set_state(i
, N_NORMAL_MEMORY
);