#include <sys/types.h>
#include <sys/cmn_err.h>
#include <sys/sunddi.h>
#include <sys/cpu_module.h>
#include <sys/cpu_module_ms_impl.h>
#include <sys/cpuvar.h>
#include <sys/x86_archext.h>
#include <sys/kmem.h>
#include <sys/pghw.h>
#include <sys/modctl.h>
#include <sys/mc.h>
#include <sys/mca_x86.h>
#include "ao.h"
int ao_ms_support_disable = 0;
static struct ao_chipshared *ao_shared[AO_MAX_CHIPS];
uint_t ao_model_limit = 0x6f;
int
ao_ms_init(cmi_hdl_t hdl, void **datap)
{
uint_t chipid = cmi_hdl_chipid(hdl);
struct ao_chipshared *sp, *osp;
ao_ms_data_t *ao;
uint64_t cap;
if (ao_ms_support_disable || cmi_hdl_model(hdl) >= ao_model_limit)
return (ENOTSUP);
if (!is_x86_feature(x86_featureset, X86FSET_MCA))
return (ENOTSUP);
if (cmi_hdl_rdmsr(hdl, IA32_MSR_MCG_CAP, &cap) != CMI_SUCCESS)
return (ENOTSUP);
if (!(cap & MCG_CAP_CTL_P))
return (ENOTSUP);
if ((cap & MCG_CAP_COUNT_MASK) != AMD_MCA_BANK_COUNT) {
cmn_err(CE_WARN, "Chip %d core %d has %llu MCA banks, "
"expected %u: disabling AMD-specific MCA support on "
"this CPU", chipid, cmi_hdl_coreid(hdl),
(u_longlong_t)cap & MCG_CAP_COUNT_MASK,
AMD_MCA_BANK_COUNT);
return (ENOTSUP);
}
ao = *datap = kmem_zalloc(sizeof (ao_ms_data_t), KM_SLEEP);
cmi_hdl_hold(hdl);
ao->ao_ms_hdl = hdl;
if ((sp = ao_shared[chipid]) == NULL) {
sp = kmem_zalloc(sizeof (struct ao_chipshared), KM_SLEEP);
sp->aos_chiprev = cmi_hdl_chiprev(hdl);
membar_producer();
osp = atomic_cas_ptr(&ao_shared[chipid], NULL, sp);
if (osp != NULL) {
kmem_free(sp, sizeof (struct ao_chipshared));
sp = osp;
}
}
ao->ao_ms_shared = sp;
return (0);
}
void
ao_ms_post_mpstartup(cmi_hdl_t hdl)
{
(void) ddi_install_driver("mc-amd");
}
cms_api_ver_t _cms_api_version = CMS_API_VERSION_2;
const cms_ops_t _cms_ops = {
ao_ms_init,
ao_ms_post_startup,
ao_ms_post_mpstartup,
NULL,
ao_ms_mcgctl_val,
ao_ms_bankctl_skipinit,
ao_ms_bankctl_val,
NULL,
NULL,
ao_ms_mca_init,
ao_ms_poll_ownermask,
NULL,
ao_ms_error_action,
ao_ms_disp_match,
ao_ms_ereport_class,
NULL,
ao_ms_ereport_includestack,
ao_ms_ereport_add_logout,
ao_ms_msrinject,
NULL,
};
static struct modlcpu modlcpu = {
&mod_cpuops,
"AMD Athlon64/Opteron Model-Specific Support"
};
static struct modlinkage modlinkage = {
MODREV_1,
(void *)&modlcpu,
NULL
};
int
_init(void)
{
return (mod_install(&modlinkage));
}
int
_info(struct modinfo *modinfop)
{
return (mod_info(&modlinkage, modinfop));
}
int
_fini(void)
{
return (mod_remove(&modlinkage));
}