11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Ported from IRIX to Linux by Kanoj Sarcar, 06/08/00. 31da177e4SLinus Torvalds * Copyright 2000 - 2001 Silicon Graphics, Inc. 41da177e4SLinus Torvalds * Copyright 2000 - 2001 Kanoj Sarcar (kanoj@sgi.com) 51da177e4SLinus Torvalds */ 61da177e4SLinus Torvalds #include <linux/config.h> 71da177e4SLinus Torvalds #include <linux/init.h> 81da177e4SLinus Torvalds #include <linux/mmzone.h> 91da177e4SLinus Torvalds #include <linux/kernel.h> 101da177e4SLinus Torvalds #include <linux/nodemask.h> 111da177e4SLinus Torvalds #include <linux/string.h> 121da177e4SLinus Torvalds 131da177e4SLinus Torvalds #include <asm/page.h> 141da177e4SLinus Torvalds #include <asm/sections.h> 151da177e4SLinus Torvalds #include <asm/smp.h> 161da177e4SLinus Torvalds #include <asm/sn/types.h> 171da177e4SLinus Torvalds #include <asm/sn/arch.h> 181da177e4SLinus Torvalds #include <asm/sn/gda.h> 191da177e4SLinus Torvalds #include <asm/sn/hub.h> 201da177e4SLinus Torvalds #include <asm/sn/mapped_kernel.h> 211da177e4SLinus Torvalds #include <asm/sn/sn_private.h> 221da177e4SLinus Torvalds 231da177e4SLinus Torvalds static cpumask_t ktext_repmask; 241da177e4SLinus Torvalds 251da177e4SLinus Torvalds /* 261da177e4SLinus Torvalds * XXX - This needs to be much smarter about where it puts copies of the 271da177e4SLinus Torvalds * kernel. For example, we should never put a copy on a headless node, 281da177e4SLinus Torvalds * and we should respect the topology of the machine. 291da177e4SLinus Torvalds */ 301da177e4SLinus Torvalds void __init setup_replication_mask() 311da177e4SLinus Torvalds { 321da177e4SLinus Torvalds cnodeid_t cnode; 331da177e4SLinus Torvalds 341da177e4SLinus Torvalds /* Set only the master cnode's bit. The master cnode is always 0. */ 351da177e4SLinus Torvalds cpus_clear(ktext_repmask); 361da177e4SLinus Torvalds cpu_set(0, ktext_repmask); 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds #ifdef CONFIG_REPLICATE_KTEXT 391da177e4SLinus Torvalds #ifndef CONFIG_MAPPED_KERNEL 401da177e4SLinus Torvalds #error Kernel replication works with mapped kernel support. No calias support. 411da177e4SLinus Torvalds #endif 421da177e4SLinus Torvalds for_each_online_node(cnode) { 431da177e4SLinus Torvalds if (cnode == 0) 441da177e4SLinus Torvalds continue; 451da177e4SLinus Torvalds /* Advertise that we have a copy of the kernel */ 461da177e4SLinus Torvalds cpu_set(cnode, ktext_repmask); 471da177e4SLinus Torvalds } 481da177e4SLinus Torvalds #endif 491da177e4SLinus Torvalds /* Set up a GDA pointer to the replication mask. */ 501da177e4SLinus Torvalds GDA->g_ktext_repmask = &ktext_repmask; 511da177e4SLinus Torvalds } 521da177e4SLinus Torvalds 531da177e4SLinus Torvalds 541da177e4SLinus Torvalds static __init void set_ktext_source(nasid_t client_nasid, nasid_t server_nasid) 551da177e4SLinus Torvalds { 561da177e4SLinus Torvalds cnodeid_t client_cnode; 571da177e4SLinus Torvalds kern_vars_t *kvp; 581da177e4SLinus Torvalds 591da177e4SLinus Torvalds client_cnode = NASID_TO_COMPACT_NODEID(client_nasid); 601da177e4SLinus Torvalds 611da177e4SLinus Torvalds kvp = &hub_data(client_nasid)->kern_vars; 621da177e4SLinus Torvalds 631da177e4SLinus Torvalds KERN_VARS_ADDR(client_nasid) = (unsigned long)kvp; 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds kvp->kv_magic = KV_MAGIC; 661da177e4SLinus Torvalds kvp->kv_ro_nasid = server_nasid; 671da177e4SLinus Torvalds kvp->kv_rw_nasid = master_nasid; 681da177e4SLinus Torvalds kvp->kv_ro_baseaddr = NODE_CAC_BASE(server_nasid); 691da177e4SLinus Torvalds kvp->kv_rw_baseaddr = NODE_CAC_BASE(master_nasid); 701da177e4SLinus Torvalds printk("REPLICATION: ON nasid %d, ktext from nasid %d, kdata from nasid %d\n", client_nasid, server_nasid, master_nasid); 711da177e4SLinus Torvalds } 721da177e4SLinus Torvalds 731da177e4SLinus Torvalds /* XXX - When the BTE works, we should use it instead of this. */ 741da177e4SLinus Torvalds static __init void copy_kernel(nasid_t dest_nasid) 751da177e4SLinus Torvalds { 761da177e4SLinus Torvalds unsigned long dest_kern_start, source_start, source_end, kern_size; 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds source_start = (unsigned long) _stext; 791da177e4SLinus Torvalds source_end = (unsigned long) _etext; 801da177e4SLinus Torvalds kern_size = source_end - source_start; 811da177e4SLinus Torvalds 821da177e4SLinus Torvalds dest_kern_start = CHANGE_ADDR_NASID(MAPPED_KERN_RO_TO_K0(source_start), 831da177e4SLinus Torvalds dest_nasid); 841da177e4SLinus Torvalds memcpy((void *)dest_kern_start, (void *)source_start, kern_size); 851da177e4SLinus Torvalds } 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds void __init replicate_kernel_text() 881da177e4SLinus Torvalds { 891da177e4SLinus Torvalds cnodeid_t cnode; 901da177e4SLinus Torvalds nasid_t client_nasid; 911da177e4SLinus Torvalds nasid_t server_nasid; 921da177e4SLinus Torvalds 931da177e4SLinus Torvalds server_nasid = master_nasid; 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds /* Record where the master node should get its kernel text */ 961da177e4SLinus Torvalds set_ktext_source(master_nasid, master_nasid); 971da177e4SLinus Torvalds 981da177e4SLinus Torvalds for_each_online_node(cnode) { 991da177e4SLinus Torvalds if (cnode == 0) 1001da177e4SLinus Torvalds continue; 1011da177e4SLinus Torvalds client_nasid = COMPACT_TO_NASID_NODEID(cnode); 1021da177e4SLinus Torvalds 1031da177e4SLinus Torvalds /* Check if this node should get a copy of the kernel */ 1041da177e4SLinus Torvalds if (cpu_isset(cnode, ktext_repmask)) { 1051da177e4SLinus Torvalds server_nasid = client_nasid; 1061da177e4SLinus Torvalds copy_kernel(server_nasid); 1071da177e4SLinus Torvalds } 1081da177e4SLinus Torvalds 1091da177e4SLinus Torvalds /* Record where this node should get its kernel text */ 1101da177e4SLinus Torvalds set_ktext_source(client_nasid, server_nasid); 1111da177e4SLinus Torvalds } 1121da177e4SLinus Torvalds } 1131da177e4SLinus Torvalds 1141da177e4SLinus Torvalds /* 1151da177e4SLinus Torvalds * Return pfn of first free page of memory on a node. PROM may allocate 1161da177e4SLinus Torvalds * data structures on the first couple of pages of the first slot of each 1171da177e4SLinus Torvalds * node. If this is the case, getfirstfree(node) > getslotstart(node, 0). 1181da177e4SLinus Torvalds */ 1191da177e4SLinus Torvalds pfn_t node_getfirstfree(cnodeid_t cnode) 1201da177e4SLinus Torvalds { 1211da177e4SLinus Torvalds unsigned long loadbase = REP_BASE; 1221da177e4SLinus Torvalds nasid_t nasid = COMPACT_TO_NASID_NODEID(cnode); 1231da177e4SLinus Torvalds unsigned long offset; 1241da177e4SLinus Torvalds 1251da177e4SLinus Torvalds #ifdef CONFIG_MAPPED_KERNEL 1261da177e4SLinus Torvalds loadbase += 16777216; 1271da177e4SLinus Torvalds #endif 1281da177e4SLinus Torvalds offset = PAGE_ALIGN((unsigned long)(&_end)) - loadbase; 1291da177e4SLinus Torvalds if ((cnode == 0) || (cpu_isset(cnode, ktext_repmask))) 1301da177e4SLinus Torvalds return (TO_NODE(nasid, offset) >> PAGE_SHIFT); 1311da177e4SLinus Torvalds else 1321da177e4SLinus Torvalds return (KDM_TO_PHYS(PAGE_ALIGN(SYMMON_STK_ADDR(nasid, 0))) >> 1331da177e4SLinus Torvalds PAGE_SHIFT); 1341da177e4SLinus Torvalds } 1351da177e4SLinus Torvalds 136