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