| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * This file is subject to the terms and conditions of the GNU General | 
|  | 3 | * Public License.  See the file "COPYING" in the main directory of this | 
|  | 4 | * archive for more details. | 
|  | 5 | * | 
|  | 6 | * Copyright (C) 2000 - 2001 by Kanoj Sarcar (kanoj@sgi.com) | 
|  | 7 | * Copyright (C) 2000 - 2001 by Silicon Graphics, Inc. | 
|  | 8 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/kernel.h> | 
|  | 10 | #include <linux/init.h> | 
|  | 11 | #include <linux/sched.h> | 
|  | 12 | #include <linux/mm.h> | 
|  | 13 | #include <linux/module.h> | 
|  | 14 | #include <linux/cpumask.h> | 
|  | 15 | #include <asm/cpu.h> | 
|  | 16 | #include <asm/io.h> | 
|  | 17 | #include <asm/pgtable.h> | 
|  | 18 | #include <asm/time.h> | 
|  | 19 | #include <asm/sn/types.h> | 
|  | 20 | #include <asm/sn/sn0/addrs.h> | 
|  | 21 | #include <asm/sn/sn0/hubni.h> | 
|  | 22 | #include <asm/sn/sn0/hubio.h> | 
|  | 23 | #include <asm/sn/klconfig.h> | 
|  | 24 | #include <asm/sn/ioc3.h> | 
|  | 25 | #include <asm/mipsregs.h> | 
|  | 26 | #include <asm/sn/gda.h> | 
|  | 27 | #include <asm/sn/hub.h> | 
|  | 28 | #include <asm/sn/intr.h> | 
|  | 29 | #include <asm/current.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <asm/processor.h> | 
|  | 31 | #include <asm/mmu_context.h> | 
|  | 32 | #include <asm/thread_info.h> | 
|  | 33 | #include <asm/sn/launch.h> | 
|  | 34 | #include <asm/sn/sn_private.h> | 
|  | 35 | #include <asm/sn/sn0/ip27.h> | 
|  | 36 | #include <asm/sn/mapped_kernel.h> | 
|  | 37 |  | 
|  | 38 | #define CPU_NONE		(cpuid_t)-1 | 
|  | 39 |  | 
|  | 40 | static DECLARE_BITMAP(hub_init_mask, MAX_COMPACT_NODES); | 
|  | 41 | nasid_t master_nasid = INVALID_NASID; | 
|  | 42 |  | 
|  | 43 | cnodeid_t	nasid_to_compact_node[MAX_NASIDS]; | 
|  | 44 | nasid_t		compact_to_nasid_node[MAX_COMPACT_NODES]; | 
|  | 45 | cnodeid_t	cpuid_to_compact_node[MAXCPUS]; | 
|  | 46 |  | 
|  | 47 | EXPORT_SYMBOL(nasid_to_compact_node); | 
|  | 48 |  | 
| Ralf Baechle | cc6e8e0 | 2007-10-11 23:46:05 +0100 | [diff] [blame] | 49 | struct cpuinfo_ip27 sn_cpu_info[NR_CPUS]; | 
|  | 50 | EXPORT_SYMBOL_GPL(sn_cpu_info); | 
|  | 51 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | extern void pcibr_setup(cnodeid_t); | 
|  | 53 |  | 
|  | 54 | extern void xtalk_probe_node(cnodeid_t nid); | 
|  | 55 |  | 
| Ralf Baechle | 234fcd1 | 2008-03-08 09:56:28 +0000 | [diff] [blame] | 56 | static void __cpuinit per_hub_init(cnodeid_t cnode) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { | 
|  | 58 | struct hub_data *hub = hub_data(cnode); | 
|  | 59 | nasid_t nasid = COMPACT_TO_NASID_NODEID(cnode); | 
| Ralf Baechle | 4f12bfe | 2005-03-21 18:59:38 +0000 | [diff] [blame] | 60 | int i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 |  | 
|  | 62 | cpu_set(smp_processor_id(), hub->h_cpus); | 
|  | 63 |  | 
|  | 64 | if (test_and_set_bit(cnode, hub_init_mask)) | 
|  | 65 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | /* | 
|  | 67 | * Set CRB timeout at 5ms, (< PI timeout of 10ms) | 
|  | 68 | */ | 
|  | 69 | REMOTE_HUB_S(nasid, IIO_ICTP, 0x800); | 
|  | 70 | REMOTE_HUB_S(nasid, IIO_ICTO, 0xff); | 
|  | 71 |  | 
|  | 72 | hub_rtc_init(cnode); | 
|  | 73 | xtalk_probe_node(cnode); | 
|  | 74 |  | 
|  | 75 | #ifdef CONFIG_REPLICATE_EXHANDLERS | 
|  | 76 | /* | 
|  | 77 | * If this is not a headless node initialization, | 
|  | 78 | * copy over the caliased exception handlers. | 
|  | 79 | */ | 
|  | 80 | if (get_compact_nodeid() == cnode) { | 
|  | 81 | extern char except_vec2_generic, except_vec3_generic; | 
|  | 82 | extern void build_tlb_refill_handler(void); | 
|  | 83 |  | 
|  | 84 | memcpy((void *)(CKSEG0 + 0x100), &except_vec2_generic, 0x80); | 
|  | 85 | memcpy((void *)(CKSEG0 + 0x180), &except_vec3_generic, 0x80); | 
|  | 86 | build_tlb_refill_handler(); | 
|  | 87 | memcpy((void *)(CKSEG0 + 0x100), (void *) CKSEG0, 0x80); | 
|  | 88 | memcpy((void *)(CKSEG0 + 0x180), &except_vec3_generic, 0x100); | 
|  | 89 | __flush_cache_all(); | 
|  | 90 | } | 
|  | 91 | #endif | 
| Ralf Baechle | 4f12bfe | 2005-03-21 18:59:38 +0000 | [diff] [blame] | 92 |  | 
|  | 93 | /* | 
|  | 94 | * Some interrupts are reserved by hardware or by software convention. | 
|  | 95 | * Mark these as reserved right away so they won't be used accidently | 
|  | 96 | * later. | 
|  | 97 | */ | 
|  | 98 | for (i = 0; i <= BASE_PCI_IRQ; i++) { | 
|  | 99 | __set_bit(i, hub->irq_alloc_mask); | 
|  | 100 | LOCAL_HUB_CLR_INTR(INT_PEND0_BASELVL + i); | 
|  | 101 | } | 
|  | 102 |  | 
|  | 103 | __set_bit(IP_PEND0_6_63, hub->irq_alloc_mask); | 
|  | 104 | LOCAL_HUB_S(PI_INT_PEND_MOD, IP_PEND0_6_63); | 
|  | 105 |  | 
|  | 106 | for (i = NI_BRDCAST_ERR_A; i <= MSC_PANIC_INTR; i++) { | 
|  | 107 | __set_bit(i, hub->irq_alloc_mask); | 
|  | 108 | LOCAL_HUB_CLR_INTR(INT_PEND1_BASELVL + i); | 
|  | 109 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } | 
|  | 111 |  | 
| Ralf Baechle | 06d428d | 2007-10-22 10:34:13 +0100 | [diff] [blame] | 112 | void __cpuinit per_cpu_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | { | 
|  | 114 | int cpu = smp_processor_id(); | 
|  | 115 | int slice = LOCAL_HUB_L(PI_CPU_NUM); | 
|  | 116 | cnodeid_t cnode = get_compact_nodeid(); | 
|  | 117 | struct hub_data *hub = hub_data(cnode); | 
|  | 118 | struct slice_data *si = hub->slice + slice; | 
|  | 119 | int i; | 
|  | 120 |  | 
|  | 121 | if (test_and_set_bit(slice, &hub->slice_map)) | 
|  | 122 | return; | 
|  | 123 |  | 
|  | 124 | clear_c0_status(ST0_IM); | 
|  | 125 |  | 
| Ralf Baechle | 4f12bfe | 2005-03-21 18:59:38 +0000 | [diff] [blame] | 126 | per_hub_init(cnode); | 
|  | 127 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | for (i = 0; i < LEVELS_PER_SLICE; i++) | 
|  | 129 | si->level_to_irq[i] = -1; | 
|  | 130 |  | 
|  | 131 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | * We use this so we can find the local hub's data as fast as only | 
|  | 133 | * possible. | 
|  | 134 | */ | 
|  | 135 | cpu_data[cpu].data = si; | 
|  | 136 |  | 
|  | 137 | cpu_time_init(); | 
|  | 138 | install_ipi(); | 
|  | 139 |  | 
|  | 140 | /* Install our NMI handler if symmon hasn't installed one. */ | 
|  | 141 | install_cpu_nmi_handler(cputoslice(cpu)); | 
|  | 142 |  | 
|  | 143 | set_c0_status(SRB_DEV0 | SRB_DEV1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } | 
|  | 145 |  | 
|  | 146 | /* | 
|  | 147 | * get_nasid() returns the physical node id number of the caller. | 
|  | 148 | */ | 
|  | 149 | nasid_t | 
|  | 150 | get_nasid(void) | 
|  | 151 | { | 
|  | 152 | return (nasid_t)((LOCAL_HUB_L(NI_STATUS_REV_ID) & NSRI_NODEID_MASK) | 
|  | 153 | >> NSRI_NODEID_SHFT); | 
|  | 154 | } | 
|  | 155 |  | 
|  | 156 | /* | 
|  | 157 | * Map the physical node id to a virtual node id (virtual node ids are contiguous). | 
|  | 158 | */ | 
|  | 159 | cnodeid_t get_compact_nodeid(void) | 
|  | 160 | { | 
|  | 161 | return NASID_TO_COMPACT_NODEID(get_nasid()); | 
|  | 162 | } | 
|  | 163 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | static inline void ioc3_eth_init(void) | 
|  | 165 | { | 
|  | 166 | struct ioc3 *ioc3; | 
|  | 167 | nasid_t nid; | 
|  | 168 |  | 
|  | 169 | nid = get_nasid(); | 
|  | 170 | ioc3 = (struct ioc3 *) KL_CONFIG_CH_CONS_INFO(nid)->memory_base; | 
|  | 171 |  | 
|  | 172 | ioc3->eier = 0; | 
|  | 173 | } | 
|  | 174 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | extern void ip27_reboot_setup(void); | 
|  | 176 |  | 
| Ralf Baechle | 2925aba | 2006-06-18 01:32:22 +0100 | [diff] [blame] | 177 | void __init plat_mem_setup(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | { | 
|  | 179 | hubreg_t p, e, n_mode; | 
|  | 180 | nasid_t nid; | 
|  | 181 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | ip27_reboot_setup(); | 
|  | 183 |  | 
|  | 184 | /* | 
|  | 185 | * hub_rtc init and cpu clock intr enabled for later calibrate_delay. | 
|  | 186 | */ | 
|  | 187 | nid = get_nasid(); | 
|  | 188 | printk("IP27: Running on node %d.\n", nid); | 
|  | 189 |  | 
|  | 190 | p = LOCAL_HUB_L(PI_CPU_PRESENT_A) & 1; | 
|  | 191 | e = LOCAL_HUB_L(PI_CPU_ENABLE_A) & 1; | 
|  | 192 | printk("Node %d has %s primary CPU%s.\n", nid, | 
|  | 193 | p ? "a" : "no", | 
|  | 194 | e ? ", CPU is running" : ""); | 
|  | 195 |  | 
|  | 196 | p = LOCAL_HUB_L(PI_CPU_PRESENT_B) & 1; | 
|  | 197 | e = LOCAL_HUB_L(PI_CPU_ENABLE_B) & 1; | 
|  | 198 | printk("Node %d has %s secondary CPU%s.\n", nid, | 
|  | 199 | p ? "a" : "no", | 
|  | 200 | e ? ", CPU is running" : ""); | 
|  | 201 |  | 
|  | 202 | /* | 
|  | 203 | * Try to catch kernel missconfigurations and give user an | 
|  | 204 | * indication what option to select. | 
|  | 205 | */ | 
|  | 206 | n_mode = LOCAL_HUB_L(NI_STATUS_REV_ID) & NSRI_MORENODES_MASK; | 
|  | 207 | printk("Machine is in %c mode.\n", n_mode ? 'N' : 'M'); | 
| Ralf Baechle | aa9772e | 2006-06-12 00:55:14 +0100 | [diff] [blame] | 208 | #ifdef CONFIG_SGI_SN_N_MODE | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | if (!n_mode) | 
|  | 210 | panic("Kernel compiled for M mode."); | 
|  | 211 | #else | 
|  | 212 | if (n_mode) | 
|  | 213 | panic("Kernel compiled for N mode."); | 
|  | 214 | #endif | 
|  | 215 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | ioc3_eth_init(); | 
|  | 217 | per_cpu_init(); | 
|  | 218 |  | 
|  | 219 | set_io_port_base(IO_BASE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | } |