xref: /openbmc/linux/arch/mips/sgi-ip27/ip27-init.c (revision be709d48)
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  */
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <linux/sched.h>
12 #include <linux/smp.h>
13 #include <linux/mm.h>
14 #include <linux/export.h>
15 #include <linux/cpumask.h>
16 #include <asm/cpu.h>
17 #include <asm/io.h>
18 #include <asm/pgtable.h>
19 #include <asm/time.h>
20 #include <asm/sn/types.h>
21 #include <asm/sn/sn0/addrs.h>
22 #include <asm/sn/sn0/hubni.h>
23 #include <asm/sn/sn0/hubio.h>
24 #include <asm/sn/klconfig.h>
25 #include <asm/sn/ioc3.h>
26 #include <asm/mipsregs.h>
27 #include <asm/sn/gda.h>
28 #include <asm/sn/hub.h>
29 #include <asm/sn/intr.h>
30 #include <asm/current.h>
31 #include <asm/processor.h>
32 #include <asm/mmu_context.h>
33 #include <asm/thread_info.h>
34 #include <asm/sn/launch.h>
35 #include <asm/sn/sn_private.h>
36 #include <asm/sn/sn0/ip27.h>
37 #include <asm/sn/mapped_kernel.h>
38 
39 #define CPU_NONE		(cpuid_t)-1
40 
41 static DECLARE_BITMAP(hub_init_mask, MAX_COMPACT_NODES);
42 nasid_t master_nasid = INVALID_NASID;
43 
44 cnodeid_t	nasid_to_compact_node[MAX_NASIDS];
45 nasid_t		compact_to_nasid_node[MAX_COMPACT_NODES];
46 cnodeid_t	cpuid_to_compact_node[MAXCPUS];
47 
48 EXPORT_SYMBOL(nasid_to_compact_node);
49 
50 struct cpuinfo_ip27 sn_cpu_info[NR_CPUS];
51 EXPORT_SYMBOL_GPL(sn_cpu_info);
52 
53 extern void pcibr_setup(cnodeid_t);
54 
55 static void per_hub_init(cnodeid_t cnode)
56 {
57 	struct hub_data *hub = hub_data(cnode);
58 	nasid_t nasid = COMPACT_TO_NASID_NODEID(cnode);
59 
60 	cpumask_set_cpu(smp_processor_id(), &hub->h_cpus);
61 
62 	if (test_and_set_bit(cnode, hub_init_mask))
63 		return;
64 	/*
65 	 * Set CRB timeout at 5ms, (< PI timeout of 10ms)
66 	 */
67 	REMOTE_HUB_S(nasid, IIO_ICTP, 0x800);
68 	REMOTE_HUB_S(nasid, IIO_ICTO, 0xff);
69 
70 	hub_rtc_init(cnode);
71 
72 #ifdef CONFIG_REPLICATE_EXHANDLERS
73 	/*
74 	 * If this is not a headless node initialization,
75 	 * copy over the caliased exception handlers.
76 	 */
77 	if (get_compact_nodeid() == cnode) {
78 		extern char except_vec2_generic, except_vec3_generic;
79 		extern void build_tlb_refill_handler(void);
80 
81 		memcpy((void *)(CKSEG0 + 0x100), &except_vec2_generic, 0x80);
82 		memcpy((void *)(CKSEG0 + 0x180), &except_vec3_generic, 0x80);
83 		build_tlb_refill_handler();
84 		memcpy((void *)(CKSEG0 + 0x100), (void *) CKSEG0, 0x80);
85 		memcpy((void *)(CKSEG0 + 0x180), &except_vec3_generic, 0x100);
86 		__flush_cache_all();
87 	}
88 #endif
89 }
90 
91 void per_cpu_init(void)
92 {
93 	int cpu = smp_processor_id();
94 	int slice = LOCAL_HUB_L(PI_CPU_NUM);
95 	cnodeid_t cnode = get_compact_nodeid();
96 	struct hub_data *hub = hub_data(cnode);
97 
98 	if (test_and_set_bit(slice, &hub->slice_map))
99 		return;
100 
101 	clear_c0_status(ST0_IM);
102 
103 	per_hub_init(cnode);
104 
105 	cpu_time_init();
106 	install_ipi();
107 
108 	/* Install our NMI handler if symmon hasn't installed one. */
109 	install_cpu_nmi_handler(cputoslice(cpu));
110 
111 	enable_percpu_irq(IP27_HUB_PEND0_IRQ, IRQ_TYPE_NONE);
112 	enable_percpu_irq(IP27_HUB_PEND1_IRQ, IRQ_TYPE_NONE);
113 }
114 
115 /*
116  * get_nasid() returns the physical node id number of the caller.
117  */
118 nasid_t
119 get_nasid(void)
120 {
121 	return (nasid_t)((LOCAL_HUB_L(NI_STATUS_REV_ID) & NSRI_NODEID_MASK)
122 			 >> NSRI_NODEID_SHFT);
123 }
124 
125 /*
126  * Map the physical node id to a virtual node id (virtual node ids are contiguous).
127  */
128 cnodeid_t get_compact_nodeid(void)
129 {
130 	return NASID_TO_COMPACT_NODEID(get_nasid());
131 }
132 
133 static inline void ioc3_eth_init(void)
134 {
135 	struct ioc3 *ioc3;
136 	nasid_t nid;
137 
138 	nid = get_nasid();
139 	ioc3 = (struct ioc3 *) KL_CONFIG_CH_CONS_INFO(nid)->memory_base;
140 
141 	ioc3->eier = 0;
142 }
143 
144 extern void ip27_reboot_setup(void);
145 
146 void __init plat_mem_setup(void)
147 {
148 	u64 p, e, n_mode;
149 	nasid_t nid;
150 
151 	ip27_reboot_setup();
152 
153 	/*
154 	 * hub_rtc init and cpu clock intr enabled for later calibrate_delay.
155 	 */
156 	nid = get_nasid();
157 	printk("IP27: Running on node %d.\n", nid);
158 
159 	p = LOCAL_HUB_L(PI_CPU_PRESENT_A) & 1;
160 	e = LOCAL_HUB_L(PI_CPU_ENABLE_A) & 1;
161 	printk("Node %d has %s primary CPU%s.\n", nid,
162 	       p ? "a" : "no",
163 	       e ? ", CPU is running" : "");
164 
165 	p = LOCAL_HUB_L(PI_CPU_PRESENT_B) & 1;
166 	e = LOCAL_HUB_L(PI_CPU_ENABLE_B) & 1;
167 	printk("Node %d has %s secondary CPU%s.\n", nid,
168 	       p ? "a" : "no",
169 	       e ? ", CPU is running" : "");
170 
171 	/*
172 	 * Try to catch kernel missconfigurations and give user an
173 	 * indication what option to select.
174 	 */
175 	n_mode = LOCAL_HUB_L(NI_STATUS_REV_ID) & NSRI_MORENODES_MASK;
176 	printk("Machine is in %c mode.\n", n_mode ? 'N' : 'M');
177 #ifdef CONFIG_SGI_SN_N_MODE
178 	if (!n_mode)
179 		panic("Kernel compiled for M mode.");
180 #else
181 	if (n_mode)
182 		panic("Kernel compiled for N mode.");
183 #endif
184 
185 	ioc3_eth_init();
186 
187 	set_io_port_base(IO_BASE);
188 }
189