Path: blob/master/arch/mips/sgi-ip27/ip27-klnuma.c
10817 views
/*1* Ported from IRIX to Linux by Kanoj Sarcar, 06/08/00.2* Copyright 2000 - 2001 Silicon Graphics, Inc.3* Copyright 2000 - 2001 Kanoj Sarcar ([email protected])4*/5#include <linux/init.h>6#include <linux/mm.h>7#include <linux/mmzone.h>8#include <linux/kernel.h>9#include <linux/nodemask.h>10#include <linux/string.h>1112#include <asm/page.h>13#include <asm/sections.h>14#include <asm/sn/types.h>15#include <asm/sn/arch.h>16#include <asm/sn/gda.h>17#include <asm/sn/hub.h>18#include <asm/sn/mapped_kernel.h>19#include <asm/sn/sn_private.h>2021static cpumask_t ktext_repmask;2223/*24* XXX - This needs to be much smarter about where it puts copies of the25* kernel. For example, we should never put a copy on a headless node,26* and we should respect the topology of the machine.27*/28void __init setup_replication_mask(void)29{30/* Set only the master cnode's bit. The master cnode is always 0. */31cpus_clear(ktext_repmask);32cpu_set(0, ktext_repmask);3334#ifdef CONFIG_REPLICATE_KTEXT35#ifndef CONFIG_MAPPED_KERNEL36#error Kernel replication works with mapped kernel support. No calias support.37#endif38{39cnodeid_t cnode;4041for_each_online_node(cnode) {42if (cnode == 0)43continue;44/* Advertise that we have a copy of the kernel */45cpu_set(cnode, ktext_repmask);46}47}48#endif49/* Set up a GDA pointer to the replication mask. */50GDA->g_ktext_repmask = &ktext_repmask;51}525354static __init void set_ktext_source(nasid_t client_nasid, nasid_t server_nasid)55{56kern_vars_t *kvp;5758kvp = &hub_data(client_nasid)->kern_vars;5960KERN_VARS_ADDR(client_nasid) = (unsigned long)kvp;6162kvp->kv_magic = KV_MAGIC;63kvp->kv_ro_nasid = server_nasid;64kvp->kv_rw_nasid = master_nasid;65kvp->kv_ro_baseaddr = NODE_CAC_BASE(server_nasid);66kvp->kv_rw_baseaddr = NODE_CAC_BASE(master_nasid);67printk("REPLICATION: ON nasid %d, ktext from nasid %d, kdata from nasid %d\n", client_nasid, server_nasid, master_nasid);68}6970/* XXX - When the BTE works, we should use it instead of this. */71static __init void copy_kernel(nasid_t dest_nasid)72{73unsigned long dest_kern_start, source_start, source_end, kern_size;7475source_start = (unsigned long) _stext;76source_end = (unsigned long) _etext;77kern_size = source_end - source_start;7879dest_kern_start = CHANGE_ADDR_NASID(MAPPED_KERN_RO_TO_K0(source_start),80dest_nasid);81memcpy((void *)dest_kern_start, (void *)source_start, kern_size);82}8384void __init replicate_kernel_text()85{86cnodeid_t cnode;87nasid_t client_nasid;88nasid_t server_nasid;8990server_nasid = master_nasid;9192/* Record where the master node should get its kernel text */93set_ktext_source(master_nasid, master_nasid);9495for_each_online_node(cnode) {96if (cnode == 0)97continue;98client_nasid = COMPACT_TO_NASID_NODEID(cnode);99100/* Check if this node should get a copy of the kernel */101if (cpu_isset(cnode, ktext_repmask)) {102server_nasid = client_nasid;103copy_kernel(server_nasid);104}105106/* Record where this node should get its kernel text */107set_ktext_source(client_nasid, server_nasid);108}109}110111/*112* Return pfn of first free page of memory on a node. PROM may allocate113* data structures on the first couple of pages of the first slot of each114* node. If this is the case, getfirstfree(node) > getslotstart(node, 0).115*/116pfn_t node_getfirstfree(cnodeid_t cnode)117{118unsigned long loadbase = REP_BASE;119nasid_t nasid = COMPACT_TO_NASID_NODEID(cnode);120unsigned long offset;121122#ifdef CONFIG_MAPPED_KERNEL123loadbase += 16777216;124#endif125offset = PAGE_ALIGN((unsigned long)(&_end)) - loadbase;126if ((cnode == 0) || (cpu_isset(cnode, ktext_repmask)))127return (TO_NODE(nasid, offset) >> PAGE_SHIFT);128else129return (KDM_TO_PHYS(PAGE_ALIGN(SYMMON_STK_ADDR(nasid, 0))) >>130PAGE_SHIFT);131}132133134