[IA64] show_mem() printk levels
[linux-2.6.22.y-op.git] / arch / ia64 / mm / contig.c
blob537c2f3833ee47bcdfd29a214c61b404d8ac4f61
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 * Copyright (C) 1998-2003 Hewlett-Packard Co
7 * David Mosberger-Tang <davidm@hpl.hp.com>
8 * Stephane Eranian <eranian@hpl.hp.com>
9 * Copyright (C) 2000, Rohit Seth <rohit.seth@intel.com>
10 * Copyright (C) 1999 VA Linux Systems
11 * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
12 * Copyright (C) 2003 Silicon Graphics, Inc. All rights reserved.
14 * Routines used by ia64 machines with contiguous (or virtually contiguous)
15 * memory.
17 #include <linux/bootmem.h>
18 #include <linux/efi.h>
19 #include <linux/mm.h>
20 #include <linux/swap.h>
22 #include <asm/meminit.h>
23 #include <asm/pgalloc.h>
24 #include <asm/pgtable.h>
25 #include <asm/sections.h>
26 #include <asm/mca.h>
28 #ifdef CONFIG_VIRTUAL_MEM_MAP
29 static unsigned long num_dma_physpages;
30 static unsigned long max_gap;
31 #endif
33 /**
34 * show_mem - display a memory statistics summary
36 * Just walks the pages in the system and describes where they're allocated.
38 void
39 show_mem (void)
41 int i, total = 0, reserved = 0;
42 int shared = 0, cached = 0;
44 printk(KERN_INFO "Mem-info:\n");
45 show_free_areas();
47 printk(KERN_INFO "Free swap: %6ldkB\n",
48 nr_swap_pages<<(PAGE_SHIFT-10));
49 i = max_mapnr;
50 for (i = 0; i < max_mapnr; i++) {
51 if (!pfn_valid(i)) {
52 #ifdef CONFIG_VIRTUAL_MEM_MAP
53 if (max_gap < LARGE_GAP)
54 continue;
55 i = vmemmap_find_next_valid_pfn(0, i) - 1;
56 #endif
57 continue;
59 total++;
60 if (PageReserved(mem_map+i))
61 reserved++;
62 else if (PageSwapCache(mem_map+i))
63 cached++;
64 else if (page_count(mem_map + i))
65 shared += page_count(mem_map + i) - 1;
67 printk(KERN_INFO "%d pages of RAM\n", total);
68 printk(KERN_INFO "%d reserved pages\n", reserved);
69 printk(KERN_INFO "%d pages shared\n", shared);
70 printk(KERN_INFO "%d pages swap cached\n", cached);
71 printk(KERN_INFO "%ld pages in page table cache\n",
72 pgtable_quicklist_total_size());
75 /* physical address where the bootmem map is located */
76 unsigned long bootmap_start;
78 /**
79 * find_max_pfn - adjust the maximum page number callback
80 * @start: start of range
81 * @end: end of range
82 * @arg: address of pointer to global max_pfn variable
84 * Passed as a callback function to efi_memmap_walk() to determine the highest
85 * available page frame number in the system.
87 int
88 find_max_pfn (unsigned long start, unsigned long end, void *arg)
90 unsigned long *max_pfnp = arg, pfn;
92 pfn = (PAGE_ALIGN(end - 1) - PAGE_OFFSET) >> PAGE_SHIFT;
93 if (pfn > *max_pfnp)
94 *max_pfnp = pfn;
95 return 0;
98 /**
99 * find_bootmap_location - callback to find a memory area for the bootmap
100 * @start: start of region
101 * @end: end of region
102 * @arg: unused callback data
104 * Find a place to put the bootmap and return its starting address in
105 * bootmap_start. This address must be page-aligned.
107 static int __init
108 find_bootmap_location (unsigned long start, unsigned long end, void *arg)
110 unsigned long needed = *(unsigned long *)arg;
111 unsigned long range_start, range_end, free_start;
112 int i;
114 #if IGNORE_PFN0
115 if (start == PAGE_OFFSET) {
116 start += PAGE_SIZE;
117 if (start >= end)
118 return 0;
120 #endif
122 free_start = PAGE_OFFSET;
124 for (i = 0; i < num_rsvd_regions; i++) {
125 range_start = max(start, free_start);
126 range_end = min(end, rsvd_region[i].start & PAGE_MASK);
128 free_start = PAGE_ALIGN(rsvd_region[i].end);
130 if (range_end <= range_start)
131 continue; /* skip over empty range */
133 if (range_end - range_start >= needed) {
134 bootmap_start = __pa(range_start);
135 return -1; /* done */
138 /* nothing more available in this segment */
139 if (range_end == end)
140 return 0;
142 return 0;
146 * find_memory - setup memory map
148 * Walk the EFI memory map and find usable memory for the system, taking
149 * into account reserved areas.
151 void __init
152 find_memory (void)
154 unsigned long bootmap_size;
156 reserve_memory();
158 /* first find highest page frame number */
159 max_pfn = 0;
160 efi_memmap_walk(find_max_pfn, &max_pfn);
162 /* how many bytes to cover all the pages */
163 bootmap_size = bootmem_bootmap_pages(max_pfn) << PAGE_SHIFT;
165 /* look for a location to hold the bootmap */
166 bootmap_start = ~0UL;
167 efi_memmap_walk(find_bootmap_location, &bootmap_size);
168 if (bootmap_start == ~0UL)
169 panic("Cannot find %ld bytes for bootmap\n", bootmap_size);
171 bootmap_size = init_bootmem(bootmap_start >> PAGE_SHIFT, max_pfn);
173 /* Free all available memory, then mark bootmem-map as being in use. */
174 efi_memmap_walk(filter_rsvd_memory, free_bootmem);
175 reserve_bootmem(bootmap_start, bootmap_size);
177 find_initrd();
180 #ifdef CONFIG_SMP
182 * per_cpu_init - setup per-cpu variables
184 * Allocate and setup per-cpu data areas.
186 void * __cpuinit
187 per_cpu_init (void)
189 void *cpu_data;
190 int cpu;
191 static int first_time=1;
194 * get_free_pages() cannot be used before cpu_init() done. BSP
195 * allocates "NR_CPUS" pages for all CPUs to avoid that AP calls
196 * get_zeroed_page().
198 if (first_time) {
199 first_time=0;
200 cpu_data = __alloc_bootmem(PERCPU_PAGE_SIZE * NR_CPUS,
201 PERCPU_PAGE_SIZE, __pa(MAX_DMA_ADDRESS));
202 for (cpu = 0; cpu < NR_CPUS; cpu++) {
203 memcpy(cpu_data, __phys_per_cpu_start, __per_cpu_end - __per_cpu_start);
204 __per_cpu_offset[cpu] = (char *) cpu_data - __per_cpu_start;
205 cpu_data += PERCPU_PAGE_SIZE;
206 per_cpu(local_per_cpu_offset, cpu) = __per_cpu_offset[cpu];
209 return __per_cpu_start + __per_cpu_offset[smp_processor_id()];
211 #endif /* CONFIG_SMP */
213 static int
214 count_pages (u64 start, u64 end, void *arg)
216 unsigned long *count = arg;
218 *count += (end - start) >> PAGE_SHIFT;
219 return 0;
222 #ifdef CONFIG_VIRTUAL_MEM_MAP
223 static int
224 count_dma_pages (u64 start, u64 end, void *arg)
226 unsigned long *count = arg;
228 if (start < MAX_DMA_ADDRESS)
229 *count += (min(end, MAX_DMA_ADDRESS) - start) >> PAGE_SHIFT;
230 return 0;
232 #endif
235 * Set up the page tables.
238 void __init
239 paging_init (void)
241 unsigned long max_dma;
242 unsigned long zones_size[MAX_NR_ZONES];
243 #ifdef CONFIG_VIRTUAL_MEM_MAP
244 unsigned long zholes_size[MAX_NR_ZONES];
245 #endif
247 /* initialize mem_map[] */
249 memset(zones_size, 0, sizeof(zones_size));
251 num_physpages = 0;
252 efi_memmap_walk(count_pages, &num_physpages);
254 max_dma = virt_to_phys((void *) MAX_DMA_ADDRESS) >> PAGE_SHIFT;
256 #ifdef CONFIG_VIRTUAL_MEM_MAP
257 memset(zholes_size, 0, sizeof(zholes_size));
259 num_dma_physpages = 0;
260 efi_memmap_walk(count_dma_pages, &num_dma_physpages);
262 if (max_low_pfn < max_dma) {
263 zones_size[ZONE_DMA] = max_low_pfn;
264 zholes_size[ZONE_DMA] = max_low_pfn - num_dma_physpages;
265 } else {
266 zones_size[ZONE_DMA] = max_dma;
267 zholes_size[ZONE_DMA] = max_dma - num_dma_physpages;
268 if (num_physpages > num_dma_physpages) {
269 zones_size[ZONE_NORMAL] = max_low_pfn - max_dma;
270 zholes_size[ZONE_NORMAL] =
271 ((max_low_pfn - max_dma) -
272 (num_physpages - num_dma_physpages));
276 efi_memmap_walk(find_largest_hole, (u64 *)&max_gap);
277 if (max_gap < LARGE_GAP) {
278 vmem_map = (struct page *) 0;
279 free_area_init_node(0, NODE_DATA(0), zones_size, 0,
280 zholes_size);
281 } else {
282 unsigned long map_size;
284 /* allocate virtual_mem_map */
286 map_size = PAGE_ALIGN(ALIGN(max_low_pfn, MAX_ORDER_NR_PAGES) *
287 sizeof(struct page));
288 vmalloc_end -= map_size;
289 vmem_map = (struct page *) vmalloc_end;
290 efi_memmap_walk(create_mem_map_page_table, NULL);
292 NODE_DATA(0)->node_mem_map = vmem_map;
293 free_area_init_node(0, NODE_DATA(0), zones_size,
294 0, zholes_size);
296 printk("Virtual mem_map starts at 0x%p\n", mem_map);
298 #else /* !CONFIG_VIRTUAL_MEM_MAP */
299 if (max_low_pfn < max_dma)
300 zones_size[ZONE_DMA] = max_low_pfn;
301 else {
302 zones_size[ZONE_DMA] = max_dma;
303 zones_size[ZONE_NORMAL] = max_low_pfn - max_dma;
305 free_area_init(zones_size);
306 #endif /* !CONFIG_VIRTUAL_MEM_MAP */
307 zero_page_memmap_ptr = virt_to_page(ia64_imva(empty_zero_page));