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