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]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
32 get_tagtype_str(fru_tagtype_t e
)
56 get_tag_size(fru_tagtype_t tag
)
77 mk_tag(fru_tagtype_t type
, uint32_t dense
, size_t pl_len
,
80 static fru_tag_t max
= { 0xFFFFFFFFFFFFFFFFULL
};
81 /* make sure the tag is clear. */
84 /* then fill it in with data. */
87 if ((dense
> max
.a
.dense
) || (pl_len
> max
.a
.pl_len
)) {
91 tag
->a
.type
= FRU_A_ID
;
93 tag
->a
.pl_len
= pl_len
;
96 if ((dense
> max
.b
.dense
) || (pl_len
> max
.b
.pl_len
)) {
100 tag
->b
.type
= FRU_B_ID
;
101 tag
->b
.dense
= dense
;
102 tag
->b
.pl_len
= pl_len
;
105 if ((dense
> max
.c
.dense
) || (pl_len
> max
.c
.pl_len
)) {
109 tag
->c
.type
= FRU_C_ID
;
110 tag
->c
.dense
= dense
;
111 tag
->c
.pl_len
= pl_len
;
114 if ((dense
> max
.d
.dense
) || (pl_len
> max
.d
.pl_len
)) {
118 tag
->d
.type
= FRU_D_ID
;
119 tag
->d
.dense
= dense
;
120 tag
->d
.pl_len
= pl_len
;
123 if ((dense
> max
.e
.dense
) || (pl_len
> max
.e
.pl_len
)) {
127 tag
->e
.type
= FRU_E_ID
;
128 tag
->e
.dense
= dense
;
129 tag
->e
.pl_len
= pl_len
;
132 if ((dense
> max
.f
.dense
) || (pl_len
> max
.f
.pl_len
)) {
136 tag
->f
.type
= FRU_F_ID
;
137 tag
->f
.dense
= dense
;
138 tag
->f
.pl_len
= pl_len
;
141 if ((dense
> max
.g
.dense
) || (pl_len
> max
.g
.pl_len
)) {
145 tag
->g
.type
= FRU_G_ID
;
146 tag
->g
.dense
= dense
;
147 tag
->g
.pl_len
= pl_len
;
154 return (get_tag_size(type
));
157 #if defined(_LITTLE_ENDIAN)
159 get_tag_type(fru_tag_t
*tag
)
165 if (tag
->a
.type
== FRU_A_ID
)
168 tmp
.raw_data
= (tag
->byte
[0] << 8) | tag
->byte
[1];
169 if (tmp
.b
.type
== FRU_B_ID
)
171 if (tmp
.c
.type
== FRU_C_ID
)
174 tmp32
= (tag
->byte
[0] << 16) | (tag
->byte
[1] << 8) | tag
->byte
[2];
175 tmp
.raw_data
= tmp32
;
176 if (tmp
.d
.type
== FRU_D_ID
)
178 if (tmp
.e
.type
== FRU_E_ID
)
181 tmp32
= (tag
->byte
[0] << 24) | (tag
->byte
[1] << 16) |
182 (tag
->byte
[2] << 8) | tag
->byte
[3];
183 tmp
.raw_data
= tmp32
;
184 if (tmp
.f
.type
== FRU_F_ID
)
187 tmp64
= ((uint64_t)tag
->byte
[0] << 40) |
188 ((uint64_t)tag
->byte
[1] << 32) |
189 ((uint64_t)tag
->byte
[2] << 24) |
190 ((uint64_t)tag
->byte
[3] << 16) |
191 ((uint64_t)tag
->byte
[4] << 8) |
192 (uint64_t)tag
->byte
[5];
193 tmp
.raw_data
= tmp64
;
194 if (tmp
.g
.type
== FRU_G_ID
)
202 get_tag_type(fru_tag_t
*tag
)
204 if (tag
->a
.type
== FRU_A_ID
)
206 else if (tag
->b
.type
== FRU_B_ID
)
208 else if (tag
->c
.type
== FRU_C_ID
)
210 else if (tag
->d
.type
== FRU_D_ID
)
212 else if (tag
->e
.type
== FRU_E_ID
)
214 else if (tag
->f
.type
== FRU_F_ID
)
216 else if (tag
->g
.type
== FRU_G_ID
)
222 #endif /* _LITTLE_ENDIAN */
224 #if defined(_LITTLE_ENDIAN)
226 get_tag_dense(fru_tag_t
*tag
)
233 switch (get_tag_type(tag
)) {
235 return (tag
->a
.dense
);
237 tmp
.raw_data
= (tag
->byte
[0] << 8) | tag
->byte
[1];
238 return (tmp
.b
.dense
);
240 tmp
.raw_data
= (tag
->byte
[0] << 8) | tag
->byte
[1];
241 return (tmp
.c
.dense
);
243 tmp32
= (tag
->byte
[0] << 16) | (tag
->byte
[1] << 8) |
245 tmp
.raw_data
= tmp32
;
246 return (tmp
.d
.dense
);
248 tmp32
= (tag
->byte
[0] << 16) | (tag
->byte
[1] << 8) |
250 tmp
.raw_data
= tmp32
;
251 return (tmp
.e
.dense
);
253 tmp32
= (tag
->byte
[0] << 24) | (tag
->byte
[1] << 16) |
254 (tag
->byte
[2] << 8) | tag
->byte
[3];
255 tmp
.raw_data
= tmp32
;
256 return (tmp
.f
.dense
);
258 tmp64
= ((uint64_t)tag
->byte
[0] << 40) |
259 ((uint64_t)tag
->byte
[1] << 32) |
260 ((uint64_t)tag
->byte
[2] << 24) |
261 ((uint64_t)tag
->byte
[3] << 16) |
262 ((uint64_t)tag
->byte
[4] << 8) |
263 (uint64_t)tag
->byte
[5];
264 tmp
.raw_data
= tmp64
;
265 return (tmp
.g
.dense
);
268 return ((uint32_t)-1);
273 get_tag_dense(fru_tag_t
*tag
)
275 switch (get_tag_type(tag
)) {
277 return (tag
->a
.dense
);
279 return (tag
->b
.dense
);
281 return (tag
->c
.dense
);
283 return (tag
->d
.dense
);
285 return (tag
->e
.dense
);
287 return (tag
->f
.dense
);
289 return (tag
->g
.dense
);
292 return ((uint32_t)-1);
295 #endif /* _LITTLE_ENDIAN */
297 #if defined(_LITTLE_ENDIAN)
299 get_payload_length(fru_tag_t
*tag
)
306 switch (get_tag_type(tag
)) {
308 return (tag
->a
.pl_len
);
310 tmp
.raw_data
= (tag
->byte
[0] << 8) | tag
->byte
[1];
311 return (tmp
.b
.pl_len
);
313 tmp
.raw_data
= (tag
->byte
[0] << 8) | tag
->byte
[1];
314 return (tmp
.c
.pl_len
);
316 tmp32
= (tag
->byte
[0] << 16) | (tag
->byte
[1] << 8) |
318 tmp
.raw_data
= tmp32
;
319 return (tmp
.d
.pl_len
);
321 tmp32
= (tag
->byte
[0] << 16) | (tag
->byte
[1] << 8) |
323 tmp
.raw_data
= tmp32
;
324 return (tmp
.e
.pl_len
);
326 tmp32
= (tag
->byte
[0] << 24) | (tag
->byte
[1] << 16) |
327 (tag
->byte
[2] << 8) | tag
->byte
[3];
328 tmp
.raw_data
= tmp32
;
329 return (tmp
.f
.pl_len
);
331 tmp64
= ((uint64_t)tag
->byte
[0] << 40) |
332 ((uint64_t)tag
->byte
[1] << 32) |
333 ((uint64_t)tag
->byte
[2] << 24) |
334 ((uint64_t)tag
->byte
[3] << 16) |
335 ((uint64_t)tag
->byte
[4] << 8) |
336 (uint64_t)tag
->byte
[5];
337 tmp
.raw_data
= tmp64
;
338 return (tmp
.g
.pl_len
);
341 return ((uint32_t)-1);
346 get_payload_length(fru_tag_t
*tag
)
348 switch (get_tag_type(tag
)) {
350 return (tag
->a
.pl_len
);
352 return (tag
->b
.pl_len
);
354 return (tag
->c
.pl_len
);
356 return (tag
->d
.pl_len
);
358 return (tag
->e
.pl_len
);
360 return (tag
->f
.pl_len
);
362 return (tag
->g
.pl_len
);
365 return ((uint32_t)-1);
368 #endif /* _LITTLE_ENDIAN */
371 tags_equal(fru_tag_t t1
, fru_tag_t t2
)
373 return ((get_tag_type(&t1
) == get_tag_type(&t2
)) &&
374 (get_tag_dense(&t1
) == get_tag_dense(&t2
)) &&
375 (get_payload_length(&t1
) == get_payload_length(&t2
)));