xref: /titanic_50/usr/src/lib/libfru/include/libfru.h (revision 02e56f3f1bfc8d9977bafb8cb5202f576dcded27)
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 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_LIBFRU_H
28 #define	_LIBFRU_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/types.h>
37 
38 #define	LIBFRU_VERSION 1
39 
40 /* fru errno return types */
41 typedef enum
42 {
43 	FRU_SUCCESS = 0,
44 	FRU_NODENOTFOUND,
45 	FRU_IOERROR,
46 	FRU_NOREGDEF,
47 	FRU_NOTCONTAINER,
48 	FRU_INVALHANDLE,
49 	FRU_INVALSEG,
50 	FRU_INVALPATH,
51 	FRU_INVALELEMENT,
52 	FRU_INVALDATASIZE,
53 	FRU_DUPSEG,
54 	FRU_NOTFIELD,
55 	FRU_NOSPACE,
56 	FRU_DATANOTFOUND,
57 	FRU_ITERFULL,
58 	FRU_INVALPERM,
59 	FRU_NOTSUP,
60 	FRU_ELEMNOTTAGGED,
61 	FRU_CONTFAILED,
62 	FRU_SEGCORRUPT,
63 	FRU_DATACORRUPT,
64 	FRU_FAILURE,
65 	FRU_WALK_TERMINATE
66 
67 } fru_errno_t;
68 
69 /*
70  * Structures for libfru.c
71  */
72 
73 /* Fru Display Types */
74 typedef enum { FDISP_Binary = 0, FDISP_Octal, FDISP_Hex, FDISP_Decimal,
75 	FDISP_String, FDISP_Time, FDISP_MSGID, FDISP_UUID, FDISP_UNDEFINED
76 } fru_displaytype_t;
77 
78 /* Fru Data Types */
79 typedef enum { FDTYPE_Binary = 0, FDTYPE_ByteArray, FDTYPE_ASCII,
80 		FDTYPE_Unicode, FDTYPE_Record, FDTYPE_Enumeration,
81 		FDTYPE_UNDEFINED
82 } fru_datatype_t;
83 
84 /* Fru Which Type */
85 typedef enum { FRU_No = 0, FRU_Yes, FRU_WHICH_UNDEFINED } fru_which_t;
86 
87 /* Fru Iteration Types */
88 typedef enum { FRU_FIFO = 0, FRU_Circular,
89 		FRU_Linear, FRU_LIFO, FRU_NOT_ITERATED } fru_itertype_t;
90 
91 /* Fru Handle Type */
92 typedef uint64_t fru_nodehdl_t;
93 
94 /* Node Types */
95 typedef enum
96 {
97 	FRU_NODE_UNKNOWN,
98 	FRU_NODE_LOCATION,
99 	FRU_NODE_FRU,
100 	FRU_NODE_CONTAINER
101 } fru_node_t;
102 
103 /* Sting list */
104 typedef struct {
105 	unsigned int num;
106 	char **strs;
107 } fru_strlist_t;
108 
109 typedef union
110 {
111 	uint32_t raw_data;
112 	struct
113 	{
114 		unsigned encrypted : 1;
115 		unsigned ignore_checksum : 1;
116 		unsigned opaque : 1;
117 		unsigned fixed : 1;
118 		unsigned unused : 13;
119 		unsigned field_perm : 3;
120 		unsigned domain_perm : 3;
121 		unsigned operations_perm : 3;
122 		unsigned engineering_perm : 3;
123 		unsigned repair_perm : 3;
124 	} field;
125 } fru_segdesc_t;
126 
127 #define	FRU_SEGDESC_PERM_DELETE_MASK (1<<0)
128 #define	FRU_SEGDESC_PERM_WRITE_MASK (1<<1)
129 #define	FRU_SEGDESC_PERM_READ_MASK (1<<2)
130 #define	FRU_SEGDESC_PERM_RW_MASK ((1<<2) | (1<<1))
131 #define	FRU_SEGDESC_PERM_RD_MASK ((1<<2) | (1<<0))
132 #define	FRU_SEGDESC_PERM_WD_MASK ((1<<1) | (1<<0))
133 #define	FRU_SEGDESC_PERM_RWD_MASK ((1<<0) | (1<<1) | (1<<2))
134 
135 #define	FRU_SEGDESC_ALL_RO_MASK 0x000036db
136 
137 #define	FRU_SEGDESC_FIXED_MASK (1<<28)
138 #define	FRU_SEGDESC_OPAQUE_MASK (1<<29)
139 #define	FRU_SEGDESC_IGNORECHECKSUM_MASK (1<<30)
140 #define	FRU_SEGDESC_ENCRYPTED_MASK (1<<31)
141 
142 /* segment descriptor field perm. */
143 #define	SEGMENT_READ	4
144 #define	SEGMENT_WRITE	2
145 #define	SEGMENT_DELETE	1
146 
147 typedef union
148 {
149 	uint32_t all_bits;
150 	struct
151 	{
152 		uint32_t read_only : 1;
153 		unsigned : 7;
154 		unsigned : 8;
155 		unsigned : 8;
156 		unsigned : 8;
157 	} field;
158 } fru_seg_hwdesc_t;
159 
160 #define	FRU_SEGNAMELEN 2
161 typedef struct {
162 	uint32_t version;
163 	char name[FRU_SEGNAMELEN + 1]; /* +1 to include '\0' byte. */
164 	fru_segdesc_t desc;
165 	uint32_t size;
166 	uint32_t address; /* used for fixed segments (0 otherwise) */
167 	fru_seg_hwdesc_t hw_desc;
168 } fru_segdef_t;
169 
170 /* Fru enumerations */
171 typedef struct {
172 	uint64_t value;
173 	char *text;
174 } fru_enum_t;
175 
176 /* Element/Field level operations */
177 #define	FRU_ELEMDEF_REV 1
178 typedef struct {
179 	uint32_t version;
180 	fru_datatype_t data_type;
181 	fru_which_t tagged;
182 	size_t data_length; /* in Bytes or Bits depending on data_type */
183 	fru_displaytype_t disp_type;
184 	fru_which_t purgeable;
185 	fru_which_t relocatable;
186 	unsigned int enum_count; /* number of enum values in table */
187 	fru_enum_t *enum_table; /* enum strings or sub-elements depending on */
188 					/* the data_type */
189 	unsigned int iteration_count;
190 	fru_itertype_t iteration_type;
191 	char *example_string;
192 } fru_elemdef_t;
193 
194 /* Data Source operations */
195 fru_errno_t fru_open_data_source(const char *name, ...);
196 fru_errno_t fru_close_data_source(void);
197 
198 /* Tree operations */
199 fru_errno_t fru_get_root(fru_nodehdl_t *handle);
200 fru_errno_t fru_get_child(fru_nodehdl_t handle, fru_nodehdl_t *child);
201 fru_errno_t fru_get_peer(fru_nodehdl_t handle, fru_nodehdl_t *peer);
202 fru_errno_t fru_get_parent(fru_nodehdl_t handle, fru_nodehdl_t *parent);
203 
204 /* Node information functions */
205 fru_errno_t fru_get_name_from_hdl(fru_nodehdl_t handle, char **name);
206 fru_errno_t fru_get_node_type(fru_nodehdl_t handle, fru_node_t *type);
207 
208 /* Segment Operations */
209 fru_errno_t fru_list_segments(fru_nodehdl_t container, fru_strlist_t *list);
210 fru_errno_t fru_create_segment(fru_nodehdl_t container, fru_segdef_t *def);
211 fru_errno_t fru_remove_segment(fru_nodehdl_t container, const char *seg_name);
212 fru_errno_t fru_get_segment_def(fru_nodehdl_t container, const char *seg_name,
213 				fru_segdef_t *definition);
214 fru_errno_t fru_list_elems_in(fru_nodehdl_t container, const char *seg_name,
215 				fru_strlist_t *list);
216 
217 /* Data operations */
218 fru_errno_t fru_read_field(fru_nodehdl_t container,
219 			char **seg_name, /* IN/OUT */
220 			unsigned int   instance,
221 			const char *field_path,
222 			void **data,
223 			size_t *data_len,
224 			char **found_path);
225 fru_errno_t fru_update_field(fru_nodehdl_t container,
226 				char *seg_name,
227 				unsigned int instance,
228 				const char *field_path,
229 				void *data,
230 				size_t length);
231 fru_errno_t fru_get_num_iterations(fru_nodehdl_t container,
232 					char **seg_name, /* IN/OUT */
233 					unsigned int instance,
234 					const char *iter_path,
235 					int *num_there,
236 					char **found_path);
237 
238 /* Tagged Element operations */
239 fru_errno_t fru_add_element(fru_nodehdl_t container, const char *seg_name,
240 				const char *element);
241 fru_errno_t fru_delete_element(fru_nodehdl_t container, const char *seg_name,
242 				unsigned int instance, const char *element);
243 
244 /* General library support */
245 fru_errno_t fru_get_definition(const char *element_name,
246 				fru_elemdef_t *definition);
247 fru_errno_t fru_get_registry(fru_strlist_t *list);
248 fru_errno_t fru_get_tagged_parents(const char *elem_name,
249 				fru_strlist_t *parents);
250 
251 /* Structure destroy functions */
252 fru_errno_t fru_destroy_strlist(fru_strlist_t *list);
253 fru_errno_t fru_destroy_elemdef(fru_elemdef_t *def);
254 
255 /* Enum to String Conversions */
256 const char *fru_strerror(fru_errno_t errnum);
257 const char *get_displaytype_str(fru_displaytype_t e);
258 const char *get_datatype_str(fru_datatype_t e);
259 const char *get_which_str(fru_which_t e);
260 const char *get_itertype_str(fru_itertype_t e);
261 
262 #ifdef	__cplusplus
263 }
264 #endif
265 
266 #endif /* _LIBFRU_H */
267