[SCSI] qla1280: convert to use the data buffer accessors
[linux-2.6/verdex.git] / arch / sh64 / mm / init.c
blob21cf42de23e222684ca502417b8419b88a6df071
1 /*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
6 * arch/sh64/mm/init.c
8 * Copyright (C) 2000, 2001 Paolo Alberelli
9 * Copyright (C) 2003, 2004 Paul Mundt
13 #include <linux/init.h>
14 #include <linux/rwsem.h>
15 #include <linux/mm.h>
16 #include <linux/swap.h>
17 #include <linux/bootmem.h>
19 #include <asm/mmu_context.h>
20 #include <asm/page.h>
21 #include <asm/pgalloc.h>
22 #include <asm/pgtable.h>
23 #include <asm/tlb.h>
25 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
28 * Cache of MMU context last used.
30 unsigned long mmu_context_cache;
31 pgd_t * mmu_pdtp_cache;
32 int after_bootmem = 0;
35 * BAD_PAGE is the page that is used for page faults when linux
36 * is out-of-memory. Older versions of linux just did a
37 * do_exit(), but using this instead means there is less risk
38 * for a process dying in kernel mode, possibly leaving an inode
39 * unused etc..
41 * BAD_PAGETABLE is the accompanying page-table: it is initialized
42 * to point to BAD_PAGE entries.
44 * ZERO_PAGE is a special page that is used for zero-initialized
45 * data and COW.
48 extern unsigned char empty_zero_page[PAGE_SIZE];
49 extern unsigned char empty_bad_page[PAGE_SIZE];
50 extern pte_t empty_bad_pte_table[PTRS_PER_PTE];
51 extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
53 extern char _text, _etext, _edata, __bss_start, _end;
54 extern char __init_begin, __init_end;
56 /* It'd be good if these lines were in the standard header file. */
57 #define START_PFN (NODE_DATA(0)->bdata->node_boot_start >> PAGE_SHIFT)
58 #define MAX_LOW_PFN (NODE_DATA(0)->bdata->node_low_pfn)
61 void show_mem(void)
63 int i, total = 0, reserved = 0;
64 int shared = 0, cached = 0;
66 printk("Mem-info:\n");
67 show_free_areas();
68 printk("Free swap: %6ldkB\n",nr_swap_pages<<(PAGE_SHIFT-10));
69 i = max_mapnr;
70 while (i-- > 0) {
71 total++;
72 if (PageReserved(mem_map+i))
73 reserved++;
74 else if (PageSwapCache(mem_map+i))
75 cached++;
76 else if (page_count(mem_map+i))
77 shared += page_count(mem_map+i) - 1;
79 printk("%d pages of RAM\n",total);
80 printk("%d reserved pages\n",reserved);
81 printk("%d pages shared\n",shared);
82 printk("%d pages swap cached\n",cached);
83 printk("%ld pages in page table cache\n", quicklist_total_size());
87 * paging_init() sets up the page tables.
89 * head.S already did a lot to set up address translation for the kernel.
90 * Here we comes with:
91 * . MMU enabled
92 * . ASID set (SR)
93 * . some 512MB regions being mapped of which the most relevant here is:
94 * . CACHED segment (ASID 0 [irrelevant], shared AND NOT user)
95 * . possible variable length regions being mapped as:
96 * . UNCACHED segment (ASID 0 [irrelevant], shared AND NOT user)
97 * . All of the memory regions are placed, independently from the platform
98 * on high addresses, above 0x80000000.
99 * . swapper_pg_dir is already cleared out by the .space directive
100 * in any case swapper does not require a real page directory since
101 * it's all kernel contained.
103 * Those pesky NULL-reference errors in the kernel are then
104 * dealt with by not mapping address 0x00000000 at all.
107 void __init paging_init(void)
109 unsigned long zones_size[MAX_NR_ZONES] = {0, };
111 pgd_init((unsigned long)swapper_pg_dir);
112 pgd_init((unsigned long)swapper_pg_dir +
113 sizeof(pgd_t) * USER_PTRS_PER_PGD);
115 mmu_context_cache = MMU_CONTEXT_FIRST_VERSION;
117 zones_size[ZONE_NORMAL] = MAX_LOW_PFN - START_PFN;
118 NODE_DATA(0)->node_mem_map = NULL;
119 free_area_init_node(0, NODE_DATA(0), zones_size, __MEMORY_START >> PAGE_SHIFT, 0);
122 void __init mem_init(void)
124 int codesize, reservedpages, datasize, initsize;
125 int tmp;
127 max_mapnr = num_physpages = MAX_LOW_PFN - START_PFN;
128 high_memory = (void *)__va(MAX_LOW_PFN * PAGE_SIZE);
131 * Clear the zero-page.
132 * This is not required but we might want to re-use
133 * this very page to pass boot parameters, one day.
135 memset(empty_zero_page, 0, PAGE_SIZE);
137 /* this will put all low memory onto the freelists */
138 totalram_pages += free_all_bootmem_node(NODE_DATA(0));
139 reservedpages = 0;
140 for (tmp = 0; tmp < num_physpages; tmp++)
142 * Only count reserved RAM pages
144 if (PageReserved(mem_map+tmp))
145 reservedpages++;
147 after_bootmem = 1;
149 codesize = (unsigned long) &_etext - (unsigned long) &_text;
150 datasize = (unsigned long) &_edata - (unsigned long) &_etext;
151 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
153 printk("Memory: %luk/%luk available (%dk kernel code, %dk reserved, %dk data, %dk init)\n",
154 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
155 max_mapnr << (PAGE_SHIFT-10),
156 codesize >> 10,
157 reservedpages << (PAGE_SHIFT-10),
158 datasize >> 10,
159 initsize >> 10);
162 void free_initmem(void)
164 unsigned long addr;
166 addr = (unsigned long)(&__init_begin);
167 for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) {
168 ClearPageReserved(virt_to_page(addr));
169 init_page_count(virt_to_page(addr));
170 free_page(addr);
171 totalram_pages++;
173 printk ("Freeing unused kernel memory: %ldk freed\n", (&__init_end - &__init_begin) >> 10);
176 #ifdef CONFIG_BLK_DEV_INITRD
177 void free_initrd_mem(unsigned long start, unsigned long end)
179 unsigned long p;
180 for (p = start; p < end; p += PAGE_SIZE) {
181 ClearPageReserved(virt_to_page(p));
182 init_page_count(virt_to_page(p));
183 free_page(p);
184 totalram_pages++;
186 printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
188 #endif