17aec1d6eScindi /* 27aec1d6eScindi * CDDL HEADER START 37aec1d6eScindi * 47aec1d6eScindi * 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. 77aec1d6eScindi * 87aec1d6eScindi * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97aec1d6eScindi * or http://www.opensolaris.org/os/licensing. 107aec1d6eScindi * See the License for the specific language governing permissions 117aec1d6eScindi * and limitations under the License. 127aec1d6eScindi * 137aec1d6eScindi * When distributing Covered Code, include this CDDL HEADER in each 147aec1d6eScindi * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157aec1d6eScindi * If applicable, add the following below this CDDL HEADER, with the 167aec1d6eScindi * fields enclosed by brackets "[]" replaced with your own identifying 177aec1d6eScindi * information: Portions Copyright [yyyy] [name of copyright owner] 187aec1d6eScindi * 197aec1d6eScindi * CDDL HEADER END 207aec1d6eScindi */ 217aec1d6eScindi 227aec1d6eScindi /* 23*c84b7bbeSAdrian Frost * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. 247aec1d6eScindi */ 257aec1d6eScindi 267aec1d6eScindi #ifndef _GCPU_H 277aec1d6eScindi #define _GCPU_H 287aec1d6eScindi 297aec1d6eScindi #include <sys/types.h> 3020c794b3Sgavinm #include <sys/cpu_module_impl.h> 3120c794b3Sgavinm #include <sys/cpu_module_ms.h> 3220c794b3Sgavinm #include <sys/ksynch.h> 3320c794b3Sgavinm #include <sys/systm.h> 3420c794b3Sgavinm #include <sys/fm/util.h> 357aec1d6eScindi 367aec1d6eScindi #ifdef __cplusplus 377aec1d6eScindi extern "C" { 387aec1d6eScindi #endif 397aec1d6eScindi 4020c794b3Sgavinm #define GCPU_MCA_ERRS_PERCPU 10 /* errorq slots per cpu */ 4120c794b3Sgavinm #define GCPU_MCA_MIN_ERRORS 30 /* minimum total errorq slots */ 4220c794b3Sgavinm #define GCPU_MCA_MAX_ERRORS 100 /* maximum total errorq slots */ 437aec1d6eScindi 4420c794b3Sgavinm typedef struct gcpu_data gcpu_data_t; 4520c794b3Sgavinm 4620c794b3Sgavinm #define GCPU_ERRCODE_MASK_ALL 0xffff 4720c794b3Sgavinm 4820c794b3Sgavinm typedef struct gcpu_error_disp { 4920c794b3Sgavinm const char *ged_class_fmt; /* ereport class formatter (last bit) */ 5020c794b3Sgavinm const char *ged_compound_fmt; /* compound error formatter */ 5120c794b3Sgavinm uint64_t ged_ereport_members; /* ereport payload members */ 5220c794b3Sgavinm uint16_t ged_errcode_mask_on; /* errcode bits that must be set ... */ 5320c794b3Sgavinm uint16_t ged_errcode_mask_off; /* ... and must be clear for a match */ 5420c794b3Sgavinm } gcpu_error_disp_t; 5520c794b3Sgavinm 5620c794b3Sgavinm /* 5720c794b3Sgavinm * For errorq_dispatch we need to have a single contiguous structure 5820c794b3Sgavinm * capturing all our logout data. We do not know in advance how many 5920c794b3Sgavinm * error detector banks there are in this cpu model, so we'll manually 6020c794b3Sgavinm * allocate additional space for the gcl_banks array below. 6120c794b3Sgavinm */ 6220c794b3Sgavinm typedef struct gcpu_bank_logout { 6320c794b3Sgavinm uint64_t gbl_status; /* MCi_STATUS value */ 6420c794b3Sgavinm uint64_t gbl_addr; /* MCi_ADDR value */ 6520c794b3Sgavinm uint64_t gbl_misc; /* MCi_MISC value */ 6620c794b3Sgavinm uint64_t gbl_disp; /* Error disposition for this bank */ 6720c794b3Sgavinm uint32_t gbl_clrdefcnt; /* Count of deferred status clears */ 6820c794b3Sgavinm } gcpu_bank_logout_t; 6920c794b3Sgavinm 7020c794b3Sgavinm /* 7120c794b3Sgavinm * The data structure we "logout" all error telemetry from all banks of 7220c794b3Sgavinm * a cpu to. The gcl_data array declared with 1 member below will actually 7320c794b3Sgavinm * have gcl_nbanks members - variable with the actual cpu model present. 7420c794b3Sgavinm * After the gcl_data array there is a further model-specific array that 7520c794b3Sgavinm * may be allocated, and gcl_ms_logout will point to that if present. 7620c794b3Sgavinm * This cpu logout data must form one contiguous chunk of memory for 7720c794b3Sgavinm * dispatch with errorq_dispatch. 7820c794b3Sgavinm */ 7920c794b3Sgavinm typedef struct gcpu_logout { 8020c794b3Sgavinm gcpu_data_t *gcl_gcpu; /* pointer to per-cpu gcpu_data_t */ 8120c794b3Sgavinm uintptr_t gcl_ip; /* instruction pointer from #mc trap */ 8220c794b3Sgavinm uint64_t gcl_timestamp; /* gethrtime() at logout */ 8320c794b3Sgavinm uint64_t gcl_mcg_status; /* MCG_STATUS register value */ 8420c794b3Sgavinm uint64_t gcl_flags; /* Flags */ 8520c794b3Sgavinm pc_t gcl_stack[FM_STK_DEPTH]; /* saved stack trace, if any */ 8620c794b3Sgavinm int gcl_stackdepth; /* saved stack trace depth */ 87*c84b7bbeSAdrian Frost int ismc; /* is a machine check flag */ 8820c794b3Sgavinm int gcl_nbanks; /* number of banks in array below */ 8920c794b3Sgavinm void *gcl_ms_logout; /* Model-specific area after gcl_data */ 9020c794b3Sgavinm gcpu_bank_logout_t gcl_data[1]; /* Bank logout areas - must be last */ 9120c794b3Sgavinm } gcpu_logout_t; 9220c794b3Sgavinm 9320c794b3Sgavinm /* 9420c794b3Sgavinm * gcl_flag values 9520c794b3Sgavinm */ 9620c794b3Sgavinm #define GCPU_GCL_F_PRIV 0x1 /* #MC during privileged code */ 9720c794b3Sgavinm #define GCPU_GCL_F_TES_P 0x2 /* MCG_CAP indicates TES_P */ 9820c794b3Sgavinm 9920c794b3Sgavinm struct gcpu_bios_bankcfg { 10020c794b3Sgavinm uint64_t bios_bank_ctl; 10120c794b3Sgavinm uint64_t bios_bank_status; 10220c794b3Sgavinm uint64_t bios_bank_addr; 10320c794b3Sgavinm uint64_t bios_bank_misc; 10420c794b3Sgavinm }; 10520c794b3Sgavinm 10620c794b3Sgavinm struct gcpu_bios_cfg { 10720c794b3Sgavinm uint64_t bios_mcg_cap; 10820c794b3Sgavinm uint64_t bios_mcg_ctl; 10920c794b3Sgavinm struct gcpu_bios_bankcfg *bios_bankcfg; 11020c794b3Sgavinm }; 11120c794b3Sgavinm 112e4b86885SCheng Sean Ye /* 113e4b86885SCheng Sean Ye * Events types in poll trace records. Keep these in sync with 114e4b86885SCheng Sean Ye * the generic cpu mdb module names for each (see gcpu_mpt_dump in mdb). 115e4b86885SCheng Sean Ye */ 11620c794b3Sgavinm #define GCPU_MPT_WHAT_CYC_ERR 0 /* cyclic-induced poll */ 11720c794b3Sgavinm #define GCPU_MPT_WHAT_POKE_ERR 1 /* manually-induced poll */ 11820c794b3Sgavinm #define GCPU_MPT_WHAT_UNFAULTING 2 /* discarded error state */ 119e3d60c9bSAdrian Frost #define GCPU_MPT_WHAT_MC_ERR 3 /* MC# */ 120e3d60c9bSAdrian Frost #define GCPU_MPT_WHAT_CMCI_ERR 4 /* CMCI interrupt */ 121e4b86885SCheng Sean Ye #define GCPU_MPT_WHAT_XPV_VIRQ 5 /* MCA_VIRQ in dom0 */ 122e4b86885SCheng Sean Ye #define GCPU_MPT_WHAT_XPV_VIRQ_LOGOUT 6 /* MCA_VIRQ logout complete */ 12320c794b3Sgavinm 124e4b86885SCheng Sean Ye typedef struct gcpu_poll_trace { 12520c794b3Sgavinm hrtime_t mpt_when; /* timestamp of event */ 12620c794b3Sgavinm uint8_t mpt_what; /* GCPU_MPT_WHAT_* (which event?) */ 12720c794b3Sgavinm uint8_t mpt_nerr; /* number of errors discovered */ 12820c794b3Sgavinm uint16_t mpt_pad1; 12920c794b3Sgavinm uint32_t mpt_pad2; 130e4b86885SCheng Sean Ye } gcpu_poll_trace_t; 13120c794b3Sgavinm 132e4b86885SCheng Sean Ye typedef struct gcpu_poll_trace_ctl { 133e4b86885SCheng Sean Ye gcpu_poll_trace_t *mptc_tbufs; /* trace buffers */ 13420c794b3Sgavinm uint_t mptc_curtrace; /* last buffer filled */ 135e4b86885SCheng Sean Ye } gcpu_poll_trace_ctl_t; 13620c794b3Sgavinm 137e3d60c9bSAdrian Frost 138e3d60c9bSAdrian Frost /* 139e3d60c9bSAdrian Frost * For counting some of the important number or time for runtime 140e3d60c9bSAdrian Frost * cmci enable/disable 141e3d60c9bSAdrian Frost */ 142e3d60c9bSAdrian Frost typedef struct gcpu_mca_cmci { 143e3d60c9bSAdrian Frost uint32_t cmci_cap; /* cmci capability for this bank */ 144e3d60c9bSAdrian Frost uint32_t ncmci; /* number of correctable errors between polls */ 145e3d60c9bSAdrian Frost uint32_t drtcmci; /* duration of no cmci when cmci is disabled */ 146e3d60c9bSAdrian Frost uint32_t cmci_enabled; /* cmci enable/disable status for this bank */ 147e3d60c9bSAdrian Frost } gcpu_mca_cmci_t; 148e3d60c9bSAdrian Frost 14920c794b3Sgavinm /* Index for gcpu_mca_logout array below */ 15020c794b3Sgavinm #define GCPU_MCA_LOGOUT_EXCEPTION 0 /* area for #MC */ 15120c794b3Sgavinm #define GCPU_MCA_LOGOUT_POLLER_1 1 /* next/prev poll area */ 15220c794b3Sgavinm #define GCPU_MCA_LOGOUT_POLLER_2 2 /* prev/next poll area */ 15320c794b3Sgavinm #define GCPU_MCA_LOGOUT_NUM 3 1547aec1d6eScindi 1557aec1d6eScindi typedef struct gcpu_mca { 15620c794b3Sgavinm gcpu_logout_t *gcpu_mca_logout[GCPU_MCA_LOGOUT_NUM]; 15720c794b3Sgavinm uint32_t gcpu_mca_nextpoll_idx; /* logout area for next poll */ 15820c794b3Sgavinm struct gcpu_bios_cfg gcpu_mca_bioscfg; 1597aec1d6eScindi uint_t gcpu_mca_nbanks; 16020c794b3Sgavinm size_t gcpu_mca_lgsz; /* size of gcpu_mca_logout structs */ 16120c794b3Sgavinm uint_t gcpu_mca_flags; /* GCPU_MCA_F_* */ 16220c794b3Sgavinm hrtime_t gcpu_mca_lastpoll; 163e4b86885SCheng Sean Ye gcpu_poll_trace_ctl_t gcpu_polltrace; 164e3d60c9bSAdrian Frost uint32_t gcpu_mca_first_poll_cmci_enabled; /* cmci on in first poll */ 165e3d60c9bSAdrian Frost gcpu_mca_cmci_t *gcpu_bank_cmci; 1667aec1d6eScindi } gcpu_mca_t; 1677aec1d6eScindi 16820c794b3Sgavinm typedef struct gcpu_mce_status { 16920c794b3Sgavinm uint_t mce_nerr; /* total errors found in logout of all banks */ 17020c794b3Sgavinm uint64_t mce_disp; /* Disposition information */ 17120c794b3Sgavinm uint_t mce_npcc; /* number of errors with PCC */ 17220c794b3Sgavinm uint_t mce_npcc_ok; /* PCC with CMS_ERRSCOPE_CURCONTEXT_OK */ 17320c794b3Sgavinm uint_t mce_nuc; /* number of errors with UC */ 17420c794b3Sgavinm uint_t mce_nuc_ok; /* UC with CMS_ERRSCOPE_CLEARED_UC */ 17520c794b3Sgavinm uint_t mce_nuc_poisoned; /* UC with CMS_ERRSCOPE_POISONED */ 17620c794b3Sgavinm uint_t mce_forcefatal; /* CMS_ERRSCOPE_FORCE_FATAL */ 17720c794b3Sgavinm uint_t mce_ignored; /* CMS_ERRSCOPE_IGNORE_ERR */ 17820c794b3Sgavinm } gcpu_mce_status_t; 17920c794b3Sgavinm 18020c794b3Sgavinm /* 18120c794b3Sgavinm * Flags for gcpu_mca_flags 18220c794b3Sgavinm */ 18320c794b3Sgavinm #define GCPU_MCA_F_UNFAULTING 0x1 /* CPU exiting faulted state */ 18420c794b3Sgavinm 18520c794b3Sgavinm /* 18620c794b3Sgavinm * State shared by all cpus on a chip 18720c794b3Sgavinm */ 18820c794b3Sgavinm struct gcpu_chipshared { 18920c794b3Sgavinm kmutex_t gcpus_cfglock; /* serial MCA config from chip cores */ 19020c794b3Sgavinm kmutex_t gcpus_poll_lock; /* serialize pollers on the same chip */ 19120c794b3Sgavinm uint32_t gcpus_actv_banks; /* MCA bank numbers active on chip */ 192a3114836SGerry Liu volatile uint32_t gcpus_actv_cnt; /* active cpu count in this chip */ 19320c794b3Sgavinm }; 19420c794b3Sgavinm 19520c794b3Sgavinm struct gcpu_data { 19620c794b3Sgavinm gcpu_mca_t gcpu_mca; /* MCA state for this CPU */ 19720c794b3Sgavinm cmi_hdl_t gcpu_hdl; /* associated handle */ 19820c794b3Sgavinm struct gcpu_chipshared *gcpu_shared; /* Shared state for the chip */ 19920c794b3Sgavinm }; 20020c794b3Sgavinm 20120c794b3Sgavinm #ifdef _KERNEL 2027aec1d6eScindi 2037aec1d6eScindi struct regs; 2047aec1d6eScindi 20520c794b3Sgavinm /* 20620c794b3Sgavinm * CMI implementation 20720c794b3Sgavinm */ 20820c794b3Sgavinm extern int gcpu_init(cmi_hdl_t, void **); 209a3114836SGerry Liu extern void gcpu_fini(cmi_hdl_t); 21020c794b3Sgavinm extern void gcpu_post_startup(cmi_hdl_t); 21120c794b3Sgavinm extern void gcpu_post_mpstartup(cmi_hdl_t); 21220c794b3Sgavinm extern void gcpu_faulted_enter(cmi_hdl_t); 21320c794b3Sgavinm extern void gcpu_faulted_exit(cmi_hdl_t); 21420c794b3Sgavinm extern void gcpu_mca_init(cmi_hdl_t); 215a3114836SGerry Liu extern void gcpu_mca_fini(cmi_hdl_t hdl); 21620c794b3Sgavinm extern cmi_errno_t gcpu_msrinject(cmi_hdl_t, cmi_mca_regs_t *, uint_t, int); 217e4b86885SCheng Sean Ye #ifndef __xpv 21820c794b3Sgavinm extern uint64_t gcpu_mca_trap(cmi_hdl_t, struct regs *); 219e3d60c9bSAdrian Frost extern void gcpu_cmci_trap(cmi_hdl_t); 22020c794b3Sgavinm extern void gcpu_hdl_poke(cmi_hdl_t); 221e4b86885SCheng Sean Ye #else 222e4b86885SCheng Sean Ye extern void gcpu_xpv_panic_callback(void); 223e4b86885SCheng Sean Ye #endif 22420c794b3Sgavinm 22520c794b3Sgavinm /* 226e3d60c9bSAdrian Frost * CMI global variable 227e3d60c9bSAdrian Frost */ 228e3d60c9bSAdrian Frost extern int cmi_enable_cmci; 229e3d60c9bSAdrian Frost 230e3d60c9bSAdrian Frost /* 23120c794b3Sgavinm * Local functions 23220c794b3Sgavinm */ 23320c794b3Sgavinm extern void gcpu_mca_poll_init(cmi_hdl_t); 234a3114836SGerry Liu extern void gcpu_mca_poll_fini(cmi_hdl_t); 23520c794b3Sgavinm extern void gcpu_mca_poll_start(cmi_hdl_t); 236e4b86885SCheng Sean Ye extern void gcpu_poll_trace_init(gcpu_poll_trace_ctl_t *); 237e4b86885SCheng Sean Ye extern void gcpu_poll_trace(gcpu_poll_trace_ctl_t *, uint8_t, uint8_t); 23820c794b3Sgavinm extern void gcpu_mca_logout(cmi_hdl_t, struct regs *, uint64_t, 239e3d60c9bSAdrian Frost gcpu_mce_status_t *, boolean_t, int); 240e4b86885SCheng Sean Ye #ifdef __xpv 241e4b86885SCheng Sean Ye extern void gcpu_xpv_mca_init(int); 242e4b86885SCheng Sean Ye #endif /* __xpv */ 24320c794b3Sgavinm 24420c794b3Sgavinm #endif /* _KERNEL */ 2457aec1d6eScindi 2467aec1d6eScindi #ifdef __cplusplus 2477aec1d6eScindi } 2487aec1d6eScindi #endif 2497aec1d6eScindi 2507aec1d6eScindi #endif /* _GCPU_H */ 251