xref: /onnv-gate/usr/src/lib/libfru/include/libfru.h (revision 11015:0a0751599d31)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*11015SSundeep.Panicker@Sun.COM  * Common Development and Distribution License (the "License").
6*11015SSundeep.Panicker@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21*11015SSundeep.Panicker@Sun.COM 
220Sstevel@tonic-gate /*
23*11015SSundeep.Panicker@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef	_LIBFRU_H
280Sstevel@tonic-gate #define	_LIBFRU_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #ifdef __cplusplus
310Sstevel@tonic-gate extern "C" {
320Sstevel@tonic-gate #endif
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #include <sys/types.h>
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #define	LIBFRU_VERSION 1
370Sstevel@tonic-gate 
380Sstevel@tonic-gate /* fru errno return types */
390Sstevel@tonic-gate typedef enum
400Sstevel@tonic-gate {
410Sstevel@tonic-gate 	FRU_SUCCESS = 0,
420Sstevel@tonic-gate 	FRU_NODENOTFOUND,
430Sstevel@tonic-gate 	FRU_IOERROR,
440Sstevel@tonic-gate 	FRU_NOREGDEF,
450Sstevel@tonic-gate 	FRU_NOTCONTAINER,
460Sstevel@tonic-gate 	FRU_INVALHANDLE,
470Sstevel@tonic-gate 	FRU_INVALSEG,
480Sstevel@tonic-gate 	FRU_INVALPATH,
490Sstevel@tonic-gate 	FRU_INVALELEMENT,
500Sstevel@tonic-gate 	FRU_INVALDATASIZE,
510Sstevel@tonic-gate 	FRU_DUPSEG,
520Sstevel@tonic-gate 	FRU_NOTFIELD,
530Sstevel@tonic-gate 	FRU_NOSPACE,
540Sstevel@tonic-gate 	FRU_DATANOTFOUND,
550Sstevel@tonic-gate 	FRU_ITERFULL,
560Sstevel@tonic-gate 	FRU_INVALPERM,
570Sstevel@tonic-gate 	FRU_NOTSUP,
580Sstevel@tonic-gate 	FRU_ELEMNOTTAGGED,
590Sstevel@tonic-gate 	FRU_CONTFAILED,
600Sstevel@tonic-gate 	FRU_SEGCORRUPT,
610Sstevel@tonic-gate 	FRU_DATACORRUPT,
620Sstevel@tonic-gate 	FRU_FAILURE,
631124Skmohan 	FRU_WALK_TERMINATE,
641124Skmohan 	FRU_NORESPONSE
650Sstevel@tonic-gate 
660Sstevel@tonic-gate } fru_errno_t;
670Sstevel@tonic-gate 
680Sstevel@tonic-gate /*
690Sstevel@tonic-gate  * Structures for libfru.c
700Sstevel@tonic-gate  */
710Sstevel@tonic-gate 
720Sstevel@tonic-gate /* Fru Display Types */
730Sstevel@tonic-gate typedef enum { FDISP_Binary = 0, FDISP_Octal, FDISP_Hex, FDISP_Decimal,
74488Skmohan 	FDISP_String, FDISP_Time, FDISP_MSGID, FDISP_UUID, FDISP_UNDEFINED
750Sstevel@tonic-gate } fru_displaytype_t;
760Sstevel@tonic-gate 
770Sstevel@tonic-gate /* Fru Data Types */
780Sstevel@tonic-gate typedef enum { FDTYPE_Binary = 0, FDTYPE_ByteArray, FDTYPE_ASCII,
790Sstevel@tonic-gate 		FDTYPE_Unicode, FDTYPE_Record, FDTYPE_Enumeration,
800Sstevel@tonic-gate 		FDTYPE_UNDEFINED
810Sstevel@tonic-gate } fru_datatype_t;
820Sstevel@tonic-gate 
830Sstevel@tonic-gate /* Fru Which Type */
840Sstevel@tonic-gate typedef enum { FRU_No = 0, FRU_Yes, FRU_WHICH_UNDEFINED } fru_which_t;
850Sstevel@tonic-gate 
860Sstevel@tonic-gate /* Fru Iteration Types */
870Sstevel@tonic-gate typedef enum { FRU_FIFO = 0, FRU_Circular,
880Sstevel@tonic-gate 		FRU_Linear, FRU_LIFO, FRU_NOT_ITERATED } fru_itertype_t;
890Sstevel@tonic-gate 
900Sstevel@tonic-gate /* Fru Handle Type */
910Sstevel@tonic-gate typedef uint64_t fru_nodehdl_t;
920Sstevel@tonic-gate 
930Sstevel@tonic-gate /* Node Types */
940Sstevel@tonic-gate typedef enum
950Sstevel@tonic-gate {
960Sstevel@tonic-gate 	FRU_NODE_UNKNOWN,
970Sstevel@tonic-gate 	FRU_NODE_LOCATION,
980Sstevel@tonic-gate 	FRU_NODE_FRU,
990Sstevel@tonic-gate 	FRU_NODE_CONTAINER
1000Sstevel@tonic-gate } fru_node_t;
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate /* Sting list */
1030Sstevel@tonic-gate typedef struct {
1040Sstevel@tonic-gate 	unsigned int num;
1050Sstevel@tonic-gate 	char **strs;
1060Sstevel@tonic-gate } fru_strlist_t;
1070Sstevel@tonic-gate 
108*11015SSundeep.Panicker@Sun.COM #if defined(_LITTLE_ENDIAN)
109*11015SSundeep.Panicker@Sun.COM typedef union
110*11015SSundeep.Panicker@Sun.COM {
111*11015SSundeep.Panicker@Sun.COM 	uint32_t raw_data;
112*11015SSundeep.Panicker@Sun.COM 	struct
113*11015SSundeep.Panicker@Sun.COM 	{
114*11015SSundeep.Panicker@Sun.COM 		unsigned repair_perm : 3;
115*11015SSundeep.Panicker@Sun.COM 		unsigned engineering_perm : 3;
116*11015SSundeep.Panicker@Sun.COM 		unsigned operations_perm : 3;
117*11015SSundeep.Panicker@Sun.COM 		unsigned domain_perm : 3;
118*11015SSundeep.Panicker@Sun.COM 		unsigned field_perm : 3;
119*11015SSundeep.Panicker@Sun.COM 		unsigned unused : 13;
120*11015SSundeep.Panicker@Sun.COM 		unsigned fixed : 1;
121*11015SSundeep.Panicker@Sun.COM 		unsigned opaque : 1;
122*11015SSundeep.Panicker@Sun.COM 		unsigned ignore_checksum : 1;
123*11015SSundeep.Panicker@Sun.COM 		unsigned encrypted : 1;
124*11015SSundeep.Panicker@Sun.COM 
125*11015SSundeep.Panicker@Sun.COM 	} field;
126*11015SSundeep.Panicker@Sun.COM } fru_segdesc_t;
127*11015SSundeep.Panicker@Sun.COM #else
1280Sstevel@tonic-gate typedef union
1290Sstevel@tonic-gate {
1300Sstevel@tonic-gate 	uint32_t raw_data;
1310Sstevel@tonic-gate 	struct
1320Sstevel@tonic-gate 	{
1330Sstevel@tonic-gate 		unsigned encrypted : 1;
1340Sstevel@tonic-gate 		unsigned ignore_checksum : 1;
1350Sstevel@tonic-gate 		unsigned opaque : 1;
1360Sstevel@tonic-gate 		unsigned fixed : 1;
1370Sstevel@tonic-gate 		unsigned unused : 13;
1380Sstevel@tonic-gate 		unsigned field_perm : 3;
1390Sstevel@tonic-gate 		unsigned domain_perm : 3;
1400Sstevel@tonic-gate 		unsigned operations_perm : 3;
1410Sstevel@tonic-gate 		unsigned engineering_perm : 3;
1420Sstevel@tonic-gate 		unsigned repair_perm : 3;
1430Sstevel@tonic-gate 	} field;
1440Sstevel@tonic-gate } fru_segdesc_t;
145*11015SSundeep.Panicker@Sun.COM #endif
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_DELETE_MASK (1<<0)
1480Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_WRITE_MASK (1<<1)
1490Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_READ_MASK (1<<2)
1500Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_RW_MASK ((1<<2) | (1<<1))
1510Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_RD_MASK ((1<<2) | (1<<0))
1520Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_WD_MASK ((1<<1) | (1<<0))
1530Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_RWD_MASK ((1<<0) | (1<<1) | (1<<2))
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate #define	FRU_SEGDESC_ALL_RO_MASK 0x000036db
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate #define	FRU_SEGDESC_FIXED_MASK (1<<28)
1580Sstevel@tonic-gate #define	FRU_SEGDESC_OPAQUE_MASK (1<<29)
1590Sstevel@tonic-gate #define	FRU_SEGDESC_IGNORECHECKSUM_MASK (1<<30)
1600Sstevel@tonic-gate #define	FRU_SEGDESC_ENCRYPTED_MASK (1<<31)
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate /* segment descriptor field perm. */
1630Sstevel@tonic-gate #define	SEGMENT_READ	4
1640Sstevel@tonic-gate #define	SEGMENT_WRITE	2
1650Sstevel@tonic-gate #define	SEGMENT_DELETE	1
1660Sstevel@tonic-gate 
167*11015SSundeep.Panicker@Sun.COM #if defined(_LITTLE_ENDIAN)
168*11015SSundeep.Panicker@Sun.COM typedef union
169*11015SSundeep.Panicker@Sun.COM {
170*11015SSundeep.Panicker@Sun.COM 	uint32_t all_bits;
171*11015SSundeep.Panicker@Sun.COM 	struct
172*11015SSundeep.Panicker@Sun.COM 	{
173*11015SSundeep.Panicker@Sun.COM 		unsigned : 8;
174*11015SSundeep.Panicker@Sun.COM 		unsigned : 8;
175*11015SSundeep.Panicker@Sun.COM 		unsigned : 8;
176*11015SSundeep.Panicker@Sun.COM 		unsigned : 7;
177*11015SSundeep.Panicker@Sun.COM 		uint32_t read_only : 1;
178*11015SSundeep.Panicker@Sun.COM 
179*11015SSundeep.Panicker@Sun.COM 	} field;
180*11015SSundeep.Panicker@Sun.COM } fru_seg_hwdesc_t;
181*11015SSundeep.Panicker@Sun.COM #else
1820Sstevel@tonic-gate typedef union
1830Sstevel@tonic-gate {
1840Sstevel@tonic-gate 	uint32_t all_bits;
1850Sstevel@tonic-gate 	struct
1860Sstevel@tonic-gate 	{
1870Sstevel@tonic-gate 		uint32_t read_only : 1;
1880Sstevel@tonic-gate 		unsigned : 7;
1890Sstevel@tonic-gate 		unsigned : 8;
1900Sstevel@tonic-gate 		unsigned : 8;
1910Sstevel@tonic-gate 		unsigned : 8;
1920Sstevel@tonic-gate 	} field;
1930Sstevel@tonic-gate } fru_seg_hwdesc_t;
194*11015SSundeep.Panicker@Sun.COM #endif
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate #define	FRU_SEGNAMELEN 2
1970Sstevel@tonic-gate typedef struct {
1980Sstevel@tonic-gate 	uint32_t version;
1990Sstevel@tonic-gate 	char name[FRU_SEGNAMELEN + 1]; /* +1 to include '\0' byte. */
2000Sstevel@tonic-gate 	fru_segdesc_t desc;
2010Sstevel@tonic-gate 	uint32_t size;
2020Sstevel@tonic-gate 	uint32_t address; /* used for fixed segments (0 otherwise) */
2030Sstevel@tonic-gate 	fru_seg_hwdesc_t hw_desc;
2040Sstevel@tonic-gate } fru_segdef_t;
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate /* Fru enumerations */
2070Sstevel@tonic-gate typedef struct {
2080Sstevel@tonic-gate 	uint64_t value;
2090Sstevel@tonic-gate 	char *text;
2100Sstevel@tonic-gate } fru_enum_t;
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate /* Element/Field level operations */
2130Sstevel@tonic-gate #define	FRU_ELEMDEF_REV 1
2140Sstevel@tonic-gate typedef struct {
2150Sstevel@tonic-gate 	uint32_t version;
2160Sstevel@tonic-gate 	fru_datatype_t data_type;
2170Sstevel@tonic-gate 	fru_which_t tagged;
2180Sstevel@tonic-gate 	size_t data_length; /* in Bytes or Bits depending on data_type */
2190Sstevel@tonic-gate 	fru_displaytype_t disp_type;
2200Sstevel@tonic-gate 	fru_which_t purgeable;
2210Sstevel@tonic-gate 	fru_which_t relocatable;
2220Sstevel@tonic-gate 	unsigned int enum_count; /* number of enum values in table */
2230Sstevel@tonic-gate 	fru_enum_t *enum_table; /* enum strings or sub-elements depending on */
2240Sstevel@tonic-gate 					/* the data_type */
2250Sstevel@tonic-gate 	unsigned int iteration_count;
2260Sstevel@tonic-gate 	fru_itertype_t iteration_type;
2270Sstevel@tonic-gate 	char *example_string;
2280Sstevel@tonic-gate } fru_elemdef_t;
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate /* Data Source operations */
2310Sstevel@tonic-gate fru_errno_t fru_open_data_source(const char *name, ...);
2320Sstevel@tonic-gate fru_errno_t fru_close_data_source(void);
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate /* Tree operations */
2350Sstevel@tonic-gate fru_errno_t fru_get_root(fru_nodehdl_t *handle);
2360Sstevel@tonic-gate fru_errno_t fru_get_child(fru_nodehdl_t handle, fru_nodehdl_t *child);
2370Sstevel@tonic-gate fru_errno_t fru_get_peer(fru_nodehdl_t handle, fru_nodehdl_t *peer);
2380Sstevel@tonic-gate fru_errno_t fru_get_parent(fru_nodehdl_t handle, fru_nodehdl_t *parent);
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate /* Node information functions */
2410Sstevel@tonic-gate fru_errno_t fru_get_name_from_hdl(fru_nodehdl_t handle, char **name);
2420Sstevel@tonic-gate fru_errno_t fru_get_node_type(fru_nodehdl_t handle, fru_node_t *type);
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate /* Segment Operations */
2450Sstevel@tonic-gate fru_errno_t fru_list_segments(fru_nodehdl_t container, fru_strlist_t *list);
2460Sstevel@tonic-gate fru_errno_t fru_create_segment(fru_nodehdl_t container, fru_segdef_t *def);
2470Sstevel@tonic-gate fru_errno_t fru_remove_segment(fru_nodehdl_t container, const char *seg_name);
2480Sstevel@tonic-gate fru_errno_t fru_get_segment_def(fru_nodehdl_t container, const char *seg_name,
2490Sstevel@tonic-gate 				fru_segdef_t *definition);
2500Sstevel@tonic-gate fru_errno_t fru_list_elems_in(fru_nodehdl_t container, const char *seg_name,
2510Sstevel@tonic-gate 				fru_strlist_t *list);
2520Sstevel@tonic-gate 
2530Sstevel@tonic-gate /* Data operations */
2540Sstevel@tonic-gate fru_errno_t fru_read_field(fru_nodehdl_t container,
2550Sstevel@tonic-gate 			char **seg_name, /* IN/OUT */
2560Sstevel@tonic-gate 			unsigned int   instance,
2570Sstevel@tonic-gate 			const char *field_path,
2580Sstevel@tonic-gate 			void **data,
2590Sstevel@tonic-gate 			size_t *data_len,
2600Sstevel@tonic-gate 			char **found_path);
2610Sstevel@tonic-gate fru_errno_t fru_update_field(fru_nodehdl_t container,
2620Sstevel@tonic-gate 				char *seg_name,
2630Sstevel@tonic-gate 				unsigned int instance,
2640Sstevel@tonic-gate 				const char *field_path,
2650Sstevel@tonic-gate 				void *data,
2660Sstevel@tonic-gate 				size_t length);
2670Sstevel@tonic-gate fru_errno_t fru_get_num_iterations(fru_nodehdl_t container,
2680Sstevel@tonic-gate 					char **seg_name, /* IN/OUT */
2690Sstevel@tonic-gate 					unsigned int instance,
2700Sstevel@tonic-gate 					const char *iter_path,
2710Sstevel@tonic-gate 					int *num_there,
2720Sstevel@tonic-gate 					char **found_path);
2730Sstevel@tonic-gate 
2740Sstevel@tonic-gate /* Tagged Element operations */
2750Sstevel@tonic-gate fru_errno_t fru_add_element(fru_nodehdl_t container, const char *seg_name,
2760Sstevel@tonic-gate 				const char *element);
2770Sstevel@tonic-gate fru_errno_t fru_delete_element(fru_nodehdl_t container, const char *seg_name,
2780Sstevel@tonic-gate 				unsigned int instance, const char *element);
2790Sstevel@tonic-gate 
2800Sstevel@tonic-gate /* General library support */
2810Sstevel@tonic-gate fru_errno_t fru_get_definition(const char *element_name,
2820Sstevel@tonic-gate 				fru_elemdef_t *definition);
2830Sstevel@tonic-gate fru_errno_t fru_get_registry(fru_strlist_t *list);
2840Sstevel@tonic-gate fru_errno_t fru_get_tagged_parents(const char *elem_name,
2850Sstevel@tonic-gate 				fru_strlist_t *parents);
2860Sstevel@tonic-gate 
2870Sstevel@tonic-gate /* Structure destroy functions */
2880Sstevel@tonic-gate fru_errno_t fru_destroy_strlist(fru_strlist_t *list);
2890Sstevel@tonic-gate fru_errno_t fru_destroy_elemdef(fru_elemdef_t *def);
2900Sstevel@tonic-gate 
2910Sstevel@tonic-gate /* Enum to String Conversions */
2920Sstevel@tonic-gate const char *fru_strerror(fru_errno_t errnum);
2930Sstevel@tonic-gate const char *get_displaytype_str(fru_displaytype_t e);
2940Sstevel@tonic-gate const char *get_datatype_str(fru_datatype_t e);
2950Sstevel@tonic-gate const char *get_which_str(fru_which_t e);
2960Sstevel@tonic-gate const char *get_itertype_str(fru_itertype_t e);
2970Sstevel@tonic-gate 
2980Sstevel@tonic-gate #ifdef	__cplusplus
2990Sstevel@tonic-gate }
3000Sstevel@tonic-gate #endif
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate #endif /* _LIBFRU_H */
303