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 * Support routines for managing state related to memory modules.
31 #include <gmem_dimm.h>
40 #include <fm/fmd_api.h>
41 #include <sys/fm/protocol.h>
43 #include <sys/nvpair.h>
46 gmem_mem_serdnm_create(fmd_hdl_t
*hdl
, const char *serdbase
, const char *serial
)
48 const char *fmt
= "%s_%s_serd";
49 size_t sz
= snprintf(NULL
, 0, fmt
, serdbase
, serial
) + 1;
50 char *nm
= fmd_hdl_alloc(hdl
, sz
, FMD_SLEEP
);
51 (void) snprintf(nm
, sz
, fmt
, serdbase
, serial
);
57 gmem_page_serdnm_create(fmd_hdl_t
*hdl
, const char *serdbase
,
60 const char *fmt
= "%s_%llXserd";
61 size_t sz
= snprintf(NULL
, 0, fmt
, serdbase
, phys_addr
) + 1;
62 char *nm
= fmd_hdl_alloc(hdl
, sz
, FMD_SLEEP
);
63 (void) snprintf(nm
, sz
, fmt
, serdbase
, phys_addr
);
69 gmem_mq_serdnm_create(fmd_hdl_t
*hdl
, const char *serdbase
,
70 uint64_t phys_addr
, uint16_t cw
, uint16_t pos
)
72 const char *fmt
= "%s_%llX_%x_%x_serd";
73 size_t sz
= snprintf(NULL
, 0, fmt
, serdbase
, phys_addr
, cw
, pos
) + 1;
74 char *nm
= fmd_hdl_alloc(hdl
, sz
, FMD_SLEEP
);
75 (void) snprintf(nm
, sz
, fmt
, serdbase
, phys_addr
, cw
, pos
);
81 gmem_get_serd_filter_ratio(nvlist_t
*nvl
)
83 uint32_t filter_ratio
= 0;
86 if (gmem
.gm_filter_ratio
== 0) {
87 if (nvlist_lookup_uint32(nvl
,
88 GMEM_ERPT_PAYLOAD_FILTER_RATIO
, &erpt_ratio
) == 0)
89 filter_ratio
= erpt_ratio
;
91 filter_ratio
= gmem
.gm_filter_ratio
;
93 return (filter_ratio
);
97 gmem_page_serd_create(fmd_hdl_t
*hdl
, gmem_page_t
*page
, nvlist_t
*nvl
)
99 uint32_t erpt_serdn
, serd_n
;
100 uint64_t erpt_serdt
, serd_t
;
102 serd_n
= gmem
.gm_ce_n
;
103 serd_t
= gmem
.gm_ce_t
;
105 if (serd_n
== DEFAULT_SERDN
&& serd_t
== DEFAULT_SERDT
) {
106 if (nvlist_lookup_uint32(nvl
, GMEM_ERPT_PAYLOAD_SERDN
,
109 if (nvlist_lookup_uint64(nvl
, GMEM_ERPT_PAYLOAD_SERDT
,
114 page
->page_case
.cc_serdnm
= gmem_page_serdnm_create(hdl
, "page",
115 page
->page_physbase
);
117 fmd_serd_create(hdl
, page
->page_case
.cc_serdnm
, serd_n
, serd_t
);
121 gmem_serd_record(fmd_hdl_t
*hdl
, const char *serdbaser
, uint32_t ratio
,
126 return (fmd_serd_record(hdl
, serdbaser
, ep
));
127 for (i
= 0; i
< ratio
; i
++) {
128 rc
= fmd_serd_record(hdl
, serdbaser
, ep
);
129 if (rc
!= FMD_B_FALSE
)
136 gmem_mem_case_restore(fmd_hdl_t
*hdl
, gmem_case_t
*cc
, fmd_case_t
*cp
,
137 const char *serdbase
, const char *serial
)
139 gmem_case_restore(hdl
, cc
, cp
, gmem_mem_serdnm_create(hdl
, serdbase
,
144 gmem_mem_retirestat_create(fmd_hdl_t
*hdl
, fmd_stat_t
*st
, const char *serial
,
145 uint64_t value
, const char *prefix
)
148 (void) snprintf(st
->fmds_name
, sizeof (st
->fmds_name
), "%s%s",
150 (void) snprintf(st
->fmds_desc
, sizeof (st
->fmds_desc
),
151 "retirements for %s%s", prefix
, serial
);
152 st
->fmds_type
= FMD_TYPE_UINT64
;
153 st
->fmds_value
.ui64
= value
;
155 (void) fmd_stat_create(hdl
, FMD_STAT_NOALLOC
, 1, st
);
159 gmem_mem_gc(fmd_hdl_t
*hdl
)
165 gmem_mem_fini(fmd_hdl_t
*hdl
)