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 | { |
Andi Kleen | 2bce2b5 | 2005-09-12 18:49:25 +0200 | [diff] [blame] | 40 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | printk(KERN_ERR "SRAT: SRAT not used.\n"); |
| 42 | acpi_numa = -1; |
Andi Kleen | 429b2b3 | 2009-07-18 08:56:57 +0200 | [diff] [blame] | 43 | for (i = 0; i < MAX_NUMNODES; i++) { |
Tejun Heo | 206e420 | 2011-02-16 12:13:07 +0100 | [diff] [blame] | 44 | numa_nodes[i].start = numa_nodes[i].end = 0; |
Andi Kleen | 429b2b3 | 2009-07-18 08:56:57 +0200 | [diff] [blame] | 45 | nodes_add[i].start = nodes_add[i].end = 0; |
| 46 | } |
Mel Gorman | 5cb248a | 2006-09-27 01:49:52 -0700 | [diff] [blame] | 47 | remove_all_active_ranges(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static __init inline int srat_disabled(void) |
| 51 | { |
Tejun Heo | ffe77a4 | 2011-02-16 12:13:06 +0100 | [diff] [blame] | 52 | return acpi_numa < 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | /* Callback for SLIT parsing */ |
| 56 | void __init acpi_numa_slit_init(struct acpi_table_slit *slit) |
| 57 | { |
Yinghai Lu | f302a5bb | 2008-07-10 20:36:37 -0700 | [diff] [blame] | 58 | unsigned length; |
| 59 | unsigned long phys; |
| 60 | |
| 61 | length = slit->header.length; |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 62 | phys = memblock_find_in_range(0, max_pfn_mapped<<PAGE_SHIFT, length, |
Yinghai Lu | f302a5bb | 2008-07-10 20:36:37 -0700 | [diff] [blame] | 63 | PAGE_SIZE); |
| 64 | |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 65 | if (phys == MEMBLOCK_ERROR) |
Yinghai Lu | f302a5bb | 2008-07-10 20:36:37 -0700 | [diff] [blame] | 66 | panic(" Can not save slit!\n"); |
| 67 | |
| 68 | acpi_slit = __va(phys); |
| 69 | memcpy(acpi_slit, slit, length); |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 70 | memblock_x86_reserve_range(phys, phys + length, "ACPI SLIT"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Suresh Siddha | 7237d3d | 2009-03-30 13:55:30 -0800 | [diff] [blame] | 73 | /* Callback for Proximity Domain -> x2APIC mapping */ |
| 74 | void __init |
| 75 | acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa) |
| 76 | { |
| 77 | int pxm, node; |
| 78 | int apic_id; |
| 79 | |
| 80 | if (srat_disabled()) |
| 81 | return; |
| 82 | if (pa->header.length < sizeof(struct acpi_srat_x2apic_cpu_affinity)) { |
| 83 | bad_srat(); |
| 84 | return; |
| 85 | } |
| 86 | if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0) |
| 87 | return; |
| 88 | pxm = pa->proximity_domain; |
| 89 | node = setup_node(pxm); |
| 90 | if (node < 0) { |
| 91 | printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm); |
| 92 | bad_srat(); |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | apic_id = pa->apic_id; |
Yinghai Lu | d3bd058 | 2010-12-16 19:09:58 -0800 | [diff] [blame] | 97 | if (apic_id >= MAX_LOCAL_APIC) { |
| 98 | printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node); |
| 99 | return; |
| 100 | } |
Tejun Heo | bbc9e2f | 2011-01-23 14:37:39 +0100 | [diff] [blame] | 101 | set_apicid_to_node(apic_id, node); |
Jack Steiner | dc09855 | 2009-04-17 09:22:42 -0500 | [diff] [blame] | 102 | node_set(node, cpu_nodes_parsed); |
Suresh Siddha | 7237d3d | 2009-03-30 13:55:30 -0800 | [diff] [blame] | 103 | acpi_numa = 1; |
Yinghai Lu | 163d386 | 2009-11-21 00:23:37 -0800 | [diff] [blame] | 104 | printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u\n", |
Suresh Siddha | 7237d3d | 2009-03-30 13:55:30 -0800 | [diff] [blame] | 105 | pxm, apic_id, node); |
| 106 | } |
| 107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | /* Callback for Proximity Domain -> LAPIC mapping */ |
| 109 | void __init |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 110 | acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | { |
| 112 | int pxm, node; |
travis@sgi.com | ef97001 | 2008-01-30 13:33:10 +0100 | [diff] [blame] | 113 | int apic_id; |
| 114 | |
Andi Kleen | d22fe80 | 2006-02-03 21:51:26 +0100 | [diff] [blame] | 115 | if (srat_disabled()) |
| 116 | return; |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 117 | if (pa->header.length != sizeof(struct acpi_srat_cpu_affinity)) { |
Andi Kleen | fad7906 | 2006-05-15 18:19:44 +0200 | [diff] [blame] | 118 | bad_srat(); |
Andi Kleen | d22fe80 | 2006-02-03 21:51:26 +0100 | [diff] [blame] | 119 | return; |
| 120 | } |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 121 | if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | return; |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 123 | pxm = pa->proximity_domain_lo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | node = setup_node(pxm); |
| 125 | if (node < 0) { |
| 126 | printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm); |
| 127 | bad_srat(); |
| 128 | return; |
| 129 | } |
Yinghai Lu | beafe91 | 2008-02-16 23:00:22 -0800 | [diff] [blame] | 130 | |
Jack Steiner | 2e42060 | 2008-09-23 15:37:13 -0500 | [diff] [blame] | 131 | if (get_uv_system_type() >= UV_X2APIC) |
Jack Steiner | a65d1d6 | 2008-03-28 14:12:08 -0500 | [diff] [blame] | 132 | apic_id = (pa->apic_id << 8) | pa->local_sapic_eid; |
| 133 | else |
| 134 | apic_id = pa->apic_id; |
Yinghai Lu | d3bd058 | 2010-12-16 19:09:58 -0800 | [diff] [blame] | 135 | |
| 136 | if (apic_id >= MAX_LOCAL_APIC) { |
| 137 | printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node); |
| 138 | return; |
| 139 | } |
| 140 | |
Tejun Heo | bbc9e2f | 2011-01-23 14:37:39 +0100 | [diff] [blame] | 141 | set_apicid_to_node(apic_id, node); |
Jack Steiner | dc09855 | 2009-04-17 09:22:42 -0500 | [diff] [blame] | 142 | node_set(node, cpu_nodes_parsed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | acpi_numa = 1; |
Yinghai Lu | 163d386 | 2009-11-21 00:23:37 -0800 | [diff] [blame] | 144 | 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] | 145 | pxm, apic_id, node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Keith Mannthey | 71efa8f | 2006-09-30 23:27:05 -0700 | [diff] [blame] | 148 | #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE |
| 149 | static inline int save_add_info(void) {return 1;} |
| 150 | #else |
| 151 | static inline int save_add_info(void) {return 0;} |
| 152 | #endif |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 153 | /* |
Yinghai Lu | 888a589 | 2009-05-15 13:59:37 -0700 | [diff] [blame] | 154 | * Update nodes_add[] |
| 155 | * This code supports one contiguous hot add area per node |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 156 | */ |
Yinghai Lu | 888a589 | 2009-05-15 13:59:37 -0700 | [diff] [blame] | 157 | static void __init |
| 158 | update_nodes_add(int node, unsigned long start, unsigned long end) |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 159 | { |
| 160 | unsigned long s_pfn = start >> PAGE_SHIFT; |
| 161 | unsigned long e_pfn = end >> PAGE_SHIFT; |
Yinghai Lu | 888a589 | 2009-05-15 13:59:37 -0700 | [diff] [blame] | 162 | int changed = 0; |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 163 | struct bootnode *nd = &nodes_add[node]; |
| 164 | |
| 165 | /* I had some trouble with strange memory hotadd regions breaking |
| 166 | the boot. Be very strict here and reject anything unexpected. |
| 167 | If you want working memory hotadd write correct SRATs. |
| 168 | |
| 169 | The node size check is a basic sanity check to guard against |
| 170 | mistakes */ |
| 171 | if ((signed long)(end - start) < NODE_MIN_SIZE) { |
| 172 | printk(KERN_ERR "SRAT: Hotplug area too small\n"); |
Yinghai Lu | 888a589 | 2009-05-15 13:59:37 -0700 | [diff] [blame] | 173 | return; |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | /* 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] | 177 | 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] | 178 | printk(KERN_ERR |
| 179 | "SRAT: Hotplug area %lu -> %lu has existing memory\n", |
| 180 | s_pfn, e_pfn); |
Yinghai Lu | 888a589 | 2009-05-15 13:59:37 -0700 | [diff] [blame] | 181 | return; |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | /* Looks good */ |
| 185 | |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 186 | if (nd->start == nd->end) { |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 187 | nd->start = start; |
| 188 | nd->end = end; |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 189 | changed = 1; |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 190 | } else { |
| 191 | if (nd->start == end) { |
| 192 | nd->start = start; |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 193 | changed = 1; |
| 194 | } |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 195 | if (nd->end == start) { |
| 196 | nd->end = end; |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 197 | changed = 1; |
| 198 | } |
| 199 | if (!changed) |
| 200 | printk(KERN_ERR "SRAT: Hotplug zone not continuous. Partly ignored\n"); |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 201 | } |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 202 | |
David Rientjes | 3a5fc0e | 2010-01-20 12:10:47 -0800 | [diff] [blame] | 203 | if (changed) { |
| 204 | node_set(node, cpu_nodes_parsed); |
Yinghai Lu | 888a589 | 2009-05-15 13:59:37 -0700 | [diff] [blame] | 205 | printk(KERN_INFO "SRAT: hot plug zone found %Lx - %Lx\n", |
| 206 | nd->start, nd->end); |
David Rientjes | 3a5fc0e | 2010-01-20 12:10:47 -0800 | [diff] [blame] | 207 | } |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 208 | } |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | /* Callback for parsing of the Proximity Domain <-> Memory Area mappings */ |
| 211 | void __init |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 212 | acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | { |
Tejun Heo | 13081df | 2011-02-16 12:13:06 +0100 | [diff] [blame] | 214 | struct bootnode *nd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | unsigned long start, end; |
| 216 | int node, pxm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
Andi Kleen | d22fe80 | 2006-02-03 21:51:26 +0100 | [diff] [blame] | 218 | if (srat_disabled()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | return; |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 220 | if (ma->header.length != sizeof(struct acpi_srat_mem_affinity)) { |
Andi Kleen | d22fe80 | 2006-02-03 21:51:26 +0100 | [diff] [blame] | 221 | bad_srat(); |
| 222 | return; |
| 223 | } |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 224 | if ((ma->flags & ACPI_SRAT_MEM_ENABLED) == 0) |
Andi Kleen | d22fe80 | 2006-02-03 21:51:26 +0100 | [diff] [blame] | 225 | return; |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 226 | |
| 227 | if ((ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) && !save_add_info()) |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 228 | return; |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 229 | start = ma->base_address; |
| 230 | end = start + ma->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | pxm = ma->proximity_domain; |
| 232 | node = setup_node(pxm); |
| 233 | if (node < 0) { |
| 234 | printk(KERN_ERR "SRAT: Too many proximity domains.\n"); |
| 235 | bad_srat(); |
| 236 | return; |
| 237 | } |
Tejun Heo | ef396ec | 2011-02-16 17:11:07 +0100 | [diff] [blame^] | 238 | |
| 239 | if (numa_add_memblk(node, start, end) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | bad_srat(); |
| 241 | return; |
| 242 | } |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 243 | |
Suresh Siddha | 6ec6e0d | 2008-03-25 10:14:35 -0700 | [diff] [blame] | 244 | printk(KERN_INFO "SRAT: Node %u PXM %u %lx-%lx\n", node, pxm, |
| 245 | start, end); |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 246 | |
Tejun Heo | 13081df | 2011-02-16 12:13:06 +0100 | [diff] [blame] | 247 | if (!(ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE)) { |
Tejun Heo | 206e420 | 2011-02-16 12:13:07 +0100 | [diff] [blame] | 248 | nd = &numa_nodes[node]; |
Tejun Heo | ec8cf29b | 2011-02-16 12:13:07 +0100 | [diff] [blame] | 249 | if (!node_test_and_set(node, mem_nodes_parsed)) { |
Tejun Heo | 13081df | 2011-02-16 12:13:06 +0100 | [diff] [blame] | 250 | nd->start = start; |
| 251 | nd->end = end; |
| 252 | } else { |
| 253 | if (start < nd->start) |
| 254 | nd->start = start; |
| 255 | if (nd->end < end) |
| 256 | nd->end = end; |
| 257 | } |
| 258 | } else |
Yinghai Lu | 888a589 | 2009-05-15 13:59:37 -0700 | [diff] [blame] | 259 | update_nodes_add(node, start, end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Andi Kleen | 8a6fdd3 | 2006-01-11 22:44:39 +0100 | [diff] [blame] | 262 | /* Sanity check to catch more bad SRATs (they are amazingly common). |
| 263 | Make sure the PXMs cover all memory. */ |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 264 | static int __init nodes_cover_memory(const struct bootnode *nodes) |
Andi Kleen | 8a6fdd3 | 2006-01-11 22:44:39 +0100 | [diff] [blame] | 265 | { |
| 266 | int i; |
| 267 | unsigned long pxmram, e820ram; |
| 268 | |
| 269 | pxmram = 0; |
Tejun Heo | ec8cf29b | 2011-02-16 12:13:07 +0100 | [diff] [blame] | 270 | for_each_node_mask(i, mem_nodes_parsed) { |
Andi Kleen | 8a6fdd3 | 2006-01-11 22:44:39 +0100 | [diff] [blame] | 271 | unsigned long s = nodes[i].start >> PAGE_SHIFT; |
| 272 | unsigned long e = nodes[i].end >> PAGE_SHIFT; |
| 273 | pxmram += e - s; |
Yinghai Lu | 3299625 | 2009-12-15 17:59:02 -0800 | [diff] [blame] | 274 | pxmram -= __absent_pages_in_range(i, s, e); |
Andi Kleen | 68a3a7f | 2006-04-07 19:49:18 +0200 | [diff] [blame] | 275 | if ((long)pxmram < 0) |
| 276 | pxmram = 0; |
Andi Kleen | 8a6fdd3 | 2006-01-11 22:44:39 +0100 | [diff] [blame] | 277 | } |
| 278 | |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 279 | e820ram = max_pfn - (memblock_x86_hole_size(0, max_pfn<<PAGE_SHIFT)>>PAGE_SHIFT); |
Yinghai Lu | 0964b05 | 2009-05-08 00:37:34 -0700 | [diff] [blame] | 280 | /* We seem to lose 3 pages somewhere. Allow 1M of slack. */ |
| 281 | if ((long)(e820ram - pxmram) >= (1<<(20 - PAGE_SHIFT))) { |
Andi Kleen | 8a6fdd3 | 2006-01-11 22:44:39 +0100 | [diff] [blame] | 282 | printk(KERN_ERR |
| 283 | "SRAT: PXMs only cover %luMB of your %luMB e820 RAM. Not used.\n", |
| 284 | (pxmram << PAGE_SHIFT) >> 20, |
| 285 | (e820ram << PAGE_SHIFT) >> 20); |
| 286 | return 0; |
| 287 | } |
| 288 | return 1; |
| 289 | } |
| 290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | void __init acpi_numa_arch_fixup(void) {} |
| 292 | |
Tejun Heo | a9aec56 | 2011-02-16 12:13:06 +0100 | [diff] [blame] | 293 | int __init x86_acpi_numa_init(void) |
| 294 | { |
| 295 | int ret; |
| 296 | |
| 297 | ret = acpi_numa_init(); |
| 298 | if (ret < 0) |
| 299 | return ret; |
| 300 | return srat_disabled() ? -EINVAL : 0; |
| 301 | } |
| 302 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | /* Use the information discovered above to actually set up the nodes. */ |
Tejun Heo | 940fed2 | 2011-02-16 12:13:06 +0100 | [diff] [blame] | 304 | int __init acpi_scan_nodes(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | { |
| 306 | int i; |
Andi Kleen | 8a6fdd3 | 2006-01-11 22:44:39 +0100 | [diff] [blame] | 307 | |
David Rientjes | ae2c6dc | 2007-07-21 17:09:56 +0200 | [diff] [blame] | 308 | if (acpi_numa <= 0) |
| 309 | return -1; |
| 310 | |
Tejun Heo | ef396ec | 2011-02-16 17:11:07 +0100 | [diff] [blame^] | 311 | if (numa_register_memblks() < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | bad_srat(); |
| 313 | return -1; |
| 314 | } |
Andi Kleen | e58e0d0 | 2005-09-12 18:49:25 +0200 | [diff] [blame] | 315 | |
Yinghai Lu | 3299625 | 2009-12-15 17:59:02 -0800 | [diff] [blame] | 316 | /* for out of order entries in SRAT */ |
| 317 | sort_node_map(); |
Tejun Heo | 206e420 | 2011-02-16 12:13:07 +0100 | [diff] [blame] | 318 | if (!nodes_cover_memory(numa_nodes)) { |
David Rientjes | 8716273 | 2009-09-25 15:20:04 -0700 | [diff] [blame] | 319 | bad_srat(); |
| 320 | return -1; |
| 321 | } |
| 322 | |
Yinghai Lu | 1411e0e | 2010-12-27 16:48:17 -0800 | [diff] [blame] | 323 | init_memory_mapping_high(); |
| 324 | |
Andi Kleen | e58e0d0 | 2005-09-12 18:49:25 +0200 | [diff] [blame] | 325 | /* Finally register nodes */ |
Suresh Siddha | e3f1cae | 2007-05-02 19:27:20 +0200 | [diff] [blame] | 326 | for_each_node_mask(i, node_possible_map) |
Tejun Heo | 206e420 | 2011-02-16 12:13:07 +0100 | [diff] [blame] | 327 | setup_node_bootmem(i, numa_nodes[i].start, numa_nodes[i].end); |
Andi Kleen | a806223 | 2006-04-07 19:49:21 +0200 | [diff] [blame] | 328 | /* Try again in case setup_node_bootmem missed one due |
| 329 | to missing bootmem */ |
Suresh Siddha | e3f1cae | 2007-05-02 19:27:20 +0200 | [diff] [blame] | 330 | for_each_node_mask(i, node_possible_map) |
Andi Kleen | a806223 | 2006-04-07 19:49:21 +0200 | [diff] [blame] | 331 | if (!node_online(i)) |
Tejun Heo | 206e420 | 2011-02-16 12:13:07 +0100 | [diff] [blame] | 332 | setup_node_bootmem(i, numa_nodes[i].start, |
| 333 | numa_nodes[i].end); |
Andi Kleen | a806223 | 2006-04-07 19:49:21 +0200 | [diff] [blame] | 334 | |
Mike Travis | 168ef54 | 2008-12-16 17:34:01 -0800 | [diff] [blame] | 335 | for (i = 0; i < nr_cpu_ids; i++) { |
Mike Travis | 0164fe1 | 2008-01-30 13:33:21 +0100 | [diff] [blame] | 336 | int node = early_cpu_to_node(i); |
| 337 | |
travis@sgi.com | 834beda1 | 2008-01-30 13:33:21 +0100 | [diff] [blame] | 338 | if (node == NUMA_NO_NODE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | continue; |
Yinghai Lu | 7c43769 | 2009-05-15 13:59:37 -0700 | [diff] [blame] | 340 | if (!node_online(node)) |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 341 | numa_clear_node(i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | } |
| 343 | numa_init_array(); |
| 344 | return 0; |
| 345 | } |
| 346 | |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 347 | #ifdef CONFIG_NUMA_EMU |
travis@sgi.com | ef97001 | 2008-01-30 13:33:10 +0100 | [diff] [blame] | 348 | static int fake_node_to_pxm_map[MAX_NUMNODES] __initdata = { |
| 349 | [0 ... MAX_NUMNODES-1] = PXM_INVAL |
| 350 | }; |
travis@sgi.com | 602a54a | 2008-01-30 13:33:21 +0100 | [diff] [blame] | 351 | static s16 fake_apicid_to_node[MAX_LOCAL_APIC] __initdata = { |
travis@sgi.com | ef97001 | 2008-01-30 13:33:10 +0100 | [diff] [blame] | 352 | [0 ... MAX_LOCAL_APIC-1] = NUMA_NO_NODE |
| 353 | }; |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 354 | static int __init find_node_by_addr(unsigned long addr) |
| 355 | { |
| 356 | int ret = NUMA_NO_NODE; |
| 357 | int i; |
| 358 | |
Tejun Heo | ec8cf29b | 2011-02-16 12:13:07 +0100 | [diff] [blame] | 359 | for_each_node_mask(i, mem_nodes_parsed) { |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 360 | /* |
| 361 | * Find the real node that this emulated node appears on. For |
| 362 | * the sake of simplicity, we only use a real node's starting |
| 363 | * address to determine which emulated node it appears on. |
| 364 | */ |
Tejun Heo | 206e420 | 2011-02-16 12:13:07 +0100 | [diff] [blame] | 365 | if (addr >= numa_nodes[i].start && addr < numa_nodes[i].end) { |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 366 | ret = i; |
| 367 | break; |
| 368 | } |
| 369 | } |
Minoru Usui | 9a1b62f | 2008-01-30 13:33:35 +0100 | [diff] [blame] | 370 | return ret; |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | /* |
| 374 | * In NUMA emulation, we need to setup proximity domain (_PXM) to node ID |
| 375 | * mappings that respect the real ACPI topology but reflect our emulated |
| 376 | * environment. For each emulated node, we find which real node it appears on |
| 377 | * and create PXM to NID mappings for those fake nodes which mirror that |
| 378 | * locality. SLIT will now represent the correct distances between emulated |
| 379 | * nodes as a result of the real topology. |
| 380 | */ |
| 381 | void __init acpi_fake_nodes(const struct bootnode *fake_nodes, int num_nodes) |
| 382 | { |
David Rientjes | 08705b8 | 2007-07-21 17:10:33 +0200 | [diff] [blame] | 383 | int i, j; |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 384 | |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 385 | for (i = 0; i < num_nodes; i++) { |
| 386 | int nid, pxm; |
| 387 | |
| 388 | nid = find_node_by_addr(fake_nodes[i].start); |
| 389 | if (nid == NUMA_NO_NODE) |
| 390 | continue; |
| 391 | pxm = node_to_pxm(nid); |
| 392 | if (pxm == PXM_INVAL) |
| 393 | continue; |
| 394 | fake_node_to_pxm_map[i] = pxm; |
David Rientjes | 08705b8 | 2007-07-21 17:10:33 +0200 | [diff] [blame] | 395 | /* |
| 396 | * For each apicid_to_node mapping that exists for this real |
| 397 | * node, it must now point to the fake node ID. |
| 398 | */ |
| 399 | for (j = 0; j < MAX_LOCAL_APIC; j++) |
Tejun Heo | bbc9e2f | 2011-01-23 14:37:39 +0100 | [diff] [blame] | 400 | if (__apicid_to_node[j] == nid && |
David Rientjes | b0c4d95 | 2010-05-06 02:24:34 -0700 | [diff] [blame] | 401 | fake_apicid_to_node[j] == NUMA_NO_NODE) |
David Rientjes | 08705b8 | 2007-07-21 17:10:33 +0200 | [diff] [blame] | 402 | fake_apicid_to_node[j] = i; |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 403 | } |
David Rientjes | a387e95 | 2010-12-22 17:23:56 -0800 | [diff] [blame] | 404 | |
| 405 | /* |
| 406 | * If there are apicid-to-node mappings for physical nodes that do not |
| 407 | * have a corresponding emulated node, it should default to a guaranteed |
| 408 | * value. |
| 409 | */ |
| 410 | for (i = 0; i < MAX_LOCAL_APIC; i++) |
Tejun Heo | bbc9e2f | 2011-01-23 14:37:39 +0100 | [diff] [blame] | 411 | if (__apicid_to_node[i] != NUMA_NO_NODE && |
David Rientjes | a387e95 | 2010-12-22 17:23:56 -0800 | [diff] [blame] | 412 | fake_apicid_to_node[i] == NUMA_NO_NODE) |
| 413 | fake_apicid_to_node[i] = 0; |
| 414 | |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 415 | for (i = 0; i < num_nodes; i++) |
| 416 | __acpi_map_pxm_to_node(fake_node_to_pxm_map[i], i); |
Tejun Heo | bbc9e2f | 2011-01-23 14:37:39 +0100 | [diff] [blame] | 417 | memcpy(__apicid_to_node, fake_apicid_to_node, sizeof(__apicid_to_node)); |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 418 | |
Tejun Heo | ec8cf29b | 2011-02-16 12:13:07 +0100 | [diff] [blame] | 419 | nodes_clear(mem_nodes_parsed); |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 420 | for (i = 0; i < num_nodes; i++) |
| 421 | if (fake_nodes[i].start != fake_nodes[i].end) |
Tejun Heo | ec8cf29b | 2011-02-16 12:13:07 +0100 | [diff] [blame] | 422 | node_set(i, mem_nodes_parsed); |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | static int null_slit_node_compare(int a, int b) |
| 426 | { |
| 427 | return node_to_pxm(a) == node_to_pxm(b); |
| 428 | } |
| 429 | #else |
| 430 | static int null_slit_node_compare(int a, int b) |
| 431 | { |
| 432 | return a == b; |
| 433 | } |
| 434 | #endif /* CONFIG_NUMA_EMU */ |
| 435 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | int __node_distance(int a, int b) |
| 437 | { |
| 438 | int index; |
| 439 | |
| 440 | if (!acpi_slit) |
David Rientjes | 3484d79 | 2007-07-21 17:10:32 +0200 | [diff] [blame] | 441 | return null_slit_node_compare(a, b) ? LOCAL_DISTANCE : |
| 442 | REMOTE_DISTANCE; |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 443 | index = acpi_slit->locality_count * node_to_pxm(a); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | return acpi_slit->entry[index + node_to_pxm(b)]; |
| 445 | } |
| 446 | |
| 447 | EXPORT_SYMBOL(__node_distance); |
Keith Mannthey | 4942e99 | 2006-09-30 23:27:06 -0700 | [diff] [blame] | 448 | |
Thomas Gleixner | 6a1673a | 2008-05-12 15:43:38 +0200 | [diff] [blame] | 449 | #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) || defined(CONFIG_ACPI_HOTPLUG_MEMORY) |
Keith Mannthey | 4942e99 | 2006-09-30 23:27:06 -0700 | [diff] [blame] | 450 | int memory_add_physaddr_to_nid(u64 start) |
| 451 | { |
| 452 | int i, ret = 0; |
| 453 | |
| 454 | for_each_node(i) |
| 455 | if (nodes_add[i].start <= start && nodes_add[i].end > start) |
| 456 | ret = i; |
| 457 | |
| 458 | return ret; |
| 459 | } |
Keith Mannthey | 8c2676a | 2006-09-30 23:27:07 -0700 | [diff] [blame] | 460 | EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid); |
Thomas Gleixner | 6a1673a | 2008-05-12 15:43:38 +0200 | [diff] [blame] | 461 | #endif |