2 * ACPI 3.0 based NUMA setup
3 * Copyright 2004 Andi Kleen, SuSE Labs.
5 * Reads the ACPI SRAT table to figure out what memory belongs to which CPUs.
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.
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>
18 #include <asm/proto.h>
21 static struct acpi_table_slit *acpi_slit;
23 static nodemask_t nodes_parsed __initdata;
24 static nodemask_t nodes_found __initdata;
25 static struct node nodes[MAX_NUMNODES] __initdata;
26 static __u8 pxm2node[256] = { [0 ... 255] = 0xff };
28 static int node_to_pxm(int n);
30 int pxm_to_node(int pxm)
32 if ((unsigned)pxm >= 256)
37 static __init int setup_node(int pxm)
39 unsigned node = pxm2node[pxm];
41 if (nodes_weight(nodes_found) >= MAX_NUMNODES)
43 node = first_unset_node(nodes_found);
44 node_set(node, nodes_found);
50 static __init int conflicting_nodes(unsigned long start, unsigned long end)
53 for_each_node_mask(i, nodes_parsed) {
54 struct node *nd = &nodes[i];
55 if (nd->start == nd->end)
57 if (nd->end > start && nd->start < end)
59 if (nd->end == end && nd->start == start)
65 static __init void cutoff_node(int i, unsigned long start, unsigned long end)
67 struct node *nd = &nodes[i];
68 if (nd->start < start) {
70 if (nd->end < nd->start)
75 if (nd->start > nd->end)
80 static __init void bad_srat(void)
83 printk(KERN_ERR "SRAT: SRAT not used.\n");
85 for (i = 0; i < MAX_LOCAL_APIC; i++)
86 apicid_to_node[i] = NUMA_NO_NODE;
89 static __init inline int srat_disabled(void)
91 return numa_off || acpi_numa < 0;
95 * A lot of BIOS fill in 10 (= no distance) everywhere. This messes
96 * up the NUMA heuristics which wants the local node to have a smaller
97 * distance than the others.
98 * Do some quick checks here and only use the SLIT if it passes.
100 static __init int slit_valid(struct acpi_table_slit *slit)
103 int d = slit->localities;
104 for (i = 0; i < d; i++) {
105 for (j = 0; j < d; j++) {
106 u8 val = slit->entry[d*i + j];
110 } else if (val <= 10)
117 /* Callback for SLIT parsing */
118 void __init acpi_numa_slit_init(struct acpi_table_slit *slit)
120 if (!slit_valid(slit)) {
121 printk(KERN_INFO "ACPI: SLIT table looks invalid. Not used.\n");
127 /* Callback for Proximity Domain -> LAPIC mapping */
129 acpi_numa_processor_affinity_init(struct acpi_table_processor_affinity *pa)
132 if (srat_disabled() || pa->flags.enabled == 0)
134 pxm = pa->proximity_domain;
135 node = setup_node(pxm);
137 printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
141 apicid_to_node[pa->apic_id] = node;
143 printk(KERN_INFO "SRAT: PXM %u -> APIC %u -> Node %u\n",
144 pxm, pa->apic_id, node);
147 /* Callback for parsing of the Proximity Domain <-> Memory Area mappings */
149 acpi_numa_memory_affinity_init(struct acpi_table_memory_affinity *ma)
152 unsigned long start, end;
156 if (srat_disabled() || ma->flags.enabled == 0)
158 pxm = ma->proximity_domain;
159 node = setup_node(pxm);
161 printk(KERN_ERR "SRAT: Too many proximity domains.\n");
165 start = ma->base_addr_lo | ((u64)ma->base_addr_hi << 32);
166 end = start + (ma->length_lo | ((u64)ma->length_hi << 32));
167 /* It is fine to add this area to the nodes data it will be used later*/
168 if (ma->flags.hot_pluggable == 1)
169 printk(KERN_INFO "SRAT: hot plug zone found %lx - %lx \n",
171 i = conflicting_nodes(start, end);
174 "SRAT: Warning: PXM %d (%lx-%lx) overlaps with itself (%Lx-%Lx)\n",
175 pxm, start, end, nodes[i].start, nodes[i].end);
178 "SRAT: PXM %d (%lx-%lx) overlaps with PXM %d (%Lx-%Lx)\n",
179 pxm, start, end, node_to_pxm(i),
180 nodes[i].start, nodes[i].end);
185 if (!node_test_and_set(node, nodes_parsed)) {
189 if (start < nd->start)
194 printk(KERN_INFO "SRAT: Node %u PXM %u %Lx-%Lx\n", node, pxm,
198 void __init acpi_numa_arch_fixup(void) {}
200 /* Use the information discovered above to actually set up the nodes. */
201 int __init acpi_scan_nodes(unsigned long start, unsigned long end)
207 /* First clean up the node list */
208 for_each_node_mask(i, nodes_parsed) {
209 cutoff_node(i, start, end);
210 if (nodes[i].start == nodes[i].end)
211 node_clear(i, nodes_parsed);
214 memnode_shift = compute_hash_shift(nodes, nodes_weight(nodes_parsed));
215 if (memnode_shift < 0) {
217 "SRAT: No NUMA node hash function found. Contact maintainer\n");
222 /* Finally register nodes */
223 for_each_node_mask(i, nodes_parsed)
224 setup_node_bootmem(i, nodes[i].start, nodes[i].end);
225 for (i = 0; i < NR_CPUS; i++) {
226 if (cpu_to_node[i] == NUMA_NO_NODE)
228 if (!node_isset(cpu_to_node[i], nodes_parsed))
229 numa_set_node(i, NUMA_NO_NODE);
235 static int node_to_pxm(int n)
238 if (pxm2node[n] == n)
240 for (i = 0; i < 256; i++)
241 if (pxm2node[i] == n)
246 int __node_distance(int a, int b)
251 return a == b ? 10 : 20;
252 index = acpi_slit->localities * node_to_pxm(a);
253 return acpi_slit->entry[index + node_to_pxm(b)];
256 EXPORT_SYMBOL(__node_distance);