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
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)
17 #include <linux/efi.h>
18 #include <linux/memblock.h>
20 #include <linux/nmi.h>
21 #include <linux/swap.h>
23 #include <asm/meminit.h>
24 #include <asm/pgalloc.h>
25 #include <asm/sections.h>
28 #ifdef CONFIG_VIRTUAL_MEM_MAP
29 static unsigned long max_gap;
32 /* physical address where the bootmem map is located */
33 unsigned long bootmap_start;
36 static void *cpu_data;
38 * per_cpu_init - setup per-cpu variables
40 * Allocate and setup per-cpu data areas.
42 void *per_cpu_init(void)
44 static bool first_time = true;
45 void *cpu0_data = __cpu0_per_cpu;
53 * get_free_pages() cannot be used before cpu_init() done.
54 * BSP allocates PERCPU_PAGE_SIZE bytes for all possible CPUs
55 * to avoid that AP calls get_zeroed_page().
57 for_each_possible_cpu(cpu) {
58 void *src = cpu == 0 ? cpu0_data : __phys_per_cpu_start;
60 memcpy(cpu_data, src, __per_cpu_end - __per_cpu_start);
61 __per_cpu_offset[cpu] = (char *)cpu_data - __per_cpu_start;
62 per_cpu(local_per_cpu_offset, cpu) = __per_cpu_offset[cpu];
65 * percpu area for cpu0 is moved from the __init area
66 * which is setup by head.S and used till this point.
67 * Update ar.k3. This move is ensures that percpu
68 * area for cpu0 is on the correct node and its
69 * virtual address isn't insanely far from other
70 * percpu areas which is important for congruent
74 ia64_set_kr(IA64_KR_PER_CPU_DATA, __pa(cpu_data) -
75 (unsigned long)__per_cpu_start);
77 cpu_data += PERCPU_PAGE_SIZE;
80 return __per_cpu_start + __per_cpu_offset[smp_processor_id()];
84 alloc_per_cpu_data(void)
86 size_t size = PERCPU_PAGE_SIZE * num_possible_cpus();
88 cpu_data = memblock_alloc_from(size, PERCPU_PAGE_SIZE,
89 __pa(MAX_DMA_ADDRESS));
91 panic("%s: Failed to allocate %lu bytes align=%lx from=%lx\n",
92 __func__, size, PERCPU_PAGE_SIZE, __pa(MAX_DMA_ADDRESS));
96 * setup_per_cpu_areas - setup percpu areas
98 * Arch code has already allocated and initialized percpu areas. All
99 * this function has to do is to teach the determined layout to the
100 * dynamic percpu allocator, which happens to be more complex than
101 * creating whole new ones using helpers.
104 setup_per_cpu_areas(void)
106 struct pcpu_alloc_info *ai;
107 struct pcpu_group_info *gi;
109 ssize_t static_size, reserved_size, dyn_size;
111 ai = pcpu_alloc_alloc_info(1, num_possible_cpus());
113 panic("failed to allocate pcpu_alloc_info");
116 /* units are assigned consecutively to possible cpus */
117 for_each_possible_cpu(cpu)
118 gi->cpu_map[gi->nr_units++] = cpu;
121 static_size = __per_cpu_end - __per_cpu_start;
122 reserved_size = PERCPU_MODULE_RESERVE;
123 dyn_size = PERCPU_PAGE_SIZE - static_size - reserved_size;
125 panic("percpu area overflow static=%zd reserved=%zd\n",
126 static_size, reserved_size);
128 ai->static_size = static_size;
129 ai->reserved_size = reserved_size;
130 ai->dyn_size = dyn_size;
131 ai->unit_size = PERCPU_PAGE_SIZE;
132 ai->atom_size = PAGE_SIZE;
133 ai->alloc_size = PERCPU_PAGE_SIZE;
135 pcpu_setup_first_chunk(ai, __per_cpu_start + __per_cpu_offset[0]);
136 pcpu_free_alloc_info(ai);
139 #define alloc_per_cpu_data() do { } while (0)
140 #endif /* CONFIG_SMP */
143 * find_memory - setup memory map
145 * Walk the EFI memory map and find usable memory for the system, taking
146 * into account reserved areas.
153 /* first find highest page frame number */
156 efi_memmap_walk(find_max_min_low_pfn, NULL);
157 max_pfn = max_low_pfn;
159 #ifdef CONFIG_VIRTUAL_MEM_MAP
160 efi_memmap_walk(filter_memory, register_active_ranges);
162 memblock_add_node(0, PFN_PHYS(max_low_pfn), 0);
167 alloc_per_cpu_data();
171 * Set up the page tables.
177 unsigned long max_dma;
178 unsigned long max_zone_pfns[MAX_NR_ZONES];
180 memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
181 #ifdef CONFIG_ZONE_DMA32
182 max_dma = virt_to_phys((void *) MAX_DMA_ADDRESS) >> PAGE_SHIFT;
183 max_zone_pfns[ZONE_DMA32] = max_dma;
185 max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
187 #ifdef CONFIG_VIRTUAL_MEM_MAP
188 efi_memmap_walk(find_largest_hole, (u64 *)&max_gap);
189 if (max_gap < LARGE_GAP) {
190 vmem_map = (struct page *) 0;
192 unsigned long map_size;
194 /* allocate virtual_mem_map */
196 map_size = PAGE_ALIGN(ALIGN(max_low_pfn, MAX_ORDER_NR_PAGES) *
197 sizeof(struct page));
198 VMALLOC_END -= map_size;
199 vmem_map = (struct page *) VMALLOC_END;
200 efi_memmap_walk(create_mem_map_page_table, NULL);
203 * alloc_node_mem_map makes an adjustment for mem_map
204 * which isn't compatible with vmem_map.
206 NODE_DATA(0)->node_mem_map = vmem_map +
207 find_min_pfn_with_active_regions();
209 printk("Virtual mem_map starts at 0x%p\n", mem_map);
211 #endif /* !CONFIG_VIRTUAL_MEM_MAP */
212 free_area_init(max_zone_pfns);
213 zero_page_memmap_ptr = virt_to_page(ia64_imva(empty_zero_page));