xref: /titanic_44/usr/src/lib/libfru/include/libfru.h (revision 6bbe05905a1c10a2703f95fb4912eb14b87f6670)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*6bbe0590SSundeep Panicker  * Common Development and Distribution License (the "License").
6*6bbe0590SSundeep Panicker  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21*6bbe0590SSundeep Panicker 
227c478bd9Sstevel@tonic-gate /*
23*6bbe0590SSundeep Panicker  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_LIBFRU_H
287c478bd9Sstevel@tonic-gate #define	_LIBFRU_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifdef __cplusplus
317c478bd9Sstevel@tonic-gate extern "C" {
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <sys/types.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #define	LIBFRU_VERSION 1
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate /* fru errno return types */
397c478bd9Sstevel@tonic-gate typedef enum
407c478bd9Sstevel@tonic-gate {
417c478bd9Sstevel@tonic-gate 	FRU_SUCCESS = 0,
427c478bd9Sstevel@tonic-gate 	FRU_NODENOTFOUND,
437c478bd9Sstevel@tonic-gate 	FRU_IOERROR,
447c478bd9Sstevel@tonic-gate 	FRU_NOREGDEF,
457c478bd9Sstevel@tonic-gate 	FRU_NOTCONTAINER,
467c478bd9Sstevel@tonic-gate 	FRU_INVALHANDLE,
477c478bd9Sstevel@tonic-gate 	FRU_INVALSEG,
487c478bd9Sstevel@tonic-gate 	FRU_INVALPATH,
497c478bd9Sstevel@tonic-gate 	FRU_INVALELEMENT,
507c478bd9Sstevel@tonic-gate 	FRU_INVALDATASIZE,
517c478bd9Sstevel@tonic-gate 	FRU_DUPSEG,
527c478bd9Sstevel@tonic-gate 	FRU_NOTFIELD,
537c478bd9Sstevel@tonic-gate 	FRU_NOSPACE,
547c478bd9Sstevel@tonic-gate 	FRU_DATANOTFOUND,
557c478bd9Sstevel@tonic-gate 	FRU_ITERFULL,
567c478bd9Sstevel@tonic-gate 	FRU_INVALPERM,
577c478bd9Sstevel@tonic-gate 	FRU_NOTSUP,
587c478bd9Sstevel@tonic-gate 	FRU_ELEMNOTTAGGED,
597c478bd9Sstevel@tonic-gate 	FRU_CONTFAILED,
607c478bd9Sstevel@tonic-gate 	FRU_SEGCORRUPT,
617c478bd9Sstevel@tonic-gate 	FRU_DATACORRUPT,
627c478bd9Sstevel@tonic-gate 	FRU_FAILURE,
6335551380Skmohan 	FRU_WALK_TERMINATE,
6435551380Skmohan 	FRU_NORESPONSE
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate } fru_errno_t;
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  * Structures for libfru.c
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /* Fru Display Types */
737c478bd9Sstevel@tonic-gate typedef enum { FDISP_Binary = 0, FDISP_Octal, FDISP_Hex, FDISP_Decimal,
74e37d48e7Skmohan 	FDISP_String, FDISP_Time, FDISP_MSGID, FDISP_UUID, FDISP_UNDEFINED
757c478bd9Sstevel@tonic-gate } fru_displaytype_t;
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /* Fru Data Types */
787c478bd9Sstevel@tonic-gate typedef enum { FDTYPE_Binary = 0, FDTYPE_ByteArray, FDTYPE_ASCII,
797c478bd9Sstevel@tonic-gate 		FDTYPE_Unicode, FDTYPE_Record, FDTYPE_Enumeration,
807c478bd9Sstevel@tonic-gate 		FDTYPE_UNDEFINED
817c478bd9Sstevel@tonic-gate } fru_datatype_t;
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate /* Fru Which Type */
847c478bd9Sstevel@tonic-gate typedef enum { FRU_No = 0, FRU_Yes, FRU_WHICH_UNDEFINED } fru_which_t;
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate /* Fru Iteration Types */
877c478bd9Sstevel@tonic-gate typedef enum { FRU_FIFO = 0, FRU_Circular,
887c478bd9Sstevel@tonic-gate 		FRU_Linear, FRU_LIFO, FRU_NOT_ITERATED } fru_itertype_t;
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate /* Fru Handle Type */
917c478bd9Sstevel@tonic-gate typedef uint64_t fru_nodehdl_t;
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /* Node Types */
947c478bd9Sstevel@tonic-gate typedef enum
957c478bd9Sstevel@tonic-gate {
967c478bd9Sstevel@tonic-gate 	FRU_NODE_UNKNOWN,
977c478bd9Sstevel@tonic-gate 	FRU_NODE_LOCATION,
987c478bd9Sstevel@tonic-gate 	FRU_NODE_FRU,
997c478bd9Sstevel@tonic-gate 	FRU_NODE_CONTAINER
1007c478bd9Sstevel@tonic-gate } fru_node_t;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /* Sting list */
1037c478bd9Sstevel@tonic-gate typedef struct {
1047c478bd9Sstevel@tonic-gate 	unsigned int num;
1057c478bd9Sstevel@tonic-gate 	char **strs;
1067c478bd9Sstevel@tonic-gate } fru_strlist_t;
1077c478bd9Sstevel@tonic-gate 
108*6bbe0590SSundeep Panicker #if defined(_LITTLE_ENDIAN)
109*6bbe0590SSundeep Panicker typedef union
110*6bbe0590SSundeep Panicker {
111*6bbe0590SSundeep Panicker 	uint32_t raw_data;
112*6bbe0590SSundeep Panicker 	struct
113*6bbe0590SSundeep Panicker 	{
114*6bbe0590SSundeep Panicker 		unsigned repair_perm : 3;
115*6bbe0590SSundeep Panicker 		unsigned engineering_perm : 3;
116*6bbe0590SSundeep Panicker 		unsigned operations_perm : 3;
117*6bbe0590SSundeep Panicker 		unsigned domain_perm : 3;
118*6bbe0590SSundeep Panicker 		unsigned field_perm : 3;
119*6bbe0590SSundeep Panicker 		unsigned unused : 13;
120*6bbe0590SSundeep Panicker 		unsigned fixed : 1;
121*6bbe0590SSundeep Panicker 		unsigned opaque : 1;
122*6bbe0590SSundeep Panicker 		unsigned ignore_checksum : 1;
123*6bbe0590SSundeep Panicker 		unsigned encrypted : 1;
124*6bbe0590SSundeep Panicker 
125*6bbe0590SSundeep Panicker 	} field;
126*6bbe0590SSundeep Panicker } fru_segdesc_t;
127*6bbe0590SSundeep Panicker #else
1287c478bd9Sstevel@tonic-gate typedef union
1297c478bd9Sstevel@tonic-gate {
1307c478bd9Sstevel@tonic-gate 	uint32_t raw_data;
1317c478bd9Sstevel@tonic-gate 	struct
1327c478bd9Sstevel@tonic-gate 	{
1337c478bd9Sstevel@tonic-gate 		unsigned encrypted : 1;
1347c478bd9Sstevel@tonic-gate 		unsigned ignore_checksum : 1;
1357c478bd9Sstevel@tonic-gate 		unsigned opaque : 1;
1367c478bd9Sstevel@tonic-gate 		unsigned fixed : 1;
1377c478bd9Sstevel@tonic-gate 		unsigned unused : 13;
1387c478bd9Sstevel@tonic-gate 		unsigned field_perm : 3;
1397c478bd9Sstevel@tonic-gate 		unsigned domain_perm : 3;
1407c478bd9Sstevel@tonic-gate 		unsigned operations_perm : 3;
1417c478bd9Sstevel@tonic-gate 		unsigned engineering_perm : 3;
1427c478bd9Sstevel@tonic-gate 		unsigned repair_perm : 3;
1437c478bd9Sstevel@tonic-gate 	} field;
1447c478bd9Sstevel@tonic-gate } fru_segdesc_t;
145*6bbe0590SSundeep Panicker #endif
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_DELETE_MASK (1<<0)
1487c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_WRITE_MASK (1<<1)
1497c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_READ_MASK (1<<2)
1507c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_RW_MASK ((1<<2) | (1<<1))
1517c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_RD_MASK ((1<<2) | (1<<0))
1527c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_WD_MASK ((1<<1) | (1<<0))
1537c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_RWD_MASK ((1<<0) | (1<<1) | (1<<2))
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_ALL_RO_MASK 0x000036db
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_FIXED_MASK (1<<28)
1587c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_OPAQUE_MASK (1<<29)
1597c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_IGNORECHECKSUM_MASK (1<<30)
1607c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_ENCRYPTED_MASK (1<<31)
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate /* segment descriptor field perm. */
1637c478bd9Sstevel@tonic-gate #define	SEGMENT_READ	4
1647c478bd9Sstevel@tonic-gate #define	SEGMENT_WRITE	2
1657c478bd9Sstevel@tonic-gate #define	SEGMENT_DELETE	1
1667c478bd9Sstevel@tonic-gate 
167*6bbe0590SSundeep Panicker #if defined(_LITTLE_ENDIAN)
168*6bbe0590SSundeep Panicker typedef union
169*6bbe0590SSundeep Panicker {
170*6bbe0590SSundeep Panicker 	uint32_t all_bits;
171*6bbe0590SSundeep Panicker 	struct
172*6bbe0590SSundeep Panicker 	{
173*6bbe0590SSundeep Panicker 		unsigned : 8;
174*6bbe0590SSundeep Panicker 		unsigned : 8;
175*6bbe0590SSundeep Panicker 		unsigned : 8;
176*6bbe0590SSundeep Panicker 		unsigned : 7;
177*6bbe0590SSundeep Panicker 		uint32_t read_only : 1;
178*6bbe0590SSundeep Panicker 
179*6bbe0590SSundeep Panicker 	} field;
180*6bbe0590SSundeep Panicker } fru_seg_hwdesc_t;
181*6bbe0590SSundeep Panicker #else
1827c478bd9Sstevel@tonic-gate typedef union
1837c478bd9Sstevel@tonic-gate {
1847c478bd9Sstevel@tonic-gate 	uint32_t all_bits;
1857c478bd9Sstevel@tonic-gate 	struct
1867c478bd9Sstevel@tonic-gate 	{
1877c478bd9Sstevel@tonic-gate 		uint32_t read_only : 1;
1887c478bd9Sstevel@tonic-gate 		unsigned : 7;
1897c478bd9Sstevel@tonic-gate 		unsigned : 8;
1907c478bd9Sstevel@tonic-gate 		unsigned : 8;
1917c478bd9Sstevel@tonic-gate 		unsigned : 8;
1927c478bd9Sstevel@tonic-gate 	} field;
1937c478bd9Sstevel@tonic-gate } fru_seg_hwdesc_t;
194*6bbe0590SSundeep Panicker #endif
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate #define	FRU_SEGNAMELEN 2
1977c478bd9Sstevel@tonic-gate typedef struct {
1987c478bd9Sstevel@tonic-gate 	uint32_t version;
1997c478bd9Sstevel@tonic-gate 	char name[FRU_SEGNAMELEN + 1]; /* +1 to include '\0' byte. */
2007c478bd9Sstevel@tonic-gate 	fru_segdesc_t desc;
2017c478bd9Sstevel@tonic-gate 	uint32_t size;
2027c478bd9Sstevel@tonic-gate 	uint32_t address; /* used for fixed segments (0 otherwise) */
2037c478bd9Sstevel@tonic-gate 	fru_seg_hwdesc_t hw_desc;
2047c478bd9Sstevel@tonic-gate } fru_segdef_t;
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate /* Fru enumerations */
2077c478bd9Sstevel@tonic-gate typedef struct {
2087c478bd9Sstevel@tonic-gate 	uint64_t value;
2097c478bd9Sstevel@tonic-gate 	char *text;
2107c478bd9Sstevel@tonic-gate } fru_enum_t;
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate /* Element/Field level operations */
2137c478bd9Sstevel@tonic-gate #define	FRU_ELEMDEF_REV 1
2147c478bd9Sstevel@tonic-gate typedef struct {
2157c478bd9Sstevel@tonic-gate 	uint32_t version;
2167c478bd9Sstevel@tonic-gate 	fru_datatype_t data_type;
2177c478bd9Sstevel@tonic-gate 	fru_which_t tagged;
2187c478bd9Sstevel@tonic-gate 	size_t data_length; /* in Bytes or Bits depending on data_type */
2197c478bd9Sstevel@tonic-gate 	fru_displaytype_t disp_type;
2207c478bd9Sstevel@tonic-gate 	fru_which_t purgeable;
2217c478bd9Sstevel@tonic-gate 	fru_which_t relocatable;
2227c478bd9Sstevel@tonic-gate 	unsigned int enum_count; /* number of enum values in table */
2237c478bd9Sstevel@tonic-gate 	fru_enum_t *enum_table; /* enum strings or sub-elements depending on */
2247c478bd9Sstevel@tonic-gate 					/* the data_type */
2257c478bd9Sstevel@tonic-gate 	unsigned int iteration_count;
2267c478bd9Sstevel@tonic-gate 	fru_itertype_t iteration_type;
2277c478bd9Sstevel@tonic-gate 	char *example_string;
2287c478bd9Sstevel@tonic-gate } fru_elemdef_t;
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate /* Data Source operations */
2317c478bd9Sstevel@tonic-gate fru_errno_t fru_open_data_source(const char *name, ...);
2327c478bd9Sstevel@tonic-gate fru_errno_t fru_close_data_source(void);
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate /* Tree operations */
2357c478bd9Sstevel@tonic-gate fru_errno_t fru_get_root(fru_nodehdl_t *handle);
2367c478bd9Sstevel@tonic-gate fru_errno_t fru_get_child(fru_nodehdl_t handle, fru_nodehdl_t *child);
2377c478bd9Sstevel@tonic-gate fru_errno_t fru_get_peer(fru_nodehdl_t handle, fru_nodehdl_t *peer);
2387c478bd9Sstevel@tonic-gate fru_errno_t fru_get_parent(fru_nodehdl_t handle, fru_nodehdl_t *parent);
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate /* Node information functions */
2417c478bd9Sstevel@tonic-gate fru_errno_t fru_get_name_from_hdl(fru_nodehdl_t handle, char **name);
2427c478bd9Sstevel@tonic-gate fru_errno_t fru_get_node_type(fru_nodehdl_t handle, fru_node_t *type);
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate /* Segment Operations */
2457c478bd9Sstevel@tonic-gate fru_errno_t fru_list_segments(fru_nodehdl_t container, fru_strlist_t *list);
2467c478bd9Sstevel@tonic-gate fru_errno_t fru_create_segment(fru_nodehdl_t container, fru_segdef_t *def);
2477c478bd9Sstevel@tonic-gate fru_errno_t fru_remove_segment(fru_nodehdl_t container, const char *seg_name);
2487c478bd9Sstevel@tonic-gate fru_errno_t fru_get_segment_def(fru_nodehdl_t container, const char *seg_name,
2497c478bd9Sstevel@tonic-gate 				fru_segdef_t *definition);
2507c478bd9Sstevel@tonic-gate fru_errno_t fru_list_elems_in(fru_nodehdl_t container, const char *seg_name,
2517c478bd9Sstevel@tonic-gate 				fru_strlist_t *list);
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate /* Data operations */
2547c478bd9Sstevel@tonic-gate fru_errno_t fru_read_field(fru_nodehdl_t container,
2557c478bd9Sstevel@tonic-gate 			char **seg_name, /* IN/OUT */
2567c478bd9Sstevel@tonic-gate 			unsigned int   instance,
2577c478bd9Sstevel@tonic-gate 			const char *field_path,
2587c478bd9Sstevel@tonic-gate 			void **data,
2597c478bd9Sstevel@tonic-gate 			size_t *data_len,
2607c478bd9Sstevel@tonic-gate 			char **found_path);
2617c478bd9Sstevel@tonic-gate fru_errno_t fru_update_field(fru_nodehdl_t container,
2627c478bd9Sstevel@tonic-gate 				char *seg_name,
2637c478bd9Sstevel@tonic-gate 				unsigned int instance,
2647c478bd9Sstevel@tonic-gate 				const char *field_path,
2657c478bd9Sstevel@tonic-gate 				void *data,
2667c478bd9Sstevel@tonic-gate 				size_t length);
2677c478bd9Sstevel@tonic-gate fru_errno_t fru_get_num_iterations(fru_nodehdl_t container,
2687c478bd9Sstevel@tonic-gate 					char **seg_name, /* IN/OUT */
2697c478bd9Sstevel@tonic-gate 					unsigned int instance,
2707c478bd9Sstevel@tonic-gate 					const char *iter_path,
2717c478bd9Sstevel@tonic-gate 					int *num_there,
2727c478bd9Sstevel@tonic-gate 					char **found_path);
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate /* Tagged Element operations */
2757c478bd9Sstevel@tonic-gate fru_errno_t fru_add_element(fru_nodehdl_t container, const char *seg_name,
2767c478bd9Sstevel@tonic-gate 				const char *element);
2777c478bd9Sstevel@tonic-gate fru_errno_t fru_delete_element(fru_nodehdl_t container, const char *seg_name,
2787c478bd9Sstevel@tonic-gate 				unsigned int instance, const char *element);
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate /* General library support */
2817c478bd9Sstevel@tonic-gate fru_errno_t fru_get_definition(const char *element_name,
2827c478bd9Sstevel@tonic-gate 				fru_elemdef_t *definition);
2837c478bd9Sstevel@tonic-gate fru_errno_t fru_get_registry(fru_strlist_t *list);
2847c478bd9Sstevel@tonic-gate fru_errno_t fru_get_tagged_parents(const char *elem_name,
2857c478bd9Sstevel@tonic-gate 				fru_strlist_t *parents);
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate /* Structure destroy functions */
2887c478bd9Sstevel@tonic-gate fru_errno_t fru_destroy_strlist(fru_strlist_t *list);
2897c478bd9Sstevel@tonic-gate fru_errno_t fru_destroy_elemdef(fru_elemdef_t *def);
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate /* Enum to String Conversions */
2927c478bd9Sstevel@tonic-gate const char *fru_strerror(fru_errno_t errnum);
2937c478bd9Sstevel@tonic-gate const char *get_displaytype_str(fru_displaytype_t e);
2947c478bd9Sstevel@tonic-gate const char *get_datatype_str(fru_datatype_t e);
2957c478bd9Sstevel@tonic-gate const char *get_which_str(fru_which_t e);
2967c478bd9Sstevel@tonic-gate const char *get_itertype_str(fru_itertype_t e);
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2997c478bd9Sstevel@tonic-gate }
3007c478bd9Sstevel@tonic-gate #endif
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate #endif /* _LIBFRU_H */
303