Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
| 6 | * Copyright (C) 2000, 05 by Ralf Baechle (ralf@linux-mips.org) |
| 7 | * Copyright (C) 2000 by Silicon Graphics, Inc. |
| 8 | * Copyright (C) 2004 by Christoph Hellwig |
| 9 | * |
Adam Buchbinder | 92a76f6 | 2016-02-25 00:44:58 -0800 | [diff] [blame] | 10 | * On SGI IP27 the ARC memory configuration data is completely bogus but |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * alternate easier to use mechanisms are available. |
| 12 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/init.h> |
| 14 | #include <linux/kernel.h> |
Tejun Heo | 9d15ffc | 2011-12-08 10:22:09 -0800 | [diff] [blame] | 15 | #include <linux/memblock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/mm.h> |
| 17 | #include <linux/mmzone.h> |
Paul Gortmaker | 26dd3e4 | 2017-01-28 21:05:57 -0500 | [diff] [blame] | 18 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/nodemask.h> |
| 20 | #include <linux/swap.h> |
Dave Hansen | 22a9835 | 2006-03-27 01:16:04 -0800 | [diff] [blame] | 21 | #include <linux/pfn.h> |
Christoph Lameter | c1f60a5 | 2006-09-25 23:31:11 -0700 | [diff] [blame] | 22 | #include <linux/highmem.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/page.h> |
Atsushi Nemoto | 6a1e552 | 2007-02-19 01:27:34 +0900 | [diff] [blame] | 24 | #include <asm/pgalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <asm/sections.h> |
| 26 | |
| 27 | #include <asm/sn/arch.h> |
| 28 | #include <asm/sn/hub.h> |
| 29 | #include <asm/sn/klconfig.h> |
| 30 | #include <asm/sn/sn_private.h> |
| 31 | |
| 32 | |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 33 | #define SLOT_PFNSHIFT (SLOT_SHIFT - PAGE_SHIFT) |
| 34 | #define PFN_NASIDSHFT (NASID_SHFT - PAGE_SHIFT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | struct node_data *__node_data[MAX_COMPACT_NODES]; |
| 37 | |
| 38 | EXPORT_SYMBOL(__node_data); |
| 39 | |
| 40 | static int fine_mode; |
| 41 | |
| 42 | static int is_fine_dirmode(void) |
| 43 | { |
Ralf Baechle | 635c9907 | 2014-10-21 14:12:49 +0200 | [diff] [blame] | 44 | return ((LOCAL_HUB_L(NI_STATUS_REV_ID) & NSRI_REGIONSIZE_MASK) >> NSRI_REGIONSIZE_SHFT) & REGIONSIZE_FINE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Thomas Bogendoerfer | db0e7d4 | 2019-02-19 16:57:15 +0100 | [diff] [blame] | 47 | static u64 get_region(cnodeid_t cnode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | { |
| 49 | if (fine_mode) |
| 50 | return COMPACT_TO_NASID_NODEID(cnode) >> NASID_TO_FINEREG_SHFT; |
| 51 | else |
| 52 | return COMPACT_TO_NASID_NODEID(cnode) >> NASID_TO_COARSEREG_SHFT; |
| 53 | } |
| 54 | |
Thomas Bogendoerfer | db0e7d4 | 2019-02-19 16:57:15 +0100 | [diff] [blame] | 55 | static u64 region_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Thomas Bogendoerfer | db0e7d4 | 2019-02-19 16:57:15 +0100 | [diff] [blame] | 57 | static void gen_region_mask(u64 *region_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
| 59 | cnodeid_t cnode; |
| 60 | |
| 61 | (*region_mask) = 0; |
| 62 | for_each_online_node(cnode) { |
| 63 | (*region_mask) |= 1ULL << get_region(cnode); |
| 64 | } |
| 65 | } |
| 66 | |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 67 | #define rou_rflag rou_flags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | static int router_distance; |
| 70 | |
| 71 | static void router_recurse(klrou_t *router_a, klrou_t *router_b, int depth) |
| 72 | { |
| 73 | klrou_t *router; |
| 74 | lboard_t *brd; |
| 75 | int port; |
| 76 | |
| 77 | if (router_a->rou_rflag == 1) |
| 78 | return; |
| 79 | |
| 80 | if (depth >= router_distance) |
| 81 | return; |
| 82 | |
| 83 | router_a->rou_rflag = 1; |
| 84 | |
| 85 | for (port = 1; port <= MAX_ROUTER_PORTS; port++) { |
| 86 | if (router_a->rou_port[port].port_nasid == INVALID_NASID) |
| 87 | continue; |
| 88 | |
| 89 | brd = (lboard_t *)NODE_OFFSET_TO_K0( |
| 90 | router_a->rou_port[port].port_nasid, |
| 91 | router_a->rou_port[port].port_offset); |
| 92 | |
| 93 | if (brd->brd_type == KLTYPE_ROUTER) { |
| 94 | router = (klrou_t *)NODE_OFFSET_TO_K0(NASID_GET(brd), brd->brd_compts[0]); |
| 95 | if (router == router_b) { |
| 96 | if (depth < router_distance) |
| 97 | router_distance = depth; |
| 98 | } |
| 99 | else |
| 100 | router_recurse(router, router_b, depth + 1); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | router_a->rou_rflag = 0; |
| 105 | } |
| 106 | |
| 107 | unsigned char __node_distances[MAX_COMPACT_NODES][MAX_COMPACT_NODES]; |
James Cowgill | 5829b0e | 2014-11-13 11:08:07 +0000 | [diff] [blame] | 108 | EXPORT_SYMBOL(__node_distances); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
| 110 | static int __init compute_node_distance(nasid_t nasid_a, nasid_t nasid_b) |
| 111 | { |
| 112 | klrou_t *router, *router_a = NULL, *router_b = NULL; |
| 113 | lboard_t *brd, *dest_brd; |
| 114 | cnodeid_t cnode; |
| 115 | nasid_t nasid; |
| 116 | int port; |
| 117 | |
| 118 | /* Figure out which routers nodes in question are connected to */ |
| 119 | for_each_online_node(cnode) { |
| 120 | nasid = COMPACT_TO_NASID_NODEID(cnode); |
| 121 | |
| 122 | if (nasid == -1) continue; |
| 123 | |
| 124 | brd = find_lboard_class((lboard_t *)KL_CONFIG_INFO(nasid), |
| 125 | KLTYPE_ROUTER); |
| 126 | |
| 127 | if (!brd) |
| 128 | continue; |
| 129 | |
| 130 | do { |
| 131 | if (brd->brd_flags & DUPLICATE_BOARD) |
| 132 | continue; |
| 133 | |
| 134 | router = (klrou_t *)NODE_OFFSET_TO_K0(NASID_GET(brd), brd->brd_compts[0]); |
| 135 | router->rou_rflag = 0; |
| 136 | |
| 137 | for (port = 1; port <= MAX_ROUTER_PORTS; port++) { |
| 138 | if (router->rou_port[port].port_nasid == INVALID_NASID) |
| 139 | continue; |
| 140 | |
| 141 | dest_brd = (lboard_t *)NODE_OFFSET_TO_K0( |
| 142 | router->rou_port[port].port_nasid, |
| 143 | router->rou_port[port].port_offset); |
| 144 | |
| 145 | if (dest_brd->brd_type == KLTYPE_IP27) { |
| 146 | if (dest_brd->brd_nasid == nasid_a) |
| 147 | router_a = router; |
| 148 | if (dest_brd->brd_nasid == nasid_b) |
| 149 | router_b = router; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | } while ((brd = find_lboard_class(KLCF_NEXT(brd), KLTYPE_ROUTER))); |
| 154 | } |
| 155 | |
| 156 | if (router_a == NULL) { |
Thomas Bogendoerfer | ab68280 | 2019-02-19 16:57:17 +0100 | [diff] [blame] | 157 | pr_info("node_distance: router_a NULL\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | return -1; |
| 159 | } |
| 160 | if (router_b == NULL) { |
Thomas Bogendoerfer | ab68280 | 2019-02-19 16:57:17 +0100 | [diff] [blame] | 161 | pr_info("node_distance: router_b NULL\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | return -1; |
| 163 | } |
| 164 | |
| 165 | if (nasid_a == nasid_b) |
| 166 | return 0; |
| 167 | |
| 168 | if (router_a == router_b) |
| 169 | return 1; |
| 170 | |
| 171 | router_distance = 100; |
| 172 | router_recurse(router_a, router_b, 2); |
| 173 | |
| 174 | return router_distance; |
| 175 | } |
| 176 | |
| 177 | static void __init init_topology_matrix(void) |
| 178 | { |
| 179 | nasid_t nasid, nasid2; |
| 180 | cnodeid_t row, col; |
| 181 | |
| 182 | for (row = 0; row < MAX_COMPACT_NODES; row++) |
| 183 | for (col = 0; col < MAX_COMPACT_NODES; col++) |
| 184 | __node_distances[row][col] = -1; |
| 185 | |
| 186 | for_each_online_node(row) { |
| 187 | nasid = COMPACT_TO_NASID_NODEID(row); |
| 188 | for_each_online_node(col) { |
| 189 | nasid2 = COMPACT_TO_NASID_NODEID(col); |
| 190 | __node_distances[row][col] = |
| 191 | compute_node_distance(nasid, nasid2); |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | static void __init dump_topology(void) |
| 197 | { |
| 198 | nasid_t nasid; |
| 199 | cnodeid_t cnode; |
| 200 | lboard_t *brd, *dest_brd; |
| 201 | int port; |
| 202 | int router_num = 0; |
| 203 | klrou_t *router; |
| 204 | cnodeid_t row, col; |
| 205 | |
Thomas Bogendoerfer | ab68280 | 2019-02-19 16:57:17 +0100 | [diff] [blame] | 206 | pr_info("************** Topology ********************\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Thomas Bogendoerfer | ab68280 | 2019-02-19 16:57:17 +0100 | [diff] [blame] | 208 | pr_info(" "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | for_each_online_node(col) |
Thomas Bogendoerfer | ab68280 | 2019-02-19 16:57:17 +0100 | [diff] [blame] | 210 | pr_cont("%02d ", col); |
| 211 | pr_cont("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | for_each_online_node(row) { |
Thomas Bogendoerfer | ab68280 | 2019-02-19 16:57:17 +0100 | [diff] [blame] | 213 | pr_info("%02d ", row); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | for_each_online_node(col) |
Thomas Bogendoerfer | ab68280 | 2019-02-19 16:57:17 +0100 | [diff] [blame] | 215 | pr_cont("%2d ", node_distance(row, col)); |
| 216 | pr_cont("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | for_each_online_node(cnode) { |
| 220 | nasid = COMPACT_TO_NASID_NODEID(cnode); |
| 221 | |
| 222 | if (nasid == -1) continue; |
| 223 | |
| 224 | brd = find_lboard_class((lboard_t *)KL_CONFIG_INFO(nasid), |
| 225 | KLTYPE_ROUTER); |
| 226 | |
| 227 | if (!brd) |
| 228 | continue; |
| 229 | |
| 230 | do { |
| 231 | if (brd->brd_flags & DUPLICATE_BOARD) |
| 232 | continue; |
Thomas Bogendoerfer | ab68280 | 2019-02-19 16:57:17 +0100 | [diff] [blame] | 233 | pr_cont("Router %d:", router_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | router_num++; |
| 235 | |
| 236 | router = (klrou_t *)NODE_OFFSET_TO_K0(NASID_GET(brd), brd->brd_compts[0]); |
| 237 | |
| 238 | for (port = 1; port <= MAX_ROUTER_PORTS; port++) { |
| 239 | if (router->rou_port[port].port_nasid == INVALID_NASID) |
| 240 | continue; |
| 241 | |
| 242 | dest_brd = (lboard_t *)NODE_OFFSET_TO_K0( |
| 243 | router->rou_port[port].port_nasid, |
| 244 | router->rou_port[port].port_offset); |
| 245 | |
| 246 | if (dest_brd->brd_type == KLTYPE_IP27) |
Thomas Bogendoerfer | ab68280 | 2019-02-19 16:57:17 +0100 | [diff] [blame] | 247 | pr_cont(" %d", dest_brd->brd_nasid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | if (dest_brd->brd_type == KLTYPE_ROUTER) |
Thomas Bogendoerfer | ab68280 | 2019-02-19 16:57:17 +0100 | [diff] [blame] | 249 | pr_cont(" r"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | } |
Thomas Bogendoerfer | ab68280 | 2019-02-19 16:57:17 +0100 | [diff] [blame] | 251 | pr_cont("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
| 253 | } while ( (brd = find_lboard_class(KLCF_NEXT(brd), KLTYPE_ROUTER)) ); |
| 254 | } |
| 255 | } |
| 256 | |
Ralf Baechle | fc0460d | 2013-05-08 03:51:58 +0200 | [diff] [blame] | 257 | static unsigned long __init slot_getbasepfn(cnodeid_t cnode, int slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { |
| 259 | nasid_t nasid = COMPACT_TO_NASID_NODEID(cnode); |
| 260 | |
Ralf Baechle | fc0460d | 2013-05-08 03:51:58 +0200 | [diff] [blame] | 261 | return ((unsigned long)nasid << PFN_NASIDSHFT) | (slot << SLOT_PFNSHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Ralf Baechle | fc0460d | 2013-05-08 03:51:58 +0200 | [diff] [blame] | 264 | static unsigned long __init slot_psize_compute(cnodeid_t node, int slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | { |
| 266 | nasid_t nasid; |
| 267 | lboard_t *brd; |
| 268 | klmembnk_t *banks; |
| 269 | unsigned long size; |
| 270 | |
| 271 | nasid = COMPACT_TO_NASID_NODEID(node); |
| 272 | /* Find the node board */ |
| 273 | brd = find_lboard((lboard_t *)KL_CONFIG_INFO(nasid), KLTYPE_IP27); |
| 274 | if (!brd) |
| 275 | return 0; |
| 276 | |
| 277 | /* Get the memory bank structure */ |
| 278 | banks = (klmembnk_t *) find_first_component(brd, KLSTRUCT_MEMBNK); |
| 279 | if (!banks) |
| 280 | return 0; |
| 281 | |
| 282 | /* Size in _Megabytes_ */ |
| 283 | size = (unsigned long)banks->membnk_bnksz[slot/4]; |
| 284 | |
| 285 | /* hack for 128 dimm banks */ |
| 286 | if (size <= 128) { |
| 287 | if (slot % 4 == 0) { |
| 288 | size <<= 20; /* size in bytes */ |
Ralf Baechle | 635c9907 | 2014-10-21 14:12:49 +0200 | [diff] [blame] | 289 | return size >> PAGE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | } else |
| 291 | return 0; |
| 292 | } else { |
| 293 | size /= 4; |
| 294 | size <<= 20; |
| 295 | return size >> PAGE_SHIFT; |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | static void __init mlreset(void) |
| 300 | { |
| 301 | int i; |
| 302 | |
| 303 | master_nasid = get_nasid(); |
| 304 | fine_mode = is_fine_dirmode(); |
| 305 | |
| 306 | /* |
| 307 | * Probe for all CPUs - this creates the cpumask and sets up the |
| 308 | * mapping tables. We need to do this as early as possible. |
| 309 | */ |
| 310 | #ifdef CONFIG_SMP |
| 311 | cpu_node_probe(); |
| 312 | #endif |
| 313 | |
| 314 | init_topology_matrix(); |
| 315 | dump_topology(); |
| 316 | |
| 317 | gen_region_mask(®ion_mask); |
| 318 | |
| 319 | setup_replication_mask(); |
| 320 | |
| 321 | /* |
| 322 | * Set all nodes' calias sizes to 8k |
| 323 | */ |
| 324 | for_each_online_node(i) { |
| 325 | nasid_t nasid; |
| 326 | |
| 327 | nasid = COMPACT_TO_NASID_NODEID(i); |
| 328 | |
| 329 | /* |
| 330 | * Always have node 0 in the region mask, otherwise |
| 331 | * CALIAS accesses get exceptions since the hub |
| 332 | * thinks it is a node 0 address. |
| 333 | */ |
| 334 | REMOTE_HUB_S(nasid, PI_REGION_PRESENT, (region_mask | 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | REMOTE_HUB_S(nasid, PI_CALIAS_SIZE, PI_CALIAS_SIZE_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
| 337 | #ifdef LATER |
| 338 | /* |
| 339 | * Set up all hubs to have a big window pointing at |
| 340 | * widget 0. Memory mode, widget 0, offset 0 |
| 341 | */ |
| 342 | REMOTE_HUB_S(nasid, IIO_ITTE(SWIN0_BIGWIN), |
| 343 | ((HUB_PIO_MAP_TO_MEM << IIO_ITTE_IOSP_SHIFT) | |
| 344 | (0 << IIO_ITTE_WIDGET_SHIFT))); |
| 345 | #endif |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | static void __init szmem(void) |
| 350 | { |
Ralf Baechle | fc0460d | 2013-05-08 03:51:58 +0200 | [diff] [blame] | 351 | unsigned long slot_psize, slot0sz = 0, nodebytes; /* Hack to detect problem configs */ |
Thomas Bogendoerfer | 2bf8ec2 | 2008-04-08 23:43:46 +0200 | [diff] [blame] | 352 | int slot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | cnodeid_t node; |
| 354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | for_each_online_node(node) { |
Thomas Bogendoerfer | 2bf8ec2 | 2008-04-08 23:43:46 +0200 | [diff] [blame] | 356 | nodebytes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | for (slot = 0; slot < MAX_MEM_SLOTS; slot++) { |
| 358 | slot_psize = slot_psize_compute(node, slot); |
| 359 | if (slot == 0) |
| 360 | slot0sz = slot_psize; |
| 361 | /* |
| 362 | * We need to refine the hack when we have replicated |
| 363 | * kernel text. |
| 364 | */ |
| 365 | nodebytes += (1LL << SLOT_SHIFT); |
Thomas Bogendoerfer | 2bf8ec2 | 2008-04-08 23:43:46 +0200 | [diff] [blame] | 366 | |
| 367 | if (!slot_psize) |
| 368 | continue; |
| 369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | if ((nodebytes >> PAGE_SHIFT) * (sizeof(struct page)) > |
Thomas Bogendoerfer | 2bf8ec2 | 2008-04-08 23:43:46 +0200 | [diff] [blame] | 371 | (slot0sz << PAGE_SHIFT)) { |
Thomas Bogendoerfer | ab68280 | 2019-02-19 16:57:17 +0100 | [diff] [blame] | 372 | pr_info("Ignoring slot %d onwards on node %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | slot, node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | slot = MAX_MEM_SLOTS; |
| 375 | continue; |
| 376 | } |
Tejun Heo | 9d15ffc | 2011-12-08 10:22:09 -0800 | [diff] [blame] | 377 | memblock_add_node(PFN_PHYS(slot_getbasepfn(node, slot)), |
| 378 | PFN_PHYS(slot_psize), node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | static void __init node_mem_init(cnodeid_t node) |
| 384 | { |
Ralf Baechle | fc0460d | 2013-05-08 03:51:58 +0200 | [diff] [blame] | 385 | unsigned long slot_firstpfn = slot_getbasepfn(node, 0); |
| 386 | unsigned long slot_freepfn = node_getfirstfree(node); |
Ralf Baechle | fc0460d | 2013-05-08 03:51:58 +0200 | [diff] [blame] | 387 | unsigned long start_pfn, end_pfn; |
Thomas Bogendoerfer | 2bf8ec2 | 2008-04-08 23:43:46 +0200 | [diff] [blame] | 388 | |
| 389 | get_pfn_range_for_nid(node, &start_pfn, &end_pfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
| 391 | /* |
| 392 | * Allocate the node data structures on the node first. |
| 393 | */ |
| 394 | __node_data[node] = __va(slot_freepfn << PAGE_SHIFT); |
Minchan Kim | 93180ce | 2012-07-31 16:46:11 -0700 | [diff] [blame] | 395 | memset(__node_data[node], 0, PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
Thomas Bogendoerfer | 2bf8ec2 | 2008-04-08 23:43:46 +0200 | [diff] [blame] | 397 | NODE_DATA(node)->node_start_pfn = start_pfn; |
| 398 | NODE_DATA(node)->node_spanned_pages = end_pfn - start_pfn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
Rusty Russell | 8dd9289 | 2015-03-05 10:49:17 +1030 | [diff] [blame] | 400 | cpumask_clear(&hub_data(node)->h_cpus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | |
| 402 | slot_freepfn += PFN_UP(sizeof(struct pglist_data) + |
| 403 | sizeof(struct hub_data)); |
| 404 | |
Thomas Bogendoerfer | 2bf8ec2 | 2008-04-08 23:43:46 +0200 | [diff] [blame] | 405 | free_bootmem_with_active_regions(node, end_pfn); |
Mike Rapoport | bcec54b | 2018-09-10 12:23:18 +0300 | [diff] [blame] | 406 | |
| 407 | memblock_reserve(slot_firstpfn << PAGE_SHIFT, |
| 408 | ((slot_freepfn - slot_firstpfn) << PAGE_SHIFT)); |
| 409 | |
Thomas Bogendoerfer | 2bf8ec2 | 2008-04-08 23:43:46 +0200 | [diff] [blame] | 410 | sparse_memory_present_with_active_regions(node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | /* |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 414 | * A node with nothing. We use it to avoid any special casing in |
Rusty Russell | 29c337a | 2009-09-24 09:34:26 -0600 | [diff] [blame] | 415 | * cpumask_of_node |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | */ |
| 417 | static struct node_data null_node = { |
| 418 | .hub = { |
| 419 | .h_cpus = CPU_MASK_NONE |
| 420 | } |
| 421 | }; |
| 422 | |
| 423 | /* |
| 424 | * Currently, the intranode memory hole support assumes that each slot |
| 425 | * contains at least 32 MBytes of memory. We assume all bootmem data |
| 426 | * fits on the first slot. |
| 427 | */ |
| 428 | void __init prom_meminit(void) |
| 429 | { |
| 430 | cnodeid_t node; |
| 431 | |
| 432 | mlreset(); |
| 433 | szmem(); |
Paul Burton | 1229ace | 2018-11-12 22:18:01 +0000 | [diff] [blame] | 434 | max_low_pfn = PHYS_PFN(memblock_end_of_DRAM()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
| 436 | for (node = 0; node < MAX_COMPACT_NODES; node++) { |
| 437 | if (node_online(node)) { |
| 438 | node_mem_init(node); |
| 439 | continue; |
| 440 | } |
| 441 | __node_data[node] = &null_node; |
| 442 | } |
| 443 | } |
| 444 | |
Atsushi Nemoto | c44e8d5 | 2006-12-30 00:43:59 +0900 | [diff] [blame] | 445 | void __init prom_free_prom_memory(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | { |
| 447 | /* We got nothing to free here ... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Jiang Liu | 31605922 | 2013-04-29 15:06:43 -0700 | [diff] [blame] | 450 | extern void setup_zero_pages(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
| 452 | void __init paging_init(void) |
| 453 | { |
Christoph Lameter | f06a968 | 2006-09-25 23:31:10 -0700 | [diff] [blame] | 454 | unsigned long zones_size[MAX_NR_ZONES] = {0, }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
| 456 | pagetable_init(); |
Thomas Bogendoerfer | 2bf8ec2 | 2008-04-08 23:43:46 +0200 | [diff] [blame] | 457 | zones_size[ZONE_NORMAL] = max_low_pfn; |
| 458 | free_area_init_nodes(zones_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | void __init mem_init(void) |
| 462 | { |
Jiang Liu | 1132137 | 2013-07-03 15:04:04 -0700 | [diff] [blame] | 463 | high_memory = (void *) __va(get_num_physpages() << PAGE_SHIFT); |
Mike Rapoport | c6ffc5c | 2018-10-30 15:09:30 -0700 | [diff] [blame] | 464 | memblock_free_all(); |
Jiang Liu | 31605922 | 2013-04-29 15:06:43 -0700 | [diff] [blame] | 465 | setup_zero_pages(); /* This comes from node 0 */ |
Jiang Liu | 1132137 | 2013-07-03 15:04:04 -0700 | [diff] [blame] | 466 | mem_init_print_info(NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | } |