^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Ported from IRIX to Linux by Kanoj Sarcar, 06/08/00.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright 2000 - 2001 Silicon Graphics, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2000 - 2001 Kanoj Sarcar (kanoj@sgi.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/mmzone.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/nodemask.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <asm/sn/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <asm/sn/arch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <asm/sn/gda.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <asm/sn/mapped_kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "ip27-common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static nodemask_t ktext_repmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * XXX - This needs to be much smarter about where it puts copies of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * kernel. For example, we should never put a copy on a headless node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * and we should respect the topology of the machine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) void __init setup_replication_mask(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /* Set only the master cnode's bit. The master cnode is always 0. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) nodes_clear(ktext_repmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) node_set(0, ktext_repmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #ifdef CONFIG_REPLICATE_KTEXT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #ifndef CONFIG_MAPPED_KERNEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #error Kernel replication works with mapped kernel support. No calias support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) nasid_t nasid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) for_each_online_node(nasid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) if (nasid == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) /* Advertise that we have a copy of the kernel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) node_set(nasid, ktext_repmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /* Set up a GDA pointer to the replication mask. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) GDA->g_ktext_repmask = &ktext_repmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static __init void set_ktext_source(nasid_t client_nasid, nasid_t server_nasid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) kern_vars_t *kvp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) kvp = &hub_data(client_nasid)->kern_vars;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) KERN_VARS_ADDR(client_nasid) = (unsigned long)kvp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) kvp->kv_magic = KV_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) kvp->kv_ro_nasid = server_nasid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) kvp->kv_rw_nasid = master_nasid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) kvp->kv_ro_baseaddr = NODE_CAC_BASE(server_nasid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) kvp->kv_rw_baseaddr = NODE_CAC_BASE(master_nasid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) printk("REPLICATION: ON nasid %d, ktext from nasid %d, kdata from nasid %d\n", client_nasid, server_nasid, master_nasid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* XXX - When the BTE works, we should use it instead of this. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static __init void copy_kernel(nasid_t dest_nasid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) unsigned long dest_kern_start, source_start, source_end, kern_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) source_start = (unsigned long) _stext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) source_end = (unsigned long) _etext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) kern_size = source_end - source_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) dest_kern_start = CHANGE_ADDR_NASID(MAPPED_KERN_RO_TO_K0(source_start),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) dest_nasid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) memcpy((void *)dest_kern_start, (void *)source_start, kern_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) void __init replicate_kernel_text(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) nasid_t client_nasid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) nasid_t server_nasid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) server_nasid = master_nasid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /* Record where the master node should get its kernel text */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) set_ktext_source(master_nasid, master_nasid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) for_each_online_node(client_nasid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (client_nasid == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /* Check if this node should get a copy of the kernel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (node_isset(client_nasid, ktext_repmask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) server_nasid = client_nasid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) copy_kernel(server_nasid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /* Record where this node should get its kernel text */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) set_ktext_source(client_nasid, server_nasid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * Return pfn of first free page of memory on a node. PROM may allocate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * data structures on the first couple of pages of the first slot of each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * node. If this is the case, getfirstfree(node) > getslotstart(node, 0).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) unsigned long node_getfirstfree(nasid_t nasid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) unsigned long loadbase = REP_BASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) unsigned long offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #ifdef CONFIG_MAPPED_KERNEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) loadbase += 16777216;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) offset = PAGE_ALIGN((unsigned long)(&_end)) - loadbase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if ((nasid == 0) || (node_isset(nasid, ktext_repmask)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return TO_NODE(nasid, offset) >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return KDM_TO_PHYS(PAGE_ALIGN(SYMMON_STK_ADDR(nasid, 0))) >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }