aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/mm/mem.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/powerpc/mm/mem.c')
-rw-r--r--arch/powerpc/mm/mem.c185
1 files changed, 184 insertions, 1 deletions
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 345db08e5d20..0650de74d0b3 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -45,8 +45,9 @@
45#include <asm/tlb.h> 45#include <asm/tlb.h>
46#include <asm/bootinfo.h> 46#include <asm/bootinfo.h>
47#include <asm/prom.h> 47#include <asm/prom.h>
48#include <asm/lmb.h>
49#include <asm/sections.h>
48 50
49#include "mem_pieces.h"
50#include "mmu_decl.h" 51#include "mmu_decl.h"
51 52
52#ifndef CPU_FTR_COHERENT_ICACHE 53#ifndef CPU_FTR_COHERENT_ICACHE
@@ -54,6 +55,9 @@
54#define CPU_FTR_NOEXECUTE 0 55#define CPU_FTR_NOEXECUTE 0
55#endif 56#endif
56 57
58int init_bootmem_done;
59int mem_init_done;
60
57/* 61/*
58 * This is called by /dev/mem to know if a given address has to 62 * This is called by /dev/mem to know if a given address has to
59 * be mapped non-cacheable or not 63 * be mapped non-cacheable or not
@@ -131,6 +135,185 @@ void show_mem(void)
131} 135}
132 136
133/* 137/*
138 * Initialize the bootmem system and give it all the memory we
139 * have available. If we are using highmem, we only put the
140 * lowmem into the bootmem system.
141 */
142#ifndef CONFIG_NEED_MULTIPLE_NODES
143void __init do_init_bootmem(void)
144{
145 unsigned long i;
146 unsigned long start, bootmap_pages;
147 unsigned long total_pages;
148 int boot_mapsize;
149
150 max_pfn = total_pages = lmb_end_of_DRAM() >> PAGE_SHIFT;
151#ifdef CONFIG_HIGHMEM
152 total_pages = total_lowmem >> PAGE_SHIFT;
153#endif
154
155 /*
156 * Find an area to use for the bootmem bitmap. Calculate the size of
157 * bitmap required as (Total Memory) / PAGE_SIZE / BITS_PER_BYTE.
158 * Add 1 additional page in case the address isn't page-aligned.
159 */
160 bootmap_pages = bootmem_bootmap_pages(total_pages);
161
162 start = lmb_alloc(bootmap_pages << PAGE_SHIFT, PAGE_SIZE);
163 BUG_ON(!start);
164
165 boot_mapsize = init_bootmem(start >> PAGE_SHIFT, total_pages);
166
167 /* Add all physical memory to the bootmem map, mark each area
168 * present.
169 */
170 for (i = 0; i < lmb.memory.cnt; i++) {
171 unsigned long base = lmb.memory.region[i].base;
172 unsigned long size = lmb_size_bytes(&lmb.memory, i);
173#ifdef CONFIG_HIGHMEM
174 if (base >= total_lowmem)
175 continue;
176 if (base + size > total_lowmem)
177 size = total_lowmem - base;
178#endif
179 free_bootmem(base, size);
180 }
181
182 /* reserve the sections we're already using */
183 for (i = 0; i < lmb.reserved.cnt; i++)
184 reserve_bootmem(lmb.reserved.region[i].base,
185 lmb_size_bytes(&lmb.reserved, i));
186
187 /* XXX need to clip this if using highmem? */
188 for (i = 0; i < lmb.memory.cnt; i++)
189 memory_present(0, lmb_start_pfn(&lmb.memory, i),
190 lmb_end_pfn(&lmb.memory, i));
191 init_bootmem_done = 1;
192}
193
194/*
195 * paging_init() sets up the page tables - in fact we've already done this.
196 */
197void __init paging_init(void)
198{
199 unsigned long zones_size[MAX_NR_ZONES];
200 unsigned long zholes_size[MAX_NR_ZONES];
201 unsigned long total_ram = lmb_phys_mem_size();
202 unsigned long top_of_ram = lmb_end_of_DRAM();
203
204#ifdef CONFIG_HIGHMEM
205 map_page(PKMAP_BASE, 0, 0); /* XXX gross */
206 pkmap_page_table = pte_offset_kernel(pmd_offset(pgd_offset_k
207 (PKMAP_BASE), PKMAP_BASE), PKMAP_BASE);
208 map_page(KMAP_FIX_BEGIN, 0, 0); /* XXX gross */
209 kmap_pte = pte_offset_kernel(pmd_offset(pgd_offset_k
210 (KMAP_FIX_BEGIN), KMAP_FIX_BEGIN), KMAP_FIX_BEGIN);
211 kmap_prot = PAGE_KERNEL;
212#endif /* CONFIG_HIGHMEM */
213
214 printk(KERN_INFO "Top of RAM: 0x%lx, Total RAM: 0x%lx\n",
215 top_of_ram, total_ram);
216 printk(KERN_INFO "Memory hole size: %ldMB\n",
217 (top_of_ram - total_ram) >> 20);
218 /*
219 * All pages are DMA-able so we put them all in the DMA zone.
220 */
221 memset(zones_size, 0, sizeof(zones_size));
222 memset(zholes_size, 0, sizeof(zholes_size));
223
224 zones_size[ZONE_DMA] = top_of_ram >> PAGE_SHIFT;
225 zholes_size[ZONE_DMA] = (top_of_ram - total_ram) >> PAGE_SHIFT;
226
227#ifdef CONFIG_HIGHMEM
228 zones_size[ZONE_DMA] = total_lowmem >> PAGE_SHIFT;
229 zones_size[ZONE_HIGHMEM] = (total_memory - total_lowmem) >> PAGE_SHIFT;
230 zholes_size[ZONE_HIGHMEM] = (top_of_ram - total_ram) >> PAGE_SHIFT;
231#else
232 zones_size[ZONE_DMA] = top_of_ram >> PAGE_SHIFT;
233 zholes_size[ZONE_DMA] = (top_of_ram - total_ram) >> PAGE_SHIFT;
234#endif /* CONFIG_HIGHMEM */
235
236 free_area_init_node(0, NODE_DATA(0), zones_size,
237 __pa(PAGE_OFFSET) >> PAGE_SHIFT, zholes_size);
238}
239#endif /* ! CONFIG_NEED_MULTIPLE_NODES */
240
241void __init mem_init(void)
242{
243#ifdef CONFIG_NEED_MULTIPLE_NODES
244 int nid;
245#endif
246 pg_data_t *pgdat;
247 unsigned long i;
248 struct page *page;
249 unsigned long reservedpages = 0, codesize, initsize, datasize, bsssize;
250
251 num_physpages = max_pfn; /* RAM is assumed contiguous */
252 high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
253
254#ifdef CONFIG_NEED_MULTIPLE_NODES
255 for_each_online_node(nid) {
256 if (NODE_DATA(nid)->node_spanned_pages != 0) {
257 printk("freeing bootmem node %x\n", nid);
258 totalram_pages +=
259 free_all_bootmem_node(NODE_DATA(nid));
260 }
261 }
262#else
263 max_mapnr = num_physpages;
264 totalram_pages += free_all_bootmem();
265#endif
266 for_each_pgdat(pgdat) {
267 for (i = 0; i < pgdat->node_spanned_pages; i++) {
268 page = pgdat_page_nr(pgdat, i);
269 if (PageReserved(page))
270 reservedpages++;
271 }
272 }
273
274 codesize = (unsigned long)&_sdata - (unsigned long)&_stext;
275 datasize = (unsigned long)&__init_begin - (unsigned long)&_sdata;
276 initsize = (unsigned long)&__init_end - (unsigned long)&__init_begin;
277 bsssize = (unsigned long)&__bss_stop - (unsigned long)&__bss_start;
278
279#ifdef CONFIG_HIGHMEM
280 {
281 unsigned long pfn, highmem_mapnr;
282
283 highmem_mapnr = total_lowmem >> PAGE_SHIFT;
284 for (pfn = highmem_mapnr; pfn < max_mapnr; ++pfn) {
285 struct page *page = pfn_to_page(pfn);
286
287 ClearPageReserved(page);
288 set_page_count(page, 1);
289 __free_page(page);
290 totalhigh_pages++;
291 }
292 totalram_pages += totalhigh_pages;
293 printk(KERN_INFO "High memory: %luk\n",
294 totalhigh_pages << (PAGE_SHIFT-10));
295 }
296#endif /* CONFIG_HIGHMEM */
297
298 printk(KERN_INFO "Memory: %luk/%luk available (%luk kernel code, "
299 "%luk reserved, %luk data, %luk bss, %luk init)\n",
300 (unsigned long)nr_free_pages() << (PAGE_SHIFT-10),
301 num_physpages << (PAGE_SHIFT-10),
302 codesize >> 10,
303 reservedpages << (PAGE_SHIFT-10),
304 datasize >> 10,
305 bsssize >> 10,
306 initsize >> 10);
307
308 mem_init_done = 1;
309
310#ifdef CONFIG_PPC64
311 /* Initialize the vDSO */
312 vdso_init();
313#endif
314}
315
316/*
134 * This is called when a page has been modified by the kernel. 317 * This is called when a page has been modified by the kernel.
135 * It just marks the page as not i-cache clean. We do the i-cache 318 * It just marks the page as not i-cache clean. We do the i-cache
136 * flush later when the page is given to a user process, if necessary. 319 * flush later when the page is given to a user process, if necessary.