Back to home page

LXR

 
 

    


0001 /*
0002  * Ported from IRIX to Linux by Kanoj Sarcar, 06/08/00.
0003  * Copyright 2000 - 2001 Silicon Graphics, Inc.
0004  * Copyright 2000 - 2001 Kanoj Sarcar (kanoj@sgi.com)
0005  */
0006 #include <linux/init.h>
0007 #include <linux/mm.h>
0008 #include <linux/mmzone.h>
0009 #include <linux/kernel.h>
0010 #include <linux/nodemask.h>
0011 #include <linux/string.h>
0012 
0013 #include <asm/page.h>
0014 #include <asm/sections.h>
0015 #include <asm/sn/types.h>
0016 #include <asm/sn/arch.h>
0017 #include <asm/sn/gda.h>
0018 #include <asm/sn/hub.h>
0019 #include <asm/sn/mapped_kernel.h>
0020 #include <asm/sn/sn_private.h>
0021 
0022 static cpumask_t ktext_repmask;
0023 
0024 /*
0025  * XXX - This needs to be much smarter about where it puts copies of the
0026  * kernel.  For example, we should never put a copy on a headless node,
0027  * and we should respect the topology of the machine.
0028  */
0029 void __init setup_replication_mask(void)
0030 {
0031     /* Set only the master cnode's bit.  The master cnode is always 0. */
0032     cpumask_clear(&ktext_repmask);
0033     cpumask_set_cpu(0, &ktext_repmask);
0034 
0035 #ifdef CONFIG_REPLICATE_KTEXT
0036 #ifndef CONFIG_MAPPED_KERNEL
0037 #error Kernel replication works with mapped kernel support. No calias support.
0038 #endif
0039     {
0040         cnodeid_t   cnode;
0041 
0042         for_each_online_node(cnode) {
0043             if (cnode == 0)
0044                 continue;
0045             /* Advertise that we have a copy of the kernel */
0046             cpumask_set_cpu(cnode, &ktext_repmask);
0047         }
0048     }
0049 #endif
0050     /* Set up a GDA pointer to the replication mask. */
0051     GDA->g_ktext_repmask = &ktext_repmask;
0052 }
0053 
0054 
0055 static __init void set_ktext_source(nasid_t client_nasid, nasid_t server_nasid)
0056 {
0057     kern_vars_t *kvp;
0058 
0059     kvp = &hub_data(client_nasid)->kern_vars;
0060 
0061     KERN_VARS_ADDR(client_nasid) = (unsigned long)kvp;
0062 
0063     kvp->kv_magic = KV_MAGIC;
0064     kvp->kv_ro_nasid = server_nasid;
0065     kvp->kv_rw_nasid = master_nasid;
0066     kvp->kv_ro_baseaddr = NODE_CAC_BASE(server_nasid);
0067     kvp->kv_rw_baseaddr = NODE_CAC_BASE(master_nasid);
0068     printk("REPLICATION: ON nasid %d, ktext from nasid %d, kdata from nasid %d\n", client_nasid, server_nasid, master_nasid);
0069 }
0070 
0071 /* XXX - When the BTE works, we should use it instead of this. */
0072 static __init void copy_kernel(nasid_t dest_nasid)
0073 {
0074     unsigned long dest_kern_start, source_start, source_end, kern_size;
0075 
0076     source_start = (unsigned long) _stext;
0077     source_end = (unsigned long) _etext;
0078     kern_size = source_end - source_start;
0079 
0080     dest_kern_start = CHANGE_ADDR_NASID(MAPPED_KERN_RO_TO_K0(source_start),
0081                         dest_nasid);
0082     memcpy((void *)dest_kern_start, (void *)source_start, kern_size);
0083 }
0084 
0085 void __init replicate_kernel_text()
0086 {
0087     cnodeid_t cnode;
0088     nasid_t client_nasid;
0089     nasid_t server_nasid;
0090 
0091     server_nasid = master_nasid;
0092 
0093     /* Record where the master node should get its kernel text */
0094     set_ktext_source(master_nasid, master_nasid);
0095 
0096     for_each_online_node(cnode) {
0097         if (cnode == 0)
0098             continue;
0099         client_nasid = COMPACT_TO_NASID_NODEID(cnode);
0100 
0101         /* Check if this node should get a copy of the kernel */
0102         if (cpumask_test_cpu(cnode, &ktext_repmask)) {
0103             server_nasid = client_nasid;
0104             copy_kernel(server_nasid);
0105         }
0106 
0107         /* Record where this node should get its kernel text */
0108         set_ktext_source(client_nasid, server_nasid);
0109     }
0110 }
0111 
0112 /*
0113  * Return pfn of first free page of memory on a node. PROM may allocate
0114  * data structures on the first couple of pages of the first slot of each
0115  * node. If this is the case, getfirstfree(node) > getslotstart(node, 0).
0116  */
0117 unsigned long node_getfirstfree(cnodeid_t cnode)
0118 {
0119     unsigned long loadbase = REP_BASE;
0120     nasid_t nasid = COMPACT_TO_NASID_NODEID(cnode);
0121     unsigned long offset;
0122 
0123 #ifdef CONFIG_MAPPED_KERNEL
0124     loadbase += 16777216;
0125 #endif
0126     offset = PAGE_ALIGN((unsigned long)(&_end)) - loadbase;
0127     if ((cnode == 0) || (cpumask_test_cpu(cnode, &ktext_repmask)))
0128         return TO_NODE(nasid, offset) >> PAGE_SHIFT;
0129     else
0130         return KDM_TO_PHYS(PAGE_ALIGN(SYMMON_STK_ADDR(nasid, 0))) >> PAGE_SHIFT;
0131 }