xref: /illumos-gate/usr/src/lib/libfruutils/fru_tag.h (revision dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 2000 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef	_FRU_TAG_H
28 #define	_FRU_TAG_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 typedef union {
39 	uint64_t raw_data;
40 	char byte[8];
41 	struct {
42 		unsigned type : 1;
43 		unsigned dense : 4;
44 		unsigned pl_len : 3;
45 	} a;
46 	struct {
47 		unsigned type : 2;
48 		unsigned dense : 11;
49 		unsigned pl_len : 3;
50 	} b;
51 	struct {
52 		unsigned type : 3;
53 		unsigned dense : 8;
54 		unsigned pl_len : 5;
55 	} c;
56 	struct {
57 		unsigned type : 4;
58 		unsigned dense : 17;
59 		unsigned pl_len : 3;
60 	} d;
61 	struct {
62 		unsigned type : 5;
63 		unsigned dense : 12;
64 		unsigned pl_len : 7;
65 	} e;
66 	struct {
67 		unsigned type : 6;
68 		unsigned dense : 14;
69 		unsigned pl_len : 12;
70 	} f;
71 	struct {
72 		unsigned type : 7;
73 		unsigned dense : 9;
74 		unsigned pl_len : 32;
75 	} g;
76 } fru_tag_t;
77 
78 #define	FRU_ID_MASK 0xFF
79 #define	FRU_A_ID 0x00
80 #define	FRU_B_ID 0x02
81 #define	FRU_C_ID 0x06
82 #define	FRU_D_ID 0x0E
83 #define	FRU_E_ID 0x1E
84 #define	FRU_F_ID 0x3E
85 #define	FRU_G_ID 0x7E
86 
87 typedef enum { FRU_A = 0x00, FRU_B = 0x80, FRU_C = 0xc0,
88 		FRU_D = 0xe0, FRU_E = 0xf0, FRU_F = 0xf8,
89 		FRU_G = 0xfc, FRU_X = 0xfe } fru_tagtype_t;
90 char *get_tagtype_str(fru_tagtype_t e);
91 size_t get_tag_size(fru_tagtype_t tag);
92 
93 /* Returns -1 on error */
94 int mk_tag(fru_tagtype_t type, uint32_t dense, size_t pl_len,
95 		fru_tag_t *tag);
96 
97 fru_tagtype_t get_tag_type(fru_tag_t *tag);
98 uint32_t get_tag_dense(fru_tag_t *tag);
99 size_t get_payload_length(fru_tag_t *tag);
100 
101 /* Returns 1 if equal, 0 if not */
102 int tags_equal(fru_tag_t t1, fru_tag_t t2);
103 
104 #ifdef	__cplusplus
105 }
106 #endif
107 
108 #endif /* _FRU_TAG_H */
109