root/arch/mips/sgi-ip27/ip27-klnuma.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. setup_replication_mask
  2. set_ktext_source
  3. copy_kernel
  4. replicate_kernel_text
  5. node_getfirstfree

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

/* [<][>][^][v][top][bottom][index][help] */