xref: /titanic_52/usr/src/uts/sun4u/os/mach_mp_startup.c (revision 65d61b8c5bb0da98e137e8d74245d8f53d690237)
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 	(void) strcpy(pi->pi_processor_type, "sparcv9");
58 	(void) strcpy(pi->pi_fputypes, "sparcv9");
59 
60 	(void) snprintf(buf, sizeof (buf),
61 	    "%s (portid %d impl 0x%x ver 0x%x clock %d MHz)",
62 	    cpunode->name, cpunode->portid,
63 	    cpunode->implementation, cpunode->version, pi->pi_clock);
64 
65 	cp->cpu_idstr = kmem_alloc(strlen(buf) + 1, KM_SLEEP);
66 	(void) strcpy(cp->cpu_idstr, buf);
67 
68 	cmn_err(CE_CONT, "?cpu%d: %s\n", cpuid, cp->cpu_idstr);
69 
70 	cp->cpu_brandstr = kmem_alloc(strlen(cpunode->name) + 1, KM_SLEEP);
71 	(void) strcpy(cp->cpu_brandstr, cpunode->name);
72 
73 	/*
74 	 * StarFire requires the signature block stuff setup here
75 	 */
76 	CPU_SGN_MAPIN(cpuid);
77 	if (cpuid == cpu0.cpu_id) {
78 		/*
79 		 * cpu0 starts out running.  Other cpus are
80 		 * still in OBP land and we will leave them
81 		 * alone for now.
82 		 */
83 		CPU_SIGNATURE(OS_SIG, SIGST_RUN, SIGSUBST_NULL, cpuid);
84 #ifdef	lint
85 		cpuid = cpuid;
86 #endif	/* lint */
87 	}
88 }
89 
90 /*
91  * Routine used to cleanup a CPU that has been powered off.  This will
92  * destroy all per-cpu information related to this cpu.
93  */
94 int
95 mp_cpu_unconfigure(int cpuid)
96 {
97 	int retval;
98 	void empty_cpu(int);
99 	extern int cleanup_cpu_common(int);
100 
101 	ASSERT(MUTEX_HELD(&cpu_lock));
102 
103 	retval = cleanup_cpu_common(cpuid);
104 
105 	empty_cpu(cpuid);
106 
107 	return (retval);
108 }
109 
110 struct mp_find_cpu_arg {
111 	int cpuid;		/* set by mp_cpu_configure() */
112 	dev_info_t *dip;	/* set by mp_find_cpu() */
113 };
114 
115 int
116 mp_find_cpu(dev_info_t *dip, void *arg)
117 {
118 	extern int get_portid_ddi(dev_info_t *, dev_info_t **);
119 	struct mp_find_cpu_arg *target = (struct mp_find_cpu_arg *)arg;
120 	char *type;
121 	int rv = DDI_WALK_CONTINUE;
122 	int cpuid;
123 
124 	if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
125 	    "device_type", &type))
126 		return (DDI_WALK_CONTINUE);
127 
128 	if (strcmp(type, "cpu") != 0)
129 		goto out;
130 
131 	cpuid = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
132 	    DDI_PROP_DONTPASS, "cpuid", -1);
133 
134 	if (cpuid == -1)
135 		cpuid = get_portid_ddi(dip, NULL);
136 	if (cpuid != target->cpuid)
137 		goto out;
138 
139 	/* Found it */
140 	rv = DDI_WALK_TERMINATE;
141 	target->dip = dip;
142 
143 out:
144 	ddi_prop_free(type);
145 	return (rv);
146 }
147 
148 /*
149  * Routine used to setup a newly inserted CPU in preparation for starting
150  * it running code.
151  */
152 int
153 mp_cpu_configure(int cpuid)
154 {
155 	extern void fill_cpu_ddi(dev_info_t *);
156 	extern int setup_cpu_common(int);
157 	struct mp_find_cpu_arg target;
158 
159 	ASSERT(MUTEX_HELD(&cpu_lock));
160 
161 	target.dip = NULL;
162 	target.cpuid = cpuid;
163 	ddi_walk_devs(ddi_root_node(), mp_find_cpu, &target);
164 
165 	if (target.dip == NULL)
166 		return (ENODEV);
167 
168 	/*
169 	 * Note:  uses cpu_lock to protect cpunodes and ncpunodes
170 	 * which will be modified inside of fill_cpu_ddi().
171 	 */
172 	fill_cpu_ddi(target.dip);
173 
174 	/*
175 	 * sun4v cpu setup may fail. sun4u assumes cpu setup to
176 	 * be always successful, so the return value is ignored.
177 	 */
178 	(void) setup_cpu_common(cpuid);
179 
180 	return (0);
181 }
182