usr/src/uts/i86pc/os/mp_startup.c
author Mark Johnson <Mark.Johnson@Sun.COM>
Mon, 15 Sep 2008 15:09:45 -0700
changeset 7605 b4a19682e632
parent 7532 bb6372f778bb
child 7656 2621e50fdf4a
permissions -rw-r--r--
6747590 microcode update support for AMD Contributed by Hans Rosenfeld <[email protected]>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     1
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     2
 * CDDL HEADER START
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     3
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
1455
b43f098fa50c 6378953 allocation of interrupt threads could be more common
andrei
parents: 1414
diff changeset
     5
 * Common Development and Distribution License (the "License").
b43f098fa50c 6378953 allocation of interrupt threads could be more common
andrei
parents: 1414
diff changeset
     6
 * You may not use this file except in compliance with the License.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     7
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    11
 * and limitations under the License.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    12
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    18
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    19
 * CDDL HEADER END
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    20
 */
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
    21
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    22
/*
5893
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
    23
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    24
 * Use is subject to license terms.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    25
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    26
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    27
#include <sys/types.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    28
#include <sys/thread.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    29
#include <sys/cpuvar.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    30
#include <sys/t_lock.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    31
#include <sys/param.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    32
#include <sys/proc.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    33
#include <sys/disp.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    34
#include <sys/class.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    35
#include <sys/cmn_err.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    36
#include <sys/debug.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    37
#include <sys/asm_linkage.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    38
#include <sys/x_call.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    39
#include <sys/systm.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    40
#include <sys/var.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    41
#include <sys/vtrace.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    42
#include <vm/hat.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    43
#include <vm/as.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    44
#include <vm/seg_kmem.h>
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
    45
#include <vm/seg_kp.h>
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    46
#include <sys/segments.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    47
#include <sys/kmem.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    48
#include <sys/stack.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    49
#include <sys/smp_impldefs.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    50
#include <sys/x86_archext.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    51
#include <sys/machsystm.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    52
#include <sys/traptrace.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    53
#include <sys/clock.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    54
#include <sys/cpc_impl.h>
3434
5142e1d7d0bc 6461311 multi-level CMT scheduling optimizations
esaxe
parents: 3029
diff changeset
    55
#include <sys/pg.h>
5142e1d7d0bc 6461311 multi-level CMT scheduling optimizations
esaxe
parents: 3029
diff changeset
    56
#include <sys/cmt.h>
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    57
#include <sys/dtrace.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    58
#include <sys/archsystm.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    59
#include <sys/fp.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    60
#include <sys/reboot.h>
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
    61
#include <sys/kdi_machimpl.h>
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    62
#include <vm/hat_i86.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    63
#include <sys/memnode.h>
938
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
    64
#include <sys/pci_cfgspace.h>
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
    65
#include <sys/mach_mmu.h>
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
    66
#include <sys/sysmacros.h>
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
    67
#if defined(__xpv)
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
    68
#include <sys/hypervisor.h>
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
    69
#endif
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents: 1389
diff changeset
    70
#include <sys/cpu_module.h>
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    71
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    72
struct cpu	cpus[1];			/* CPU data */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    73
struct cpu	*cpu[NCPU] = {&cpus[0]};	/* pointers to all CPUs */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    74
cpu_core_t	cpu_core[NCPU];			/* cpu_core structures */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    75
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    76
/*
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
    77
 * Useful for disabling MP bring-up on a MP capable system.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    78
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    79
int use_mp = 1;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    80
2006
11a559c797d5 5081104 NCPU has been outgrown on x86
andrei
parents: 1642
diff changeset
    81
/*
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
    82
 * to be set by a PSM to indicate what cpus
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
    83
 * are sitting around on the system.
2006
11a559c797d5 5081104 NCPU has been outgrown on x86
andrei
parents: 1642
diff changeset
    84
 */
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
    85
cpuset_t mp_cpus;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    86
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    87
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    88
 * This variable is used by the hat layer to decide whether or not
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    89
 * critical sections are needed to prevent race conditions.  For sun4m,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    90
 * this variable is set once enough MP initialization has been done in
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    91
 * order to allow cross calls.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    92
 */
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
    93
int flushes_require_xcalls;
6336
4eaf084434c9 6470538 domUs are unfriendly when too little memory is available to boot
bholler
parents: 5894
diff changeset
    94
4eaf084434c9 6470538 domUs are unfriendly when too little memory is available to boot
bholler
parents: 5894
diff changeset
    95
cpuset_t cpu_ready_set;		/* initialized in startup() */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    96
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    97
static 	void	mp_startup(void);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    98
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    99
static void cpu_sep_enable(void);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   100
static void cpu_sep_disable(void);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   101
static void cpu_asysc_enable(void);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   102
static void cpu_asysc_disable(void);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   103
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   104
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   105
 * Init CPU info - get CPU type info for processor_info system call.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   106
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   107
void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   108
init_cpu_info(struct cpu *cp)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   109
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   110
	processor_info_t *pi = &cp->cpu_type_info;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   111
	char buf[CPU_IDSTRLEN];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   112
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   113
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   114
	 * Get clock-frequency property for the CPU.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   115
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   116
	pi->pi_clock = cpu_freq;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   117
4667
2cb417b1d90c PSARC/2004/826 Opteron Athlon64 Frequency Management
mh27603
parents: 4581
diff changeset
   118
	/*
2cb417b1d90c PSARC/2004/826 Opteron Athlon64 Frequency Management
mh27603
parents: 4581
diff changeset
   119
	 * Current frequency in Hz.
2cb417b1d90c PSARC/2004/826 Opteron Athlon64 Frequency Management
mh27603
parents: 4581
diff changeset
   120
	 */
4718
4e06f379632e 6584239 CPU power management additions to processor_info_t potentially break processor_info() consumers.
mh27603
parents: 4667
diff changeset
   121
	cp->cpu_curr_clock = cpu_freq_hz;
4667
2cb417b1d90c PSARC/2004/826 Opteron Athlon64 Frequency Management
mh27603
parents: 4581
diff changeset
   122
4877
5744980c78cf 6587576 cpu_info kstat is returning garbage in supported_frequencies_Hz
mh27603
parents: 4718
diff changeset
   123
	/*
5744980c78cf 6587576 cpu_info kstat is returning garbage in supported_frequencies_Hz
mh27603
parents: 4718
diff changeset
   124
	 * Supported frequencies.
5744980c78cf 6587576 cpu_info kstat is returning garbage in supported_frequencies_Hz
mh27603
parents: 4718
diff changeset
   125
	 */
5744980c78cf 6587576 cpu_info kstat is returning garbage in supported_frequencies_Hz
mh27603
parents: 4718
diff changeset
   126
	cpu_set_supp_freqs(cp, NULL);
5744980c78cf 6587576 cpu_info kstat is returning garbage in supported_frequencies_Hz
mh27603
parents: 4718
diff changeset
   127
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   128
	(void) strcpy(pi->pi_processor_type, "i386");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   129
	if (fpu_exists)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   130
		(void) strcpy(pi->pi_fputypes, "i387 compatible");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   131
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   132
	(void) cpuid_getidstr(cp, buf, sizeof (buf));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   133
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   134
	cp->cpu_idstr = kmem_alloc(strlen(buf) + 1, KM_SLEEP);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   135
	(void) strcpy(cp->cpu_idstr, buf);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   136
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   137
	cmn_err(CE_CONT, "?cpu%d: %s\n", cp->cpu_id, cp->cpu_idstr);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   138
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   139
	(void) cpuid_getbrandstr(cp, buf, sizeof (buf));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   140
	cp->cpu_brandstr = kmem_alloc(strlen(buf) + 1, KM_SLEEP);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   141
	(void) strcpy(cp->cpu_brandstr, buf);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   142
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   143
	cmn_err(CE_CONT, "?cpu%d: %s\n", cp->cpu_id, cp->cpu_brandstr);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   144
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   145
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   146
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   147
 * Configure syscall support on this CPU.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   148
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   149
/*ARGSUSED*/
5295
a21f2449e5f9 PSARC/2005/469 X86 Energy Star compliance
randyf
parents: 5254
diff changeset
   150
void
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   151
init_cpu_syscall(struct cpu *cp)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   152
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   153
	kpreempt_disable();
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   154
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   155
#if defined(__amd64)
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   156
	if ((x86_feature & (X86_MSR | X86_ASYSC)) == (X86_MSR | X86_ASYSC)) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   157
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   158
#if !defined(__lint)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   159
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   160
		 * The syscall instruction imposes a certain ordering on
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   161
		 * segment selectors, so we double-check that ordering
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   162
		 * here.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   163
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   164
		ASSERT(KDS_SEL == KCS_SEL + 8);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   165
		ASSERT(UDS_SEL == U32CS_SEL + 8);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   166
		ASSERT(UCS_SEL == U32CS_SEL + 16);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   167
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   168
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   169
		 * Turn syscall/sysret extensions on.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   170
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   171
		cpu_asysc_enable();
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   172
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   173
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   174
		 * Program the magic registers ..
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   175
		 */
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   176
		wrmsr(MSR_AMD_STAR,
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   177
		    ((uint64_t)(U32CS_SEL << 16 | KCS_SEL)) << 32);
770
0eda482eb80f 6311933 rdmsr/wrmsr do not need to set/pass values via memory pointers
kucharsk
parents: 414
diff changeset
   178
		wrmsr(MSR_AMD_LSTAR, (uint64_t)(uintptr_t)sys_syscall);
0eda482eb80f 6311933 rdmsr/wrmsr do not need to set/pass values via memory pointers
kucharsk
parents: 414
diff changeset
   179
		wrmsr(MSR_AMD_CSTAR, (uint64_t)(uintptr_t)sys_syscall32);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   180
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   181
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   182
		 * This list of flags is masked off the incoming
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   183
		 * %rfl when we enter the kernel.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   184
		 */
770
0eda482eb80f 6311933 rdmsr/wrmsr do not need to set/pass values via memory pointers
kucharsk
parents: 414
diff changeset
   185
		wrmsr(MSR_AMD_SFMASK, (uint64_t)(uintptr_t)(PS_IE | PS_T));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   186
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   187
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   188
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   189
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   190
	 * On 32-bit kernels, we use sysenter/sysexit because it's too
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   191
	 * hard to use syscall/sysret, and it is more portable anyway.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   192
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   193
	 * On 64-bit kernels on Nocona machines, the 32-bit syscall
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   194
	 * variant isn't available to 32-bit applications, but sysenter is.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   195
	 */
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   196
	if ((x86_feature & (X86_MSR | X86_SEP)) == (X86_MSR | X86_SEP)) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   197
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   198
#if !defined(__lint)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   199
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   200
		 * The sysenter instruction imposes a certain ordering on
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   201
		 * segment selectors, so we double-check that ordering
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   202
		 * here. See "sysenter" in Intel document 245471-012, "IA-32
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   203
		 * Intel Architecture Software Developer's Manual Volume 2:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   204
		 * Instruction Set Reference"
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   205
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   206
		ASSERT(KDS_SEL == KCS_SEL + 8);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   207
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   208
		ASSERT32(UCS_SEL == ((KCS_SEL + 16) | 3));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   209
		ASSERT32(UDS_SEL == UCS_SEL + 8);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   210
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   211
		ASSERT64(U32CS_SEL == ((KCS_SEL + 16) | 3));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   212
		ASSERT64(UDS_SEL == U32CS_SEL + 8);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   213
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   214
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   215
		cpu_sep_enable();
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   216
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   217
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   218
		 * resume() sets this value to the base of the threads stack
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   219
		 * via a context handler.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   220
		 */
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   221
		wrmsr(MSR_INTC_SEP_ESP, 0);
