]> asedeno.scripts.mit.edu Git - linux.git/blob - arch/mips/sgi-ip27/ip27-init.c
MIPS: SGI-IP27: collect externs in new header file
[linux.git] / arch / mips / sgi-ip27 / ip27-init.c
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 #include "ip27-common.h"
40
41 #define CPU_NONE                (cpuid_t)-1
42
43 static DECLARE_BITMAP(hub_init_mask, MAX_COMPACT_NODES);
44 nasid_t master_nasid = INVALID_NASID;
45
46 struct cpuinfo_ip27 sn_cpu_info[NR_CPUS];
47 EXPORT_SYMBOL_GPL(sn_cpu_info);
48
49 static void per_hub_init(nasid_t nasid)
50 {
51         struct hub_data *hub = hub_data(nasid);
52
53         cpumask_set_cpu(smp_processor_id(), &hub->h_cpus);
54
55         if (test_and_set_bit(nasid, hub_init_mask))
56                 return;
57         /*
58          * Set CRB timeout at 5ms, (< PI timeout of 10ms)
59          */
60         REMOTE_HUB_S(nasid, IIO_ICTP, 0x800);
61         REMOTE_HUB_S(nasid, IIO_ICTO, 0xff);
62
63         hub_rtc_init(nasid);
64
65 #ifdef CONFIG_REPLICATE_EXHANDLERS
66         /*
67          * If this is not a headless node initialization,
68          * copy over the caliased exception handlers.
69          */
70         if (get_nasid() == nasid) {
71                 extern char except_vec2_generic, except_vec3_generic;
72                 extern void build_tlb_refill_handler(void);
73
74                 memcpy((void *)(CKSEG0 + 0x100), &except_vec2_generic, 0x80);
75                 memcpy((void *)(CKSEG0 + 0x180), &except_vec3_generic, 0x80);
76                 build_tlb_refill_handler();
77                 memcpy((void *)(CKSEG0 + 0x100), (void *) CKSEG0, 0x80);
78                 memcpy((void *)(CKSEG0 + 0x180), &except_vec3_generic, 0x100);
79                 __flush_cache_all();
80         }
81 #endif
82 }
83
84 void per_cpu_init(void)
85 {
86         int cpu = smp_processor_id();
87         int slice = LOCAL_HUB_L(PI_CPU_NUM);
88         nasid_t nasid = get_nasid();
89         struct hub_data *hub = hub_data(nasid);
90
91         if (test_and_set_bit(slice, &hub->slice_map))
92                 return;
93
94         clear_c0_status(ST0_IM);
95
96         per_hub_init(nasid);
97
98         cpu_time_init();
99         install_ipi();
100
101         /* Install our NMI handler if symmon hasn't installed one. */
102         install_cpu_nmi_handler(cputoslice(cpu));
103
104         enable_percpu_irq(IP27_HUB_PEND0_IRQ, IRQ_TYPE_NONE);
105         enable_percpu_irq(IP27_HUB_PEND1_IRQ, IRQ_TYPE_NONE);
106 }
107
108 /*
109  * get_nasid() returns the physical node id number of the caller.
110  */
111 nasid_t
112 get_nasid(void)
113 {
114         return (nasid_t)((LOCAL_HUB_L(NI_STATUS_REV_ID) & NSRI_NODEID_MASK)
115                          >> NSRI_NODEID_SHFT);
116 }
117
118 void __init plat_mem_setup(void)
119 {
120         u64 p, e, n_mode;
121         nasid_t nid;
122
123         ip27_reboot_setup();
124
125         /*
126          * hub_rtc init and cpu clock intr enabled for later calibrate_delay.
127          */
128         nid = get_nasid();
129         printk("IP27: Running on node %d.\n", nid);
130
131         p = LOCAL_HUB_L(PI_CPU_PRESENT_A) & 1;
132         e = LOCAL_HUB_L(PI_CPU_ENABLE_A) & 1;
133         printk("Node %d has %s primary CPU%s.\n", nid,
134                p ? "a" : "no",
135                e ? ", CPU is running" : "");
136
137         p = LOCAL_HUB_L(PI_CPU_PRESENT_B) & 1;
138         e = LOCAL_HUB_L(PI_CPU_ENABLE_B) & 1;
139         printk("Node %d has %s secondary CPU%s.\n", nid,
140                p ? "a" : "no",
141                e ? ", CPU is running" : "");
142
143         /*
144          * Try to catch kernel missconfigurations and give user an
145          * indication what option to select.
146          */
147         n_mode = LOCAL_HUB_L(NI_STATUS_REV_ID) & NSRI_MORENODES_MASK;
148         printk("Machine is in %c mode.\n", n_mode ? 'N' : 'M');
149 #ifdef CONFIG_SGI_SN_N_MODE
150         if (!n_mode)
151                 panic("Kernel compiled for M mode.");
152 #else
153         if (n_mode)
154                 panic("Kernel compiled for N mode.");
155 #endif
156
157         ioport_resource.start = 0;
158         ioport_resource.end = ~0UL;
159         set_io_port_base(IO_BASE);
160 }