Linux Audio

Check our new training course

Loading...
v6.8
  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/agent.h>
 19#include <asm/sn/arch.h>
 20#include <asm/sn/gda.h>
 21#include <asm/sn/intr.h>
 22#include <asm/sn/klconfig.h>
 23#include <asm/sn/launch.h>
 24#include <asm/sn/mapped_kernel.h>
 
 25#include <asm/sn/types.h>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 26
 27#include "ip27-common.h"
 
 
 
 
 
 
 
 
 28
 29static int node_scan_cpus(nasid_t nasid, int highest)
 30{
 31	static int cpus_found;
 32	lboard_t *brd;
 33	klcpu_t *acpu;
 
 34	cpuid_t cpuid;
 35
 36	brd = find_lboard((lboard_t *)KL_CONFIG_INFO(nasid), KLTYPE_IP27);
 37
 38	do {
 39		acpu = (klcpu_t *)find_first_component(brd, KLSTRUCT_CPU);
 40		while (acpu) {
 41			cpuid = acpu->cpu_info.virtid;
 
 
 
 
 
 42			/* Only let it join in if it's marked enabled */
 43			if ((acpu->cpu_info.flags & KLINFO_ENABLE) &&
 44			    (cpus_found != NR_CPUS)) {
 45				if (cpuid > highest)
 46					highest = cpuid;
 47				set_cpu_possible(cpuid, true);
 48				cputonasid(cpus_found) = nasid;
 49				cputoslice(cpus_found) = acpu->cpu_info.physid;
 50				sn_cpu_info[cpus_found].p_speed =
 51							acpu->cpu_speed;
 52				cpus_found++;
 
 53			}
 54			acpu = (klcpu_t *)find_component(brd, (klinfo_t *)acpu,
 55								KLSTRUCT_CPU);
 56		}
 57		brd = KLCF_NEXT(brd);
 58		if (!brd)
 59			break;
 60
 61		brd = find_lboard(brd, KLTYPE_IP27);
 62	} while (brd);
 63
 64	return highest;
 65}
 66
 67void cpu_node_probe(void)
 68{
 69	int i, highest = 0;
 70	gda_t *gdap = GDA;
 71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 72	nodes_clear(node_online_map);
 73	for (i = 0; i < MAX_NUMNODES; i++) {
 74		nasid_t nasid = gdap->g_nasidtable[i];
 75		if (nasid == INVALID_NASID)
 76			break;
 77		node_set_online(nasid);
 78		highest = node_scan_cpus(nasid, highest);
 
 
 79	}
 80
 81	printk("Discovered %d cpus on %d nodes\n", highest + 1, num_online_nodes());
 82}
 83
 84static __init void intr_clear_all(nasid_t nasid)
 85{
 86	int i;
 87
 88	REMOTE_HUB_S(nasid, PI_INT_MASK0_A, 0);
 89	REMOTE_HUB_S(nasid, PI_INT_MASK0_B, 0);
 90	REMOTE_HUB_S(nasid, PI_INT_MASK1_A, 0);
 91	REMOTE_HUB_S(nasid, PI_INT_MASK1_B, 0);
 92
 93	for (i = 0; i < 128; i++)
 94		REMOTE_HUB_CLR_INTR(nasid, i);
 95}
 96
 97static void ip27_send_ipi_single(int destid, unsigned int action)
 98{
 99	int irq;
100
101	switch (action) {
102	case SMP_RESCHEDULE_YOURSELF:
103		irq = CPU_RESCHED_A_IRQ;
104		break;
105	case SMP_CALL_FUNCTION:
106		irq = CPU_CALL_A_IRQ;
107		break;
108	default:
109		panic("sendintr");
110	}
111
112	irq += cputoslice(destid);
113
114	/*
115	 * Set the interrupt bit associated with the CPU we want to
116	 * send the interrupt to.
 
117	 */
118	REMOTE_HUB_SEND_INTR(cpu_to_node(destid), irq);
119}
120
121static void ip27_send_ipi_mask(const struct cpumask *mask, unsigned int action)
122{
123	unsigned int i;
124
125	for_each_cpu(i, mask)
126		ip27_send_ipi_single(i, action);
127}
128
129static void ip27_init_cpu(void)
130{
131	per_cpu_init();
132}
133
134static void ip27_smp_finish(void)
135{
 
 
136	hub_rt_clock_event_init();
137	local_irq_enable();
138}
139
 
 
 
 
140/*
141 * Launch a slave into smp_bootstrap().	 It doesn't take an argument, and we
142 * set sp to the kernel stack of the newly created idle process, gp to the proc
143 * struct so that current_thread_info() will work.
144 */
145static int ip27_boot_secondary(int cpu, struct task_struct *idle)
146{
147	unsigned long gp = (unsigned long)task_thread_info(idle);
148	unsigned long sp = __KSTK_TOS(idle);
149
150	LAUNCH_SLAVE(cputonasid(cpu), cputoslice(cpu),
151		(launch_proc_t)MAPPED_KERN_RW_TO_K0(smp_bootstrap),
152		0, (void *) sp, (void *) gp);
153	return 0;
154}
155
156static void __init ip27_smp_setup(void)
157{
158	nasid_t nasid;
159
160	for_each_online_node(nasid) {
161		if (nasid == 0)
162			continue;
163		intr_clear_all(nasid);
164	}
165
166	replicate_kernel_text();
167
168	/*
169	 * PROM sets up system, that boot cpu is always first CPU on nasid 0
 
 
 
170	 */
171	cputonasid(0) = 0;
172	cputoslice(0) = LOCAL_HUB_L(PI_CPU_NUM);
173}
174
175static void __init ip27_prepare_cpus(unsigned int max_cpus)
176{
177	/* We already did everything necessary earlier */
178}
179
180const struct plat_smp_ops ip27_smp_ops = {
181	.send_ipi_single	= ip27_send_ipi_single,
182	.send_ipi_mask		= ip27_send_ipi_mask,
183	.init_secondary		= ip27_init_cpu,
184	.smp_finish		= ip27_smp_finish,
 
185	.boot_secondary		= ip27_boot_secondary,
186	.smp_setup		= ip27_smp_setup,
187	.prepare_cpus		= ip27_prepare_cpus,
188	.prepare_boot_cpu	= ip27_init_cpu,
189};
v3.1
  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/nodemask.h>
 
 12#include <asm/page.h>
 13#include <asm/processor.h>
 
 
 14#include <asm/sn/arch.h>
 15#include <asm/sn/gda.h>
 16#include <asm/sn/intr.h>
 17#include <asm/sn/klconfig.h>
 18#include <asm/sn/launch.h>
 19#include <asm/sn/mapped_kernel.h>
 20#include <asm/sn/sn_private.h>
 21#include <asm/sn/types.h>
 22#include <asm/sn/sn0/hubpi.h>
 23#include <asm/sn/sn0/hubio.h>
 24#include <asm/sn/sn0/ip27.h>
 25
 26/*
 27 * Takes as first input the PROM assigned cpu id, and the kernel
 28 * assigned cpu id as the second.
 29 */
 30static void alloc_cpupda(cpuid_t cpu, int cpunum)
 31{
 32	cnodeid_t node = get_cpu_cnode(cpu);
 33	nasid_t nasid = COMPACT_TO_NASID_NODEID(node);
 34
 35	cputonasid(cpunum) = nasid;
 36	sn_cpu_info[cpunum].p_nodeid = node;
 37	cputoslice(cpunum) = get_cpu_slice(cpu);
 38}
 39
 40static nasid_t get_actual_nasid(lboard_t *brd)
 41{
 42	klhub_t *hub;
 43
 44	if (!brd)
 45		return INVALID_NASID;
 46
 47	/* find out if we are a completely disabled brd. */
 48	hub  = (klhub_t *)find_first_component(brd, KLSTRUCT_HUB);
 49	if (!hub)
 50		return INVALID_NASID;
 51	if (!(hub->hub_info.flags & KLINFO_ENABLE))	/* disabled node brd */
 52		return hub->hub_info.physid;
 53	else
 54		return brd->brd_nasid;
 55}
 56
 57static int do_cpumask(cnodeid_t cnode, nasid_t nasid, int highest)
 58{
 59	static int tot_cpus_found = 0;
 60	lboard_t *brd;
 61	klcpu_t *acpu;
 62	int cpus_found = 0;
 63	cpuid_t cpuid;
 64
 65	brd = find_lboard((lboard_t *)KL_CONFIG_INFO(nasid), KLTYPE_IP27);
 66
 67	do {
 68		acpu = (klcpu_t *)find_first_component(brd, KLSTRUCT_CPU);
 69		while (acpu) {
 70			cpuid = acpu->cpu_info.virtid;
 71			/* cnode is not valid for completely disabled brds */
 72			if (get_actual_nasid(brd) == brd->brd_nasid)
 73				cpuid_to_compact_node[cpuid] = cnode;
 74			if (cpuid > highest)
 75				highest = cpuid;
 76			/* Only let it join in if it's marked enabled */
 77			if ((acpu->cpu_info.flags & KLINFO_ENABLE) &&
 78			    (tot_cpus_found != NR_CPUS)) {
 79				cpu_set(cpuid, cpu_possible_map);
 80				alloc_cpupda(cpuid, tot_cpus_found);
 
 
 
 
 
 81				cpus_found++;
 82				tot_cpus_found++;
 83			}
 84			acpu = (klcpu_t *)find_component(brd, (klinfo_t *)acpu,
 85								KLSTRUCT_CPU);
 86		}
 87		brd = KLCF_NEXT(brd);
 88		if (!brd)
 89			break;
 90
 91		brd = find_lboard(brd, KLTYPE_IP27);
 92	} while (brd);
 93
 94	return highest;
 95}
 96
 97void cpu_node_probe(void)
 98{
 99	int i, highest = 0;
100	gda_t *gdap = GDA;
101
102	/*
103	 * Initialize the arrays to invalid nodeid (-1)
104	 */
105	for (i = 0; i < MAX_COMPACT_NODES; i++)
106		compact_to_nasid_node[i] = INVALID_NASID;
107	for (i = 0; i < MAX_NASIDS; i++)
108		nasid_to_compact_node[i] = INVALID_CNODEID;
109	for (i = 0; i < MAXCPUS; i++)
110		cpuid_to_compact_node[i] = INVALID_CNODEID;
111
112	/*
113	 * MCD - this whole "compact node" stuff can probably be dropped,
114	 * as we can handle sparse numbering now
115	 */
116	nodes_clear(node_online_map);
117	for (i = 0; i < MAX_COMPACT_NODES; i++) {
118		nasid_t nasid = gdap->g_nasidtable[i];
119		if (nasid == INVALID_NASID)
120			break;
121		compact_to_nasid_node[i] = nasid;
122		nasid_to_compact_node[nasid] = i;
123		node_set_online(num_online_nodes());
124		highest = do_cpumask(i, nasid, highest);
125	}
126
127	printk("Discovered %d cpus on %d nodes\n", highest + 1, num_online_nodes());
128}
129
130static __init void intr_clear_all(nasid_t nasid)
131{
132	int i;
133
134	REMOTE_HUB_S(nasid, PI_INT_MASK0_A, 0);
135	REMOTE_HUB_S(nasid, PI_INT_MASK0_B, 0);
136	REMOTE_HUB_S(nasid, PI_INT_MASK1_A, 0);
137	REMOTE_HUB_S(nasid, PI_INT_MASK1_B, 0);
138
139	for (i = 0; i < 128; i++)
140		REMOTE_HUB_CLR_INTR(nasid, i);
141}
142
143static void ip27_send_ipi_single(int destid, unsigned int action)
144{
145	int irq;
146
147	switch (action) {
148	case SMP_RESCHEDULE_YOURSELF:
149		irq = CPU_RESCHED_A_IRQ;
150		break;
151	case SMP_CALL_FUNCTION:
152		irq = CPU_CALL_A_IRQ;
153		break;
154	default:
155		panic("sendintr");
156	}
157
158	irq += cputoslice(destid);
159
160	/*
161	 * Convert the compact hub number to the NASID to get the correct
162	 * part of the address space.  Then set the interrupt bit associated
163	 * with the CPU we want to send the interrupt to.
164	 */
165	REMOTE_HUB_SEND_INTR(COMPACT_TO_NASID_NODEID(cpu_to_node(destid)), irq);
166}
167
168static void ip27_send_ipi_mask(const struct cpumask *mask, unsigned int action)
169{
170	unsigned int i;
171
172	for_each_cpu(i, mask)
173		ip27_send_ipi_single(i, action);
174}
175
176static void __cpuinit ip27_init_secondary(void)
177{
178	per_cpu_init();
179}
180
181static void __cpuinit ip27_smp_finish(void)
182{
183	extern void hub_rt_clock_event_init(void);
184
185	hub_rt_clock_event_init();
186	local_irq_enable();
187}
188
189static void __init ip27_cpus_done(void)
190{
191}
192
193/*
194 * Launch a slave into smp_bootstrap().  It doesn't take an argument, and we
195 * set sp to the kernel stack of the newly created idle process, gp to the proc
196 * struct so that current_thread_info() will work.
197 */
198static void __cpuinit ip27_boot_secondary(int cpu, struct task_struct *idle)
199{
200	unsigned long gp = (unsigned long)task_thread_info(idle);
201	unsigned long sp = __KSTK_TOS(idle);
202
203	LAUNCH_SLAVE(cputonasid(cpu), cputoslice(cpu),
204		(launch_proc_t)MAPPED_KERN_RW_TO_K0(smp_bootstrap),
205		0, (void *) sp, (void *) gp);
 
206}
207
208static void __init ip27_smp_setup(void)
209{
210	cnodeid_t	cnode;
211
212	for_each_online_node(cnode) {
213		if (cnode == 0)
214			continue;
215		intr_clear_all(COMPACT_TO_NASID_NODEID(cnode));
216	}
217
218	replicate_kernel_text();
219
220	/*
221	 * Assumption to be fixed: we're always booted on logical / physical
222	 * processor 0.  While we're always running on logical processor 0
223	 * this still means this is physical processor zero; it might for
224	 * example be disabled in the firmware.
225	 */
226	alloc_cpupda(0, 0);
 
227}
228
229static void __init ip27_prepare_cpus(unsigned int max_cpus)
230{
231	/* We already did everything necessary earlier */
232}
233
234struct plat_smp_ops ip27_smp_ops = {
235	.send_ipi_single	= ip27_send_ipi_single,
236	.send_ipi_mask		= ip27_send_ipi_mask,
237	.init_secondary		= ip27_init_secondary,
238	.smp_finish		= ip27_smp_finish,
239	.cpus_done		= ip27_cpus_done,
240	.boot_secondary		= ip27_boot_secondary,
241	.smp_setup		= ip27_smp_setup,
242	.prepare_cpus		= ip27_prepare_cpus,
 
243};