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