xref: /onnv-gate/usr/src/uts/sun4u/io/sbd_cpu.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 /*
30*0Sstevel@tonic-gate  * CPU support routines for DR
31*0Sstevel@tonic-gate  */
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate #include <sys/debug.h>
34*0Sstevel@tonic-gate #include <sys/types.h>
35*0Sstevel@tonic-gate #include <sys/errno.h>
36*0Sstevel@tonic-gate #include <sys/cred.h>
37*0Sstevel@tonic-gate #include <sys/dditypes.h>
38*0Sstevel@tonic-gate #include <sys/devops.h>
39*0Sstevel@tonic-gate #include <sys/modctl.h>
40*0Sstevel@tonic-gate #include <sys/poll.h>
41*0Sstevel@tonic-gate #include <sys/conf.h>
42*0Sstevel@tonic-gate #include <sys/ddi.h>
43*0Sstevel@tonic-gate #include <sys/sunddi.h>
44*0Sstevel@tonic-gate #include <sys/sunndi.h>
45*0Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
46*0Sstevel@tonic-gate #include <sys/ndi_impldefs.h>
47*0Sstevel@tonic-gate #include <sys/stat.h>
48*0Sstevel@tonic-gate #include <sys/kmem.h>
49*0Sstevel@tonic-gate #include <sys/processor.h>
50*0Sstevel@tonic-gate #include <sys/cpuvar.h>
51*0Sstevel@tonic-gate #include <sys/mem_config.h>
52*0Sstevel@tonic-gate #include <sys/promif.h>
53*0Sstevel@tonic-gate #include <sys/x_call.h>
54*0Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h>
55*0Sstevel@tonic-gate #include <sys/membar.h>
56*0Sstevel@tonic-gate #include <sys/stack.h>
57*0Sstevel@tonic-gate #include <sys/sysmacros.h>
58*0Sstevel@tonic-gate #include <sys/machsystm.h>
59*0Sstevel@tonic-gate #include <sys/spitregs.h>
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate #include <sys/archsystm.h>
62*0Sstevel@tonic-gate #include <vm/hat_sfmmu.h>
63*0Sstevel@tonic-gate #include <sys/pte.h>
64*0Sstevel@tonic-gate #include <sys/mmu.h>
65*0Sstevel@tonic-gate #include <sys/x_call.h>
66*0Sstevel@tonic-gate #include <sys/cpu_module.h>
67*0Sstevel@tonic-gate #include <sys/cheetahregs.h>
68*0Sstevel@tonic-gate 
69*0Sstevel@tonic-gate #include <sys/autoconf.h>
70*0Sstevel@tonic-gate #include <sys/cmn_err.h>
71*0Sstevel@tonic-gate 
72*0Sstevel@tonic-gate #include <sys/sbdpriv.h>
73*0Sstevel@tonic-gate 
74*0Sstevel@tonic-gate void
sbd_cpu_set_prop(sbd_cpu_unit_t * cp,dev_info_t * dip)75*0Sstevel@tonic-gate sbd_cpu_set_prop(sbd_cpu_unit_t *cp, dev_info_t *dip)
76*0Sstevel@tonic-gate {
77*0Sstevel@tonic-gate 	uint32_t	clock_freq;
78*0Sstevel@tonic-gate 	int		ecache_size = 0;
79*0Sstevel@tonic-gate 	char		*cache_str = NULL;
80*0Sstevel@tonic-gate 
81*0Sstevel@tonic-gate 	/* read in the CPU speed */
82*0Sstevel@tonic-gate 	clock_freq = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
83*0Sstevel@tonic-gate 	    DDI_PROP_DONTPASS, "clock-frequency", 0);
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate 	ASSERT(clock_freq != 0);
86*0Sstevel@tonic-gate 
87*0Sstevel@tonic-gate 	/*
88*0Sstevel@tonic-gate 	 * The ecache property string is not the same
89*0Sstevel@tonic-gate 	 * for all CPU implementations.
90*0Sstevel@tonic-gate 	 */
91*0Sstevel@tonic-gate 	switch (cp->sbc_cpu_impl) {
92*0Sstevel@tonic-gate 	case CHEETAH_IMPL:
93*0Sstevel@tonic-gate 	case CHEETAH_PLUS_IMPL:
94*0Sstevel@tonic-gate 		cache_str = "ecache-size";
95*0Sstevel@tonic-gate 		break;
96*0Sstevel@tonic-gate 	case JAGUAR_IMPL:
97*0Sstevel@tonic-gate 		cache_str = "l2-cache-size";
98*0Sstevel@tonic-gate 		break;
99*0Sstevel@tonic-gate 	case PANTHER_IMPL:
100*0Sstevel@tonic-gate 		cache_str = "l3-cache-size";
101*0Sstevel@tonic-gate 		break;
102*0Sstevel@tonic-gate 	default:
103*0Sstevel@tonic-gate 		cmn_err(CE_WARN, "cpu implementation type "
104*0Sstevel@tonic-gate 		    "is an unknown %d value", cp->sbc_cpu_impl);
105*0Sstevel@tonic-gate 		ASSERT(0);
106*0Sstevel@tonic-gate 		break;
107*0Sstevel@tonic-gate 	}
108*0Sstevel@tonic-gate 
109*0Sstevel@tonic-gate 	if (cache_str != NULL) {
110*0Sstevel@tonic-gate 		/* read in the ecache size */
111*0Sstevel@tonic-gate 		ecache_size = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
112*0Sstevel@tonic-gate 		    DDI_PROP_DONTPASS, cache_str, 0);
113*0Sstevel@tonic-gate 	}
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate 	/*
116*0Sstevel@tonic-gate 	 * In the case the size is still 0,
117*0Sstevel@tonic-gate 	 * a zero value will be displayed running non-debug.
118*0Sstevel@tonic-gate 	 */
119*0Sstevel@tonic-gate 	ASSERT(ecache_size != 0);
120*0Sstevel@tonic-gate 
121*0Sstevel@tonic-gate 	/* convert to the proper units */
122*0Sstevel@tonic-gate 	cp->sbc_speed = (clock_freq + 500000) / 1000000;
123*0Sstevel@tonic-gate 	cp->sbc_ecache = ecache_size / (1024 * 1024);
124*0Sstevel@tonic-gate }
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate static void
sbd_fill_cpu_stat(sbd_cpu_unit_t * cp,dev_info_t * dip,sbd_cpu_stat_t * csp)127*0Sstevel@tonic-gate sbd_fill_cpu_stat(sbd_cpu_unit_t *cp, dev_info_t *dip, sbd_cpu_stat_t *csp)
128*0Sstevel@tonic-gate {
129*0Sstevel@tonic-gate 	int		namelen;
130*0Sstevel@tonic-gate 
131*0Sstevel@tonic-gate 	bzero((caddr_t)csp, sizeof (*csp));
132*0Sstevel@tonic-gate 	csp->cs_type = cp->sbc_cm.sbdev_type;
133*0Sstevel@tonic-gate 	csp->cs_unit = cp->sbc_cm.sbdev_unum;
134*0Sstevel@tonic-gate 	namelen = sizeof (csp->cs_name);
135*0Sstevel@tonic-gate 	(void) ddi_getlongprop_buf(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
136*0Sstevel@tonic-gate 	    OBP_DEVICETYPE, (caddr_t)csp->cs_name, &namelen);
137*0Sstevel@tonic-gate 	csp->cs_busy = cp->sbc_cm.sbdev_busy;
138*0Sstevel@tonic-gate 	csp->cs_time = cp->sbc_cm.sbdev_time;
139*0Sstevel@tonic-gate 	csp->cs_ostate = cp->sbc_cm.sbdev_ostate;
140*0Sstevel@tonic-gate 	csp->cs_cpuid = cp->sbc_cpu_id;
141*0Sstevel@tonic-gate 	csp->cs_suspend = 0;
142*0Sstevel@tonic-gate 
143*0Sstevel@tonic-gate 	/*
144*0Sstevel@tonic-gate 	 * If we have marked the cpu's condition previously
145*0Sstevel@tonic-gate 	 * then don't rewrite it
146*0Sstevel@tonic-gate 	 */
147*0Sstevel@tonic-gate 	if (csp->cs_cond != SBD_COND_UNUSABLE)
148*0Sstevel@tonic-gate 		csp->cs_cond = sbd_get_comp_cond(dip);
149*0Sstevel@tonic-gate 
150*0Sstevel@tonic-gate 	/*
151*0Sstevel@tonic-gate 	 * If the speed and ecache properties have not been
152*0Sstevel@tonic-gate 	 * cached yet, read them in from the device tree.
153*0Sstevel@tonic-gate 	 */
154*0Sstevel@tonic-gate 	if ((cp->sbc_speed == 0) || (cp->sbc_ecache == 0))
155*0Sstevel@tonic-gate 		sbd_cpu_set_prop(cp, dip);
156*0Sstevel@tonic-gate 
157*0Sstevel@tonic-gate 	/* use the cached speed and ecache values */
158*0Sstevel@tonic-gate 	csp->cs_speed = cp->sbc_speed;
159*0Sstevel@tonic-gate 	csp->cs_ecache = cp->sbc_ecache;
160*0Sstevel@tonic-gate }
161*0Sstevel@tonic-gate 
162*0Sstevel@tonic-gate static void
sbd_fill_cmp_stat(sbd_cpu_stat_t * csp,int ncores,int impl,sbd_cmp_stat_t * psp)163*0Sstevel@tonic-gate sbd_fill_cmp_stat(sbd_cpu_stat_t *csp, int ncores, int impl,
164*0Sstevel@tonic-gate     sbd_cmp_stat_t *psp)
165*0Sstevel@tonic-gate {
166*0Sstevel@tonic-gate 	int	core;
167*0Sstevel@tonic-gate 
168*0Sstevel@tonic-gate 	ASSERT(csp && psp && (ncores >= 1));
169*0Sstevel@tonic-gate 
170*0Sstevel@tonic-gate 	bzero((caddr_t)psp, sizeof (*psp));
171*0Sstevel@tonic-gate 
172*0Sstevel@tonic-gate 	/*
173*0Sstevel@tonic-gate 	 * Fill in the common status information based
174*0Sstevel@tonic-gate 	 * on the data for the first core.
175*0Sstevel@tonic-gate 	 */
176*0Sstevel@tonic-gate 	psp->ps_type = SBD_COMP_CMP;
177*0Sstevel@tonic-gate 	psp->ps_unit = SBD_CMP_NUM(csp->cs_unit);
178*0Sstevel@tonic-gate 	(void) strncpy(psp->ps_name, csp->cs_name, sizeof (psp->ps_name));
179*0Sstevel@tonic-gate 	psp->ps_cond = csp->cs_cond;
180*0Sstevel@tonic-gate 	psp->ps_busy = csp->cs_busy;
181*0Sstevel@tonic-gate 	psp->ps_time = csp->cs_time;
182*0Sstevel@tonic-gate 	psp->ps_ostate = csp->cs_ostate;
183*0Sstevel@tonic-gate 	psp->ps_suspend = csp->cs_suspend;
184*0Sstevel@tonic-gate 
185*0Sstevel@tonic-gate 	/* CMP specific status data */
186*0Sstevel@tonic-gate 	*psp->ps_cpuid = csp->cs_cpuid;
187*0Sstevel@tonic-gate 	psp->ps_ncores = 1;
188*0Sstevel@tonic-gate 	psp->ps_speed = csp->cs_speed;
189*0Sstevel@tonic-gate 	psp->ps_ecache = csp->cs_ecache;
190*0Sstevel@tonic-gate 
191*0Sstevel@tonic-gate 	/*
192*0Sstevel@tonic-gate 	 * Walk through the data for the remaining cores.
193*0Sstevel@tonic-gate 	 * Make any adjustments to the common status data,
194*0Sstevel@tonic-gate 	 * or the shared CMP specific data if necessary.
195*0Sstevel@tonic-gate 	 */
196*0Sstevel@tonic-gate 	for (core = 1; core < ncores; core++) {
197*0Sstevel@tonic-gate 
198*0Sstevel@tonic-gate 		/*
199*0Sstevel@tonic-gate 		 * The following properties should be the same
200*0Sstevel@tonic-gate 		 * for all the cores of the CMP.
201*0Sstevel@tonic-gate 		 */
202*0Sstevel@tonic-gate 		ASSERT(psp->ps_unit == SBD_CMP_NUM(csp[core].cs_unit));
203*0Sstevel@tonic-gate 		ASSERT(psp->ps_speed == csp[core].cs_speed);
204*0Sstevel@tonic-gate 
205*0Sstevel@tonic-gate 		psp->ps_cpuid[core] = csp[core].cs_cpuid;
206*0Sstevel@tonic-gate 		psp->ps_ncores++;
207*0Sstevel@tonic-gate 
208*0Sstevel@tonic-gate 		/*
209*0Sstevel@tonic-gate 		 * Jaguar has a split ecache, so the ecache
210*0Sstevel@tonic-gate 		 * for each core must be added together to
211*0Sstevel@tonic-gate 		 * get the total ecache for the whole chip.
212*0Sstevel@tonic-gate 		 */
213*0Sstevel@tonic-gate 		if (IS_JAGUAR(impl)) {
214*0Sstevel@tonic-gate 			psp->ps_ecache += csp[core].cs_ecache;
215*0Sstevel@tonic-gate 		}
216*0Sstevel@tonic-gate 
217*0Sstevel@tonic-gate 		/* adjust time if necessary */
218*0Sstevel@tonic-gate 		if (csp[core].cs_time > psp->ps_time) {
219*0Sstevel@tonic-gate 			psp->ps_time = csp[core].cs_time;
220*0Sstevel@tonic-gate 		}
221*0Sstevel@tonic-gate 
222*0Sstevel@tonic-gate 		psp->ps_busy |= csp[core].cs_busy;
223*0Sstevel@tonic-gate 
224*0Sstevel@tonic-gate 		/*
225*0Sstevel@tonic-gate 		 * If any of the cores are configured, the
226*0Sstevel@tonic-gate 		 * entire CMP is marked as configured.
227*0Sstevel@tonic-gate 		 */
228*0Sstevel@tonic-gate 		if (csp[core].cs_ostate == SBD_STAT_CONFIGURED) {
229*0Sstevel@tonic-gate 			psp->ps_ostate = csp[core].cs_ostate;
230*0Sstevel@tonic-gate 		}
231*0Sstevel@tonic-gate 	}
232*0Sstevel@tonic-gate }
233*0Sstevel@tonic-gate 
234*0Sstevel@tonic-gate int
sbd_cpu_flags(sbd_handle_t * hp,sbd_devset_t devset,sbd_dev_stat_t * dsp)235*0Sstevel@tonic-gate sbd_cpu_flags(sbd_handle_t *hp, sbd_devset_t devset, sbd_dev_stat_t *dsp)
236*0Sstevel@tonic-gate {
237*0Sstevel@tonic-gate 	int		cmp;
238*0Sstevel@tonic-gate 	int		ncpu;
239*0Sstevel@tonic-gate 	sbd_board_t	*sbp;
240*0Sstevel@tonic-gate 	sbdp_handle_t	*hdp;
241*0Sstevel@tonic-gate 	sbd_cpu_stat_t	cstat[MAX_CORES_PER_CMP];
242*0Sstevel@tonic-gate 
243*0Sstevel@tonic-gate 	sbp = SBDH2BD(hp->h_sbd);
244*0Sstevel@tonic-gate 	hdp = sbd_get_sbdp_handle(sbp, hp);
245*0Sstevel@tonic-gate 
246*0Sstevel@tonic-gate 	/*
247*0Sstevel@tonic-gate 	 * Grab the status lock before accessing the dip as we allow
248*0Sstevel@tonic-gate 	 * concurrent status and branch unconfigure and disconnect.
249*0Sstevel@tonic-gate 	 *
250*0Sstevel@tonic-gate 	 * The disconnect thread clears the present devset first
251*0Sstevel@tonic-gate 	 * and then destroys dips. It is possible that the status
252*0Sstevel@tonic-gate 	 * thread checks the present devset before they are cleared
253*0Sstevel@tonic-gate 	 * but accesses the dip after they are destroyed causing a
254*0Sstevel@tonic-gate 	 * panic. To prevent this, the status thread should check
255*0Sstevel@tonic-gate 	 * the present devset and access dips with status lock held.
256*0Sstevel@tonic-gate 	 * Similarly disconnect thread should clear the present devset
257*0Sstevel@tonic-gate 	 * and destroy dips with status lock held.
258*0Sstevel@tonic-gate 	 */
259*0Sstevel@tonic-gate 	mutex_enter(&sbp->sb_slock);
260*0Sstevel@tonic-gate 
261*0Sstevel@tonic-gate 	/*
262*0Sstevel@tonic-gate 	 * Only look for requested devices that are actually present.
263*0Sstevel@tonic-gate 	 */
264*0Sstevel@tonic-gate 	devset &= SBD_DEVS_PRESENT(sbp);
265*0Sstevel@tonic-gate 
266*0Sstevel@tonic-gate 	/*
267*0Sstevel@tonic-gate 	 * Treat every CPU as a CMP.  In the case where the
268*0Sstevel@tonic-gate 	 * device is not a CMP, treat it as a CMP with only
269*0Sstevel@tonic-gate 	 * one core.
270*0Sstevel@tonic-gate 	 */
271*0Sstevel@tonic-gate 	for (cmp = ncpu = 0; cmp < MAX_CMP_UNITS_PER_BOARD; cmp++) {
272*0Sstevel@tonic-gate 
273*0Sstevel@tonic-gate 		int		ncores;
274*0Sstevel@tonic-gate 		int		core;
275*0Sstevel@tonic-gate 		dev_info_t	*dip;
276*0Sstevel@tonic-gate 		sbd_cpu_unit_t	*cp;
277*0Sstevel@tonic-gate 		sbd_cmp_stat_t	*psp;
278*0Sstevel@tonic-gate 
279*0Sstevel@tonic-gate 		if (DEVSET_IN_SET(devset, SBD_COMP_CMP, cmp) == 0)
280*0Sstevel@tonic-gate 			continue;
281*0Sstevel@tonic-gate 
282*0Sstevel@tonic-gate 		ncores = 0;
283*0Sstevel@tonic-gate 
284*0Sstevel@tonic-gate 		for (core = 0; core < MAX_CORES_PER_CMP; core++) {
285*0Sstevel@tonic-gate 			int	unit;
286*0Sstevel@tonic-gate 
287*0Sstevel@tonic-gate 			unit = sbdp_portid_to_cpu_unit(cmp, core);
288*0Sstevel@tonic-gate 
289*0Sstevel@tonic-gate 			/*
290*0Sstevel@tonic-gate 			 * Check to make sure the cpu is in a state
291*0Sstevel@tonic-gate 			 * where its fully initialized.
292*0Sstevel@tonic-gate 			 */
293*0Sstevel@tonic-gate 			if (SBD_DEVICE_STATE(sbp, SBD_COMP_CPU, unit) ==
294*0Sstevel@tonic-gate 			    SBD_STATE_EMPTY)
295*0Sstevel@tonic-gate 				continue;
296*0Sstevel@tonic-gate 
297*0Sstevel@tonic-gate 			dip = sbp->sb_devlist[NIX(SBD_COMP_CMP)][unit];
298*0Sstevel@tonic-gate 			if (dip == NULL)
299*0Sstevel@tonic-gate 				continue;
300*0Sstevel@tonic-gate 
301*0Sstevel@tonic-gate 			cp = SBD_GET_BOARD_CPUUNIT(sbp, unit);
302*0Sstevel@tonic-gate 
303*0Sstevel@tonic-gate 			sbd_fill_cpu_stat(cp, dip, &cstat[ncores++]);
304*0Sstevel@tonic-gate 		}
305*0Sstevel@tonic-gate 
306*0Sstevel@tonic-gate 		if (ncores == 0)
307*0Sstevel@tonic-gate 			continue;
308*0Sstevel@tonic-gate 
309*0Sstevel@tonic-gate 		/*
310*0Sstevel@tonic-gate 		 * Store the data to the outgoing array. If the
311*0Sstevel@tonic-gate 		 * device is a CMP, combine all the data for the
312*0Sstevel@tonic-gate 		 * cores into a single stat structure.
313*0Sstevel@tonic-gate 		 *
314*0Sstevel@tonic-gate 		 * The check for a CMP device uses the last core
315*0Sstevel@tonic-gate 		 * found, assuming that all cores will have the
316*0Sstevel@tonic-gate 		 * same implementation.
317*0Sstevel@tonic-gate 		 */
318*0Sstevel@tonic-gate 		if (CPU_IMPL_IS_CMP(cp->sbc_cpu_impl)) {
319*0Sstevel@tonic-gate 			psp = (sbd_cmp_stat_t *)dsp;
320*0Sstevel@tonic-gate 			sbd_fill_cmp_stat(cstat, ncores, cp->sbc_cpu_impl, psp);
321*0Sstevel@tonic-gate 		} else {
322*0Sstevel@tonic-gate 			ASSERT(ncores == 1);
323*0Sstevel@tonic-gate 			bcopy(cstat, dsp, sizeof (sbd_cpu_stat_t));
324*0Sstevel@tonic-gate 		}
325*0Sstevel@tonic-gate 
326*0Sstevel@tonic-gate 		dsp++;
327*0Sstevel@tonic-gate 		ncpu++;
328*0Sstevel@tonic-gate 	}
329*0Sstevel@tonic-gate 
330*0Sstevel@tonic-gate 	mutex_exit(&sbp->sb_slock);
331*0Sstevel@tonic-gate 
332*0Sstevel@tonic-gate 	sbd_release_sbdp_handle(hdp);
333*0Sstevel@tonic-gate 
334*0Sstevel@tonic-gate 	return (ncpu);
335*0Sstevel@tonic-gate }
336*0Sstevel@tonic-gate 
337*0Sstevel@tonic-gate int
sbd_pre_release_cpu(sbd_handle_t * hp,sbd_devlist_t * devlist,int devnum)338*0Sstevel@tonic-gate sbd_pre_release_cpu(sbd_handle_t *hp, sbd_devlist_t *devlist, int devnum)
339*0Sstevel@tonic-gate {
340*0Sstevel@tonic-gate 	int		i, rv = 0, unit;
341*0Sstevel@tonic-gate 	dev_info_t	*dip;
342*0Sstevel@tonic-gate 	processorid_t	cpuid;
343*0Sstevel@tonic-gate 	struct cpu	*cpup;
344*0Sstevel@tonic-gate 	sbd_board_t	*sbp = SBDH2BD(hp->h_sbd);
345*0Sstevel@tonic-gate 	sbderror_t	*ep = SBD_HD2ERR(hp);
346*0Sstevel@tonic-gate 	sbd_cpu_unit_t	*cp;
347*0Sstevel@tonic-gate 	static fn_t	f = "sbd_pre_release_cpu";
348*0Sstevel@tonic-gate 	sbdp_handle_t	*hdp;
349*0Sstevel@tonic-gate 
350*0Sstevel@tonic-gate 	hdp = sbd_get_sbdp_handle(sbp, hp);
351*0Sstevel@tonic-gate 	/*
352*0Sstevel@tonic-gate 	 * May have to juggle bootproc in release_component
353*0Sstevel@tonic-gate 	 */
354*0Sstevel@tonic-gate 	mutex_enter(&cpu_lock);
355*0Sstevel@tonic-gate 
356*0Sstevel@tonic-gate 	for (i = 0; i < devnum; i++, devlist++) {
357*0Sstevel@tonic-gate 		dip = devlist->dv_dip;
358*0Sstevel@tonic-gate 
359*0Sstevel@tonic-gate 		cpuid = sbdp_get_cpuid(hdp, dip);
360*0Sstevel@tonic-gate 		if (cpuid < 0) {
361*0Sstevel@tonic-gate 			if (hp->h_flags & SBD_IOCTL_FLAG_FORCE) {
362*0Sstevel@tonic-gate 				cmn_err(CE_WARN,
363*0Sstevel@tonic-gate 					"sbd:%s: failed to get cpuid for "
364*0Sstevel@tonic-gate 					"dip (0x%p)", f, (void *)dip);
365*0Sstevel@tonic-gate 				continue;
366*0Sstevel@tonic-gate 			} else {
367*0Sstevel@tonic-gate 				SBD_GET_PERR(hdp->h_err, SBD_HD2ERR(hp));
368*0Sstevel@tonic-gate 				break;
369*0Sstevel@tonic-gate 			}
370*0Sstevel@tonic-gate 		}
371*0Sstevel@tonic-gate 
372*0Sstevel@tonic-gate 
373*0Sstevel@tonic-gate 		unit = sbdp_get_unit_num(hdp, dip);
374*0Sstevel@tonic-gate 		if (unit < 0) {
375*0Sstevel@tonic-gate 			if (hp->h_flags & SBD_IOCTL_FLAG_FORCE) {
376*0Sstevel@tonic-gate 			cmn_err(CE_WARN,
377*0Sstevel@tonic-gate 				"sbd:%s: failed to get unit (cpu %d)",
378*0Sstevel@tonic-gate 				f, cpuid);
379*0Sstevel@tonic-gate 				continue;
380*0Sstevel@tonic-gate 			} else {
381*0Sstevel@tonic-gate 				SBD_GET_PERR(hdp->h_err, SBD_HD2ERR(hp));
382*0Sstevel@tonic-gate 				break;
383*0Sstevel@tonic-gate 			}
384*0Sstevel@tonic-gate 		}
385*0Sstevel@tonic-gate 
386*0Sstevel@tonic-gate 		cp = SBD_GET_BOARD_CPUUNIT(sbp, unit);
387*0Sstevel@tonic-gate 		cp->sbc_cpu_flags = cpu[cpuid]->cpu_flags;
388*0Sstevel@tonic-gate 
389*0Sstevel@tonic-gate 		if (cpu_flagged_active(cp->sbc_cpu_flags)) {
390*0Sstevel@tonic-gate 			int cpu_offline_flags = 0;
391*0Sstevel@tonic-gate 
392*0Sstevel@tonic-gate 			if (hp->h_flags & SBD_IOCTL_FLAG_FORCE)
393*0Sstevel@tonic-gate 				cpu_offline_flags = CPU_FORCED;
394*0Sstevel@tonic-gate 			PR_CPU("%s: offlining cpuid %d unit %d", f,
395*0Sstevel@tonic-gate 				cpuid, unit);
396*0Sstevel@tonic-gate 			if (cpu_offline(cpu[cpuid], cpu_offline_flags)) {
397*0Sstevel@tonic-gate 				cmn_err(CE_WARN,
398*0Sstevel@tonic-gate 					"%s: failed to offline cpu %d",
399*0Sstevel@tonic-gate 					f, cpuid);
400*0Sstevel@tonic-gate 				rv = -1;
401*0Sstevel@tonic-gate 				SBD_SET_ERR(ep, ESBD_OFFLINE);
402*0Sstevel@tonic-gate 				SBD_SET_ERRSTR(ep, sbp->sb_cpupath[i]);
403*0Sstevel@tonic-gate 				cpup = cpu_get(cpuid);
404*0Sstevel@tonic-gate 				if (cpup && disp_bound_threads(cpup, 0)) {
405*0Sstevel@tonic-gate 					cmn_err(CE_WARN, "sbd:%s: thread(s) "
406*0Sstevel@tonic-gate 						"bound to cpu %d",
407*0Sstevel@tonic-gate 						f, cpup->cpu_id);
408*0Sstevel@tonic-gate 				}
409*0Sstevel@tonic-gate 				break;
410*0Sstevel@tonic-gate 			}
411*0Sstevel@tonic-gate 		}
412*0Sstevel@tonic-gate 
413*0Sstevel@tonic-gate 		if (rv == 0) {
414*0Sstevel@tonic-gate 			if (sbdp_release_component(hdp, dip)) {
415*0Sstevel@tonic-gate 				SBD_GET_PERR(hdp->h_err, ep);
416*0Sstevel@tonic-gate 				break;
417*0Sstevel@tonic-gate 			}
418*0Sstevel@tonic-gate 		}
419*0Sstevel@tonic-gate 
420*0Sstevel@tonic-gate 		if (rv)
421*0Sstevel@tonic-gate 			break;
422*0Sstevel@tonic-gate 	}
423*0Sstevel@tonic-gate 
424*0Sstevel@tonic-gate 	mutex_exit(&cpu_lock);
425*0Sstevel@tonic-gate 
426*0Sstevel@tonic-gate 	if (rv) {
427*0Sstevel@tonic-gate 		/*
428*0Sstevel@tonic-gate 		 * Need to unwind others since at this level (pre-release)
429*0Sstevel@tonic-gate 		 * the device state has not yet transitioned and failures
430*0Sstevel@tonic-gate 		 * will prevent us from reaching the "post" release
431*0Sstevel@tonic-gate 		 * function where states are normally transitioned.
432*0Sstevel@tonic-gate 		 */
433*0Sstevel@tonic-gate 		for (; i >= 0; i--, devlist--) {
434*0Sstevel@tonic-gate 			dip = devlist->dv_dip;
435*0Sstevel@tonic-gate 			unit = sbdp_get_unit_num(hdp, dip);
436*0Sstevel@tonic-gate 			if (unit < 0) {
437*0Sstevel@tonic-gate 				cmn_err(CE_WARN,
438*0Sstevel@tonic-gate 					"sbd:%s: failed to get unit for "
439*0Sstevel@tonic-gate 					"dip (0x%p)", f, (void *)dip);
440*0Sstevel@tonic-gate 				break;
441*0Sstevel@tonic-gate 			}
442*0Sstevel@tonic-gate 			(void) sbd_cancel_cpu(hp, unit);
443*0Sstevel@tonic-gate 		}
444*0Sstevel@tonic-gate 	}
445*0Sstevel@tonic-gate 
446*0Sstevel@tonic-gate 	SBD_INJECT_ERR(SBD_OFFLINE_CPU_PSEUDO_ERR,
447*0Sstevel@tonic-gate 		hp->h_err, EIO,
448*0Sstevel@tonic-gate 		ESBD_OFFLINE,
449*0Sstevel@tonic-gate 		sbp->sb_cpupath[devnum - 1]);
450*0Sstevel@tonic-gate 
451*0Sstevel@tonic-gate 	sbd_release_sbdp_handle(hdp);
452*0Sstevel@tonic-gate 
453*0Sstevel@tonic-gate 	return (rv);
454*0Sstevel@tonic-gate }
455*0Sstevel@tonic-gate 
456*0Sstevel@tonic-gate int
sbd_pre_attach_cpu(sbd_handle_t * hp,sbd_devlist_t * devlist,int devnum)457*0Sstevel@tonic-gate sbd_pre_attach_cpu(sbd_handle_t *hp, sbd_devlist_t *devlist, int devnum)
458*0Sstevel@tonic-gate {
459*0Sstevel@tonic-gate 	int		i;
460*0Sstevel@tonic-gate 	int		unit;
461*0Sstevel@tonic-gate 	processorid_t	cpuid;
462*0Sstevel@tonic-gate 	sbd_board_t	*sbp = SBDH2BD(hp->h_sbd);
463*0Sstevel@tonic-gate 	sbd_istate_t	dstate;
464*0Sstevel@tonic-gate 	dev_info_t	*dip;
465*0Sstevel@tonic-gate 	static fn_t	f = "sbd_pre_attach_cpu";
466*0Sstevel@tonic-gate 	sbdp_handle_t	*hdp;
467*0Sstevel@tonic-gate 
468*0Sstevel@tonic-gate 	PR_CPU("%s...\n", f);
469*0Sstevel@tonic-gate 
470*0Sstevel@tonic-gate 	hdp = sbd_get_sbdp_handle(sbp, hp);
471*0Sstevel@tonic-gate 
472*0Sstevel@tonic-gate 	for (i = 0; i < devnum; i++, devlist++) {
473*0Sstevel@tonic-gate 		dip = devlist->dv_dip;
474*0Sstevel@tonic-gate 
475*0Sstevel@tonic-gate 		ASSERT(sbd_is_cmp_child(dip) || e_ddi_branch_held(dip));
476*0Sstevel@tonic-gate 
477*0Sstevel@tonic-gate 		cpuid = sbdp_get_cpuid(hdp, dip);
478*0Sstevel@tonic-gate 		if (cpuid < 0) {
479*0Sstevel@tonic-gate 			if (hp->h_flags & SBD_IOCTL_FLAG_FORCE) {
480*0Sstevel@tonic-gate 				cmn_err(CE_WARN,
481*0Sstevel@tonic-gate 					"sbd:%s: failed to get cpuid for "
482*0Sstevel@tonic-gate 					"dip (0x%p)", f, (void *)dip);
483*0Sstevel@tonic-gate 				continue;
484*0Sstevel@tonic-gate 			} else {
485*0Sstevel@tonic-gate 				SBD_GET_PERR(hdp->h_err, SBD_HD2ERR(hp));
486*0Sstevel@tonic-gate 				break;
487*0Sstevel@tonic-gate 			}
488*0Sstevel@tonic-gate 		}
489*0Sstevel@tonic-gate 
490*0Sstevel@tonic-gate 		unit = sbdp_get_unit_num(hdp, dip);
491*0Sstevel@tonic-gate 		if (unit < 0) {
492*0Sstevel@tonic-gate 			if (hp->h_flags & SBD_IOCTL_FLAG_FORCE) {
493*0Sstevel@tonic-gate 			cmn_err(CE_WARN,
494*0Sstevel@tonic-gate 				"sbd:%s: failed to get unit (cpu %d)",
495*0Sstevel@tonic-gate 				f, cpuid);
496*0Sstevel@tonic-gate 				continue;
497*0Sstevel@tonic-gate 			} else {
498*0Sstevel@tonic-gate 				SBD_GET_PERR(hdp->h_err, SBD_HD2ERR(hp));
499*0Sstevel@tonic-gate 				break;
500*0Sstevel@tonic-gate 			}
501*0Sstevel@tonic-gate 		}
502*0Sstevel@tonic-gate 
503*0Sstevel@tonic-gate 		PR_CPU("%s: attach cpu-unit (%d.%d)\n",
504*0Sstevel@tonic-gate 			f, sbp->sb_num, unit);
505*0Sstevel@tonic-gate 
506*0Sstevel@tonic-gate 		dstate = SBD_DEVICE_STATE(sbp, SBD_COMP_CPU, unit);
507*0Sstevel@tonic-gate 
508*0Sstevel@tonic-gate 		if (dstate == SBD_STATE_UNCONFIGURED) {
509*0Sstevel@tonic-gate 			/*
510*0Sstevel@tonic-gate 			 * If we're coming from the UNCONFIGURED
511*0Sstevel@tonic-gate 			 * state then the cpu's sigblock will
512*0Sstevel@tonic-gate 			 * still be mapped in.  Need to unmap it
513*0Sstevel@tonic-gate 			 * before continuing with attachment.
514*0Sstevel@tonic-gate 			 */
515*0Sstevel@tonic-gate 			PR_CPU("%s: unmapping sigblk for cpu %d\n",
516*0Sstevel@tonic-gate 				f, cpuid);
517*0Sstevel@tonic-gate 
518*0Sstevel@tonic-gate 			/* platform specific release of sigblk */
519*0Sstevel@tonic-gate 			CPU_SGN_MAPOUT(cpuid);
520*0Sstevel@tonic-gate 		}
521*0Sstevel@tonic-gate 
522*0Sstevel@tonic-gate 	}
523*0Sstevel@tonic-gate 
524*0Sstevel@tonic-gate 	mutex_enter(&cpu_lock);
525*0Sstevel@tonic-gate 
526*0Sstevel@tonic-gate 	sbd_release_sbdp_handle(hdp);
527*0Sstevel@tonic-gate 
528*0Sstevel@tonic-gate 	return (0);
529*0Sstevel@tonic-gate }
530*0Sstevel@tonic-gate 
531*0Sstevel@tonic-gate int
sbd_post_attach_cpu(sbd_handle_t * hp,sbd_devlist_t * devlist,int devnum)532*0Sstevel@tonic-gate sbd_post_attach_cpu(sbd_handle_t *hp, sbd_devlist_t *devlist, int devnum)
533*0Sstevel@tonic-gate {
534*0Sstevel@tonic-gate 	int		i;
535*0Sstevel@tonic-gate 	sbderror_t	*ep = SBD_HD2ERR(hp);
536*0Sstevel@tonic-gate 	sbd_board_t	*sbp = SBDH2BD(hp->h_sbd);
537*0Sstevel@tonic-gate 	processorid_t	cpuid;
538*0Sstevel@tonic-gate 	struct cpu	*cp;
539*0Sstevel@tonic-gate 	dev_info_t	*dip;
540*0Sstevel@tonic-gate 	int		err = ESBD_NOERROR;
541*0Sstevel@tonic-gate 	sbdp_handle_t	*hdp;
542*0Sstevel@tonic-gate 	static fn_t	f = "sbd_post_attach_cpu";
543*0Sstevel@tonic-gate 	sbd_cpu_unit_t	*cpup;
544*0Sstevel@tonic-gate 	int		unit;
545*0Sstevel@tonic-gate 
546*0Sstevel@tonic-gate 	hdp = sbd_get_sbdp_handle(sbp, hp);
547*0Sstevel@tonic-gate 
548*0Sstevel@tonic-gate 	/* Startup and online newly-attached CPUs */
549*0Sstevel@tonic-gate 	for (i = 0; i < devnum; i++, devlist++) {
550*0Sstevel@tonic-gate 		dip = devlist->dv_dip;
551*0Sstevel@tonic-gate 		cpuid = sbdp_get_cpuid(hdp, dip);
552*0Sstevel@tonic-gate 		if (cpuid < 0) {
553*0Sstevel@tonic-gate 			if (hp->h_flags & SBD_IOCTL_FLAG_FORCE) {
554*0Sstevel@tonic-gate 				cmn_err(CE_WARN,
555*0Sstevel@tonic-gate 				    "sbd:%s: failed to get cpuid for "
556*0Sstevel@tonic-gate 				    "dip (0x%p)", f, (void *)dip);
557*0Sstevel@tonic-gate 				continue;
558*0Sstevel@tonic-gate 			} else {
559*0Sstevel@tonic-gate 				SBD_GET_PERR(hdp->h_err, ep);
560*0Sstevel@tonic-gate 				break;
561*0Sstevel@tonic-gate 			}
562*0Sstevel@tonic-gate 		}
563*0Sstevel@tonic-gate 
564*0Sstevel@tonic-gate 		cp = cpu_get(cpuid);
565*0Sstevel@tonic-gate 
566*0Sstevel@tonic-gate 		if (cp == NULL) {
567*0Sstevel@tonic-gate 			if (hp->h_flags & SBD_IOCTL_FLAG_FORCE) {
568*0Sstevel@tonic-gate 				cmn_err(CE_WARN,
569*0Sstevel@tonic-gate 				    "sbd:%s: cpu_get failed for cpu %d",
570*0Sstevel@tonic-gate 				    f, cpuid);
571*0Sstevel@tonic-gate 				continue;
572*0Sstevel@tonic-gate 			} else {
573*0Sstevel@tonic-gate 				SBD_SET_ERR(ep, ESBD_INTERNAL);
574*0Sstevel@tonic-gate 				SBD_SET_ERRSTR(ep, sbp->sb_cpupath[i]);
575*0Sstevel@tonic-gate 				break;
576*0Sstevel@tonic-gate 			}
577*0Sstevel@tonic-gate 		}
578*0Sstevel@tonic-gate 
579*0Sstevel@tonic-gate 		if (cpu_is_poweredoff(cp)) {
580*0Sstevel@tonic-gate 			if (cpu_poweron(cp) != 0) {
581*0Sstevel@tonic-gate 				SBD_SET_ERR(ep, ESBD_CPUSTART);
582*0Sstevel@tonic-gate 				SBD_SET_ERRSTR(ep, sbp->sb_cpupath[i]);
583*0Sstevel@tonic-gate 				cmn_err(CE_WARN,
584*0Sstevel@tonic-gate 				    "%s: failed to power-on cpu %d",
585*0Sstevel@tonic-gate 				    f, cpuid);
586*0Sstevel@tonic-gate 				break;
587*0Sstevel@tonic-gate 			}
588*0Sstevel@tonic-gate 			SBD_INJECT_ERR(SBD_POWERON_CPU_PSEUDO_ERR,
589*0Sstevel@tonic-gate 			    ep, EIO,
590*0Sstevel@tonic-gate 			    ESBD_CPUSTOP,
591*0Sstevel@tonic-gate 			    sbp->sb_cpupath[i]);
592*0Sstevel@tonic-gate 			PR_CPU("%s: cpu %d powered ON\n", f, cpuid);
593*0Sstevel@tonic-gate 		}
594*0Sstevel@tonic-gate 
595*0Sstevel@tonic-gate 		if (cpu_is_offline(cp)) {
596*0Sstevel@tonic-gate 			PR_CPU("%s: onlining cpu %d...\n", f, cpuid);
597*0Sstevel@tonic-gate 
598*0Sstevel@tonic-gate 			if (cpu_online(cp) != 0) {
599*0Sstevel@tonic-gate 				SBD_SET_ERR(ep, ESBD_ONLINE);
600*0Sstevel@tonic-gate 				SBD_SET_ERRSTR(ep, sbp->sb_cpupath[i]);
601*0Sstevel@tonic-gate 				cmn_err(CE_WARN,
602*0Sstevel@tonic-gate 				    "%s: failed to online cpu %d",
603*0Sstevel@tonic-gate 				    f, cp->cpu_id);
604*0Sstevel@tonic-gate 			}
605*0Sstevel@tonic-gate 			SBD_INJECT_ERR(SBD_ONLINE_CPU_PSEUDO_ERR,
606*0Sstevel@tonic-gate 			    ep, EIO,
607*0Sstevel@tonic-gate 			    ESBD_ONLINE,
608*0Sstevel@tonic-gate 			    sbp->sb_cpupath[i]);
609*0Sstevel@tonic-gate 		}
610*0Sstevel@tonic-gate 
611*0Sstevel@tonic-gate 		/*
612*0Sstevel@tonic-gate 		 * if there is no error mark the cpu as OK to use
613*0Sstevel@tonic-gate 		 */
614*0Sstevel@tonic-gate 		if (SBD_GET_ERR(ep) == 0) {
615*0Sstevel@tonic-gate 			unit = sbdp_get_unit_num(hdp, dip);
616*0Sstevel@tonic-gate 			if (unit < 0) {
617*0Sstevel@tonic-gate 				if (hp->h_flags & SBD_IOCTL_FLAG_FORCE) {
618*0Sstevel@tonic-gate 					cmn_err(CE_WARN,
619*0Sstevel@tonic-gate 					    "sbd:%s: failed to get unit "
620*0Sstevel@tonic-gate 					    "(cpu %d)", f, cpuid);
621*0Sstevel@tonic-gate 					continue;
622*0Sstevel@tonic-gate 				} else {
623*0Sstevel@tonic-gate 					SBD_GET_PERR(hdp->h_err,
624*0Sstevel@tonic-gate 					    SBD_HD2ERR(hp));
625*0Sstevel@tonic-gate 					break;
626*0Sstevel@tonic-gate 				}
627*0Sstevel@tonic-gate 			}
628*0Sstevel@tonic-gate 			cpup = SBD_GET_BOARD_CPUUNIT(sbp, unit);
629*0Sstevel@tonic-gate 			cpup->sbc_cm.sbdev_cond = SBD_COND_OK;
630*0Sstevel@tonic-gate 		}
631*0Sstevel@tonic-gate 	}
632*0Sstevel@tonic-gate 
633*0Sstevel@tonic-gate 	mutex_exit(&cpu_lock);
634*0Sstevel@tonic-gate 
635*0Sstevel@tonic-gate 	sbd_release_sbdp_handle(hdp);
636*0Sstevel@tonic-gate 
637*0Sstevel@tonic-gate 	if (err != ESBD_NOERROR) {
638*0Sstevel@tonic-gate 		return (-1);
639*0Sstevel@tonic-gate 	} else {
640*0Sstevel@tonic-gate 		return (0);
641*0Sstevel@tonic-gate 	}
642*0Sstevel@tonic-gate }
643*0Sstevel@tonic-gate 
644*0Sstevel@tonic-gate int
sbd_pre_detach_cpu(sbd_handle_t * hp,sbd_devlist_t * devlist,int devnum)645*0Sstevel@tonic-gate sbd_pre_detach_cpu(sbd_handle_t *hp, sbd_devlist_t *devlist, int devnum)
646*0Sstevel@tonic-gate {
647*0Sstevel@tonic-gate 	int		i;
648*0Sstevel@tonic-gate 	int		unit;
649*0Sstevel@tonic-gate 	processorid_t	cpuid;
650*0Sstevel@tonic-gate 	dev_info_t	*dip;
651*0Sstevel@tonic-gate 	struct cpu	*cpu;
652*0Sstevel@tonic-gate 	sbd_board_t	*sbp = SBDH2BD(hp->h_sbd);
653*0Sstevel@tonic-gate 	sbderror_t	*ep = SBD_HD2ERR(hp);
654*0Sstevel@tonic-gate 	static fn_t	f = "sbd_pre_detach_cpu";
655*0Sstevel@tonic-gate 	sbdp_handle_t	*hdp;
656*0Sstevel@tonic-gate 	int		rv = 0;
657*0Sstevel@tonic-gate 
658*0Sstevel@tonic-gate 	PR_CPU("%s...\n", f);
659*0Sstevel@tonic-gate 
660*0Sstevel@tonic-gate 	hdp = sbd_get_sbdp_handle(sbp, hp);
661*0Sstevel@tonic-gate 
662*0Sstevel@tonic-gate 	mutex_enter(&cpu_lock);
663*0Sstevel@tonic-gate 
664*0Sstevel@tonic-gate 	for (i = 0; i < devnum; i++, devlist++) {
665*0Sstevel@tonic-gate 		dip = devlist->dv_dip;
666*0Sstevel@tonic-gate 		cpuid = sbdp_get_cpuid(hdp, dip);
667*0Sstevel@tonic-gate 		if (cpuid < 0) {
668*0Sstevel@tonic-gate 			if (hp->h_flags & SBD_IOCTL_FLAG_FORCE) {
669*0Sstevel@tonic-gate 				cmn_err(CE_WARN,
670*0Sstevel@tonic-gate 				    "sbd:%s: failed to get cpuid for "
671*0Sstevel@tonic-gate 				    "dip (0x%p)", f, (void *)dip);
672*0Sstevel@tonic-gate 				continue;
673*0Sstevel@tonic-gate 			} else {
674*0Sstevel@tonic-gate 				SBD_GET_PERR(hdp->h_err, SBD_HD2ERR(hp));
675*0Sstevel@tonic-gate 				break;
676*0Sstevel@tonic-gate 			}
677*0Sstevel@tonic-gate 		}
678*0Sstevel@tonic-gate 
679*0Sstevel@tonic-gate 		cpu = cpu_get(cpuid);
680*0Sstevel@tonic-gate 
681*0Sstevel@tonic-gate 		if (cpu == NULL) {
682*0Sstevel@tonic-gate 			if (hp->h_flags & SBD_IOCTL_FLAG_FORCE) {
683*0Sstevel@tonic-gate 				cmn_err(CE_WARN,
684*0Sstevel@tonic-gate 				    "sbd:%s: failed to get cpu %d",
685*0Sstevel@tonic-gate 				    f, cpuid);
686*0Sstevel@tonic-gate 				continue;
687*0Sstevel@tonic-gate 			} else {
688*0Sstevel@tonic-gate 				SBD_SET_ERR(ep, ESBD_INTERNAL);
689*0Sstevel@tonic-gate 				SBD_SET_ERRSTR(ep, sbp->sb_cpupath[i]);
690*0Sstevel@tonic-gate 				break;
691*0Sstevel@tonic-gate 			}
692*0Sstevel@tonic-gate 		}
693*0Sstevel@tonic-gate 
694*0Sstevel@tonic-gate 		unit = sbdp_get_unit_num(hdp, dip);
695*0Sstevel@tonic-gate 		if (unit < 0) {
696*0Sstevel@tonic-gate 			if (hp->h_flags & SBD_IOCTL_FLAG_FORCE) {
697*0Sstevel@tonic-gate 				cmn_err(CE_WARN,
698*0Sstevel@tonic-gate 				    "sbd:%s: failed to get unit (cpu %d)",
699*0Sstevel@tonic-gate 				    f, cpuid);
700*0Sstevel@tonic-gate 				continue;
701*0Sstevel@tonic-gate 			} else {
702*0Sstevel@tonic-gate 				SBD_GET_PERR(hdp->h_err, SBD_HD2ERR(hp));
703*0Sstevel@tonic-gate 				break;
704*0Sstevel@tonic-gate 			}
705*0Sstevel@tonic-gate 		}
706*0Sstevel@tonic-gate 
707*0Sstevel@tonic-gate 		PR_CPU("%s: OS detach cpu-unit (%d.%d)\n",
708*0Sstevel@tonic-gate 		    f, sbp->sb_num, unit);
709*0Sstevel@tonic-gate 
710*0Sstevel@tonic-gate 		/*
711*0Sstevel@tonic-gate 		 * CPUs were offlined during Release.
712*0Sstevel@tonic-gate 		 */
713*0Sstevel@tonic-gate 		if (cpu_is_poweredoff(cpu)) {
714*0Sstevel@tonic-gate 			PR_CPU("%s: cpu %d already powered OFF\n", f, cpuid);
715*0Sstevel@tonic-gate 			continue;
716*0Sstevel@tonic-gate 		}
717*0Sstevel@tonic-gate 
718*0Sstevel@tonic-gate 		if (cpu_is_offline(cpu)) {
719*0Sstevel@tonic-gate 			int	e;
720*0Sstevel@tonic-gate 
721*0Sstevel@tonic-gate 			if (e = cpu_poweroff(cpu)) {
722*0Sstevel@tonic-gate 				cmn_err(CE_WARN,
723*0Sstevel@tonic-gate 				    "%s: failed to power-off cpu %d "
724*0Sstevel@tonic-gate 				    "(errno %d)",
725*0Sstevel@tonic-gate 				    f, cpu->cpu_id, e);
726*0Sstevel@tonic-gate 				SBD_SET_ERR(ep, ESBD_CPUSTOP);
727*0Sstevel@tonic-gate 				SBD_SET_ERRSTR(ep, sbp->sb_cpupath[i]);
728*0Sstevel@tonic-gate 
729*0Sstevel@tonic-gate 				rv = -1;
730*0Sstevel@tonic-gate 				break;
731*0Sstevel@tonic-gate 			} else {
732*0Sstevel@tonic-gate 				PR_CPU("%s: cpu %d powered OFF\n",
733*0Sstevel@tonic-gate 					f, cpuid);
734*0Sstevel@tonic-gate 			}
735*0Sstevel@tonic-gate 		} else {
736*0Sstevel@tonic-gate 			cmn_err(CE_WARN, "%s: cpu %d still active",
737*0Sstevel@tonic-gate 				f, cpu->cpu_id);
738*0Sstevel@tonic-gate 			SBD_SET_ERR(ep, ESBD_BUSY);
739*0Sstevel@tonic-gate 			SBD_SET_ERRSTR(ep, sbp->sb_cpupath[i]);
740*0Sstevel@tonic-gate 			rv = -1;
741*0Sstevel@tonic-gate 			break;
742*0Sstevel@tonic-gate 		}
743*0Sstevel@tonic-gate 	}
744*0Sstevel@tonic-gate 
745*0Sstevel@tonic-gate 	sbd_release_sbdp_handle(hdp);
746*0Sstevel@tonic-gate 
747*0Sstevel@tonic-gate 	return (rv);
748*0Sstevel@tonic-gate }
749*0Sstevel@tonic-gate 
750*0Sstevel@tonic-gate int
sbd_post_detach_cpu(sbd_handle_t * hp,sbd_devlist_t * devlist,int devnum)751*0Sstevel@tonic-gate sbd_post_detach_cpu(sbd_handle_t *hp, sbd_devlist_t *devlist, int devnum)
752*0Sstevel@tonic-gate {
753*0Sstevel@tonic-gate 	static fn_t	f = "sbd_post_detach_cpu";
754*0Sstevel@tonic-gate 	int		i;
755*0Sstevel@tonic-gate 	sbderror_t	*ep = SBD_HD2ERR(hp);
756*0Sstevel@tonic-gate 	sbd_board_t	*sbp = SBDH2BD(hp->h_sbd);
757*0Sstevel@tonic-gate 	processorid_t	cpuid;
758*0Sstevel@tonic-gate 	dev_info_t	*dip;
759*0Sstevel@tonic-gate 	sbdp_handle_t	*hdp;
760*0Sstevel@tonic-gate 	sbd_cpu_unit_t	*cpup;
761*0Sstevel@tonic-gate 	int		unit;
762*0Sstevel@tonic-gate 
763*0Sstevel@tonic-gate 	PR_CPU("%s...\n", f);
764*0Sstevel@tonic-gate 
765*0Sstevel@tonic-gate 	/*
766*0Sstevel@tonic-gate 	 * We should be holding the cpu_lock at this point,
767*0Sstevel@tonic-gate 	 * and should have blocked device tree changes.
768*0Sstevel@tonic-gate 	 */
769*0Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
770*0Sstevel@tonic-gate 
771*0Sstevel@tonic-gate 	for (i = 0; i < devnum; i++, devlist++) {
772*0Sstevel@tonic-gate 		dip = devlist->dv_dip;
773*0Sstevel@tonic-gate 		hdp = sbd_get_sbdp_handle(sbp, hp);
774*0Sstevel@tonic-gate 		cpuid = sbdp_get_cpuid(hdp, dip);
775*0Sstevel@tonic-gate 		if (cpuid < 0) {
776*0Sstevel@tonic-gate 			if (hp->h_flags & SBD_IOCTL_FLAG_FORCE) {
777*0Sstevel@tonic-gate 				cmn_err(CE_WARN,
778*0Sstevel@tonic-gate 					"sbd:%s: failed to get cpuid for "
779*0Sstevel@tonic-gate 					"dip (0x%p)", f, (void *)dip);
780*0Sstevel@tonic-gate 				continue;
781*0Sstevel@tonic-gate 			} else {
782*0Sstevel@tonic-gate 				SBD_GET_PERR(hdp->h_err, ep);
783*0Sstevel@tonic-gate 				break;
784*0Sstevel@tonic-gate 			}
785*0Sstevel@tonic-gate 		}
786*0Sstevel@tonic-gate 		/*
787*0Sstevel@tonic-gate 		 * if there is no error mark the cpu as unusable
788*0Sstevel@tonic-gate 		 */
789*0Sstevel@tonic-gate 		if (SBD_GET_ERR(ep) == 0) {
790*0Sstevel@tonic-gate 			unit = sbdp_get_unit_num(hdp, dip);
791*0Sstevel@tonic-gate 			if (unit < 0) {
792*0Sstevel@tonic-gate 				if (hp->h_flags & SBD_IOCTL_FLAG_FORCE) {
793*0Sstevel@tonic-gate 					cmn_err(CE_WARN,
794*0Sstevel@tonic-gate 					    "sbd:%s: failed to get unit "
795*0Sstevel@tonic-gate 					    "(cpu %d)", f, cpuid);
796*0Sstevel@tonic-gate 					continue;
797*0Sstevel@tonic-gate 				} else {
798*0Sstevel@tonic-gate 					SBD_GET_PERR(hdp->h_err,
799*0Sstevel@tonic-gate 					    SBD_HD2ERR(hp));
800*0Sstevel@tonic-gate 					break;
801*0Sstevel@tonic-gate 				}
802*0Sstevel@tonic-gate 			}
803*0Sstevel@tonic-gate 			cpup = SBD_GET_BOARD_CPUUNIT(sbp, unit);
804*0Sstevel@tonic-gate 			cpup->sbc_cm.sbdev_cond = SBD_COND_UNUSABLE;
805*0Sstevel@tonic-gate 		}
806*0Sstevel@tonic-gate 		sbd_release_sbdp_handle(hdp);
807*0Sstevel@tonic-gate 	}
808*0Sstevel@tonic-gate 
809*0Sstevel@tonic-gate 	mutex_exit(&cpu_lock);
810*0Sstevel@tonic-gate 
811*0Sstevel@tonic-gate 
812*0Sstevel@tonic-gate 	return (0);
813*0Sstevel@tonic-gate }
814*0Sstevel@tonic-gate 
815*0Sstevel@tonic-gate /*
816*0Sstevel@tonic-gate  * Cancel previous release operation for cpu.  For cpus this means simply
817*0Sstevel@tonic-gate  * bringing cpus that were offline back online.  Note that they had to have been
818*0Sstevel@tonic-gate  * online at the time they were released.  If attempting to power on or online
819*0Sstevel@tonic-gate  * a CPU fails, SBD_CPUERR_FATAL is returned to indicate that the CPU appears to
820*0Sstevel@tonic-gate  * be unsalvageable.  If a CPU reaches an online or nointr state but can't be
821*0Sstevel@tonic-gate  * taken to a "lesser" state, SBD_CPUERR_RECOVERABLE is returned to indicate
822*0Sstevel@tonic-gate  * that it was not returned to its original state but appears to be functional.
823*0Sstevel@tonic-gate  * Note that the latter case can occur due to unexpected but non-erroneous CPU
824*0Sstevel@tonic-gate  * manipulation (e.g. by the "psradm" command) during the DR operation.
825*0Sstevel@tonic-gate  */
826*0Sstevel@tonic-gate int
sbd_cancel_cpu(sbd_handle_t * hp,int unit)827*0Sstevel@tonic-gate sbd_cancel_cpu(sbd_handle_t *hp, int unit)
828*0Sstevel@tonic-gate {
829*0Sstevel@tonic-gate 	int		rv = SBD_CPUERR_NONE;
830*0Sstevel@tonic-gate 	sbd_board_t	*sbp = SBDH2BD(hp->h_sbd);
831*0Sstevel@tonic-gate 	sbderror_t	*ep = SBD_HD2ERR(hp);
832*0Sstevel@tonic-gate 	sbd_cpu_unit_t	*cp;
833*0Sstevel@tonic-gate 	static fn_t	f = "sbd_cancel_cpu";
834*0Sstevel@tonic-gate 	struct cpu	*cpup;
835*0Sstevel@tonic-gate 	int		cpu_offline_flags = 0;
836*0Sstevel@tonic-gate 
837*0Sstevel@tonic-gate 	PR_ALL("%s...\n", f);
838*0Sstevel@tonic-gate 
839*0Sstevel@tonic-gate 	cp = SBD_GET_BOARD_CPUUNIT(sbp, unit);
840*0Sstevel@tonic-gate 
841*0Sstevel@tonic-gate 	/*
842*0Sstevel@tonic-gate 	 * If CPU should remain off, nothing needs to be done.
843*0Sstevel@tonic-gate 	 */
844*0Sstevel@tonic-gate 	if (cpu_flagged_poweredoff(cp->sbc_cpu_flags))
845*0Sstevel@tonic-gate 		return (rv);
846*0Sstevel@tonic-gate 
847*0Sstevel@tonic-gate 	if (hp->h_flags & SBD_IOCTL_FLAG_FORCE)
848*0Sstevel@tonic-gate 		cpu_offline_flags = CPU_FORCED;
849*0Sstevel@tonic-gate 
850*0Sstevel@tonic-gate 	/*
851*0Sstevel@tonic-gate 	 * CPU had been either offline, online, or set to no-intr.  We
852*0Sstevel@tonic-gate 	 * will return a component to its original state that it was
853*0Sstevel@tonic-gate 	 * prior to the failed DR operation.  There is a possible race
854*0Sstevel@tonic-gate 	 * condition between the calls to this function and re-obtaining
855*0Sstevel@tonic-gate 	 * the cpu_lock where a cpu state could change.  Because of this
856*0Sstevel@tonic-gate 	 * we can't externally document that we are trying to roll cpus
857*0Sstevel@tonic-gate 	 * back to their original state, but we believe a best effort
858*0Sstevel@tonic-gate 	 * should be made.
859*0Sstevel@tonic-gate 	 */
860*0Sstevel@tonic-gate 
861*0Sstevel@tonic-gate 	mutex_enter(&cpu_lock);
862*0Sstevel@tonic-gate 	cpup = cpu[cp->sbc_cpu_id];
863*0Sstevel@tonic-gate 
864*0Sstevel@tonic-gate 	/*
865*0Sstevel@tonic-gate 	 * The following will compare the cpu's current state with a
866*0Sstevel@tonic-gate 	 * snapshot of its state taken before the failed DR operation
867*0Sstevel@tonic-gate 	 * had started.
868*0Sstevel@tonic-gate 	 */
869*0Sstevel@tonic-gate 	/* POWEROFF */
870*0Sstevel@tonic-gate 	if (cpu_is_poweredoff(cpup)) {
871*0Sstevel@tonic-gate 		if (cpu_poweron(cpup)) {
872*0Sstevel@tonic-gate 			cmn_err(CE_WARN,
873*0Sstevel@tonic-gate 			    "sbd:%s: failed to power-on cpu %d",
874*0Sstevel@tonic-gate 			    f, cp->sbc_cpu_id);
875*0Sstevel@tonic-gate 			SBD_SET_ERR(ep, ESBD_CPUSTART);
876*0Sstevel@tonic-gate 			SBD_SET_ERRSTR(ep, sbp->sb_cpupath[unit]);
877*0Sstevel@tonic-gate 			rv = SBD_CPUERR_FATAL;
878*0Sstevel@tonic-gate 			goto out;
879*0Sstevel@tonic-gate 		}
880*0Sstevel@tonic-gate 		SBD_INJECT_ERR(SBD_POWERON_CPU_PSEUDO_ERR,
881*0Sstevel@tonic-gate 		    hp->h_err, EIO,
882*0Sstevel@tonic-gate 		    ESBD_CPUSTART,
883*0Sstevel@tonic-gate 		    sbp->sb_cpupath[unit]);
884*0Sstevel@tonic-gate 	}
885*0Sstevel@tonic-gate 
886*0Sstevel@tonic-gate 	/* OFFLINE */
887*0Sstevel@tonic-gate 	if (cpu_is_offline(cpup)) {
888*0Sstevel@tonic-gate 		if (cpu_flagged_offline(cp->sbc_cpu_flags)) {
889*0Sstevel@tonic-gate 			PR_CPU("%s: leaving cpu %d OFFLINE\n",
890*0Sstevel@tonic-gate 			    f, cp->sbc_cpu_id);
891*0Sstevel@tonic-gate 		} else if (cpu_online(cpup)) {
892*0Sstevel@tonic-gate 			cmn_err(CE_WARN,
893*0Sstevel@tonic-gate 			    "sbd:%s: failed to online cpu %d",
894*0Sstevel@tonic-gate 			    f, cp->sbc_cpu_id);
895*0Sstevel@tonic-gate 			SBD_SET_ERR(ep, ESBD_ONLINE);
896*0Sstevel@tonic-gate 			SBD_SET_ERRSTR(ep, sbp->sb_cpupath[unit]);
897*0Sstevel@tonic-gate 			rv = SBD_CPUERR_FATAL;
898*0Sstevel@tonic-gate 			goto out;
899*0Sstevel@tonic-gate 		} else {
900*0Sstevel@tonic-gate 			SBD_INJECT_ERR(SBD_ONLINE_CPU_PSEUDO_ERR,
901*0Sstevel@tonic-gate 			    hp->h_err, EIO,
902*0Sstevel@tonic-gate 			    ESBD_ONLINE,
903*0Sstevel@tonic-gate 			    sbp->sb_cpupath[unit]);
904*0Sstevel@tonic-gate 		}
905*0Sstevel@tonic-gate 	}
906*0Sstevel@tonic-gate 
907*0Sstevel@tonic-gate 	/* ONLINE */
908*0Sstevel@tonic-gate 	if (cpu_is_online(cpup)) {
909*0Sstevel@tonic-gate 		if (cpu_flagged_online(cp->sbc_cpu_flags)) {
910*0Sstevel@tonic-gate 			PR_CPU("%s: setting cpu %d ONLINE\n",
911*0Sstevel@tonic-gate 			    f, cp->sbc_cpu_id);
912*0Sstevel@tonic-gate 		} else if (cpu_flagged_offline(cp->sbc_cpu_flags)) {
913*0Sstevel@tonic-gate 			if (cpu_offline(cpup, cpu_offline_flags)) {
914*0Sstevel@tonic-gate 				cmn_err(CE_WARN,
915*0Sstevel@tonic-gate 				    "sbd:%s: failed to offline"
916*0Sstevel@tonic-gate 				    " cpu %d", f, cp->sbc_cpu_id);
917*0Sstevel@tonic-gate 				rv = SBD_CPUERR_RECOVERABLE;
918*0Sstevel@tonic-gate 				goto out;
919*0Sstevel@tonic-gate 			}
920*0Sstevel@tonic-gate 		} else if (cpu_flagged_nointr(cp->sbc_cpu_flags)) {
921*0Sstevel@tonic-gate 			if (cpu_intr_disable(cpup)) {
922*0Sstevel@tonic-gate 				cmn_err(CE_WARN, "%s: failed to "
923*0Sstevel@tonic-gate 				    "disable interrupts on cpu %d",
924*0Sstevel@tonic-gate 				    f, cp->sbc_cpu_id);
925*0Sstevel@tonic-gate 				rv = SBD_CPUERR_RECOVERABLE;
926*0Sstevel@tonic-gate 			} else {
927*0Sstevel@tonic-gate 				PR_CPU("%s: setting cpu %d to NOINTR"
928*0Sstevel@tonic-gate 				    " (was online)\n",
929*0Sstevel@tonic-gate 				    f, cp->sbc_cpu_id);
930*0Sstevel@tonic-gate 			}
931*0Sstevel@tonic-gate 			goto out;
932*0Sstevel@tonic-gate 		}
933*0Sstevel@tonic-gate 	}
934*0Sstevel@tonic-gate 
935*0Sstevel@tonic-gate 	/* NOINTR */
936*0Sstevel@tonic-gate 	if (cpu_is_nointr(cpup)) {
937*0Sstevel@tonic-gate 		if (cpu_flagged_online(cp->sbc_cpu_flags)) {
938*0Sstevel@tonic-gate 			cpu_intr_enable(cpup);
939*0Sstevel@tonic-gate 			PR_CPU("%s: setting cpu %d ONLINE"
940*0Sstevel@tonic-gate 			    "(was nointr)\n",
941*0Sstevel@tonic-gate 			    f, cp->sbc_cpu_id);
942*0Sstevel@tonic-gate 		}
943*0Sstevel@tonic-gate 		if (cpu_flagged_offline(cp->sbc_cpu_flags)) {
944*0Sstevel@tonic-gate 			if (cpu_offline(cpup, cpu_offline_flags)) {
945*0Sstevel@tonic-gate 				cmn_err(CE_WARN,
946*0Sstevel@tonic-gate 				    "sbd:%s: failed to offline"
947*0Sstevel@tonic-gate 				    " cpu %d", f, cp->sbc_cpu_id);
948*0Sstevel@tonic-gate 				rv = SBD_CPUERR_RECOVERABLE;
949*0Sstevel@tonic-gate 			}
950*0Sstevel@tonic-gate 		}
951*0Sstevel@tonic-gate 	}
952*0Sstevel@tonic-gate out:
953*0Sstevel@tonic-gate 	mutex_exit(&cpu_lock);
954*0Sstevel@tonic-gate 
955*0Sstevel@tonic-gate 	return (rv);
956*0Sstevel@tonic-gate }
957*0Sstevel@tonic-gate 
958*0Sstevel@tonic-gate int
sbd_connect_cpu(sbd_board_t * sbp,int unit)959*0Sstevel@tonic-gate sbd_connect_cpu(sbd_board_t *sbp, int unit)
960*0Sstevel@tonic-gate {
961*0Sstevel@tonic-gate 	int		rv;
962*0Sstevel@tonic-gate 	processorid_t	cpuid;
963*0Sstevel@tonic-gate 	struct cpu	*cpu;
964*0Sstevel@tonic-gate 	dev_info_t	*dip;
965*0Sstevel@tonic-gate 	sbdp_handle_t	*hdp;
966*0Sstevel@tonic-gate 	extern kmutex_t	cpu_lock;
967*0Sstevel@tonic-gate 	static fn_t	f = "sbd_connect_cpu";
968*0Sstevel@tonic-gate 	sbd_handle_t	*hp = MACHBD2HD(sbp);
969*0Sstevel@tonic-gate 
970*0Sstevel@tonic-gate 	/*
971*0Sstevel@tonic-gate 	 * get dip for cpu just located in tree walk
972*0Sstevel@tonic-gate 	 */
973*0Sstevel@tonic-gate 	if (SBD_DEV_IS_PRESENT(sbp, SBD_COMP_CPU, unit)) {
974*0Sstevel@tonic-gate 		dip = sbp->sb_devlist[NIX(SBD_COMP_CPU)][unit];
975*0Sstevel@tonic-gate 		if (dip == NULL) {
976*0Sstevel@tonic-gate 			cmn_err(CE_WARN,
977*0Sstevel@tonic-gate 			"sbd:%s: bad dip for cpu unit %d board %d",
978*0Sstevel@tonic-gate 			f, unit, sbp->sb_num);
979*0Sstevel@tonic-gate 			return (-1);
980*0Sstevel@tonic-gate 		}
981*0Sstevel@tonic-gate 		PR_CPU("%s...\n", f);
982*0Sstevel@tonic-gate 	} else {
983*0Sstevel@tonic-gate 		return (0);
984*0Sstevel@tonic-gate 	}
985*0Sstevel@tonic-gate 
986*0Sstevel@tonic-gate 	/*
987*0Sstevel@tonic-gate 	 * if sbd has attached this cpu, no need to bring
988*0Sstevel@tonic-gate 	 * it out of reset
989*0Sstevel@tonic-gate 	 */
990*0Sstevel@tonic-gate 	if (SBD_DEV_IS_ATTACHED(sbp, SBD_COMP_CPU, unit)) {
991*0Sstevel@tonic-gate 		return (0);
992*0Sstevel@tonic-gate 	}
993*0Sstevel@tonic-gate 
994*0Sstevel@tonic-gate 	hdp = sbd_get_sbdp_handle(sbp, hp);
995*0Sstevel@tonic-gate 
996*0Sstevel@tonic-gate 	cpuid = sbdp_get_cpuid(hdp, dip);
997*0Sstevel@tonic-gate 	if (cpuid == -1) {
998*0Sstevel@tonic-gate 		sbd_release_sbdp_handle(hdp);
999*0Sstevel@tonic-gate 		return (-1);
1000*0Sstevel@tonic-gate 	}
1001*0Sstevel@tonic-gate 
1002*0Sstevel@tonic-gate 	/*
1003*0Sstevel@tonic-gate 	 * if the cpu is already under Solaris control,
1004*0Sstevel@tonic-gate 	 * do not wake it up
1005*0Sstevel@tonic-gate 	 */
1006*0Sstevel@tonic-gate 	mutex_enter(&cpu_lock);
1007*0Sstevel@tonic-gate 	cpu = cpu_get(cpuid);
1008*0Sstevel@tonic-gate 	mutex_exit(&cpu_lock);
1009*0Sstevel@tonic-gate 	if (cpu != NULL) {
1010*0Sstevel@tonic-gate 		sbd_release_sbdp_handle(hdp);
1011*0Sstevel@tonic-gate 		return (0);
1012*0Sstevel@tonic-gate 	}
1013*0Sstevel@tonic-gate 
1014*0Sstevel@tonic-gate 	rv = sbdp_connect_cpu(hdp, dip, cpuid);
1015*0Sstevel@tonic-gate 
1016*0Sstevel@tonic-gate 	if (rv != 0) {
1017*0Sstevel@tonic-gate 		sbp->sb_memaccess_ok = 0;
1018*0Sstevel@tonic-gate 		cmn_err(CE_WARN,
1019*0Sstevel@tonic-gate 			"sbd:%s: failed to wake up cpu unit %d board %d",
1020*0Sstevel@tonic-gate 			f, unit, sbp->sb_num);
1021*0Sstevel@tonic-gate 		sbd_release_sbdp_handle(hdp);
1022*0Sstevel@tonic-gate 		return (rv);
1023*0Sstevel@tonic-gate 	}
1024*0Sstevel@tonic-gate 	sbd_release_sbdp_handle(hdp);
1025*0Sstevel@tonic-gate 
1026*0Sstevel@tonic-gate 	return (rv);
1027*0Sstevel@tonic-gate }
1028*0Sstevel@tonic-gate 
1029*0Sstevel@tonic-gate int
sbd_disconnect_cpu(sbd_handle_t * hp,int unit)1030*0Sstevel@tonic-gate sbd_disconnect_cpu(sbd_handle_t *hp, int unit)
1031*0Sstevel@tonic-gate {
1032*0Sstevel@tonic-gate 	sbd_board_t	*sbp = SBDH2BD(hp->h_sbd);
1033*0Sstevel@tonic-gate 	int		rv;
1034*0Sstevel@tonic-gate 	dev_info_t	*dip;
1035*0Sstevel@tonic-gate 	sbdp_handle_t	*hdp;
1036*0Sstevel@tonic-gate 	sbd_cpu_unit_t *cp;
1037*0Sstevel@tonic-gate 	processorid_t   cpuid;
1038*0Sstevel@tonic-gate 	static fn_t	f = "sbd_disconnect_cpu";
1039*0Sstevel@tonic-gate 
1040*0Sstevel@tonic-gate 	PR_CPU("%s...\n", f);
1041*0Sstevel@tonic-gate 
1042*0Sstevel@tonic-gate 	ASSERT((SBD_DEVICE_STATE(sbp, SBD_COMP_CPU, unit) ==
1043*0Sstevel@tonic-gate 						SBD_STATE_CONNECTED) ||
1044*0Sstevel@tonic-gate 		(SBD_DEVICE_STATE(sbp, SBD_COMP_CPU, unit) ==
1045*0Sstevel@tonic-gate 						SBD_STATE_UNCONFIGURED));
1046*0Sstevel@tonic-gate 
1047*0Sstevel@tonic-gate 	cp = SBD_GET_BOARD_CPUUNIT(sbp, unit);
1048*0Sstevel@tonic-gate 
1049*0Sstevel@tonic-gate 	cpuid = cp->sbc_cpu_id;
1050*0Sstevel@tonic-gate 
1051*0Sstevel@tonic-gate 	dip = sbp->sb_devlist[NIX(SBD_COMP_CPU)][unit];
1052*0Sstevel@tonic-gate 
1053*0Sstevel@tonic-gate 	hdp = sbd_get_sbdp_handle(sbp, hp);
1054*0Sstevel@tonic-gate 
1055*0Sstevel@tonic-gate 	rv = sbdp_disconnect_cpu(hdp, dip, cpuid);
1056*0Sstevel@tonic-gate 
1057*0Sstevel@tonic-gate 	if (rv != 0) {
1058*0Sstevel@tonic-gate 		SBD_GET_PERR(hdp->h_err, SBD_HD2ERR(hp));
1059*0Sstevel@tonic-gate 	}
1060*0Sstevel@tonic-gate 	sbd_release_sbdp_handle(hdp);
1061*0Sstevel@tonic-gate 
1062*0Sstevel@tonic-gate 	return (rv);
1063*0Sstevel@tonic-gate }
1064