xref: /onnv-gate/usr/src/uts/i86pc/cpu/amd_opteron/ao_main.c (revision 12826:fca99d9e3f2f)
11414Scindi /*
21414Scindi  * CDDL HEADER START
31414Scindi  *
41414Scindi  * The contents of this file are subject to the terms of the
51642Sgavinm  * Common Development and Distribution License (the "License").
61642Sgavinm  * You may not use this file except in compliance with the License.
71414Scindi  *
81414Scindi  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91414Scindi  * or http://www.opensolaris.org/os/licensing.
101414Scindi  * See the License for the specific language governing permissions
111414Scindi  * and limitations under the License.
121414Scindi  *
131414Scindi  * When distributing Covered Code, include this CDDL HEADER in each
141414Scindi  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151414Scindi  * If applicable, add the following below this CDDL HEADER, with the
161414Scindi  * fields enclosed by brackets "[]" replaced with your own identifying
171414Scindi  * information: Portions Copyright [yyyy] [name of copyright owner]
181414Scindi  *
191414Scindi  * CDDL HEADER END
201414Scindi  */
211414Scindi 
221414Scindi /*
2312437SAdrian.Frost@Sun.COM  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
241414Scindi  */
251414Scindi 
261414Scindi /*
271414Scindi  * The CPU module for the AMD Athlon64 and Opteron processors
281414Scindi  */
291414Scindi 
301414Scindi #include <sys/types.h>
311414Scindi #include <sys/cmn_err.h>
321414Scindi #include <sys/sunddi.h>
335254Sgavinm #include <sys/cpu_module.h>
345254Sgavinm #include <sys/cpu_module_ms_impl.h>
351414Scindi #include <sys/cpuvar.h>
361414Scindi #include <sys/x86_archext.h>
371414Scindi #include <sys/kmem.h>
383434Sesaxe #include <sys/pghw.h>
391414Scindi #include <sys/modctl.h>
401414Scindi #include <sys/mc.h>
412785Srab #include <sys/mca_x86.h>
421414Scindi 
431414Scindi #include "ao.h"
441414Scindi 
455254Sgavinm int ao_ms_support_disable = 0;
465254Sgavinm 
475254Sgavinm static struct ao_chipshared *ao_shared[AO_MAX_CHIPS];
482869Sgavinm 
491414Scindi /*
502869Sgavinm  * This cpu module supports AMD family 0xf revisions B/C/D/E/F/G.  If
512869Sgavinm  * a family 0xf cpu beyond the rev G model limit is detected then
522869Sgavinm  * return ENOTSUP and let the generic x86 CPU module load instead.
531414Scindi  */
542869Sgavinm uint_t ao_model_limit = 0x6f;
551414Scindi 
565254Sgavinm int
ao_ms_init(cmi_hdl_t hdl,void ** datap)575254Sgavinm ao_ms_init(cmi_hdl_t hdl, void **datap)
581414Scindi {
595254Sgavinm 	uint_t chipid = cmi_hdl_chipid(hdl);
602869Sgavinm 	struct ao_chipshared *sp, *osp;
615254Sgavinm 	ao_ms_data_t *ao;
622785Srab 	uint64_t cap;
631414Scindi 
645254Sgavinm 	if (ao_ms_support_disable || cmi_hdl_model(hdl) >= ao_model_limit)
651414Scindi 		return (ENOTSUP);
661414Scindi 
67*12826Skuriakose.kuruvilla@oracle.com 	if (!is_x86_feature(x86_featureset, X86FSET_MCA))
682785Srab 		return (ENOTSUP);
692785Srab 
705254Sgavinm 	if (cmi_hdl_rdmsr(hdl, IA32_MSR_MCG_CAP, &cap) != CMI_SUCCESS)
715254Sgavinm 		return (ENOTSUP);
725254Sgavinm 
732785Srab 	if (!(cap & MCG_CAP_CTL_P))
742785Srab 		return (ENOTSUP);
752785Srab 
763766Sgavinm 	if ((cap & MCG_CAP_COUNT_MASK) != AMD_MCA_BANK_COUNT) {
775254Sgavinm 		cmn_err(CE_WARN, "Chip %d core %d has %llu MCA banks, "
785254Sgavinm 		    "expected %u: disabling AMD-specific MCA support on "
795254Sgavinm 		    "this CPU", chipid, cmi_hdl_coreid(hdl),
805254Sgavinm 		    (u_longlong_t)cap & MCG_CAP_COUNT_MASK,
813766Sgavinm 		    AMD_MCA_BANK_COUNT);
823766Sgavinm 		return (ENOTSUP);
833766Sgavinm 	}
843766Sgavinm 
855254Sgavinm 	ao = *datap = kmem_zalloc(sizeof (ao_ms_data_t), KM_SLEEP);
865254Sgavinm 	cmi_hdl_hold(hdl);	/* release in fini */
875254Sgavinm 	ao->ao_ms_hdl = hdl;
881414Scindi 
892869Sgavinm 	/*
902869Sgavinm 	 * Allocate the chipshared structure if it appears not to have been
912869Sgavinm 	 * allocated already (by a sibling core).  Install the newly
922869Sgavinm 	 * allocated pointer atomically in case a sibling core beats
932869Sgavinm 	 * us to it.
942869Sgavinm 	 */
952869Sgavinm 	if ((sp = ao_shared[chipid]) == NULL) {
962869Sgavinm 		sp = kmem_zalloc(sizeof (struct ao_chipshared), KM_SLEEP);
976000Sgavinm 		sp->aos_chiprev = cmi_hdl_chiprev(hdl);
986000Sgavinm 		membar_producer();
996000Sgavinm 
1002869Sgavinm 		osp = atomic_cas_ptr(&ao_shared[chipid], NULL, sp);
1012869Sgavinm 		if (osp != NULL) {
1022869Sgavinm 			kmem_free(sp, sizeof (struct ao_chipshared));
1032869Sgavinm 			sp = osp;
1042869Sgavinm 		}
1052869Sgavinm 	}
1065254Sgavinm 	ao->ao_ms_shared = sp;
1072869Sgavinm 
1081414Scindi 	return (0);
1091414Scindi }
1101414Scindi 
1111642Sgavinm /*ARGSUSED*/
1125254Sgavinm void
ao_ms_post_mpstartup(cmi_hdl_t hdl)1135254Sgavinm ao_ms_post_mpstartup(cmi_hdl_t hdl)
1141642Sgavinm {
1151642Sgavinm 	(void) ddi_install_driver("mc-amd");
1161642Sgavinm }
1171642Sgavinm 
11812437SAdrian.Frost@Sun.COM cms_api_ver_t _cms_api_version = CMS_API_VERSION_2;
1191414Scindi 
1205254Sgavinm const cms_ops_t _cms_ops = {
1215254Sgavinm 	ao_ms_init,			/* cms_init */
1225254Sgavinm 	ao_ms_post_startup,		/* cms_post_startup */
1235254Sgavinm 	ao_ms_post_mpstartup,		/* cms_post_mpstartup */
1245254Sgavinm 	NULL,				/* cms_logout_size */
1255254Sgavinm 	ao_ms_mcgctl_val,		/* cms_mcgctl_val */
1265254Sgavinm 	ao_ms_bankctl_skipinit,		/* cms_bankctl_skipinit */
1275254Sgavinm 	ao_ms_bankctl_val,		/* cms_bankctl_val */
1285254Sgavinm 	NULL,				/* cms_bankstatus_skipinit */
1295254Sgavinm 	NULL,				/* cms_bankstatus_val */
1305254Sgavinm 	ao_ms_mca_init,			/* cms_mca_init */
1315254Sgavinm 	ao_ms_poll_ownermask,		/* cms_poll_ownermask */
1325254Sgavinm 	NULL,				/* cms_bank_logout */
1335254Sgavinm 	ao_ms_error_action,		/* cms_error_action */
1345254Sgavinm 	ao_ms_disp_match,		/* cms_disp_match */
1355254Sgavinm 	ao_ms_ereport_class,		/* cms_ereport_class */
1365254Sgavinm 	NULL,				/* cms_ereport_detector */
1375254Sgavinm 	ao_ms_ereport_includestack,	/* cms_ereport_includestack */
1385254Sgavinm 	ao_ms_ereport_add_logout,	/* cms_ereport_add_logout */
1395254Sgavinm 	ao_ms_msrinject,		/* cms_msrinject */
1405254Sgavinm 	NULL,				/* cms_fini */
1411414Scindi };
1421414Scindi 
1431414Scindi static struct modlcpu modlcpu = {
1441414Scindi 	&mod_cpuops,
1455254Sgavinm 	"AMD Athlon64/Opteron Model-Specific Support"
1461414Scindi };
1471414Scindi 
1481414Scindi static struct modlinkage modlinkage = {
1491414Scindi 	MODREV_1,
1501414Scindi 	(void *)&modlcpu,
1511414Scindi 	NULL
1521414Scindi };
1531414Scindi 
1541414Scindi int
_init(void)1551414Scindi _init(void)
1561414Scindi {
1575254Sgavinm 	return (mod_install(&modlinkage));
1581414Scindi }
1591414Scindi 
1601414Scindi int
_info(struct modinfo * modinfop)1611414Scindi _info(struct modinfo *modinfop)
1621414Scindi {
1631414Scindi 	return (mod_info(&modlinkage, modinfop));
1641414Scindi }
1651414Scindi 
1661414Scindi int
_fini(void)1671414Scindi _fini(void)
1681414Scindi {
1695254Sgavinm 	return (mod_remove(&modlinkage));
1701414Scindi }
171