xref: /openbmc/linux/arch/mips/sgi-ip27/ip27-init.c (revision 9d0aaf98)
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/bootinfo.h>
17 #include <asm/cpu.h>
18 #include <asm/io.h>
19 #include <asm/pgtable.h>
20 #include <asm/sgialib.h>
21 #include <asm/time.h>
22 #include <asm/sn/agent.h>
23 #include <asm/sn/types.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/intr.h>
29 #include <asm/current.h>
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/mapped_kernel.h>
35 
36 #include "ip27-common.h"
37 
38 #define CPU_NONE		(cpuid_t)-1
39 
40 static DECLARE_BITMAP(hub_init_mask, MAX_NUMNODES);
41 nasid_t master_nasid = INVALID_NASID;
42 
43 struct cpuinfo_ip27 sn_cpu_info[NR_CPUS];
44 EXPORT_SYMBOL_GPL(sn_cpu_info);
45 
46 static void per_hub_init(nasid_t nasid)
47 {
48 	struct hub_data *hub = hub_data(nasid);
49 
50 	cpumask_set_cpu(smp_processor_id(), &hub->h_cpus);
51 
52 	if (test_and_set_bit(nasid, hub_init_mask))
53 		return;
54 	/*
55 	 * Set CRB timeout at 5ms, (< PI timeout of 10ms)
56 	 */
57 	REMOTE_HUB_S(nasid, IIO_ICTP, 0x800);
58 	REMOTE_HUB_S(nasid, IIO_ICTO, 0xff);
59 
60 	hub_rtc_init(nasid);
61 
62 	if (nasid) {
63 		/* copy exception handlers from first node to current node */
64 		memcpy((void *)NODE_OFFSET_TO_K0(nasid, 0),
65 		       (void *)CKSEG0, 0x200);
66 		__flush_cache_all();
67 		/* switch to node local exception handlers */
68 		REMOTE_HUB_S(nasid, PI_CALIAS_SIZE, PI_CALIAS_SIZE_8K);
69 	}
70 }
71 
72 void per_cpu_init(void)
73 {
74 	int cpu = smp_processor_id();
75 	int slice = LOCAL_HUB_L(PI_CPU_NUM);
76 	nasid_t nasid = get_nasid();
77 	struct hub_data *hub = hub_data(nasid);
78 
79 	if (test_and_set_bit(slice, &hub->slice_map))
80 		return;
81 
82 	clear_c0_status(ST0_IM);
83 
84 	per_hub_init(nasid);
85 
86 	cpu_time_init();
87 	install_ipi();
88 
89 	/* Install our NMI handler if symmon hasn't installed one. */
90 	install_cpu_nmi_handler(cputoslice(cpu));
91 
92 	enable_percpu_irq(IP27_HUB_PEND0_IRQ, IRQ_TYPE_NONE);
93 	enable_percpu_irq(IP27_HUB_PEND1_IRQ, IRQ_TYPE_NONE);
94 }
95 
96 void __init plat_mem_setup(void)
97 {
98 	u64 p, e, n_mode;
99 	nasid_t nid;
100 
101 	register_smp_ops(&ip27_smp_ops);
102 
103 	ip27_reboot_setup();
104 
105 	/*
106 	 * hub_rtc init and cpu clock intr enabled for later calibrate_delay.
107 	 */
108 	nid = get_nasid();
109 	printk("IP27: Running on node %d.\n", nid);
110 
111 	p = LOCAL_HUB_L(PI_CPU_PRESENT_A) & 1;
112 	e = LOCAL_HUB_L(PI_CPU_ENABLE_A) & 1;
113 	printk("Node %d has %s primary CPU%s.\n", nid,
114 	       p ? "a" : "no",
115 	       e ? ", CPU is running" : "");
116 
117 	p = LOCAL_HUB_L(PI_CPU_PRESENT_B) & 1;
118 	e = LOCAL_HUB_L(PI_CPU_ENABLE_B) & 1;
119 	printk("Node %d has %s secondary CPU%s.\n", nid,
120 	       p ? "a" : "no",
121 	       e ? ", CPU is running" : "");
122 
123 	/*
124 	 * Try to catch kernel missconfigurations and give user an
125 	 * indication what option to select.
126 	 */
127 	n_mode = LOCAL_HUB_L(NI_STATUS_REV_ID) & NSRI_MORENODES_MASK;
128 	printk("Machine is in %c mode.\n", n_mode ? 'N' : 'M');
129 #ifdef CONFIG_SGI_SN_N_MODE
130 	if (!n_mode)
131 		panic("Kernel compiled for M mode.");
132 #else
133 	if (n_mode)
134 		panic("Kernel compiled for N mode.");
135 #endif
136 
137 	ioport_resource.start = 0;
138 	ioport_resource.end = ~0UL;
139 	set_io_port_base(IO_BASE);
140 }
141 
142 const char *get_system_type(void)
143 {
144 	return "SGI Origin";
145 }
146 
147 void __init prom_init(void)
148 {
149 	prom_init_cmdline(fw_arg0, (LONG *)fw_arg1);
150 	prom_meminit();
151 }
152 
153