xref: /openbmc/linux/arch/x86/mm/numa.c (revision 22fd411a)
1 /* Common code for 32 and 64-bit NUMA */
2 #include <linux/topology.h>
3 #include <linux/module.h>
4 #include <linux/bootmem.h>
5 #include <asm/numa.h>
6 #include <asm/acpi.h>
7 
8 int __initdata numa_off;
9 
10 static __init int numa_setup(char *opt)
11 {
12 	if (!opt)
13 		return -EINVAL;
14 	if (!strncmp(opt, "off", 3))
15 		numa_off = 1;
16 #ifdef CONFIG_NUMA_EMU
17 	if (!strncmp(opt, "fake=", 5))
18 		numa_emu_cmdline(opt + 5);
19 #endif
20 #ifdef CONFIG_ACPI_NUMA
21 	if (!strncmp(opt, "noacpi", 6))
22 		acpi_numa = -1;
23 #endif
24 	return 0;
25 }
26 early_param("numa", numa_setup);
27 
28 /*
29  * Which logical CPUs are on which nodes
30  */
31 cpumask_var_t node_to_cpumask_map[MAX_NUMNODES];
32 EXPORT_SYMBOL(node_to_cpumask_map);
33 
34 /*
35  * Allocate node_to_cpumask_map based on number of available nodes
36  * Requires node_possible_map to be valid.
37  *
38  * Note: node_to_cpumask() is not valid until after this is done.
39  * (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.)
40  */
41 void __init setup_node_to_cpumask_map(void)
42 {
43 	unsigned int node, num = 0;
44 
45 	/* setup nr_node_ids if not done yet */
46 	if (nr_node_ids == MAX_NUMNODES) {
47 		for_each_node_mask(node, node_possible_map)
48 			num = node;
49 		nr_node_ids = num + 1;
50 	}
51 
52 	/* allocate the map */
53 	for (node = 0; node < nr_node_ids; node++)
54 		alloc_bootmem_cpumask_var(&node_to_cpumask_map[node]);
55 
56 	/* cpumask_of_node() will now work */
57 	pr_debug("Node to cpumask map for %d nodes\n", nr_node_ids);
58 }
59 
60 #ifdef CONFIG_DEBUG_PER_CPU_MAPS
61 /*
62  * Returns a pointer to the bitmask of CPUs on Node 'node'.
63  */
64 const struct cpumask *cpumask_of_node(int node)
65 {
66 	if (node >= nr_node_ids) {
67 		printk(KERN_WARNING
68 			"cpumask_of_node(%d): node > nr_node_ids(%d)\n",
69 			node, nr_node_ids);
70 		dump_stack();
71 		return cpu_none_mask;
72 	}
73 	if (node_to_cpumask_map[node] == NULL) {
74 		printk(KERN_WARNING
75 			"cpumask_of_node(%d): no node_to_cpumask_map!\n",
76 			node);
77 		dump_stack();
78 		return cpu_online_mask;
79 	}
80 	return node_to_cpumask_map[node];
81 }
82 EXPORT_SYMBOL(cpumask_of_node);
83 #endif
84