]> asedeno.scripts.mit.edu Git - linux.git/blob - arch/mips/sgi-ip27/ip27-smp.c
MIPS: SGI-IP27: collect externs in new header file
[linux.git] / arch / mips / sgi-ip27 / ip27-smp.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/init.h>
10 #include <linux/sched.h>
11 #include <linux/sched/task_stack.h>
12 #include <linux/topology.h>
13 #include <linux/nodemask.h>
14
15 #include <asm/page.h>
16 #include <asm/processor.h>
17 #include <asm/ptrace.h>
18 #include <asm/sn/arch.h>
19 #include <asm/sn/gda.h>
20 #include <asm/sn/intr.h>
21 #include <asm/sn/klconfig.h>
22 #include <asm/sn/launch.h>
23 #include <asm/sn/mapped_kernel.h>
24 #include <asm/sn/sn_private.h>
25 #include <asm/sn/types.h>
26 #include <asm/sn/sn0/hubpi.h>
27 #include <asm/sn/sn0/hubio.h>
28 #include <asm/sn/sn0/ip27.h>
29
30 #include "ip27-common.h"
31
32 /*
33  * Takes as first input the PROM assigned cpu id, and the kernel
34  * assigned cpu id as the second.
35  */
36 static void alloc_cpupda(nasid_t nasid, cpuid_t cpu, int cpunum)
37 {
38         cputonasid(cpunum) = nasid;
39         cputoslice(cpunum) = get_cpu_slice(cpu);
40 }
41
42 static int do_cpumask(nasid_t nasid, int highest)
43 {
44         static int tot_cpus_found = 0;
45         lboard_t *brd;
46         klcpu_t *acpu;
47         int cpus_found = 0;
48         cpuid_t cpuid;
49
50         brd = find_lboard((lboard_t *)KL_CONFIG_INFO(nasid), KLTYPE_IP27);
51
52         do {
53                 acpu = (klcpu_t *)find_first_component(brd, KLSTRUCT_CPU);
54                 while (acpu) {
55                         cpuid = acpu->cpu_info.virtid;
56                         /* Only let it join in if it's marked enabled */
57                         if ((acpu->cpu_info.flags & KLINFO_ENABLE) &&
58                             (tot_cpus_found != NR_CPUS)) {
59                                 if (cpuid > highest)
60                                         highest = cpuid;
61                                 set_cpu_possible(cpuid, true);
62                                 alloc_cpupda(nasid, cpuid, tot_cpus_found);
63                                 cpus_found++;
64                                 tot_cpus_found++;
65                         }
66                         acpu = (klcpu_t *)find_component(brd, (klinfo_t *)acpu,
67                                                                 KLSTRUCT_CPU);
68                 }
69                 brd = KLCF_NEXT(brd);
70                 if (!brd)
71                         break;
72
73                 brd = find_lboard(brd, KLTYPE_IP27);
74         } while (brd);
75
76         return highest;
77 }
78
79 void cpu_node_probe(void)
80 {
81         int i, highest = 0;
82         gda_t *gdap = GDA;
83
84         /*
85          * MCD - this whole "compact node" stuff can probably be dropped,
86          * as we can handle sparse numbering now
87          */
88         nodes_clear(node_online_map);
89         for (i = 0; i < MAX_COMPACT_NODES; i++) {
90                 nasid_t nasid = gdap->g_nasidtable[i];
91                 if (nasid == INVALID_NASID)
92                         break;
93                 node_set_online(nasid);
94                 highest = do_cpumask(nasid, highest);
95         }
96
97         printk("Discovered %d cpus on %d nodes\n", highest + 1, num_online_nodes());
98 }
99
100 static __init void intr_clear_all(nasid_t nasid)
101 {
102         int i;
103
104         REMOTE_HUB_S(nasid, PI_INT_MASK0_A, 0);
105         REMOTE_HUB_S(nasid, PI_INT_MASK0_B, 0);
106         REMOTE_HUB_S(nasid, PI_INT_MASK1_A, 0);
107         REMOTE_HUB_S(nasid, PI_INT_MASK1_B, 0);
108
109         for (i = 0; i < 128; i++)
110                 REMOTE_HUB_CLR_INTR(nasid, i);
111 }
112
113 static void ip27_send_ipi_single(int destid, unsigned int action)
114 {
115         int irq;
116
117         switch (action) {
118         case SMP_RESCHEDULE_YOURSELF:
119                 irq = CPU_RESCHED_A_IRQ;
120                 break;
121         case SMP_CALL_FUNCTION:
122                 irq = CPU_CALL_A_IRQ;
123                 break;
124         default:
125                 panic("sendintr");
126         }
127
128         irq += cputoslice(destid);
129
130         /*
131          * Set the interrupt bit associated with the CPU we want to
132          * send the interrupt to.
133          */
134         REMOTE_HUB_SEND_INTR(cpu_to_node(destid), irq);
135 }
136
137 static void ip27_send_ipi_mask(const struct cpumask *mask, unsigned int action)
138 {
139         unsigned int i;
140
141         for_each_cpu(i, mask)
142                 ip27_send_ipi_single(i, action);
143 }
144
145 static void ip27_init_cpu(void)
146 {
147         per_cpu_init();
148 }
149
150 static void ip27_smp_finish(void)
151 {
152         hub_rt_clock_event_init();
153         local_irq_enable();
154 }
155
156 /*
157  * Launch a slave into smp_bootstrap().  It doesn't take an argument, and we
158  * set sp to the kernel stack of the newly created idle process, gp to the proc
159  * struct so that current_thread_info() will work.
160  */
161 static int ip27_boot_secondary(int cpu, struct task_struct *idle)
162 {
163         unsigned long gp = (unsigned long)task_thread_info(idle);
164         unsigned long sp = __KSTK_TOS(idle);
165
166         LAUNCH_SLAVE(cputonasid(cpu), cputoslice(cpu),
167                 (launch_proc_t)MAPPED_KERN_RW_TO_K0(smp_bootstrap),
168                 0, (void *) sp, (void *) gp);
169         return 0;
170 }
171
172 static void __init ip27_smp_setup(void)
173 {
174         nasid_t nasid;
175
176         for_each_online_node(nasid) {
177                 if (nasid == 0)
178                         continue;
179                 intr_clear_all(nasid);
180         }
181
182         replicate_kernel_text();
183
184         /*
185          * PROM sets up system, that boot cpu is always first CPU on nasid 0
186          */
187         alloc_cpupda(0, 0, 0);
188 }
189
190 static void __init ip27_prepare_cpus(unsigned int max_cpus)
191 {
192         /* We already did everything necessary earlier */
193 }
194
195 const struct plat_smp_ops ip27_smp_ops = {
196         .send_ipi_single        = ip27_send_ipi_single,
197         .send_ipi_mask          = ip27_send_ipi_mask,
198         .init_secondary         = ip27_init_cpu,
199         .smp_finish             = ip27_smp_finish,
200         .boot_secondary         = ip27_boot_secondary,
201         .smp_setup              = ip27_smp_setup,
202         .prepare_cpus           = ip27_prepare_cpus,
203         .prepare_boot_cpu       = ip27_init_cpu,
204 };