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