ia64/xen-unstable

view xen/arch/ia64/linux-xen/mm_contig.c @ 9770:ced37bea0647

[IA64] FPH enabling + cleanup

Move contents of switch_to macro from xensystem.h to context_switch function.
Initialize FPU on all processors. FPH is always enabled in Xen.
Speed up context-switch (a little bit!) by not enabling/disabling FPH.
Cleanup (unused function/variablesi/fields, debug printf...)
vmx_ia64_switch_to removed (was unused).

Signed-off-by: Tristan Gingold <tristan.gingold@bull.net>
author awilliam@xenbuild.aw
date Tue Apr 25 22:35:41 2006 -0600 (2006-04-25)
parents 0c94043f5c5b
children fd1d742487f8
line source
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 * 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.
13 *
14 * Routines used by ia64 machines with contiguous (or virtually contiguous)
15 * memory.
16 */
17 #include <linux/config.h>
18 #include <linux/bootmem.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 #include <linux/efi.h>
29 #ifdef CONFIG_VIRTUAL_MEM_MAP
30 static unsigned long num_dma_physpages;
31 #endif
33 /**
34 * show_mem - display a memory statistics summary
35 *
36 * Just walks the pages in the system and describes where they're allocated.
37 */
38 #ifndef XEN
39 void
40 show_mem (void)
41 {
42 int i, total = 0, reserved = 0;
43 int shared = 0, cached = 0;
45 printk("Mem-info:\n");
46 show_free_areas();
48 printk("Free swap: %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10));
49 i = max_mapnr;
50 while (i-- > 0) {
51 if (!mfn_valid(i))
52 continue;
53 total++;
54 if (PageReserved(mem_map+i))
55 reserved++;
56 else if (PageSwapCache(mem_map+i))
57 cached++;
58 else if (page_count(mem_map + i))
59 shared += page_count(mem_map + i) - 1;
60 }
61 printk("%d pages of RAM\n", total);
62 printk("%d reserved pages\n", reserved);
63 printk("%d pages shared\n", shared);
64 printk("%d pages swap cached\n", cached);
65 printk("%ld pages in page table cache\n",
66 pgtable_quicklist_total_size());
67 }
68 #endif
70 /* physical address where the bootmem map is located */
71 unsigned long bootmap_start;
73 /**
74 * find_max_pfn - adjust the maximum page number callback
75 * @start: start of range
76 * @end: end of range
77 * @arg: address of pointer to global max_pfn variable
78 *
79 * Passed as a callback function to efi_memmap_walk() to determine the highest
80 * available page frame number in the system.
81 */
82 int
83 find_max_pfn (unsigned long start, unsigned long end, void *arg)
84 {
85 unsigned long *max_pfnp = arg, pfn;
87 pfn = (PAGE_ALIGN(end - 1) - PAGE_OFFSET) >> PAGE_SHIFT;
88 if (pfn > *max_pfnp)
89 *max_pfnp = pfn;
90 return 0;
91 }
93 /**
94 * find_bootmap_location - callback to find a memory area for the bootmap
95 * @start: start of region
96 * @end: end of region
97 * @arg: unused callback data
98 *
99 * Find a place to put the bootmap and return its starting address in
100 * bootmap_start. This address must be page-aligned.
101 */
102 int
103 find_bootmap_location (unsigned long start, unsigned long end, void *arg)
104 {
105 unsigned long needed = *(unsigned long *)arg;
106 unsigned long range_start, range_end, free_start;
107 int i;
109 #if IGNORE_PFN0
110 if (start == PAGE_OFFSET) {
111 start += PAGE_SIZE;
112 if (start >= end)
113 return 0;
114 }
115 #endif
117 free_start = PAGE_OFFSET;
119 for (i = 0; i < num_rsvd_regions; i++) {
120 range_start = max(start, free_start);
121 range_end = min(end, rsvd_region[i].start & PAGE_MASK);
123 free_start = PAGE_ALIGN(rsvd_region[i].end);
125 if (range_end <= range_start)
126 continue; /* skip over empty range */
128 if (range_end - range_start >= needed) {
129 bootmap_start = __pa(range_start);
130 return -1; /* done */
131 }
133 /* nothing more available in this segment */
134 if (range_end == end)
135 return 0;
136 }
137 return 0;
138 }
140 /**
141 * find_memory - setup memory map
142 *
143 * Walk the EFI memory map and find usable memory for the system, taking
144 * into account reserved areas.
145 */
146 #ifndef XEN
147 void
148 find_memory (void)
149 {
150 unsigned long bootmap_size;
152 reserve_memory();
154 /* first find highest page frame number */
155 max_pfn = 0;
156 efi_memmap_walk(find_max_pfn, &max_pfn);
158 /* how many bytes to cover all the pages */
159 bootmap_size = bootmem_bootmap_pages(max_pfn) << PAGE_SHIFT;
161 /* look for a location to hold the bootmap */
162 bootmap_start = ~0UL;
163 efi_memmap_walk(find_bootmap_location, &bootmap_size);
164 if (bootmap_start == ~0UL)
165 panic("Cannot find %ld bytes for bootmap\n", bootmap_size);
167 bootmap_size = init_bootmem(bootmap_start >> PAGE_SHIFT, max_pfn);
169 /* Free all available memory, then mark bootmem-map as being in use. */
170 efi_memmap_walk(filter_rsvd_memory, free_bootmem);
171 reserve_bootmem(bootmap_start, bootmap_size);
173 find_initrd();
174 }
175 #endif
177 #ifdef CONFIG_SMP
178 /**
179 * per_cpu_init - setup per-cpu variables
180 *
181 * Allocate and setup per-cpu data areas.
182 */
183 void *
184 per_cpu_init (void)
185 {
186 void *cpu_data;
187 int cpu;
189 /*
190 * get_free_pages() cannot be used before cpu_init() done. BSP
191 * allocates "NR_CPUS" pages for all CPUs to avoid that AP calls
192 * get_zeroed_page().
193 */
194 if (smp_processor_id() == 0) {
195 #ifdef XEN
196 cpu_data = alloc_xenheap_pages(get_order(NR_CPUS
197 * PERCPU_PAGE_SIZE));
198 #else
199 cpu_data = __alloc_bootmem(PERCPU_PAGE_SIZE * NR_CPUS,
200 PERCPU_PAGE_SIZE, __pa(MAX_DMA_ADDRESS));
201 #endif
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];
207 }
208 }
209 return __per_cpu_start + __per_cpu_offset[smp_processor_id()];
210 }
211 #endif /* CONFIG_SMP */
213 #ifndef XEN
214 static int
215 count_pages (u64 start, u64 end, void *arg)
216 {
217 unsigned long *count = arg;
219 *count += (end - start) >> PAGE_SHIFT;
220 return 0;
221 }
223 #ifdef CONFIG_VIRTUAL_MEM_MAP
224 static int
225 count_dma_pages (u64 start, u64 end, void *arg)
226 {
227 unsigned long *count = arg;
229 if (start < MAX_DMA_ADDRESS)
230 *count += (min(end, MAX_DMA_ADDRESS) - start) >> PAGE_SHIFT;
231 return 0;
232 }
233 #endif
235 /*
236 * Set up the page tables.
237 */
239 void
240 paging_init (void)
241 {
242 unsigned long max_dma;
243 unsigned long zones_size[MAX_NR_ZONES];
244 #ifdef CONFIG_VIRTUAL_MEM_MAP
245 unsigned long zholes_size[MAX_NR_ZONES];
246 unsigned long max_gap;
247 #endif
249 /* initialize mem_map[] */
251 memset(zones_size, 0, sizeof(zones_size));
253 num_physpages = 0;
254 efi_memmap_walk(count_pages, &num_physpages);
256 max_dma = virt_to_maddr((void *) MAX_DMA_ADDRESS) >> PAGE_SHIFT;
258 #ifdef CONFIG_VIRTUAL_MEM_MAP
259 memset(zholes_size, 0, sizeof(zholes_size));
261 num_dma_physpages = 0;
262 efi_memmap_walk(count_dma_pages, &num_dma_physpages);
264 if (max_low_pfn < max_dma) {
265 zones_size[ZONE_DMA] = max_low_pfn;
266 zholes_size[ZONE_DMA] = max_low_pfn - num_dma_physpages;
267 } else {
268 zones_size[ZONE_DMA] = max_dma;
269 zholes_size[ZONE_DMA] = max_dma - num_dma_physpages;
270 if (num_physpages > num_dma_physpages) {
271 zones_size[ZONE_NORMAL] = max_low_pfn - max_dma;
272 zholes_size[ZONE_NORMAL] =
273 ((max_low_pfn - max_dma) -
274 (num_physpages - num_dma_physpages));
275 }
276 }
278 max_gap = 0;
279 efi_memmap_walk(find_largest_hole, (u64 *)&max_gap);
280 if (max_gap < LARGE_GAP) {
281 vmem_map = (struct page *) 0;
282 free_area_init_node(0, &contig_page_data, zones_size, 0,
283 zholes_size);
284 } else {
285 unsigned long map_size;
287 /* allocate virtual_mem_map */
289 map_size = PAGE_ALIGN(max_low_pfn * sizeof(struct page));
290 vmalloc_end -= map_size;
291 vmem_map = (struct page *) vmalloc_end;
292 efi_memmap_walk(create_mem_map_page_table, NULL);
294 NODE_DATA(0)->node_mem_map = vmem_map;
295 free_area_init_node(0, &contig_page_data, zones_size,
296 0, zholes_size);
298 printk("Virtual mem_map starts at 0x%p\n", mem_map);
299 }
300 #else /* !CONFIG_VIRTUAL_MEM_MAP */
301 if (max_low_pfn < max_dma)
302 zones_size[ZONE_DMA] = max_low_pfn;
303 else {
304 zones_size[ZONE_DMA] = max_dma;
305 zones_size[ZONE_NORMAL] = max_low_pfn - max_dma;
306 }
307 free_area_init(zones_size);
308 #endif /* !CONFIG_VIRTUAL_MEM_MAP */
309 zero_page_memmap_ptr = virt_to_page(ia64_imva(empty_zero_page));
310 }
311 #endif