xref: /onnv-gate/usr/src/uts/sun4u/os/mach_mp_startup.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <sys/machsystm.h>
30*0Sstevel@tonic-gate #include <sys/cpu_module.h>
31*0Sstevel@tonic-gate #include <sys/dtrace.h>
32*0Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h>
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate /*
35*0Sstevel@tonic-gate  * Useful for disabling MP bring-up for an MP capable kernel
36*0Sstevel@tonic-gate  * (a kernel that was built with MP defined)
37*0Sstevel@tonic-gate  */
38*0Sstevel@tonic-gate int use_mp = 1;			/* set to come up mp */
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate /*
41*0Sstevel@tonic-gate  * Init CPU info - get CPU type info for processor_info system call.
42*0Sstevel@tonic-gate  */
43*0Sstevel@tonic-gate void
44*0Sstevel@tonic-gate init_cpu_info(struct cpu *cp)
45*0Sstevel@tonic-gate {
46*0Sstevel@tonic-gate 	processor_info_t *pi = &cp->cpu_type_info;
47*0Sstevel@tonic-gate 	int cpuid = cp->cpu_id;
48*0Sstevel@tonic-gate 	struct cpu_node *cpunode = &cpunodes[cpuid];
49*0Sstevel@tonic-gate 	char buf[CPU_IDSTRLEN];
50*0Sstevel@tonic-gate 
51*0Sstevel@tonic-gate 	cp->cpu_fpowner = NULL;		/* not used for V9 */
52*0Sstevel@tonic-gate 
53*0Sstevel@tonic-gate 	/*
54*0Sstevel@tonic-gate 	 * Get clock-frequency property from cpunodes[] for the CPU.
55*0Sstevel@tonic-gate 	 */
56*0Sstevel@tonic-gate 	pi->pi_clock = (cpunode->clock_freq + 500000) / 1000000;
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate 	(void) strcpy(pi->pi_processor_type, "sparcv9");
59*0Sstevel@tonic-gate 	(void) strcpy(pi->pi_fputypes, "sparcv9");
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate 	(void) snprintf(buf, sizeof (buf),
62*0Sstevel@tonic-gate 	    "%s (portid %d impl 0x%x ver 0x%x clock %d MHz)",
63*0Sstevel@tonic-gate 	    cpunode->name, cpunode->portid,
64*0Sstevel@tonic-gate 	    cpunode->implementation, cpunode->version, pi->pi_clock);
65*0Sstevel@tonic-gate 
66*0Sstevel@tonic-gate 	cp->cpu_idstr = kmem_alloc(strlen(buf) + 1, KM_SLEEP);
67*0Sstevel@tonic-gate 	(void) strcpy(cp->cpu_idstr, buf);
68*0Sstevel@tonic-gate 
69*0Sstevel@tonic-gate 	cmn_err(CE_CONT, "?cpu%d: %s\n", cpuid, cp->cpu_idstr);
70*0Sstevel@tonic-gate 
71*0Sstevel@tonic-gate 	cp->cpu_brandstr = kmem_alloc(strlen(cpunode->name) + 1, KM_SLEEP);
72*0Sstevel@tonic-gate 	(void) strcpy(cp->cpu_brandstr, cpunode->name);
73*0Sstevel@tonic-gate 
74*0Sstevel@tonic-gate 	/*
75*0Sstevel@tonic-gate 	 * StarFire requires the signature block stuff setup here
76*0Sstevel@tonic-gate 	 */
77*0Sstevel@tonic-gate 	CPU_SGN_MAPIN(cpuid);
78*0Sstevel@tonic-gate 	if (cpuid == cpu0.cpu_id) {
79*0Sstevel@tonic-gate 		/*
80*0Sstevel@tonic-gate 		 * cpu0 starts out running.  Other cpus are
81*0Sstevel@tonic-gate 		 * still in OBP land and we will leave them
82*0Sstevel@tonic-gate 		 * alone for now.
83*0Sstevel@tonic-gate 		 */
84*0Sstevel@tonic-gate 		CPU_SIGNATURE(OS_SIG, SIGST_RUN, SIGSUBST_NULL, cpuid);
85*0Sstevel@tonic-gate #ifdef	lint
86*0Sstevel@tonic-gate 		cpuid = cpuid;
87*0Sstevel@tonic-gate #endif	/* lint */
88*0Sstevel@tonic-gate 	}
89*0Sstevel@tonic-gate }
90*0Sstevel@tonic-gate 
91*0Sstevel@tonic-gate /*
92*0Sstevel@tonic-gate  * Routine used to cleanup a CPU that has been powered off.  This will
93*0Sstevel@tonic-gate  * destroy all per-cpu information related to this cpu.
94*0Sstevel@tonic-gate  */
95*0Sstevel@tonic-gate int
96*0Sstevel@tonic-gate mp_cpu_unconfigure(int cpuid)
97*0Sstevel@tonic-gate {
98*0Sstevel@tonic-gate 	int retval;
99*0Sstevel@tonic-gate 	void empty_cpu(int);
100*0Sstevel@tonic-gate 	extern int cleanup_cpu_common(int);
101*0Sstevel@tonic-gate 
102*0Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
103*0Sstevel@tonic-gate 
104*0Sstevel@tonic-gate 	retval = cleanup_cpu_common(cpuid);
105*0Sstevel@tonic-gate 
106*0Sstevel@tonic-gate 	empty_cpu(cpuid);
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate 	return (retval);
109*0Sstevel@tonic-gate }
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate struct mp_find_cpu_arg {
112*0Sstevel@tonic-gate 	int cpuid;		/* set by mp_cpu_configure() */
113*0Sstevel@tonic-gate 	dev_info_t *dip;	/* set by mp_find_cpu() */
114*0Sstevel@tonic-gate };
115*0Sstevel@tonic-gate 
116*0Sstevel@tonic-gate int
117*0Sstevel@tonic-gate mp_find_cpu(dev_info_t *dip, void *arg)
118*0Sstevel@tonic-gate {
119*0Sstevel@tonic-gate 	extern int get_portid_ddi(dev_info_t *, dev_info_t **);
120*0Sstevel@tonic-gate 	struct mp_find_cpu_arg *target = (struct mp_find_cpu_arg *)arg;
121*0Sstevel@tonic-gate 	char *type;
122*0Sstevel@tonic-gate 	int rv = DDI_WALK_CONTINUE;
123*0Sstevel@tonic-gate 	int cpuid;
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate 	if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
126*0Sstevel@tonic-gate 	    "device_type", &type))
127*0Sstevel@tonic-gate 		return (DDI_WALK_CONTINUE);
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate 	if (strcmp(type, "cpu") != 0)
130*0Sstevel@tonic-gate 		goto out;
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate 	cpuid = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
133*0Sstevel@tonic-gate 	    DDI_PROP_DONTPASS, "cpuid", -1);
134*0Sstevel@tonic-gate 
135*0Sstevel@tonic-gate 	if (cpuid == -1)
136*0Sstevel@tonic-gate 		cpuid = get_portid_ddi(dip, NULL);
137*0Sstevel@tonic-gate 	if (cpuid != target->cpuid)
138*0Sstevel@tonic-gate 		goto out;
139*0Sstevel@tonic-gate 
140*0Sstevel@tonic-gate 	/* Found it */
141*0Sstevel@tonic-gate 	rv = DDI_WALK_TERMINATE;
142*0Sstevel@tonic-gate 	target->dip = dip;
143*0Sstevel@tonic-gate 
144*0Sstevel@tonic-gate out:
145*0Sstevel@tonic-gate 	ddi_prop_free(type);
146*0Sstevel@tonic-gate 	return (rv);
147*0Sstevel@tonic-gate }
148*0Sstevel@tonic-gate 
149*0Sstevel@tonic-gate /*
150*0Sstevel@tonic-gate  * Routine used to setup a newly inserted CPU in preparation for starting
151*0Sstevel@tonic-gate  * it running code.
152*0Sstevel@tonic-gate  */
153*0Sstevel@tonic-gate int
154*0Sstevel@tonic-gate mp_cpu_configure(int cpuid)
155*0Sstevel@tonic-gate {
156*0Sstevel@tonic-gate 	extern void fill_cpu_ddi(dev_info_t *);
157*0Sstevel@tonic-gate 	extern void setup_cpu_common(int);
158*0Sstevel@tonic-gate 	struct mp_find_cpu_arg target;
159*0Sstevel@tonic-gate 
160*0Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
161*0Sstevel@tonic-gate 
162*0Sstevel@tonic-gate 	target.dip = NULL;
163*0Sstevel@tonic-gate 	target.cpuid = cpuid;
164*0Sstevel@tonic-gate 	ddi_walk_devs(ddi_root_node(), mp_find_cpu, &target);
165*0Sstevel@tonic-gate 
166*0Sstevel@tonic-gate 	if (target.dip == NULL)
167*0Sstevel@tonic-gate 		return (ENODEV);
168*0Sstevel@tonic-gate 
169*0Sstevel@tonic-gate 	/*
170*0Sstevel@tonic-gate 	 * Note:  uses cpu_lock to protect cpunodes and ncpunodes
171*0Sstevel@tonic-gate 	 * which will be modified inside of fill_cpu_ddi().
172*0Sstevel@tonic-gate 	 */
173*0Sstevel@tonic-gate 	fill_cpu_ddi(target.dip);
174*0Sstevel@tonic-gate 
175*0Sstevel@tonic-gate 	setup_cpu_common(cpuid);
176*0Sstevel@tonic-gate 
177*0Sstevel@tonic-gate 	return (0);
178*0Sstevel@tonic-gate }
179