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