xref: /titanic_51/usr/src/uts/i86pc/cpu/amd_opteron/ao.h (revision cbdcbd056f15c9c9fd82d5543b3a502677c4d391)
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 2009 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 #include <sys/types.h>
31 #include <sys/mc.h>
32 #include <sys/mca_amd.h>
33 #include <sys/mc_amd.h>
34 #include <sys/cpu_module_ms_impl.h>
35 #include <sys/nvpair.h>
36 #include <sys/cyclic.h>
37 #include <sys/errorq.h>
38 #include <sys/kobj.h>
39 #include <sys/fm/util.h>
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 #define	AO_MAX_CHIPS		8
46 
47 #define	AO_MCA_MAX_ERRORS	10
48 
49 typedef struct ao_ms_data ao_ms_data_t;
50 
51 /*
52  * Rather than using torturous conditionals, we match errors using a table of
53  * ao_error_disp_t's.  The members in the ao_error_disp_t are matched against
54  * the value of MCi_STATUS, with a successful match indicating that the given
55  * error occurred.
56  *
57  * While aed_stat_code will match most of the status code bits, a few of the
58  * status code fields are either/or, and are treated separately so as to
59  * minimize the number of ao_error_disp_t structures that must be created.
60  * For example, the dc.tag_par error can have r4 values drd or dwr.  Rather
61  * than creating two ao_error_disp_t's, we use the separate aed_stat_r4_bits
62  * field to indicate both AO_MCA_R4_BIT_DRD and AO_MCA_R4_BIT_DWD.  As the
63  * matching r4 values are drawn from aed_stat_r4_bits, we don't use the r4
64  * bits in aed_stat_code for matching.  Similar reasoning lies behind the
65  * creation of the pp and ii fields.
66  */
67 #define	AO_AED_PANIC_NEVER	0x00
68 #define	AO_AED_PANIC_IFMCE	0x01
69 #define	AO_AED_PANIC_ALWAYS	0x80
70 
71 /*
72  * The AO_AED_F_* flags tell us how to interpret aspects of the error
73  * telemetry, such as which bits of the captured address are valid for
74  * this error.
75  */
76 					/* MCi_ADDR ... */
77 #define	AO_AED_F_LINEAR		0x01	/* is a linear address */
78 #define	AO_AED_F_PHYSICAL	0x02	/* is a physical address */
79 #define	AO_AED_F_PAGEALIGNED	0x04	/* aligns to page size */
80 #define	AO_AED_F_L2SETWAY	0x08	/* 3:0 = way, 15/14/13/12:6 = set */
81 
82 #define	AO_AED_FLAGS_ADDRTYPE	(AO_AED_F_LINEAR | AO_AED_F_PHYSICAL | \
83     AO_AED_F_PAGEALIGNED | AO_AED_F_L2SETWAY)
84 
85 /*
86  * The AO_AED_ET_* flags group individual error dispositions into
87  * error types.  This is used to nominate additional telemetry beyond the
88  * architectural bank registers to capture for this error type.
89  */
90 #define	AO_AED_ET_MEMECC		0x0001	/* Main memory ECC error */
91 
92 typedef struct ao_error_disp {
93 	const char *aed_class;		/* ereport class for use if match */
94 	uint64_t aed_ereport_members;	/* ereport contents flags if match */
95 	uint64_t aed_stat_mask;		/* status msr bits for match */
96 	uint64_t aed_stat_mask_res;	/* status mask result for match */
97 	uint16_t aed_stat_code;		/* status code for match */
98 	uint8_t aed_stat_extcode;	/* extended status code for match */
99 	uint8_t aed_stat_pp_bits:4;	/* AO_MCA_PP_BIT_* for pp matching */
100 	uint8_t aed_stat_ii_bits:4;	/* AO_MCA_II_BIT_* for ii matching */
101 	uint16_t aed_stat_r4_bits;	/* AO_MCA_R4_BIT_* for r4 matching */
102 	uint8_t aed_addrvalid_hi;	/* most significant valid addr bit */
103 	uint8_t aed_addrvalid_lo;	/* least significant valid addr bit */
104 	uint8_t aed_panic_when;		/* extra conditions for panic */
105 	uint16_t aed_flags;		/* AO_AED_F_* */
106 	uint16_t aed_errtype;		/* AO_AED_ET_* */
107 } ao_error_disp_t;
108 
109 /*
110  * We store non-architectutal config as inherited from the BIOS to assist
111  * in troubleshooting.
112  */
113 struct ao_bios_cfg {
114 	uint64_t *bcfg_bank_mask;
115 };
116 
117 /*
118  * The master data structure used to hold MCA-related state.
119  */
120 typedef struct ao_ms_mca {
121 	struct ao_bios_cfg ao_mca_bios_cfg;
122 	kmutex_t ao_mca_poll_lock;	/* keep pollers from colliding */
123 	uint_t ao_mca_flags;		/* AO_MCA_F_* */
124 } ao_ms_mca_t;
125 
126 /*
127  * Per-chip shared state
128  */
129 struct ao_chipshared {
130 	uint32_t aos_chiprev;
131 	volatile ulong_t aos_cfgonce;	/* Config performed once per chip */
132 	hrtime_t aos_nb_poll_timestamp;
133 	cmi_hdl_t aos_nb_poll_owner;
134 	uint64_t aos_bcfg_nb_misc;	/* BIOS value of MC4_MISC MSR */
135 	uint32_t aos_bcfg_nb_cfg;	/* BIOS value of NB MCA Config */
136 	uint32_t aos_bcfg_nb_sparectl;	/* BIOS value of Online Spare Control */
137 	uint32_t aos_bcfg_dcfg_lo;	/* BIOS value of DRAM Config Low */
138 	uint32_t aos_bcfg_dcfg_hi;	/* BIOS value of DRAM Config High */
139 	uint32_t aos_bcfg_scrubctl;	/* BIOS value of scrub control */
140 };
141 
142 /* Bit numbers for once-per-chip operations policed by cms_once */
143 enum ao_cfgonce_bitnum {
144 	AO_CFGONCE_NBMCA,
145 	AO_CFGONCE_NBCFG,
146 	AO_CFGONCE_DRAMCFG
147 };
148 
149 /*
150  * Per-CPU model-specific state
151  */
152 struct ao_ms_data {
153 	cmi_hdl_t ao_ms_hdl;
154 	ao_ms_mca_t ao_ms_mca;
155 	struct ao_chipshared *ao_ms_shared;
156 	uint64_t ao_ms_hwcr_val;
157 };
158 
159 #ifdef _KERNEL
160 
161 struct regs;
162 
163 /*
164  * Our cms_ops operations and function prototypes for all non-NULL members.
165  */
166 extern const cms_ops_t _cms_ops;
167 
168 extern int ao_ms_init(cmi_hdl_t, void **);
169 extern void ao_ms_post_startup(cmi_hdl_t);
170 extern void ao_ms_post_mpstartup(cmi_hdl_t);
171 extern uint64_t ao_ms_mcgctl_val(cmi_hdl_t, int, uint64_t);
172 extern boolean_t ao_ms_bankctl_skipinit(cmi_hdl_t, int);
173 extern uint64_t ao_ms_bankctl_val(cmi_hdl_t, int, uint64_t);
174 extern void ao_ms_mca_init(cmi_hdl_t, int);
175 extern uint64_t ao_ms_poll_ownermask(cmi_hdl_t, hrtime_t);
176 extern uint32_t ao_ms_error_action(cmi_hdl_t, int, int, uint64_t,
177     uint64_t, uint64_t, void *);
178 extern cms_cookie_t ao_ms_disp_match(cmi_hdl_t, int, uint64_t, uint64_t,
179     uint64_t, void *);
180 extern void ao_ms_ereport_class(cmi_hdl_t, cms_cookie_t, const char **,
181     const char **);
182 extern boolean_t ao_ms_ereport_includestack(cmi_hdl_t, cms_cookie_t);
183 extern void ao_ms_ereport_add_logout(cmi_hdl_t, nvlist_t *,
184     nv_alloc_t *, int, uint64_t, uint64_t, uint64_t, void *, void *);
185 extern cms_errno_t ao_ms_msrinject(cmi_hdl_t, uint_t, uint64_t);
186 
187 /*
188  * Local functions
189  */
190 extern void ao_procnode_scrubber_enable(cmi_hdl_t, ao_ms_data_t *);
191 extern void ao_pcicfg_write(uint_t, uint_t, uint_t, uint32_t);
192 extern uint32_t ao_pcicfg_read(uint_t, uint_t, uint_t);
193 extern void ao_bankstatus_prewrite(cmi_hdl_t, ao_ms_data_t *);
194 extern void ao_bankstatus_postwrite(cmi_hdl_t, ao_ms_data_t *);
195 
196 #endif /* _KERNEL */
197 
198 #ifdef __cplusplus
199 }
200 #endif
201 
202 #endif /* _AO_H */
203