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 __init
int setup_node(int pxm
)
30 unsigned node
= pxm2node
[pxm
];
32 if (nodes_weight(nodes_found
) >= MAX_NUMNODES
)
34 node
= first_unset_node(nodes_found
);
35 node_set(node
, nodes_found
);
41 static __init
int conflicting_nodes(unsigned long start
, unsigned long end
)
44 for_each_online_node(i
) {
45 struct node
*nd
= &nodes
[i
];
46 if (nd
->start
== nd
->end
)
48 if (nd
->end
> start
&& nd
->start
< end
)
50 if (nd
->end
== end
&& nd
->start
== start
)
56 static __init
void cutoff_node(int i
, unsigned long start
, unsigned long end
)
58 struct node
*nd
= &nodes
[i
];
59 if (nd
->start
< start
) {
61 if (nd
->end
< nd
->start
)
68 if (nd
->start
> nd
->end
)
73 static __init
void bad_srat(void)
75 printk(KERN_ERR
"SRAT: SRAT not used.\n");
79 static __init
inline int srat_disabled(void)
81 return numa_off
|| acpi_numa
< 0;
84 /* Callback for SLIT parsing */
85 void __init
acpi_numa_slit_init(struct acpi_table_slit
*slit
)
90 /* Callback for Proximity Domain -> LAPIC mapping */
92 acpi_numa_processor_affinity_init(struct acpi_table_processor_affinity
*pa
)
95 if (srat_disabled() || pa
->flags
.enabled
== 0)
97 pxm
= pa
->proximity_domain
;
98 node
= setup_node(pxm
);
100 printk(KERN_ERR
"SRAT: Too many proximity domains %x\n", pxm
);
104 apicid_to_node
[pa
->apic_id
] = node
;
106 printk(KERN_INFO
"SRAT: PXM %u -> APIC %u -> Node %u\n",
107 pxm
, pa
->apic_id
, node
);
110 /* Callback for parsing of the Proximity Domain <-> Memory Area mappings */
112 acpi_numa_memory_affinity_init(struct acpi_table_memory_affinity
*ma
)
115 unsigned long start
, end
;
119 if (srat_disabled() || ma
->flags
.enabled
== 0)
121 pxm
= ma
->proximity_domain
;
122 node
= setup_node(pxm
);
124 printk(KERN_ERR
"SRAT: Too many proximity domains.\n");
128 start
= ma
->base_addr_lo
| ((u64
)ma
->base_addr_hi
<< 32);
129 end
= start
+ (ma
->length_lo
| ((u64
)ma
->length_hi
<< 32));
130 /* It is fine to add this area to the nodes data it will be used later*/
131 if (ma
->flags
.hot_pluggable
== 1)
132 printk(KERN_INFO
"SRAT: hot plug zone found %lx - %lx \n",
134 i
= conflicting_nodes(start
, end
);
137 "SRAT: pxm %d overlap %lx-%lx with node %d(%Lx-%Lx)\n",
138 pxm
, start
, end
, i
, nodes
[i
].start
, nodes
[i
].end
);
143 if (!node_test_and_set(node
, nodes_parsed
)) {
147 if (start
< nd
->start
)
152 if (!(nd
->end
& 0xfff))
154 printk(KERN_INFO
"SRAT: Node %u PXM %u %Lx-%Lx\n", node
, pxm
,
158 void __init
acpi_numa_arch_fixup(void) {}
160 /* Use the information discovered above to actually set up the nodes. */
161 int __init
acpi_scan_nodes(unsigned long start
, unsigned long end
)
166 memnode_shift
= compute_hash_shift(nodes
, nodes_weight(nodes_parsed
));
167 if (memnode_shift
< 0) {
169 "SRAT: No NUMA node hash function found. Contact maintainer\n");
173 for (i
= 0; i
< MAX_NUMNODES
; i
++) {
174 if (!node_isset(i
, nodes_parsed
))
176 cutoff_node(i
, start
, end
);
177 if (nodes
[i
].start
== nodes
[i
].end
) {
178 node_clear(i
, nodes_parsed
);
181 setup_node_bootmem(i
, nodes
[i
].start
, nodes
[i
].end
);
183 for (i
= 0; i
< NR_CPUS
; i
++) {
184 if (cpu_to_node
[i
] == NUMA_NO_NODE
)
186 if (!node_isset(cpu_to_node
[i
], nodes_parsed
))
187 cpu_to_node
[i
] = NUMA_NO_NODE
;
193 int node_to_pxm(int n
)
196 if (pxm2node
[n
] == n
)
198 for (i
= 0; i
< 256; i
++)
199 if (pxm2node
[i
] == n
)
204 int __node_distance(int a
, int b
)
209 return a
== b
? 10 : 20;
210 index
= acpi_slit
->localities
* node_to_pxm(a
);
211 return acpi_slit
->entry
[index
+ node_to_pxm(b
)];
214 EXPORT_SYMBOL(__node_distance
);