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.
5 *
6 * arch/sh64/mm/init.c
7 *
8 * Copyright (C) 2000, 2001 Paolo Alberelli
9 *
10 */
11
12 #include <linux/init.h>
13 #include <linux/mm.h>
14 #include <linux/swap.h>
15 #include <linux/bootmem.h>
16 #include <linux/highmem.h>
17
18 #include <asm/mmu_context.h>
19 #include <asm/page.h>
20 #include <asm/pgalloc.h>
21 #include <asm/pgtable.h>
22 #include <asm/tlb.h>
23
24 #ifdef CONFIG_BLK_DEV_INITRD
25 #include <linux/blk.h>
26 #endif
27
28 mmu_gather_t mmu_gathers[NR_CPUS];
29
30 /*
31 * Cache of MMU context last used.
32 */
33 unsigned long mmu_context_cache;
34 pgd_t * mmu_pdtp_cache;
35
36 static unsigned long totalram_pages = 0;
37 static unsigned long totalhigh_pages = 0;
38
39 /*
40 * BAD_PAGE is the page that is used for page faults when linux
41 * is out-of-memory. Older versions of linux just did a
42 * do_exit(), but using this instead means there is less risk
43 * for a process dying in kernel mode, possibly leaving an inode
44 * unused etc..
45 *
46 * BAD_PAGETABLE is the accompanying page-table: it is initialized
47 * to point to BAD_PAGE entries.
48 *
49 * ZERO_PAGE is a special page that is used for zero-initialized
50 * data and COW.
51 */
52
53 extern unsigned char empty_zero_page[PAGE_SIZE];
54 extern unsigned char empty_bad_page[PAGE_SIZE];
55 extern pte_t empty_bad_pte_table[PTRS_PER_PTE];
56 extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
57
58 extern char _text, _etext, _edata, __bss_start, _end;
59 extern char __init_begin, __init_end;
60
61 /* It'd be good if these lines were in the standard header file. */
62 #define START_PFN (NODE_DATA(0)->bdata->node_boot_start >> PAGE_SHIFT)
63 #define MAX_LOW_PFN (NODE_DATA(0)->bdata->node_low_pfn)
64
65
show_mem(void)66 void show_mem(void)
67 {
68 int i, total = 0, reserved = 0;
69 int shared = 0, cached = 0;
70
71 printk("Mem-info:\n");
72 show_free_areas();
73 printk("Free swap: %6dkB\n",nr_swap_pages<<(PAGE_SHIFT-10));
74 i = max_mapnr;
75 while (i-- > 0) {
76 total++;
77 if (PageReserved(mem_map+i))
78 reserved++;
79 else if (PageSwapCache(mem_map+i))
80 cached++;
81 else if (page_count(mem_map+i))
82 shared += page_count(mem_map+i) - 1;
83 }
84 printk("%d pages of RAM\n",total);
85 printk("%d reserved pages\n",reserved);
86 printk("%d pages shared\n",shared);
87 printk("%d pages swap cached\n",cached);
88
89 show_buffers();
90 }
91
92 /*
93 * paging_init() sets up the page tables.
94 *
95 * head.S already did a lot to set up address translation for the kernel.
96 * Here we comes with:
97 * . MMU enabled
98 * . ASID set (SR)
99 * . some 512MB regions being mapped of which the most relevant here is:
100 * . CACHED segment (ASID 0 [irrelevant], shared AND NOT user)
101 * . possible variable length regions being mapped as:
102 * . UNCACHED segment (ASID 0 [irrelevant], shared AND NOT user)
103 * . All of the memory regions are placed, independently from the platform
104 * on high addresses, above 0x80000000.
105 * . swapper_pg_dir is already cleared out by the .space directive
106 * in any case swapper does not require a real page directory since
107 * it's all kernel contained.
108 *
109 * Those pesky NULL-reference errors in the kernel are then
110 * dealt with by not mapping address 0x00000000 at all.
111 *
112 */
paging_init(void)113 void __init paging_init(void)
114 {
115 unsigned long zones_size[MAX_NR_ZONES] = {0, 0, 0};
116
117
118 mmu_context_cache = MMU_CONTEXT_FIRST_VERSION;
119
120 /*
121 * All memory is good as ZONE_NORMAL (fall-through) and ZONE_DMA.
122 */
123 zones_size[ZONE_DMA] = MAX_LOW_PFN - START_PFN;
124
125 free_area_init_node(0, NODE_DATA(0), 0,zones_size, __MEMORY_START, 0);
126 }
127
mem_init(void)128 void __init mem_init(void)
129 {
130 int codesize, reservedpages, datasize, initsize;
131 int tmp;
132
133 max_mapnr = num_physpages = MAX_LOW_PFN - START_PFN;
134 high_memory = (void *)__va(MAX_LOW_PFN * PAGE_SIZE);
135
136 /*
137 * Clear the zero-page.
138 * This is not required but we might want to re-use
139 * this very page to pass boot parameters, one day.
140 */
141 memset(empty_zero_page, 0, PAGE_SIZE);
142
143 /* this will put all low memory onto the freelists */
144 totalram_pages += free_all_bootmem();
145 reservedpages = 0;
146 for (tmp = 0; tmp < num_physpages; tmp++)
147 /*
148 * Only count reserved RAM pages
149 */
150 if (PageReserved(mem_map+tmp))
151 reservedpages++;
152 codesize = (unsigned long) &_etext - (unsigned long) &_text;
153 datasize = (unsigned long) &_edata - (unsigned long) &_etext;
154 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
155
156 printk("Memory: %luk/%luk available (%dk kernel code, %dk reserved, %dk data, %dk init)\n",
157 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
158 max_mapnr << (PAGE_SHIFT-10),
159 codesize >> 10,
160 reservedpages << (PAGE_SHIFT-10),
161 datasize >> 10,
162 initsize >> 10);
163 }
164
free_initmem(void)165 void free_initmem(void)
166 {
167 unsigned long addr;
168
169 addr = (unsigned long)(&__init_begin);
170 for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) {
171 ClearPageReserved(mem_map + MAP_NR(addr));
172 set_page_count(mem_map+MAP_NR(addr), 1);
173 free_page(addr);
174 totalram_pages++;
175 }
176 printk ("Freeing unused kernel memory: %ldk freed\n", (&__init_end - &__init_begin) >> 10);
177 }
178
179 #ifdef CONFIG_BLK_DEV_INITRD
free_initrd_mem(unsigned long start,unsigned long end)180 void free_initrd_mem(unsigned long start, unsigned long end)
181 {
182 unsigned long p;
183 for (p = start; p < end; p += PAGE_SIZE) {
184 ClearPageReserved(mem_map + MAP_NR(p));
185 set_page_count(mem_map+MAP_NR(p), 1);
186 free_page(p);
187 totalram_pages++;
188 }
189 printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
190 }
191 #endif
192
si_meminfo(struct sysinfo * val)193 void si_meminfo(struct sysinfo *val)
194 {
195 val->totalram = totalram_pages;
196 val->sharedram = 0;
197 val->freeram = nr_free_pages();
198 val->bufferram = atomic_read(&buffermem_pages);
199 val->totalhigh = totalhigh_pages;
200 val->freehigh = nr_free_highpages();
201 val->mem_unit = PAGE_SIZE;
202 return;
203 }
204