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 /* 22*fb2f18f8Sesaxe * Copyright 2007 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> 32*fb2f18f8Sesaxe #include <sys/pghw.h> 337c478bd9Sstevel@tonic-gate #include <sys/debug.h> 34685679f7Sakolb #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 144*fb2f18f8Sesaxe /* ARGSUSED */ 145*fb2f18f8Sesaxe int 146*fb2f18f8Sesaxe pg_plat_hw_shared(cpu_t *cp, pghw_type_t hw) 1478949bcd6Sandrei { 14825cf1a30Sjl139090 int impl; 14925cf1a30Sjl139090 15025cf1a30Sjl139090 impl = cpunodes[cp->cpu_id].implementation; 15125cf1a30Sjl139090 152*fb2f18f8Sesaxe switch (hw) { 153*fb2f18f8Sesaxe case PGHW_IPIPE: 154*fb2f18f8Sesaxe if (IS_OLYMPUS_C(impl)) 155*fb2f18f8Sesaxe return (1); 156*fb2f18f8Sesaxe break; 157*fb2f18f8Sesaxe case PGHW_CHIP: 158*fb2f18f8Sesaxe if (IS_JAGUAR(impl) || IS_PANTHER(impl)) 159*fb2f18f8Sesaxe return (1); 160*fb2f18f8Sesaxe break; 161*fb2f18f8Sesaxe case PGHW_CACHE: 162*fb2f18f8Sesaxe if (IS_PANTHER(impl)) 163*fb2f18f8Sesaxe return (1); 164*fb2f18f8Sesaxe break; 165*fb2f18f8Sesaxe } 166*fb2f18f8Sesaxe return (0); 167*fb2f18f8Sesaxe } 168*fb2f18f8Sesaxe 169*fb2f18f8Sesaxe int 170*fb2f18f8Sesaxe pg_plat_cpus_share(cpu_t *cpu_a, cpu_t *cpu_b, pghw_type_t hw) 171*fb2f18f8Sesaxe { 172*fb2f18f8Sesaxe int impla, implb; 173*fb2f18f8Sesaxe 174*fb2f18f8Sesaxe impla = cpunodes[cpu_a->cpu_id].implementation; 175*fb2f18f8Sesaxe implb = cpunodes[cpu_b->cpu_id].implementation; 176*fb2f18f8Sesaxe 177*fb2f18f8Sesaxe switch (hw) { 178*fb2f18f8Sesaxe case PGHW_IPIPE: 179*fb2f18f8Sesaxe case PGHW_CHIP: 180*fb2f18f8Sesaxe return (pg_plat_hw_instance_id(cpu_a, hw) == 181*fb2f18f8Sesaxe pg_plat_hw_instance_id(cpu_b, hw)); 182*fb2f18f8Sesaxe case PGHW_CACHE: 183*fb2f18f8Sesaxe return (IS_PANTHER(impla) && IS_PANTHER(implb) && 184*fb2f18f8Sesaxe pg_plat_cpus_share(cpu_a, cpu_b, PGHW_CHIP)); 185*fb2f18f8Sesaxe } 186*fb2f18f8Sesaxe return (0); 187*fb2f18f8Sesaxe } 188*fb2f18f8Sesaxe 189*fb2f18f8Sesaxe id_t 190*fb2f18f8Sesaxe pg_plat_hw_instance_id(cpu_t *cpu, pghw_type_t hw) 191*fb2f18f8Sesaxe { 192*fb2f18f8Sesaxe int impl; 193*fb2f18f8Sesaxe 194*fb2f18f8Sesaxe switch (hw) { 195*fb2f18f8Sesaxe case PGHW_IPIPE: 196*fb2f18f8Sesaxe impl = cpunodes[cpu->cpu_id].implementation; 197*fb2f18f8Sesaxe 19825cf1a30Sjl139090 if (IS_OLYMPUS_C(impl)) { 19925cf1a30Sjl139090 /* 20025cf1a30Sjl139090 * Currently only Fujitsu Olympus-c processor supports 20125cf1a30Sjl139090 * multi-stranded cores. Return the cpu_id with 20225cf1a30Sjl139090 * the strand bit masked out. 20325cf1a30Sjl139090 */ 204*fb2f18f8Sesaxe return ((id_t)((uint_t)cpu->cpu_id & ~(0x1))); 20525cf1a30Sjl139090 } else { 206*fb2f18f8Sesaxe return (cpu->cpu_id); 2078949bcd6Sandrei } 208*fb2f18f8Sesaxe case PGHW_CHIP: 209*fb2f18f8Sesaxe return (cmp_cpu_to_chip(cpu->cpu_id)); 210*fb2f18f8Sesaxe case PGHW_CACHE: 211*fb2f18f8Sesaxe return (IS_PANTHER(impl) && 212*fb2f18f8Sesaxe pg_plat_hw_instance_id(cpu, PGHW_CHIP)); 213*fb2f18f8Sesaxe default: 214*fb2f18f8Sesaxe return (-1); 215*fb2f18f8Sesaxe } 216*fb2f18f8Sesaxe } 217*fb2f18f8Sesaxe 218*fb2f18f8Sesaxe int 219*fb2f18f8Sesaxe pg_plat_hw_level(pghw_type_t hw) 220*fb2f18f8Sesaxe { 221*fb2f18f8Sesaxe int i; 222*fb2f18f8Sesaxe static pghw_type_t hw_hier[] = { 223*fb2f18f8Sesaxe PGHW_IPIPE, 224*fb2f18f8Sesaxe PGHW_CHIP, 225*fb2f18f8Sesaxe PGHW_CACHE, 226*fb2f18f8Sesaxe PGHW_NUM_COMPONENTS 227*fb2f18f8Sesaxe }; 228*fb2f18f8Sesaxe 229*fb2f18f8Sesaxe for (i = 0; hw_hier[i] != PGHW_NUM_COMPONENTS; i++) { 230*fb2f18f8Sesaxe if (hw_hier[i] == hw) 231*fb2f18f8Sesaxe return (i); 232*fb2f18f8Sesaxe } 233*fb2f18f8Sesaxe return (-1); 234*fb2f18f8Sesaxe } 235*fb2f18f8Sesaxe 236*fb2f18f8Sesaxe id_t 237*fb2f18f8Sesaxe pg_plat_get_core_id(cpu_t *cp) 238*fb2f18f8Sesaxe { 239*fb2f18f8Sesaxe return (pg_plat_hw_instance_id(cp, PGHW_IPIPE)); 24025cf1a30Sjl139090 } 2418949bcd6Sandrei 2427c478bd9Sstevel@tonic-gate void 243*fb2f18f8Sesaxe cmp_set_nosteal_interval(void) 2447c478bd9Sstevel@tonic-gate { 245*fb2f18f8Sesaxe /* Set the nosteal interval (used by disp_getbest()) to 100us */ 246*fb2f18f8Sesaxe nosteal_nsec = 100000UL; 2477c478bd9Sstevel@tonic-gate } 248