Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ACPI 3.0 based NUMA setup |
| 3 | * Copyright 2004 Andi Kleen, SuSE Labs. |
| 4 | * |
| 5 | * Reads the ACPI SRAT table to figure out what memory belongs to which CPUs. |
| 6 | * |
| 7 | * Called from acpi_numa_init while reading the SRAT and SLIT tables. |
| 8 | * Assumes all memory regions belonging to a single proximity domain |
| 9 | * are in one chunk. Holes between them will be included in the node. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/acpi.h> |
| 14 | #include <linux/mmzone.h> |
| 15 | #include <linux/bitmap.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/topology.h> |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 18 | #include <linux/bootmem.h> |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 19 | #include <linux/memblock.h> |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 20 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/proto.h> |
| 22 | #include <asm/numa.h> |
Andi Kleen | 8a6fdd3 | 2006-01-11 22:44:39 +0100 | [diff] [blame] | 23 | #include <asm/e820.h> |
Ingo Molnar | 7b6aa33 | 2009-02-17 13:58:15 +0100 | [diff] [blame] | 24 | #include <asm/apic.h> |
Ingo Molnar | 4ec71fa | 2009-01-21 10:24:27 +0100 | [diff] [blame] | 25 | #include <asm/uv/uv.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Andi Kleen | c31fbb1 | 2006-09-26 10:52:33 +0200 | [diff] [blame] | 27 | int acpi_numa __initdata; |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | static struct acpi_table_slit *acpi_slit; |
| 30 | |
Keith Mannthey | 4942e99 | 2006-09-30 23:27:06 -0700 | [diff] [blame] | 31 | static struct bootnode nodes_add[MAX_NUMNODES]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | static __init int setup_node(int pxm) |
| 34 | { |
Yasunori Goto | 762834e | 2006-06-23 02:03:19 -0700 | [diff] [blame] | 35 | return acpi_map_pxm_to_node(pxm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | static __init void bad_srat(void) |
| 39 | { |
| 40 | printk(KERN_ERR "SRAT: SRAT not used.\n"); |
| 41 | acpi_numa = -1; |
Tejun Heo | 9155623 | 2011-02-16 17:11:09 +0100 | [diff] [blame] | 42 | memset(nodes_add, 0, sizeof(nodes_add)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | static __init inline int srat_disabled(void) |
| 46 | { |
Tejun Heo | ffe77a4 | 2011-02-16 12:13:06 +0100 | [diff] [blame] | 47 | return acpi_numa < 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /* Callback for SLIT parsing */ |
| 51 | void __init acpi_numa_slit_init(struct acpi_table_slit *slit) |
| 52 | { |
Tejun Heo | ac7136b | 2011-02-16 17:11:09 +0100 | [diff] [blame^] | 53 | int i, j; |
Yinghai Lu | f302a5bb | 2008-07-10 20:36:37 -0700 | [diff] [blame] | 54 | unsigned length; |
| 55 | unsigned long phys; |
| 56 | |
Tejun Heo | ac7136b | 2011-02-16 17:11:09 +0100 | [diff] [blame^] | 57 | for (i = 0; i < slit->locality_count; i++) |
| 58 | for (j = 0; j < slit->locality_count; j++) |
| 59 | numa_set_distance(pxm_to_node(i), pxm_to_node(j), |
| 60 | slit->entry[slit->locality_count * i + j]); |
| 61 | |
| 62 | /* acpi_slit is used only by emulation */ |
Yinghai Lu | f302a5bb | 2008-07-10 20:36:37 -0700 | [diff] [blame] | 63 | length = slit->header.length; |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 64 | phys = memblock_find_in_range(0, max_pfn_mapped<<PAGE_SHIFT, length, |
Yinghai Lu | f302a5bb | 2008-07-10 20:36:37 -0700 | [diff] [blame] | 65 | PAGE_SIZE); |
| 66 | |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 67 | if (phys == MEMBLOCK_ERROR) |
Yinghai Lu | f302a5bb | 2008-07-10 20:36:37 -0700 | [diff] [blame] | 68 | panic(" Can not save slit!\n"); |
| 69 | |
| 70 | acpi_slit = __va(phys); |
| 71 | memcpy(acpi_slit, slit, length); |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 72 | memblock_x86_reserve_range(phys, phys + length, "ACPI SLIT"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Suresh Siddha | 7237d3d | 2009-03-30 13:55:30 -0800 | [diff] [blame] | 75 | /* Callback for Proximity Domain -> x2APIC mapping */ |
| 76 | void __init |
| 77 | acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa) |
| 78 | { |
| 79 | int pxm, node; |
| 80 | int apic_id; |
| 81 | |
| 82 | if (srat_disabled()) |
| 83 | return; |
| 84 | if (pa->header.length < sizeof(struct acpi_srat_x2apic_cpu_affinity)) { |
| 85 | bad_srat(); |
| 86 | return; |
| 87 | } |
| 88 | if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0) |
| 89 | return; |
| 90 | pxm = pa->proximity_domain; |
| 91 | node = setup_node(pxm); |
| 92 | if (node < 0) { |
| 93 | printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm); |
| 94 | bad_srat(); |
| 95 | return; |
| 96 | } |
| 97 | |
| 98 | apic_id = pa->apic_id; |
Yinghai Lu | d3bd058 | 2010-12-16 19:09:58 -0800 | [diff] [blame] | 99 | if (apic_id >= MAX_LOCAL_APIC) { |
| 100 | printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node); |
| 101 | return; |
| 102 | } |
Tejun Heo | bbc9e2f | 2011-01-23 14:37:39 +0100 | [diff] [blame] | 103 | set_apicid_to_node(apic_id, node); |
Tejun Heo | 92d4a43 | 2011-02-16 17:11:09 +0100 | [diff] [blame] | 104 | node_set(node, numa_nodes_parsed); |
Suresh Siddha | 7237d3d | 2009-03-30 13:55:30 -0800 | [diff] [blame] | 105 | acpi_numa = 1; |
Yinghai Lu | 163d386 | 2009-11-21 00:23:37 -0800 | [diff] [blame] | 106 | printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u\n", |
Suresh Siddha | 7237d3d | 2009-03-30 13:55:30 -0800 | [diff] [blame] | 107 | pxm, apic_id, node); |
| 108 | } |
| 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | /* Callback for Proximity Domain -> LAPIC mapping */ |
| 111 | void __init |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 112 | acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | { |
| 114 | int pxm, node; |
travis@sgi.com | ef97001 | 2008-01-30 13:33:10 +0100 | [diff] [blame] | 115 | int apic_id; |
| 116 | |
Andi Kleen | d22fe80 | 2006-02-03 21:51:26 +0100 | [diff] [blame] | 117 | if (srat_disabled()) |
| 118 | return; |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 119 | if (pa->header.length != sizeof(struct acpi_srat_cpu_affinity)) { |
Andi Kleen | fad7906 | 2006-05-15 18:19:44 +0200 | [diff] [blame] | 120 | bad_srat(); |
Andi Kleen | d22fe80 | 2006-02-03 21:51:26 +0100 | [diff] [blame] | 121 | return; |
| 122 | } |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 123 | if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | return; |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 125 | pxm = pa->proximity_domain_lo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | node = setup_node(pxm); |
| 127 | if (node < 0) { |
| 128 | printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm); |
| 129 | bad_srat(); |
| 130 | return; |
| 131 | } |
Yinghai Lu | beafe91 | 2008-02-16 23:00:22 -0800 | [diff] [blame] | 132 | |
Jack Steiner | 2e42060 | 2008-09-23 15:37:13 -0500 | [diff] [blame] | 133 | if (get_uv_system_type() >= UV_X2APIC) |
Jack Steiner | a65d1d6 | 2008-03-28 14:12:08 -0500 | [diff] [blame] | 134 | apic_id = (pa->apic_id << 8) | pa->local_sapic_eid; |
| 135 | else |
| 136 | apic_id = pa->apic_id; |
Yinghai Lu | d3bd058 | 2010-12-16 19:09:58 -0800 | [diff] [blame] | 137 | |
| 138 | if (apic_id >= MAX_LOCAL_APIC) { |
| 139 | printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node); |
| 140 | return; |
| 141 | } |
| 142 | |
Tejun Heo | bbc9e2f | 2011-01-23 14:37:39 +0100 | [diff] [blame] | 143 | set_apicid_to_node(apic_id, node); |
Tejun Heo | 92d4a43 | 2011-02-16 17:11:09 +0100 | [diff] [blame] | 144 | node_set(node, numa_nodes_parsed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | acpi_numa = 1; |
Yinghai Lu | 163d386 | 2009-11-21 00:23:37 -0800 | [diff] [blame] | 146 | printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u\n", |
travis@sgi.com | ef97001 | 2008-01-30 13:33:10 +0100 | [diff] [blame] | 147 | pxm, apic_id, node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Keith Mannthey | 71efa8f | 2006-09-30 23:27:05 -0700 | [diff] [blame] | 150 | #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE |
| 151 | static inline int save_add_info(void) {return 1;} |
| 152 | #else |
| 153 | static inline int save_add_info(void) {return 0;} |
| 154 | #endif |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 155 | /* |
Yinghai Lu | 888a589 | 2009-05-15 13:59:37 -0700 | [diff] [blame] | 156 | * Update nodes_add[] |
| 157 | * This code supports one contiguous hot add area per node |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 158 | */ |
Yinghai Lu | 888a589 | 2009-05-15 13:59:37 -0700 | [diff] [blame] | 159 | static void __init |
| 160 | update_nodes_add(int node, unsigned long start, unsigned long end) |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 161 | { |
| 162 | unsigned long s_pfn = start >> PAGE_SHIFT; |
| 163 | unsigned long e_pfn = end >> PAGE_SHIFT; |
Yinghai Lu | 888a589 | 2009-05-15 13:59:37 -0700 | [diff] [blame] | 164 | int changed = 0; |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 165 | struct bootnode *nd = &nodes_add[node]; |
| 166 | |
| 167 | /* I had some trouble with strange memory hotadd regions breaking |
| 168 | the boot. Be very strict here and reject anything unexpected. |
| 169 | If you want working memory hotadd write correct SRATs. |
| 170 | |
| 171 | The node size check is a basic sanity check to guard against |
| 172 | mistakes */ |
| 173 | if ((signed long)(end - start) < NODE_MIN_SIZE) { |
| 174 | printk(KERN_ERR "SRAT: Hotplug area too small\n"); |
Yinghai Lu | 888a589 | 2009-05-15 13:59:37 -0700 | [diff] [blame] | 175 | return; |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /* This check might be a bit too strict, but I'm keeping it for now. */ |
Mel Gorman | 5cb248a | 2006-09-27 01:49:52 -0700 | [diff] [blame] | 179 | if (absent_pages_in_range(s_pfn, e_pfn) != e_pfn - s_pfn) { |
Mel Gorman | 9c7cd68 | 2006-09-27 01:49:58 -0700 | [diff] [blame] | 180 | printk(KERN_ERR |
| 181 | "SRAT: Hotplug area %lu -> %lu has existing memory\n", |
| 182 | s_pfn, e_pfn); |
Yinghai Lu | 888a589 | 2009-05-15 13:59:37 -0700 | [diff] [blame] | 183 | return; |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /* Looks good */ |
| 187 | |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 188 | if (nd->start == nd->end) { |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 189 | nd->start = start; |
| 190 | nd->end = end; |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 191 | changed = 1; |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 192 | } else { |
| 193 | if (nd->start == end) { |
| 194 | nd->start = start; |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 195 | changed = 1; |
| 196 | } |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 197 | if (nd->end == start) { |
| 198 | nd->end = end; |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 199 | changed = 1; |
| 200 | } |
| 201 | if (!changed) |
| 202 | printk(KERN_ERR "SRAT: Hotplug zone not continuous. Partly ignored\n"); |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 203 | } |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 204 | |
David Rientjes | 3a5fc0e | 2010-01-20 12:10:47 -0800 | [diff] [blame] | 205 | if (changed) { |
Tejun Heo | 92d4a43 | 2011-02-16 17:11:09 +0100 | [diff] [blame] | 206 | node_set(node, numa_nodes_parsed); |
Yinghai Lu | 888a589 | 2009-05-15 13:59:37 -0700 | [diff] [blame] | 207 | printk(KERN_INFO "SRAT: hot plug zone found %Lx - %Lx\n", |
| 208 | nd->start, nd->end); |
David Rientjes | 3a5fc0e | 2010-01-20 12:10:47 -0800 | [diff] [blame] | 209 | } |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 210 | } |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | /* Callback for parsing of the Proximity Domain <-> Memory Area mappings */ |
| 213 | void __init |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 214 | acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | unsigned long start, end; |
| 217 | int node, pxm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
Andi Kleen | d22fe80 | 2006-02-03 21:51:26 +0100 | [diff] [blame] | 219 | if (srat_disabled()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | return; |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 221 | if (ma->header.length != sizeof(struct acpi_srat_mem_affinity)) { |
Andi Kleen | d22fe80 | 2006-02-03 21:51:26 +0100 | [diff] [blame] | 222 | bad_srat(); |
| 223 | return; |
| 224 | } |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 225 | if ((ma->flags & ACPI_SRAT_MEM_ENABLED) == 0) |
Andi Kleen | d22fe80 | 2006-02-03 21:51:26 +0100 | [diff] [blame] | 226 | return; |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 227 | |
| 228 | if ((ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) && !save_add_info()) |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 229 | return; |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 230 | start = ma->base_address; |
| 231 | end = start + ma->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | pxm = ma->proximity_domain; |
| 233 | node = setup_node(pxm); |
| 234 | if (node < 0) { |
| 235 | printk(KERN_ERR "SRAT: Too many proximity domains.\n"); |
| 236 | bad_srat(); |
| 237 | return; |
| 238 | } |
Tejun Heo | ef396ec | 2011-02-16 17:11:07 +0100 | [diff] [blame] | 239 | |
| 240 | if (numa_add_memblk(node, start, end) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | bad_srat(); |
| 242 | return; |
| 243 | } |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 244 | |
Suresh Siddha | 6ec6e0d | 2008-03-25 10:14:35 -0700 | [diff] [blame] | 245 | printk(KERN_INFO "SRAT: Node %u PXM %u %lx-%lx\n", node, pxm, |
| 246 | start, end); |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 247 | |
Tejun Heo | 4697bdc | 2011-02-16 17:11:09 +0100 | [diff] [blame] | 248 | if (ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) |
Yinghai Lu | 888a589 | 2009-05-15 13:59:37 -0700 | [diff] [blame] | 249 | update_nodes_add(node, start, end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | void __init acpi_numa_arch_fixup(void) {} |
| 253 | |
Tejun Heo | a9aec56 | 2011-02-16 12:13:06 +0100 | [diff] [blame] | 254 | int __init x86_acpi_numa_init(void) |
| 255 | { |
| 256 | int ret; |
| 257 | |
| 258 | ret = acpi_numa_init(); |
| 259 | if (ret < 0) |
| 260 | return ret; |
| 261 | return srat_disabled() ? -EINVAL : 0; |
| 262 | } |
| 263 | |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 264 | #ifdef CONFIG_NUMA_EMU |
travis@sgi.com | ef97001 | 2008-01-30 13:33:10 +0100 | [diff] [blame] | 265 | static int fake_node_to_pxm_map[MAX_NUMNODES] __initdata = { |
| 266 | [0 ... MAX_NUMNODES-1] = PXM_INVAL |
| 267 | }; |
travis@sgi.com | 602a54a | 2008-01-30 13:33:21 +0100 | [diff] [blame] | 268 | static s16 fake_apicid_to_node[MAX_LOCAL_APIC] __initdata = { |
travis@sgi.com | ef97001 | 2008-01-30 13:33:10 +0100 | [diff] [blame] | 269 | [0 ... MAX_LOCAL_APIC-1] = NUMA_NO_NODE |
| 270 | }; |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 271 | |
| 272 | /* |
| 273 | * In NUMA emulation, we need to setup proximity domain (_PXM) to node ID |
| 274 | * mappings that respect the real ACPI topology but reflect our emulated |
| 275 | * environment. For each emulated node, we find which real node it appears on |
| 276 | * and create PXM to NID mappings for those fake nodes which mirror that |
| 277 | * locality. SLIT will now represent the correct distances between emulated |
| 278 | * nodes as a result of the real topology. |
| 279 | */ |
| 280 | void __init acpi_fake_nodes(const struct bootnode *fake_nodes, int num_nodes) |
| 281 | { |
David Rientjes | 08705b8 | 2007-07-21 17:10:33 +0200 | [diff] [blame] | 282 | int i, j; |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 283 | |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 284 | for (i = 0; i < num_nodes; i++) { |
| 285 | int nid, pxm; |
| 286 | |
| 287 | nid = find_node_by_addr(fake_nodes[i].start); |
| 288 | if (nid == NUMA_NO_NODE) |
| 289 | continue; |
| 290 | pxm = node_to_pxm(nid); |
| 291 | if (pxm == PXM_INVAL) |
| 292 | continue; |
| 293 | fake_node_to_pxm_map[i] = pxm; |
David Rientjes | 08705b8 | 2007-07-21 17:10:33 +0200 | [diff] [blame] | 294 | /* |
| 295 | * For each apicid_to_node mapping that exists for this real |
| 296 | * node, it must now point to the fake node ID. |
| 297 | */ |
| 298 | for (j = 0; j < MAX_LOCAL_APIC; j++) |
Tejun Heo | bbc9e2f | 2011-01-23 14:37:39 +0100 | [diff] [blame] | 299 | if (__apicid_to_node[j] == nid && |
David Rientjes | b0c4d95 | 2010-05-06 02:24:34 -0700 | [diff] [blame] | 300 | fake_apicid_to_node[j] == NUMA_NO_NODE) |
David Rientjes | 08705b8 | 2007-07-21 17:10:33 +0200 | [diff] [blame] | 301 | fake_apicid_to_node[j] = i; |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 302 | } |
David Rientjes | a387e95 | 2010-12-22 17:23:56 -0800 | [diff] [blame] | 303 | |
| 304 | /* |
| 305 | * If there are apicid-to-node mappings for physical nodes that do not |
| 306 | * have a corresponding emulated node, it should default to a guaranteed |
| 307 | * value. |
| 308 | */ |
| 309 | for (i = 0; i < MAX_LOCAL_APIC; i++) |
Tejun Heo | bbc9e2f | 2011-01-23 14:37:39 +0100 | [diff] [blame] | 310 | if (__apicid_to_node[i] != NUMA_NO_NODE && |
David Rientjes | a387e95 | 2010-12-22 17:23:56 -0800 | [diff] [blame] | 311 | fake_apicid_to_node[i] == NUMA_NO_NODE) |
| 312 | fake_apicid_to_node[i] = 0; |
| 313 | |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 314 | for (i = 0; i < num_nodes; i++) |
| 315 | __acpi_map_pxm_to_node(fake_node_to_pxm_map[i], i); |
Tejun Heo | bbc9e2f | 2011-01-23 14:37:39 +0100 | [diff] [blame] | 316 | memcpy(__apicid_to_node, fake_apicid_to_node, sizeof(__apicid_to_node)); |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 317 | |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 318 | for (i = 0; i < num_nodes; i++) |
| 319 | if (fake_nodes[i].start != fake_nodes[i].end) |
Tejun Heo | 4697bdc | 2011-02-16 17:11:09 +0100 | [diff] [blame] | 320 | node_set(i, numa_nodes_parsed); |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 321 | } |
| 322 | |
Tejun Heo | ac7136b | 2011-02-16 17:11:09 +0100 | [diff] [blame^] | 323 | int acpi_emu_node_distance(int a, int b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | { |
| 325 | int index; |
| 326 | |
| 327 | if (!acpi_slit) |
Tejun Heo | ac7136b | 2011-02-16 17:11:09 +0100 | [diff] [blame^] | 328 | return node_to_pxm(a) == node_to_pxm(b) ? |
| 329 | LOCAL_DISTANCE : REMOTE_DISTANCE; |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 330 | index = acpi_slit->locality_count * node_to_pxm(a); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | return acpi_slit->entry[index + node_to_pxm(b)]; |
| 332 | } |
Tejun Heo | ac7136b | 2011-02-16 17:11:09 +0100 | [diff] [blame^] | 333 | #endif /* CONFIG_NUMA_EMU */ |
Keith Mannthey | 4942e99 | 2006-09-30 23:27:06 -0700 | [diff] [blame] | 334 | |
Thomas Gleixner | 6a1673a | 2008-05-12 15:43:38 +0200 | [diff] [blame] | 335 | #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) || defined(CONFIG_ACPI_HOTPLUG_MEMORY) |
Keith Mannthey | 4942e99 | 2006-09-30 23:27:06 -0700 | [diff] [blame] | 336 | int memory_add_physaddr_to_nid(u64 start) |
| 337 | { |
| 338 | int i, ret = 0; |
| 339 | |
| 340 | for_each_node(i) |
| 341 | if (nodes_add[i].start <= start && nodes_add[i].end > start) |
| 342 | ret = i; |
| 343 | |
| 344 | return ret; |
| 345 | } |
Keith Mannthey | 8c2676a | 2006-09-30 23:27:07 -0700 | [diff] [blame] | 346 | EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid); |
Thomas Gleixner | 6a1673a | 2008-05-12 15:43:38 +0200 | [diff] [blame] | 347 | #endif |