xref: /onnv-gate/usr/src/lib/libfru/include/libfru.h (revision 1124:330dd028780c)
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
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23488Skmohan  * Copyright 2005 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #ifdef __cplusplus
330Sstevel@tonic-gate extern "C" {
340Sstevel@tonic-gate #endif
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #include <sys/types.h>
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #define	LIBFRU_VERSION 1
390Sstevel@tonic-gate 
400Sstevel@tonic-gate /* fru errno return types */
410Sstevel@tonic-gate typedef enum
420Sstevel@tonic-gate {
430Sstevel@tonic-gate 	FRU_SUCCESS = 0,
440Sstevel@tonic-gate 	FRU_NODENOTFOUND,
450Sstevel@tonic-gate 	FRU_IOERROR,
460Sstevel@tonic-gate 	FRU_NOREGDEF,
470Sstevel@tonic-gate 	FRU_NOTCONTAINER,
480Sstevel@tonic-gate 	FRU_INVALHANDLE,
490Sstevel@tonic-gate 	FRU_INVALSEG,
500Sstevel@tonic-gate 	FRU_INVALPATH,
510Sstevel@tonic-gate 	FRU_INVALELEMENT,
520Sstevel@tonic-gate 	FRU_INVALDATASIZE,
530Sstevel@tonic-gate 	FRU_DUPSEG,
540Sstevel@tonic-gate 	FRU_NOTFIELD,
550Sstevel@tonic-gate 	FRU_NOSPACE,
560Sstevel@tonic-gate 	FRU_DATANOTFOUND,
570Sstevel@tonic-gate 	FRU_ITERFULL,
580Sstevel@tonic-gate 	FRU_INVALPERM,
590Sstevel@tonic-gate 	FRU_NOTSUP,
600Sstevel@tonic-gate 	FRU_ELEMNOTTAGGED,
610Sstevel@tonic-gate 	FRU_CONTFAILED,
620Sstevel@tonic-gate 	FRU_SEGCORRUPT,
630Sstevel@tonic-gate 	FRU_DATACORRUPT,
640Sstevel@tonic-gate 	FRU_FAILURE,
65*1124Skmohan 	FRU_WALK_TERMINATE,
66*1124Skmohan 	FRU_NORESPONSE
670Sstevel@tonic-gate 
680Sstevel@tonic-gate } fru_errno_t;
690Sstevel@tonic-gate 
700Sstevel@tonic-gate /*
710Sstevel@tonic-gate  * Structures for libfru.c
720Sstevel@tonic-gate  */
730Sstevel@tonic-gate 
740Sstevel@tonic-gate /* Fru Display Types */
750Sstevel@tonic-gate typedef enum { FDISP_Binary = 0, FDISP_Octal, FDISP_Hex, FDISP_Decimal,
76488Skmohan 	FDISP_String, FDISP_Time, FDISP_MSGID, FDISP_UUID, FDISP_UNDEFINED
770Sstevel@tonic-gate } fru_displaytype_t;
780Sstevel@tonic-gate 
790Sstevel@tonic-gate /* Fru Data Types */
800Sstevel@tonic-gate typedef enum { FDTYPE_Binary = 0, FDTYPE_ByteArray, FDTYPE_ASCII,
810Sstevel@tonic-gate 		FDTYPE_Unicode, FDTYPE_Record, FDTYPE_Enumeration,
820Sstevel@tonic-gate 		FDTYPE_UNDEFINED
830Sstevel@tonic-gate } fru_datatype_t;
840Sstevel@tonic-gate 
850Sstevel@tonic-gate /* Fru Which Type */
860Sstevel@tonic-gate typedef enum { FRU_No = 0, FRU_Yes, FRU_WHICH_UNDEFINED } fru_which_t;
870Sstevel@tonic-gate 
880Sstevel@tonic-gate /* Fru Iteration Types */
890Sstevel@tonic-gate typedef enum { FRU_FIFO = 0, FRU_Circular,
900Sstevel@tonic-gate 		FRU_Linear, FRU_LIFO, FRU_NOT_ITERATED } fru_itertype_t;
910Sstevel@tonic-gate 
920Sstevel@tonic-gate /* Fru Handle Type */
930Sstevel@tonic-gate typedef uint64_t fru_nodehdl_t;
940Sstevel@tonic-gate 
950Sstevel@tonic-gate /* Node Types */
960Sstevel@tonic-gate typedef enum
970Sstevel@tonic-gate {
980Sstevel@tonic-gate 	FRU_NODE_UNKNOWN,
990Sstevel@tonic-gate 	FRU_NODE_LOCATION,
1000Sstevel@tonic-gate 	FRU_NODE_FRU,
1010Sstevel@tonic-gate 	FRU_NODE_CONTAINER
1020Sstevel@tonic-gate } fru_node_t;
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate /* Sting list */
1050Sstevel@tonic-gate typedef struct {
1060Sstevel@tonic-gate 	unsigned int num;
1070Sstevel@tonic-gate 	char **strs;
1080Sstevel@tonic-gate } fru_strlist_t;
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate typedef union
1110Sstevel@tonic-gate {
1120Sstevel@tonic-gate 	uint32_t raw_data;
1130Sstevel@tonic-gate 	struct
1140Sstevel@tonic-gate 	{
1150Sstevel@tonic-gate 		unsigned encrypted : 1;
1160Sstevel@tonic-gate 		unsigned ignore_checksum : 1;
1170Sstevel@tonic-gate 		unsigned opaque : 1;
1180Sstevel@tonic-gate 		unsigned fixed : 1;
1190Sstevel@tonic-gate 		unsigned unused : 13;
1200Sstevel@tonic-gate 		unsigned field_perm : 3;
1210Sstevel@tonic-gate 		unsigned domain_perm : 3;
1220Sstevel@tonic-gate 		unsigned operations_perm : 3;
1230Sstevel@tonic-gate 		unsigned engineering_perm : 3;
1240Sstevel@tonic-gate 		unsigned repair_perm : 3;
1250Sstevel@tonic-gate 	} field;
1260Sstevel@tonic-gate } fru_segdesc_t;
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_DELETE_MASK (1<<0)
1290Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_WRITE_MASK (1<<1)
1300Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_READ_MASK (1<<2)
1310Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_RW_MASK ((1<<2) | (1<<1))
1320Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_RD_MASK ((1<<2) | (1<<0))
1330Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_WD_MASK ((1<<1) | (1<<0))
1340Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_RWD_MASK ((1<<0) | (1<<1) | (1<<2))
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate #define	FRU_SEGDESC_ALL_RO_MASK 0x000036db
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate #define	FRU_SEGDESC_FIXED_MASK (1<<28)
1390Sstevel@tonic-gate #define	FRU_SEGDESC_OPAQUE_MASK (1<<29)
1400Sstevel@tonic-gate #define	FRU_SEGDESC_IGNORECHECKSUM_MASK (1<<30)
1410Sstevel@tonic-gate #define	FRU_SEGDESC_ENCRYPTED_MASK (1<<31)
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate /* segment descriptor field perm. */
1440Sstevel@tonic-gate #define	SEGMENT_READ	4
1450Sstevel@tonic-gate #define	SEGMENT_WRITE	2
1460Sstevel@tonic-gate #define	SEGMENT_DELETE	1
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate typedef union
1490Sstevel@tonic-gate {
1500Sstevel@tonic-gate 	uint32_t all_bits;
1510Sstevel@tonic-gate 	struct
1520Sstevel@tonic-gate 	{
1530Sstevel@tonic-gate 		uint32_t read_only : 1;
1540Sstevel@tonic-gate 		unsigned : 7;
1550Sstevel@tonic-gate 		unsigned : 8;
1560Sstevel@tonic-gate 		unsigned : 8;
1570Sstevel@tonic-gate 		unsigned : 8;
1580Sstevel@tonic-gate 	} field;
1590Sstevel@tonic-gate } fru_seg_hwdesc_t;
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate #define	FRU_SEGNAMELEN 2
1620Sstevel@tonic-gate typedef struct {
1630Sstevel@tonic-gate 	uint32_t version;
1640Sstevel@tonic-gate 	char name[FRU_SEGNAMELEN + 1]; /* +1 to include '\0' byte. */
1650Sstevel@tonic-gate 	fru_segdesc_t desc;
1660Sstevel@tonic-gate 	uint32_t size;
1670Sstevel@tonic-gate 	uint32_t address; /* used for fixed segments (0 otherwise) */
1680Sstevel@tonic-gate 	fru_seg_hwdesc_t hw_desc;
1690Sstevel@tonic-gate } fru_segdef_t;
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate /* Fru enumerations */
1720Sstevel@tonic-gate typedef struct {
1730Sstevel@tonic-gate 	uint64_t value;
1740Sstevel@tonic-gate 	char *text;
1750Sstevel@tonic-gate } fru_enum_t;
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate /* Element/Field level operations */
1780Sstevel@tonic-gate #define	FRU_ELEMDEF_REV 1
1790Sstevel@tonic-gate typedef struct {
1800Sstevel@tonic-gate 	uint32_t version;
1810Sstevel@tonic-gate 	fru_datatype_t data_type;
1820Sstevel@tonic-gate 	fru_which_t tagged;
1830Sstevel@tonic-gate 	size_t data_length; /* in Bytes or Bits depending on data_type */
1840Sstevel@tonic-gate 	fru_displaytype_t disp_type;
1850Sstevel@tonic-gate 	fru_which_t purgeable;
1860Sstevel@tonic-gate 	fru_which_t relocatable;
1870Sstevel@tonic-gate 	unsigned int enum_count; /* number of enum values in table */
1880Sstevel@tonic-gate 	fru_enum_t *enum_table; /* enum strings or sub-elements depending on */
1890Sstevel@tonic-gate 					/* the data_type */
1900Sstevel@tonic-gate 	unsigned int iteration_count;
1910Sstevel@tonic-gate 	fru_itertype_t iteration_type;
1920Sstevel@tonic-gate 	char *example_string;
1930Sstevel@tonic-gate } fru_elemdef_t;
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate /* Data Source operations */
1960Sstevel@tonic-gate fru_errno_t fru_open_data_source(const char *name, ...);
1970Sstevel@tonic-gate fru_errno_t fru_close_data_source(void);
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate /* Tree operations */
2000Sstevel@tonic-gate fru_errno_t fru_get_root(fru_nodehdl_t *handle);
2010Sstevel@tonic-gate fru_errno_t fru_get_child(fru_nodehdl_t handle, fru_nodehdl_t *child);
2020Sstevel@tonic-gate fru_errno_t fru_get_peer(fru_nodehdl_t handle, fru_nodehdl_t *peer);
2030Sstevel@tonic-gate fru_errno_t fru_get_parent(fru_nodehdl_t handle, fru_nodehdl_t *parent);
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate /* Node information functions */
2060Sstevel@tonic-gate fru_errno_t fru_get_name_from_hdl(fru_nodehdl_t handle, char **name);
2070Sstevel@tonic-gate fru_errno_t fru_get_node_type(fru_nodehdl_t handle, fru_node_t *type);
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate /* Segment Operations */
2100Sstevel@tonic-gate fru_errno_t fru_list_segments(fru_nodehdl_t container, fru_strlist_t *list);
2110Sstevel@tonic-gate fru_errno_t fru_create_segment(fru_nodehdl_t container, fru_segdef_t *def);
2120Sstevel@tonic-gate fru_errno_t fru_remove_segment(fru_nodehdl_t container, const char *seg_name);
2130Sstevel@tonic-gate fru_errno_t fru_get_segment_def(fru_nodehdl_t container, const char *seg_name,
2140Sstevel@tonic-gate 				fru_segdef_t *definition);
2150Sstevel@tonic-gate fru_errno_t fru_list_elems_in(fru_nodehdl_t container, const char *seg_name,
2160Sstevel@tonic-gate 				fru_strlist_t *list);
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate /* Data operations */
2190Sstevel@tonic-gate fru_errno_t fru_read_field(fru_nodehdl_t container,
2200Sstevel@tonic-gate 			char **seg_name, /* IN/OUT */
2210Sstevel@tonic-gate 			unsigned int   instance,
2220Sstevel@tonic-gate 			const char *field_path,
2230Sstevel@tonic-gate 			void **data,
2240Sstevel@tonic-gate 			size_t *data_len,
2250Sstevel@tonic-gate 			char **found_path);
2260Sstevel@tonic-gate fru_errno_t fru_update_field(fru_nodehdl_t container,
2270Sstevel@tonic-gate 				char *seg_name,
2280Sstevel@tonic-gate 				unsigned int instance,
2290Sstevel@tonic-gate 				const char *field_path,
2300Sstevel@tonic-gate 				void *data,
2310Sstevel@tonic-gate 				size_t length);
2320Sstevel@tonic-gate fru_errno_t fru_get_num_iterations(fru_nodehdl_t container,
2330Sstevel@tonic-gate 					char **seg_name, /* IN/OUT */
2340Sstevel@tonic-gate 					unsigned int instance,
2350Sstevel@tonic-gate 					const char *iter_path,
2360Sstevel@tonic-gate 					int *num_there,
2370Sstevel@tonic-gate 					char **found_path);
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate /* Tagged Element operations */
2400Sstevel@tonic-gate fru_errno_t fru_add_element(fru_nodehdl_t container, const char *seg_name,
2410Sstevel@tonic-gate 				const char *element);
2420Sstevel@tonic-gate fru_errno_t fru_delete_element(fru_nodehdl_t container, const char *seg_name,
2430Sstevel@tonic-gate 				unsigned int instance, const char *element);
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate /* General library support */
2460Sstevel@tonic-gate fru_errno_t fru_get_definition(const char *element_name,
2470Sstevel@tonic-gate 				fru_elemdef_t *definition);
2480Sstevel@tonic-gate fru_errno_t fru_get_registry(fru_strlist_t *list);
2490Sstevel@tonic-gate fru_errno_t fru_get_tagged_parents(const char *elem_name,
2500Sstevel@tonic-gate 				fru_strlist_t *parents);
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate /* Structure destroy functions */
2530Sstevel@tonic-gate fru_errno_t fru_destroy_strlist(fru_strlist_t *list);
2540Sstevel@tonic-gate fru_errno_t fru_destroy_elemdef(fru_elemdef_t *def);
2550Sstevel@tonic-gate 
2560Sstevel@tonic-gate /* Enum to String Conversions */
2570Sstevel@tonic-gate const char *fru_strerror(fru_errno_t errnum);
2580Sstevel@tonic-gate const char *get_displaytype_str(fru_displaytype_t e);
2590Sstevel@tonic-gate const char *get_datatype_str(fru_datatype_t e);
2600Sstevel@tonic-gate const char *get_which_str(fru_which_t e);
2610Sstevel@tonic-gate const char *get_itertype_str(fru_itertype_t e);
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate #ifdef	__cplusplus
2640Sstevel@tonic-gate }
2650Sstevel@tonic-gate #endif
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate #endif /* _LIBFRU_H */
268