1*7532SSean.Ye@Sun.COM /*
2*7532SSean.Ye@Sun.COM  * CDDL HEADER START
3*7532SSean.Ye@Sun.COM  *
4*7532SSean.Ye@Sun.COM  * The contents of this file are subject to the terms of the
5*7532SSean.Ye@Sun.COM  * Common Development and Distribution License (the "License").
6*7532SSean.Ye@Sun.COM  * You may not use this file except in compliance with the License.
7*7532SSean.Ye@Sun.COM  *
8*7532SSean.Ye@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*7532SSean.Ye@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*7532SSean.Ye@Sun.COM  * See the License for the specific language governing permissions
11*7532SSean.Ye@Sun.COM  * and limitations under the License.
12*7532SSean.Ye@Sun.COM  *
13*7532SSean.Ye@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*7532SSean.Ye@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*7532SSean.Ye@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*7532SSean.Ye@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*7532SSean.Ye@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*7532SSean.Ye@Sun.COM  *
19*7532SSean.Ye@Sun.COM  * CDDL HEADER END
20*7532SSean.Ye@Sun.COM  */
21*7532SSean.Ye@Sun.COM 
22*7532SSean.Ye@Sun.COM /*
23*7532SSean.Ye@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24*7532SSean.Ye@Sun.COM  * Use is subject to license terms.
25*7532SSean.Ye@Sun.COM  */
26*7532SSean.Ye@Sun.COM 
27*7532SSean.Ye@Sun.COM #ifndef _SYS_CPU_MODULE_H
28*7532SSean.Ye@Sun.COM #define	_SYS_CPU_MODULE_H
29*7532SSean.Ye@Sun.COM 
30*7532SSean.Ye@Sun.COM #include <sys/types.h>
31*7532SSean.Ye@Sun.COM #include <sys/cpuvar.h>
32*7532SSean.Ye@Sun.COM #include <sys/nvpair.h>
33*7532SSean.Ye@Sun.COM #include <sys/mc.h>
34*7532SSean.Ye@Sun.COM #include <sys/sunddi.h>
35*7532SSean.Ye@Sun.COM 
36*7532SSean.Ye@Sun.COM #ifdef __cplusplus
37*7532SSean.Ye@Sun.COM extern "C" {
38*7532SSean.Ye@Sun.COM #endif
39*7532SSean.Ye@Sun.COM 
40*7532SSean.Ye@Sun.COM #ifdef _KERNEL
41*7532SSean.Ye@Sun.COM 
42*7532SSean.Ye@Sun.COM #define	CMIERR_BASE	0xc000
43*7532SSean.Ye@Sun.COM 
44*7532SSean.Ye@Sun.COM typedef enum cmi_errno {
45*7532SSean.Ye@Sun.COM 	CMI_SUCCESS = 0,
46*7532SSean.Ye@Sun.COM 	/*
47*7532SSean.Ye@Sun.COM 	 * CPU Module Interface API error return values/
48*7532SSean.Ye@Sun.COM 	 */
49*7532SSean.Ye@Sun.COM 	CMIERR_UNKNOWN = CMIERR_BASE,	/* no specific error reason reported */
50*7532SSean.Ye@Sun.COM 	CMIERR_API,			/* API usage error caught */
51*7532SSean.Ye@Sun.COM 	CMIERR_NOTSUP,			/* Unsupported operation */
52*7532SSean.Ye@Sun.COM 	CMIERR_HDL_CLASS,		/* Inappropriate handle class */
53*7532SSean.Ye@Sun.COM 	CMIERR_HDL_NOTFOUND,		/* Can't find handle for resource */
54*7532SSean.Ye@Sun.COM 	CMIERR_MSRGPF,			/* #GP during cmi_hdl_{wr,rd}msr */
55*7532SSean.Ye@Sun.COM 	CMIERR_INTERPOSE,		/* MSR/PCICFG interposition error */
56*7532SSean.Ye@Sun.COM 	CMIERR_DEADLOCK,		/* Deadlock avoidance */
57*7532SSean.Ye@Sun.COM 	/*
58*7532SSean.Ye@Sun.COM 	 * Memory-controller related errors
59*7532SSean.Ye@Sun.COM 	 */
60*7532SSean.Ye@Sun.COM 	CMIERR_MC_ABSENT,		/* No, or not yet registered, MC ops */
61*7532SSean.Ye@Sun.COM 	CMIERR_MC_NOTSUP,		/* Requested functionality unimpld */
62*7532SSean.Ye@Sun.COM 	CMIERR_MC_NOMEMSCRUB,		/* No dram scrubber, or disabled */
63*7532SSean.Ye@Sun.COM 	CMIERR_MC_SYNDROME,		/* Invalid syndrome or syndrome type */
64*7532SSean.Ye@Sun.COM 	CMIERR_MC_BADSTATE,		/* MC driver state is invalid */
65*7532SSean.Ye@Sun.COM 	CMIERR_MC_NOADDR,		/* Address not found */
66*7532SSean.Ye@Sun.COM 	CMIERR_MC_RSRCNOTPRESENT,	/* Resource not present in system */
67*7532SSean.Ye@Sun.COM 	CMIERR_MC_ADDRBITS,		/* Too few valid addr bits */
68*7532SSean.Ye@Sun.COM 	CMIERR_MC_INVALUNUM,		/* Invalid input unum */
69*7532SSean.Ye@Sun.COM 	CMIERR_MC_PARTIALUNUMTOPA	/* unum to pa reflected physaddr */
70*7532SSean.Ye@Sun.COM } cmi_errno_t;
71*7532SSean.Ye@Sun.COM 
72*7532SSean.Ye@Sun.COM /*
73*7532SSean.Ye@Sun.COM  * All access to cpu information is made via a handle, in order to get
74*7532SSean.Ye@Sun.COM  * the desired info even when running non-natively.
75*7532SSean.Ye@Sun.COM  *
76*7532SSean.Ye@Sun.COM  * A CMI_HDL_NATIVE handle is used when we believe we are running on
77*7532SSean.Ye@Sun.COM  * bare-metal.  If we *are* on bare metal then this handle type will
78*7532SSean.Ye@Sun.COM  * get us through to the real hardware, and there will be a 1:1 correspondence
79*7532SSean.Ye@Sun.COM  * between handles and cpu_t structures; if not, say we are a domU to
80*7532SSean.Ye@Sun.COM  * some unknown/undetected/unannounced hypervisor then chances are the
81*7532SSean.Ye@Sun.COM  * hypervisor is not exposing much hardware detail to us so we should
82*7532SSean.Ye@Sun.COM  * be prepared for some operations that "cannot fail" to fail or return
83*7532SSean.Ye@Sun.COM  * odd data.
84*7532SSean.Ye@Sun.COM  *
85*7532SSean.Ye@Sun.COM  * A CMI_HDL_SOLARIS_xVM_MCA handle is used when we are running
86*7532SSean.Ye@Sun.COM  * in i86xpv architecture - dom0 to a Solaris xVM hypervisor - and want to
87*7532SSean.Ye@Sun.COM  * use a handle on each real execution core (as opposed to vcpu)
88*7532SSean.Ye@Sun.COM  * to perform MCA related activities.  The model for this handle type
89*7532SSean.Ye@Sun.COM  * is that the hypervisor continues to own the real hardware and
90*7532SSean.Ye@Sun.COM  * includes a polling service and #MC handler which forward error
91*7532SSean.Ye@Sun.COM  * telemetry to dom0 for logging and diagnosis.  As such, the operations
92*7532SSean.Ye@Sun.COM  * such as RDMSR and WRMSR for this handle type do *not* read and write
93*7532SSean.Ye@Sun.COM  * real MSRs via hypercalls- instead they should provide the values from
94*7532SSean.Ye@Sun.COM  * already-read MCA bank telemetry, and writes are discarded.
95*7532SSean.Ye@Sun.COM  *
96*7532SSean.Ye@Sun.COM  * If some application requires real MSR read and write access another
97*7532SSean.Ye@Sun.COM  * handle class should be introduced.
98*7532SSean.Ye@Sun.COM  */
99*7532SSean.Ye@Sun.COM 
100*7532SSean.Ye@Sun.COM typedef struct cmi_hdl *cmi_hdl_t;	/* opaque chip/core/strand handle */
101*7532SSean.Ye@Sun.COM 
102*7532SSean.Ye@Sun.COM enum cmi_hdl_class {
103*7532SSean.Ye@Sun.COM 	CMI_HDL_NATIVE,
104*7532SSean.Ye@Sun.COM 	CMI_HDL_SOLARIS_xVM_MCA,
105*7532SSean.Ye@Sun.COM 	CMI_HDL_NEUTRAL
106*7532SSean.Ye@Sun.COM };
107*7532SSean.Ye@Sun.COM 
108*7532SSean.Ye@Sun.COM struct regs;
109*7532SSean.Ye@Sun.COM 
110*7532SSean.Ye@Sun.COM typedef struct cmi_mc_ops {
111*7532SSean.Ye@Sun.COM 	cmi_errno_t (*cmi_mc_patounum)(void *, uint64_t, uint8_t, uint8_t,
112*7532SSean.Ye@Sun.COM 	    uint32_t, int, mc_unum_t *);
113*7532SSean.Ye@Sun.COM 	cmi_errno_t (*cmi_mc_unumtopa)(void *, mc_unum_t *, nvlist_t *,
114*7532SSean.Ye@Sun.COM 	    uint64_t *);
115*7532SSean.Ye@Sun.COM 	void (*cmi_mc_logout)(cmi_hdl_t, boolean_t, boolean_t);
116*7532SSean.Ye@Sun.COM } cmi_mc_ops_t;
117*7532SSean.Ye@Sun.COM 
118*7532SSean.Ye@Sun.COM extern cmi_hdl_t cmi_init(enum cmi_hdl_class, uint_t, uint_t, uint_t);
119*7532SSean.Ye@Sun.COM extern void cmi_post_startup(void);
120*7532SSean.Ye@Sun.COM extern void cmi_post_mpstartup(void);
121*7532SSean.Ye@Sun.COM extern void cmi_fini(cmi_hdl_t);
122*7532SSean.Ye@Sun.COM 
123*7532SSean.Ye@Sun.COM extern void cmi_hdl_hold(cmi_hdl_t);
124*7532SSean.Ye@Sun.COM extern void cmi_hdl_rele(cmi_hdl_t);
125*7532SSean.Ye@Sun.COM extern void *cmi_hdl_getcmidata(cmi_hdl_t);
126*7532SSean.Ye@Sun.COM extern void cmi_hdl_setspecific(cmi_hdl_t, void *);
127*7532SSean.Ye@Sun.COM extern void *cmi_hdl_getspecific(cmi_hdl_t);
128*7532SSean.Ye@Sun.COM extern const struct cmi_mc_ops *cmi_hdl_getmcops(cmi_hdl_t);
129*7532SSean.Ye@Sun.COM extern void *cmi_hdl_getmcdata(cmi_hdl_t);
130*7532SSean.Ye@Sun.COM extern enum cmi_hdl_class cmi_hdl_class(cmi_hdl_t);
131*7532SSean.Ye@Sun.COM 
132*7532SSean.Ye@Sun.COM extern cmi_hdl_t cmi_hdl_lookup(enum cmi_hdl_class, uint_t, uint_t, uint_t);
133*7532SSean.Ye@Sun.COM extern cmi_hdl_t cmi_hdl_any(void);
134*7532SSean.Ye@Sun.COM 
135*7532SSean.Ye@Sun.COM #define	CMI_HDL_WALK_NEXT	0
136*7532SSean.Ye@Sun.COM #define	CMI_HDL_WALK_DONE	1
137*7532SSean.Ye@Sun.COM extern void cmi_hdl_walk(int (*)(cmi_hdl_t, void *, void *, void *),
138*7532SSean.Ye@Sun.COM     void *, void *, void *);
139*7532SSean.Ye@Sun.COM 
140*7532SSean.Ye@Sun.COM extern void cmi_hdlconf_rdmsr_nohw(cmi_hdl_t);
141*7532SSean.Ye@Sun.COM extern void cmi_hdlconf_wrmsr_nohw(cmi_hdl_t);
142*7532SSean.Ye@Sun.COM extern cmi_errno_t cmi_hdl_rdmsr(cmi_hdl_t, uint_t, uint64_t *);
143*7532SSean.Ye@Sun.COM extern cmi_errno_t cmi_hdl_wrmsr(cmi_hdl_t, uint_t, uint64_t);
144*7532SSean.Ye@Sun.COM 
145*7532SSean.Ye@Sun.COM extern void cmi_hdl_enable_mce(cmi_hdl_t);
146*7532SSean.Ye@Sun.COM 
147*7532SSean.Ye@Sun.COM extern uint_t cmi_hdl_vendor(cmi_hdl_t);
148*7532SSean.Ye@Sun.COM extern const char *cmi_hdl_vendorstr(cmi_hdl_t);
149*7532SSean.Ye@Sun.COM extern uint_t cmi_hdl_family(cmi_hdl_t);
150*7532SSean.Ye@Sun.COM extern uint_t cmi_hdl_model(cmi_hdl_t);
151*7532SSean.Ye@Sun.COM extern uint_t cmi_hdl_stepping(cmi_hdl_t);
152*7532SSean.Ye@Sun.COM extern uint_t cmi_hdl_chipid(cmi_hdl_t);
153*7532SSean.Ye@Sun.COM extern uint_t cmi_hdl_dieid(cmi_hdl_t);
154*7532SSean.Ye@Sun.COM extern uint_t cmi_hdl_coreid(cmi_hdl_t);
155*7532SSean.Ye@Sun.COM extern uint_t cmi_hdl_strandid(cmi_hdl_t);
156*7532SSean.Ye@Sun.COM extern boolean_t cmi_hdl_is_cmt(cmi_hdl_t);
157*7532SSean.Ye@Sun.COM extern uint32_t cmi_hdl_chiprev(cmi_hdl_t);
158*7532SSean.Ye@Sun.COM extern const char *cmi_hdl_chiprevstr(cmi_hdl_t);
159*7532SSean.Ye@Sun.COM extern uint32_t cmi_hdl_getsockettype(cmi_hdl_t);
160*7532SSean.Ye@Sun.COM extern id_t cmi_hdl_logical_id(cmi_hdl_t);
161*7532SSean.Ye@Sun.COM 
162*7532SSean.Ye@Sun.COM extern int cmi_hdl_online(cmi_hdl_t, int, int *);
163*7532SSean.Ye@Sun.COM 
164*7532SSean.Ye@Sun.COM #ifndef	__xpv
165*7532SSean.Ye@Sun.COM extern uint_t cmi_ntv_hwchipid(cpu_t *);
166*7532SSean.Ye@Sun.COM extern uint_t cmi_ntv_hwcoreid(cpu_t *);
167*7532SSean.Ye@Sun.COM extern uint_t cmi_ntv_hwstrandid(cpu_t *);
168*7532SSean.Ye@Sun.COM #endif	/* __xpv */
169*7532SSean.Ye@Sun.COM 
170*7532SSean.Ye@Sun.COM typedef struct cmi_mca_regs {
171*7532SSean.Ye@Sun.COM 	uint_t cmr_msrnum;
172*7532SSean.Ye@Sun.COM 	uint64_t cmr_msrval;
173*7532SSean.Ye@Sun.COM } cmi_mca_regs_t;
174*7532SSean.Ye@Sun.COM 
175*7532SSean.Ye@Sun.COM extern cmi_errno_t cmi_hdl_msrinject(cmi_hdl_t, cmi_mca_regs_t *, uint_t,
176*7532SSean.Ye@Sun.COM     int);
177*7532SSean.Ye@Sun.COM extern void cmi_hdl_msrinterpose(cmi_hdl_t, cmi_mca_regs_t *, uint_t);
178*7532SSean.Ye@Sun.COM extern void cmi_hdl_msrforward(cmi_hdl_t, cmi_mca_regs_t *, uint_t);
179*7532SSean.Ye@Sun.COM extern boolean_t cmi_inj_tainted(void);
180*7532SSean.Ye@Sun.COM 
181*7532SSean.Ye@Sun.COM extern void cmi_faulted_enter(cmi_hdl_t);
182*7532SSean.Ye@Sun.COM extern void cmi_faulted_exit(cmi_hdl_t);
183*7532SSean.Ye@Sun.COM 
184*7532SSean.Ye@Sun.COM extern void cmi_pcird_nohw(void);
185*7532SSean.Ye@Sun.COM extern void cmi_pciwr_nohw(void);
186*7532SSean.Ye@Sun.COM extern uint8_t cmi_pci_getb(int, int, int, int, int *, ddi_acc_handle_t);
187*7532SSean.Ye@Sun.COM extern uint16_t cmi_pci_getw(int, int, int, int, int *, ddi_acc_handle_t);
188*7532SSean.Ye@Sun.COM extern uint32_t cmi_pci_getl(int, int, int, int, int *, ddi_acc_handle_t);
189*7532SSean.Ye@Sun.COM extern void cmi_pci_interposeb(int, int, int, int, uint8_t);
190*7532SSean.Ye@Sun.COM extern void cmi_pci_interposew(int, int, int, int, uint16_t);
191*7532SSean.Ye@Sun.COM extern void cmi_pci_interposel(int, int, int, int, uint32_t);
192*7532SSean.Ye@Sun.COM extern void cmi_pci_putb(int, int, int, int, ddi_acc_handle_t, uint8_t);
193*7532SSean.Ye@Sun.COM extern void cmi_pci_putw(int, int, int, int, ddi_acc_handle_t, uint16_t);
194*7532SSean.Ye@Sun.COM extern void cmi_pci_putl(int, int, int, int, ddi_acc_handle_t, uint32_t);
195*7532SSean.Ye@Sun.COM 
196*7532SSean.Ye@Sun.COM extern void cmi_mca_init(cmi_hdl_t);
197*7532SSean.Ye@Sun.COM 
198*7532SSean.Ye@Sun.COM extern void cmi_hdl_poke(cmi_hdl_t);
199*7532SSean.Ye@Sun.COM extern void cmi_hdl_int(cmi_hdl_t, int);
200*7532SSean.Ye@Sun.COM 
201*7532SSean.Ye@Sun.COM extern void cmi_mca_trap(struct regs *);
202*7532SSean.Ye@Sun.COM 
203*7532SSean.Ye@Sun.COM extern boolean_t cmi_panic_on_ue(void);
204*7532SSean.Ye@Sun.COM 
205*7532SSean.Ye@Sun.COM extern void cmi_mc_register(cmi_hdl_t, const struct cmi_mc_ops *, void *);
206*7532SSean.Ye@Sun.COM extern void cmi_mc_sw_memscrub_disable(void);
207*7532SSean.Ye@Sun.COM extern cmi_errno_t cmi_mc_patounum(uint64_t, uint8_t, uint8_t, uint32_t, int,
208*7532SSean.Ye@Sun.COM     mc_unum_t *);
209*7532SSean.Ye@Sun.COM extern cmi_errno_t cmi_mc_unumtopa(mc_unum_t *, nvlist_t *, uint64_t *);
210*7532SSean.Ye@Sun.COM extern void cmi_mc_logout(cmi_hdl_t, boolean_t, boolean_t);
211*7532SSean.Ye@Sun.COM 
212*7532SSean.Ye@Sun.COM extern void cmi_panic_callback(void);
213*7532SSean.Ye@Sun.COM 
214*7532SSean.Ye@Sun.COM #endif /* _KERNEL */
215*7532SSean.Ye@Sun.COM 
216*7532SSean.Ye@Sun.COM #ifdef __cplusplus
217*7532SSean.Ye@Sun.COM }
218*7532SSean.Ye@Sun.COM #endif
219*7532SSean.Ye@Sun.COM 
220*7532SSean.Ye@Sun.COM #endif /* _SYS_CPU_MODULE_H */
221