xref: /onnv-gate/usr/src/uts/sun4u/os/mach_mp_startup.c (revision 4050:9349e27b46cc)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*4050Sjb145095  * Common Development and Distribution License (the "License").
6*4050Sjb145095  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*4050Sjb145095  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <sys/machsystm.h>
290Sstevel@tonic-gate #include <sys/cpu_module.h>
300Sstevel@tonic-gate #include <sys/dtrace.h>
310Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h>
320Sstevel@tonic-gate 
330Sstevel@tonic-gate /*
340Sstevel@tonic-gate  * Useful for disabling MP bring-up for an MP capable kernel
350Sstevel@tonic-gate  * (a kernel that was built with MP defined)
360Sstevel@tonic-gate  */
370Sstevel@tonic-gate int use_mp = 1;			/* set to come up mp */
380Sstevel@tonic-gate 
390Sstevel@tonic-gate /*
400Sstevel@tonic-gate  * Init CPU info - get CPU type info for processor_info system call.
410Sstevel@tonic-gate  */
420Sstevel@tonic-gate void
430Sstevel@tonic-gate init_cpu_info(struct cpu *cp)
440Sstevel@tonic-gate {
450Sstevel@tonic-gate 	processor_info_t *pi = &cp->cpu_type_info;
460Sstevel@tonic-gate 	int cpuid = cp->cpu_id;
470Sstevel@tonic-gate 	struct cpu_node *cpunode = &cpunodes[cpuid];
480Sstevel@tonic-gate 	char buf[CPU_IDSTRLEN];
490Sstevel@tonic-gate 
500Sstevel@tonic-gate 	cp->cpu_fpowner = NULL;		/* not used for V9 */
510Sstevel@tonic-gate 
520Sstevel@tonic-gate 	/*
530Sstevel@tonic-gate 	 * Get clock-frequency property from cpunodes[] for the CPU.
540Sstevel@tonic-gate 	 */
550Sstevel@tonic-gate 	pi->pi_clock = (cpunode->clock_freq + 500000) / 1000000;
560Sstevel@tonic-gate 
570Sstevel@tonic-gate 	(void) strcpy(pi->pi_processor_type, "sparcv9");
580Sstevel@tonic-gate 	(void) strcpy(pi->pi_fputypes, "sparcv9");
590Sstevel@tonic-gate 
600Sstevel@tonic-gate 	(void) snprintf(buf, sizeof (buf),
610Sstevel@tonic-gate 	    "%s (portid %d impl 0x%x ver 0x%x clock %d MHz)",
620Sstevel@tonic-gate 	    cpunode->name, cpunode->portid,
630Sstevel@tonic-gate 	    cpunode->implementation, cpunode->version, pi->pi_clock);
640Sstevel@tonic-gate 
650Sstevel@tonic-gate 	cp->cpu_idstr = kmem_alloc(strlen(buf) + 1, KM_SLEEP);
660Sstevel@tonic-gate 	(void) strcpy(cp->cpu_idstr, buf);
670Sstevel@tonic-gate 
680Sstevel@tonic-gate 	cmn_err(CE_CONT, "?cpu%d: %s\n", cpuid, cp->cpu_idstr);
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 	cp->cpu_brandstr = kmem_alloc(strlen(cpunode->name) + 1, KM_SLEEP);
710Sstevel@tonic-gate 	(void) strcpy(cp->cpu_brandstr, cpunode->name);
720Sstevel@tonic-gate 
730Sstevel@tonic-gate 	/*
740Sstevel@tonic-gate 	 * StarFire requires the signature block stuff setup here
750Sstevel@tonic-gate 	 */
760Sstevel@tonic-gate 	CPU_SGN_MAPIN(cpuid);
770Sstevel@tonic-gate 	if (cpuid == cpu0.cpu_id) {
780Sstevel@tonic-gate 		/*
790Sstevel@tonic-gate 		 * cpu0 starts out running.  Other cpus are
800Sstevel@tonic-gate 		 * still in OBP land and we will leave them
810Sstevel@tonic-gate 		 * alone for now.
820Sstevel@tonic-gate 		 */
830Sstevel@tonic-gate 		CPU_SIGNATURE(OS_SIG, SIGST_RUN, SIGSUBST_NULL, cpuid);
840Sstevel@tonic-gate #ifdef	lint
850Sstevel@tonic-gate 		cpuid = cpuid;
860Sstevel@tonic-gate #endif	/* lint */
870Sstevel@tonic-gate 	}
880Sstevel@tonic-gate }
890Sstevel@tonic-gate 
900Sstevel@tonic-gate /*
910Sstevel@tonic-gate  * Routine used to cleanup a CPU that has been powered off.  This will
920Sstevel@tonic-gate  * destroy all per-cpu information related to this cpu.
930Sstevel@tonic-gate  */
940Sstevel@tonic-gate int
950Sstevel@tonic-gate mp_cpu_unconfigure(int cpuid)
960Sstevel@tonic-gate {
970Sstevel@tonic-gate 	int retval;
980Sstevel@tonic-gate 	void empty_cpu(int);
990Sstevel@tonic-gate 	extern int cleanup_cpu_common(int);
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 	retval = cleanup_cpu_common(cpuid);
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate 	empty_cpu(cpuid);
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate 	return (retval);
1080Sstevel@tonic-gate }
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate struct mp_find_cpu_arg {
1110Sstevel@tonic-gate 	int cpuid;		/* set by mp_cpu_configure() */
1120Sstevel@tonic-gate 	dev_info_t *dip;	/* set by mp_find_cpu() */
1130Sstevel@tonic-gate };
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate int
1160Sstevel@tonic-gate mp_find_cpu(dev_info_t *dip, void *arg)
1170Sstevel@tonic-gate {
1180Sstevel@tonic-gate 	extern int get_portid_ddi(dev_info_t *, dev_info_t **);
1190Sstevel@tonic-gate 	struct mp_find_cpu_arg *target = (struct mp_find_cpu_arg *)arg;
1200Sstevel@tonic-gate 	char *type;
1210Sstevel@tonic-gate 	int rv = DDI_WALK_CONTINUE;
1220Sstevel@tonic-gate 	int cpuid;
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate 	if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
1250Sstevel@tonic-gate 	    "device_type", &type))
1260Sstevel@tonic-gate 		return (DDI_WALK_CONTINUE);
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate 	if (strcmp(type, "cpu") != 0)
1290Sstevel@tonic-gate 		goto out;
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate 	cpuid = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
1320Sstevel@tonic-gate 	    DDI_PROP_DONTPASS, "cpuid", -1);
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate 	if (cpuid == -1)
1350Sstevel@tonic-gate 		cpuid = get_portid_ddi(dip, NULL);
1360Sstevel@tonic-gate 	if (cpuid != target->cpuid)
1370Sstevel@tonic-gate 		goto out;
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate 	/* Found it */
1400Sstevel@tonic-gate 	rv = DDI_WALK_TERMINATE;
1410Sstevel@tonic-gate 	target->dip = dip;
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate out:
1440Sstevel@tonic-gate 	ddi_prop_free(type);
1450Sstevel@tonic-gate 	return (rv);
1460Sstevel@tonic-gate }
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate /*
1490Sstevel@tonic-gate  * Routine used to setup a newly inserted CPU in preparation for starting
1500Sstevel@tonic-gate  * it running code.
1510Sstevel@tonic-gate  */
1520Sstevel@tonic-gate int
1530Sstevel@tonic-gate mp_cpu_configure(int cpuid)
1540Sstevel@tonic-gate {
1550Sstevel@tonic-gate 	extern void fill_cpu_ddi(dev_info_t *);
156*4050Sjb145095 	extern int setup_cpu_common(int);
1570Sstevel@tonic-gate 	struct mp_find_cpu_arg target;
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate 	target.dip = NULL;
1620Sstevel@tonic-gate 	target.cpuid = cpuid;
1630Sstevel@tonic-gate 	ddi_walk_devs(ddi_root_node(), mp_find_cpu, &target);
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 	if (target.dip == NULL)
1660Sstevel@tonic-gate 		return (ENODEV);
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate 	/*
1690Sstevel@tonic-gate 	 * Note:  uses cpu_lock to protect cpunodes and ncpunodes
1700Sstevel@tonic-gate 	 * which will be modified inside of fill_cpu_ddi().
1710Sstevel@tonic-gate 	 */
1720Sstevel@tonic-gate 	fill_cpu_ddi(target.dip);
1730Sstevel@tonic-gate 
174*4050Sjb145095 	/*
175*4050Sjb145095 	 * sun4v cpu setup may fail. sun4u assumes cpu setup to
176*4050Sjb145095 	 * be always successful, so the return value is ignored.
177*4050Sjb145095 	 */
178*4050Sjb145095 	(void) setup_cpu_common(cpuid);
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate 	return (0);
1810Sstevel@tonic-gate }
182