xref: /illumos-gate/usr/src/uts/i86pc/cpu/amd_opteron/ao.h (revision 1979231e)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _AO_H
28 #define	_AO_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/mc.h>
34 #include <sys/mca_amd.h>
35 #include <sys/cpu_module_impl.h>
36 #include <sys/nvpair.h>
37 #include <sys/cyclic.h>
38 #include <sys/errorq.h>
39 #include <sys/kobj.h>
40 #include <sys/fm/util.h>
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 #define	AO_MCA_MAX_ERRORS	10
47 
48 typedef struct ao_data ao_data_t;
49 
50 typedef struct ao_bank_regs {
51 	uint32_t abr_status;
52 	uint32_t abr_addr;
53 } ao_bank_regs_t;
54 
55 extern ao_bank_regs_t ao_bank_regs[AMD_MCA_BANK_COUNT];
56 
57 /*
58  * Rather than using torturous conditionals, we match errors using a table of
59  * ao_error_disp_t's.  The members in the ao_error_disp_t are matched against
60  * the value of MCi_STATUS, with a successful match indicating that the given
61  * error occurred.
62  *
63  * While aed_stat_code will match most of the status code bits, a few of the
64  * status code fields are either/or, and are treated separately so as to
65  * minimize the number of ao_error_disp_t structures that must be created.
66  * For example, the dc.tag_par error can have r4 values drd or dwr.  Rather
67  * than creating two ao_error_disp_t's, we use the separate aed_stat_r4_bits
68  * field to indicate both AO_MCA_R4_BIT_DRD and AO_MCA_R4_BIT_DWD.  As the
69  * matching r4 values are drawn from aed_stat_r4_bits, we don't use the r4
70  * bits in aed_stat_code for matching.  Similar reasoning lies behind the
71  * creation of the pp and ii fields.
72  */
73 #define	AO_AED_PANIC_NEVER	0x00
74 #define	AO_AED_PANIC_IFMCE	0x01
75 #define	AO_AED_PANIC_ALWAYS	0x80
76 
77 #define	AO_AED_F_CORRECTABLE	0x01
78 #define	AO_AED_F_LOFAULT_OK	0x02
79 
80 typedef struct ao_error_disp {
81 	const char *aed_class;		/* ereport class for use if match */
82 	uint64_t aed_ereport_members;	/* ereport contents flags if match */
83 	uint64_t aed_stat_mask;		/* status msr bits for match */
84 	uint64_t aed_stat_mask_res;	/* status mask result for match */
85 	uint16_t aed_stat_code;		/* status code for match */
86 	uint8_t aed_stat_extcode;	/* extended status code for match */
87 	uint8_t aed_stat_pp_bits:4;	/* AO_MCA_PP_BIT_* for pp matching */
88 	uint8_t aed_stat_ii_bits:4;	/* AO_MCA_II_BIT_* for ii matching */
89 	uint16_t aed_stat_r4_bits;	/* AO_MCA_R4_BIT_* for r4 matching */
90 	uint8_t aed_panic_when;		/* extra conditions for panic */
91 	uint8_t aed_flags;		/* AO_AED_F_* */
92 } ao_error_disp_t;
93 
94 /*
95  * The poller has two parts.  First is the omni cyclic, which runs on all
96  * CPUs, and which polls the error MSRs at some fixed (long) interval.  This
97  * cyclic will run on all machines, all the time, and thus must have minimal
98  * runtime impact.  The second portion of the poller is manually-initiated, and
99  * is used by the error injector/synthesizer to request an immediate poll of the
100  * error state registers.
101  *
102  * With this number of moving parts, it is essential that we have some sort of
103  * audit log for post-mortem analysis.  A circular array of trace buffers
104  * (ao_mca_poll_trace_t structures) is kept to record this activity.  Whenever
105  * an event occurs that is of interest to the poller, an entry is made in
106  * the trace array describing that event.
107  */
108 #define	AO_MPT_WHAT_CYC_ERR		0	/* cyclic-induced poll */
109 #define	AO_MPT_WHAT_POKE_ERR		1	/* manually-induced poll */
110 #define	AO_MPT_WHAT_UNFAULTING		2	/* discarded error state */
111 
112 typedef struct ao_mca_poll_trace {
113 	hrtime_t mpt_when;		/* timestamp of event */
114 	uint8_t mpt_what;		/* AO_MPT_WHAT_* (which event?) */
115 	uint8_t mpt_nerr;		/* number of errors discovered */
116 	uint16_t mpt_pad1;
117 	uint32_t mpt_pad2;
118 } ao_mca_poll_trace_t;
119 
120 /*
121  * Processor error state is saved in logout areas.  There are three separate
122  * logout areas, each used for a different purpose.  The logout areas are stored
123  * in an array (ao_mca_logout), indexed by the AO_MCA_LOGOUT_* macros.
124  *
125  * The save areas are:
126  *
127  * 1. Exception handler MSR save - Written to by the initial portion of the #mc
128  *    handler.  Read from by the main body of the exception handler.
129  *
130  * 3. Poller MSR save - Used by the poller to store error state MSR values.
131  *    While this logout area doesn't necessarily have to live in the ao_mca_t,
132  *    it does so to enhance observability.
133  *
134  * The logout areas contain both global error state (acl_ip, acl_timestamp,
135  * etc.), as well as a bank array.  The bank array contains one ao_bank_logout_t
136  * per error reporting bank.
137  */
138 
139 typedef struct ao_bank_logout {
140 	uint64_t abl_status;		/* Saved MCi_STATUS register */
141 	uint64_t abl_addr;		/* Saved MCi_ADDR register */
142 } ao_bank_logout_t;
143 
144 #define	AO_ACL_F_PRIV		0x1	/* #mc in kernel mode (else user) */
145 #define	AO_ACL_F_FATAL		0x2	/* logout detected fatal error(s) */
146 
147 typedef struct ao_cpu_logout {
148 	ao_data_t *acl_ao;		/* pointer to per-cpu ao_data_t */
149 	uintptr_t acl_ip;		/* instruction pointer if #mc trap */
150 	uint64_t acl_timestamp;		/* gethrtime() at time of logout */
151 	uint64_t acl_mcg_status;	/* MCG_STATUS register value */
152 	ao_bank_logout_t acl_banks[AMD_MCA_BANK_COUNT]; /* bank state saves */
153 	pc_t acl_stack[FM_STK_DEPTH];	/* saved stack trace (if any) */
154 	int acl_stackdepth;		/* saved stack trace depth */
155 	uint_t acl_flags;		/* flags (see AO_ACL_F_* above) */
156 } ao_cpu_logout_t;
157 
158 /* Index for ao_mca_logout, below */
159 #define	AO_MCA_LOGOUT_EXCEPTION		0
160 #define	AO_MCA_LOGOUT_POLLER		1
161 #define	AO_MCA_LOGOUT_NUM		2
162 
163 #define	AO_MCA_F_UNFAULTING		0x1	/* CPU exiting faulted state */
164 
165 /*
166  * We store config as inherited from the BIOS to assist in troubleshooting.
167  */
168 typedef struct ao_bios_cfg {
169 	uint64_t bcfg_bank_ctl[AMD_MCA_BANK_COUNT];
170 	uint64_t bcfg_bank_mask[AMD_MCA_BANK_COUNT];
171 	uint32_t bcfg_nb_cfg;
172 } ao_bios_cfg_t;
173 
174 /*
175  * The master data structure used to hold MCA-related state.
176  */
177 typedef struct ao_mca {
178 	ao_bios_cfg_t ao_mca_bios_cfg;	/* Bank and NB config before our init */
179 	ao_cpu_logout_t ao_mca_logout[AO_MCA_LOGOUT_NUM]; /* save areas */
180 	kmutex_t ao_mca_poll_lock;	/* keep pollers from colliding */
181 	ao_mca_poll_trace_t *ao_mca_poll_trace; /* trace buffers for this cpu */
182 	uint_t ao_mca_poll_curtrace;	/* most recently-filled trace buffer */
183 	uint_t ao_mca_flags;		/* AO_MCA_F_* */
184 } ao_mca_t;
185 
186 /*
187  * Per-CPU state
188  */
189 struct ao_data {
190 	ao_mca_t ao_mca;		/* MCA state for this CPU */
191 	cpu_t *ao_cpu;			/* link to CPU's cpu_t */
192 	const cmi_mc_ops_t *ao_mc_ops;	/* memory controller ops */
193 	void *ao_mc_data;		/* argument for memory controller ops */
194 };
195 
196 #ifdef _KERNEL
197 
198 struct regs;
199 
200 extern errorq_t *ao_mca_queue;
201 extern const cmi_ops_t _cmi_ops;
202 
203 extern void ao_faulted_enter(void *);
204 extern void ao_faulted_exit(void *);
205 extern int ao_scrubber_enable(void *, uint64_t, uint64_t);
206 
207 extern void ao_mca_post_init(void *);
208 extern void ao_mca_init(void *);
209 extern int ao_mca_trap(void *, struct regs *);
210 extern int ao_mca_inject(void *, cmi_mca_regs_t *, uint_t);
211 extern void ao_mca_poke(void *);
212 extern void ao_mca_poll_init(ao_mca_t *);
213 extern void ao_mca_poll_start(void);
214 
215 extern int ao_mca_logout(ao_cpu_logout_t *, struct regs *, int *);
216 extern void ao_mca_drain(void *, const void *, const errorq_elem_t *);
217 extern nvlist_t *ao_fmri_create(ao_data_t *, nv_alloc_t *);
218 
219 extern void ao_mc_register(void *, const cmi_mc_ops_t *, void *);
220 extern const struct cmi_mc_ops *ao_mc_getops(void *);
221 extern int ao_mc_patounum(ao_data_t *, uint64_t, uint32_t, int, mc_unum_t *);
222 extern int ao_mc_unumtopa(ao_data_t *, mc_unum_t *, nvlist_t *, uint64_t *);
223 
224 extern void ao_pcicfg_write(uint_t, uint_t, uint_t, uint32_t);
225 extern uint32_t ao_pcicfg_read(uint_t, uint_t, uint_t);
226 
227 #endif /* _KERNEL */
228 
229 #ifdef __cplusplus
230 }
231 #endif
232 
233 #endif /* _AO_H */
234