xref: /onnv-gate/usr/src/uts/intel/sys/cpu_module.h (revision 12004:93f274d4a367)
17532SSean.Ye@Sun.COM /*
27532SSean.Ye@Sun.COM  * CDDL HEADER START
37532SSean.Ye@Sun.COM  *
47532SSean.Ye@Sun.COM  * The contents of this file are subject to the terms of the
57532SSean.Ye@Sun.COM  * Common Development and Distribution License (the "License").
67532SSean.Ye@Sun.COM  * You may not use this file except in compliance with the License.
77532SSean.Ye@Sun.COM  *
87532SSean.Ye@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97532SSean.Ye@Sun.COM  * or http://www.opensolaris.org/os/licensing.
107532SSean.Ye@Sun.COM  * See the License for the specific language governing permissions
117532SSean.Ye@Sun.COM  * and limitations under the License.
127532SSean.Ye@Sun.COM  *
137532SSean.Ye@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
147532SSean.Ye@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157532SSean.Ye@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
167532SSean.Ye@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
177532SSean.Ye@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
187532SSean.Ye@Sun.COM  *
197532SSean.Ye@Sun.COM  * CDDL HEADER END
207532SSean.Ye@Sun.COM  */
217532SSean.Ye@Sun.COM 
227532SSean.Ye@Sun.COM /*
23*12004Sjiang.liu@intel.com  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
247532SSean.Ye@Sun.COM  * Use is subject to license terms.
257532SSean.Ye@Sun.COM  */
267532SSean.Ye@Sun.COM 
277532SSean.Ye@Sun.COM #ifndef _SYS_CPU_MODULE_H
287532SSean.Ye@Sun.COM #define	_SYS_CPU_MODULE_H
297532SSean.Ye@Sun.COM 
307532SSean.Ye@Sun.COM #include <sys/types.h>
317532SSean.Ye@Sun.COM #include <sys/cpuvar.h>
327532SSean.Ye@Sun.COM #include <sys/nvpair.h>
337532SSean.Ye@Sun.COM #include <sys/mc.h>
347532SSean.Ye@Sun.COM #include <sys/sunddi.h>
357532SSean.Ye@Sun.COM 
367532SSean.Ye@Sun.COM #ifdef __cplusplus
377532SSean.Ye@Sun.COM extern "C" {
387532SSean.Ye@Sun.COM #endif
397532SSean.Ye@Sun.COM 
407532SSean.Ye@Sun.COM #ifdef _KERNEL
417532SSean.Ye@Sun.COM 
427532SSean.Ye@Sun.COM #define	CMIERR_BASE	0xc000
437532SSean.Ye@Sun.COM 
447532SSean.Ye@Sun.COM typedef enum cmi_errno {
457532SSean.Ye@Sun.COM 	CMI_SUCCESS = 0,
467532SSean.Ye@Sun.COM 	/*
477532SSean.Ye@Sun.COM 	 * CPU Module Interface API error return values/
487532SSean.Ye@Sun.COM 	 */
497532SSean.Ye@Sun.COM 	CMIERR_UNKNOWN = CMIERR_BASE,	/* no specific error reason reported */
507532SSean.Ye@Sun.COM 	CMIERR_API,			/* API usage error caught */
517532SSean.Ye@Sun.COM 	CMIERR_NOTSUP,			/* Unsupported operation */
527532SSean.Ye@Sun.COM 	CMIERR_HDL_CLASS,		/* Inappropriate handle class */
537532SSean.Ye@Sun.COM 	CMIERR_HDL_NOTFOUND,		/* Can't find handle for resource */
547532SSean.Ye@Sun.COM 	CMIERR_MSRGPF,			/* #GP during cmi_hdl_{wr,rd}msr */
557532SSean.Ye@Sun.COM 	CMIERR_INTERPOSE,		/* MSR/PCICFG interposition error */
567532SSean.Ye@Sun.COM 	CMIERR_DEADLOCK,		/* Deadlock avoidance */
577532SSean.Ye@Sun.COM 	/*
587532SSean.Ye@Sun.COM 	 * Memory-controller related errors
597532SSean.Ye@Sun.COM 	 */
607532SSean.Ye@Sun.COM 	CMIERR_MC_ABSENT,		/* No, or not yet registered, MC ops */
617532SSean.Ye@Sun.COM 	CMIERR_MC_NOTSUP,		/* Requested functionality unimpld */
627532SSean.Ye@Sun.COM 	CMIERR_MC_NOMEMSCRUB,		/* No dram scrubber, or disabled */
637532SSean.Ye@Sun.COM 	CMIERR_MC_SYNDROME,		/* Invalid syndrome or syndrome type */
647532SSean.Ye@Sun.COM 	CMIERR_MC_BADSTATE,		/* MC driver state is invalid */
657532SSean.Ye@Sun.COM 	CMIERR_MC_NOADDR,		/* Address not found */
667532SSean.Ye@Sun.COM 	CMIERR_MC_RSRCNOTPRESENT,	/* Resource not present in system */
677532SSean.Ye@Sun.COM 	CMIERR_MC_ADDRBITS,		/* Too few valid addr bits */
687532SSean.Ye@Sun.COM 	CMIERR_MC_INVALUNUM,		/* Invalid input unum */
697532SSean.Ye@Sun.COM 	CMIERR_MC_PARTIALUNUMTOPA	/* unum to pa reflected physaddr */
707532SSean.Ye@Sun.COM } cmi_errno_t;
717532SSean.Ye@Sun.COM 
727532SSean.Ye@Sun.COM /*
737532SSean.Ye@Sun.COM  * All access to cpu information is made via a handle, in order to get
747532SSean.Ye@Sun.COM  * the desired info even when running non-natively.
757532SSean.Ye@Sun.COM  *
767532SSean.Ye@Sun.COM  * A CMI_HDL_NATIVE handle is used when we believe we are running on
777532SSean.Ye@Sun.COM  * bare-metal.  If we *are* on bare metal then this handle type will
787532SSean.Ye@Sun.COM  * get us through to the real hardware, and there will be a 1:1 correspondence
797532SSean.Ye@Sun.COM  * between handles and cpu_t structures; if not, say we are a domU to
807532SSean.Ye@Sun.COM  * some unknown/undetected/unannounced hypervisor then chances are the
817532SSean.Ye@Sun.COM  * hypervisor is not exposing much hardware detail to us so we should
827532SSean.Ye@Sun.COM  * be prepared for some operations that "cannot fail" to fail or return
837532SSean.Ye@Sun.COM  * odd data.
847532SSean.Ye@Sun.COM  *
857532SSean.Ye@Sun.COM  * A CMI_HDL_SOLARIS_xVM_MCA handle is used when we are running
867532SSean.Ye@Sun.COM  * in i86xpv architecture - dom0 to a Solaris xVM hypervisor - and want to
877532SSean.Ye@Sun.COM  * use a handle on each real execution core (as opposed to vcpu)
887532SSean.Ye@Sun.COM  * to perform MCA related activities.  The model for this handle type
897532SSean.Ye@Sun.COM  * is that the hypervisor continues to own the real hardware and
907532SSean.Ye@Sun.COM  * includes a polling service and #MC handler which forward error
917532SSean.Ye@Sun.COM  * telemetry to dom0 for logging and diagnosis.  As such, the operations
927532SSean.Ye@Sun.COM  * such as RDMSR and WRMSR for this handle type do *not* read and write
937532SSean.Ye@Sun.COM  * real MSRs via hypercalls- instead they should provide the values from
947532SSean.Ye@Sun.COM  * already-read MCA bank telemetry, and writes are discarded.
957532SSean.Ye@Sun.COM  *
967532SSean.Ye@Sun.COM  * If some application requires real MSR read and write access another
977532SSean.Ye@Sun.COM  * handle class should be introduced.
987532SSean.Ye@Sun.COM  */
997532SSean.Ye@Sun.COM 
1007532SSean.Ye@Sun.COM typedef struct cmi_hdl *cmi_hdl_t;	/* opaque chip/core/strand handle */
1017532SSean.Ye@Sun.COM 
1027532SSean.Ye@Sun.COM enum cmi_hdl_class {
1037532SSean.Ye@Sun.COM 	CMI_HDL_NATIVE,
1047532SSean.Ye@Sun.COM 	CMI_HDL_SOLARIS_xVM_MCA,
1057532SSean.Ye@Sun.COM 	CMI_HDL_NEUTRAL
1067532SSean.Ye@Sun.COM };
1077532SSean.Ye@Sun.COM 
1087532SSean.Ye@Sun.COM struct regs;
1097532SSean.Ye@Sun.COM 
1107532SSean.Ye@Sun.COM typedef struct cmi_mc_ops {
1117532SSean.Ye@Sun.COM 	cmi_errno_t (*cmi_mc_patounum)(void *, uint64_t, uint8_t, uint8_t,
1127532SSean.Ye@Sun.COM 	    uint32_t, int, mc_unum_t *);
1137532SSean.Ye@Sun.COM 	cmi_errno_t (*cmi_mc_unumtopa)(void *, mc_unum_t *, nvlist_t *,
1147532SSean.Ye@Sun.COM 	    uint64_t *);
1157532SSean.Ye@Sun.COM 	void (*cmi_mc_logout)(cmi_hdl_t, boolean_t, boolean_t);
1167532SSean.Ye@Sun.COM } cmi_mc_ops_t;
1177532SSean.Ye@Sun.COM 
1187532SSean.Ye@Sun.COM extern cmi_hdl_t cmi_init(enum cmi_hdl_class, uint_t, uint_t, uint_t);
1197532SSean.Ye@Sun.COM extern void cmi_post_startup(void);
1207532SSean.Ye@Sun.COM extern void cmi_post_mpstartup(void);
1217532SSean.Ye@Sun.COM extern void cmi_fini(cmi_hdl_t);
1227532SSean.Ye@Sun.COM 
1237532SSean.Ye@Sun.COM extern void cmi_hdl_hold(cmi_hdl_t);
1247532SSean.Ye@Sun.COM extern void cmi_hdl_rele(cmi_hdl_t);
1257532SSean.Ye@Sun.COM extern void *cmi_hdl_getcmidata(cmi_hdl_t);
1267532SSean.Ye@Sun.COM extern void cmi_hdl_setspecific(cmi_hdl_t, void *);
1277532SSean.Ye@Sun.COM extern void *cmi_hdl_getspecific(cmi_hdl_t);
1287532SSean.Ye@Sun.COM extern const struct cmi_mc_ops *cmi_hdl_getmcops(cmi_hdl_t);
1297532SSean.Ye@Sun.COM extern void *cmi_hdl_getmcdata(cmi_hdl_t);
1307532SSean.Ye@Sun.COM extern enum cmi_hdl_class cmi_hdl_class(cmi_hdl_t);
1317532SSean.Ye@Sun.COM 
1327532SSean.Ye@Sun.COM extern cmi_hdl_t cmi_hdl_lookup(enum cmi_hdl_class, uint_t, uint_t, uint_t);
1337532SSean.Ye@Sun.COM extern cmi_hdl_t cmi_hdl_any(void);
1347532SSean.Ye@Sun.COM 
1357532SSean.Ye@Sun.COM #define	CMI_HDL_WALK_NEXT	0
1367532SSean.Ye@Sun.COM #define	CMI_HDL_WALK_DONE	1
1377532SSean.Ye@Sun.COM extern void cmi_hdl_walk(int (*)(cmi_hdl_t, void *, void *, void *),
1387532SSean.Ye@Sun.COM     void *, void *, void *);
1397532SSean.Ye@Sun.COM 
1407532SSean.Ye@Sun.COM extern void cmi_hdlconf_rdmsr_nohw(cmi_hdl_t);
1417532SSean.Ye@Sun.COM extern void cmi_hdlconf_wrmsr_nohw(cmi_hdl_t);
1427532SSean.Ye@Sun.COM extern cmi_errno_t cmi_hdl_rdmsr(cmi_hdl_t, uint_t, uint64_t *);
1437532SSean.Ye@Sun.COM extern cmi_errno_t cmi_hdl_wrmsr(cmi_hdl_t, uint_t, uint64_t);
1447532SSean.Ye@Sun.COM 
1457532SSean.Ye@Sun.COM extern void cmi_hdl_enable_mce(cmi_hdl_t);
1467532SSean.Ye@Sun.COM extern uint_t cmi_hdl_vendor(cmi_hdl_t);
1477532SSean.Ye@Sun.COM extern const char *cmi_hdl_vendorstr(cmi_hdl_t);
1487532SSean.Ye@Sun.COM extern uint_t cmi_hdl_family(cmi_hdl_t);
1497532SSean.Ye@Sun.COM extern uint_t cmi_hdl_model(cmi_hdl_t);
1507532SSean.Ye@Sun.COM extern uint_t cmi_hdl_stepping(cmi_hdl_t);
1517532SSean.Ye@Sun.COM extern uint_t cmi_hdl_chipid(cmi_hdl_t);
15210947SSrihari.Venkatesan@Sun.COM extern uint_t cmi_hdl_procnodeid(cmi_hdl_t);
1537532SSean.Ye@Sun.COM extern uint_t cmi_hdl_coreid(cmi_hdl_t);
1547532SSean.Ye@Sun.COM extern uint_t cmi_hdl_strandid(cmi_hdl_t);
15510942STom.Pothier@Sun.COM extern uint_t cmi_hdl_strand_apicid(cmi_hdl_t);
15610947SSrihari.Venkatesan@Sun.COM extern uint_t cmi_hdl_procnodes_per_pkg(cmi_hdl_t);
1577532SSean.Ye@Sun.COM extern boolean_t cmi_hdl_is_cmt(cmi_hdl_t);
1587532SSean.Ye@Sun.COM extern uint32_t cmi_hdl_chiprev(cmi_hdl_t);
1597532SSean.Ye@Sun.COM extern const char *cmi_hdl_chiprevstr(cmi_hdl_t);
1607532SSean.Ye@Sun.COM extern uint32_t cmi_hdl_getsockettype(cmi_hdl_t);
1619482SKuriakose.Kuruvilla@Sun.COM extern const char *cmi_hdl_getsocketstr(cmi_hdl_t);
1627532SSean.Ye@Sun.COM extern id_t cmi_hdl_logical_id(cmi_hdl_t);
16310942STom.Pothier@Sun.COM extern uint16_t cmi_hdl_smbiosid(cmi_hdl_t);
16410942STom.Pothier@Sun.COM extern uint_t cmi_hdl_smb_chipid(cmi_hdl_t);
16510942STom.Pothier@Sun.COM extern nvlist_t *cmi_hdl_smb_bboard(cmi_hdl_t);
1667532SSean.Ye@Sun.COM 
1677532SSean.Ye@Sun.COM extern int cmi_hdl_online(cmi_hdl_t, int, int *);
1687532SSean.Ye@Sun.COM 
1697532SSean.Ye@Sun.COM #ifndef	__xpv
1707532SSean.Ye@Sun.COM extern uint_t cmi_ntv_hwchipid(cpu_t *);
17110947SSrihari.Venkatesan@Sun.COM extern uint_t cmi_ntv_hwprocnodeid(cpu_t *);
1727532SSean.Ye@Sun.COM extern uint_t cmi_ntv_hwcoreid(cpu_t *);
1737532SSean.Ye@Sun.COM extern uint_t cmi_ntv_hwstrandid(cpu_t *);
174*12004Sjiang.liu@intel.com extern void cmi_ntv_hwdisable_mce(cmi_hdl_t);
1757532SSean.Ye@Sun.COM #endif	/* __xpv */
1767532SSean.Ye@Sun.COM 
1777532SSean.Ye@Sun.COM typedef struct cmi_mca_regs {
1787532SSean.Ye@Sun.COM 	uint_t cmr_msrnum;
1797532SSean.Ye@Sun.COM 	uint64_t cmr_msrval;
1807532SSean.Ye@Sun.COM } cmi_mca_regs_t;
1817532SSean.Ye@Sun.COM 
1827532SSean.Ye@Sun.COM extern cmi_errno_t cmi_hdl_msrinject(cmi_hdl_t, cmi_mca_regs_t *, uint_t,
1837532SSean.Ye@Sun.COM     int);
1847532SSean.Ye@Sun.COM extern void cmi_hdl_msrinterpose(cmi_hdl_t, cmi_mca_regs_t *, uint_t);
1857532SSean.Ye@Sun.COM extern void cmi_hdl_msrforward(cmi_hdl_t, cmi_mca_regs_t *, uint_t);
1867532SSean.Ye@Sun.COM extern boolean_t cmi_inj_tainted(void);
1877532SSean.Ye@Sun.COM 
1887532SSean.Ye@Sun.COM extern void cmi_faulted_enter(cmi_hdl_t);
1897532SSean.Ye@Sun.COM extern void cmi_faulted_exit(cmi_hdl_t);
1907532SSean.Ye@Sun.COM 
1917532SSean.Ye@Sun.COM extern void cmi_pcird_nohw(void);
1927532SSean.Ye@Sun.COM extern void cmi_pciwr_nohw(void);
1937532SSean.Ye@Sun.COM extern uint8_t cmi_pci_getb(int, int, int, int, int *, ddi_acc_handle_t);
1947532SSean.Ye@Sun.COM extern uint16_t cmi_pci_getw(int, int, int, int, int *, ddi_acc_handle_t);
1957532SSean.Ye@Sun.COM extern uint32_t cmi_pci_getl(int, int, int, int, int *, ddi_acc_handle_t);
1967532SSean.Ye@Sun.COM extern void cmi_pci_interposeb(int, int, int, int, uint8_t);
1977532SSean.Ye@Sun.COM extern void cmi_pci_interposew(int, int, int, int, uint16_t);
1987532SSean.Ye@Sun.COM extern void cmi_pci_interposel(int, int, int, int, uint32_t);
1997532SSean.Ye@Sun.COM extern void cmi_pci_putb(int, int, int, int, ddi_acc_handle_t, uint8_t);
2007532SSean.Ye@Sun.COM extern void cmi_pci_putw(int, int, int, int, ddi_acc_handle_t, uint16_t);
2017532SSean.Ye@Sun.COM extern void cmi_pci_putl(int, int, int, int, ddi_acc_handle_t, uint32_t);
2027532SSean.Ye@Sun.COM 
2037532SSean.Ye@Sun.COM extern void cmi_mca_init(cmi_hdl_t);
2047532SSean.Ye@Sun.COM 
2057532SSean.Ye@Sun.COM extern void cmi_hdl_poke(cmi_hdl_t);
2067532SSean.Ye@Sun.COM extern void cmi_hdl_int(cmi_hdl_t, int);
2077532SSean.Ye@Sun.COM 
2087532SSean.Ye@Sun.COM extern void cmi_mca_trap(struct regs *);
2097532SSean.Ye@Sun.COM 
2107532SSean.Ye@Sun.COM extern boolean_t cmi_panic_on_ue(void);
2117532SSean.Ye@Sun.COM 
2127532SSean.Ye@Sun.COM extern void cmi_mc_register(cmi_hdl_t, const struct cmi_mc_ops *, void *);
213*12004Sjiang.liu@intel.com extern cmi_errno_t cmi_mc_register_global(const struct cmi_mc_ops *, void *);
2147532SSean.Ye@Sun.COM extern void cmi_mc_sw_memscrub_disable(void);
2157532SSean.Ye@Sun.COM extern cmi_errno_t cmi_mc_patounum(uint64_t, uint8_t, uint8_t, uint32_t, int,
2167532SSean.Ye@Sun.COM     mc_unum_t *);
2177532SSean.Ye@Sun.COM extern cmi_errno_t cmi_mc_unumtopa(mc_unum_t *, nvlist_t *, uint64_t *);
2187532SSean.Ye@Sun.COM extern void cmi_mc_logout(cmi_hdl_t, boolean_t, boolean_t);
2197532SSean.Ye@Sun.COM 
2207532SSean.Ye@Sun.COM extern void cmi_panic_callback(void);
2217532SSean.Ye@Sun.COM 
2227532SSean.Ye@Sun.COM #endif /* _KERNEL */
2237532SSean.Ye@Sun.COM 
2247532SSean.Ye@Sun.COM #ifdef __cplusplus
2257532SSean.Ye@Sun.COM }
2267532SSean.Ye@Sun.COM #endif
2277532SSean.Ye@Sun.COM 
2287532SSean.Ye@Sun.COM #endif /* _SYS_CPU_MODULE_H */
229