blob: 8386c58fdb3a0f21811b529350eab812ab49d624 [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001// SPDX-License-Identifier: GPL-2.0
2/*
3 * NUMA support for s390
4 *
5 * Implement NUMA core code.
6 *
7 * Copyright IBM Corp. 2015
8 */
9
10#define KMSG_COMPONENT "numa"
11#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12
13#include <linux/kernel.h>
14#include <linux/mmzone.h>
15#include <linux/cpumask.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000016#include <linux/memblock.h>
17#include <linux/slab.h>
18#include <linux/node.h>
19
20#include <asm/numa.h>
21#include "numa_mode.h"
22
23pg_data_t *node_data[MAX_NUMNODES];
24EXPORT_SYMBOL(node_data);
25
26cpumask_t node_to_cpumask_map[MAX_NUMNODES];
27EXPORT_SYMBOL(node_to_cpumask_map);
28
29static void plain_setup(void)
30{
31 node_set(0, node_possible_map);
32}
33
34const struct numa_mode numa_mode_plain = {
35 .name = "plain",
36 .setup = plain_setup,
37};
38
39static const struct numa_mode *mode = &numa_mode_plain;
40
41int numa_pfn_to_nid(unsigned long pfn)
42{
43 return mode->__pfn_to_nid ? mode->__pfn_to_nid(pfn) : 0;
44}
45
46void numa_update_cpu_topology(void)
47{
48 if (mode->update_cpu_topology)
49 mode->update_cpu_topology();
50}
51
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000052int numa_debug_enabled;
53
54/*
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000055 * numa_setup_memory() - Assign bootmem to nodes
56 *
57 * The memory is first added to memblock without any respect to nodes.
58 * This is fixed before remaining memblock memory is handed over to the
59 * buddy allocator.
60 * An important side effect is that large bootmem allocations might easily
61 * cross node boundaries, which can be needed for large allocations with
62 * smaller memory stripes in each node (i.e. when using NUMA emulation).
63 *
64 * Memory defines nodes:
65 * Therefore this routine also sets the nodes online with memory.
66 */
67static void __init numa_setup_memory(void)
68{
69 unsigned long cur_base, align, end_of_dram;
70 int nid = 0;
71
72 end_of_dram = memblock_end_of_DRAM();
73 align = mode->align ? mode->align() : ULONG_MAX;
74
75 /*
76 * Step through all available memory and assign it to the nodes
77 * indicated by the mode implementation.
78 * All nodes which are seen here will be set online.
79 */
80 cur_base = 0;
81 do {
82 nid = numa_pfn_to_nid(PFN_DOWN(cur_base));
83 node_set_online(nid);
84 memblock_set_node(cur_base, align, &memblock.memory, nid);
85 cur_base += align;
86 } while (cur_base < end_of_dram);
87
88 /* Allocate and fill out node_data */
David Brazdil0f672f62019-12-10 10:32:29 +000089 for (nid = 0; nid < MAX_NUMNODES; nid++) {
90 NODE_DATA(nid) = memblock_alloc(sizeof(pg_data_t), 8);
91 if (!NODE_DATA(nid))
92 panic("%s: Failed to allocate %zu bytes align=0x%x\n",
93 __func__, sizeof(pg_data_t), 8);
94 }
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000095
96 for_each_online_node(nid) {
97 unsigned long start_pfn, end_pfn;
98 unsigned long t_start, t_end;
99 int i;
100
101 start_pfn = ULONG_MAX;
102 end_pfn = 0;
103 for_each_mem_pfn_range(i, nid, &t_start, &t_end, NULL) {
104 if (t_start < start_pfn)
105 start_pfn = t_start;
106 if (t_end > end_pfn)
107 end_pfn = t_end;
108 }
109 NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn;
110 NODE_DATA(nid)->node_id = nid;
111 }
112}
113
114/*
115 * numa_setup() - Earliest initialization
116 *
117 * Assign the mode and call the mode's setup routine.
118 */
119void __init numa_setup(void)
120{
121 pr_info("NUMA mode: %s\n", mode->name);
122 nodes_clear(node_possible_map);
123 /* Initially attach all possible CPUs to node 0. */
124 cpumask_copy(&node_to_cpumask_map[0], cpu_possible_mask);
125 if (mode->setup)
126 mode->setup();
127 numa_setup_memory();
128 memblock_dump_all();
129}
130
131/*
132 * numa_init_late() - Initialization initcall
133 *
134 * Register NUMA nodes.
135 */
136static int __init numa_init_late(void)
137{
138 int nid;
139
140 for_each_online_node(nid)
141 register_one_node(nid);
142 return 0;
143}
144arch_initcall(numa_init_late);
145
146static int __init parse_debug(char *parm)
147{
148 numa_debug_enabled = 1;
149 return 0;
150}
151early_param("numa_debug", parse_debug);
152
153static int __init parse_numa(char *parm)
154{
David Brazdil0f672f62019-12-10 10:32:29 +0000155 if (!parm)
156 return 1;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000157 if (strcmp(parm, numa_mode_plain.name) == 0)
158 mode = &numa_mode_plain;
159#ifdef CONFIG_NUMA_EMU
160 if (strcmp(parm, numa_mode_emu.name) == 0)
161 mode = &numa_mode_emu;
162#endif
163 return 0;
164}
165early_param("numa", parse_numa);