xref: /onnv-gate/usr/src/uts/sun4u/os/cmp.c (revision 1772:78cca3d2cc4b)
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*1772Sjl139090  * Common Development and Distribution License (the "License").
6*1772Sjl139090  * 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 /*
221228Sandrei  * Copyright 2006 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/types.h>
290Sstevel@tonic-gate #include <sys/machsystm.h>
300Sstevel@tonic-gate #include <sys/x_call.h>
310Sstevel@tonic-gate #include <sys/cmp.h>
320Sstevel@tonic-gate #include <sys/debug.h>
330Sstevel@tonic-gate #include <sys/chip.h>
340Sstevel@tonic-gate #include <sys/cheetahregs.h>
350Sstevel@tonic-gate 
360Sstevel@tonic-gate /*
370Sstevel@tonic-gate  * Note: We assume that chipid == portid.  This is not necessarily true.
380Sstevel@tonic-gate  * We buried it down here in the implementation, and not in the
390Sstevel@tonic-gate  * interfaces, so that we can change it later.
400Sstevel@tonic-gate  */
410Sstevel@tonic-gate 
420Sstevel@tonic-gate /*
430Sstevel@tonic-gate  * pre-alloc'ed because this is used early in boot (before the memory
440Sstevel@tonic-gate  * allocator is available).
450Sstevel@tonic-gate  */
460Sstevel@tonic-gate static cpuset_t chips[MAX_CPU_CHIPID];
470Sstevel@tonic-gate 
480Sstevel@tonic-gate /*
490Sstevel@tonic-gate  * Returns 1 if cpuid is CMP-capable, 0 otherwise.
500Sstevel@tonic-gate  */
510Sstevel@tonic-gate int
520Sstevel@tonic-gate cmp_cpu_is_cmp(processorid_t cpuid)
530Sstevel@tonic-gate {
540Sstevel@tonic-gate 	chipid_t chipid;
550Sstevel@tonic-gate 
560Sstevel@tonic-gate 	/* N.B. We're assuming that the cpunode[].portid is still intact */
570Sstevel@tonic-gate 	chipid = cpunodes[cpuid].portid;
580Sstevel@tonic-gate 	return (!CPUSET_ISNULL(chips[chipid]));
590Sstevel@tonic-gate }
600Sstevel@tonic-gate 
610Sstevel@tonic-gate /*
620Sstevel@tonic-gate  * Indicate that this core (cpuid) resides on the chip indicated by chipid.
630Sstevel@tonic-gate  * Called during boot and DR add.
640Sstevel@tonic-gate  */
650Sstevel@tonic-gate void
660Sstevel@tonic-gate cmp_add_cpu(chipid_t chipid, processorid_t cpuid)
670Sstevel@tonic-gate {
680Sstevel@tonic-gate 	CPUSET_ADD(chips[chipid], cpuid);
690Sstevel@tonic-gate }
700Sstevel@tonic-gate 
710Sstevel@tonic-gate /*
720Sstevel@tonic-gate  * Indicate that this core (cpuid) is being DR removed.
730Sstevel@tonic-gate  */
740Sstevel@tonic-gate void
750Sstevel@tonic-gate cmp_delete_cpu(processorid_t cpuid)
760Sstevel@tonic-gate {
770Sstevel@tonic-gate 	chipid_t chipid;
780Sstevel@tonic-gate 
790Sstevel@tonic-gate 	/* N.B. We're assuming that the cpunode[].portid is still intact */
800Sstevel@tonic-gate 	chipid = cpunodes[cpuid].portid;
810Sstevel@tonic-gate 	CPUSET_DEL(chips[chipid], cpuid);
820Sstevel@tonic-gate }
830Sstevel@tonic-gate 
840Sstevel@tonic-gate /*
850Sstevel@tonic-gate  * Called when cpuid is being onlined or offlined.  If the offlined
860Sstevel@tonic-gate  * processor is CMP-capable then current target of the CMP Error Steering
870Sstevel@tonic-gate  * Register is set to either the lowest numbered on-line sibling core, if
880Sstevel@tonic-gate  * one exists, or else to this core.
890Sstevel@tonic-gate  */
90*1772Sjl139090 /* ARGSUSED */
910Sstevel@tonic-gate void
920Sstevel@tonic-gate cmp_error_resteer(processorid_t cpuid)
930Sstevel@tonic-gate {
94*1772Sjl139090 #ifndef	_CMP_NO_ERROR_STEERING
950Sstevel@tonic-gate 	cpuset_t mycores;
960Sstevel@tonic-gate 	cpu_t *cpu;
970Sstevel@tonic-gate 	chipid_t chipid;
980Sstevel@tonic-gate 	int i;
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate 	if (!cmp_cpu_is_cmp(cpuid))
1010Sstevel@tonic-gate 	    return;
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
1040Sstevel@tonic-gate 	chipid = cpunodes[cpuid].portid;
1050Sstevel@tonic-gate 	mycores = chips[chipid];
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate 	/* Look for an online sibling core */
1080Sstevel@tonic-gate 	for (i = 0; i < NCPU; i++) {
1090Sstevel@tonic-gate 		if (i == cpuid)
1100Sstevel@tonic-gate 			continue;
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate 		if (CPU_IN_SET(mycores, i) &&
1130Sstevel@tonic-gate 		    (cpu = cpu_get(i)) != NULL && cpu_is_active(cpu)) {
1140Sstevel@tonic-gate 			/* Found one, reset error steering  */
1150Sstevel@tonic-gate 			xc_one(i, (xcfunc_t *)set_cmp_error_steering, 0, 0);
1160Sstevel@tonic-gate 			break;
1170Sstevel@tonic-gate 		}
1180Sstevel@tonic-gate 	}
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 	/* No online sibling cores, point to this core.  */
1210Sstevel@tonic-gate 	if (i == NCPU) {
1220Sstevel@tonic-gate 		xc_one(cpuid, (xcfunc_t *)set_cmp_error_steering, 0, 0);
1230Sstevel@tonic-gate 	}
124*1772Sjl139090 #else
125*1772Sjl139090 	/* Not all CMP's support (e.g. Olympus-C by Fujitsu) error steering */
126*1772Sjl139090 	return;
127*1772Sjl139090 #endif /* _CMP_NO_ERROR_STEERING */
1280Sstevel@tonic-gate }
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate chipid_t
1310Sstevel@tonic-gate cmp_cpu_to_chip(processorid_t cpuid)
1320Sstevel@tonic-gate {
1330Sstevel@tonic-gate 	if (!cmp_cpu_is_cmp(cpuid)) {
1340Sstevel@tonic-gate 		/* This CPU is not a CMP, so by definition chipid==cpuid */
1350Sstevel@tonic-gate 		ASSERT(cpuid < MAX_CPU_CHIPID && CPUSET_ISNULL(chips[cpuid]));
1360Sstevel@tonic-gate 		return (cpuid);
1370Sstevel@tonic-gate 	}
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate 	/* N.B. We're assuming that the cpunode[].portid is still intact */
1400Sstevel@tonic-gate 	return (cpunodes[cpuid].portid);
1410Sstevel@tonic-gate }
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate /*
1440Sstevel@tonic-gate  * Return a chip "id" for the given cpu_t
1450Sstevel@tonic-gate  * cpu_t's residing on the same physical processor
1460Sstevel@tonic-gate  * should map to the same "id"
1470Sstevel@tonic-gate  */
1480Sstevel@tonic-gate chipid_t
1490Sstevel@tonic-gate chip_plat_get_chipid(cpu_t *cp)
1500Sstevel@tonic-gate {
1510Sstevel@tonic-gate 	return (cmp_cpu_to_chip(cp->cpu_id));
1520Sstevel@tonic-gate }
1530Sstevel@tonic-gate 
1541228Sandrei /*
155*1772Sjl139090  * Return the "core id" for the given cpu_t
156*1772Sjl139090  * The "core id" space spans uniquely across all
157*1772Sjl139090  * cpu chips.
1581228Sandrei  */
1591228Sandrei id_t
1601228Sandrei chip_plat_get_coreid(cpu_t *cp)
1611228Sandrei {
162*1772Sjl139090 	int impl;
163*1772Sjl139090 
164*1772Sjl139090 	impl = cpunodes[cp->cpu_id].implementation;
165*1772Sjl139090 
166*1772Sjl139090 	if (IS_OLYMPUS_C(impl)) {
167*1772Sjl139090 		/*
168*1772Sjl139090 		 * Currently only Fujitsu Olympus-c processor supports
169*1772Sjl139090 		 * multi-stranded cores. Return the cpu_id with
170*1772Sjl139090 		 * the strand bit masked out.
171*1772Sjl139090 		 */
172*1772Sjl139090 		return ((id_t)((uint_t)cp->cpu_id & ~(0x1)));
173*1772Sjl139090 	} else {
174*1772Sjl139090 		return (cp->cpu_id);
175*1772Sjl139090 	}
1761228Sandrei }
1771228Sandrei 
1780Sstevel@tonic-gate void
1790Sstevel@tonic-gate chip_plat_define_chip(cpu_t *cp, chip_def_t *cd)
1800Sstevel@tonic-gate {
1810Sstevel@tonic-gate 	int	impl;
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate 	/*
1840Sstevel@tonic-gate 	 * Define the chip's type
1850Sstevel@tonic-gate 	 */
1860Sstevel@tonic-gate 	impl = cpunodes[cp->cpu_id].implementation;
1870Sstevel@tonic-gate 
1880Sstevel@tonic-gate 	if (IS_JAGUAR(impl)) {
1890Sstevel@tonic-gate 		cd->chipd_type = CHIP_CMP_SPLIT_CACHE;
190*1772Sjl139090 	} else if (IS_PANTHER(impl) || IS_OLYMPUS_C(impl)) {
1910Sstevel@tonic-gate 		cd->chipd_type = CHIP_CMP_SHARED_CACHE;
1920Sstevel@tonic-gate 	} else {
1930Sstevel@tonic-gate 		cd->chipd_type = CHIP_DEFAULT;
1940Sstevel@tonic-gate 	}
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate 	/*
1970Sstevel@tonic-gate 	 * Define any needed adjustment of rechoose_interval
1980Sstevel@tonic-gate 	 * For now, all chips use the default. This
1990Sstevel@tonic-gate 	 * will change with future processors.
2000Sstevel@tonic-gate 	 */
2010Sstevel@tonic-gate 	cd->chipd_rechoose_adj = 0;
2020Sstevel@tonic-gate }
203