Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Generic VM initialization for x86-64 NUMA setups. |
| 3 | * Copyright 2002,2003 Andi Kleen, SuSE Labs. |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 4 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #include <linux/kernel.h> |
| 6 | #include <linux/mm.h> |
| 7 | #include <linux/string.h> |
| 8 | #include <linux/init.h> |
| 9 | #include <linux/bootmem.h> |
Yinghai Lu | 72d7c3b | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 10 | #include <linux/memblock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/mmzone.h> |
| 12 | #include <linux/ctype.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/nodemask.h> |
travis@sgi.com | 3cc87e3 | 2008-01-30 13:33:11 +0100 | [diff] [blame] | 15 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | #include <asm/e820.h> |
| 18 | #include <asm/proto.h> |
| 19 | #include <asm/dma.h> |
| 20 | #include <asm/numa.h> |
| 21 | #include <asm/acpi.h> |
Andreas Herrmann | 23ac4ae | 2010-09-17 18:03:43 +0200 | [diff] [blame] | 22 | #include <asm/amd_nb.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Ravikiran G Thirumalai | 6c231b7 | 2005-09-06 15:17:45 -0700 | [diff] [blame] | 24 | struct pglist_data *node_data[MAX_NUMNODES] __read_mostly; |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 25 | EXPORT_SYMBOL(node_data); |
| 26 | |
Eric Dumazet | dcf36bf | 2006-03-25 16:31:46 +0100 | [diff] [blame] | 27 | struct memnode memnode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Thomas Gleixner | 864fc31 | 2008-05-12 15:43:36 +0200 | [diff] [blame] | 29 | static unsigned long __initdata nodemap_addr; |
| 30 | static unsigned long __initdata nodemap_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Brian Gerst | 6470aff | 2009-01-27 12:56:47 +0900 | [diff] [blame] | 32 | /* |
Eric Dumazet | 529a340 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 33 | * Given a shift value, try to populate memnodemap[] |
| 34 | * Returns : |
| 35 | * 1 if OK |
| 36 | * 0 if memnodmap[] too small (of shift too small) |
| 37 | * -1 if node overlap or lost ram (shift too big) |
| 38 | */ |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 39 | static int __init populate_memnodemap(const struct bootnode *nodes, |
Suresh Siddha | 6ec6e0d | 2008-03-25 10:14:35 -0700 | [diff] [blame] | 40 | int numnodes, int shift, int *nodeids) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | { |
Eric Dumazet | 529a340 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 42 | unsigned long addr, end; |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 43 | int i, res = -1; |
Keith Mannthey | b684664 | 2005-07-28 21:15:38 -0700 | [diff] [blame] | 44 | |
travis@sgi.com | 4323838 | 2008-01-30 13:33:25 +0100 | [diff] [blame] | 45 | memset(memnodemap, 0xff, sizeof(s16)*memnodemapsize); |
Eric Dumazet | 529a340 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 46 | for (i = 0; i < numnodes; i++) { |
| 47 | addr = nodes[i].start; |
| 48 | end = nodes[i].end; |
| 49 | if (addr >= end) |
| 50 | continue; |
Amul Shah | 076422d | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 51 | if ((end >> shift) >= memnodemapsize) |
Eric Dumazet | 529a340 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 52 | return 0; |
| 53 | do { |
travis@sgi.com | 4323838 | 2008-01-30 13:33:25 +0100 | [diff] [blame] | 54 | if (memnodemap[addr >> shift] != NUMA_NO_NODE) |
Eric Dumazet | 529a340 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 55 | return -1; |
Suresh Siddha | 6ec6e0d | 2008-03-25 10:14:35 -0700 | [diff] [blame] | 56 | |
| 57 | if (!nodeids) |
| 58 | memnodemap[addr >> shift] = i; |
| 59 | else |
| 60 | memnodemap[addr >> shift] = nodeids[i]; |
| 61 | |
Amul Shah | 076422d | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 62 | addr += (1UL << shift); |
Eric Dumazet | 529a340 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 63 | } while (addr < end); |
| 64 | res = 1; |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 65 | } |
Eric Dumazet | 529a340 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 66 | return res; |
| 67 | } |
| 68 | |
Amul Shah | 076422d | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 69 | static int __init allocate_cachealigned_memnodemap(void) |
| 70 | { |
Yinghai Lu | 24a5da7 | 2008-02-01 17:49:41 +0100 | [diff] [blame] | 71 | unsigned long addr; |
Amul Shah | 076422d | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 72 | |
| 73 | memnodemap = memnode.embedded_map; |
travis@sgi.com | 316390b | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 74 | if (memnodemapsize <= ARRAY_SIZE(memnode.embedded_map)) |
Amul Shah | 076422d | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 75 | return 0; |
Amul Shah | 076422d | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 76 | |
Yinghai Lu | 24a5da7 | 2008-02-01 17:49:41 +0100 | [diff] [blame] | 77 | addr = 0x8000; |
Joerg Roedel | be3e89e | 2008-07-25 16:48:58 +0200 | [diff] [blame] | 78 | nodemap_size = roundup(sizeof(s16) * memnodemapsize, L1_CACHE_BYTES); |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 79 | nodemap_addr = memblock_find_in_range(addr, max_pfn<<PAGE_SHIFT, |
Yinghai Lu | 24a5da7 | 2008-02-01 17:49:41 +0100 | [diff] [blame] | 80 | nodemap_size, L1_CACHE_BYTES); |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 81 | if (nodemap_addr == MEMBLOCK_ERROR) { |
Amul Shah | 076422d | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 82 | printk(KERN_ERR |
| 83 | "NUMA: Unable to allocate Memory to Node hash map\n"); |
| 84 | nodemap_addr = nodemap_size = 0; |
| 85 | return -1; |
| 86 | } |
Yinghai Lu | 24a5da7 | 2008-02-01 17:49:41 +0100 | [diff] [blame] | 87 | memnodemap = phys_to_virt(nodemap_addr); |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 88 | memblock_x86_reserve_range(nodemap_addr, nodemap_addr + nodemap_size, "MEMNODEMAP"); |
Amul Shah | 076422d | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 89 | |
| 90 | printk(KERN_DEBUG "NUMA: Allocated memnodemap from %lx - %lx\n", |
| 91 | nodemap_addr, nodemap_addr + nodemap_size); |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | /* |
| 96 | * The LSB of all start and end addresses in the node map is the value of the |
| 97 | * maximum possible shift. |
| 98 | */ |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 99 | static int __init extract_lsb_from_nodes(const struct bootnode *nodes, |
| 100 | int numnodes) |
Amul Shah | 076422d | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 101 | { |
Amul Shah | 5441392 | 2007-02-13 13:26:20 +0100 | [diff] [blame] | 102 | int i, nodes_used = 0; |
Amul Shah | 076422d | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 103 | unsigned long start, end; |
| 104 | unsigned long bitfield = 0, memtop = 0; |
| 105 | |
| 106 | for (i = 0; i < numnodes; i++) { |
| 107 | start = nodes[i].start; |
| 108 | end = nodes[i].end; |
| 109 | if (start >= end) |
| 110 | continue; |
Amul Shah | 5441392 | 2007-02-13 13:26:20 +0100 | [diff] [blame] | 111 | bitfield |= start; |
| 112 | nodes_used++; |
Amul Shah | 076422d | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 113 | if (end > memtop) |
| 114 | memtop = end; |
| 115 | } |
Amul Shah | 5441392 | 2007-02-13 13:26:20 +0100 | [diff] [blame] | 116 | if (nodes_used <= 1) |
| 117 | i = 63; |
| 118 | else |
| 119 | i = find_first_bit(&bitfield, sizeof(unsigned long)*8); |
Amul Shah | 076422d | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 120 | memnodemapsize = (memtop >> i)+1; |
| 121 | return i; |
| 122 | } |
| 123 | |
Suresh Siddha | 6ec6e0d | 2008-03-25 10:14:35 -0700 | [diff] [blame] | 124 | int __init compute_hash_shift(struct bootnode *nodes, int numnodes, |
| 125 | int *nodeids) |
Eric Dumazet | 529a340 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 126 | { |
Amul Shah | 076422d | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 127 | int shift; |
Eric Dumazet | 529a340 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 128 | |
Amul Shah | 076422d | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 129 | shift = extract_lsb_from_nodes(nodes, numnodes); |
| 130 | if (allocate_cachealigned_memnodemap()) |
| 131 | return -1; |
Andi Kleen | 6b050f8 | 2006-01-11 22:44:33 +0100 | [diff] [blame] | 132 | printk(KERN_DEBUG "NUMA: Using %d for the hash shift.\n", |
Eric Dumazet | 529a340 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 133 | shift); |
| 134 | |
Suresh Siddha | 6ec6e0d | 2008-03-25 10:14:35 -0700 | [diff] [blame] | 135 | if (populate_memnodemap(nodes, numnodes, shift, nodeids) != 1) { |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 136 | printk(KERN_INFO "Your memory is not aligned you need to " |
| 137 | "rebuild your kernel with a bigger NODEMAPSIZE " |
| 138 | "shift=%d\n", shift); |
Eric Dumazet | 529a340 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 139 | return -1; |
| 140 | } |
Keith Mannthey | b684664 | 2005-07-28 21:15:38 -0700 | [diff] [blame] | 141 | return shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | } |
| 143 | |
KAMEZAWA Hiroyuki | f2dbcfa | 2009-02-18 14:48:32 -0800 | [diff] [blame] | 144 | int __meminit __early_pfn_to_nid(unsigned long pfn) |
Matt Tolentino | bbfceef | 2005-06-23 00:08:07 -0700 | [diff] [blame] | 145 | { |
| 146 | return phys_to_nid(pfn << PAGE_SHIFT); |
| 147 | } |
Matt Tolentino | bbfceef | 2005-06-23 00:08:07 -0700 | [diff] [blame] | 148 | |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 149 | static void * __init early_node_mem(int nodeid, unsigned long start, |
Yinghai Lu | 24a5da7 | 2008-02-01 17:49:41 +0100 | [diff] [blame] | 150 | unsigned long end, unsigned long size, |
| 151 | unsigned long align) |
Andi Kleen | a806223 | 2006-04-07 19:49:21 +0200 | [diff] [blame] | 152 | { |
Yinghai Lu | cef625e | 2010-02-10 01:20:18 -0800 | [diff] [blame] | 153 | unsigned long mem; |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 154 | |
Yinghai Lu | cef625e | 2010-02-10 01:20:18 -0800 | [diff] [blame] | 155 | /* |
| 156 | * put it on high as possible |
| 157 | * something will go with NODE_DATA |
| 158 | */ |
| 159 | if (start < (MAX_DMA_PFN<<PAGE_SHIFT)) |
| 160 | start = MAX_DMA_PFN<<PAGE_SHIFT; |
| 161 | if (start < (MAX_DMA32_PFN<<PAGE_SHIFT) && |
| 162 | end > (MAX_DMA32_PFN<<PAGE_SHIFT)) |
| 163 | start = MAX_DMA32_PFN<<PAGE_SHIFT; |
Yinghai Lu | 72d7c3b | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 164 | mem = memblock_x86_find_in_range_node(nodeid, start, end, size, align); |
| 165 | if (mem != MEMBLOCK_ERROR) |
Andi Kleen | a806223 | 2006-04-07 19:49:21 +0200 | [diff] [blame] | 166 | return __va(mem); |
Yinghai Lu | 9347e0b | 2008-02-01 17:49:42 +0100 | [diff] [blame] | 167 | |
Yinghai Lu | cef625e | 2010-02-10 01:20:18 -0800 | [diff] [blame] | 168 | /* extend the search scope */ |
| 169 | end = max_pfn_mapped << PAGE_SHIFT; |
Yinghai Lu | 419db27 | 2010-10-28 09:50:17 -0700 | [diff] [blame] | 170 | start = MAX_DMA_PFN << PAGE_SHIFT; |
| 171 | mem = memblock_find_in_range(start, end, size, align); |
Yinghai Lu | 72d7c3b | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 172 | if (mem != MEMBLOCK_ERROR) |
Yinghai Lu | 1842f90 | 2010-02-10 01:20:15 -0800 | [diff] [blame] | 173 | return __va(mem); |
| 174 | |
| 175 | printk(KERN_ERR "Cannot find %lu bytes in node %d\n", |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 176 | size, nodeid); |
Yinghai Lu | 1842f90 | 2010-02-10 01:20:15 -0800 | [diff] [blame] | 177 | |
| 178 | return NULL; |
Andi Kleen | a806223 | 2006-04-07 19:49:21 +0200 | [diff] [blame] | 179 | } |
| 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | /* Initialize bootmem allocator for a node */ |
Yinghai Lu | 7c43769 | 2009-05-15 13:59:37 -0700 | [diff] [blame] | 182 | void __init |
| 183 | setup_node_bootmem(int nodeid, unsigned long start, unsigned long end) |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 184 | { |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 185 | unsigned long start_pfn, last_pfn, nodedata_phys; |
Yinghai Lu | 7c43769 | 2009-05-15 13:59:37 -0700 | [diff] [blame] | 186 | const int pgdat_size = roundup(sizeof(pg_data_t), PAGE_SIZE); |
Yinghai Lu | 1a27fc0 | 2008-03-18 12:52:37 -0700 | [diff] [blame] | 187 | int nid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
Yinghai Lu | 4c31e92 | 2009-04-22 14:19:27 -0700 | [diff] [blame] | 189 | if (!end) |
| 190 | return; |
| 191 | |
Yinghai Lu | 7c43769 | 2009-05-15 13:59:37 -0700 | [diff] [blame] | 192 | /* |
| 193 | * Don't confuse VM with a node that doesn't have the |
| 194 | * minimum amount of memory: |
| 195 | */ |
| 196 | if (end && (end - start) < NODE_MIN_SIZE) |
| 197 | return; |
| 198 | |
Joerg Roedel | be3e89e | 2008-07-25 16:48:58 +0200 | [diff] [blame] | 199 | start = roundup(start, ZONE_ALIGN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 201 | printk(KERN_INFO "Initmem setup node %d %016lx-%016lx\n", nodeid, |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 202 | start, end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
| 204 | start_pfn = start >> PAGE_SHIFT; |
Thomas Gleixner | 886533a | 2008-05-12 15:43:36 +0200 | [diff] [blame] | 205 | last_pfn = end >> PAGE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
Yinghai Lu | 24a5da7 | 2008-02-01 17:49:41 +0100 | [diff] [blame] | 207 | node_data[nodeid] = early_node_mem(nodeid, start, end, pgdat_size, |
| 208 | SMP_CACHE_BYTES); |
Andi Kleen | a806223 | 2006-04-07 19:49:21 +0200 | [diff] [blame] | 209 | if (node_data[nodeid] == NULL) |
| 210 | return; |
| 211 | nodedata_phys = __pa(node_data[nodeid]); |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 212 | memblock_x86_reserve_range(nodedata_phys, nodedata_phys + pgdat_size, "NODE_DATA"); |
Yinghai Lu | 6118f76 | 2008-02-04 16:47:56 +0100 | [diff] [blame] | 213 | printk(KERN_INFO " NODE_DATA [%016lx - %016lx]\n", nodedata_phys, |
| 214 | nodedata_phys + pgdat_size - 1); |
Yinghai Lu | 1842f90 | 2010-02-10 01:20:15 -0800 | [diff] [blame] | 215 | nid = phys_to_nid(nodedata_phys); |
| 216 | if (nid != nodeid) |
| 217 | printk(KERN_INFO " NODE_DATA(%d) on node %d\n", nodeid, nid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | memset(NODE_DATA(nodeid), 0, sizeof(pg_data_t)); |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 220 | NODE_DATA(nodeid)->node_id = nodeid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | NODE_DATA(nodeid)->node_start_pfn = start_pfn; |
Thomas Gleixner | 886533a | 2008-05-12 15:43:36 +0200 | [diff] [blame] | 222 | NODE_DATA(nodeid)->node_spanned_pages = last_pfn - start_pfn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | node_set_online(nodeid); |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 225 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | #ifdef CONFIG_NUMA_EMU |
Rohit Seth | 53fee04 | 2007-02-13 13:26:22 +0100 | [diff] [blame] | 228 | /* Numa emulation */ |
David Rientjes | adc1938 | 2009-09-25 15:20:09 -0700 | [diff] [blame] | 229 | static struct bootnode nodes[MAX_NUMNODES] __initdata; |
David Rientjes | c1c3443 | 2010-12-22 17:23:54 -0800 | [diff] [blame] | 230 | static struct bootnode physnodes[MAX_NUMNODES] __cpuinitdata; |
Thomas Gleixner | 864fc31 | 2008-05-12 15:43:36 +0200 | [diff] [blame] | 231 | static char *cmdline __initdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
Jan Beulich | 9032160 | 2011-01-19 08:57:21 +0000 | [diff] [blame] | 233 | void __init numa_emu_cmdline(char *str) |
| 234 | { |
| 235 | cmdline = str; |
| 236 | } |
| 237 | |
David Rientjes | adc1938 | 2009-09-25 15:20:09 -0700 | [diff] [blame] | 238 | static int __init setup_physnodes(unsigned long start, unsigned long end, |
Hans Rosenfeld | eec1d4f | 2010-10-29 17:14:30 +0200 | [diff] [blame] | 239 | int acpi, int amd) |
David Rientjes | adc1938 | 2009-09-25 15:20:09 -0700 | [diff] [blame] | 240 | { |
David Rientjes | adc1938 | 2009-09-25 15:20:09 -0700 | [diff] [blame] | 241 | int ret = 0; |
| 242 | int i; |
| 243 | |
David Rientjes | c1c3443 | 2010-12-22 17:23:54 -0800 | [diff] [blame] | 244 | memset(physnodes, 0, sizeof(physnodes)); |
David Rientjes | adc1938 | 2009-09-25 15:20:09 -0700 | [diff] [blame] | 245 | #ifdef CONFIG_ACPI_NUMA |
| 246 | if (acpi) |
David Rientjes | a387e95 | 2010-12-22 17:23:56 -0800 | [diff] [blame] | 247 | acpi_get_nodes(physnodes, start, end); |
David Rientjes | adc1938 | 2009-09-25 15:20:09 -0700 | [diff] [blame] | 248 | #endif |
Hans Rosenfeld | eec1d4f | 2010-10-29 17:14:30 +0200 | [diff] [blame] | 249 | #ifdef CONFIG_AMD_NUMA |
| 250 | if (amd) |
David Rientjes | a387e95 | 2010-12-22 17:23:56 -0800 | [diff] [blame] | 251 | amd_get_nodes(physnodes); |
David Rientjes | adc1938 | 2009-09-25 15:20:09 -0700 | [diff] [blame] | 252 | #endif |
| 253 | /* |
| 254 | * Basic sanity checking on the physical node map: there may be errors |
Hans Rosenfeld | eec1d4f | 2010-10-29 17:14:30 +0200 | [diff] [blame] | 255 | * if the SRAT or AMD code incorrectly reported the topology or the mem= |
David Rientjes | adc1938 | 2009-09-25 15:20:09 -0700 | [diff] [blame] | 256 | * kernel parameter is used. |
| 257 | */ |
David Rientjes | a387e95 | 2010-12-22 17:23:56 -0800 | [diff] [blame] | 258 | for (i = 0; i < MAX_NUMNODES; i++) { |
David Rientjes | adc1938 | 2009-09-25 15:20:09 -0700 | [diff] [blame] | 259 | if (physnodes[i].start == physnodes[i].end) |
| 260 | continue; |
| 261 | if (physnodes[i].start > end) { |
| 262 | physnodes[i].end = physnodes[i].start; |
| 263 | continue; |
| 264 | } |
| 265 | if (physnodes[i].end < start) { |
| 266 | physnodes[i].start = physnodes[i].end; |
| 267 | continue; |
| 268 | } |
| 269 | if (physnodes[i].start < start) |
| 270 | physnodes[i].start = start; |
| 271 | if (physnodes[i].end > end) |
| 272 | physnodes[i].end = end; |
David Rientjes | adc1938 | 2009-09-25 15:20:09 -0700 | [diff] [blame] | 273 | ret++; |
| 274 | } |
| 275 | |
| 276 | /* |
| 277 | * If no physical topology was detected, a single node is faked to cover |
| 278 | * the entire address space. |
| 279 | */ |
| 280 | if (!ret) { |
| 281 | physnodes[ret].start = start; |
| 282 | physnodes[ret].end = end; |
| 283 | ret = 1; |
| 284 | } |
| 285 | return ret; |
| 286 | } |
| 287 | |
David Rientjes | f51bf30 | 2010-12-22 17:23:51 -0800 | [diff] [blame] | 288 | static void __init fake_physnodes(int acpi, int amd, int nr_nodes) |
| 289 | { |
| 290 | int i; |
| 291 | |
| 292 | BUG_ON(acpi && amd); |
| 293 | #ifdef CONFIG_ACPI_NUMA |
| 294 | if (acpi) |
| 295 | acpi_fake_nodes(nodes, nr_nodes); |
| 296 | #endif |
| 297 | #ifdef CONFIG_AMD_NUMA |
| 298 | if (amd) |
| 299 | amd_fake_nodes(nodes, nr_nodes); |
| 300 | #endif |
| 301 | if (!acpi && !amd) |
| 302 | for (i = 0; i < nr_cpu_ids; i++) |
| 303 | numa_set_node(i, 0); |
| 304 | } |
| 305 | |
Rohit Seth | 53fee04 | 2007-02-13 13:26:22 +0100 | [diff] [blame] | 306 | /* |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 307 | * Setups up nid to range from addr to addr + size. If the end |
| 308 | * boundary is greater than max_addr, then max_addr is used instead. |
| 309 | * The return value is 0 if there is additional memory left for |
| 310 | * allocation past addr and -1 otherwise. addr is adjusted to be at |
| 311 | * the end of the node. |
Rohit Seth | 53fee04 | 2007-02-13 13:26:22 +0100 | [diff] [blame] | 312 | */ |
David Rientjes | adc1938 | 2009-09-25 15:20:09 -0700 | [diff] [blame] | 313 | static int __init setup_node_range(int nid, u64 *addr, u64 size, u64 max_addr) |
Rohit Seth | 53fee04 | 2007-02-13 13:26:22 +0100 | [diff] [blame] | 314 | { |
David Rientjes | 8b8ca80e | 2007-05-02 19:27:09 +0200 | [diff] [blame] | 315 | int ret = 0; |
| 316 | nodes[nid].start = *addr; |
| 317 | *addr += size; |
| 318 | if (*addr >= max_addr) { |
| 319 | *addr = max_addr; |
| 320 | ret = -1; |
| 321 | } |
| 322 | nodes[nid].end = *addr; |
Suresh Siddha | e3f1cae | 2007-05-02 19:27:20 +0200 | [diff] [blame] | 323 | node_set(nid, node_possible_map); |
David Rientjes | 8b8ca80e | 2007-05-02 19:27:09 +0200 | [diff] [blame] | 324 | printk(KERN_INFO "Faking node %d at %016Lx-%016Lx (%LuMB)\n", nid, |
| 325 | nodes[nid].start, nodes[nid].end, |
| 326 | (nodes[nid].end - nodes[nid].start) >> 20); |
| 327 | return ret; |
Rohit Seth | 53fee04 | 2007-02-13 13:26:22 +0100 | [diff] [blame] | 328 | } |
| 329 | |
David Rientjes | 8b8ca80e | 2007-05-02 19:27:09 +0200 | [diff] [blame] | 330 | /* |
David Rientjes | adc1938 | 2009-09-25 15:20:09 -0700 | [diff] [blame] | 331 | * Sets up nr_nodes fake nodes interleaved over physical nodes ranging from addr |
| 332 | * to max_addr. The return value is the number of nodes allocated. |
| 333 | */ |
David Rientjes | c1c3443 | 2010-12-22 17:23:54 -0800 | [diff] [blame] | 334 | static int __init split_nodes_interleave(u64 addr, u64 max_addr, int nr_nodes) |
David Rientjes | adc1938 | 2009-09-25 15:20:09 -0700 | [diff] [blame] | 335 | { |
| 336 | nodemask_t physnode_mask = NODE_MASK_NONE; |
| 337 | u64 size; |
| 338 | int big; |
| 339 | int ret = 0; |
| 340 | int i; |
| 341 | |
| 342 | if (nr_nodes <= 0) |
| 343 | return -1; |
| 344 | if (nr_nodes > MAX_NUMNODES) { |
| 345 | pr_info("numa=fake=%d too large, reducing to %d\n", |
| 346 | nr_nodes, MAX_NUMNODES); |
| 347 | nr_nodes = MAX_NUMNODES; |
| 348 | } |
| 349 | |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 350 | size = (max_addr - addr - memblock_x86_hole_size(addr, max_addr)) / nr_nodes; |
David Rientjes | adc1938 | 2009-09-25 15:20:09 -0700 | [diff] [blame] | 351 | /* |
| 352 | * Calculate the number of big nodes that can be allocated as a result |
| 353 | * of consolidating the remainder. |
| 354 | */ |
David Rientjes | 68fd111 | 2010-02-15 13:43:25 -0800 | [diff] [blame] | 355 | big = ((size & ~FAKE_NODE_MIN_HASH_MASK) * nr_nodes) / |
David Rientjes | adc1938 | 2009-09-25 15:20:09 -0700 | [diff] [blame] | 356 | FAKE_NODE_MIN_SIZE; |
| 357 | |
| 358 | size &= FAKE_NODE_MIN_HASH_MASK; |
| 359 | if (!size) { |
| 360 | pr_err("Not enough memory for each node. " |
| 361 | "NUMA emulation disabled.\n"); |
| 362 | return -1; |
| 363 | } |
| 364 | |
David Rientjes | c1c3443 | 2010-12-22 17:23:54 -0800 | [diff] [blame] | 365 | for (i = 0; i < MAX_NUMNODES; i++) |
David Rientjes | adc1938 | 2009-09-25 15:20:09 -0700 | [diff] [blame] | 366 | if (physnodes[i].start != physnodes[i].end) |
| 367 | node_set(i, physnode_mask); |
| 368 | |
| 369 | /* |
| 370 | * Continue to fill physical nodes with fake nodes until there is no |
| 371 | * memory left on any of them. |
| 372 | */ |
| 373 | while (nodes_weight(physnode_mask)) { |
| 374 | for_each_node_mask(i, physnode_mask) { |
| 375 | u64 end = physnodes[i].start + size; |
| 376 | u64 dma32_end = PFN_PHYS(MAX_DMA32_PFN); |
| 377 | |
| 378 | if (ret < big) |
| 379 | end += FAKE_NODE_MIN_SIZE; |
| 380 | |
| 381 | /* |
| 382 | * Continue to add memory to this fake node if its |
| 383 | * non-reserved memory is less than the per-node size. |
| 384 | */ |
| 385 | while (end - physnodes[i].start - |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 386 | memblock_x86_hole_size(physnodes[i].start, end) < size) { |
David Rientjes | adc1938 | 2009-09-25 15:20:09 -0700 | [diff] [blame] | 387 | end += FAKE_NODE_MIN_SIZE; |
| 388 | if (end > physnodes[i].end) { |
| 389 | end = physnodes[i].end; |
| 390 | break; |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | /* |
| 395 | * If there won't be at least FAKE_NODE_MIN_SIZE of |
| 396 | * non-reserved memory in ZONE_DMA32 for the next node, |
| 397 | * this one must extend to the boundary. |
| 398 | */ |
| 399 | if (end < dma32_end && dma32_end - end - |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 400 | memblock_x86_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE) |
David Rientjes | adc1938 | 2009-09-25 15:20:09 -0700 | [diff] [blame] | 401 | end = dma32_end; |
| 402 | |
| 403 | /* |
| 404 | * If there won't be enough non-reserved memory for the |
| 405 | * next node, this one must extend to the end of the |
| 406 | * physical node. |
| 407 | */ |
| 408 | if (physnodes[i].end - end - |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 409 | memblock_x86_hole_size(end, physnodes[i].end) < size) |
David Rientjes | adc1938 | 2009-09-25 15:20:09 -0700 | [diff] [blame] | 410 | end = physnodes[i].end; |
| 411 | |
| 412 | /* |
| 413 | * Avoid allocating more nodes than requested, which can |
| 414 | * happen as a result of rounding down each node's size |
| 415 | * to FAKE_NODE_MIN_SIZE. |
| 416 | */ |
| 417 | if (nodes_weight(physnode_mask) + ret >= nr_nodes) |
| 418 | end = physnodes[i].end; |
| 419 | |
| 420 | if (setup_node_range(ret++, &physnodes[i].start, |
| 421 | end - physnodes[i].start, |
| 422 | physnodes[i].end) < 0) |
| 423 | node_clear(i, physnode_mask); |
| 424 | } |
| 425 | } |
| 426 | return ret; |
| 427 | } |
| 428 | |
| 429 | /* |
David Rientjes | 8df5bb34 | 2010-02-15 13:43:30 -0800 | [diff] [blame] | 430 | * Returns the end address of a node so that there is at least `size' amount of |
| 431 | * non-reserved memory or `max_addr' is reached. |
| 432 | */ |
| 433 | static u64 __init find_end_of_node(u64 start, u64 max_addr, u64 size) |
| 434 | { |
| 435 | u64 end = start + size; |
| 436 | |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 437 | while (end - start - memblock_x86_hole_size(start, end) < size) { |
David Rientjes | 8df5bb34 | 2010-02-15 13:43:30 -0800 | [diff] [blame] | 438 | end += FAKE_NODE_MIN_SIZE; |
| 439 | if (end > max_addr) { |
| 440 | end = max_addr; |
| 441 | break; |
| 442 | } |
| 443 | } |
| 444 | return end; |
| 445 | } |
| 446 | |
| 447 | /* |
| 448 | * Sets up fake nodes of `size' interleaved over physical nodes ranging from |
| 449 | * `addr' to `max_addr'. The return value is the number of nodes allocated. |
| 450 | */ |
| 451 | static int __init split_nodes_size_interleave(u64 addr, u64 max_addr, u64 size) |
| 452 | { |
| 453 | nodemask_t physnode_mask = NODE_MASK_NONE; |
| 454 | u64 min_size; |
| 455 | int ret = 0; |
| 456 | int i; |
| 457 | |
| 458 | if (!size) |
| 459 | return -1; |
| 460 | /* |
| 461 | * The limit on emulated nodes is MAX_NUMNODES, so the size per node is |
| 462 | * increased accordingly if the requested size is too small. This |
| 463 | * creates a uniform distribution of node sizes across the entire |
| 464 | * machine (but not necessarily over physical nodes). |
| 465 | */ |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 466 | min_size = (max_addr - addr - memblock_x86_hole_size(addr, max_addr)) / |
David Rientjes | 8df5bb34 | 2010-02-15 13:43:30 -0800 | [diff] [blame] | 467 | MAX_NUMNODES; |
| 468 | min_size = max(min_size, FAKE_NODE_MIN_SIZE); |
| 469 | if ((min_size & FAKE_NODE_MIN_HASH_MASK) < min_size) |
| 470 | min_size = (min_size + FAKE_NODE_MIN_SIZE) & |
| 471 | FAKE_NODE_MIN_HASH_MASK; |
| 472 | if (size < min_size) { |
| 473 | pr_err("Fake node size %LuMB too small, increasing to %LuMB\n", |
| 474 | size >> 20, min_size >> 20); |
| 475 | size = min_size; |
| 476 | } |
| 477 | size &= FAKE_NODE_MIN_HASH_MASK; |
| 478 | |
| 479 | for (i = 0; i < MAX_NUMNODES; i++) |
| 480 | if (physnodes[i].start != physnodes[i].end) |
| 481 | node_set(i, physnode_mask); |
| 482 | /* |
| 483 | * Fill physical nodes with fake nodes of size until there is no memory |
| 484 | * left on any of them. |
| 485 | */ |
| 486 | while (nodes_weight(physnode_mask)) { |
| 487 | for_each_node_mask(i, physnode_mask) { |
| 488 | u64 dma32_end = MAX_DMA32_PFN << PAGE_SHIFT; |
| 489 | u64 end; |
| 490 | |
| 491 | end = find_end_of_node(physnodes[i].start, |
| 492 | physnodes[i].end, size); |
| 493 | /* |
| 494 | * If there won't be at least FAKE_NODE_MIN_SIZE of |
| 495 | * non-reserved memory in ZONE_DMA32 for the next node, |
| 496 | * this one must extend to the boundary. |
| 497 | */ |
| 498 | if (end < dma32_end && dma32_end - end - |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 499 | memblock_x86_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE) |
David Rientjes | 8df5bb34 | 2010-02-15 13:43:30 -0800 | [diff] [blame] | 500 | end = dma32_end; |
| 501 | |
| 502 | /* |
| 503 | * If there won't be enough non-reserved memory for the |
| 504 | * next node, this one must extend to the end of the |
| 505 | * physical node. |
| 506 | */ |
| 507 | if (physnodes[i].end - end - |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 508 | memblock_x86_hole_size(end, physnodes[i].end) < size) |
David Rientjes | 8df5bb34 | 2010-02-15 13:43:30 -0800 | [diff] [blame] | 509 | end = physnodes[i].end; |
| 510 | |
| 511 | /* |
| 512 | * Setup the fake node that will be allocated as bootmem |
| 513 | * later. If setup_node_range() returns non-zero, there |
| 514 | * is no more memory available on this physical node. |
| 515 | */ |
| 516 | if (setup_node_range(ret++, &physnodes[i].start, |
| 517 | end - physnodes[i].start, |
| 518 | physnodes[i].end) < 0) |
| 519 | node_clear(i, physnode_mask); |
| 520 | } |
| 521 | } |
| 522 | return ret; |
| 523 | } |
| 524 | |
| 525 | /* |
Thomas Gleixner | 886533a | 2008-05-12 15:43:36 +0200 | [diff] [blame] | 526 | * Sets up the system RAM area from start_pfn to last_pfn according to the |
David Rientjes | 8b8ca80e | 2007-05-02 19:27:09 +0200 | [diff] [blame] | 527 | * numa=fake command-line option. |
| 528 | */ |
David Rientjes | adc1938 | 2009-09-25 15:20:09 -0700 | [diff] [blame] | 529 | static int __init numa_emulation(unsigned long start_pfn, |
Hans Rosenfeld | eec1d4f | 2010-10-29 17:14:30 +0200 | [diff] [blame] | 530 | unsigned long last_pfn, int acpi, int amd) |
David Rientjes | 8b8ca80e | 2007-05-02 19:27:09 +0200 | [diff] [blame] | 531 | { |
David Rientjes | ca2107c | 2010-02-15 13:43:33 -0800 | [diff] [blame] | 532 | u64 addr = start_pfn << PAGE_SHIFT; |
Thomas Gleixner | 886533a | 2008-05-12 15:43:36 +0200 | [diff] [blame] | 533 | u64 max_addr = last_pfn << PAGE_SHIFT; |
David Rientjes | ca2107c | 2010-02-15 13:43:33 -0800 | [diff] [blame] | 534 | int num_nodes; |
| 535 | int i; |
David Rientjes | 8b8ca80e | 2007-05-02 19:27:09 +0200 | [diff] [blame] | 536 | |
David Rientjes | 8b8ca80e | 2007-05-02 19:27:09 +0200 | [diff] [blame] | 537 | /* |
David Rientjes | 8df5bb34 | 2010-02-15 13:43:30 -0800 | [diff] [blame] | 538 | * If the numa=fake command-line contains a 'M' or 'G', it represents |
David Rientjes | ca2107c | 2010-02-15 13:43:33 -0800 | [diff] [blame] | 539 | * the fixed node size. Otherwise, if it is just a single number N, |
| 540 | * split the system RAM into N fake nodes. |
David Rientjes | 8df5bb34 | 2010-02-15 13:43:30 -0800 | [diff] [blame] | 541 | */ |
| 542 | if (strchr(cmdline, 'M') || strchr(cmdline, 'G')) { |
David Rientjes | ca2107c | 2010-02-15 13:43:33 -0800 | [diff] [blame] | 543 | u64 size; |
| 544 | |
David Rientjes | 8df5bb34 | 2010-02-15 13:43:30 -0800 | [diff] [blame] | 545 | size = memparse(cmdline, &cmdline); |
| 546 | num_nodes = split_nodes_size_interleave(addr, max_addr, size); |
David Rientjes | ca2107c | 2010-02-15 13:43:33 -0800 | [diff] [blame] | 547 | } else { |
| 548 | unsigned long n; |
| 549 | |
| 550 | n = simple_strtoul(cmdline, NULL, 0); |
David Rientjes | c1c3443 | 2010-12-22 17:23:54 -0800 | [diff] [blame] | 551 | num_nodes = split_nodes_interleave(addr, max_addr, n); |
David Rientjes | 8df5bb34 | 2010-02-15 13:43:30 -0800 | [diff] [blame] | 552 | } |
| 553 | |
David Rientjes | ca2107c | 2010-02-15 13:43:33 -0800 | [diff] [blame] | 554 | if (num_nodes < 0) |
| 555 | return num_nodes; |
Suresh Siddha | 6ec6e0d | 2008-03-25 10:14:35 -0700 | [diff] [blame] | 556 | memnode_shift = compute_hash_shift(nodes, num_nodes, NULL); |
David Rientjes | 8b8ca80e | 2007-05-02 19:27:09 +0200 | [diff] [blame] | 557 | if (memnode_shift < 0) { |
| 558 | memnode_shift = 0; |
| 559 | printk(KERN_ERR "No NUMA hash function found. NUMA emulation " |
| 560 | "disabled.\n"); |
| 561 | return -1; |
| 562 | } |
| 563 | |
| 564 | /* |
David Rientjes | adc1938 | 2009-09-25 15:20:09 -0700 | [diff] [blame] | 565 | * We need to vacate all active ranges that may have been registered for |
| 566 | * the e820 memory map. |
David Rientjes | 8b8ca80e | 2007-05-02 19:27:09 +0200 | [diff] [blame] | 567 | */ |
| 568 | remove_all_active_ranges(); |
Suresh Siddha | e3f1cae | 2007-05-02 19:27:20 +0200 | [diff] [blame] | 569 | for_each_node_mask(i, node_possible_map) { |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 570 | memblock_x86_register_active_regions(i, nodes[i].start >> PAGE_SHIFT, |
Mel Gorman | 5cb248a | 2006-09-27 01:49:52 -0700 | [diff] [blame] | 571 | nodes[i].end >> PAGE_SHIFT); |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 572 | setup_node_bootmem(i, nodes[i].start, nodes[i].end); |
Mel Gorman | 5cb248a | 2006-09-27 01:49:52 -0700 | [diff] [blame] | 573 | } |
David Rientjes | c1c3443 | 2010-12-22 17:23:54 -0800 | [diff] [blame] | 574 | setup_physnodes(addr, max_addr, acpi, amd); |
David Rientjes | f51bf30 | 2010-12-22 17:23:51 -0800 | [diff] [blame] | 575 | fake_physnodes(acpi, amd, num_nodes); |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 576 | numa_init_array(); |
| 577 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | } |
David Rientjes | 8b8ca80e | 2007-05-02 19:27:09 +0200 | [diff] [blame] | 579 | #endif /* CONFIG_NUMA_EMU */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
David Rientjes | 8ee2deb | 2009-09-25 15:20:00 -0700 | [diff] [blame] | 581 | void __init initmem_init(unsigned long start_pfn, unsigned long last_pfn, |
Hans Rosenfeld | eec1d4f | 2010-10-29 17:14:30 +0200 | [diff] [blame] | 582 | int acpi, int amd) |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 583 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | int i; |
| 585 | |
Suresh Siddha | e3f1cae | 2007-05-02 19:27:20 +0200 | [diff] [blame] | 586 | nodes_clear(node_possible_map); |
Yinghai Lu | b7ad149 | 2008-02-17 02:02:21 -0800 | [diff] [blame] | 587 | nodes_clear(node_online_map); |
Suresh Siddha | e3f1cae | 2007-05-02 19:27:20 +0200 | [diff] [blame] | 588 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | #ifdef CONFIG_NUMA_EMU |
David Rientjes | c1c3443 | 2010-12-22 17:23:54 -0800 | [diff] [blame] | 590 | setup_physnodes(start_pfn << PAGE_SHIFT, last_pfn << PAGE_SHIFT, |
| 591 | acpi, amd); |
Hans Rosenfeld | eec1d4f | 2010-10-29 17:14:30 +0200 | [diff] [blame] | 592 | if (cmdline && !numa_emulation(start_pfn, last_pfn, acpi, amd)) |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 593 | return; |
David Rientjes | c1c3443 | 2010-12-22 17:23:54 -0800 | [diff] [blame] | 594 | setup_physnodes(start_pfn << PAGE_SHIFT, last_pfn << PAGE_SHIFT, |
| 595 | acpi, amd); |
Suresh Siddha | e3f1cae | 2007-05-02 19:27:20 +0200 | [diff] [blame] | 596 | nodes_clear(node_possible_map); |
Yinghai Lu | b7ad149 | 2008-02-17 02:02:21 -0800 | [diff] [blame] | 597 | nodes_clear(node_online_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | #endif |
| 599 | |
| 600 | #ifdef CONFIG_ACPI_NUMA |
David Rientjes | 8716273 | 2009-09-25 15:20:04 -0700 | [diff] [blame] | 601 | if (!numa_off && acpi && !acpi_scan_nodes(start_pfn << PAGE_SHIFT, |
| 602 | last_pfn << PAGE_SHIFT)) |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 603 | return; |
Suresh Siddha | e3f1cae | 2007-05-02 19:27:20 +0200 | [diff] [blame] | 604 | nodes_clear(node_possible_map); |
Yinghai Lu | b7ad149 | 2008-02-17 02:02:21 -0800 | [diff] [blame] | 605 | nodes_clear(node_online_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | #endif |
| 607 | |
Hans Rosenfeld | eec1d4f | 2010-10-29 17:14:30 +0200 | [diff] [blame] | 608 | #ifdef CONFIG_AMD_NUMA |
| 609 | if (!numa_off && amd && !amd_scan_nodes()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | return; |
Suresh Siddha | e3f1cae | 2007-05-02 19:27:20 +0200 | [diff] [blame] | 611 | nodes_clear(node_possible_map); |
Yinghai Lu | b7ad149 | 2008-02-17 02:02:21 -0800 | [diff] [blame] | 612 | nodes_clear(node_online_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | #endif |
| 614 | printk(KERN_INFO "%s\n", |
| 615 | numa_off ? "NUMA turned off" : "No NUMA configuration found"); |
| 616 | |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 617 | printk(KERN_INFO "Faking a node at %016lx-%016lx\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | start_pfn << PAGE_SHIFT, |
Thomas Gleixner | 886533a | 2008-05-12 15:43:36 +0200 | [diff] [blame] | 619 | last_pfn << PAGE_SHIFT); |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 620 | /* setup dummy node covering all memory */ |
| 621 | memnode_shift = 63; |
Amul Shah | 076422d | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 622 | memnodemap = memnode.embedded_map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | memnodemap[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | node_set_online(0); |
Suresh Siddha | e3f1cae | 2007-05-02 19:27:20 +0200 | [diff] [blame] | 625 | node_set(0, node_possible_map); |
Mike Travis | 168ef54 | 2008-12-16 17:34:01 -0800 | [diff] [blame] | 626 | for (i = 0; i < nr_cpu_ids; i++) |
Andi Kleen | 69d81fc | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 627 | numa_set_node(i, 0); |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 628 | memblock_x86_register_active_regions(0, start_pfn, last_pfn); |
Thomas Gleixner | 886533a | 2008-05-12 15:43:36 +0200 | [diff] [blame] | 629 | setup_node_bootmem(0, start_pfn << PAGE_SHIFT, last_pfn << PAGE_SHIFT); |
Andi Kleen | 69d81fc | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 630 | } |
| 631 | |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 632 | unsigned long __init numa_free_all_bootmem(void) |
| 633 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | unsigned long pages = 0; |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 635 | int i; |
| 636 | |
| 637 | for_each_online_node(i) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | pages += free_all_bootmem_node(NODE_DATA(i)); |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 639 | |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 640 | pages += free_all_memory_core_early(MAX_NUMNODES); |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | return pages; |
Thomas Gleixner | e3cfe52 | 2008-01-30 13:30:37 +0100 | [diff] [blame] | 643 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
Tejun Heo | bbc9e2f | 2011-01-23 14:37:39 +0100 | [diff] [blame] | 645 | int __cpuinit numa_cpu_node(int cpu) |
| 646 | { |
| 647 | int apicid = early_per_cpu(x86_cpu_to_apicid, cpu); |
| 648 | |
| 649 | if (apicid != BAD_APICID) |
| 650 | return __apicid_to_node[apicid]; |
| 651 | return NUMA_NO_NODE; |
| 652 | } |
Andi Kleen | cf05013 | 2006-01-11 22:46:27 +0100 | [diff] [blame] | 653 | |
Tejun Heo | de2d944 | 2011-01-23 14:37:41 +0100 | [diff] [blame] | 654 | /* |
| 655 | * UGLINESS AHEAD: Currently, CONFIG_NUMA_EMU is 64bit only and makes use |
| 656 | * of 64bit specific data structures. The distinction is artificial and |
| 657 | * should be removed. numa_{add|remove}_cpu() are implemented in numa.c |
| 658 | * for both 32 and 64bit when CONFIG_NUMA_EMU is disabled but here when |
| 659 | * enabled. |
| 660 | * |
| 661 | * NUMA emulation is planned to be made generic and the following and other |
| 662 | * related code should be moved to numa.c. |
| 663 | */ |
| 664 | #ifdef CONFIG_NUMA_EMU |
| 665 | # ifndef CONFIG_DEBUG_PER_CPU_MAPS |
David Rientjes | c1c3443 | 2010-12-22 17:23:54 -0800 | [diff] [blame] | 666 | void __cpuinit numa_add_cpu(int cpu) |
| 667 | { |
| 668 | unsigned long addr; |
Tejun Heo | bbc9e2f | 2011-01-23 14:37:39 +0100 | [diff] [blame] | 669 | int physnid, nid; |
David Rientjes | c1c3443 | 2010-12-22 17:23:54 -0800 | [diff] [blame] | 670 | |
Tejun Heo | bbc9e2f | 2011-01-23 14:37:39 +0100 | [diff] [blame] | 671 | nid = numa_cpu_node(cpu); |
David Rientjes | c1c3443 | 2010-12-22 17:23:54 -0800 | [diff] [blame] | 672 | if (nid == NUMA_NO_NODE) |
| 673 | nid = early_cpu_to_node(cpu); |
| 674 | BUG_ON(nid == NUMA_NO_NODE || !node_online(nid)); |
| 675 | |
| 676 | /* |
| 677 | * Use the starting address of the emulated node to find which physical |
| 678 | * node it is allocated on. |
| 679 | */ |
| 680 | addr = node_start_pfn(nid) << PAGE_SHIFT; |
| 681 | for (physnid = 0; physnid < MAX_NUMNODES; physnid++) |
| 682 | if (addr >= physnodes[physnid].start && |
| 683 | addr < physnodes[physnid].end) |
| 684 | break; |
| 685 | |
| 686 | /* |
| 687 | * Map the cpu to each emulated node that is allocated on the physical |
| 688 | * node of the cpu's apic id. |
| 689 | */ |
| 690 | for_each_online_node(nid) { |
| 691 | addr = node_start_pfn(nid) << PAGE_SHIFT; |
| 692 | if (addr >= physnodes[physnid].start && |
| 693 | addr < physnodes[physnid].end) |
| 694 | cpumask_set_cpu(cpu, node_to_cpumask_map[nid]); |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | void __cpuinit numa_remove_cpu(int cpu) |
| 699 | { |
| 700 | int i; |
| 701 | |
| 702 | for_each_online_node(i) |
| 703 | cpumask_clear_cpu(cpu, node_to_cpumask_map[i]); |
| 704 | } |
Tejun Heo | de2d944 | 2011-01-23 14:37:41 +0100 | [diff] [blame] | 705 | # else /* !CONFIG_DEBUG_PER_CPU_MAPS */ |
David Rientjes | d906f0e | 2010-12-30 10:54:16 -0800 | [diff] [blame] | 706 | static void __cpuinit numa_set_cpumask(int cpu, int enable) |
| 707 | { |
| 708 | int node = early_cpu_to_node(cpu); |
| 709 | struct cpumask *mask; |
David Rientjes | c1c3443 | 2010-12-22 17:23:54 -0800 | [diff] [blame] | 710 | int i; |
Brian Gerst | 6470aff | 2009-01-27 12:56:47 +0900 | [diff] [blame] | 711 | |
David Rientjes | c1c3443 | 2010-12-22 17:23:54 -0800 | [diff] [blame] | 712 | for_each_online_node(i) { |
| 713 | unsigned long addr; |
| 714 | |
| 715 | addr = node_start_pfn(i) << PAGE_SHIFT; |
| 716 | if (addr < physnodes[node].start || |
| 717 | addr >= physnodes[node].end) |
| 718 | continue; |
David Rientjes | d906f0e | 2010-12-30 10:54:16 -0800 | [diff] [blame] | 719 | mask = debug_cpumask_set_cpu(cpu, enable); |
| 720 | if (!mask) |
David Rientjes | c1c3443 | 2010-12-22 17:23:54 -0800 | [diff] [blame] | 721 | return; |
David Rientjes | c1c3443 | 2010-12-22 17:23:54 -0800 | [diff] [blame] | 722 | |
| 723 | if (enable) |
| 724 | cpumask_set_cpu(cpu, mask); |
| 725 | else |
| 726 | cpumask_clear_cpu(cpu, mask); |
Brian Gerst | 6470aff | 2009-01-27 12:56:47 +0900 | [diff] [blame] | 727 | } |
Brian Gerst | 6470aff | 2009-01-27 12:56:47 +0900 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | void __cpuinit numa_add_cpu(int cpu) |
| 731 | { |
| 732 | numa_set_cpumask(cpu, 1); |
| 733 | } |
| 734 | |
| 735 | void __cpuinit numa_remove_cpu(int cpu) |
| 736 | { |
| 737 | numa_set_cpumask(cpu, 0); |
| 738 | } |
Tejun Heo | de2d944 | 2011-01-23 14:37:41 +0100 | [diff] [blame] | 739 | # endif /* !CONFIG_DEBUG_PER_CPU_MAPS */ |
| 740 | #endif /* CONFIG_NUMA_EMU */ |