xref: /illumos-gate/usr/src/uts/sun4u/os/mach_mp_startup.c (revision 7014882c6a3672fd0e5d60200af8643ae53c5928)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <sys/machsystm.h>
27 #include <sys/cpu_module.h>
28 #include <sys/dtrace.h>
29 #include <sys/cpu_sgnblk_defs.h>
30 
31 /*
32  * Useful for disabling MP bring-up for an MP capable kernel
33  * (a kernel that was built with MP defined)
34  */
35 int use_mp = 1;			/* set to come up mp */
36 
37 /*
38  * Init CPU info - get CPU type info for processor_info system call.
39  */
40 void
41 init_cpu_info(struct cpu *cp)
42 {
43 	processor_info_t *pi = &cp->cpu_type_info;
44 	int cpuid = cp->cpu_id;
45 	struct cpu_node *cpunode = &cpunodes[cpuid];
46 
47 	cp->cpu_fpowner = NULL;		/* not used for V9 */
48 
49 	/*
50 	 * Get clock-frequency property from cpunodes[] for the CPU.
51 	 */
52 	pi->pi_clock = (cpunode->clock_freq + 500000) / 1000000;
53 
54 	/*
55 	 * Current frequency in Hz.
56 	 */
57 	cp->cpu_curr_clock = cpunode->clock_freq;
58 
59 	/*
60 	 * Supported frequencies.
61 	 */
62 	cpu_set_supp_freqs(cp, NULL);
63 
64 	(void) strcpy(pi->pi_processor_type, "sparcv9");
65 	(void) strcpy(pi->pi_fputypes, "sparcv9");
66 
67 	/*
68 	 * StarFire requires the signature block stuff setup here
69 	 */
70 	CPU_SGN_MAPIN(cpuid);
71 	if (cpuid == cpu0.cpu_id) {
72 		/*
73 		 * cpu0 starts out running.  Other cpus are
74 		 * still in OBP land and we will leave them
75 		 * alone for now.
76 		 */
77 		CPU_SIGNATURE(OS_SIG, SIGST_RUN, SIGSUBST_NULL, cpuid);
78 #ifdef	lint
79 		cpuid = cpuid;
80 #endif	/* lint */
81 	}
82 }
83 
84 /*
85  * Routine used to cleanup a CPU that has been powered off.  This will
86  * destroy all per-cpu information related to this cpu.
87  */
88 int
89 mp_cpu_unconfigure(int cpuid)
90 {
91 	int retval;
92 	void empty_cpu(int);
93 	extern int cleanup_cpu_common(int);
94 
95 	ASSERT(MUTEX_HELD(&cpu_lock));
96 
97 	retval = cleanup_cpu_common(cpuid);
98 
99 	empty_cpu(cpuid);
100 
101 	return (retval);
102 }
103 
104 struct mp_find_cpu_arg {
105 	int cpuid;		/* set by mp_cpu_configure() */
106 	dev_info_t *dip;	/* set by mp_find_cpu() */
107 };
108 
109 int
110 mp_find_cpu(dev_info_t *dip, void *arg)
111 {
112 	extern int get_portid_ddi(dev_info_t *, dev_info_t **);
113 	struct mp_find_cpu_arg *target = (struct mp_find_cpu_arg *)arg;
114 	char *type;
115 	int rv = DDI_WALK_CONTINUE;
116 	int cpuid;
117 
118 	if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
119 	    "device_type", &type))
120 		return (DDI_WALK_CONTINUE);
121 
122 	if (strcmp(type, "cpu") != 0)
123 		goto out;
124 
125 	cpuid = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
126 	    DDI_PROP_DONTPASS, "cpuid", -1);
127 
128 	if (cpuid == -1)
129 		cpuid = get_portid_ddi(dip, NULL);
130 	if (cpuid != target->cpuid)
131 		goto out;
132 
133 	/* Found it */
134 	rv = DDI_WALK_TERMINATE;
135 	target->dip = dip;
136 
137 out:
138 	ddi_prop_free(type);
139 	return (rv);
140 }
141 
142 /*
143  * Routine used to setup a newly inserted CPU in preparation for starting
144  * it running code.
145  */
146 int
147 mp_cpu_configure(int cpuid)
148 {
149 	extern void fill_cpu_ddi(dev_info_t *);
150 	extern int setup_cpu_common(int);
151 	struct mp_find_cpu_arg target;
152 
153 	ASSERT(MUTEX_HELD(&cpu_lock));
154 
155 	target.dip = NULL;
156 	target.cpuid = cpuid;
157 	ddi_walk_devs(ddi_root_node(), mp_find_cpu, &target);
158 
159 	if (target.dip == NULL)
160 		return (ENODEV);
161 
162 	/*
163 	 * Note:  uses cpu_lock to protect cpunodes and ncpunodes
164 	 * which will be modified inside of fill_cpu_ddi().
165 	 */
166 	fill_cpu_ddi(target.dip);
167 
168 	/*
169 	 * sun4v cpu setup may fail. sun4u assumes cpu setup to
170 	 * be always successful, so the return value is ignored.
171 	 */
172 	(void) setup_cpu_common(cpuid);
173 
174 	return (0);
175 }
176 
177 void
178 populate_idstr(struct cpu *cp)
179 {
180 	char buf[CPU_IDSTRLEN];
181 	struct cpu_node *cpunode;
182 	processor_info_t *pi;
183 
184 	cpunode = &cpunodes[cp->cpu_id];
185 	pi = &cp->cpu_type_info;
186 	(void) snprintf(buf, sizeof (buf),
187 	    "%s (portid %d impl 0x%x ver 0x%x clock %d MHz)",
188 	    cpunode->name, cpunode->portid, cpunode->implementation,
189 	    cpunode->version, pi->pi_clock);
190 	cp->cpu_idstr = kmem_alloc(strlen(buf) + 1, KM_SLEEP);
191 	(void) strcpy(cp->cpu_idstr, buf);
192 
193 	cp->cpu_brandstr = kmem_alloc(strlen(cpunode->name) + 1, KM_SLEEP);
194 	(void) strcpy(cp->cpu_brandstr, cpunode->name);
195 
196 	cmn_err(CE_CONT, "?cpu%d: %s\n", cp->cpu_id, cp->cpu_idstr);
197 }
198