sparc32: Trivial removal of sun4c references in comments.
[deliverable/linux.git] / arch / sparc / mm / init_32.c
CommitLineData
88278ca2 1/*
1da177e4
LT
2 * linux/arch/sparc/mm/init.c
3 *
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1995 Eddie C. Dost (ecd@skynet.be)
6 * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
7 * Copyright (C) 2000 Anton Blanchard (anton@samba.org)
8 */
9
1da177e4
LT
10#include <linux/module.h>
11#include <linux/signal.h>
12#include <linux/sched.h>
13#include <linux/kernel.h>
14#include <linux/errno.h>
15#include <linux/string.h>
16#include <linux/types.h>
17#include <linux/ptrace.h>
18#include <linux/mman.h>
19#include <linux/mm.h>
20#include <linux/swap.h>
21#include <linux/initrd.h>
22#include <linux/init.h>
23#include <linux/highmem.h>
24#include <linux/bootmem.h>
f538f3df 25#include <linux/pagemap.h>
1aa0365f 26#include <linux/poison.h>
5a0e3ad6 27#include <linux/gfp.h>
1da177e4 28
86ed40bd 29#include <asm/sections.h>
1da177e4
LT
30#include <asm/page.h>
31#include <asm/pgtable.h>
32#include <asm/vaddrs.h>
33#include <asm/pgalloc.h> /* bug in asm-generic/tlb.h: check_pgt_cache */
34#include <asm/tlb.h>
942a6bdd 35#include <asm/prom.h>
0fd7ef1f 36#include <asm/leon.h>
1da177e4 37
1da177e4 38unsigned long *sparc_valid_addr_bitmap;
6943f3da 39EXPORT_SYMBOL(sparc_valid_addr_bitmap);
1da177e4
LT
40
41unsigned long phys_base;
6943f3da
SR
42EXPORT_SYMBOL(phys_base);
43
1da177e4 44unsigned long pfn_base;
6943f3da 45EXPORT_SYMBOL(pfn_base);
1da177e4
LT
46
47unsigned long page_kernel;
6943f3da 48EXPORT_SYMBOL(page_kernel);
1da177e4
LT
49
50struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS+1];
51unsigned long sparc_unmapped_base;
52
53struct pgtable_cache_struct pgt_quicklists;
54
1da177e4
LT
55/* Initial ramdisk setup */
56extern unsigned int sparc_ramdisk_image;
57extern unsigned int sparc_ramdisk_size;
58
59unsigned long highstart_pfn, highend_pfn;
60
61pte_t *kmap_pte;
62pgprot_t kmap_prot;
63
64#define kmap_get_fixmap_pte(vaddr) \
65 pte_offset_kernel(pmd_offset(pgd_offset_k(vaddr), (vaddr)), (vaddr))
66
67void __init kmap_init(void)
68{
69 /* cache the first kmap pte */
70 kmap_pte = kmap_get_fixmap_pte(__fix_to_virt(FIX_KMAP_BEGIN));
71 kmap_prot = __pgprot(SRMMU_ET_PTE | SRMMU_PRIV | SRMMU_CACHE);
72}
73
b2b755b5 74void show_mem(unsigned int filter)
1da177e4
LT
75{
76 printk("Mem-info:\n");
7bf02ea2 77 show_free_areas(filter);
1da177e4
LT
78 printk("Free swap: %6ldkB\n",
79 nr_swap_pages << (PAGE_SHIFT-10));
80 printk("%ld pages of RAM\n", totalram_pages);
f0f0d0c6 81 printk("%ld free pages\n", nr_free_pages());
1da177e4
LT
82#if 0 /* undefined pgtable_cache_size, pgd_cache_size */
83 printk("%ld pages in page table cache\n",pgtable_cache_size);
84#ifndef CONFIG_SMP
85 if (sparc_cpu_model == sun4m || sparc_cpu_model == sun4d)
86 printk("%ld entries in page dir cache\n",pgd_cache_size);
87#endif
88#endif
89}
90
91void __init sparc_context_init(int numctx)
92{
93 int ctx;
94
95 ctx_list_pool = __alloc_bootmem(numctx * sizeof(struct ctx_list), SMP_CACHE_BYTES, 0UL);
96
97 for(ctx = 0; ctx < numctx; ctx++) {
98 struct ctx_list *clist;
99
100 clist = (ctx_list_pool + ctx);
101 clist->ctx_number = ctx;
102 clist->ctx_mm = NULL;
103 }
104 ctx_free.next = ctx_free.prev = &ctx_free;
105 ctx_used.next = ctx_used.prev = &ctx_used;
106 for(ctx = 0; ctx < numctx; ctx++)
107 add_to_free_ctxlist(ctx_list_pool + ctx);
108}
109
110extern unsigned long cmdline_memory_size;
111unsigned long last_valid_pfn;
112
113unsigned long calc_highpages(void)
114{
115 int i;
116 int nr = 0;
117
118 for (i = 0; sp_banks[i].num_bytes != 0; i++) {
119 unsigned long start_pfn = sp_banks[i].base_addr >> PAGE_SHIFT;
120 unsigned long end_pfn = (sp_banks[i].base_addr + sp_banks[i].num_bytes) >> PAGE_SHIFT;
121
122 if (end_pfn <= max_low_pfn)
123 continue;
124
125 if (start_pfn < max_low_pfn)
126 start_pfn = max_low_pfn;
127
128 nr += end_pfn - start_pfn;
129 }
130
131 return nr;
132}
133
50215d65 134static unsigned long calc_max_low_pfn(void)
1da177e4
LT
135{
136 int i;
137 unsigned long tmp = pfn_base + (SRMMU_MAXMEM >> PAGE_SHIFT);
138 unsigned long curr_pfn, last_pfn;
139
140 last_pfn = (sp_banks[0].base_addr + sp_banks[0].num_bytes) >> PAGE_SHIFT;
141 for (i = 1; sp_banks[i].num_bytes != 0; i++) {
142 curr_pfn = sp_banks[i].base_addr >> PAGE_SHIFT;
143
144 if (curr_pfn >= tmp) {
145 if (last_pfn < tmp)
146 tmp = last_pfn;
147 break;
148 }
149
150 last_pfn = (sp_banks[i].base_addr + sp_banks[i].num_bytes) >> PAGE_SHIFT;
151 }
152
153 return tmp;
154}
155
156unsigned long __init bootmem_init(unsigned long *pages_avail)
157{
158 unsigned long bootmap_size, start_pfn;
159 unsigned long end_of_phys_memory = 0UL;
160 unsigned long bootmap_pfn, bytes_avail, size;
161 int i;
162
163 bytes_avail = 0UL;
164 for (i = 0; sp_banks[i].num_bytes != 0; i++) {
165 end_of_phys_memory = sp_banks[i].base_addr +
166 sp_banks[i].num_bytes;
167 bytes_avail += sp_banks[i].num_bytes;
168 if (cmdline_memory_size) {
169 if (bytes_avail > cmdline_memory_size) {
170 unsigned long slack = bytes_avail - cmdline_memory_size;
171
172 bytes_avail -= slack;
173 end_of_phys_memory -= slack;
174
175 sp_banks[i].num_bytes -= slack;
176 if (sp_banks[i].num_bytes == 0) {
177 sp_banks[i].base_addr = 0xdeadbeef;
178 } else {
179 sp_banks[i+1].num_bytes = 0;
180 sp_banks[i+1].base_addr = 0xdeadbeef;
181 }
182 break;
183 }
184 }
185 }
186
187 /* Start with page aligned address of last symbol in kernel
188 * image.
189 */
190 start_pfn = (unsigned long)__pa(PAGE_ALIGN((unsigned long) &_end));
191
192 /* Now shift down to get the real physical page frame number. */
193 start_pfn >>= PAGE_SHIFT;
194
195 bootmap_pfn = start_pfn;
196
197 max_pfn = end_of_phys_memory >> PAGE_SHIFT;
198
199 max_low_pfn = max_pfn;
200 highstart_pfn = highend_pfn = max_pfn;
201
202 if (max_low_pfn > pfn_base + (SRMMU_MAXMEM >> PAGE_SHIFT)) {
203 highstart_pfn = pfn_base + (SRMMU_MAXMEM >> PAGE_SHIFT);
204 max_low_pfn = calc_max_low_pfn();
205 printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
206 calc_highpages() >> (20 - PAGE_SHIFT));
207 }
208
209#ifdef CONFIG_BLK_DEV_INITRD
210 /* Now have to check initial ramdisk, so that bootmap does not overwrite it */
211 if (sparc_ramdisk_image) {
efb89630
DM
212 if (sparc_ramdisk_image >= (unsigned long)&_end - 2 * PAGE_SIZE)
213 sparc_ramdisk_image -= KERNBASE;
1da177e4
LT
214 initrd_start = sparc_ramdisk_image + phys_base;
215 initrd_end = initrd_start + sparc_ramdisk_size;
216 if (initrd_end > end_of_phys_memory) {
217 printk(KERN_CRIT "initrd extends beyond end of memory "
218 "(0x%016lx > 0x%016lx)\ndisabling initrd\n",
219 initrd_end, end_of_phys_memory);
220 initrd_start = 0;
221 }
222 if (initrd_start) {
223 if (initrd_start >= (start_pfn << PAGE_SHIFT) &&
224 initrd_start < (start_pfn << PAGE_SHIFT) + 2 * PAGE_SIZE)
225 bootmap_pfn = PAGE_ALIGN (initrd_end) >> PAGE_SHIFT;
226 }
227 }
228#endif
229 /* Initialize the boot-time allocator. */
230 bootmap_size = init_bootmem_node(NODE_DATA(0), bootmap_pfn, pfn_base,
231 max_low_pfn);
232
233 /* Now register the available physical memory with the
234 * allocator.
235 */
236 *pages_avail = 0;
237 for (i = 0; sp_banks[i].num_bytes != 0; i++) {
238 unsigned long curr_pfn, last_pfn;
239
240 curr_pfn = sp_banks[i].base_addr >> PAGE_SHIFT;
241 if (curr_pfn >= max_low_pfn)
242 break;
243
244 last_pfn = (sp_banks[i].base_addr + sp_banks[i].num_bytes) >> PAGE_SHIFT;
245 if (last_pfn > max_low_pfn)
246 last_pfn = max_low_pfn;
247
248 /*
249 * .. finally, did all the rounding and playing
250 * around just make the area go away?
251 */
252 if (last_pfn <= curr_pfn)
253 continue;
254
255 size = (last_pfn - curr_pfn) << PAGE_SHIFT;
256 *pages_avail += last_pfn - curr_pfn;
257
258 free_bootmem(sp_banks[i].base_addr, size);
259 }
260
261#ifdef CONFIG_BLK_DEV_INITRD
262 if (initrd_start) {
263 /* Reserve the initrd image area. */
264 size = initrd_end - initrd_start;
72a7fe39 265 reserve_bootmem(initrd_start, size, BOOTMEM_DEFAULT);
1da177e4
LT
266 *pages_avail -= PAGE_ALIGN(size) >> PAGE_SHIFT;
267
268 initrd_start = (initrd_start - phys_base) + PAGE_OFFSET;
269 initrd_end = (initrd_end - phys_base) + PAGE_OFFSET;
270 }
271#endif
272 /* Reserve the kernel text/data/bss. */
273 size = (start_pfn << PAGE_SHIFT) - phys_base;
72a7fe39 274 reserve_bootmem(phys_base, size, BOOTMEM_DEFAULT);
1da177e4
LT
275 *pages_avail -= PAGE_ALIGN(size) >> PAGE_SHIFT;
276
277 /* Reserve the bootmem map. We do not account for it
278 * in pages_avail because we will release that memory
279 * in free_all_bootmem.
280 */
281 size = bootmap_size;
72a7fe39 282 reserve_bootmem((bootmap_pfn << PAGE_SHIFT), size, BOOTMEM_DEFAULT);
1da177e4
LT
283 *pages_avail -= PAGE_ALIGN(size) >> PAGE_SHIFT;
284
285 return max_pfn;
286}
287
288/*
289 * check_pgt_cache
290 *
291 * This is called at the end of unmapping of VMA (zap_page_range),
ee906c9e
DM
292 * to rescan the page cache for architecture specific things.
293 * Most architectures define check_pgt_cache empty.
1da177e4
LT
294 *
295 * We simply copy the 2.4 implementation for now.
296 */
50215d65 297static int pgt_cache_water[2] = { 25, 50 };
1da177e4
LT
298
299void check_pgt_cache(void)
300{
301 do_check_pgt_cache(pgt_cache_water[0], pgt_cache_water[1]);
302}
303
304/*
305 * paging_init() sets up the page tables: We call the MMU specific
306 * init routine based upon the Sun model type on the Sparc.
307 *
308 */
1da177e4
LT
309extern void srmmu_paging_init(void);
310extern void device_scan(void);
311
378e515c
AV
312pgprot_t PAGE_SHARED __read_mostly;
313EXPORT_SYMBOL(PAGE_SHARED);
314
1da177e4
LT
315void __init paging_init(void)
316{
317 switch(sparc_cpu_model) {
0fd7ef1f
KE
318 case sparc_leon:
319 leon_init();
320 /* fall through */
1da177e4
LT
321 case sun4m:
322 case sun4d:
323 srmmu_paging_init();
324 sparc_unmapped_base = 0x50000000;
325 BTFIXUPSET_SETHI(sparc_unmapped_base, 0x50000000);
326 break;
327 default:
328 prom_printf("paging_init: Cannot init paging on this Sparc\n");
329 prom_printf("paging_init: sparc_cpu_model = %d\n", sparc_cpu_model);
330 prom_printf("paging_init: Halting...\n");
331 prom_halt();
6cb79b3f 332 }
1da177e4
LT
333
334 /* Initialize the protection map with non-constant, MMU dependent values. */
335 protection_map[0] = PAGE_NONE;
336 protection_map[1] = PAGE_READONLY;
337 protection_map[2] = PAGE_COPY;
338 protection_map[3] = PAGE_COPY;
339 protection_map[4] = PAGE_READONLY;
340 protection_map[5] = PAGE_READONLY;
341 protection_map[6] = PAGE_COPY;
342 protection_map[7] = PAGE_COPY;
343 protection_map[8] = PAGE_NONE;
344 protection_map[9] = PAGE_READONLY;
345 protection_map[10] = PAGE_SHARED;
346 protection_map[11] = PAGE_SHARED;
347 protection_map[12] = PAGE_READONLY;
348 protection_map[13] = PAGE_READONLY;
349 protection_map[14] = PAGE_SHARED;
350 protection_map[15] = PAGE_SHARED;
351 btfixup();
942a6bdd 352 prom_build_devicetree();
890db403 353 of_fill_in_cpu_data();
1da177e4
LT
354 device_scan();
355}
356
1da177e4
LT
357static void __init taint_real_pages(void)
358{
359 int i;
360
361 for (i = 0; sp_banks[i].num_bytes; i++) {
362 unsigned long start, end;
363
364 start = sp_banks[i].base_addr;
365 end = start + sp_banks[i].num_bytes;
366
367 while (start < end) {
368 set_bit(start >> 20, sparc_valid_addr_bitmap);
369 start += PAGE_SIZE;
370 }
371 }
372}
373
50215d65 374static void map_high_region(unsigned long start_pfn, unsigned long end_pfn)
1da177e4
LT
375{
376 unsigned long tmp;
377
378#ifdef CONFIG_DEBUG_HIGHMEM
379 printk("mapping high region %08lx - %08lx\n", start_pfn, end_pfn);
380#endif
381
382 for (tmp = start_pfn; tmp < end_pfn; tmp++) {
383 struct page *page = pfn_to_page(tmp);
384
385 ClearPageReserved(page);
7835e98b 386 init_page_count(page);
1da177e4
LT
387 __free_page(page);
388 totalhigh_pages++;
389 }
390}
391
392void __init mem_init(void)
393{
394 int codepages = 0;
395 int datapages = 0;
396 int initpages = 0;
397 int reservedpages = 0;
398 int i;
399
400 if (PKMAP_BASE+LAST_PKMAP*PAGE_SIZE >= FIXADDR_START) {
401 prom_printf("BUG: fixmap and pkmap areas overlap\n");
402 prom_printf("pkbase: 0x%lx pkend: 0x%lx fixstart 0x%lx\n",
403 PKMAP_BASE,
404 (unsigned long)PKMAP_BASE+LAST_PKMAP*PAGE_SIZE,
405 FIXADDR_START);
406 prom_printf("Please mail sparclinux@vger.kernel.org.\n");
407 prom_halt();
408 }
409
410
411 /* Saves us work later. */
412 memset((void *)&empty_zero_page, 0, PAGE_SIZE);
413
414 i = last_valid_pfn >> ((20 - PAGE_SHIFT) + 5);
415 i += 1;
416 sparc_valid_addr_bitmap = (unsigned long *)
417 __alloc_bootmem(i << 2, SMP_CACHE_BYTES, 0UL);
418
419 if (sparc_valid_addr_bitmap == NULL) {
420 prom_printf("mem_init: Cannot alloc valid_addr_bitmap.\n");
421 prom_halt();
422 }
423 memset(sparc_valid_addr_bitmap, 0, i << 2);
424
425 taint_real_pages();
426
427 max_mapnr = last_valid_pfn - pfn_base;
428 high_memory = __va(max_low_pfn << PAGE_SHIFT);
429
430 totalram_pages = free_all_bootmem();
431
432 for (i = 0; sp_banks[i].num_bytes != 0; i++) {
433 unsigned long start_pfn = sp_banks[i].base_addr >> PAGE_SHIFT;
434 unsigned long end_pfn = (sp_banks[i].base_addr + sp_banks[i].num_bytes) >> PAGE_SHIFT;
435
436 num_physpages += sp_banks[i].num_bytes >> PAGE_SHIFT;
437
438 if (end_pfn <= highstart_pfn)
439 continue;
440
441 if (start_pfn < highstart_pfn)
442 start_pfn = highstart_pfn;
443
444 map_high_region(start_pfn, end_pfn);
445 }
446
447 totalram_pages += totalhigh_pages;
448
86ed40bd 449 codepages = (((unsigned long) &_etext) - ((unsigned long)&_start));
1da177e4 450 codepages = PAGE_ALIGN(codepages) >> PAGE_SHIFT;
86ed40bd 451 datapages = (((unsigned long) &_edata) - ((unsigned long)&_etext));
1da177e4
LT
452 datapages = PAGE_ALIGN(datapages) >> PAGE_SHIFT;
453 initpages = (((unsigned long) &__init_end) - ((unsigned long) &__init_begin));
454 initpages = PAGE_ALIGN(initpages) >> PAGE_SHIFT;
455
456 /* Ignore memory holes for the purpose of counting reserved pages */
457 for (i=0; i < max_low_pfn; i++)
458 if (test_bit(i >> (20 - PAGE_SHIFT), sparc_valid_addr_bitmap)
459 && PageReserved(pfn_to_page(i)))
460 reservedpages++;
461
462 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, %dk reserved, %dk data, %dk init, %ldk highmem)\n",
cc013a88 463 nr_free_pages() << (PAGE_SHIFT-10),
1da177e4
LT
464 num_physpages << (PAGE_SHIFT - 10),
465 codepages << (PAGE_SHIFT-10),
466 reservedpages << (PAGE_SHIFT - 10),
467 datapages << (PAGE_SHIFT-10),
468 initpages << (PAGE_SHIFT-10),
469 totalhigh_pages << (PAGE_SHIFT-10));
470}
471
472void free_initmem (void)
473{
474 unsigned long addr;
86ed40bd 475 unsigned long freed;
1da177e4
LT
476
477 addr = (unsigned long)(&__init_begin);
86ed40bd 478 freed = (unsigned long)(&__init_end) - addr;
1da177e4
LT
479 for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) {
480 struct page *p;
481
1aa0365f 482 memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE);
1da177e4
LT
483 p = virt_to_page(addr);
484
485 ClearPageReserved(p);
7835e98b 486 init_page_count(p);
1da177e4
LT
487 __free_page(p);
488 totalram_pages++;
489 num_physpages++;
490 }
86ed40bd
SR
491 printk(KERN_INFO "Freeing unused kernel memory: %ldk freed\n",
492 freed >> 10);
1da177e4
LT
493}
494
495#ifdef CONFIG_BLK_DEV_INITRD
496void free_initrd_mem(unsigned long start, unsigned long end)
497{
498 if (start < end)
1aa0365f
RR
499 printk(KERN_INFO "Freeing initrd memory: %ldk freed\n",
500 (end - start) >> 10);
1da177e4 501 for (; start < end; start += PAGE_SIZE) {
1aa0365f
RR
502 struct page *p;
503
504 memset((void *)start, POISON_FREE_INITMEM, PAGE_SIZE);
505 p = virt_to_page(start);
1da177e4
LT
506
507 ClearPageReserved(p);
7835e98b 508 init_page_count(p);
1da177e4 509 __free_page(p);
1aa0365f 510 totalram_pages++;
1da177e4
LT
511 num_physpages++;
512 }
513}
514#endif
515
516void sparc_flush_page_to_ram(struct page *page)
517{
518 unsigned long vaddr = (unsigned long)page_address(page);
519
520 if (vaddr)
521 __flush_page_to_ram(vaddr);
522}
6943f3da 523EXPORT_SYMBOL(sparc_flush_page_to_ram);
This page took 0.855437 seconds and 5 git commands to generate.