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.
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.
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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
28 * Case management and saved state restoration
31 #include <cmd_state.h>
38 #include <cmd_dp_page.h>
39 #include <cmd_Lxcache.h>
44 #include <cmd_branch.h>
48 #include <fm/fmd_api.h>
54 /* Must be in sync with cmd_ptrsubtype_t */
55 static cmd_case_closer_f
*const cmd_case_closers
[] = {
57 cmd_cpuerr_close
, /* CMD_PTR_CPU_ICACHE */
58 cmd_cpuerr_close
, /* CMD_PTR_CPU_DCACHE */
59 cmd_cpuerr_close
, /* CMD_PTR_CPU_PCACHE */
60 cmd_cpuerr_close
, /* CMD_PTR_CPU_ITLB */
61 cmd_cpuerr_close
, /* CMD_PTR_CPU_DTLB */
62 cmd_cpuerr_close
, /* CMD_PTR_CPU_L2DATA */
63 cmd_cpuerr_close
, /* CMD_PTR_CPU_L2DATA_UERETRY */
64 cmd_cpuerr_close
, /* CMD_PTR_CPU_L2TAG */
65 cmd_cpuerr_close
, /* CMD_PTR_CPU_L3DATA */
66 cmd_cpuerr_close
, /* CMD_PTR_CPU_L3DATA_UERETRY */
67 cmd_cpuerr_close
, /* CMD_PTR_CPU_L3TAG */
68 cmd_dimm_close
, /* CMD_PTR_DIMM_CASE */
69 cmd_bank_close
, /* CMD_PTR_BANK_CASE */
70 cmd_page_close
, /* CMD_PTR_PAGE_CASE */
71 cmd_cpuerr_close
, /* CMD_PTR_CPU_FPU */
72 NULL
, /* CMD_PTR_CPU_XR_RETRY */
73 cmd_cpuerr_close
, /* CMD_PTR_CPU_IREG */
74 cmd_cpuerr_close
, /* CMD_PTR_CPU_FREG */
75 cmd_cpuerr_close
, /* CMD_PTR_CPU_MAU */
76 cmd_cpuerr_close
, /* CMD_PTR_CPU_L2CTL */
78 cmd_dp_close
, /* CMD_PTR_DP_CASE */
80 NULL
, /* CMD_PTR_DP_CASE */
82 NULL
, /* CMD_PTR_DP_PAGE_DEFER */
83 cmd_cpuerr_close
, /* CMD_PTR_CPU_INV_SFSR */
84 cmd_cpuerr_close
, /* CMD_PTR_CPU_UE_DET_CPU */
85 cmd_cpuerr_close
, /* CMD_PTR_CPU_UE_DET_IO */
86 cmd_cpuerr_close
, /* CMD_PTR_CPU_MTLB */
87 cmd_cpuerr_close
, /* CMD_PTR_CPU_TLBP */
88 cmd_cpuerr_close
, /* CMD_PTR_CPU_UGESR_INV_URG */
89 cmd_cpuerr_close
, /* CMD_PTR_CPU_UGESR_CRE */
90 cmd_cpuerr_close
, /* CMD_PTR_CPU_UGESR_TSB_CTX */
91 cmd_cpuerr_close
, /* CMD_PTR_CPU_UGESR_TSBP */
92 cmd_cpuerr_close
, /* CMD_PTR_CPU_UGESR_PSTATE */
93 cmd_cpuerr_close
, /* CMD_PTR_CPU_UGESR_TSTATE */
94 cmd_cpuerr_close
, /* CMD_PTR_CPU_UGESR_IUG_F */
95 cmd_cpuerr_close
, /* CMD_PTR_CPU_UGESR_IUG_R */
96 cmd_cpuerr_close
, /* CMD_PTR_CPU_UGESR_SDC */
97 cmd_cpuerr_close
, /* CMD_PTR_CPU_UGESR_WDT */
98 cmd_cpuerr_close
, /* CMD_PTR_CPU_UGESR_DTLB */
99 cmd_cpuerr_close
, /* CMD_PTR_CPU_UGESR_ITLB */
100 cmd_cpuerr_close
, /* CMD_PTR_CPU_UGESR_CORE_ERR */
101 cmd_cpuerr_close
, /* CMD_PTR_CPU_UGESR_DAE */
102 cmd_cpuerr_close
, /* CMD_PTR_CPU_UGESR_IAE */
103 cmd_cpuerr_close
, /* CMD_PTR_CPU_UGESR_UGE */
104 cmd_cpuerr_close
, /* CMD_PTR_CPU_MISC_REGS */
105 cmd_cpuerr_close
, /* CMD_PTR_CPU_LFU */
107 cmd_branch_close
/* CMD_PTR_BRANCH_CASE */
110 cmd_Lxcache_close
, /* CMD_PTR_CACHE_CASE */
116 cmd_case_create(fmd_hdl_t
*hdl
, cmd_header_t
*hdr
, cmd_ptrsubtype_t ptrsubtype
,
120 cmd_case_closer_t
*cl
;
123 cl
= fmd_hdl_alloc(hdl
, sizeof (cmd_case_closer_t
), FMD_SLEEP
);
124 cl
->cl_func
= cmd_case_closers
[ptrsubtype
];
127 cp
= fmd_case_open(hdl
, cl
);
129 ptr
.ptr_type
= hdr
->hdr_nodetype
;
130 ptr
.ptr_subtype
= ptrsubtype
;
131 (void) strcpy(ptr
.ptr_name
, hdr
->hdr_bufname
);
133 *uuidp
= fmd_case_uuid(hdl
, cp
);
134 fmd_buf_write(hdl
, cp
, *uuidp
, &ptr
, sizeof (cmd_case_ptr_t
));
140 cmd_case_redirect(fmd_hdl_t
*hdl
, fmd_case_t
*cp
, cmd_ptrsubtype_t newsubtype
)
142 const char *uuid
= fmd_case_uuid(hdl
, cp
);
145 fmd_buf_read(hdl
, cp
, uuid
, &ptr
, sizeof (cmd_case_ptr_t
));
146 fmd_hdl_debug(hdl
, "redirecting case %s from %d to %d\n", uuid
,
147 ptr
.ptr_subtype
, newsubtype
);
148 ptr
.ptr_subtype
= newsubtype
;
149 fmd_buf_write(hdl
, cp
, uuid
, &ptr
, sizeof (cmd_case_ptr_t
));
153 cmd_case_fini(fmd_hdl_t
*hdl
, fmd_case_t
*cp
, int close
)
155 const char *uuid
= fmd_case_uuid(hdl
, cp
);
156 cmd_case_closer_t
*cl
= fmd_case_getspecific(hdl
, cp
);
159 fmd_hdl_debug(hdl
, "closing case %s\n", uuid
);
161 if (fmd_serd_exists(hdl
, uuid
))
162 fmd_serd_destroy(hdl
, uuid
);
164 if (fmd_buf_size(hdl
, cp
, uuid
) != 0)
165 fmd_buf_destroy(hdl
, cp
, uuid
);
167 fmd_case_setspecific(hdl
, cp
, NULL
);
168 fmd_case_close(hdl
, cp
);
172 fmd_hdl_free(hdl
, cl
, sizeof (cmd_case_closer_t
));
175 /* Must be in sync with cmd_nodetype_t */
176 static cmd_case_restorer_f
*const cmd_case_restorers
[] = {
178 cmd_cpu_restore
, /* CMD_NT_CPU */
179 cmd_dimm_restore
, /* CMD_NT_DIMM */
180 cmd_bank_restore
, /* CMD_NT_BANK */
181 cmd_page_restore
, /* CMD_NT_PAGE */
183 cmd_dp_restore
, /* CMD_NT_DP */
184 cmd_Lxcache_restore
, /* CMD_NT_CACHE */
187 cmd_branch_restore
/* CMD_NT_BRANCH */
192 cmd_state_restore(fmd_hdl_t
*hdl
)
194 fmd_case_t
*cp
= NULL
;
196 while ((cp
= fmd_case_next(hdl
, cp
)) != NULL
) {
197 const char *uuid
= fmd_case_uuid(hdl
, cp
);
198 cmd_case_closer_t
*cl
;
203 if ((sz
= fmd_buf_size(hdl
, cp
, uuid
)) == 0)
205 else if (sz
!= sizeof (cmd_case_ptr_t
))
206 return (cmd_set_errno(EINVAL
));
208 fmd_buf_read(hdl
, cp
, fmd_case_uuid(hdl
, cp
), &ptr
,
209 sizeof (cmd_case_ptr_t
));
211 if (ptr
.ptr_type
== 0 || ptr
.ptr_type
>=
212 sizeof (cmd_case_restorers
) /
213 sizeof (cmd_case_restorer_f
*))
214 return (cmd_set_errno(EINVAL
));
216 if ((thing
= cmd_case_restorers
[ptr
.ptr_type
](hdl
,
217 cp
, &ptr
)) == NULL
) {
218 fmd_hdl_debug(hdl
, "Unable to restore case %s\n", uuid
);
222 cl
= fmd_hdl_alloc(hdl
, sizeof (cmd_case_closer_t
), FMD_SLEEP
);
223 cl
->cl_func
= cmd_case_closers
[ptr
.ptr_subtype
];
225 fmd_case_setspecific(hdl
, cp
, cl
);
228 cmd_trw_restore(hdl
);
230 cmd_cpu_validate(hdl
);
231 cmd_bank_validate(hdl
);
232 cmd_dimm_validate(hdl
);
235 * cmd_dp_page_validate() must be done before cmd_dp_validate()
236 * and cmd_page_validate()
238 cmd_dp_page_validate(hdl
);
239 cmd_dp_validate(hdl
);
241 cmd_page_validate(hdl
);
243 cmd_branch_validate(hdl
);
250 cmd_case_restore(fmd_hdl_t
*hdl
, cmd_case_t
*cc
, fmd_case_t
*cp
, char *serdnm
)
252 if (!fmd_serd_exists(hdl
, serdnm
)) {
253 fmd_hdl_strfree(hdl
, serdnm
);
258 cc
->cc_serdnm
= serdnm
;