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