xref: /onnv-gate/usr/src/uts/sun4u/os/cmp.c (revision 1228:9e051e1a3f68)
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
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23*1228Sandrei  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <sys/machsystm.h>
310Sstevel@tonic-gate #include <sys/x_call.h>
320Sstevel@tonic-gate #include <sys/cmp.h>
330Sstevel@tonic-gate #include <sys/debug.h>
340Sstevel@tonic-gate #include <sys/chip.h>
350Sstevel@tonic-gate #include <sys/cheetahregs.h>
360Sstevel@tonic-gate 
370Sstevel@tonic-gate /*
380Sstevel@tonic-gate  * Note: We assume that chipid == portid.  This is not necessarily true.
390Sstevel@tonic-gate  * We buried it down here in the implementation, and not in the
400Sstevel@tonic-gate  * interfaces, so that we can change it later.
410Sstevel@tonic-gate  */
420Sstevel@tonic-gate 
430Sstevel@tonic-gate /*
440Sstevel@tonic-gate  * pre-alloc'ed because this is used early in boot (before the memory
450Sstevel@tonic-gate  * allocator is available).
460Sstevel@tonic-gate  */
470Sstevel@tonic-gate static cpuset_t chips[MAX_CPU_CHIPID];
480Sstevel@tonic-gate 
490Sstevel@tonic-gate /*
500Sstevel@tonic-gate  * Returns 1 if cpuid is CMP-capable, 0 otherwise.
510Sstevel@tonic-gate  */
520Sstevel@tonic-gate int
530Sstevel@tonic-gate cmp_cpu_is_cmp(processorid_t cpuid)
540Sstevel@tonic-gate {
550Sstevel@tonic-gate 	chipid_t chipid;
560Sstevel@tonic-gate 
570Sstevel@tonic-gate 	/* N.B. We're assuming that the cpunode[].portid is still intact */
580Sstevel@tonic-gate 	chipid = cpunodes[cpuid].portid;
590Sstevel@tonic-gate 	return (!CPUSET_ISNULL(chips[chipid]));
600Sstevel@tonic-gate }
610Sstevel@tonic-gate 
620Sstevel@tonic-gate /*
630Sstevel@tonic-gate  * Indicate that this core (cpuid) resides on the chip indicated by chipid.
640Sstevel@tonic-gate  * Called during boot and DR add.
650Sstevel@tonic-gate  */
660Sstevel@tonic-gate void
670Sstevel@tonic-gate cmp_add_cpu(chipid_t chipid, processorid_t cpuid)
680Sstevel@tonic-gate {
690Sstevel@tonic-gate 	CPUSET_ADD(chips[chipid], cpuid);
700Sstevel@tonic-gate }
710Sstevel@tonic-gate 
720Sstevel@tonic-gate /*
730Sstevel@tonic-gate  * Indicate that this core (cpuid) is being DR removed.
740Sstevel@tonic-gate  */
750Sstevel@tonic-gate void
760Sstevel@tonic-gate cmp_delete_cpu(processorid_t cpuid)
770Sstevel@tonic-gate {
780Sstevel@tonic-gate 	chipid_t chipid;
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 	/* N.B. We're assuming that the cpunode[].portid is still intact */
810Sstevel@tonic-gate 	chipid = cpunodes[cpuid].portid;
820Sstevel@tonic-gate 	CPUSET_DEL(chips[chipid], cpuid);
830Sstevel@tonic-gate }
840Sstevel@tonic-gate 
850Sstevel@tonic-gate /*
860Sstevel@tonic-gate  * Called when cpuid is being onlined or offlined.  If the offlined
870Sstevel@tonic-gate  * processor is CMP-capable then current target of the CMP Error Steering
880Sstevel@tonic-gate  * Register is set to either the lowest numbered on-line sibling core, if
890Sstevel@tonic-gate  * one exists, or else to this core.
900Sstevel@tonic-gate  */
910Sstevel@tonic-gate void
920Sstevel@tonic-gate cmp_error_resteer(processorid_t cpuid)
930Sstevel@tonic-gate {
940Sstevel@tonic-gate 	cpuset_t mycores;
950Sstevel@tonic-gate 	cpu_t *cpu;
960Sstevel@tonic-gate 	chipid_t chipid;
970Sstevel@tonic-gate 	int i;
980Sstevel@tonic-gate 
990Sstevel@tonic-gate 	if (!cmp_cpu_is_cmp(cpuid))
1000Sstevel@tonic-gate 	    return;
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
1030Sstevel@tonic-gate 	chipid = cpunodes[cpuid].portid;
1040Sstevel@tonic-gate 	mycores = chips[chipid];
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate 	/* Look for an online sibling core */
1070Sstevel@tonic-gate 	for (i = 0; i < NCPU; i++) {
1080Sstevel@tonic-gate 		if (i == cpuid)
1090Sstevel@tonic-gate 			continue;
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 		if (CPU_IN_SET(mycores, i) &&
1120Sstevel@tonic-gate 		    (cpu = cpu_get(i)) != NULL && cpu_is_active(cpu)) {
1130Sstevel@tonic-gate 			/* Found one, reset error steering  */
1140Sstevel@tonic-gate 			xc_one(i, (xcfunc_t *)set_cmp_error_steering, 0, 0);
1150Sstevel@tonic-gate 			break;
1160Sstevel@tonic-gate 		}
1170Sstevel@tonic-gate 	}
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate 	/* No online sibling cores, point to this core.  */
1200Sstevel@tonic-gate 	if (i == NCPU) {
1210Sstevel@tonic-gate 		xc_one(cpuid, (xcfunc_t *)set_cmp_error_steering, 0, 0);
1220Sstevel@tonic-gate 	}
1230Sstevel@tonic-gate }
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate chipid_t
1260Sstevel@tonic-gate cmp_cpu_to_chip(processorid_t cpuid)
1270Sstevel@tonic-gate {
1280Sstevel@tonic-gate 	if (!cmp_cpu_is_cmp(cpuid)) {
1290Sstevel@tonic-gate 		/* This CPU is not a CMP, so by definition chipid==cpuid */
1300Sstevel@tonic-gate 		ASSERT(cpuid < MAX_CPU_CHIPID && CPUSET_ISNULL(chips[cpuid]));
1310Sstevel@tonic-gate 		return (cpuid);
1320Sstevel@tonic-gate 	}
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate 	/* N.B. We're assuming that the cpunode[].portid is still intact */
1350Sstevel@tonic-gate 	return (cpunodes[cpuid].portid);
1360Sstevel@tonic-gate }
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate /*
1390Sstevel@tonic-gate  * Return a chip "id" for the given cpu_t
1400Sstevel@tonic-gate  * cpu_t's residing on the same physical processor
1410Sstevel@tonic-gate  * should map to the same "id"
1420Sstevel@tonic-gate  */
1430Sstevel@tonic-gate chipid_t
1440Sstevel@tonic-gate chip_plat_get_chipid(cpu_t *cp)
1450Sstevel@tonic-gate {
1460Sstevel@tonic-gate 	return (cmp_cpu_to_chip(cp->cpu_id));
1470Sstevel@tonic-gate }
1480Sstevel@tonic-gate 
149*1228Sandrei /*
150*1228Sandrei  * We don't have any multi-threaded cores on sun4u yet.
151*1228Sandrei  */
152*1228Sandrei id_t
153*1228Sandrei chip_plat_get_coreid(cpu_t *cp)
154*1228Sandrei {
155*1228Sandrei 	return (cp->cpu_id);
156*1228Sandrei }
157*1228Sandrei 
1580Sstevel@tonic-gate void
1590Sstevel@tonic-gate chip_plat_define_chip(cpu_t *cp, chip_def_t *cd)
1600Sstevel@tonic-gate {
1610Sstevel@tonic-gate 	int	impl;
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate 	/*
1640Sstevel@tonic-gate 	 * Define the chip's type
1650Sstevel@tonic-gate 	 */
1660Sstevel@tonic-gate 	impl = cpunodes[cp->cpu_id].implementation;
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate 	if (IS_JAGUAR(impl)) {
1690Sstevel@tonic-gate 		cd->chipd_type = CHIP_CMP_SPLIT_CACHE;
1700Sstevel@tonic-gate 	} else if (IS_PANTHER(impl)) {
1710Sstevel@tonic-gate 		cd->chipd_type = CHIP_CMP_SHARED_CACHE;
1720Sstevel@tonic-gate 	} else {
1730Sstevel@tonic-gate 		cd->chipd_type = CHIP_DEFAULT;
1740Sstevel@tonic-gate 	}
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate 	/*
1770Sstevel@tonic-gate 	 * Define any needed adjustment of rechoose_interval
1780Sstevel@tonic-gate 	 * For now, all chips use the default. This
1790Sstevel@tonic-gate 	 * will change with future processors.
1800Sstevel@tonic-gate 	 */
1810Sstevel@tonic-gate 	cd->chipd_rechoose_adj = 0;
1820Sstevel@tonic-gate }
183