770
0eda482eb80f 6311933 rdmsr/wrmsr do not need to set/pass values via memory pointers
kucharsk
parents: 414
diff changeset
   222
		wrmsr(MSR_INTC_SEP_EIP, (uint64_t)(uintptr_t)sys_sysenter);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   223
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   224
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   225
	kpreempt_enable();
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   226
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   227
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   228
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   229
 * Multiprocessor initialization.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   230
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   231
 * Allocate and initialize the cpu structure, TRAPTRACE buffer, and the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   232
 * startup and idle threads for the specified CPU.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   233
 */
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   234
struct cpu *
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   235
mp_startup_init(int cpun)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   236
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   237
	struct cpu *cp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   238
	kthread_id_t tp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   239
	caddr_t	sp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   240
	proc_t *procp;
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   241
#if !defined(__xpv)
5045
75a798a98460 6577948 mach_alloc_mwait leaks memory when a CPU fails to start
bholler
parents: 4877
diff changeset
   242
	extern int idle_cpu_prefer_mwait;
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   243
#endif
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   244
	extern void idle();
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   245
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   246
#ifdef TRAPTRACE
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   247
	trap_trace_ctl_t *ttc = &trap_trace_ctl[cpun];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   248
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   249
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   250
	ASSERT(cpun < NCPU && cpu[cpun] == NULL);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   251
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   252
	cp = kmem_zalloc(sizeof (*cp), KM_SLEEP);
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   253
#if !defined(__xpv)
5045
75a798a98460 6577948 mach_alloc_mwait leaks memory when a CPU fails to start
bholler
parents: 4877
diff changeset
   254
	if ((x86_feature & X86_MWAIT) && idle_cpu_prefer_mwait)
