mlsetup.c revision 32842aabdc7c6f8f0c6140a256cf42cf5404fefb
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2012 Gary Mills
*
* Copyright (c) 2011 by Delphix. All rights reserved.
*/
/*
* Copyright (c) 2010, Intel Corporation.
* All rights reserved.
*/
#include <sys/sysmacros.h>
#include <sys/x86_archext.h>
#include <sys/privregs.h>
#include <sys/machsystm.h>
#include <sys/bootconf.h>
#include <sys/boot_console.h>
#include <sys/kdi_machimpl.h>
#include <sys/archsystm.h>
#include <sys/pci_cfgspace.h>
#ifdef __xpv
#include <sys/hypervisor.h>
#else
#include <sys/xpv_support.h>
#endif
/*
* some globals for patching the result of cpuid
* to solve problems w/ creative cpu vendors
*/
extern uint32_t cpuid_feature_ecx_include;
extern uint32_t cpuid_feature_ecx_exclude;
extern uint32_t cpuid_feature_edx_include;
extern uint32_t cpuid_feature_edx_exclude;
/*
* Set console mode
*/
static void
{
}
/*
* Setup routine called right before main(). Interposing this function
* before main() allows us to call it in a machine-independent fashion.
*/
void
{
extern struct classfuncs sys_classfuncs;
extern char t0stack[];
extern int post_fastreboot;
extern uint64_t plat_dr_options;
/*
* initialize cpu_self
*/
#if defined(__xpv)
/*
* Point at the hypervisor's virtual cpu structure
*/
#endif
/*
* check if we've got special bits to clear or set
* when checking cpu features
*/
else
else
else
else
/*
* Initialize idt0, gdt0, ldt0_default, ktss0 and dftss.
*/
/*
* lgrp_init() and possibly cpuid_pass1() need PCI config
* space access
*/
#if defined(__xpv)
if (DOMAIN_IS_INITDOMAIN(xen_info))
#else
/*
* Initialize the platform type from CPU 0 to ensure that
* determine_platform() is only ever called once.
*/
#endif
/*
* The first lightweight pass (pass0) through the cpuid data
* was done in locore before mlsetup was called. Do the next
* pass in C code.
*
* The x86_featureset is initialized here based on the capabilities
* of the boot CPU. Note that if we choose to support CPUs that have
* different feature sets (at which point we would almost certainly
* want to set the feature bits to correspond to the feature
* minimum) this value may be altered.
*/
#if !defined(__xpv)
if ((get_hwenv() & HW_XEN_HVM) != 0)
xen_hvm_init();
/*
* Before we do anything with the TSCs, we need to work around
* Intel erratum BT81. On some CPUs, warm reset does not
* clear the TSC. If we are on such a CPU, we will clear TSC ourselves
* here. Other CPUs will clear it when we boot them later, and the
* resulting skew will be handled by tsc_sync_master()/_slave();
* note that such skew already exists and has to be handled anyway.
*
* We do this only on metal. This same problem can occur with a
* hypervisor that does not happen to virtualise a TSC that starts from
* zero, regardless of CPU type; however, we do not expect hypervisors
* that do not virtualise TSC that way to handle writes to TSC
* correctly, either.
*/
}
/*
* Patch the tsc_read routine with appropriate set of instructions,
* depending on the processor family and architecure, to read the
* time-stamp counter while ensuring no out-of-order execution.
* Patch it while the kernel text is still writable.
*
* Note: tsc_read is not patched for intel processors whose family
* is >6 and for amd whose family >f (in case they don't support rdtscp
* instruction, unlikely). By default tsc_read will use cpuid for
* serialization in such cases. The following code needs to be
* revisited if intel processors of family >= f retains the
* instruction serialization nature of mfence instruction.
* Note: tsc_read is not patched for x86 processors which do
* not support "mfence". By default tsc_read will use cpuid for
* serialization in such cases.
*
* The Xen hypervisor does not correctly report whether rdtscp is
* supported or not, so we must assume that it is not.
*/
if ((get_hwenv() & HW_XEN_HVM) == 0 &&
#endif /* !__xpv */
/*
* Some i386 processors do not implement the rdtsc instruction,
* or at least they do not implement it correctly. Patch them to
* return 0.
*/
#endif /* __i386 && !__xpv */
#endif /* __amd64 && !__xpv */
#if !defined(__xpv)
/* XXPV what, if anything, should be dorked with here under xen? */
/*
* While we're thinking about the TSC, let's set up %cr4 so that
* userland can issue rdtsc, and initialize the TSC_AUX value
* (the cpuid) for the rdtscp instruction on appropriately
* capable hardware.
*/
(void) wrmsr(MSR_AMD_TSCAUX, 0);
#endif /* __xpv */
/*
* initialize t0
*/
p0.p_stkpageszc = 0;
p0.p_brkpageszc = 0;
/*
* The kernel doesn't use LDTs unless a process explicitly requests one.
*/
/*
*/
/*
* Initialize lists of available and active CPUs.
*/
/*
* Now that we have taken over the GDT, IDT and have initialized
* active CPU list it's time to inform kmdb if present.
*/
kdi_idt_sync();
/*
* Explicitly set console to text mode (0x3) if this is a boot
* post Fast Reboot, and the console is set to CONS_SCREEN_TEXT.
*/
set_console_mode(0x3);
/*
* If requested (boot -d) drop into kmdb.
*
* This must be done after cpu_list_init() on the 64-bit kernel
* since taking a trap requires that we re-compute gsbase based
* on the cpu list.
*/
if (boothowto & RB_DEBUGENTER)
kmdb_enter();
/* User-set option overrides firmware value. */
}
#if defined(__xpv)
/* No support of DR operations on xpv */
plat_dr_options = 0;
#else /* __xpv */
/* Flag PLAT_DR_FEATURE_ENABLED should only be set by DR driver. */
#ifndef __amd64
#endif /* __amd64 */
#endif /* __xpv */
/*
* Get value of "plat_dr_physmax" boot option.
* It overrides values calculated from MSCT or SRAT table.
*/
}
/* Get value of boot_ncpus. */
boot_ncpus = NCPU;
} else {
boot_ncpus = (int)prop_value;
boot_ncpus = NCPU;
}
/*
* Set max_ncpus and boot_max_ncpus to boot_ncpus if platform doesn't
* support CPU DR operations.
*/
if (plat_dr_support_cpu() == 0) {
} else {
} else {
max_ncpus = (int)prop_value;
}
if (boot_ncpus > max_ncpus) {
}
}
} else {
boot_max_ncpus = (int)prop_value;
} else if (boot_max_ncpus > max_ncpus) {
}
}
}
/*
* Initialize the lgrp framework
*/
prom_printf("unix: kernel halted by -h flag\n");
}
/*
* Fill out cpu_ucode_info. Update microcode if necessary.
*/
if (workaround_errata(CPU) != 0)
panic("critical workaround(s) missing for boot cpu");
}
void
{
/*
* Construct the directory path from the filename.
*/
int len;
char *p;
const char isastr[] = "/amd64";
return;
p--; /* remove trailing '/' characters */
if (p == filename)
p++; /* so "/" -is- the modpath in this case */
/*
* Remove optional isa-dependent directory name - the module
* subsystem will put this back again (!)
*/
p -= isalen;
/*
* "/platform/mumblefrotz" + " " + MOD_DEFPATH
*/
}