- Linus: more PageDirty / swapcache handling
[davej-history.git] / arch / mips64 / sgi-ip27 / ip27-klnuma.c
blob5891e017ee35f79f859328a4c9a8f05668379ff5
1 /*
2 * Ported from IRIX to Linux by Kanoj Sarcar, 06/08/00.
3 * Copyright 2000 Silicon Graphics, Inc.
4 */
5 #include <linux/config.h>
6 #include <linux/init.h>
7 #include <linux/mmzone.h>
8 #include <linux/kernel.h>
9 #include <linux/string.h>
11 #include <asm/page.h>
12 #include <asm/sn/types.h>
13 #include <asm/sn/arch.h>
14 #include <asm/sn/gda.h>
15 #include <asm/mmzone.h>
16 #include <asm/sn/klkernvars.h>
17 #include <asm/sn/mapped_kernel.h>
18 #include <asm/sn/sn_private.h>
20 #define CPUMASK_CLRALL(p) (p) = 0
21 #define CPUMASK_SETB(p, bit) (p) |= 1 << (bit)
22 #define CPUMASK_TSTB(p, bit) ((p) & (1ULL << (bit)))
24 extern char _end;
25 static cpumask_t ktext_repmask;
28 * XXX - This needs to be much smarter about where it puts copies of the
29 * kernel. For example, we should never put a copy on a headless node,
30 * and we should respect the topology of the machine.
32 void __init setup_replication_mask(int maxnodes)
34 static int numa_kernel_replication_ratio;
35 cnodeid_t cnode;
37 /* Set only the master cnode's bit. The master cnode is always 0. */
38 CPUMASK_CLRALL(ktext_repmask);
39 CPUMASK_SETB(ktext_repmask, 0);
41 numa_kernel_replication_ratio = 0;
42 #ifdef CONFIG_REPLICATE_KTEXT
43 #ifndef CONFIG_MAPPED_KERNEL
44 #error Kernel replication works with mapped kernel support. No calias support.
45 #endif
46 numa_kernel_replication_ratio = 1;
47 #endif
49 for (cnode = 1; cnode < numnodes; cnode++) {
50 /* See if this node should get a copy of the kernel */
51 if (numa_kernel_replication_ratio &&
52 !(cnode % numa_kernel_replication_ratio)) {
54 /* Advertise that we have a copy of the kernel */
55 CPUMASK_SETB(ktext_repmask, cnode);
59 /* Set up a GDA pointer to the replication mask. */
60 GDA->g_ktext_repmask = &ktext_repmask;
64 static __init void set_ktext_source(nasid_t client_nasid, nasid_t server_nasid)
66 kern_vars_t *kvp;
67 cnodeid_t client_cnode;
69 client_cnode = NASID_TO_COMPACT_NODEID(client_nasid);
71 kvp = &(PLAT_NODE_DATA(client_cnode)->kern_vars);
73 KERN_VARS_ADDR(client_nasid) = (unsigned long)kvp;
75 kvp->kv_magic = KV_MAGIC;
77 kvp->kv_ro_nasid = server_nasid;
78 kvp->kv_rw_nasid = master_nasid;
79 kvp->kv_ro_baseaddr = NODE_CAC_BASE(server_nasid);
80 kvp->kv_rw_baseaddr = NODE_CAC_BASE(master_nasid);
81 printk("REPLICATION: ON nasid %d, ktext from nasid %d, kdata from nasid %d\n", client_nasid, server_nasid, master_nasid);
84 /* XXX - When the BTE works, we should use it instead of this. */
85 static __init void copy_kernel(nasid_t dest_nasid)
87 extern char _stext, _etext;
88 unsigned long dest_kern_start, source_start, source_end, kern_size;
90 source_start = (unsigned long)&_stext;
91 source_end = (unsigned long)&_etext;
92 kern_size = source_end - source_start;
94 dest_kern_start = CHANGE_ADDR_NASID(MAPPED_KERN_RO_TO_K0(source_start),
95 dest_nasid);
96 memcpy((void *)dest_kern_start, (void *)source_start, kern_size);
99 void __init replicate_kernel_text(int maxnodes)
101 cnodeid_t cnode;
102 nasid_t client_nasid;
103 nasid_t server_nasid;
105 server_nasid = master_nasid;
107 /* Record where the master node should get its kernel text */
108 set_ktext_source(master_nasid, master_nasid);
110 for (cnode = 1; cnode < maxnodes; cnode++) {
111 client_nasid = COMPACT_TO_NASID_NODEID(cnode);
113 /* Check if this node should get a copy of the kernel */
114 if (CPUMASK_TSTB(ktext_repmask, cnode)) {
115 server_nasid = client_nasid;
116 copy_kernel(server_nasid);
119 /* Record where this node should get its kernel text */
120 set_ktext_source(client_nasid, server_nasid);
125 * Return pfn of first free page of memory on a node. PROM may allocate
126 * data structures on the first couple of pages of the first slot of each
127 * node. If this is the case, getfirstfree(node) > getslotstart(node, 0).
129 pfn_t node_getfirstfree(cnodeid_t cnode)
131 unsigned long loadbase = CKSEG0;
132 nasid_t nasid = COMPACT_TO_NASID_NODEID(cnode);
133 unsigned long offset;
135 #ifdef CONFIG_MAPPED_KERNEL
136 loadbase = CKSSEG + 16777216;
137 #endif
138 offset = PAGE_ALIGN((unsigned long)(&_end)) - loadbase;
139 if ((cnode == 0) || (CPUMASK_TSTB(ktext_repmask, cnode)))
140 return (TO_NODE(nasid, offset) >> PAGE_SHIFT);
141 else
142 return (KDM_TO_PHYS(PAGE_ALIGN(SYMMON_STK_ADDR(nasid, 0))) >>
143 PAGE_SHIFT);