75a798a98460 6577948 mach_alloc_mwait leaks memory when a CPU fails to start
bholler
parents: 4877
diff changeset
   255
		cp->cpu_m.mcpu_mwait = cpuid_mwait_alloc(CPU);
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   256
#endif
4481
2bb321aaf3c3 6495392 use monitor/mwait for halting idle CPUs where supported
bholler
parents: 3446
diff changeset
   257
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   258
	procp = curthread->t_procp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   259
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   260
	mutex_enter(&cpu_lock);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   261
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   262
	 * Initialize the dispatcher first.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   263
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   264
	disp_cpu_init(cp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   265
	mutex_exit(&cpu_lock);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   266
414
c62c3f13a640 6286816 page_numtopp_nolock is inefficent
kchow
parents: 359
diff changeset
   267
	cpu_vm_data_init(cp);
c62c3f13a640 6286816 page_numtopp_nolock is inefficent
kchow
parents: 359
diff changeset
   268
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   269
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   270
	 * Allocate and initialize the startup thread for this CPU.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   271
	 * Interrupt and process switch stacks get allocated later
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   272
	 * when the CPU starts running.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   273
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   274
	tp = thread_create(NULL, 0, NULL, NULL, 0, procp,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   275
	    TS_STOPPED, maxclsyspri);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   276
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   277
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   278
	 * Set state to TS_ONPROC since this thread will start running
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   279
	 * as soon as the CPU comes online.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   280
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   281
	 * All the other fields of the thread structure are setup by
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   282
	 * thread_create().
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   283
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   284
	THREAD_ONPROC(tp, cp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   285
	tp->t_preempt = 1;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   286
	tp->t_bound_cpu = cp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   287
	tp->t_affinitycnt = 1;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   288
	tp->t_cpu = cp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   289
	tp->t_disp_queue = cp->cpu_disp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   290
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   291
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   292
	 * Setup thread to start in mp_startup.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   293
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   294
	sp = tp->t_stk;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   295
	tp->t_pc = (uintptr_t)mp_startup;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   296
	tp->t_sp = (uintptr_t)(sp - MINFRAME);
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   297
#if defined(__amd64)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   298
	tp->t_sp -= STACK_ENTRY_ALIGN;		/* fake a call */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   299
#endif
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   300
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   301
	cp->cpu_id = cpun;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   302
	cp->cpu_self = cp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   303
	cp->cpu_thread = tp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   304
	cp->cpu_lwp = NULL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   305
	cp->cpu_dispthread = tp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   306
	cp->cpu_dispatch_pri = DISP_PRIO(tp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   307
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   308
	/*
1482
dd0dbac7d2af 6381715 cpu_base_spl must be set before mp_startup to prevent device interrupts from inducing panics
sethg
parents: 1455
diff changeset
   309
	 * cpu_base_spl must be set explicitly here to prevent any blocking
dd0dbac7d2af 6381715 cpu_base_spl must be set before mp_startup to prevent device interrupts from inducing panics
sethg
parents: 1455
diff changeset
   310
	 * operations in mp_startup from causing the spl of the cpu to drop
dd0dbac7d2af 6381715 cpu_base_spl must be set before mp_startup to prevent device interrupts from inducing panics
sethg
parents: 1455
diff changeset
   311
	 * to 0 (allowing device interrupts before we're ready) in resume().
dd0dbac7d2af 6381715 cpu_base_spl must be set before mp_startup to prevent device interrupts from inducing panics
sethg
parents: 1455
diff changeset
   312
	 * cpu_base_spl MUST remain at LOCK_LEVEL until the cpu is CPU_READY.
dd0dbac7d2af 6381715 cpu_base_spl must be set before mp_startup to prevent device interrupts from inducing panics
sethg
parents: 1455
diff changeset
   313
	 * As an extra bit of security on DEBUG kernels, this is enforced with
dd0dbac7d2af 6381715 cpu_base_spl must be set before mp_startup to prevent device interrupts from inducing panics
sethg
parents: 1455
diff changeset
   314
	 * an assertion in mp_startup() -- before cpu_base_spl is set to its
dd0dbac7d2af 6381715 cpu_base_spl must be set before mp_startup to prevent device interrupts from inducing panics
sethg
parents: 1455
diff changeset
   315
	 * proper value.
dd0dbac7d2af 6381715 cpu_base_spl must be set before mp_startup to prevent device interrupts from inducing panics
sethg
parents: 1455
diff changeset
   316
	 */
dd0dbac7d2af 6381715 cpu_base_spl must be set before mp_startup to prevent device interrupts from inducing panics
sethg
parents: 1455
diff changeset
   317
	cp->cpu_base_spl = ipltospl(LOCK_LEVEL);
dd0dbac7d2af 6381715 cpu_base_spl must be set before mp_startup to prevent device interrupts from inducing panics
sethg
parents: 1455
diff changeset
   318
dd0dbac7d2af 6381715 cpu_base_spl must be set before mp_startup to prevent device interrupts from inducing panics
sethg
parents: 1455
diff changeset
   319
	/*
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   320
	 * Now, initialize per-CPU idle thread for this CPU.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   321
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   322
	tp = thread_create(NULL, PAGESIZE, idle, NULL, 0, procp, TS_ONPROC, -1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   323
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   324
	cp->cpu_idle_thread = tp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   325
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   326
	tp->t_preempt = 1;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   327
	tp->t_bound_cpu = cp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   328
	tp->t_affinitycnt = 1;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   329
	tp->t_cpu = cp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   330
	tp->t_disp_queue = cp->cpu_disp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   331
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   332
	/*
3434
5142e1d7d0bc 6461311 multi-level CMT scheduling optimizations
esaxe
parents: 3029
diff changeset
   333
	 * Bootstrap the CPU's PG data
60
747dee212c5e 6281872 set lgrp_load_thresh=0 and set lgrp_mem_policy_root=6 in /etc/system cause panic on dual core v40z
esaxe
parents: 0
diff changeset
   334
	 */
3434
5142e1d7d0bc 6461311 multi-level CMT scheduling optimizations
esaxe
parents: 3029
diff changeset
   335
	pg_cpu_bootstrap(cp);
60
747dee212c5e 6281872 set lgrp_load_thresh=0 and set lgrp_mem_policy_root=6 in /etc/system cause panic on dual core v40z
esaxe
parents: 0
diff changeset
   336
747dee212c5e 6281872 set lgrp_load_thresh=0 and set lgrp_mem_policy_root=6 in /etc/system cause panic on dual core v40z
esaxe
parents: 0
diff changeset
   337
	/*
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   338
	 * Perform CPC initialization on the new CPU.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   339
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   340
	kcpc_hw_init(cp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   341
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   342
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   343
	 * Allocate virtual addresses for cpu_caddr1 and cpu_caddr2
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   344
	 * for each CPU.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   345
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   346
	setup_vaddr_for_ppcopy(cp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   347
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   348
	/*
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   349
	 * Allocate page for new GDT and initialize from current GDT.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   350
	 */
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   351
#if !defined(__lint)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   352
	ASSERT((sizeof (*cp->cpu_gdt) * NGDT) <= PAGESIZE);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   353
#endif
5460
265cc42b6f62 6624280 GDT, LDT, IDT and TSS should not share pages with other things
josephb
parents: 5295
diff changeset
   354
	cp->cpu_gdt = kmem_zalloc(PAGESIZE, KM_SLEEP);
265cc42b6f62 6624280 GDT, LDT, IDT and TSS should not share pages with other things
josephb
parents: 5295
diff changeset
   355
	bcopy(CPU->cpu_gdt, cp->cpu_gdt, (sizeof (*cp->cpu_gdt) * NGDT));
1626
9a953b15f01f 6254431 GDT should reside on its own page
rab
parents: 1582
diff changeset
   356
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   357
#if defined(__i386)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   358
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   359
	 * setup kernel %gs.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   360
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   361
	set_usegd(&cp->cpu_gdt[GDT_GS], cp, sizeof (struct cpu) -1, SDT_MEMRWA,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   362
	    SEL_KPL, 0, 1);
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   363
#endif
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   364
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   365
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   366
	 * If we have more than one node, each cpu gets a copy of IDT
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   367
	 * local to its node. If this is a Pentium box, we use cpu 0's
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   368
	 * IDT. cpu 0's IDT has been made read-only to workaround the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   369
	 * cmpxchgl register bug
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   370
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   371
	if (system_hardware.hd_nodes && x86_type != X86_TYPE_P5) {
5460
265cc42b6f62 6624280 GDT, LDT, IDT and TSS should not share pages with other things
josephb
parents: 5295
diff changeset
   372
#if !defined(__lint)
265cc42b6f62 6624280 GDT, LDT, IDT and TSS should not share pages with other things
josephb
parents: 5295
diff changeset
   373
		ASSERT((sizeof (*CPU->cpu_idt) * NIDT) <= PAGESIZE);
265cc42b6f62 6624280 GDT, LDT, IDT and TSS should not share pages with other things
josephb
parents: 5295
diff changeset
   374
#endif
265cc42b6f62 6624280 GDT, LDT, IDT and TSS should not share pages with other things
josephb
parents: 5295
diff changeset
   375
		cp->cpu_idt = kmem_zalloc(PAGESIZE, KM_SLEEP);
265cc42b6f62 6624280 GDT, LDT, IDT and TSS should not share pages with other things
josephb
parents: 5295
diff changeset
   376
		bcopy(CPU->cpu_idt, cp->cpu_idt, PAGESIZE);
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   377
	} else {
5460
265cc42b6f62 6624280 GDT, LDT, IDT and TSS should not share pages with other things
josephb
parents: 5295
diff changeset
   378
		cp->cpu_idt = CPU->cpu_idt;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   379
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   380
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   381
	/*
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   382
	 * Get interrupt priority data from cpu 0.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   383
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   384
	cp->cpu_pri_data = CPU->cpu_pri_data;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   385
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   386
	/*
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   387
	 * alloc space for cpuid info
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   388
	 */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   389
	cpuid_alloc_space(cp);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   390
4581
b6104e41b06c PSARC/2007/349 Intel Microcode Update Support
sherrym
parents: 4481
diff changeset
   391
	/*
b6104e41b06c PSARC/2007/349 Intel Microcode Update Support
sherrym
parents: 4481
diff changeset
   392
	 * alloc space for ucode_info
b6104e41b06c PSARC/2007/349 Intel Microcode Update Support
sherrym
parents: 4481
diff changeset
   393
	 */
b6104e41b06c PSARC/2007/349 Intel Microcode Update Support
sherrym
parents: 4481
diff changeset
   394
	ucode_alloc_space(cp);
b6104e41b06c PSARC/2007/349 Intel Microcode Update Support
sherrym
parents: 4481
diff changeset
   395
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   396
	hat_cpu_online(cp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   397
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   398
#ifdef TRAPTRACE
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   399
	/*
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   400
	 * If this is a TRAPTRACE kernel, allocate TRAPTRACE buffers
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   401
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   402
	ttc->ttc_first = (uintptr_t)kmem_zalloc(trap_trace_bufsize, KM_SLEEP);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   403
	ttc->ttc_next = ttc->ttc_first;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   404
	ttc->ttc_limit = ttc->ttc_first + trap_trace_bufsize;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   405
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   406
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   407
	 * Record that we have another CPU.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   408
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   409
	mutex_enter(&cpu_lock);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   410
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   411
	 * Initialize the interrupt threads for this CPU
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   412
	 */
1455
b43f098fa50c 6378953 allocation of interrupt threads could be more common
andrei
parents: 1414
diff changeset
   413
	cpu_intr_alloc(cp, NINTR_THREADS);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   414
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   415
	 * Add CPU to list of available CPUs.  It'll be on the active list
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   416
	 * after mp_startup().
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   417
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   418
	cpu_add_unit(cp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   419
	mutex_exit(&cpu_lock);
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   420
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   421
	return (cp);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   422
}
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   423
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   424
/*
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   425
 * Undo what was done in mp_startup_init
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   426
 */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   427
static void
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   428
mp_startup_fini(struct cpu *cp, int error)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   429
{
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   430
	mutex_enter(&cpu_lock);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   431
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   432
	/*
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   433
	 * Remove the CPU from the list of available CPUs.
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   434
	 */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   435
	cpu_del_unit(cp->cpu_id);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   436
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   437
	if (error == ETIMEDOUT) {
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   438
		/*
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   439
		 * The cpu was started, but never *seemed* to run any
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   440
		 * code in the kernel; it's probably off spinning in its
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   441
		 * own private world, though with potential references to
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   442
		 * our kmem-allocated IDTs and GDTs (for example).
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   443
		 *
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   444
		 * Worse still, it may actually wake up some time later,
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   445
		 * so rather than guess what it might or might not do, we
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   446
		 * leave the fundamental data structures intact.
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   447
		 */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   448
		cp->cpu_flags = 0;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   449
		mutex_exit(&cpu_lock);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   450
		return;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   451
	}
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   452
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   453
	/*
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   454
	 * At this point, the only threads bound to this CPU should
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   455
	 * special per-cpu threads: it's idle thread, it's pause threads,
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   456
	 * and it's interrupt threads.  Clean these up.
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   457
	 */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   458
	cpu_destroy_bound_threads(cp);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   459
	cp->cpu_idle_thread = NULL;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   460
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   461
	/*
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   462
	 * Free the interrupt stack.
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   463
	 */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   464
	segkp_release(segkp,
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   465
	    cp->cpu_intr_stack - (INTR_STACK_SIZE - SA(MINFRAME)));
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   466
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   467
	mutex_exit(&cpu_lock);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   468
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   469
#ifdef TRAPTRACE
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   470
	/*
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   471
	 * Discard the trap trace buffer
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   472
	 */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   473
	{
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   474
		trap_trace_ctl_t *ttc = &trap_trace_ctl[cp->cpu_id];
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   475
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   476
		kmem_free((void *)ttc->ttc_first, trap_trace_bufsize);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   477
		ttc->ttc_first = NULL;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   478
	}
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   479
#endif
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   480
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   481
	hat_cpu_offline(cp);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   482
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   483
	cpuid_free_space(cp);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   484
4581
b6104e41b06c PSARC/2007/349 Intel Microcode Update Support
sherrym
parents: 4481
diff changeset
   485
	ucode_free_space(cp);
b6104e41b06c PSARC/2007/349 Intel Microcode Update Support
sherrym
parents: 4481
diff changeset
   486
5460
265cc42b6f62 6624280 GDT, LDT, IDT and TSS should not share pages with other things
josephb
parents: 5295
diff changeset
   487
	if (cp->cpu_idt != CPU->cpu_idt)
265cc42b6f62 6624280 GDT, LDT, IDT and TSS should not share pages with other things
josephb
parents: 5295
diff changeset
   488
		kmem_free(cp->cpu_idt, PAGESIZE);
265cc42b6f62 6624280 GDT, LDT, IDT and TSS should not share pages with other things
josephb
parents: 5295
diff changeset
   489
	cp->cpu_idt = NULL;
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   490
5460
265cc42b6f62 6624280 GDT, LDT, IDT and TSS should not share pages with other things
josephb
parents: 5295
diff changeset
   491
	kmem_free(cp->cpu_gdt, PAGESIZE);
265cc42b6f62 6624280 GDT, LDT, IDT and TSS should not share pages with other things
josephb
parents: 5295
diff changeset
   492
	cp->cpu_gdt = NULL;
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   493
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   494
	teardown_vaddr_for_ppcopy(cp);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   495
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   496
	kcpc_hw_fini(cp);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   497
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   498
	cp->cpu_dispthread = NULL;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   499
	cp->cpu_thread = NULL;	/* discarded by cpu_destroy_bound_threads() */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   500
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   501
	cpu_vm_data_destroy(cp);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   502
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   503
	mutex_enter(&cpu_lock);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   504
	disp_cpu_fini(cp);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   505
	mutex_exit(&cpu_lock);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   506
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   507
#if !defined(__xpv)
5045
75a798a98460 6577948 mach_alloc_mwait leaks memory when a CPU fails to start
bholler
parents: 4877
diff changeset
   508
	if (cp->cpu_m.mcpu_mwait != NULL)
75a798a98460 6577948 mach_alloc_mwait leaks memory when a CPU fails to start
bholler
parents: 4877
diff changeset
   509
		cpuid_mwait_free(cp);
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   510
#endif
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   511
	kmem_free(cp, sizeof (*cp));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   512
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   513
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   514
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   515
 * Apply workarounds for known errata, and warn about those that are absent.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   516
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   517
 * System vendors occasionally create configurations which contain different
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   518
 * revisions of the CPUs that are almost but not exactly the same.  At the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   519
 * time of writing, this meant that their clock rates were the same, their
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   520
 * feature sets were the same, but the required workaround were -not-
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   521
 * necessarily the same.  So, this routine is invoked on -every- CPU soon
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   522
 * after starting to make sure that the resulting system contains the most
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   523
 * pessimal set of workarounds needed to cope with *any* of the CPUs in the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   524
 * system.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   525
 *
938
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
   526
 * workaround_errata is invoked early in mlsetup() for CPU 0, and in
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
   527
 * mp_startup() for all slave CPUs. Slaves process workaround_errata prior
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
   528
 * to acknowledging their readiness to the master, so this routine will
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
   529
 * never be executed by multiple CPUs in parallel, thus making updates to
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
   530
 * global data safe.
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
   531
 *
359
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
   532
 * These workarounds are based on Rev 3.57 of the Revision Guide for
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
   533
 * AMD Athlon(tm) 64 and AMD Opteron(tm) Processors, August 2005.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   534
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   535
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   536
#if defined(OPTERON_ERRATUM_88)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   537
int opteron_erratum_88;		/* if non-zero -> at least one cpu has it */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   538
#endif
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   539
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   540
#if defined(OPTERON_ERRATUM_91)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   541
int opteron_erratum_91;		/* if non-zero -> at least one cpu has it */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   542
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   543
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   544
#if defined(OPTERON_ERRATUM_93)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   545
int opteron_erratum_93;		/* if non-zero -> at least one cpu has it */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   546
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   547
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   548
#if defined(OPTERON_ERRATUM_95)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   549
int opteron_erratum_95;		/* if non-zero -> at least one cpu has it */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   550
#endif
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   551
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   552
#if defined(OPTERON_ERRATUM_100)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   553
int opteron_erratum_100;	/* if non-zero -> at least one cpu has it */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   554
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   555
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   556
#if defined(OPTERON_ERRATUM_108)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   557
int opteron_erratum_108;	/* if non-zero -> at least one cpu has it */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   558
#endif
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   559
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   560
#if defined(OPTERON_ERRATUM_109)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   561
int opteron_erratum_109;	/* if non-zero -> at least one cpu has it */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   562
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   563
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   564
#if defined(OPTERON_ERRATUM_121)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   565
int opteron_erratum_121;	/* if non-zero -> at least one cpu has it */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   566
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   567
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   568
#if defined(OPTERON_ERRATUM_122)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   569
int opteron_erratum_122;	/* if non-zero -> at least one cpu has it */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   570
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   571
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   572
#if defined(OPTERON_ERRATUM_123)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   573
int opteron_erratum_123;	/* if non-zero -> at least one cpu has it */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   574
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   575
359
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
   576
#if defined(OPTERON_ERRATUM_131)
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
   577
int opteron_erratum_131;	/* if non-zero -> at least one cpu has it */
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
   578
#endif
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   579
938
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
   580
#if defined(OPTERON_WORKAROUND_6336786)
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
   581
int opteron_workaround_6336786;	/* non-zero -> WA relevant and applied */
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
   582
int opteron_workaround_6336786_UP = 0;	/* Not needed for UP */
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
   583
#endif
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
   584
1582
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
   585
#if defined(OPTERON_WORKAROUND_6323525)
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
   586
int opteron_workaround_6323525;	/* if non-zero -> at least one cpu has it */
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
   587
#endif
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
   588
6691
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   589
#if defined(OPTERON_ERRATUM_298)
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   590
int opteron_erratum_298;
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   591
#endif
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   592
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   593
static void
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   594
workaround_warning(cpu_t *cp, uint_t erratum)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   595
{
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   596
	cmn_err(CE_WARN, "cpu%d: no workaround for erratum %u",
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   597
	    cp->cpu_id, erratum);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   598
}
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   599
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   600
static void
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   601
workaround_applied(uint_t erratum)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   602
{
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   603
	if (erratum > 1000000)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   604
		cmn_err(CE_CONT, "?workaround applied for cpu issue #%d\n",
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   605
		    erratum);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   606
	else
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   607
		cmn_err(CE_CONT, "?workaround applied for cpu erratum #%d\n",
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   608
		    erratum);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   609
}
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   610
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   611
static void
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   612
msr_warning(cpu_t *cp, const char *rw, uint_t msr, int error)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   613
{
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   614
	cmn_err(CE_WARN, "cpu%d: couldn't %smsr 0x%x, error %d",
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   615
	    cp->cpu_id, rw, msr, error);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   616
}
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   617
5893
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   618
/*
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   619
 * Determine the number of nodes in an Opteron / Greyhound family system.
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   620
 */
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   621
static uint_t
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   622
opteron_get_nnodes(void)
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   623
{
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   624
	static uint_t nnodes = 0;
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   625
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   626
#ifdef	DEBUG
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   627
	uint_t family;
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   628
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   629
	family = cpuid_getfamily(CPU);
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   630
	ASSERT(family == 0xf || family == 0x10);
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   631
#endif	/* DEBUG */
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   632
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   633
	if (nnodes == 0) {
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   634
		/*
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   635
		 * Obtain the number of nodes in the system from
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   636
		 * bits [6:4] of the Node ID register on node 0.
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   637
		 *
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   638
		 * The actual node count is NodeID[6:4] + 1
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   639
		 *
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   640
		 * The Node ID register is accessed via function 0,
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   641
		 * offset 0x60. Node 0 is device 24.
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   642
		 */
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   643
		nnodes = ((pci_getl_func(0, 24, 0, 0x60) & 0x70) >> 4) + 1;
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   644
	}
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   645
	return (nnodes);
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   646
}
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   647
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   648
#if defined(__xpv)
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   649
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   650
/*
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   651
 * On dom0, we can determine the number of physical cpus on the machine.
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   652
 * This number is important when figuring out what workarounds are
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   653
 * appropriate, so compute it now.
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   654
 */
6670
1961a43f2335 6685348 Hypervisor event provider for DTrace
tariq
parents: 6336
diff changeset
   655
uint_t
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   656
xen_get_nphyscpus(void)
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   657
{
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   658
	static uint_t nphyscpus = 0;
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   659
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   660
	ASSERT(DOMAIN_IS_INITDOMAIN(xen_info));
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   661
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   662
	if (nphyscpus == 0) {
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   663
		xen_sysctl_t op;
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   664
		xen_sysctl_physinfo_t *pi = &op.u.physinfo;
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   665
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   666
		op.cmd = XEN_SYSCTL_physinfo;
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   667
		op.interface_version = XEN_SYSCTL_INTERFACE_VERSION;
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   668
		if (HYPERVISOR_sysctl(&op) == 0)
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   669
			nphyscpus = pi->threads_per_core *
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   670
			    pi->cores_per_socket * pi->sockets_per_node *
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   671
			    pi->nr_nodes;
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   672
	}
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   673
	return (nphyscpus);
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   674
}
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   675
#endif
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   676
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   677
uint_t
6691
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   678
do_erratum_298(struct cpu *cpu)
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   679
{
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   680
	static int	osvwrc = -3;
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   681
	extern int	osvw_opteron_erratum(cpu_t *, uint_t);
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   682
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   683
	/*
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   684
	 * L2 Eviction May Occur During Processor Operation To Set
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   685
	 * Accessed or Dirty Bit.
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   686
	 */
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   687
	if (osvwrc == -3) {
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   688
		osvwrc = osvw_opteron_erratum(cpu, 298);
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   689
	} else {
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   690
		/* osvw return codes should be consistent for all cpus */
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   691
		ASSERT(osvwrc == osvw_opteron_erratum(cpu, 298));
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   692
	}
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   693
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   694
	switch (osvwrc) {
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   695
	case 0:		/* erratum is not present: do nothing */
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   696
		break;
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   697
	case 1:		/* erratum is present: BIOS workaround applied */
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   698
		/*
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   699
		 * check if workaround is actually in place and issue warning
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   700
		 * if not.
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   701
		 */
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   702
		if (((rdmsr(MSR_AMD_HWCR) & AMD_HWCR_TLBCACHEDIS) == 0) ||
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   703
		    ((rdmsr(MSR_AMD_BU_CFG) & AMD_BU_CFG_E298) == 0)) {
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   704
#if defined(OPTERON_ERRATUM_298)
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   705
			opteron_erratum_298++;
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   706
#else
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   707
			workaround_warning(cpu, 298);
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   708
			return (1);
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   709
#endif
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   710
		}
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   711
		break;
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   712
	case -1:	/* cannot determine via osvw: check cpuid */
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   713
		if ((cpuid_opteron_erratum(cpu, 298) > 0) &&
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   714
		    (((rdmsr(MSR_AMD_HWCR) & AMD_HWCR_TLBCACHEDIS) == 0) ||
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   715
		    ((rdmsr(MSR_AMD_BU_CFG) & AMD_BU_CFG_E298) == 0))) {
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   716
#if defined(OPTERON_ERRATUM_298)
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   717
			opteron_erratum_298++;
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   718
#else
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   719
			workaround_warning(cpu, 298);
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   720
			return (1);
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   721
#endif
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   722
		}
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   723
		break;
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   724
	}
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   725
	return (0);
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   726
}
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   727
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
   728
uint_t
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   729
workaround_errata(struct cpu *cpu)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   730
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   731
	uint_t missing = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   732
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   733
	ASSERT(cpu == CPU);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   734
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   735
	/*LINTED*/
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   736
	if (cpuid_opteron_erratum(cpu, 88) > 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   737
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   738
		 * SWAPGS May Fail To Read Correct GS Base
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   739
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   740
#if defined(OPTERON_ERRATUM_88)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   741
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   742
		 * The workaround is an mfence in the relevant assembler code
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   743
		 */
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   744
		opteron_erratum_88++;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   745
#else
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   746
		workaround_warning(cpu, 88);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   747
		missing++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   748
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   749
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   750
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   751
	if (cpuid_opteron_erratum(cpu, 91) > 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   752
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   753
		 * Software Prefetches May Report A Page Fault
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   754
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   755
#if defined(OPTERON_ERRATUM_91)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   756
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   757
		 * fix is in trap.c
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   758
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   759
		opteron_erratum_91++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   760
#else
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   761
		workaround_warning(cpu, 91);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   762
		missing++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   763
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   764
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   765
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   766
	if (cpuid_opteron_erratum(cpu, 93) > 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   767
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   768
		 * RSM Auto-Halt Restart Returns to Incorrect RIP
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   769
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   770
#if defined(OPTERON_ERRATUM_93)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   771
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   772
		 * fix is in trap.c
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   773
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   774
		opteron_erratum_93++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   775
#else
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   776
		workaround_warning(cpu, 93);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   777
		missing++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   778
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   779
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   780
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   781
	/*LINTED*/
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   782
	if (cpuid_opteron_erratum(cpu, 95) > 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   783
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   784
		 * RET Instruction May Return to Incorrect EIP
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   785
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   786
#if defined(OPTERON_ERRATUM_95)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   787
#if defined(_LP64)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   788
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   789
		 * Workaround this by ensuring that 32-bit user code and
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   790
		 * 64-bit kernel code never occupy the same address
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   791
		 * range mod 4G.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   792
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   793
		if (_userlimit32 > 0xc0000000ul)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   794
			*(uintptr_t *)&_userlimit32 = 0xc0000000ul;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   795
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   796
		/*LINTED*/
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   797
		ASSERT((uint32_t)COREHEAP_BASE == 0xc0000000u);
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   798
		opteron_erratum_95++;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   799
#endif	/* _LP64 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   800
#else
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   801
		workaround_warning(cpu, 95);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   802
		missing++;
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   803
#endif
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   804
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   805
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   806
	if (cpuid_opteron_erratum(cpu, 100) > 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   807
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   808
		 * Compatibility Mode Branches Transfer to Illegal Address
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   809
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   810
#if defined(OPTERON_ERRATUM_100)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   811
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   812
		 * fix is in trap.c
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   813
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   814
		opteron_erratum_100++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   815
#else
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   816
		workaround_warning(cpu, 100);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   817
		missing++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   818
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   819
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   820
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   821
	/*LINTED*/
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   822
	if (cpuid_opteron_erratum(cpu, 108) > 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   823
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   824
		 * CPUID Instruction May Return Incorrect Model Number In
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   825
		 * Some Processors
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   826
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   827
#if defined(OPTERON_ERRATUM_108)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   828
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   829
		 * (Our cpuid-handling code corrects the model number on
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   830
		 * those processors)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   831
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   832
#else
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   833
		workaround_warning(cpu, 108);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   834
		missing++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   835
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   836
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   837
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   838
	/*LINTED*/
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   839
	if (cpuid_opteron_erratum(cpu, 109) > 0) do {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   840
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   841
		 * Certain Reverse REP MOVS May Produce Unpredictable Behaviour
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   842
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   843
#if defined(OPTERON_ERRATUM_109)
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   844
		/*
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   845
		 * The "workaround" is to print a warning to upgrade the BIOS
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   846
		 */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   847
		uint64_t value;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   848
		const uint_t msr = MSR_AMD_PATCHLEVEL;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   849
		int err;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   850
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   851
		if ((err = checked_rdmsr(msr, &value)) != 0) {
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   852
			msr_warning(cpu, "rd", msr, err);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   853
			workaround_warning(cpu, 109);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   854
			missing++;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   855
		}
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   856
		if (value == 0)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   857
			opteron_erratum_109++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   858
#else
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   859
		workaround_warning(cpu, 109);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   860
		missing++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   861
#endif
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   862
	/*CONSTANTCONDITION*/
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   863
	} while (0);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   864
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   865
	/*LINTED*/
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   866
	if (cpuid_opteron_erratum(cpu, 121) > 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   867
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   868
		 * Sequential Execution Across Non_Canonical Boundary Caused
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   869
		 * Processor Hang
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   870
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   871
#if defined(OPTERON_ERRATUM_121)
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   872
#if defined(_LP64)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   873
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   874
		 * Erratum 121 is only present in long (64 bit) mode.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   875
		 * Workaround is to include the page immediately before the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   876
		 * va hole to eliminate the possibility of system hangs due to
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   877
		 * sequential execution across the va hole boundary.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   878
		 */
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   879
		if (opteron_erratum_121)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   880
			opteron_erratum_121++;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   881
		else {
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   882
			if (hole_start) {
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   883
				hole_start -= PAGESIZE;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   884
			} else {
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   885
				/*
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   886
				 * hole_start not yet initialized by
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   887
				 * mmu_init. Initialize hole_start
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   888
				 * with value to be subtracted.
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   889
				 */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   890
				hole_start = PAGESIZE;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   891
			}
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   892
			opteron_erratum_121++;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   893
		}
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   894
#endif	/* _LP64 */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   895
#else
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   896
		workaround_warning(cpu, 121);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   897
		missing++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   898
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   899
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   900
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   901
	/*LINTED*/
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   902
	if (cpuid_opteron_erratum(cpu, 122) > 0) do {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   903
		/*
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   904
		 * TLB Flush Filter May Cause Coherency Problem in
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   905
		 * Multiprocessor Systems
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   906
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   907
#if defined(OPTERON_ERRATUM_122)
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   908
		uint64_t value;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   909
		const uint_t msr = MSR_AMD_HWCR;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   910
		int error;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   911
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   912
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   913
		 * Erratum 122 is only present in MP configurations (multi-core
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   914
		 * or multi-processor).
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   915
		 */
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   916
#if defined(__xpv)
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   917
		if (!DOMAIN_IS_INITDOMAIN(xen_info))
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   918
			break;
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   919
		if (!opteron_erratum_122 && xen_get_nphyscpus() == 1)
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   920
			break;
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   921
#else
5893
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
   922
		if (!opteron_erratum_122 && opteron_get_nnodes() == 1 &&
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   923
		    cpuid_get_ncpu_per_chip(cpu) == 1)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   924
			break;
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   925
#endif
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   926
		/* disable TLB Flush Filter */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   927
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   928
		if ((error = checked_rdmsr(msr, &value)) != 0) {
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   929
			msr_warning(cpu, "rd", msr, error);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   930
			workaround_warning(cpu, 122);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   931
			missing++;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   932
		} else {
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   933
			value |= (uint64_t)AMD_HWCR_FFDIS;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   934
			if ((error = checked_wrmsr(msr, value)) != 0) {
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   935
				msr_warning(cpu, "wr", msr, error);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   936
				workaround_warning(cpu, 122);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   937
				missing++;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   938
			}
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   939
		}
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   940
		opteron_erratum_122++;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   941
#else
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   942
		workaround_warning(cpu, 122);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   943
		missing++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   944
#endif
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   945
	/*CONSTANTCONDITION*/
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   946
	} while (0);
302
b21b2a25a939 6295986 False AMD Erratum 123 warning message on stinger dual-core machines
kchow
parents: 60
diff changeset
   947
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   948
	/*LINTED*/
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   949
	if (cpuid_opteron_erratum(cpu, 123) > 0) do {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   950
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   951
		 * Bypassed Reads May Cause Data Corruption of System Hang in
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   952
		 * Dual Core Processors
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   953
		 */
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   954
#if defined(OPTERON_ERRATUM_123)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   955
		uint64_t value;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   956
		const uint_t msr = MSR_AMD_PATCHLEVEL;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   957
		int err;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   958
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   959
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   960
		 * Erratum 123 applies only to multi-core cpus.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   961
		 */
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   962
		if (cpuid_get_ncpu_per_chip(cpu) < 2)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   963
			break;
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   964
#if defined(__xpv)
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   965
		if (!DOMAIN_IS_INITDOMAIN(xen_info))
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   966
			break;
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
   967
#endif
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   968
		/*
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   969
		 * The "workaround" is to print a warning to upgrade the BIOS
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   970
		 */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   971
		if ((err = checked_rdmsr(msr, &value)) != 0) {
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   972
			msr_warning(cpu, "rd", msr, err);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   973
			workaround_warning(cpu, 123);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   974
			missing++;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   975
		}
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   976
		if (value == 0)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   977
			opteron_erratum_123++;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   978
#else
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   979
		workaround_warning(cpu, 123);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   980
		missing++;
359
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
   981
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   982
#endif
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   983
	/*CONSTANTCONDITION*/
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   984
	} while (0);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   985
359
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
   986
	/*LINTED*/
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   987
	if (cpuid_opteron_erratum(cpu, 131) > 0) do {
359
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
   988
		/*
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
   989
		 * Multiprocessor Systems with Four or More Cores May Deadlock
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
   990
		 * Waiting for a Probe Response
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
   991
		 */
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   992
#if defined(OPTERON_ERRATUM_131)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   993
		uint64_t nbcfg;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   994
		const uint_t msr = MSR_AMD_NB_CFG;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   995
		const uint64_t wabits =
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   996
		    AMD_NB_CFG_SRQ_HEARTBEAT | AMD_NB_CFG_SRQ_SPR;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   997
		int error;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
   998
359
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
   999
		/*
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1000
		 * Erratum 131 applies to any system with four or more cores.
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1001
		 */
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1002
		if (opteron_erratum_131)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1003
			break;
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1004
#if defined(__xpv)
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1005
		if (!DOMAIN_IS_INITDOMAIN(xen_info))
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1006
			break;
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1007
		if (xen_get_nphyscpus() < 4)
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1008
			break;
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1009
#else
5893
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
  1010
		if (opteron_get_nnodes() * cpuid_get_ncpu_per_chip(cpu) < 4)
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1011
			break;
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1012
#endif
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1013
		/*
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1014
		 * Print a warning if neither of the workarounds for
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1015
		 * erratum 131 is present.
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1016
		 */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1017
		if ((error = checked_rdmsr(msr, &nbcfg)) != 0) {
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1018
			msr_warning(cpu, "rd", msr, error);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1019
			workaround_warning(cpu, 131);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1020
			missing++;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1021
		} else if ((nbcfg & wabits) == 0) {
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1022
			opteron_erratum_131++;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1023
		} else {
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1024
			/* cannot have both workarounds set */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1025
			ASSERT((nbcfg & wabits) != wabits);
359
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1026
		}
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1027
#else
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1028
		workaround_warning(cpu, 131);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1029
		missing++;
359
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1030
#endif
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1031
	/*CONSTANTCONDITION*/
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1032
	} while (0);
938
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1033
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1034
	/*
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1035
	 * This isn't really an erratum, but for convenience the
938
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1036
	 * detection/workaround code lives here and in cpuid_opteron_erratum.
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1037
	 */
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1038
	if (cpuid_opteron_erratum(cpu, 6336786) > 0) {
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1039
#if defined(OPTERON_WORKAROUND_6336786)
938
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1040
		/*
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1041
		 * Disable C1-Clock ramping on multi-core/multi-processor
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1042
		 * K8 platforms to guard against TSC drift.
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1043
		 */
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1044
		if (opteron_workaround_6336786) {
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1045
			opteron_workaround_6336786++;
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1046
#if defined(__xpv)
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1047
		} else if ((DOMAIN_IS_INITDOMAIN(xen_info) &&
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1048
		    xen_get_nphyscpus() > 1) ||
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1049
		    opteron_workaround_6336786_UP) {
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1050
			/*
5893
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
  1051
			 * XXPV	Hmm.  We can't walk the Northbridges on
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1052
			 *	the hypervisor; so just complain and drive
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1053
			 *	on.  This probably needs to be fixed in
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1054
			 *	the hypervisor itself.
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1055
			 */
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1056
			opteron_workaround_6336786++;
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1057
			workaround_warning(cpu, 6336786);
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1058
#else	/* __xpv */
5893
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
  1059
		} else if ((opteron_get_nnodes() *
5894
16a9cdac6a22 6629854 node interleaving can undermine C1 clock ramping workaround (fix cstyle)
esaxe
parents: 5893
diff changeset
  1060
		    cpuid_get_ncpu_per_chip(cpu) > 1) ||
938
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1061
		    opteron_workaround_6336786_UP) {
5893
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
  1062
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
  1063
			uint_t	node, nnodes;
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1064
			uint8_t data;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1065
5893
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
  1066
			nnodes = opteron_get_nnodes();
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
  1067
			for (node = 0; node < nnodes; node++) {
938
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1068
				/*
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1069
				 * Clear PMM7[1:0] (function 3, offset 0x87)
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1070
				 * Northbridge device is the node id + 24.
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1071
				 */
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1072
				data = pci_getb_func(0, node + 24, 3, 0x87);
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1073
				data &= 0xFC;
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1074
				pci_putb_func(0, node + 24, 3, 0x87, data);
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1075
			}
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1076
			opteron_workaround_6336786++;
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1077
#endif	/* __xpv */
938
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1078
		}
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1079
#else
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1080
		workaround_warning(cpu, 6336786);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1081
		missing++;
938
2d438f28c673 6336786 time doesn't fly when CPUs are not having fun
esaxe
parents: 770
diff changeset
  1082
#endif
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1083
	}
1582
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
  1084
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
  1085
	/*LINTED*/
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
  1086
	/*
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
  1087
	 * Mutex primitives don't work as expected.
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
  1088
	 */
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
  1089
	if (cpuid_opteron_erratum(cpu, 6323525) > 0) {
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1090
#if defined(OPTERON_WORKAROUND_6323525)
1582
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
  1091
		/*
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1092
		 * This problem only occurs with 2 or more cores. If bit in
6691
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
  1093
		 * MSR_AMD_BU_CFG set, then not applicable. The workaround
1582
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
  1094
		 * is to patch the semaphone routines with the lfence
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
  1095
		 * instruction to provide necessary load memory barrier with
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
  1096
		 * possible subsequent read-modify-write ops.
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
  1097
		 *
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
  1098
		 * It is too early in boot to call the patch routine so
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
  1099
		 * set erratum variable to be done in startup_end().
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
  1100
		 */
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
  1101
		if (opteron_workaround_6323525) {
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
  1102
			opteron_workaround_6323525++;
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1103
#if defined(__xpv)
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1104
		} else if (x86_feature & X86_SSE2) {
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1105
			if (DOMAIN_IS_INITDOMAIN(xen_info)) {
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1106
				/*
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1107
				 * XXPV	Use dom0_msr here when extended
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1108
				 *	operations are supported?
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1109
				 */
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1110
				if (xen_get_nphyscpus() > 1)
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1111
					opteron_workaround_6323525++;
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1112
			} else {
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1113
				/*
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1114
				 * We have no way to tell how many physical
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1115
				 * cpus there are, or even if this processor
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1116
				 * has the problem, so enable the workaround
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1117
				 * unconditionally (at some performance cost).
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1118
				 */
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1119
				opteron_workaround_6323525++;
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1120
			}
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1121
#else	/* __xpv */
5893
6c165e7db1e4 6629854 node interleaving can undermine C1 clock ramping workaround
esaxe
parents: 5460
diff changeset
  1122
		} else if ((x86_feature & X86_SSE2) && ((opteron_get_nnodes() *
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1123
		    cpuid_get_ncpu_per_chip(cpu)) > 1)) {
6691
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
  1124
			if ((xrdmsr(MSR_AMD_BU_CFG) & 0x02) == 0)
1582
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
  1125
				opteron_workaround_6323525++;
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1126
#endif	/* __xpv */
1582
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
  1127
		}
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1128
#else
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1129
		workaround_warning(cpu, 6323525);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1130
		missing++;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1131
#endif
1582
eb879d43ab47 6323525 Mutual exclusion primitives don't work as expected on Opteron systems
kchow
parents: 1482
diff changeset
  1132
	}
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1133
6691
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
  1134
	missing += do_erratum_298(cpu);
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
  1135
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1136
#ifdef __xpv
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1137
	return (0);
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1138
#else
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1139
	return (missing);
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1140
#endif
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1141
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1142
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1143
void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1144
workaround_errata_end()
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1145
{
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1146
#if defined(OPTERON_ERRATUM_88)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1147
	if (opteron_erratum_88)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1148
		workaround_applied(88);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1149
#endif
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1150
#if defined(OPTERON_ERRATUM_91)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1151
	if (opteron_erratum_91)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1152
		workaround_applied(91);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1153
#endif
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1154
#if defined(OPTERON_ERRATUM_93)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1155
	if (opteron_erratum_93)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1156
		workaround_applied(93);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1157
#endif
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1158
#if defined(OPTERON_ERRATUM_95)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1159
	if (opteron_erratum_95)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1160
		workaround_applied(95);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1161
#endif
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1162
#if defined(OPTERON_ERRATUM_100)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1163
	if (opteron_erratum_100)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1164
		workaround_applied(100);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1165
#endif
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1166
#if defined(OPTERON_ERRATUM_108)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1167
	if (opteron_erratum_108)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1168
		workaround_applied(108);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1169
#endif
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1170
#if defined(OPTERON_ERRATUM_109)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1171
	if (opteron_erratum_109) {
359
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1172
		cmn_err(CE_WARN,
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1173
		    "BIOS microcode patch for AMD Athlon(tm) 64/Opteron(tm)"
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1174
		    " processor\nerratum 109 was not detected; updating your"
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1175
		    " system's BIOS to a version\ncontaining this"
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1176
		    " microcode patch is HIGHLY recommended or erroneous"
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1177
		    " system\noperation may occur.\n");
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1178
	}
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1179
#endif
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1180
#if defined(OPTERON_ERRATUM_121)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1181
	if (opteron_erratum_121)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1182
		workaround_applied(121);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1183
#endif
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1184
#if defined(OPTERON_ERRATUM_122)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1185
	if (opteron_erratum_122)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1186
		workaround_applied(122);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1187
#endif
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1188
#if defined(OPTERON_ERRATUM_123)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1189
	if (opteron_erratum_123) {
359
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1190
		cmn_err(CE_WARN,
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1191
		    "BIOS microcode patch for AMD Athlon(tm) 64/Opteron(tm)"
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1192
		    " processor\nerratum 123 was not detected; updating your"
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1193
		    " system's BIOS to a version\ncontaining this"
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1194
		    " microcode patch is HIGHLY recommended or erroneous"
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1195
		    " system\noperation may occur.\n");
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1196
	}
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1197
#endif
359
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1198
#if defined(OPTERON_ERRATUM_131)
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1199
	if (opteron_erratum_131) {
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1200
		cmn_err(CE_WARN,
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1201
		    "BIOS microcode patch for AMD Athlon(tm) 64/Opteron(tm)"
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1202
		    " processor\nerratum 131 was not detected; updating your"
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1203
		    " system's BIOS to a version\ncontaining this"
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1204
		    " microcode patch is HIGHLY recommended or erroneous"
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1205
		    " system\noperation may occur.\n");
a88cb999e7ec 6288246 amd64 kernel needs to detect AMD Opteron erratum 131
kucharsk
parents: 302
diff changeset
  1206
	}
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1207
#endif
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1208
#if defined(OPTERON_WORKAROUND_6336786)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1209
	if (opteron_workaround_6336786)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1210
		workaround_applied(6336786);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1211
#endif
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1212
#if defined(OPTERON_WORKAROUND_6323525)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1213
	if (opteron_workaround_6323525)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1214
		workaround_applied(6323525);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1215
#endif
6691
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
  1216
#if defined(OPTERON_ERRATUM_298)
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
  1217
	if (opteron_erratum_298) {
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
  1218
		cmn_err(CE_WARN,
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
  1219
		    "BIOS microcode patch for AMD 64/Opteron(tm)"
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
  1220
		    " processor\nerratum 298 was not detected; updating your"
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
  1221
		    " system's BIOS to a version\ncontaining this"
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
  1222
		    " microcode patch is HIGHLY recommended or erroneous"
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
  1223
		    " system\noperation may occur.\n");
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
  1224
	}
f8848c7acc9e 6671130 Shanghai provides better TLB management for 1GB pages
kchow
parents: 6670
diff changeset
  1225
#endif
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1226
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1227
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1228
static cpuset_t procset;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1229
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1230
/*
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1231
 * Start a single cpu, assuming that the kernel context is available
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1232
 * to successfully start another cpu.
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1233
 *
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1234
 * (For example, real mode code is mapped into the right place
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1235
 * in memory and is ready to be run.)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1236
 */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1237
int
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1238
start_cpu(processorid_t who)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1239
{
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1240
	void *ctx;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1241
	cpu_t *cp;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1242
	int delays;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1243
	int error = 0;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1244
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1245
	ASSERT(who != 0);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1246
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1247
	/*
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1248
	 * Check if there's at least a Mbyte of kmem available
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1249
	 * before attempting to start the cpu.
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1250
	 */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1251
	if (kmem_avail() < 1024 * 1024) {
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1252
		/*
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1253
		 * Kick off a reap in case that helps us with
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1254
		 * later attempts ..
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1255
		 */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1256
		kmem_reap();
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1257
		return (ENOMEM);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1258
	}
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1259
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1260
	cp = mp_startup_init(who);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1261
	if ((ctx = mach_cpucontext_alloc(cp)) == NULL ||
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1262
	    (error = mach_cpu_start(cp, ctx)) != 0) {
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1263
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1264
		/*
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1265
		 * Something went wrong before we even started it
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1266
		 */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1267
		if (ctx)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1268
			cmn_err(CE_WARN,
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1269
			    "cpu%d: failed to start error %d",
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1270
			    cp->cpu_id, error);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1271
		else
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1272
			cmn_err(CE_WARN,
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1273
			    "cpu%d: failed to allocate context", cp->cpu_id);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1274
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1275
		if (ctx)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1276
			mach_cpucontext_free(cp, ctx, error);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1277
		else
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1278
			error = EAGAIN;		/* hmm. */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1279
		mp_startup_fini(cp, error);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1280
		return (error);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1281
	}
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1282
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1283
	for (delays = 0; !CPU_IN_SET(procset, who); delays++) {
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1284
		if (delays == 500) {
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1285
			/*
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1286
			 * After five seconds, things are probably looking
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1287
			 * a bit bleak - explain the hang.
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1288
			 */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1289
			cmn_err(CE_NOTE, "cpu%d: started, "
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1290
			    "but not running in the kernel yet", who);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1291
		} else if (delays > 2000) {
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1292
			/*
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1293
			 * We waited at least 20 seconds, bail ..
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1294
			 */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1295
			error = ETIMEDOUT;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1296
			cmn_err(CE_WARN, "cpu%d: timed out", who);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1297
			mach_cpucontext_free(cp, ctx, error);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1298
			mp_startup_fini(cp, error);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1299
			return (error);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1300
		}
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1301
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1302
		/*
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1303
		 * wait at least 10ms, then check again..
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1304
		 */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1305
		delay(USEC_TO_TICK_ROUNDUP(10000));
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1306
	}
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1307
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1308
	mach_cpucontext_free(cp, ctx, 0);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1309
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1310
#ifndef __xpv
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1311
	if (tsc_gethrtime_enable)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1312
		tsc_sync_master(who);
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1313
#endif
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1314
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1315
	if (dtrace_cpu_init != NULL) {
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1316
		/*
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1317
		 * DTrace CPU initialization expects cpu_lock to be held.
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1318
		 */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1319
		mutex_enter(&cpu_lock);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1320
		(*dtrace_cpu_init)(who);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1321
		mutex_exit(&cpu_lock);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1322
	}
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1323
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1324
	while (!CPU_IN_SET(cpu_ready_set, who))
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1325
		delay(1);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1326
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1327
	return (0);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1328
}
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1329
2006
11a559c797d5 5081104 NCPU has been outgrown on x86
andrei
parents: 1642
diff changeset
  1330
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1331
/*ARGSUSED*/
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1332
void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1333
start_other_cpus(int cprboot)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1334
{
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1335
	uint_t who;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1336
	uint_t skipped = 0;
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1337
	uint_t bootcpuid = 0;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1338
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1339
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1340
	 * Initialize our own cpu_info.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1341
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1342
	init_cpu_info(CPU);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1343
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1344
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1345
	 * Initialize our syscall handlers
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1346
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1347
	init_cpu_syscall(CPU);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1348
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1349
	/*
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1350
	 * Take the boot cpu out of the mp_cpus set because we know
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1351
	 * it's already running.  Add it to the cpu_ready_set for
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1352
	 * precisely the same reason.
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1353
	 */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1354
	CPUSET_DEL(mp_cpus, bootcpuid);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1355
	CPUSET_ADD(cpu_ready_set, bootcpuid);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1356
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1357
	/*
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1358
	 * if only 1 cpu or not using MP, skip the rest of this
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1359
	 */
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1360
	if (CPUSET_ISNULL(mp_cpus) || use_mp == 0) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1361
		if (use_mp == 0)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1362
			cmn_err(CE_CONT, "?***** Not in MP mode\n");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1363
		goto done;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1364
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1365
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1366
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1367
	 * perform such initialization as is needed
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1368
	 * to be able to take CPUs on- and off-line.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1369
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1370
	cpu_pause_init();
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1371
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1372
	xc_init();		/* initialize processor crosscalls */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1373
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1374
	if (mach_cpucontext_init() != 0)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1375
		goto done;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1376
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1377
	flushes_require_xcalls = 1;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1378
2575
a95d80de4e01 6436283 anonymous tracing is broken on MP systems
nf202958
parents: 2519
diff changeset
  1379
	/*
a95d80de4e01 6436283 anonymous tracing is broken on MP systems
nf202958
parents: 2519
diff changeset
  1380
	 * We lock our affinity to the master CPU to ensure that all slave CPUs
a95d80de4e01 6436283 anonymous tracing is broken on MP systems
nf202958
parents: 2519
diff changeset
  1381
	 * do their TSC syncs with the same CPU.
a95d80de4e01 6436283 anonymous tracing is broken on MP systems
nf202958
parents: 2519
diff changeset
  1382
	 */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1383
	affinity_set(CPU_CURRENT);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1384
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1385
	for (who = 0; who < NCPU; who++) {
2575
a95d80de4e01 6436283 anonymous tracing is broken on MP systems
nf202958
parents: 2519
diff changeset
  1386
2006
11a559c797d5 5081104 NCPU has been outgrown on x86
andrei
parents: 1642
diff changeset
  1387
		if (!CPU_IN_SET(mp_cpus, who))
11a559c797d5 5081104 NCPU has been outgrown on x86
andrei
parents: 1642
diff changeset
  1388
			continue;
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1389
		ASSERT(who != bootcpuid);
2006
11a559c797d5 5081104 NCPU has been outgrown on x86
andrei
parents: 1642
diff changeset
  1390
		if (ncpus >= max_ncpus) {
11a559c797d5 5081104 NCPU has been outgrown on x86
andrei
parents: 1642
diff changeset
  1391
			skipped = who;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1392
			continue;
2006
11a559c797d5 5081104 NCPU has been outgrown on x86
andrei
parents: 1642
diff changeset
  1393
		}
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1394
		if (start_cpu(who) != 0)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1395
			CPUSET_DEL(mp_cpus, who);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1396
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1397
4581
b6104e41b06c PSARC/2007/349 Intel Microcode Update Support
sherrym
parents: 4481
diff changeset
  1398
	/* Free the space allocated to hold the microcode file */
7605
b4a19682e632 6747590 microcode update support for AMD
Mark Johnson <Mark.Johnson@Sun.COM>
parents: 7532
diff changeset
  1399
	ucode_cleanup();
4581
b6104e41b06c PSARC/2007/349 Intel Microcode Update Support
sherrym
parents: 4481
diff changeset
  1400
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1401
	affinity_clear();
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1402
2006
11a559c797d5 5081104 NCPU has been outgrown on x86
andrei
parents: 1642
diff changeset
  1403
	if (skipped) {
11a559c797d5 5081104 NCPU has been outgrown on x86
andrei
parents: 1642
diff changeset
  1404
		cmn_err(CE_NOTE,
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1405
		    "System detected %d cpus, but "
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1406
		    "only %d cpu(s) were enabled during boot.",
2006
11a559c797d5 5081104 NCPU has been outgrown on x86
andrei
parents: 1642
diff changeset
  1407
		    skipped + 1, ncpus);
11a559c797d5 5081104 NCPU has been outgrown on x86
andrei
parents: 1642
diff changeset
  1408
		cmn_err(CE_NOTE,
11a559c797d5 5081104 NCPU has been outgrown on x86
andrei
parents: 1642
diff changeset
  1409
		    "Use \"boot-ncpus\" parameter to enable more CPU(s). "
11a559c797d5 5081104 NCPU has been outgrown on x86
andrei
parents: 1642
diff changeset
  1410
		    "See eeprom(1M).");
11a559c797d5 5081104 NCPU has been outgrown on x86
andrei
parents: 1642
diff changeset
  1411
	}
11a559c797d5 5081104 NCPU has been outgrown on x86
andrei
parents: 1642
diff changeset
  1412
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1413
done:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1414
	workaround_errata_end();
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1415
	mach_cpucontext_fini();
1642
f7086dc70948 6398359 do not enable amd dram scrubber if local node has no memory
gavinm
parents: 1626
diff changeset
  1416
f7086dc70948 6398359 do not enable amd dram scrubber if local node has no memory
gavinm
parents: 1626
diff changeset
  1417
	cmi_post_mpstartup();
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1418
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1419
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1420
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1421
 * Dummy functions - no i86pc platforms support dynamic cpu allocation.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1422
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1423
/*ARGSUSED*/
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1424
int
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1425
mp_cpu_configure(int cpuid)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1426
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1427
	return (ENOTSUP);		/* not supported */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1428
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1429
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1430
/*ARGSUSED*/
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1431
int
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1432
mp_cpu_unconfigure(int cpuid)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1433
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1434
	return (ENOTSUP);		/* not supported */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1435
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1436
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1437
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1438
 * Startup function for 'other' CPUs (besides boot cpu).
2985
78b075f897aa 6480953 system seems hung,invisible panic, on debug kernel, never gets to mp_startup
dmick
parents: 2575
diff changeset
  1439
 * Called from real_mode_start.
1251
beb2ccc7537c 6305935 Attaching driver to CPU triggers ASSERT on MP systems on reboot
kchow
parents: 938
diff changeset
  1440
 *
beb2ccc7537c 6305935 Attaching driver to CPU triggers ASSERT on MP systems on reboot
kchow
parents: 938
diff changeset
  1441
 * WARNING: until CPU_READY is set, mp_startup and routines called by
beb2ccc7537c 6305935 Attaching driver to CPU triggers ASSERT on MP systems on reboot
kchow
parents: 938
diff changeset
  1442
 * mp_startup should not call routines (e.g. kmem_free) that could call
beb2ccc7537c 6305935 Attaching driver to CPU triggers ASSERT on MP systems on reboot
kchow
parents: 938
diff changeset
  1443
 * hat_unload which requires CPU_READY to be set.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1444
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1445
void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1446
mp_startup(void)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1447
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1448
	struct cpu *cp = CPU;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1449
	uint_t new_x86_feature;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1450
2985
78b075f897aa 6480953 system seems hung,invisible panic, on debug kernel, never gets to mp_startup
dmick
parents: 2575
diff changeset
  1451
	/*
3021
900097ae20cf 6446729 "cpu 1 failed to start" when TSC counters are not in sync
dmick
parents: 2985
diff changeset
  1452
	 * We need to get TSC on this proc synced (i.e., any delta
900097ae20cf 6446729 "cpu 1 failed to start" when TSC counters are not in sync
dmick
parents: 2985
diff changeset
  1453
	 * from cpu0 accounted for) as soon as we can, because many
900097ae20cf 6446729 "cpu 1 failed to start" when TSC counters are not in sync
dmick
parents: 2985
diff changeset
  1454
	 * many things use gethrtime/pc_gethrestime, including
900097ae20cf 6446729 "cpu 1 failed to start" when TSC counters are not in sync
dmick
parents: 2985
diff changeset
  1455
	 * interrupts, cmn_err, etc.
900097ae20cf 6446729 "cpu 1 failed to start" when TSC counters are not in sync
dmick
parents: 2985
diff changeset
  1456
	 */
900097ae20cf 6446729 "cpu 1 failed to start" when TSC counters are not in sync
dmick
parents: 2985
diff changeset
  1457
900097ae20cf 6446729 "cpu 1 failed to start" when TSC counters are not in sync
dmick
parents: 2985
diff changeset
  1458
	/* Let cpu0 continue into tsc_sync_master() */
900097ae20cf 6446729 "cpu 1 failed to start" when TSC counters are not in sync
dmick
parents: 2985
diff changeset
  1459
	CPUSET_ATOMIC_ADD(procset, cp->cpu_id);
900097ae20cf 6446729 "cpu 1 failed to start" when TSC counters are not in sync
dmick
parents: 2985
diff changeset
  1460
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1461
#ifndef __xpv
3021
900097ae20cf 6446729 "cpu 1 failed to start" when TSC counters are not in sync
dmick
parents: 2985
diff changeset
  1462
	if (tsc_gethrtime_enable)
900097ae20cf 6446729 "cpu 1 failed to start" when TSC counters are not in sync
dmick
parents: 2985
diff changeset
  1463
		tsc_sync_slave();
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1464
#endif
3021
900097ae20cf 6446729 "cpu 1 failed to start" when TSC counters are not in sync
dmick
parents: 2985
diff changeset
  1465
900097ae20cf 6446729 "cpu 1 failed to start" when TSC counters are not in sync
dmick
parents: 2985
diff changeset
  1466
	/*
2985
78b075f897aa 6480953 system seems hung,invisible panic, on debug kernel, never gets to mp_startup
dmick
parents: 2575
diff changeset
  1467
	 * Once this was done from assembly, but it's safer here; if
78b075f897aa 6480953 system seems hung,invisible panic, on debug kernel, never gets to mp_startup
dmick
parents: 2575
diff changeset
  1468
	 * it blocks, we need to be able to swtch() to and from, and
78b075f897aa 6480953 system seems hung,invisible panic, on debug kernel, never gets to mp_startup
dmick
parents: 2575
diff changeset
  1469
	 * since we get here by calling t_pc, we need to do that call
78b075f897aa 6480953 system seems hung,invisible panic, on debug kernel, never gets to mp_startup
dmick
parents: 2575
diff changeset
  1470
	 * before swtch() overwrites it.
78b075f897aa 6480953 system seems hung,invisible panic, on debug kernel, never gets to mp_startup
dmick
parents: 2575
diff changeset
  1471
	 */
78b075f897aa 6480953 system seems hung,invisible panic, on debug kernel, never gets to mp_startup
dmick
parents: 2575
diff changeset
  1472
	(void) (*ap_mlsetup)();
78b075f897aa 6480953 system seems hung,invisible panic, on debug kernel, never gets to mp_startup
dmick
parents: 2575
diff changeset
  1473
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1474
	new_x86_feature = cpuid_pass1(cp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1475
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1476
#ifndef __xpv
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1477
	/*
5159
6cdd421a2458 6590353 ancient mtrr crud in i86pc/os/startup.c must die
johnlev
parents: 5084
diff changeset
  1478
	 * Program this cpu's PAT
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1479
	 */
5159
6cdd421a2458 6590353 ancient mtrr crud in i86pc/os/startup.c must die
johnlev
parents: 5084
diff changeset
  1480
	if (x86_feature & X86_PAT)
6cdd421a2458 6590353 ancient mtrr crud in i86pc/os/startup.c must die
johnlev
parents: 5084
diff changeset
  1481
		pat_sync();
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1482
#endif
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1483
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1484
	/*
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1485
	 * Set up TSC_AUX to contain the cpuid for this processor
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1486
	 * for the rdtscp instruction.
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1487
	 */
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1488
	if (x86_feature & X86_TSCP)
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1489
		(void) wrmsr(MSR_AMD_TSCAUX, cp->cpu_id);
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1490
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1491
	/*
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1492
	 * Initialize this CPU's syscall handlers
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1493
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1494
	init_cpu_syscall(cp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1495
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1496
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1497
	 * Enable interrupts with spl set to LOCK_LEVEL. LOCK_LEVEL is the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1498
	 * highest level at which a routine is permitted to block on
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1499
	 * an adaptive mutex (allows for cpu poke interrupt in case
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1500
	 * the cpu is blocked on a mutex and halts). Setting LOCK_LEVEL blocks
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1501
	 * device interrupts that may end up in the hat layer issuing cross
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1502
	 * calls before CPU_READY is set.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1503
	 */
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1504
	splx(ipltospl(LOCK_LEVEL));
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1505
	sti();
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1506
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1507
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1508
	 * Do a sanity check to make sure this new CPU is a sane thing
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1509
	 * to add to the collection of processors running this system.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1510
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1511
	 * XXX	Clearly this needs to get more sophisticated, if x86
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1512
	 * systems start to get built out of heterogenous CPUs; as is
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1513
	 * likely to happen once the number of processors in a configuration
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1514
	 * gets large enough.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1515
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1516
	if ((x86_feature & new_x86_feature) != x86_feature) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1517
		cmn_err(CE_CONT, "?cpu%d: %b\n",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1518
		    cp->cpu_id, new_x86_feature, FMT_X86_FEATURE);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1519
		cmn_err(CE_WARN, "cpu%d feature mismatch", cp->cpu_id);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1520
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1521
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1522
	/*
4481
2bb321aaf3c3 6495392 use monitor/mwait for halting idle CPUs where supported
bholler
parents: 3446
diff changeset
  1523
	 * We do not support cpus with mixed monitor/mwait support if the
2bb321aaf3c3 6495392 use monitor/mwait for halting idle CPUs where supported
bholler
parents: 3446
diff changeset
  1524
	 * boot cpu supports monitor/mwait.
2bb321aaf3c3 6495392 use monitor/mwait for halting idle CPUs where supported
bholler
parents: 3446
diff changeset
  1525
	 */
2bb321aaf3c3 6495392 use monitor/mwait for halting idle CPUs where supported
bholler
parents: 3446
diff changeset
  1526
	if ((x86_feature & ~new_x86_feature) & X86_MWAIT)
2bb321aaf3c3 6495392 use monitor/mwait for halting idle CPUs where supported
bholler
parents: 3446
diff changeset
  1527
		panic("unsupported mixed cpu monitor/mwait support detected");
2bb321aaf3c3 6495392 use monitor/mwait for halting idle CPUs where supported
bholler
parents: 3446
diff changeset
  1528
2bb321aaf3c3 6495392 use monitor/mwait for halting idle CPUs where supported
bholler
parents: 3446
diff changeset
  1529
	/*
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1530
	 * We could be more sophisticated here, and just mark the CPU
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1531
	 * as "faulted" but at this point we'll opt for the easier
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1532
	 * answer of dieing horribly.  Provided the boot cpu is ok,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1533
	 * the system can be recovered by booting with use_mp set to zero.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1534
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1535
	if (workaround_errata(cp) != 0)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1536
		panic("critical workaround(s) missing for cpu%d", cp->cpu_id);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1537
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1538
	cpuid_pass2(cp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1539
	cpuid_pass3(cp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1540
	(void) cpuid_pass4(cp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1541
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1542
	init_cpu_info(cp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1543
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1544
	mutex_enter(&cpu_lock);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1545
	/*
3434
5142e1d7d0bc 6461311 multi-level CMT scheduling optimizations
esaxe
parents: 3029
diff changeset
  1546
	 * Processor group initialization for this CPU is dependent on the
5142e1d7d0bc 6461311 multi-level CMT scheduling optimizations
esaxe
parents: 3029
diff changeset
  1547
	 * cpuid probing, which must be done in the context of the current
5142e1d7d0bc 6461311 multi-level CMT scheduling optimizations
esaxe
parents: 3029
diff changeset
  1548
	 * CPU.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1549
	 */
3434
5142e1d7d0bc 6461311 multi-level CMT scheduling optimizations
esaxe
parents: 3029
diff changeset
  1550
	pghw_physid_create(cp);
5142e1d7d0bc 6461311 multi-level CMT scheduling optimizations
esaxe
parents: 3029
diff changeset
  1551
	pg_cpu_init(cp);
5142e1d7d0bc 6461311 multi-level CMT scheduling optimizations
esaxe
parents: 3029
diff changeset
  1552
	pg_cmt_cpu_startup(cp);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1553
6749
22c537726e3e 6657646 diskless mp system hangs during mp_startup(), with device interrupts masked
sherrym
parents: 6691
diff changeset
  1554
	cp->cpu_flags |= CPU_RUNNING | CPU_READY | CPU_EXISTS;
2575
a95d80de4e01 6436283 anonymous tracing is broken on MP systems
nf202958
parents: 2519
diff changeset
  1555
a95d80de4e01 6436283 anonymous tracing is broken on MP systems
nf202958
parents: 2519
diff changeset
  1556
	if (dtrace_cpu_init != NULL) {
a95d80de4e01 6436283 anonymous tracing is broken on MP systems
nf202958
parents: 2519
diff changeset
  1557
		(*dtrace_cpu_init)(cp->cpu_id);
a95d80de4e01 6436283 anonymous tracing is broken on MP systems
nf202958
parents: 2519
diff changeset
  1558
	}
a95d80de4e01 6436283 anonymous tracing is broken on MP systems
nf202958
parents: 2519
diff changeset
  1559
4581
b6104e41b06c PSARC/2007/349 Intel Microcode Update Support
sherrym
parents: 4481
diff changeset
  1560
	/*
b6104e41b06c PSARC/2007/349 Intel Microcode Update Support
sherrym
parents: 4481
diff changeset
  1561
	 * Fill out cpu_ucode_info.  Update microcode if necessary.
b6104e41b06c PSARC/2007/349 Intel Microcode Update Support
sherrym
parents: 4481
diff changeset
  1562
	 */
b6104e41b06c PSARC/2007/349 Intel Microcode Update Support
sherrym
parents: 4481
diff changeset
  1563
	ucode_check(cp);
b6104e41b06c PSARC/2007/349 Intel Microcode Update Support
sherrym
parents: 4481
diff changeset
  1564
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1565
	mutex_exit(&cpu_lock);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1566
3029
e8e4c69d4f79 6488621 mp_startup must enable kernel preemption as soon as CPUs are ready
sethg
parents: 3021
diff changeset
  1567
	/*
e8e4c69d4f79 6488621 mp_startup must enable kernel preemption as soon as CPUs are ready
sethg
parents: 3021
diff changeset
  1568
	 * Enable preemption here so that contention for any locks acquired
e8e4c69d4f79 6488621 mp_startup must enable kernel preemption as soon as CPUs are ready
sethg
parents: 3021
diff changeset
  1569
	 * later in mp_startup may be preempted if the thread owning those
e8e4c69d4f79 6488621 mp_startup must enable kernel preemption as soon as CPUs are ready
sethg
parents: 3021
diff changeset
  1570
	 * locks is continously executing on other CPUs (for example, this
e8e4c69d4f79 6488621 mp_startup must enable kernel preemption as soon as CPUs are ready
sethg
parents: 3021
diff changeset
  1571
	 * CPU must be preemptible to allow other CPUs to pause it during their
e8e4c69d4f79 6488621 mp_startup must enable kernel preemption as soon as CPUs are ready
sethg
parents: 3021
diff changeset
  1572
	 * startup phases).  It's safe to enable preemption here because the
e8e4c69d4f79 6488621 mp_startup must enable kernel preemption as soon as CPUs are ready
sethg
parents: 3021
diff changeset
  1573
	 * CPU state is pretty-much fully constructed.
e8e4c69d4f79 6488621 mp_startup must enable kernel preemption as soon as CPUs are ready
sethg
parents: 3021
diff changeset
  1574
	 */
e8e4c69d4f79 6488621 mp_startup must enable kernel preemption as soon as CPUs are ready
sethg
parents: 3021
diff changeset
  1575
	curthread->t_preempt = 0;
e8e4c69d4f79 6488621 mp_startup must enable kernel preemption as soon as CPUs are ready
sethg
parents: 3021
diff changeset
  1576
1482
dd0dbac7d2af 6381715 cpu_base_spl must be set before mp_startup to prevent device interrupts from inducing panics
sethg
parents: 1455
diff changeset
  1577
	/* The base spl should still be at LOCK LEVEL here */
dd0dbac7d2af 6381715 cpu_base_spl must be set before mp_startup to prevent device interrupts from inducing panics
sethg
parents: 1455
diff changeset
  1578
	ASSERT(cp->cpu_base_spl == ipltospl(LOCK_LEVEL));
dd0dbac7d2af 6381715 cpu_base_spl must be set before mp_startup to prevent device interrupts from inducing panics
sethg
parents: 1455
diff changeset
  1579
	set_base_spl();		/* Restore the spl to its proper value */
dd0dbac7d2af 6381715 cpu_base_spl must be set before mp_startup to prevent device interrupts from inducing panics
sethg
parents: 1455
diff changeset
  1580
6749
22c537726e3e 6657646 diskless mp system hangs during mp_startup(), with device interrupts masked
sherrym
parents: 6691
diff changeset
  1581
	/* Enable interrupts */
22c537726e3e 6657646 diskless mp system hangs during mp_startup(), with device interrupts masked
sherrym
parents: 6691
diff changeset
  1582
	(void) spl0();
22c537726e3e 6657646 diskless mp system hangs during mp_startup(), with device interrupts masked
sherrym
parents: 6691
diff changeset
  1583
	mutex_enter(&cpu_lock);
22c537726e3e 6657646 diskless mp system hangs during mp_startup(), with device interrupts masked
sherrym
parents: 6691
diff changeset
  1584
	cpu_enable_intr(cp);
22c537726e3e 6657646 diskless mp system hangs during mp_startup(), with device interrupts masked
sherrym
parents: 6691
diff changeset
  1585
	cpu_add_active(cp);
22c537726e3e 6657646 diskless mp system hangs during mp_startup(), with device interrupts masked
sherrym
parents: 6691
diff changeset
  1586
	mutex_exit(&cpu_lock);
22c537726e3e 6657646 diskless mp system hangs during mp_startup(), with device interrupts masked
sherrym
parents: 6691
diff changeset
  1587
22c537726e3e 6657646 diskless mp system hangs during mp_startup(), with device interrupts masked
sherrym
parents: 6691
diff changeset
  1588
	add_cpunode2devtree(cp->cpu_id, cp->cpu_m.mcpu_cpi);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1589
5254
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1590
#ifndef __xpv
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1591
	{
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1592
		/*
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1593
		 * Set up the CPU module for this CPU.  This can't be done
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1594
		 * before this CPU is made CPU_READY, because we may (in
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1595
		 * heterogeneous systems) need to go load another CPU module.
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1596
		 * The act of attempting to load a module may trigger a
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1597
		 * cross-call, which will ASSERT unless this cpu is CPU_READY.
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1598
		 */
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1599
		cmi_hdl_t hdl;
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents: 1389
diff changeset
  1600
5254
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1601
		if ((hdl = cmi_init(CMI_HDL_NATIVE, cmi_ntv_hwchipid(CPU),
7532
bb6372f778bb PSARC 2008/569 FMA Topology & Retire Agent Refinements
Cheng Sean Ye <Sean.Ye@Sun.COM>
parents: 7349
diff changeset
  1602
		    cmi_ntv_hwcoreid(CPU), cmi_ntv_hwstrandid(CPU))) != NULL) {
5254
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1603
			if (x86_feature & X86_MCA)
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1604
				cmi_mca_init(hdl);
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1605
		}
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1606
	}
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1607
#endif /* __xpv */
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents: 1389
diff changeset
  1608
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1609
	if (boothowto & RB_DEBUG)
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1610
		kdi_cpu_init();
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1611
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1612
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1613
	 * Setting the bit in cpu_ready_set must be the last operation in
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1614
	 * processor initialization; the boot CPU will continue to boot once
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1615
	 * it sees this bit set for all active CPUs.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1616
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1617
	CPUSET_ATOMIC_ADD(cpu_ready_set, cp->cpu_id);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1618
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1619
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1620
	 * Because mp_startup() gets fired off after init() starts, we
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1621
	 * can't use the '?' trick to do 'boot -v' printing - so we
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1622
	 * always direct the 'cpu .. online' messages to the log.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1623
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1624
	cmn_err(CE_CONT, "!cpu%d initialization complete - online\n",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1625
	    cp->cpu_id);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1626
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1627
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1628
	 * Now we are done with the startup thread, so free it up.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1629
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1630
	thread_exit();
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1631
	panic("mp_startup: cannot return");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1632
	/*NOTREACHED*/
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1633
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1634
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1635
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1636
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1637
 * Start CPU on user request.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1638
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1639
/* ARGSUSED */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1640
int
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1641
mp_cpu_start(struct cpu *cp)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1642
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1643
	ASSERT(MUTEX_HELD(&cpu_lock));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1644
	return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1645
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1646
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1647
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1648
 * Stop CPU on user request.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1649
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1650
/* ARGSUSED */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1651
int
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1652
mp_cpu_stop(struct cpu *cp)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1653
{
1389
8a6ef7ca5644 6342823 Unable to offline CPU 0 on x86 systems
dmick
parents: 1251
diff changeset
  1654
	extern int cbe_psm_timer_mode;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1655
	ASSERT(MUTEX_HELD(&cpu_lock));
1389
8a6ef7ca5644 6342823 Unable to offline CPU 0 on x86 systems
dmick
parents: 1251
diff changeset
  1656
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1657
#ifdef __xpv
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1658
	/*
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1659
	 * We can't offline vcpu0.
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1660
	 */
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1661
	if (cp->cpu_id == 0)
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1662
		return (EBUSY);
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1663
#endif
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1664
1389
8a6ef7ca5644 6342823 Unable to offline CPU 0 on x86 systems
dmick
parents: 1251
diff changeset
  1665
	/*
8a6ef7ca5644 6342823 Unable to offline CPU 0 on x86 systems
dmick
parents: 1251
diff changeset
  1666
	 * If TIMER_PERIODIC mode is used, CPU0 is the one running it;
8a6ef7ca5644 6342823 Unable to offline CPU 0 on x86 systems
dmick
parents: 1251
diff changeset
  1667
	 * can't stop it.  (This is true only for machines with no TSC.)
8a6ef7ca5644 6342823 Unable to offline CPU 0 on x86 systems
dmick
parents: 1251
diff changeset
  1668
	 */
8a6ef7ca5644 6342823 Unable to offline CPU 0 on x86 systems
dmick
parents: 1251
diff changeset
  1669
8a6ef7ca5644 6342823 Unable to offline CPU 0 on x86 systems
dmick
parents: 1251
diff changeset
  1670
	if ((cbe_psm_timer_mode == TIMER_PERIODIC) && (cp->cpu_id == 0))
5084
7d838c5c0eed PSARC 2006/260 Solaris on Xen
johnlev
parents: 5045
diff changeset
  1671
		return (EBUSY);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1672
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1673
	return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1674
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1675
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1676
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1677
 * Take the specified CPU out of participation in interrupts.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1678
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1679
int
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1680
cpu_disable_intr(struct cpu *cp)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1681
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1682
	if (psm_disable_intr(cp->cpu_id) != DDI_SUCCESS)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1683
		return (EBUSY);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1684
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1685
	cp->cpu_flags &= ~CPU_ENABLE;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1686
	return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1687
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1688
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1689
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1690
 * Allow the specified CPU to participate in interrupts.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1691
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1692
void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1693
cpu_enable_intr(struct cpu *cp)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1694
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1695
	ASSERT(MUTEX_HELD(&cpu_lock));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1696
	cp->cpu_flags |= CPU_ENABLE;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1697
	psm_enable_intr(cp->cpu_id);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1698
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1699
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1700
5254
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1701
/*ARGSUSED*/
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1702
void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1703
mp_cpu_faulted_enter(struct cpu *cp)
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents: 1389
diff changeset
  1704
{
5254
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1705
#ifndef __xpv
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1706
	cmi_hdl_t hdl = cmi_hdl_lookup(CMI_HDL_NATIVE, cmi_ntv_hwchipid(cp),
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1707
	    cmi_ntv_hwcoreid(cp), cmi_ntv_hwstrandid(cp));
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1708
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1709
	if (hdl != NULL) {
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1710
		cmi_faulted_enter(hdl);
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1711
		cmi_hdl_rele(hdl);
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1712
	}
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1713
#endif
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents: 1389
diff changeset
  1714
}
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1715
5254
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1716
/*ARGSUSED*/
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1717
void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1718
mp_cpu_faulted_exit(struct cpu *cp)
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents: 1389
diff changeset
  1719
{
5254
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1720
#ifndef __xpv
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1721
	cmi_hdl_t hdl = cmi_hdl_lookup(CMI_HDL_NATIVE, cmi_ntv_hwchipid(cp),
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1722
	    cmi_ntv_hwcoreid(cp), cmi_ntv_hwstrandid(cp));
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1723
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1724
	if (hdl != NULL) {
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1725
		cmi_faulted_exit(hdl);
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1726
		cmi_hdl_rele(hdl);
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1727
	}
38162db71c7d PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents: 5159
diff changeset
  1728
#endif
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents: 1389
diff changeset
  1729
}
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1730
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1731
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1732
 * The following two routines are used as context operators on threads belonging
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1733
 * to processes with a private LDT (see sysi86).  Due to the rarity of such
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1734
 * processes, these routines are currently written for best code readability and
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1735
 * organization rather than speed.  We could avoid checking x86_feature at every
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1736
 * context switch by installing different context ops, depending on the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1737
 * x86_feature flags, at LDT creation time -- one for each combination of fast
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1738
 * syscall feature flags.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1739
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1740
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1741
/*ARGSUSED*/
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1742
void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1743
cpu_fast_syscall_disable(void *arg)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1744
{
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1745
	if ((x86_feature & (X86_MSR | X86_SEP)) == (X86_MSR | X86_SEP))
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1746
		cpu_sep_disable();
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1747
	if ((x86_feature & (X86_MSR | X86_ASYSC)) == (X86_MSR | X86_ASYSC))
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1748
		cpu_asysc_disable();
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1749
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1750
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1751
/*ARGSUSED*/
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1752
void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1753
cpu_fast_syscall_enable(void *arg)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1754
{
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1755
	if ((x86_feature & (X86_MSR | X86_SEP)) == (X86_MSR | X86_SEP))
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1756
		cpu_sep_enable();
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1757
	if ((x86_feature & (X86_MSR | X86_ASYSC)) == (X86_MSR | X86_ASYSC))
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1758
		cpu_asysc_enable();
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1759
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1760
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1761
static void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1762
cpu_sep_enable(void)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1763
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1764
	ASSERT(x86_feature & X86_SEP);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1765
	ASSERT(curthread->t_preempt || getpil() >= LOCK_LEVEL);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1766
770
0eda482eb80f 6311933 rdmsr/wrmsr do not need to set/pass values via memory pointers
kucharsk
parents: 414
diff changeset
  1767
	wrmsr(MSR_INTC_SEP_CS, (uint64_t)(uintptr_t)KCS_SEL);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1768
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1769
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1770
static void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1771
cpu_sep_disable(void)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1772
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1773
	ASSERT(x86_feature & X86_SEP);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1774
	ASSERT(curthread->t_preempt || getpil() >= LOCK_LEVEL);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1775
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1776
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1777
	 * Setting the SYSENTER_CS_MSR register to 0 causes software executing
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1778
	 * the sysenter or sysexit instruction to trigger a #gp fault.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1779
	 */
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 3434
diff changeset
  1780
	wrmsr(MSR_INTC_SEP_CS, 0);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1781
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1782
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1783
static void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1784
cpu_asysc_enable(void)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1785
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1786
	ASSERT(x86_feature & X86_ASYSC);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1787
	ASSERT(curthread->t_preempt || getpil() >= LOCK_LEVEL);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1788
770
0eda482eb80f 6311933 rdmsr/wrmsr do not need to set/pass values via memory pointers
kucharsk
parents: 414
diff changeset
  1789
	wrmsr(MSR_AMD_EFER, rdmsr(MSR_AMD_EFER) |
0eda482eb80f 6311933 rdmsr/wrmsr do not need to set/pass values via memory pointers
kucharsk
parents: 414
diff changeset
  1790
	    (uint64_t)(uintptr_t)AMD_EFER_SCE);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1791
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1792
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1793
static void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1794
cpu_asysc_disable(void)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1795
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1796
	ASSERT(x86_feature & X86_ASYSC);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1797
	ASSERT(curthread->t_preempt || getpil() >= LOCK_LEVEL);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1798
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1799
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1800
	 * Turn off the SCE (syscall enable) bit in the EFER register. Software
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1801
	 * executing syscall or sysret with this bit off will incur a #ud trap.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1802
	 */
770
0eda482eb80f 6311933 rdmsr/wrmsr do not need to set/pass values via memory pointers
kucharsk
parents: 414
diff changeset
  1803
	wrmsr(MSR_AMD_EFER, rdmsr(MSR_AMD_EFER) &
0eda482eb80f 6311933 rdmsr/wrmsr do not need to set/pass values via memory pointers
kucharsk
parents: 414
diff changeset
  1804
	    ~((uint64_t)(uintptr_t)AMD_EFER_SCE));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1805
}