xref: /titanic_52/usr/src/uts/sun4u/os/cmp.c (revision 685679f7e4cc349aa1260fad8dbfaf07089c7b19)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
525cf1a30Sjl139090  * Common Development and Distribution License (the "License").
625cf1a30Sjl139090  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
228949bcd6Sandrei  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <sys/types.h>
297c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
307c478bd9Sstevel@tonic-gate #include <sys/x_call.h>
317c478bd9Sstevel@tonic-gate #include <sys/cmp.h>
327c478bd9Sstevel@tonic-gate #include <sys/debug.h>
337c478bd9Sstevel@tonic-gate #include <sys/chip.h>
34*685679f7Sakolb #include <sys/disp.h>
357c478bd9Sstevel@tonic-gate #include <sys/cheetahregs.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /*
387c478bd9Sstevel@tonic-gate  * Note: We assume that chipid == portid.  This is not necessarily true.
397c478bd9Sstevel@tonic-gate  * We buried it down here in the implementation, and not in the
407c478bd9Sstevel@tonic-gate  * interfaces, so that we can change it later.
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  * pre-alloc'ed because this is used early in boot (before the memory
457c478bd9Sstevel@tonic-gate  * allocator is available).
467c478bd9Sstevel@tonic-gate  */
477c478bd9Sstevel@tonic-gate static cpuset_t chips[MAX_CPU_CHIPID];
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate /*
507c478bd9Sstevel@tonic-gate  * Returns 1 if cpuid is CMP-capable, 0 otherwise.
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate int
537c478bd9Sstevel@tonic-gate cmp_cpu_is_cmp(processorid_t cpuid)
547c478bd9Sstevel@tonic-gate {
557c478bd9Sstevel@tonic-gate 	chipid_t chipid;
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate 	/* N.B. We're assuming that the cpunode[].portid is still intact */
587c478bd9Sstevel@tonic-gate 	chipid = cpunodes[cpuid].portid;
597c478bd9Sstevel@tonic-gate 	return (!CPUSET_ISNULL(chips[chipid]));
607c478bd9Sstevel@tonic-gate }
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate  * Indicate that this core (cpuid) resides on the chip indicated by chipid.
647c478bd9Sstevel@tonic-gate  * Called during boot and DR add.
657c478bd9Sstevel@tonic-gate  */
667c478bd9Sstevel@tonic-gate void
677c478bd9Sstevel@tonic-gate cmp_add_cpu(chipid_t chipid, processorid_t cpuid)
687c478bd9Sstevel@tonic-gate {
697c478bd9Sstevel@tonic-gate 	CPUSET_ADD(chips[chipid], cpuid);
707c478bd9Sstevel@tonic-gate }
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate  * Indicate that this core (cpuid) is being DR removed.
747c478bd9Sstevel@tonic-gate  */
757c478bd9Sstevel@tonic-gate void
767c478bd9Sstevel@tonic-gate cmp_delete_cpu(processorid_t cpuid)
777c478bd9Sstevel@tonic-gate {
787c478bd9Sstevel@tonic-gate 	chipid_t chipid;
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 	/* N.B. We're assuming that the cpunode[].portid is still intact */
817c478bd9Sstevel@tonic-gate 	chipid = cpunodes[cpuid].portid;
827c478bd9Sstevel@tonic-gate 	CPUSET_DEL(chips[chipid], cpuid);
837c478bd9Sstevel@tonic-gate }
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate /*
867c478bd9Sstevel@tonic-gate  * Called when cpuid is being onlined or offlined.  If the offlined
877c478bd9Sstevel@tonic-gate  * processor is CMP-capable then current target of the CMP Error Steering
887c478bd9Sstevel@tonic-gate  * Register is set to either the lowest numbered on-line sibling core, if
897c478bd9Sstevel@tonic-gate  * one exists, or else to this core.
907c478bd9Sstevel@tonic-gate  */
9125cf1a30Sjl139090 /* ARGSUSED */
927c478bd9Sstevel@tonic-gate void
937c478bd9Sstevel@tonic-gate cmp_error_resteer(processorid_t cpuid)
947c478bd9Sstevel@tonic-gate {
9525cf1a30Sjl139090 #ifndef	_CMP_NO_ERROR_STEERING
967c478bd9Sstevel@tonic-gate 	cpuset_t mycores;
977c478bd9Sstevel@tonic-gate 	cpu_t *cpu;
987c478bd9Sstevel@tonic-gate 	chipid_t chipid;
997c478bd9Sstevel@tonic-gate 	int i;
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	if (!cmp_cpu_is_cmp(cpuid))
1027c478bd9Sstevel@tonic-gate 	    return;
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
1057c478bd9Sstevel@tonic-gate 	chipid = cpunodes[cpuid].portid;
1067c478bd9Sstevel@tonic-gate 	mycores = chips[chipid];
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 	/* Look for an online sibling core */
1097c478bd9Sstevel@tonic-gate 	for (i = 0; i < NCPU; i++) {
1107c478bd9Sstevel@tonic-gate 		if (i == cpuid)
1117c478bd9Sstevel@tonic-gate 			continue;
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 		if (CPU_IN_SET(mycores, i) &&
1147c478bd9Sstevel@tonic-gate 		    (cpu = cpu_get(i)) != NULL && cpu_is_active(cpu)) {
1157c478bd9Sstevel@tonic-gate 			/* Found one, reset error steering  */
1167c478bd9Sstevel@tonic-gate 			xc_one(i, (xcfunc_t *)set_cmp_error_steering, 0, 0);
1177c478bd9Sstevel@tonic-gate 			break;
1187c478bd9Sstevel@tonic-gate 		}
1197c478bd9Sstevel@tonic-gate 	}
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 	/* No online sibling cores, point to this core.  */
1227c478bd9Sstevel@tonic-gate 	if (i == NCPU) {
1237c478bd9Sstevel@tonic-gate 		xc_one(cpuid, (xcfunc_t *)set_cmp_error_steering, 0, 0);
1247c478bd9Sstevel@tonic-gate 	}
12525cf1a30Sjl139090 #else
12625cf1a30Sjl139090 	/* Not all CMP's support (e.g. Olympus-C by Fujitsu) error steering */
12725cf1a30Sjl139090 	return;
12825cf1a30Sjl139090 #endif /* _CMP_NO_ERROR_STEERING */
1297c478bd9Sstevel@tonic-gate }
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate chipid_t
1327c478bd9Sstevel@tonic-gate cmp_cpu_to_chip(processorid_t cpuid)
1337c478bd9Sstevel@tonic-gate {
1347c478bd9Sstevel@tonic-gate 	if (!cmp_cpu_is_cmp(cpuid)) {
1357c478bd9Sstevel@tonic-gate 		/* This CPU is not a CMP, so by definition chipid==cpuid */
1367c478bd9Sstevel@tonic-gate 		ASSERT(cpuid < MAX_CPU_CHIPID && CPUSET_ISNULL(chips[cpuid]));
1377c478bd9Sstevel@tonic-gate 		return (cpuid);
1387c478bd9Sstevel@tonic-gate 	}
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate 	/* N.B. We're assuming that the cpunode[].portid is still intact */
1417c478bd9Sstevel@tonic-gate 	return (cpunodes[cpuid].portid);
1427c478bd9Sstevel@tonic-gate }
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate /*
1457c478bd9Sstevel@tonic-gate  * Return a chip "id" for the given cpu_t
1467c478bd9Sstevel@tonic-gate  * cpu_t's residing on the same physical processor
1477c478bd9Sstevel@tonic-gate  * should map to the same "id"
1487c478bd9Sstevel@tonic-gate  */
1497c478bd9Sstevel@tonic-gate chipid_t
1507c478bd9Sstevel@tonic-gate chip_plat_get_chipid(cpu_t *cp)
1517c478bd9Sstevel@tonic-gate {
1527c478bd9Sstevel@tonic-gate 	return (cmp_cpu_to_chip(cp->cpu_id));
1537c478bd9Sstevel@tonic-gate }
1547c478bd9Sstevel@tonic-gate 
1558949bcd6Sandrei /*
15625cf1a30Sjl139090  * Return the "core id" for the given cpu_t
15725cf1a30Sjl139090  * The "core id" space spans uniquely across all
15825cf1a30Sjl139090  * cpu chips.
1598949bcd6Sandrei  */
1608949bcd6Sandrei id_t
1618949bcd6Sandrei chip_plat_get_coreid(cpu_t *cp)
1628949bcd6Sandrei {
16325cf1a30Sjl139090 	int impl;
16425cf1a30Sjl139090 
16525cf1a30Sjl139090 	impl = cpunodes[cp->cpu_id].implementation;
16625cf1a30Sjl139090 
16725cf1a30Sjl139090 	if (IS_OLYMPUS_C(impl)) {
16825cf1a30Sjl139090 		/*
16925cf1a30Sjl139090 		 * Currently only Fujitsu Olympus-c processor supports
17025cf1a30Sjl139090 		 * multi-stranded cores. Return the cpu_id with
17125cf1a30Sjl139090 		 * the strand bit masked out.
17225cf1a30Sjl139090 		 */
17325cf1a30Sjl139090 		return ((id_t)((uint_t)cp->cpu_id & ~(0x1)));
17425cf1a30Sjl139090 	} else {
1758949bcd6Sandrei 		return (cp->cpu_id);
1768949bcd6Sandrei 	}
17725cf1a30Sjl139090 }
1788949bcd6Sandrei 
1797c478bd9Sstevel@tonic-gate void
1807c478bd9Sstevel@tonic-gate chip_plat_define_chip(cpu_t *cp, chip_def_t *cd)
1817c478bd9Sstevel@tonic-gate {
1827c478bd9Sstevel@tonic-gate 	int	impl;
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate 	/*
1857c478bd9Sstevel@tonic-gate 	 * Define the chip's type
1867c478bd9Sstevel@tonic-gate 	 */
1877c478bd9Sstevel@tonic-gate 	impl = cpunodes[cp->cpu_id].implementation;
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate 	if (IS_JAGUAR(impl)) {
1907c478bd9Sstevel@tonic-gate 		cd->chipd_type = CHIP_CMP_SPLIT_CACHE;
19125cf1a30Sjl139090 	} else if (IS_PANTHER(impl) || IS_OLYMPUS_C(impl)) {
1927c478bd9Sstevel@tonic-gate 		cd->chipd_type = CHIP_CMP_SHARED_CACHE;
1937c478bd9Sstevel@tonic-gate 	} else {
1947c478bd9Sstevel@tonic-gate 		cd->chipd_type = CHIP_DEFAULT;
1957c478bd9Sstevel@tonic-gate 	}
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 	/*
1987c478bd9Sstevel@tonic-gate 	 * Define any needed adjustment of rechoose_interval
1997c478bd9Sstevel@tonic-gate 	 * For now, all chips use the default. This
2007c478bd9Sstevel@tonic-gate 	 * will change with future processors.
2017c478bd9Sstevel@tonic-gate 	 */
2027c478bd9Sstevel@tonic-gate 	cd->chipd_rechoose_adj = 0;
203*685679f7Sakolb 	cd->chipd_nosteal = 100000ULL; /* 100 usecs */
2047c478bd9Sstevel@tonic-gate }
205