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 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * Case management and saved state restoration
30 #include <gmem_state.h>
32 #include <gmem_page.h>
33 #include <gmem_dimm.h>
37 #include <fm/fmd_api.h>
39 /* Must be in sync with gmem_ptrsubtype_t */
40 static gmem_case_closer_f
*const gmem_case_closers
[] = {
42 gmem_dimm_close
, /* GMEM_PTR_DIMM_CASE */
43 gmem_page_close
, /* GMEM_PTR_PAGE_CASE */
47 gmem_case_create(fmd_hdl_t
*hdl
, gmem_header_t
*hdr
,
48 gmem_ptrsubtype_t ptrsubtype
, const char **uuidp
)
51 gmem_case_closer_t
*cl
;
54 cl
= fmd_hdl_alloc(hdl
, sizeof (gmem_case_closer_t
), FMD_SLEEP
);
55 cl
->cl_func
= gmem_case_closers
[ptrsubtype
];
58 cp
= fmd_case_open(hdl
, cl
);
60 ptr
.ptr_type
= hdr
->hdr_nodetype
;
61 ptr
.ptr_subtype
= ptrsubtype
;
62 (void) strcpy(ptr
.ptr_name
, hdr
->hdr_bufname
);
64 *uuidp
= fmd_case_uuid(hdl
, cp
);
65 fmd_buf_write(hdl
, cp
, *uuidp
, &ptr
, sizeof (gmem_case_ptr_t
));
71 gmem_case_redirect(fmd_hdl_t
*hdl
, fmd_case_t
*cp
, gmem_ptrsubtype_t newsubtype
)
73 const char *uuid
= fmd_case_uuid(hdl
, cp
);
76 fmd_buf_read(hdl
, cp
, uuid
, &ptr
, sizeof (gmem_case_ptr_t
));
77 fmd_hdl_debug(hdl
, "redirecting case %s from %d to %d\n", uuid
,
78 ptr
.ptr_subtype
, newsubtype
);
79 ptr
.ptr_subtype
= newsubtype
;
80 fmd_buf_write(hdl
, cp
, uuid
, &ptr
, sizeof (gmem_case_ptr_t
));
84 gmem_case_fini(fmd_hdl_t
*hdl
, fmd_case_t
*cp
, int close
)
86 const char *uuid
= fmd_case_uuid(hdl
, cp
);
87 gmem_case_closer_t
*cl
= fmd_case_getspecific(hdl
, cp
);
90 fmd_hdl_debug(hdl
, "closing case %s\n", uuid
);
92 if (fmd_serd_exists(hdl
, uuid
))
93 fmd_serd_destroy(hdl
, uuid
);
95 if (fmd_buf_size(hdl
, cp
, uuid
) != 0)
96 fmd_buf_destroy(hdl
, cp
, uuid
);
98 fmd_case_setspecific(hdl
, cp
, NULL
);
99 fmd_case_close(hdl
, cp
);
103 fmd_hdl_free(hdl
, cl
, sizeof (gmem_case_closer_t
));
106 /* Must be in sync with gmem_nodetype_t */
107 static gmem_case_restorer_f
*const gmem_case_restorers
[] = {
109 gmem_dimm_restore
, /* CMD_NT_DIMM */
110 gmem_page_restore
, /* CMD_NT_PAGE */
114 gmem_state_restore(fmd_hdl_t
*hdl
)
116 fmd_case_t
*cp
= NULL
;
118 while ((cp
= fmd_case_next(hdl
, cp
)) != NULL
) {
119 const char *uuid
= fmd_case_uuid(hdl
, cp
);
120 gmem_case_closer_t
*cl
;
125 if ((sz
= fmd_buf_size(hdl
, cp
, uuid
)) == 0)
127 else if (sz
!= sizeof (gmem_case_ptr_t
))
128 return (gmem_set_errno(EINVAL
));
130 fmd_buf_read(hdl
, cp
, fmd_case_uuid(hdl
, cp
), &ptr
,
131 sizeof (gmem_case_ptr_t
));
133 if (ptr
.ptr_type
== 0 || ptr
.ptr_type
>
134 sizeof (gmem_case_restorers
) /
135 sizeof (gmem_case_restorer_f
*))
136 return (gmem_set_errno(EINVAL
));
138 if ((thing
= gmem_case_restorers
[ptr
.ptr_type
](hdl
,
139 cp
, &ptr
)) == NULL
) {
140 fmd_hdl_debug(hdl
, "Unable to restore case %s\n", uuid
);
144 cl
= fmd_hdl_alloc(hdl
, sizeof (gmem_case_closer_t
), FMD_SLEEP
);
145 cl
->cl_func
= gmem_case_closers
[ptr
.ptr_subtype
];
147 fmd_case_setspecific(hdl
, cp
, cl
);
150 gmem_dimm_validate(hdl
);
151 gmem_page_validate(hdl
);
157 gmem_case_restore(fmd_hdl_t
*hdl
, gmem_case_t
*cc
, fmd_case_t
*cp
, char *serdnm
)
159 if (!fmd_serd_exists(hdl
, serdnm
)) {
160 fmd_hdl_strfree(hdl
, serdnm
);
165 cc
->cc_serdnm
= serdnm
;