120c794b3Sgavinm /*
220c794b3Sgavinm * CDDL HEADER START
320c794b3Sgavinm *
420c794b3Sgavinm * The contents of this file are subject to the terms of the
520c794b3Sgavinm * Common Development and Distribution License (the "License").
620c794b3Sgavinm * You may not use this file except in compliance with the License.
720c794b3Sgavinm *
820c794b3Sgavinm * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
920c794b3Sgavinm * or http://www.opensolaris.org/os/licensing.
1020c794b3Sgavinm * See the License for the specific language governing permissions
1120c794b3Sgavinm * and limitations under the License.
1220c794b3Sgavinm *
1320c794b3Sgavinm * When distributing Covered Code, include this CDDL HEADER in each
1420c794b3Sgavinm * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1520c794b3Sgavinm * If applicable, add the following below this CDDL HEADER, with the
1620c794b3Sgavinm * fields enclosed by brackets "[]" replaced with your own identifying
1720c794b3Sgavinm * information: Portions Copyright [yyyy] [name of copyright owner]
1820c794b3Sgavinm *
1920c794b3Sgavinm * CDDL HEADER END
2020c794b3Sgavinm */
2120c794b3Sgavinm
2220c794b3Sgavinm /*
23c84b7bbeSAdrian Frost * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
2420c794b3Sgavinm */
2520c794b3Sgavinm
2620c794b3Sgavinm /*
2720c794b3Sgavinm * "Generic AMD" model-specific support. If no more-specific support can
2820c794b3Sgavinm * be found, or such modules declines to initialize, then for AuthenticAMD
2920c794b3Sgavinm * cpus this module can have a crack at providing some AMD model-specific
3020c794b3Sgavinm * support that at least goes beyond common MCA architectural features
3120c794b3Sgavinm * if not down to the nitty-gritty level for a particular model. We
3220c794b3Sgavinm * are layered on top of a cpu module, likely cpu.generic, so there is no
3320c794b3Sgavinm * need for us to perform common architecturally-accessible functions.
3420c794b3Sgavinm */
3520c794b3Sgavinm
3620c794b3Sgavinm #include <sys/types.h>
3720c794b3Sgavinm #include <sys/cmn_err.h>
3820c794b3Sgavinm #include <sys/modctl.h>
3920c794b3Sgavinm #include <sys/cpu_module.h>
4020c794b3Sgavinm #include <sys/mca_x86.h>
4120c794b3Sgavinm #include <sys/pci_cfgspace.h>
4220c794b3Sgavinm #include <sys/x86_archext.h>
4320c794b3Sgavinm #include <sys/mc_amd.h>
4420c794b3Sgavinm #include <sys/fm/protocol.h>
4520c794b3Sgavinm #include <sys/fm/cpu/GENAMD.h>
46074bb90dSTom Pothier #include <sys/fm/smb/fmsmb.h>
47074bb90dSTom Pothier #include <sys/fm/util.h>
4820c794b3Sgavinm #include <sys/nvpair.h>
4920c794b3Sgavinm #include <sys/controlregs.h>
5020c794b3Sgavinm #include <sys/pghw.h>
5120c794b3Sgavinm #include <sys/sunddi.h>
5225f47677Sgavinm #include <sys/sysmacros.h>
5320c794b3Sgavinm #include <sys/cpu_module_ms_impl.h>
5420c794b3Sgavinm
5520c794b3Sgavinm #include "authamd.h"
5620c794b3Sgavinm
57074bb90dSTom Pothier extern int x86gentopo_legacy; /* x86 generic topo support */
58074bb90dSTom Pothier
5920c794b3Sgavinm int authamd_ms_support_disable = 0;
6020c794b3Sgavinm
6120c794b3Sgavinm #define AUTHAMD_F_REVS_BCDE \
6220c794b3Sgavinm (X86_CHIPREV_AMD_F_REV_B | X86_CHIPREV_AMD_F_REV_C0 | \
6320c794b3Sgavinm X86_CHIPREV_AMD_F_REV_CG | X86_CHIPREV_AMD_F_REV_D | \
6420c794b3Sgavinm X86_CHIPREV_AMD_F_REV_E)
6520c794b3Sgavinm
6620c794b3Sgavinm #define AUTHAMD_F_REVS_FG \
6720c794b3Sgavinm (X86_CHIPREV_AMD_F_REV_F | X86_CHIPREV_AMD_F_REV_G)
6820c794b3Sgavinm
6920c794b3Sgavinm #define AUTHAMD_10_REVS_AB \
7020c794b3Sgavinm (X86_CHIPREV_AMD_10_REV_A | X86_CHIPREV_AMD_10_REV_B)
7120c794b3Sgavinm
7220c794b3Sgavinm /*
7320c794b3Sgavinm * Bitmasks of support for various features. Try to enable features
7420c794b3Sgavinm * via inclusion in one of these bitmasks and check that at the
7520c794b3Sgavinm * feature imlementation - that way new family support may often simply
7620c794b3Sgavinm * simply need to update these bitmasks.
7720c794b3Sgavinm */
7820c794b3Sgavinm
7920c794b3Sgavinm /*
80a4e4e13fSgavinm * Models that include an on-chip NorthBridge.
81a4e4e13fSgavinm */
82a4e4e13fSgavinm #define AUTHAMD_NBONCHIP(rev) \
83a4e4e13fSgavinm (X86_CHIPREV_ATLEAST(rev, X86_CHIPREV_AMD_F_REV_B) || \
84a4e4e13fSgavinm X86_CHIPREV_ATLEAST(rev, X86_CHIPREV_AMD_10_REV_A))
85a4e4e13fSgavinm
86a4e4e13fSgavinm /*
8720c794b3Sgavinm * Families/revisions for which we can recognise main memory ECC errors.
8820c794b3Sgavinm */
8920c794b3Sgavinm #define AUTHAMD_MEMECC_RECOGNISED(rev) \
9020c794b3Sgavinm (X86_CHIPREV_ATLEAST(rev, X86_CHIPREV_AMD_F_REV_B) || \
9120c794b3Sgavinm X86_CHIPREV_ATLEAST(rev, X86_CHIPREV_AMD_10_REV_A))
9220c794b3Sgavinm
9320c794b3Sgavinm /*
9420c794b3Sgavinm * Families/revisions that have an Online Spare Control Register
9520c794b3Sgavinm */
9620c794b3Sgavinm #define AUTHAMD_HAS_ONLINESPARECTL(rev) \
9720c794b3Sgavinm (X86_CHIPREV_ATLEAST(rev, X86_CHIPREV_AMD_F_REV_F) || \
9820c794b3Sgavinm X86_CHIPREV_ATLEAST(rev, X86_CHIPREV_AMD_10_REV_A))
9920c794b3Sgavinm
10020c794b3Sgavinm /*
10125f47677Sgavinm * Families/revisions for which we will perform NB MCA Config changes
10225f47677Sgavinm */
10325f47677Sgavinm #define AUTHAMD_DO_NBMCACFG(rev) \
104a4e4e13fSgavinm (X86_CHIPREV_ATLEAST(rev, X86_CHIPREV_AMD_F_REV_B) || \
10525f47677Sgavinm X86_CHIPREV_ATLEAST(rev, X86_CHIPREV_AMD_10_REV_A))
10625f47677Sgavinm
10725f47677Sgavinm /*
10825f47677Sgavinm * Families/revisions that have chip cache scrubbers.
10925f47677Sgavinm */
11025f47677Sgavinm #define AUTHAMD_HAS_CHIPSCRUB(rev) \
111a4e4e13fSgavinm (X86_CHIPREV_ATLEAST(rev, X86_CHIPREV_AMD_F_REV_B) || \
11225f47677Sgavinm X86_CHIPREV_ATLEAST(rev, X86_CHIPREV_AMD_10_REV_A))
11325f47677Sgavinm
11425f47677Sgavinm /*
11520c794b3Sgavinm * Families/revisions that have a NB misc register or registers -
11620c794b3Sgavinm * evaluates to 0 if no support, otherwise the number of MC4_MISCj.
11720c794b3Sgavinm */
11820c794b3Sgavinm #define AUTHAMD_NBMISC_NUM(rev) \
11920c794b3Sgavinm (X86_CHIPREV_ATLEAST(rev, X86_CHIPREV_AMD_F_REV_F)? 1 : \
12020c794b3Sgavinm (X86_CHIPREV_ATLEAST(rev, X86_CHIPREV_AMD_10_REV_A) ? 3 : 0))
12120c794b3Sgavinm
12220c794b3Sgavinm /*
12320c794b3Sgavinm * Families/revision for which we wish not to machine check for GART
12420c794b3Sgavinm * table walk errors - bit 10 of NB CTL.
12520c794b3Sgavinm */
12620c794b3Sgavinm #define AUTHAMD_NOGARTTBLWLK_MC(rev) \
12720c794b3Sgavinm (X86_CHIPREV_ATLEAST(rev, X86_CHIPREV_AMD_F_REV_B) || \
12820c794b3Sgavinm X86_CHIPREV_ATLEAST(rev, X86_CHIPREV_AMD_10_REV_A))
12920c794b3Sgavinm
13020c794b3Sgavinm /*
13125f47677Sgavinm * Families/revisions that are potentially L3 capable
13225f47677Sgavinm */
13325f47677Sgavinm #define AUTHAMD_L3CAPABLE(rev) \
13425f47677Sgavinm (X86_CHIPREV_ATLEAST(rev, X86_CHIPREV_AMD_10_REV_A))
13525f47677Sgavinm
13625f47677Sgavinm /*
1375667185bSSrihari Venkatesan * Families/revisions that support x8 ChipKill ECC
1385667185bSSrihari Venkatesan */
1395667185bSSrihari Venkatesan #define AUTHAMD_SUPPORTS_X8ECC(rev) \
140*79321794SJens Elkner (X86_CHIPREV_ATLEAST(rev, X86_CHIPREV_AMD_10_REV_D0))
1415667185bSSrihari Venkatesan
1425667185bSSrihari Venkatesan /*
14320c794b3Sgavinm * We recognise main memory ECC errors for AUTHAMD_MEMECC_RECOGNISED
14420c794b3Sgavinm * revisions as:
14520c794b3Sgavinm *
14620c794b3Sgavinm * - being reported by the NB
14720c794b3Sgavinm * - being a compound bus/interconnect error (external to chip)
14820c794b3Sgavinm * - having LL of LG
14920c794b3Sgavinm * - having II of MEM (but could still be a master/target abort)
15020c794b3Sgavinm * - having CECC or UECC set
15120c794b3Sgavinm *
15220c794b3Sgavinm * We do not check the extended error code (first nibble of the
15320c794b3Sgavinm * model-specific error code on AMD) since this has changed from
15420c794b3Sgavinm * family 0xf to family 0x10 (ext code 0 now reserved on family 0x10).
15520c794b3Sgavinm * Instead we use CECC/UECC to separate off the master/target
15620c794b3Sgavinm * abort cases.
15720c794b3Sgavinm *
15820c794b3Sgavinm * We insist that the detector be the NorthBridge bank; although
15920c794b3Sgavinm * IC/DC can report some main memory errors, they do not capture
16020c794b3Sgavinm * an address at sufficient resolution to be useful and the NB will
16120c794b3Sgavinm * report most errors.
16220c794b3Sgavinm */
16320c794b3Sgavinm #define AUTHAMD_IS_MEMECCERR(bank, status) \
16420c794b3Sgavinm ((bank) == AMD_MCA_BANK_NB && \
16520c794b3Sgavinm MCAX86_ERRCODE_ISBUS_INTERCONNECT(MCAX86_ERRCODE(status)) && \
16620c794b3Sgavinm MCAX86_ERRCODE_LL(MCAX86_ERRCODE(status)) == MCAX86_ERRCODE_LL_LG && \
16720c794b3Sgavinm MCAX86_ERRCODE_II(MCAX86_ERRCODE(status)) == MCAX86_ERRCODE_II_MEM && \
16820c794b3Sgavinm ((status) & (AMD_BANK_STAT_CECC | AMD_BANK_STAT_UECC)))
16920c794b3Sgavinm
17020c794b3Sgavinm static authamd_error_disp_t authamd_memce_disp = {
17120c794b3Sgavinm FM_EREPORT_CPU_GENAMD,
17220c794b3Sgavinm FM_EREPORT_CPU_GENAMD_MEM_CE,
17320c794b3Sgavinm FM_EREPORT_GENAMD_PAYLOAD_FLAGS_MEM_CE
17420c794b3Sgavinm };
17520c794b3Sgavinm
17620c794b3Sgavinm static authamd_error_disp_t authamd_memue_disp = {
17720c794b3Sgavinm FM_EREPORT_CPU_GENAMD,
17820c794b3Sgavinm FM_EREPORT_CPU_GENAMD_MEM_UE,
17920c794b3Sgavinm FM_EREPORT_GENAMD_PAYLOAD_FLAGS_MEM_UE
18020c794b3Sgavinm };
18120c794b3Sgavinm
18220c794b3Sgavinm static authamd_error_disp_t authamd_ckmemce_disp = {
18320c794b3Sgavinm FM_EREPORT_CPU_GENAMD,
18420c794b3Sgavinm FM_EREPORT_CPU_GENAMD_CKMEM_CE,
18520c794b3Sgavinm FM_EREPORT_GENAMD_PAYLOAD_FLAGS_CKMEM_CE
18620c794b3Sgavinm };
18720c794b3Sgavinm
18820c794b3Sgavinm static authamd_error_disp_t authamd_ckmemue_disp = {
18920c794b3Sgavinm FM_EREPORT_CPU_GENAMD,
19020c794b3Sgavinm FM_EREPORT_CPU_GENAMD_CKMEM_UE,
19120c794b3Sgavinm FM_EREPORT_GENAMD_PAYLOAD_FLAGS_CKMEM_UE
19220c794b3Sgavinm };
19320c794b3Sgavinm
19420c794b3Sgavinm /*
19520c794b3Sgavinm * We recognise GART walk errors as:
19620c794b3Sgavinm *
19720c794b3Sgavinm * - being reported by the NB
19820c794b3Sgavinm * - being a compound TLB error
19920c794b3Sgavinm * - having LL of LG and TT of GEN
20020c794b3Sgavinm * - having UC set
20120c794b3Sgavinm * - possibly having PCC set (if source CPU)
20220c794b3Sgavinm */
20320c794b3Sgavinm #define AUTHAMD_IS_GARTERR(bank, status) \
20420c794b3Sgavinm ((bank) == AMD_MCA_BANK_NB && \
20520c794b3Sgavinm MCAX86_ERRCODE_ISTLB(MCAX86_ERRCODE(status)) && \
20620c794b3Sgavinm MCAX86_ERRCODE_LL(MCAX86_ERRCODE(status)) == MCAX86_ERRCODE_LL_LG && \
20720c794b3Sgavinm MCAX86_ERRCODE_TT(MCAX86_ERRCODE(status)) == MCAX86_ERRCODE_TT_GEN && \
20820c794b3Sgavinm (status) & MSR_MC_STATUS_UC)
20920c794b3Sgavinm
21020c794b3Sgavinm static authamd_error_disp_t authamd_gart_disp = {
21120c794b3Sgavinm FM_EREPORT_CPU_GENAMD, /* use generic subclass */
21220c794b3Sgavinm FM_EREPORT_CPU_GENADM_GARTTBLWLK, /* use generic leafclass */
21320c794b3Sgavinm 0 /* no additional payload */
21420c794b3Sgavinm };
21520c794b3Sgavinm
21620c794b3Sgavinm
2178031591dSSrihari Venkatesan static struct authamd_nodeshared *authamd_shared[AUTHAMD_MAX_NODES];
21820c794b3Sgavinm
21920c794b3Sgavinm static int
authamd_chip_once(authamd_data_t * authamd,enum authamd_cfgonce_bitnum what)22020c794b3Sgavinm authamd_chip_once(authamd_data_t *authamd, enum authamd_cfgonce_bitnum what)
22120c794b3Sgavinm {
2225667185bSSrihari Venkatesan return (atomic_set_long_excl(&authamd->amd_shared->ans_cfgonce,
22320c794b3Sgavinm what) == 0 ? B_TRUE : B_FALSE);
22420c794b3Sgavinm }
22520c794b3Sgavinm
22620c794b3Sgavinm static void
authamd_pcicfg_write(uint_t procnodeid,uint_t func,uint_t reg,uint32_t val)2278031591dSSrihari Venkatesan authamd_pcicfg_write(uint_t procnodeid, uint_t func, uint_t reg, uint32_t val)
22820c794b3Sgavinm {
2298031591dSSrihari Venkatesan ASSERT(procnodeid + 24 <= 31);
23020c794b3Sgavinm ASSERT((func & 7) == func);
2315667185bSSrihari Venkatesan ASSERT((reg & 3) == 0 && reg < 4096);
23220c794b3Sgavinm
2338031591dSSrihari Venkatesan cmi_pci_putl(0, procnodeid + 24, func, reg, 0, val);
23420c794b3Sgavinm }
23520c794b3Sgavinm
23620c794b3Sgavinm static uint32_t
authamd_pcicfg_read(uint_t procnodeid,uint_t func,uint_t reg)2378031591dSSrihari Venkatesan authamd_pcicfg_read(uint_t procnodeid, uint_t func, uint_t reg)
23820c794b3Sgavinm {
2398031591dSSrihari Venkatesan ASSERT(procnodeid + 24 <= 31);
24020c794b3Sgavinm ASSERT((func & 7) == func);
2415667185bSSrihari Venkatesan ASSERT((reg & 3) == 0 && reg < 4096);
24220c794b3Sgavinm
2438031591dSSrihari Venkatesan return (cmi_pci_getl(0, procnodeid + 24, func, reg, 0, 0));
24420c794b3Sgavinm }
24520c794b3Sgavinm
24620c794b3Sgavinm void
authamd_bankstatus_prewrite(cmi_hdl_t hdl,authamd_data_t * authamd)24720c794b3Sgavinm authamd_bankstatus_prewrite(cmi_hdl_t hdl, authamd_data_t *authamd)
24820c794b3Sgavinm {
24920c794b3Sgavinm uint64_t hwcr;
25020c794b3Sgavinm
25120c794b3Sgavinm if (cmi_hdl_rdmsr(hdl, MSR_AMD_HWCR, &hwcr) != CMI_SUCCESS)
25220c794b3Sgavinm return;
25320c794b3Sgavinm
25420c794b3Sgavinm authamd->amd_hwcr = hwcr;
25520c794b3Sgavinm
25620c794b3Sgavinm if (!(hwcr & AMD_HWCR_MCI_STATUS_WREN)) {
25720c794b3Sgavinm hwcr |= AMD_HWCR_MCI_STATUS_WREN;
25820c794b3Sgavinm (void) cmi_hdl_wrmsr(hdl, MSR_AMD_HWCR, hwcr);
25920c794b3Sgavinm }
26020c794b3Sgavinm }
26120c794b3Sgavinm
26220c794b3Sgavinm void
authamd_bankstatus_postwrite(cmi_hdl_t hdl,authamd_data_t * authamd)26320c794b3Sgavinm authamd_bankstatus_postwrite(cmi_hdl_t hdl, authamd_data_t *authamd)
26420c794b3Sgavinm {
26520c794b3Sgavinm uint64_t hwcr = authamd->amd_hwcr;
26620c794b3Sgavinm
26720c794b3Sgavinm if (!(hwcr & AMD_HWCR_MCI_STATUS_WREN)) {
26820c794b3Sgavinm hwcr &= ~AMD_HWCR_MCI_STATUS_WREN;
26920c794b3Sgavinm (void) cmi_hdl_wrmsr(hdl, MSR_AMD_HWCR, hwcr);
27020c794b3Sgavinm }
27120c794b3Sgavinm }
27220c794b3Sgavinm
27320c794b3Sgavinm /*
27420c794b3Sgavinm * Read EccCnt repeatedly for all possible channel/chip-select combos:
27520c794b3Sgavinm *
27620c794b3Sgavinm * - read sparectl register
27720c794b3Sgavinm * - if EccErrCntWrEn is set, clear that bit in the just-read value
27820c794b3Sgavinm * and write it back to sparectl; this *may* clobber the EccCnt
27920c794b3Sgavinm * for the channel/chip-select combination currently selected, so
28020c794b3Sgavinm * we leave this bit clear if we had to clear it
28120c794b3Sgavinm * - cycle through all channel/chip-select combinations writing each
28220c794b3Sgavinm * combination to sparectl before reading the register back for
28320c794b3Sgavinm * EccCnt for that combination; since EccErrCntWrEn is clear
28420c794b3Sgavinm * the writes to select what count to read will not themselves
28520c794b3Sgavinm * zero any counts
28620c794b3Sgavinm */
28720c794b3Sgavinm static int
authamd_read_ecccnt(authamd_data_t * authamd,struct authamd_logout * msl)28820c794b3Sgavinm authamd_read_ecccnt(authamd_data_t *authamd, struct authamd_logout *msl)
28920c794b3Sgavinm {
29020c794b3Sgavinm union mcreg_sparectl sparectl;
2915667185bSSrihari Venkatesan uint_t procnodeid = authamd->amd_shared->ans_procnodeid;
2925667185bSSrihari Venkatesan uint_t family = authamd->amd_shared->ans_family;
2935667185bSSrihari Venkatesan uint32_t rev = authamd->amd_shared->ans_rev;
29420c794b3Sgavinm int chan, cs;
29520c794b3Sgavinm
29620c794b3Sgavinm /*
29720c794b3Sgavinm * Check for feature support; this macro will test down to the
29820c794b3Sgavinm * family revision number, whereafter we'll switch on family
29920c794b3Sgavinm * assuming that future revisions will use the same register
30020c794b3Sgavinm * format.
30120c794b3Sgavinm */
30220c794b3Sgavinm if (!AUTHAMD_HAS_ONLINESPARECTL(rev)) {
30320c794b3Sgavinm bzero(&msl->aal_eccerrcnt, sizeof (msl->aal_eccerrcnt));
30420c794b3Sgavinm return (0);
30520c794b3Sgavinm }
30620c794b3Sgavinm
30720c794b3Sgavinm MCREG_VAL32(&sparectl) =
3088031591dSSrihari Venkatesan authamd_pcicfg_read(procnodeid, MC_FUNC_MISCCTL,
3098031591dSSrihari Venkatesan MC_CTL_REG_SPARECTL);
31020c794b3Sgavinm
31120c794b3Sgavinm switch (family) {
31220c794b3Sgavinm case AUTHAMD_FAMILY_F:
31320c794b3Sgavinm MCREG_FIELD_F_revFG(&sparectl, EccErrCntWrEn) = 0;
31420c794b3Sgavinm break;
31520c794b3Sgavinm
31620c794b3Sgavinm case AUTHAMD_FAMILY_10:
31720c794b3Sgavinm MCREG_FIELD_10_revAB(&sparectl, EccErrCntWrEn) = 0;
31820c794b3Sgavinm break;
31920c794b3Sgavinm }
32020c794b3Sgavinm
32120c794b3Sgavinm for (chan = 0; chan < AUTHAMD_DRAM_NCHANNEL; chan++) {
32220c794b3Sgavinm switch (family) {
32320c794b3Sgavinm case AUTHAMD_FAMILY_F:
32420c794b3Sgavinm MCREG_FIELD_F_revFG(&sparectl, EccErrCntDramChan) =
32520c794b3Sgavinm chan;
32620c794b3Sgavinm break;
32720c794b3Sgavinm
32820c794b3Sgavinm case AUTHAMD_FAMILY_10:
32920c794b3Sgavinm MCREG_FIELD_10_revAB(&sparectl, EccErrCntDramChan) =
33020c794b3Sgavinm chan;
33120c794b3Sgavinm break;
33220c794b3Sgavinm }
33320c794b3Sgavinm
33420c794b3Sgavinm for (cs = 0; cs < AUTHAMD_DRAM_NCS; cs++) {
33520c794b3Sgavinm switch (family) {
33620c794b3Sgavinm case AUTHAMD_FAMILY_F:
33720c794b3Sgavinm MCREG_FIELD_F_revFG(&sparectl,
33820c794b3Sgavinm EccErrCntDramCs) = cs;
33920c794b3Sgavinm break;
34020c794b3Sgavinm
34120c794b3Sgavinm case AUTHAMD_FAMILY_10:
34220c794b3Sgavinm MCREG_FIELD_10_revAB(&sparectl,
34320c794b3Sgavinm EccErrCntDramCs) = cs;
34420c794b3Sgavinm break;
34520c794b3Sgavinm }
34620c794b3Sgavinm
3478031591dSSrihari Venkatesan authamd_pcicfg_write(procnodeid, MC_FUNC_MISCCTL,
34820c794b3Sgavinm MC_CTL_REG_SPARECTL, MCREG_VAL32(&sparectl));
34920c794b3Sgavinm
3508031591dSSrihari Venkatesan MCREG_VAL32(&sparectl) = authamd_pcicfg_read(procnodeid,
35120c794b3Sgavinm MC_FUNC_MISCCTL, MC_CTL_REG_SPARECTL);
35220c794b3Sgavinm
35320c794b3Sgavinm switch (family) {
35420c794b3Sgavinm case AUTHAMD_FAMILY_F:
35520c794b3Sgavinm msl->aal_eccerrcnt[chan][cs] =
35620c794b3Sgavinm MCREG_FIELD_F_revFG(&sparectl, EccErrCnt);
35720c794b3Sgavinm break;
35820c794b3Sgavinm case AUTHAMD_FAMILY_10:
35920c794b3Sgavinm msl->aal_eccerrcnt[chan][cs] =
36020c794b3Sgavinm MCREG_FIELD_10_revAB(&sparectl, EccErrCnt);
36120c794b3Sgavinm break;
36220c794b3Sgavinm }
36320c794b3Sgavinm }
36420c794b3Sgavinm }
36520c794b3Sgavinm
36620c794b3Sgavinm return (1);
36720c794b3Sgavinm }
36820c794b3Sgavinm
36920c794b3Sgavinm /*
37020c794b3Sgavinm * Clear EccCnt for all possible channel/chip-select combos:
37120c794b3Sgavinm *
37220c794b3Sgavinm * - set EccErrCntWrEn in sparectl, if necessary
37320c794b3Sgavinm * - write 0 to EccCnt for all channel/chip-select combinations
37420c794b3Sgavinm * - clear EccErrCntWrEn
37520c794b3Sgavinm *
37620c794b3Sgavinm * If requested also disable the interrupts taken on counter overflow
37720c794b3Sgavinm * and on swap done.
37820c794b3Sgavinm */
37920c794b3Sgavinm static void
authamd_clear_ecccnt(authamd_data_t * authamd,boolean_t clrint)38020c794b3Sgavinm authamd_clear_ecccnt(authamd_data_t *authamd, boolean_t clrint)
38120c794b3Sgavinm {
38220c794b3Sgavinm union mcreg_sparectl sparectl;
3835667185bSSrihari Venkatesan uint_t procnodeid = authamd->amd_shared->ans_procnodeid;
3845667185bSSrihari Venkatesan uint_t family = authamd->amd_shared->ans_family;
3855667185bSSrihari Venkatesan uint32_t rev = authamd->amd_shared->ans_rev;
38620c794b3Sgavinm int chan, cs;
38720c794b3Sgavinm
38820c794b3Sgavinm if (!AUTHAMD_HAS_ONLINESPARECTL(rev))
38920c794b3Sgavinm return;
39020c794b3Sgavinm
39120c794b3Sgavinm MCREG_VAL32(&sparectl) =
3928031591dSSrihari Venkatesan authamd_pcicfg_read(procnodeid, MC_FUNC_MISCCTL,
3938031591dSSrihari Venkatesan MC_CTL_REG_SPARECTL);
39420c794b3Sgavinm
39520c794b3Sgavinm switch (family) {
39620c794b3Sgavinm case AUTHAMD_FAMILY_F:
39720c794b3Sgavinm MCREG_FIELD_F_revFG(&sparectl, EccErrCntWrEn) = 1;
39820c794b3Sgavinm if (clrint) {
39920c794b3Sgavinm MCREG_FIELD_F_revFG(&sparectl, EccErrInt) = 0;
40020c794b3Sgavinm MCREG_FIELD_F_revFG(&sparectl, SwapDoneInt) = 0;
40120c794b3Sgavinm }
40220c794b3Sgavinm break;
40320c794b3Sgavinm
40420c794b3Sgavinm case AUTHAMD_FAMILY_10:
40520c794b3Sgavinm MCREG_FIELD_10_revAB(&sparectl, EccErrCntWrEn) = 1;
40620c794b3Sgavinm if (clrint) {
40720c794b3Sgavinm MCREG_FIELD_10_revAB(&sparectl, EccErrInt) = 0;
40820c794b3Sgavinm MCREG_FIELD_10_revAB(&sparectl, SwapDoneInt) = 0;
40920c794b3Sgavinm }
41020c794b3Sgavinm break;
41120c794b3Sgavinm }
41220c794b3Sgavinm
4138031591dSSrihari Venkatesan authamd_pcicfg_write(procnodeid, MC_FUNC_MISCCTL,
41420c794b3Sgavinm MC_CTL_REG_SPARECTL, MCREG_VAL32(&sparectl));
41520c794b3Sgavinm
41620c794b3Sgavinm for (chan = 0; chan < AUTHAMD_DRAM_NCHANNEL; chan++) {
41720c794b3Sgavinm switch (family) {
41820c794b3Sgavinm case AUTHAMD_FAMILY_F:
41920c794b3Sgavinm MCREG_FIELD_F_revFG(&sparectl, EccErrCntDramChan) =
42020c794b3Sgavinm chan;
42120c794b3Sgavinm break;
42220c794b3Sgavinm
42320c794b3Sgavinm case AUTHAMD_FAMILY_10:
42420c794b3Sgavinm MCREG_FIELD_10_revAB(&sparectl, EccErrCntDramChan) =
42520c794b3Sgavinm chan;
42620c794b3Sgavinm break;
42720c794b3Sgavinm }
42820c794b3Sgavinm
42920c794b3Sgavinm for (cs = 0; cs < AUTHAMD_DRAM_NCS; cs++) {
43020c794b3Sgavinm switch (family) {
43120c794b3Sgavinm case AUTHAMD_FAMILY_F:
43220c794b3Sgavinm MCREG_FIELD_F_revFG(&sparectl,
43320c794b3Sgavinm EccErrCntDramCs) = cs;
43420c794b3Sgavinm MCREG_FIELD_F_revFG(&sparectl,
43520c794b3Sgavinm EccErrCnt) = 0;
43620c794b3Sgavinm break;
43720c794b3Sgavinm
43820c794b3Sgavinm case AUTHAMD_FAMILY_10:
43920c794b3Sgavinm MCREG_FIELD_10_revAB(&sparectl,
44020c794b3Sgavinm EccErrCntDramCs) = cs;
44120c794b3Sgavinm MCREG_FIELD_10_revAB(&sparectl,
44220c794b3Sgavinm EccErrCnt) = 0;
44320c794b3Sgavinm break;
44420c794b3Sgavinm }
44520c794b3Sgavinm
4468031591dSSrihari Venkatesan authamd_pcicfg_write(procnodeid, MC_FUNC_MISCCTL,
44720c794b3Sgavinm MC_CTL_REG_SPARECTL, MCREG_VAL32(&sparectl));
44820c794b3Sgavinm }
44920c794b3Sgavinm }
45020c794b3Sgavinm }
45120c794b3Sgavinm
452a24e89c4SKuriakose Kuruvilla
453a24e89c4SKuriakose Kuruvilla /*
454a24e89c4SKuriakose Kuruvilla * Return
455a24e89c4SKuriakose Kuruvilla * 1: supported
456a24e89c4SKuriakose Kuruvilla * 0: unsupported
457a24e89c4SKuriakose Kuruvilla */
458a24e89c4SKuriakose Kuruvilla static int
authamd_supported(cmi_hdl_t hdl)4598031591dSSrihari Venkatesan authamd_supported(cmi_hdl_t hdl)
460a24e89c4SKuriakose Kuruvilla {
4618031591dSSrihari Venkatesan uint_t family = cmi_hdl_family(hdl);
462a24e89c4SKuriakose Kuruvilla
4638031591dSSrihari Venkatesan switch (family) {
4648031591dSSrihari Venkatesan case AUTHAMD_FAMILY_6:
4658031591dSSrihari Venkatesan case AUTHAMD_FAMILY_F:
4668031591dSSrihari Venkatesan case AUTHAMD_FAMILY_10:
467a24e89c4SKuriakose Kuruvilla return (1);
4688031591dSSrihari Venkatesan default:
469a24e89c4SKuriakose Kuruvilla return (0);
470a24e89c4SKuriakose Kuruvilla }
4718031591dSSrihari Venkatesan }
472a24e89c4SKuriakose Kuruvilla
47320c794b3Sgavinm /*
47420c794b3Sgavinm * cms_init entry point.
47520c794b3Sgavinm *
47620c794b3Sgavinm * This module provides broad model-specific support for AMD families
47720c794b3Sgavinm * 0x6, 0xf and 0x10. Future families will have to be evaluated once their
47820c794b3Sgavinm * documentation is available.
47920c794b3Sgavinm */
48020c794b3Sgavinm int
authamd_init(cmi_hdl_t hdl,void ** datap)48120c794b3Sgavinm authamd_init(cmi_hdl_t hdl, void **datap)
48220c794b3Sgavinm {
48320c794b3Sgavinm uint_t chipid = cmi_hdl_chipid(hdl);
4848031591dSSrihari Venkatesan uint_t procnodeid = cmi_hdl_procnodeid(hdl);
4858031591dSSrihari Venkatesan struct authamd_nodeshared *sp, *osp;
48620c794b3Sgavinm uint_t family = cmi_hdl_family(hdl);
487a24e89c4SKuriakose Kuruvilla uint32_t rev = cmi_hdl_chiprev(hdl);
48820c794b3Sgavinm authamd_data_t *authamd;
48920c794b3Sgavinm uint64_t cap;
49020c794b3Sgavinm
491a24e89c4SKuriakose Kuruvilla if (authamd_ms_support_disable ||
4928031591dSSrihari Venkatesan !authamd_supported(hdl))
49320c794b3Sgavinm return (ENOTSUP);
49420c794b3Sgavinm
4957417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_MCA))
49620c794b3Sgavinm return (ENOTSUP);
49720c794b3Sgavinm
49820c794b3Sgavinm if (cmi_hdl_rdmsr(hdl, IA32_MSR_MCG_CAP, &cap) != CMI_SUCCESS)
49920c794b3Sgavinm return (ENOTSUP);
50020c794b3Sgavinm
50120c794b3Sgavinm if (!(cap & MCG_CAP_CTL_P))
50220c794b3Sgavinm return (ENOTSUP);
50320c794b3Sgavinm
50420c794b3Sgavinm authamd = *datap = kmem_zalloc(sizeof (authamd_data_t), KM_SLEEP);
50520c794b3Sgavinm cmi_hdl_hold(hdl); /* release in fini */
50620c794b3Sgavinm authamd->amd_hdl = hdl;
50720c794b3Sgavinm
5088031591dSSrihari Venkatesan if ((sp = authamd_shared[procnodeid]) == NULL) {
5098031591dSSrihari Venkatesan sp = kmem_zalloc(sizeof (struct authamd_nodeshared), KM_SLEEP);
5105667185bSSrihari Venkatesan sp->ans_chipid = chipid;
5115667185bSSrihari Venkatesan sp->ans_procnodeid = procnodeid;
5125667185bSSrihari Venkatesan sp->ans_family = family;
5135667185bSSrihari Venkatesan sp->ans_rev = rev;
514a3c46958Sgavinm membar_producer();
515a3c46958Sgavinm
5168031591dSSrihari Venkatesan osp = atomic_cas_ptr(&authamd_shared[procnodeid], NULL, sp);
51720c794b3Sgavinm if (osp != NULL) {
5188031591dSSrihari Venkatesan kmem_free(sp, sizeof (struct authamd_nodeshared));
51920c794b3Sgavinm sp = osp;
52020c794b3Sgavinm }
52120c794b3Sgavinm }
52220c794b3Sgavinm authamd->amd_shared = sp;
52320c794b3Sgavinm
52420c794b3Sgavinm return (0);
52520c794b3Sgavinm }
52620c794b3Sgavinm
52720c794b3Sgavinm /*
52820c794b3Sgavinm * cms_logout_size entry point.
52920c794b3Sgavinm */
53020c794b3Sgavinm /*ARGSUSED*/
53120c794b3Sgavinm size_t
authamd_logout_size(cmi_hdl_t hdl)53220c794b3Sgavinm authamd_logout_size(cmi_hdl_t hdl)
53320c794b3Sgavinm {
53420c794b3Sgavinm return (sizeof (struct authamd_logout));
53520c794b3Sgavinm }
53620c794b3Sgavinm
53720c794b3Sgavinm /*
53820c794b3Sgavinm * cms_mcgctl_val entry point
53920c794b3Sgavinm *
54020c794b3Sgavinm * Instead of setting all bits to 1 we can set just those for the
54120c794b3Sgavinm * error detector banks known to exist.
54220c794b3Sgavinm */
54320c794b3Sgavinm /*ARGSUSED*/
54420c794b3Sgavinm uint64_t
authamd_mcgctl_val(cmi_hdl_t hdl,int nbanks,uint64_t proposed)54520c794b3Sgavinm authamd_mcgctl_val(cmi_hdl_t hdl, int nbanks, uint64_t proposed)
54620c794b3Sgavinm {
54720c794b3Sgavinm return (nbanks < 64 ? (1ULL << nbanks) - 1 : proposed);
54820c794b3Sgavinm }
54920c794b3Sgavinm
55020c794b3Sgavinm /*
55120c794b3Sgavinm * cms_bankctl_skipinit entry point
55220c794b3Sgavinm *
55320c794b3Sgavinm * On K6 we do not initialize MC0_CTL since, reportedly, this bank (for DC)
55420c794b3Sgavinm * may produce spurious machine checks.
555a4e4e13fSgavinm *
556a4e4e13fSgavinm * Only allow a single core to setup the NorthBridge MCi_CTL register.
55720c794b3Sgavinm */
55820c794b3Sgavinm /*ARGSUSED*/
55920c794b3Sgavinm boolean_t
authamd_bankctl_skipinit(cmi_hdl_t hdl,int bank)56020c794b3Sgavinm authamd_bankctl_skipinit(cmi_hdl_t hdl, int bank)
56120c794b3Sgavinm {
56220c794b3Sgavinm authamd_data_t *authamd = cms_hdl_getcmsdata(hdl);
5635667185bSSrihari Venkatesan uint32_t rev = authamd->amd_shared->ans_rev;
56420c794b3Sgavinm
5655667185bSSrihari Venkatesan if (authamd->amd_shared->ans_family == AUTHAMD_FAMILY_6)
566a4e4e13fSgavinm return (bank == 0 ? B_TRUE : B_FALSE);
567a4e4e13fSgavinm
568a4e4e13fSgavinm if (AUTHAMD_NBONCHIP(rev) && bank == AMD_MCA_BANK_NB) {
569a4e4e13fSgavinm return (authamd_chip_once(authamd, AUTHAMD_CFGONCE_NBMCA) ==
570a4e4e13fSgavinm B_TRUE ? B_FALSE : B_TRUE);
571a4e4e13fSgavinm }
572a4e4e13fSgavinm
573a4e4e13fSgavinm return (B_FALSE);
57420c794b3Sgavinm }
57520c794b3Sgavinm
57620c794b3Sgavinm /*
57720c794b3Sgavinm * cms_bankctl_val entry point
57820c794b3Sgavinm */
57920c794b3Sgavinm uint64_t
authamd_bankctl_val(cmi_hdl_t hdl,int bank,uint64_t proposed)58020c794b3Sgavinm authamd_bankctl_val(cmi_hdl_t hdl, int bank, uint64_t proposed)
58120c794b3Sgavinm {
58220c794b3Sgavinm authamd_data_t *authamd = cms_hdl_getcmsdata(hdl);
5835667185bSSrihari Venkatesan uint32_t rev = authamd->amd_shared->ans_rev;
58420c794b3Sgavinm uint64_t val = proposed;
58520c794b3Sgavinm
58620c794b3Sgavinm /*
58720c794b3Sgavinm * The Intel MCA says we can write all 1's to enable #MC for
58820c794b3Sgavinm * all errors, and AMD docs say much the same. But, depending
58920c794b3Sgavinm * perhaps on other config registers, taking machine checks
59020c794b3Sgavinm * for some errors such as GART TLB errors and master/target
59120c794b3Sgavinm * aborts may be bad - they set UC and sometime also PCC, but
59220c794b3Sgavinm * we should not always panic for these error types.
59320c794b3Sgavinm *
59420c794b3Sgavinm * Our cms_error_action entry point can suppress such panics,
59520c794b3Sgavinm * however we can also use the cms_bankctl_val entry point to
59620c794b3Sgavinm * veto enabling of some of the known villains in the first place.
59720c794b3Sgavinm */
59820c794b3Sgavinm if (bank == AMD_MCA_BANK_NB && AUTHAMD_NOGARTTBLWLK_MC(rev))
59920c794b3Sgavinm val &= ~AMD_NB_EN_GARTTBLWK;
60020c794b3Sgavinm
60120c794b3Sgavinm return (val);
60220c794b3Sgavinm }
60320c794b3Sgavinm
60420c794b3Sgavinm /*
60525f47677Sgavinm * Bits to add to NB MCA config (after watchdog config).
60625f47677Sgavinm */
60725f47677Sgavinm uint32_t authamd_nb_mcacfg_add = AMD_NB_CFG_ADD_CMN;
60825f47677Sgavinm
60925f47677Sgavinm /*
61025f47677Sgavinm * Bits to remove from NB MCA config (after watchdog config)
61125f47677Sgavinm */
61225f47677Sgavinm uint32_t authamd_nb_mcacfg_remove = AMD_NB_CFG_REMOVE_CMN;
61325f47677Sgavinm
61425f47677Sgavinm /*
61525f47677Sgavinm * NB Watchdog policy, and rate we use if enabling.
61625f47677Sgavinm */
61725f47677Sgavinm enum {
61825f47677Sgavinm AUTHAMD_NB_WDOG_LEAVEALONE,
61925f47677Sgavinm AUTHAMD_NB_WDOG_DISABLE,
62025f47677Sgavinm AUTHAMD_NB_WDOG_ENABLE_IF_DISABLED,
62125f47677Sgavinm AUTHAMD_NB_WDOG_ENABLE_FORCE_RATE
62225f47677Sgavinm } authamd_nb_watchdog_policy = AUTHAMD_NB_WDOG_ENABLE_IF_DISABLED;
62325f47677Sgavinm
62425f47677Sgavinm uint32_t authamd_nb_mcacfg_wdog = AMD_NB_CFG_WDOGTMRCNTSEL_4095 |
62525f47677Sgavinm AMD_NB_CFG_WDOGTMRBASESEL_1MS;
62625f47677Sgavinm
62725f47677Sgavinm /*
62825f47677Sgavinm * Per-core cache scrubbing policy and rates.
62925f47677Sgavinm */
63025f47677Sgavinm enum {
63125f47677Sgavinm AUTHAMD_SCRUB_BIOSDEFAULT, /* leave as BIOS configured */
63225f47677Sgavinm AUTHAMD_SCRUB_FIXED, /* assign our chosen rate */
63325f47677Sgavinm AUTHAMD_SCRUB_MAX /* use higher of ours and BIOS rate */
63425f47677Sgavinm } authamd_scrub_policy = AUTHAMD_SCRUB_MAX;
63525f47677Sgavinm
63625f47677Sgavinm uint32_t authamd_scrub_rate_dcache = 0xf; /* 64K per 0.67 seconds */
63725f47677Sgavinm uint32_t authamd_scrub_rate_l2cache = 0xe; /* 1MB per 5.3 seconds */
63825f47677Sgavinm uint32_t authamd_scrub_rate_l3cache = 0xd; /* 1MB per 2.7 seconds */
63925f47677Sgavinm
64025f47677Sgavinm static uint32_t
authamd_scrubrate(uint32_t osrate,uint32_t biosrate,const char * varnm)64125f47677Sgavinm authamd_scrubrate(uint32_t osrate, uint32_t biosrate, const char *varnm)
64225f47677Sgavinm {
64325f47677Sgavinm uint32_t rate;
64425f47677Sgavinm
64525f47677Sgavinm if (osrate > AMD_NB_SCRUBCTL_RATE_MAX) {
64625f47677Sgavinm cmn_err(CE_WARN, "%s is too large, resetting to 0x%x\n",
64725f47677Sgavinm varnm, AMD_NB_SCRUBCTL_RATE_MAX);
64825f47677Sgavinm osrate = AMD_NB_SCRUBCTL_RATE_MAX;
64925f47677Sgavinm }
65025f47677Sgavinm
65125f47677Sgavinm switch (authamd_scrub_policy) {
65225f47677Sgavinm case AUTHAMD_SCRUB_FIXED:
65325f47677Sgavinm rate = osrate;
65425f47677Sgavinm break;
65525f47677Sgavinm
65625f47677Sgavinm default:
65725f47677Sgavinm cmn_err(CE_WARN, "Unknown authamd_scrub_policy %d - "
65825f47677Sgavinm "using default policy of AUTHAMD_SCRUB_MAX",
65925f47677Sgavinm authamd_scrub_policy);
66025f47677Sgavinm /*FALLTHRU*/
66125f47677Sgavinm
66225f47677Sgavinm case AUTHAMD_SCRUB_MAX:
66325f47677Sgavinm if (osrate != 0 && biosrate != 0)
66425f47677Sgavinm rate = MIN(osrate, biosrate); /* small is fast */
66525f47677Sgavinm else
66625f47677Sgavinm rate = osrate ? osrate : biosrate;
66725f47677Sgavinm }
66825f47677Sgavinm
66925f47677Sgavinm return (rate);
67025f47677Sgavinm }
67125f47677Sgavinm
67225f47677Sgavinm /*
67320c794b3Sgavinm * cms_mca_init entry point.
67420c794b3Sgavinm */
67520c794b3Sgavinm /*ARGSUSED*/
67620c794b3Sgavinm void
authamd_mca_init(cmi_hdl_t hdl,int nbanks)67720c794b3Sgavinm authamd_mca_init(cmi_hdl_t hdl, int nbanks)
67820c794b3Sgavinm {
67920c794b3Sgavinm authamd_data_t *authamd = cms_hdl_getcmsdata(hdl);
6805667185bSSrihari Venkatesan uint32_t rev = authamd->amd_shared->ans_rev;
6815667185bSSrihari Venkatesan uint_t procnodeid = authamd->amd_shared->ans_procnodeid;
68220c794b3Sgavinm
68320c794b3Sgavinm /*
68420c794b3Sgavinm * On chips with a NB online spare control register take control
68520c794b3Sgavinm * and clear ECC counts.
68620c794b3Sgavinm */
68720c794b3Sgavinm if (AUTHAMD_HAS_ONLINESPARECTL(rev) &&
68820c794b3Sgavinm authamd_chip_once(authamd, AUTHAMD_CFGONCE_ONLNSPRCFG)) {
68920c794b3Sgavinm authamd_clear_ecccnt(authamd, B_TRUE);
69020c794b3Sgavinm }
69120c794b3Sgavinm
69220c794b3Sgavinm /*
69320c794b3Sgavinm * And since we are claiming the telemetry stop the BIOS receiving
69420c794b3Sgavinm * an SMI on NB threshold overflow.
69520c794b3Sgavinm */
69620c794b3Sgavinm if (AUTHAMD_NBMISC_NUM(rev) &&
69720c794b3Sgavinm authamd_chip_once(authamd, AUTHAMD_CFGONCE_NBTHRESH)) {
69820c794b3Sgavinm union mcmsr_nbmisc nbm;
69920c794b3Sgavinm int i;
70020c794b3Sgavinm
70120c794b3Sgavinm authamd_bankstatus_prewrite(hdl, authamd);
70220c794b3Sgavinm
70320c794b3Sgavinm for (i = 0; i < AUTHAMD_NBMISC_NUM(rev); i++) {
70420c794b3Sgavinm if (cmi_hdl_rdmsr(hdl, MC_MSR_NB_MISC(i),
70520c794b3Sgavinm (uint64_t *)&nbm) != CMI_SUCCESS)
70620c794b3Sgavinm continue;
70720c794b3Sgavinm
70820c794b3Sgavinm if (X86_CHIPREV_ATLEAST(rev, X86_CHIPREV_AMD_F_REV_F) &&
70920c794b3Sgavinm MCMSR_FIELD_F_revFG(&nbm, mcmisc_Valid) &&
71020c794b3Sgavinm MCMSR_FIELD_F_revFG(&nbm, mcmisc_CntP)) {
71120c794b3Sgavinm MCMSR_FIELD_F_revFG(&nbm, mcmisc_IntType) = 0;
71220c794b3Sgavinm } else if (X86_CHIPREV_ATLEAST(rev,
71320c794b3Sgavinm X86_CHIPREV_AMD_10_REV_A) &&
71420c794b3Sgavinm MCMSR_FIELD_10_revAB(&nbm, mcmisc_Valid) &&
71520c794b3Sgavinm MCMSR_FIELD_10_revAB(&nbm, mcmisc_CntP)) {
71620c794b3Sgavinm MCMSR_FIELD_10_revAB(&nbm, mcmisc_IntType) = 0;
71720c794b3Sgavinm }
71820c794b3Sgavinm
71920c794b3Sgavinm (void) cmi_hdl_wrmsr(hdl, MC_MSR_NB_MISC(i),
72020c794b3Sgavinm MCMSR_VAL(&nbm));
72120c794b3Sgavinm }
72220c794b3Sgavinm
72320c794b3Sgavinm authamd_bankstatus_postwrite(hdl, authamd);
72420c794b3Sgavinm }
72525f47677Sgavinm
72625f47677Sgavinm /*
72725f47677Sgavinm * NB MCA Configuration Register.
72825f47677Sgavinm */
72925f47677Sgavinm if (AUTHAMD_DO_NBMCACFG(rev) &&
73025f47677Sgavinm authamd_chip_once(authamd, AUTHAMD_CFGONCE_NBMCACFG)) {
7318031591dSSrihari Venkatesan uint32_t val = authamd_pcicfg_read(procnodeid, MC_FUNC_MISCCTL,
73225f47677Sgavinm MC_CTL_REG_NBCFG);
73325f47677Sgavinm
73425f47677Sgavinm switch (authamd_nb_watchdog_policy) {
73525f47677Sgavinm case AUTHAMD_NB_WDOG_LEAVEALONE:
73625f47677Sgavinm break;
73725f47677Sgavinm
73825f47677Sgavinm case AUTHAMD_NB_WDOG_DISABLE:
73925f47677Sgavinm val &= ~(AMD_NB_CFG_WDOGTMRBASESEL_MASK |
74025f47677Sgavinm AMD_NB_CFG_WDOGTMRCNTSEL_MASK);
74125f47677Sgavinm val |= AMD_NB_CFG_WDOGTMRDIS;
74225f47677Sgavinm break;
74325f47677Sgavinm
74425f47677Sgavinm default:
74525f47677Sgavinm cmn_err(CE_NOTE, "authamd_nb_watchdog_policy=%d "
74625f47677Sgavinm "unrecognised, using default policy",
74725f47677Sgavinm authamd_nb_watchdog_policy);
74825f47677Sgavinm /*FALLTHRU*/
74925f47677Sgavinm
75025f47677Sgavinm case AUTHAMD_NB_WDOG_ENABLE_IF_DISABLED:
75125f47677Sgavinm if (!(val & AMD_NB_CFG_WDOGTMRDIS))
75225f47677Sgavinm break; /* if enabled leave rate intact */
75325f47677Sgavinm /*FALLTHRU*/
75425f47677Sgavinm
75525f47677Sgavinm case AUTHAMD_NB_WDOG_ENABLE_FORCE_RATE:
75625f47677Sgavinm val &= ~(AMD_NB_CFG_WDOGTMRBASESEL_MASK |
75725f47677Sgavinm AMD_NB_CFG_WDOGTMRCNTSEL_MASK |
75825f47677Sgavinm AMD_NB_CFG_WDOGTMRDIS);
75925f47677Sgavinm val |= authamd_nb_mcacfg_wdog;
76025f47677Sgavinm break;
76125f47677Sgavinm }
76225f47677Sgavinm
76325f47677Sgavinm /*
76425f47677Sgavinm * Bit 0 of the NB MCA Config register is reserved on family
76525f47677Sgavinm * 0x10.
76625f47677Sgavinm */
76725f47677Sgavinm if (X86_CHIPREV_ATLEAST(rev, X86_CHIPREV_AMD_10_REV_A))
76825f47677Sgavinm authamd_nb_mcacfg_add &= ~AMD_NB_CFG_CPUECCERREN;
76925f47677Sgavinm
77025f47677Sgavinm val &= ~authamd_nb_mcacfg_remove;
77125f47677Sgavinm val |= authamd_nb_mcacfg_add;
77225f47677Sgavinm
7738031591dSSrihari Venkatesan authamd_pcicfg_write(procnodeid, MC_FUNC_MISCCTL,
7748031591dSSrihari Venkatesan MC_CTL_REG_NBCFG, val);
77525f47677Sgavinm }
77625f47677Sgavinm
77725f47677Sgavinm /*
77825f47677Sgavinm * Cache scrubbing. We can't enable DRAM scrubbing since
77925f47677Sgavinm * we don't know the DRAM base for this node.
78025f47677Sgavinm */
78125f47677Sgavinm if (AUTHAMD_HAS_CHIPSCRUB(rev) &&
78225f47677Sgavinm authamd_scrub_policy != AUTHAMD_SCRUB_BIOSDEFAULT &&
78325f47677Sgavinm authamd_chip_once(authamd, AUTHAMD_CFGONCE_CACHESCRUB)) {
7848031591dSSrihari Venkatesan uint32_t val = authamd_pcicfg_read(procnodeid, MC_FUNC_MISCCTL,
78525f47677Sgavinm MC_CTL_REG_SCRUBCTL);
78625f47677Sgavinm int l3cap = 0;
78725f47677Sgavinm
78825f47677Sgavinm if (AUTHAMD_L3CAPABLE(rev)) {
7898031591dSSrihari Venkatesan l3cap = (authamd_pcicfg_read(procnodeid,
7908031591dSSrihari Venkatesan MC_FUNC_MISCCTL, MC_CTL_REG_NBCAP) &
7918031591dSSrihari Venkatesan MC_NBCAP_L3CAPABLE) != 0;
79225f47677Sgavinm }
79325f47677Sgavinm
79425f47677Sgavinm authamd_scrub_rate_dcache =
79525f47677Sgavinm authamd_scrubrate(authamd_scrub_rate_dcache,
79625f47677Sgavinm (val & AMD_NB_SCRUBCTL_DC_MASK) >> AMD_NB_SCRUBCTL_DC_SHIFT,
79725f47677Sgavinm "authamd_scrub_rate_dcache");
79825f47677Sgavinm
79925f47677Sgavinm authamd_scrub_rate_l2cache =
80025f47677Sgavinm authamd_scrubrate(authamd_scrub_rate_l2cache,
80125f47677Sgavinm (val & AMD_NB_SCRUBCTL_L2_MASK) >> AMD_NB_SCRUBCTL_L2_SHIFT,
80225f47677Sgavinm "authamd_scrub_rate_l2cache");
80325f47677Sgavinm
80425f47677Sgavinm authamd_scrub_rate_l3cache = l3cap ?
80525f47677Sgavinm authamd_scrubrate(authamd_scrub_rate_l3cache,
80625f47677Sgavinm (val & AMD_NB_SCRUBCTL_L3_MASK) >> AMD_NB_SCRUBCTL_L3_SHIFT,
80725f47677Sgavinm "authamd_scrub_rate_l3cache") : 0;
80825f47677Sgavinm
80925f47677Sgavinm val = AMD_NB_MKSCRUBCTL(authamd_scrub_rate_l3cache,
81025f47677Sgavinm authamd_scrub_rate_dcache, authamd_scrub_rate_l2cache,
81125f47677Sgavinm val & AMD_NB_SCRUBCTL_DRAM_MASK);
81225f47677Sgavinm
8138031591dSSrihari Venkatesan authamd_pcicfg_write(procnodeid, MC_FUNC_MISCCTL,
81425f47677Sgavinm MC_CTL_REG_SCRUBCTL, val);
81525f47677Sgavinm }
81625f47677Sgavinm
8175667185bSSrihari Venkatesan /*
8185667185bSSrihari Venkatesan * ECC symbol size. Defaults to 4.
8195667185bSSrihari Venkatesan * Set to 8 on systems that support x8 ECC and have it enabled.
8205667185bSSrihari Venkatesan */
8215667185bSSrihari Venkatesan if (authamd_chip_once(authamd, AUTHAMD_CFGONCE_ECCSYMSZ)) {
8225667185bSSrihari Venkatesan authamd->amd_shared->ans_eccsymsz = "C4";
8235667185bSSrihari Venkatesan if (AUTHAMD_SUPPORTS_X8ECC(rev) &&
8245667185bSSrihari Venkatesan (authamd_pcicfg_read(procnodeid, MC_FUNC_MISCCTL,
8255667185bSSrihari Venkatesan MC_CTL_REG_EXTNBCFG) & MC_EXTNBCFG_ECCSYMSZ))
8265667185bSSrihari Venkatesan authamd->amd_shared->ans_eccsymsz = "C8";
8275667185bSSrihari Venkatesan }
82825f47677Sgavinm }
82925f47677Sgavinm
83025f47677Sgavinm /*
83125f47677Sgavinm * cms_poll_ownermask entry point.
83225f47677Sgavinm */
83325f47677Sgavinm uint64_t
authamd_poll_ownermask(cmi_hdl_t hdl,hrtime_t pintvl)83425f47677Sgavinm authamd_poll_ownermask(cmi_hdl_t hdl, hrtime_t pintvl)
83525f47677Sgavinm {
83625f47677Sgavinm authamd_data_t *authamd = cms_hdl_getcmsdata(hdl);
8375667185bSSrihari Venkatesan struct authamd_nodeshared *ansp = authamd->amd_shared;
83825f47677Sgavinm hrtime_t now = gethrtime_waitfree();
8395667185bSSrihari Venkatesan hrtime_t last = ansp->ans_poll_timestamp;
84025f47677Sgavinm int dopoll = 0;
84125f47677Sgavinm
84225f47677Sgavinm if (now - last > 2 * pintvl || last == 0) {
8435667185bSSrihari Venkatesan ansp->ans_pollowner = hdl;
84425f47677Sgavinm dopoll = 1;
8455667185bSSrihari Venkatesan } else if (ansp->ans_pollowner == hdl) {
84625f47677Sgavinm dopoll = 1;
84725f47677Sgavinm }
84825f47677Sgavinm
84925f47677Sgavinm if (dopoll)
8505667185bSSrihari Venkatesan ansp->ans_poll_timestamp = now;
85125f47677Sgavinm
85225f47677Sgavinm return (dopoll ? -1ULL : ~(1 << AMD_MCA_BANK_NB));
85325f47677Sgavinm
85420c794b3Sgavinm }
85520c794b3Sgavinm
85620c794b3Sgavinm /*
85720c794b3Sgavinm * cms_bank_logout entry point.
85820c794b3Sgavinm */
85920c794b3Sgavinm /*ARGSUSED*/
86020c794b3Sgavinm void
authamd_bank_logout(cmi_hdl_t hdl,int bank,uint64_t status,uint64_t addr,uint64_t misc,void * mslogout)86120c794b3Sgavinm authamd_bank_logout(cmi_hdl_t hdl, int bank, uint64_t status,
86220c794b3Sgavinm uint64_t addr, uint64_t misc, void *mslogout)
86320c794b3Sgavinm {
86420c794b3Sgavinm authamd_data_t *authamd = cms_hdl_getcmsdata(hdl);
86520c794b3Sgavinm struct authamd_logout *msl = mslogout;
8665667185bSSrihari Venkatesan uint32_t rev = authamd->amd_shared->ans_rev;
86720c794b3Sgavinm
86820c794b3Sgavinm if (msl == NULL)
86920c794b3Sgavinm return;
87020c794b3Sgavinm
87120c794b3Sgavinm /*
87220c794b3Sgavinm * For main memory ECC errors on revisions with an Online Spare
87320c794b3Sgavinm * Control Register grab the ECC counts by channel and chip-select
87420c794b3Sgavinm * and reset them to 0.
87520c794b3Sgavinm */
87620c794b3Sgavinm if (AUTHAMD_MEMECC_RECOGNISED(rev) &&
87720c794b3Sgavinm AUTHAMD_IS_MEMECCERR(bank, status) &&
87820c794b3Sgavinm AUTHAMD_HAS_ONLINESPARECTL(rev)) {
87920c794b3Sgavinm if (authamd_read_ecccnt(authamd, msl))
88020c794b3Sgavinm authamd_clear_ecccnt(authamd, B_FALSE);
88120c794b3Sgavinm }
88220c794b3Sgavinm }
88320c794b3Sgavinm
88420c794b3Sgavinm /*
88520c794b3Sgavinm * cms_error_action entry point
88620c794b3Sgavinm */
88720c794b3Sgavinm
88820c794b3Sgavinm int authamd_forgive_uc = 0; /* For test/debug only */
88920c794b3Sgavinm int authamd_forgive_pcc = 0; /* For test/debug only */
89020c794b3Sgavinm int authamd_fake_poison = 0; /* For test/debug only */
89120c794b3Sgavinm
89220c794b3Sgavinm /*ARGSUSED*/
89320c794b3Sgavinm uint32_t
authamd_error_action(cmi_hdl_t hdl,int ismc,int bank,uint64_t status,uint64_t addr,uint64_t misc,void * mslogout)89420c794b3Sgavinm authamd_error_action(cmi_hdl_t hdl, int ismc, int bank,
89520c794b3Sgavinm uint64_t status, uint64_t addr, uint64_t misc, void *mslogout)
89620c794b3Sgavinm {
89720c794b3Sgavinm authamd_error_disp_t *disp;
89820c794b3Sgavinm uint32_t rv = 0;
89920c794b3Sgavinm
90020c794b3Sgavinm if (authamd_forgive_uc)
90120c794b3Sgavinm rv |= CMS_ERRSCOPE_CLEARED_UC;
90220c794b3Sgavinm
90320c794b3Sgavinm if (authamd_forgive_pcc)
90420c794b3Sgavinm rv |= CMS_ERRSCOPE_CURCONTEXT_OK;
90520c794b3Sgavinm
90620c794b3Sgavinm if (authamd_fake_poison && status & MSR_MC_STATUS_UC)
90720c794b3Sgavinm rv |= CMS_ERRSCOPE_POISONED;
90820c794b3Sgavinm
90920c794b3Sgavinm if (rv)
91020c794b3Sgavinm return (rv);
91120c794b3Sgavinm
912c84b7bbeSAdrian Frost disp = authamd_disp_match(hdl, ismc, bank, status, addr, misc,
913c84b7bbeSAdrian Frost mslogout);
91420c794b3Sgavinm
91520c794b3Sgavinm if (disp == &authamd_gart_disp) {
91620c794b3Sgavinm /*
91720c794b3Sgavinm * GART walk errors set UC and possibly PCC (if source CPU)
91820c794b3Sgavinm * but should not be regarded as terminal.
91920c794b3Sgavinm */
92020c794b3Sgavinm return (CMS_ERRSCOPE_IGNORE_ERR);
92120c794b3Sgavinm }
92220c794b3Sgavinm
92320c794b3Sgavinm /*
92420c794b3Sgavinm * May also want to consider master abort and target abort. These
92520c794b3Sgavinm * also set UC and PCC (if src CPU) but the requester gets -1
92620c794b3Sgavinm * and I believe the IO stuff in Solaris will handle that.
92720c794b3Sgavinm */
92820c794b3Sgavinm
92920c794b3Sgavinm return (rv);
93020c794b3Sgavinm }
93120c794b3Sgavinm
93220c794b3Sgavinm /*
93320c794b3Sgavinm * cms_disp_match entry point
93420c794b3Sgavinm */
93520c794b3Sgavinm /*ARGSUSED*/
93620c794b3Sgavinm cms_cookie_t
authamd_disp_match(cmi_hdl_t hdl,int ismc,int bank,uint64_t status,uint64_t addr,uint64_t misc,void * mslogout)937c84b7bbeSAdrian Frost authamd_disp_match(cmi_hdl_t hdl, int ismc, int bank, uint64_t status,
93820c794b3Sgavinm uint64_t addr, uint64_t misc, void *mslogout)
93920c794b3Sgavinm {
94020c794b3Sgavinm authamd_data_t *authamd = cms_hdl_getcmsdata(hdl);
94120c794b3Sgavinm /* uint16_t errcode = MCAX86_ERRCODE(status); */
94220c794b3Sgavinm uint16_t exterrcode = AMD_EXT_ERRCODE(status);
9435667185bSSrihari Venkatesan uint32_t rev = authamd->amd_shared->ans_rev;
94420c794b3Sgavinm
94520c794b3Sgavinm /*
94620c794b3Sgavinm * Recognise main memory ECC errors
94720c794b3Sgavinm */
94820c794b3Sgavinm if (AUTHAMD_MEMECC_RECOGNISED(rev) &&
94920c794b3Sgavinm AUTHAMD_IS_MEMECCERR(bank, status)) {
95020c794b3Sgavinm if (status & AMD_BANK_STAT_CECC) {
95120c794b3Sgavinm return (exterrcode == 0 ? &authamd_memce_disp :
95220c794b3Sgavinm &authamd_ckmemce_disp);
95320c794b3Sgavinm } else if (status & AMD_BANK_STAT_UECC) {
95420c794b3Sgavinm return (exterrcode == 0 ? &authamd_memue_disp :
95520c794b3Sgavinm &authamd_ckmemue_disp);
95620c794b3Sgavinm }
95720c794b3Sgavinm }
95820c794b3Sgavinm
95920c794b3Sgavinm /*
96020c794b3Sgavinm * Recognise GART walk errors
96120c794b3Sgavinm */
96220c794b3Sgavinm if (AUTHAMD_NOGARTTBLWLK_MC(rev) && AUTHAMD_IS_GARTERR(bank, status))
96320c794b3Sgavinm return (&authamd_gart_disp);
96420c794b3Sgavinm
96520c794b3Sgavinm return (NULL);
96620c794b3Sgavinm }
96720c794b3Sgavinm
96820c794b3Sgavinm /*
96920c794b3Sgavinm * cms_ereport_class entry point
97020c794b3Sgavinm */
97120c794b3Sgavinm /*ARGSUSED*/
97220c794b3Sgavinm void
authamd_ereport_class(cmi_hdl_t hdl,cms_cookie_t mscookie,const char ** cpuclsp,const char ** leafclsp)97320c794b3Sgavinm authamd_ereport_class(cmi_hdl_t hdl, cms_cookie_t mscookie,
97420c794b3Sgavinm const char **cpuclsp, const char **leafclsp)
97520c794b3Sgavinm {
97620c794b3Sgavinm const authamd_error_disp_t *aed = mscookie;
97720c794b3Sgavinm
97820c794b3Sgavinm if (aed == NULL)
97920c794b3Sgavinm return;
98020c794b3Sgavinm
98120c794b3Sgavinm if (aed->aad_subclass != NULL)
98220c794b3Sgavinm *cpuclsp = aed->aad_subclass;
98320c794b3Sgavinm if (aed->aad_leafclass != NULL)
98420c794b3Sgavinm *leafclsp = aed->aad_leafclass;
98520c794b3Sgavinm }
98620c794b3Sgavinm
98720c794b3Sgavinm /*ARGSUSED*/
98820c794b3Sgavinm static void
authamd_ereport_add_resource(cmi_hdl_t hdl,authamd_data_t * authamd,nvlist_t * ereport,nv_alloc_t * nva,void * mslogout)98920c794b3Sgavinm authamd_ereport_add_resource(cmi_hdl_t hdl, authamd_data_t *authamd,
99020c794b3Sgavinm nvlist_t *ereport, nv_alloc_t *nva, void *mslogout)
99120c794b3Sgavinm {
99220c794b3Sgavinm nvlist_t *elems[AUTHAMD_DRAM_NCHANNEL * AUTHAMD_DRAM_NCS];
99320c794b3Sgavinm uint8_t counts[AUTHAMD_DRAM_NCHANNEL * AUTHAMD_DRAM_NCS];
99420c794b3Sgavinm authamd_logout_t *msl;
99520c794b3Sgavinm nvlist_t *nvl;
99620c794b3Sgavinm int nelems = 0;
9978031591dSSrihari Venkatesan int i, chan, cs, mc;
998074bb90dSTom Pothier nvlist_t *board_list = NULL;
99920c794b3Sgavinm
100020c794b3Sgavinm if ((msl = mslogout) == NULL)
100120c794b3Sgavinm return;
100220c794b3Sgavinm
10038031591dSSrihari Venkatesan /* Assume all processors have the same number of nodes */
10045667185bSSrihari Venkatesan mc = authamd->amd_shared->ans_procnodeid %
10058031591dSSrihari Venkatesan cpuid_get_procnodes_per_pkg(CPU);
10068031591dSSrihari Venkatesan
100720c794b3Sgavinm for (chan = 0; chan < AUTHAMD_DRAM_NCHANNEL; chan++) {
100820c794b3Sgavinm for (cs = 0; cs < AUTHAMD_DRAM_NCS; cs++) {
100920c794b3Sgavinm if (msl->aal_eccerrcnt[chan][cs] == 0)
101020c794b3Sgavinm continue;
101120c794b3Sgavinm
101220c794b3Sgavinm if ((nvl = fm_nvlist_create(nva)) == NULL)
101320c794b3Sgavinm continue;
101420c794b3Sgavinm
101520c794b3Sgavinm elems[nelems] = nvl;
101620c794b3Sgavinm counts[nelems++] = msl->aal_eccerrcnt[chan][cs];
101720c794b3Sgavinm
1018074bb90dSTom Pothier if (!x86gentopo_legacy) {
1019074bb90dSTom Pothier board_list = cmi_hdl_smb_bboard(hdl);
1020074bb90dSTom Pothier if (board_list == NULL)
1021074bb90dSTom Pothier continue;
1022074bb90dSTom Pothier fm_fmri_hc_create(nvl, FM_HC_SCHEME_VERSION,
1023074bb90dSTom Pothier NULL, NULL, board_list, 4,
1024074bb90dSTom Pothier "chip", cmi_hdl_smb_chipid(hdl),
1025074bb90dSTom Pothier "memory-controller", 0,
1026074bb90dSTom Pothier "dram-channel", chan,
1027074bb90dSTom Pothier "chip-select", cs);
1028074bb90dSTom Pothier } else {
1029074bb90dSTom Pothier fm_fmri_hc_set(nvl, FM_HC_SCHEME_VERSION,
1030074bb90dSTom Pothier NULL, NULL, 5,
103120c794b3Sgavinm "motherboard", 0,
10325667185bSSrihari Venkatesan "chip", authamd->amd_shared->ans_chipid,
10338031591dSSrihari Venkatesan "memory-controller", mc,
103420c794b3Sgavinm "dram-channel", chan,
103520c794b3Sgavinm "chip-select", cs);
103620c794b3Sgavinm }
103720c794b3Sgavinm }
1038074bb90dSTom Pothier }
103920c794b3Sgavinm
104020c794b3Sgavinm if (nelems == 0)
104120c794b3Sgavinm return;
104220c794b3Sgavinm
104320c794b3Sgavinm fm_payload_set(ereport, FM_EREPORT_GENAMD_PAYLOAD_NAME_RESOURCE,
104420c794b3Sgavinm DATA_TYPE_NVLIST_ARRAY, nelems, elems,
104520c794b3Sgavinm NULL);
104620c794b3Sgavinm
104720c794b3Sgavinm fm_payload_set(ereport, FM_EREPORT_GENAMD_PAYLOAD_NAME_RESOURCECNT,
104820c794b3Sgavinm DATA_TYPE_UINT8_ARRAY, nelems, &counts[0],
104920c794b3Sgavinm NULL);
105020c794b3Sgavinm
105120c794b3Sgavinm for (i = 0; i < nelems; i++)
105220c794b3Sgavinm fm_nvlist_destroy(elems[i], nva ? FM_NVA_RETAIN : FM_NVA_FREE);
105320c794b3Sgavinm }
105420c794b3Sgavinm
105520c794b3Sgavinm /*
105620c794b3Sgavinm * cms_ereport_add_logout entry point
105720c794b3Sgavinm */
105820c794b3Sgavinm /*ARGSUSED*/
105920c794b3Sgavinm void
authamd_ereport_add_logout(cmi_hdl_t hdl,nvlist_t * ereport,nv_alloc_t * nva,int bank,uint64_t status,uint64_t addr,uint64_t misc,void * mslogout,cms_cookie_t mscookie)106020c794b3Sgavinm authamd_ereport_add_logout(cmi_hdl_t hdl, nvlist_t *ereport, nv_alloc_t *nva,
106120c794b3Sgavinm int bank, uint64_t status, uint64_t addr, uint64_t misc,
106220c794b3Sgavinm void *mslogout, cms_cookie_t mscookie)
106320c794b3Sgavinm {
106420c794b3Sgavinm authamd_data_t *authamd = cms_hdl_getcmsdata(hdl);
106520c794b3Sgavinm const authamd_error_disp_t *aed = mscookie;
106620c794b3Sgavinm uint64_t members;
106720c794b3Sgavinm
106820c794b3Sgavinm if (aed == NULL)
106920c794b3Sgavinm return;
107020c794b3Sgavinm
107120c794b3Sgavinm members = aed->aad_ereport_members;
107220c794b3Sgavinm
107320c794b3Sgavinm if (members & FM_EREPORT_GENAMD_PAYLOAD_FLAG_SYND) {
107420c794b3Sgavinm fm_payload_set(ereport, FM_EREPORT_GENAMD_PAYLOAD_NAME_SYND,
107520c794b3Sgavinm DATA_TYPE_UINT16, (uint16_t)AMD_BANK_SYND(status),
107620c794b3Sgavinm NULL);
107720c794b3Sgavinm
107820c794b3Sgavinm if (members & FM_EREPORT_GENAMD_PAYLOAD_FLAG_SYNDTYPE) {
107920c794b3Sgavinm fm_payload_set(ereport,
108020c794b3Sgavinm FM_EREPORT_GENAMD_PAYLOAD_NAME_SYNDTYPE,
108120c794b3Sgavinm DATA_TYPE_STRING, "E",
108220c794b3Sgavinm NULL);
108320c794b3Sgavinm }
108420c794b3Sgavinm }
108520c794b3Sgavinm
108620c794b3Sgavinm if (members & FM_EREPORT_GENAMD_PAYLOAD_FLAG_CKSYND) {
108720c794b3Sgavinm fm_payload_set(ereport, FM_EREPORT_GENAMD_PAYLOAD_NAME_CKSYND,
108820c794b3Sgavinm DATA_TYPE_UINT16, (uint16_t)AMD_NB_STAT_CKSYND(status),
108920c794b3Sgavinm NULL);
109020c794b3Sgavinm
109120c794b3Sgavinm if (members & FM_EREPORT_GENAMD_PAYLOAD_FLAG_SYNDTYPE) {
109220c794b3Sgavinm fm_payload_set(ereport,
109320c794b3Sgavinm FM_EREPORT_GENAMD_PAYLOAD_NAME_SYNDTYPE,
10945667185bSSrihari Venkatesan DATA_TYPE_STRING, authamd->amd_shared->ans_eccsymsz,
109520c794b3Sgavinm NULL);
109620c794b3Sgavinm }
109720c794b3Sgavinm }
109820c794b3Sgavinm
109920c794b3Sgavinm if (members & FM_EREPORT_GENAMD_PAYLOAD_FLAG_RESOURCE &&
110020c794b3Sgavinm status & MSR_MC_STATUS_ADDRV) {
110120c794b3Sgavinm authamd_ereport_add_resource(hdl, authamd, ereport, nva,
110220c794b3Sgavinm mslogout);
110320c794b3Sgavinm }
110420c794b3Sgavinm }
110520c794b3Sgavinm
110620c794b3Sgavinm /*
110720c794b3Sgavinm * cms_msrinject entry point
110820c794b3Sgavinm */
110920c794b3Sgavinm cms_errno_t
authamd_msrinject(cmi_hdl_t hdl,uint_t msr,uint64_t val)111020c794b3Sgavinm authamd_msrinject(cmi_hdl_t hdl, uint_t msr, uint64_t val)
111120c794b3Sgavinm {
111220c794b3Sgavinm authamd_data_t *authamd = cms_hdl_getcmsdata(hdl);
111320c794b3Sgavinm cms_errno_t rv = CMSERR_BADMSRWRITE;
111420c794b3Sgavinm
111520c794b3Sgavinm authamd_bankstatus_prewrite(hdl, authamd);
111620c794b3Sgavinm if (cmi_hdl_wrmsr(hdl, msr, val) == CMI_SUCCESS)
111720c794b3Sgavinm rv = CMS_SUCCESS;
111820c794b3Sgavinm authamd_bankstatus_postwrite(hdl, authamd);
111920c794b3Sgavinm
112020c794b3Sgavinm return (rv);
112120c794b3Sgavinm }
112220c794b3Sgavinm
1123c84b7bbeSAdrian Frost cms_api_ver_t _cms_api_version = CMS_API_VERSION_2;
112420c794b3Sgavinm
112520c794b3Sgavinm const cms_ops_t _cms_ops = {
112620c794b3Sgavinm authamd_init, /* cms_init */
112720c794b3Sgavinm NULL, /* cms_post_startup */
112820c794b3Sgavinm NULL, /* cms_post_mpstartup */
112920c794b3Sgavinm authamd_logout_size, /* cms_logout_size */
113020c794b3Sgavinm authamd_mcgctl_val, /* cms_mcgctl_val */
113120c794b3Sgavinm authamd_bankctl_skipinit, /* cms_bankctl_skipinit */
113220c794b3Sgavinm authamd_bankctl_val, /* cms_bankctl_val */
113320c794b3Sgavinm NULL, /* cms_bankstatus_skipinit */
113420c794b3Sgavinm NULL, /* cms_bankstatus_val */
113520c794b3Sgavinm authamd_mca_init, /* cms_mca_init */
113625f47677Sgavinm authamd_poll_ownermask, /* cms_poll_ownermask */
113720c794b3Sgavinm authamd_bank_logout, /* cms_bank_logout */
113820c794b3Sgavinm authamd_error_action, /* cms_error_action */
113920c794b3Sgavinm authamd_disp_match, /* cms_disp_match */
114020c794b3Sgavinm authamd_ereport_class, /* cms_ereport_class */
114120c794b3Sgavinm NULL, /* cms_ereport_detector */
114220c794b3Sgavinm NULL, /* cms_ereport_includestack */
114320c794b3Sgavinm authamd_ereport_add_logout, /* cms_ereport_add_logout */
114420c794b3Sgavinm authamd_msrinject, /* cms_msrinject */
114520c794b3Sgavinm NULL, /* cms_fini */
114620c794b3Sgavinm };
114720c794b3Sgavinm
114820c794b3Sgavinm static struct modlcpu modlcpu = {
114920c794b3Sgavinm &mod_cpuops,
115020c794b3Sgavinm "Generic AMD model-specific MCA"
115120c794b3Sgavinm };
115220c794b3Sgavinm
115320c794b3Sgavinm static struct modlinkage modlinkage = {
115420c794b3Sgavinm MODREV_1,
115520c794b3Sgavinm (void *)&modlcpu,
115620c794b3Sgavinm NULL
115720c794b3Sgavinm };
115820c794b3Sgavinm
115920c794b3Sgavinm int
_init(void)116020c794b3Sgavinm _init(void)
116120c794b3Sgavinm {
116220c794b3Sgavinm return (mod_install(&modlinkage));
116320c794b3Sgavinm }
116420c794b3Sgavinm
116520c794b3Sgavinm int
_info(struct modinfo * modinfop)116620c794b3Sgavinm _info(struct modinfo *modinfop)
116720c794b3Sgavinm {
116820c794b3Sgavinm return (mod_info(&modlinkage, modinfop));
116920c794b3Sgavinm }
117020c794b3Sgavinm
117120c794b3Sgavinm int
_fini(void)117220c794b3Sgavinm _fini(void)
117320c794b3Sgavinm {
117420c794b3Sgavinm return (mod_remove(&modlinkage));
117520c794b3Sgavinm }
1176