xref: /titanic_51/usr/src/lib/libfru/include/libfru.h (revision e37d48e735b8e55f327dfa35a2d0006049ea5e58)
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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*e37d48e7Skmohan  * Copyright 2005 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef __cplusplus
337c478bd9Sstevel@tonic-gate extern "C" {
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <sys/types.h>
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #define	LIBFRU_VERSION 1
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /* fru errno return types */
417c478bd9Sstevel@tonic-gate typedef enum
427c478bd9Sstevel@tonic-gate {
437c478bd9Sstevel@tonic-gate 	FRU_SUCCESS = 0,
447c478bd9Sstevel@tonic-gate 	FRU_NODENOTFOUND,
457c478bd9Sstevel@tonic-gate 	FRU_IOERROR,
467c478bd9Sstevel@tonic-gate 	FRU_NOREGDEF,
477c478bd9Sstevel@tonic-gate 	FRU_NOTCONTAINER,
487c478bd9Sstevel@tonic-gate 	FRU_INVALHANDLE,
497c478bd9Sstevel@tonic-gate 	FRU_INVALSEG,
507c478bd9Sstevel@tonic-gate 	FRU_INVALPATH,
517c478bd9Sstevel@tonic-gate 	FRU_INVALELEMENT,
527c478bd9Sstevel@tonic-gate 	FRU_INVALDATASIZE,
537c478bd9Sstevel@tonic-gate 	FRU_DUPSEG,
547c478bd9Sstevel@tonic-gate 	FRU_NOTFIELD,
557c478bd9Sstevel@tonic-gate 	FRU_NOSPACE,
567c478bd9Sstevel@tonic-gate 	FRU_DATANOTFOUND,
577c478bd9Sstevel@tonic-gate 	FRU_ITERFULL,
587c478bd9Sstevel@tonic-gate 	FRU_INVALPERM,
597c478bd9Sstevel@tonic-gate 	FRU_NOTSUP,
607c478bd9Sstevel@tonic-gate 	FRU_ELEMNOTTAGGED,
617c478bd9Sstevel@tonic-gate 	FRU_CONTFAILED,
627c478bd9Sstevel@tonic-gate 	FRU_SEGCORRUPT,
637c478bd9Sstevel@tonic-gate 	FRU_DATACORRUPT,
647c478bd9Sstevel@tonic-gate 	FRU_FAILURE,
657c478bd9Sstevel@tonic-gate 	FRU_WALK_TERMINATE
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate } fru_errno_t;
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate /*
707c478bd9Sstevel@tonic-gate  * Structures for libfru.c
717c478bd9Sstevel@tonic-gate  */
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate /* Fru Display Types */
747c478bd9Sstevel@tonic-gate typedef enum { FDISP_Binary = 0, FDISP_Octal, FDISP_Hex, FDISP_Decimal,
75*e37d48e7Skmohan 	FDISP_String, FDISP_Time, FDISP_MSGID, FDISP_UUID, FDISP_UNDEFINED
767c478bd9Sstevel@tonic-gate } fru_displaytype_t;
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate /* Fru Data Types */
797c478bd9Sstevel@tonic-gate typedef enum { FDTYPE_Binary = 0, FDTYPE_ByteArray, FDTYPE_ASCII,
807c478bd9Sstevel@tonic-gate 		FDTYPE_Unicode, FDTYPE_Record, FDTYPE_Enumeration,
817c478bd9Sstevel@tonic-gate 		FDTYPE_UNDEFINED
827c478bd9Sstevel@tonic-gate } fru_datatype_t;
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate /* Fru Which Type */
857c478bd9Sstevel@tonic-gate typedef enum { FRU_No = 0, FRU_Yes, FRU_WHICH_UNDEFINED } fru_which_t;
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate /* Fru Iteration Types */
887c478bd9Sstevel@tonic-gate typedef enum { FRU_FIFO = 0, FRU_Circular,
897c478bd9Sstevel@tonic-gate 		FRU_Linear, FRU_LIFO, FRU_NOT_ITERATED } fru_itertype_t;
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /* Fru Handle Type */
927c478bd9Sstevel@tonic-gate typedef uint64_t fru_nodehdl_t;
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /* Node Types */
957c478bd9Sstevel@tonic-gate typedef enum
967c478bd9Sstevel@tonic-gate {
977c478bd9Sstevel@tonic-gate 	FRU_NODE_UNKNOWN,
987c478bd9Sstevel@tonic-gate 	FRU_NODE_LOCATION,
997c478bd9Sstevel@tonic-gate 	FRU_NODE_FRU,
1007c478bd9Sstevel@tonic-gate 	FRU_NODE_CONTAINER
1017c478bd9Sstevel@tonic-gate } fru_node_t;
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate /* Sting list */
1047c478bd9Sstevel@tonic-gate typedef struct {
1057c478bd9Sstevel@tonic-gate 	unsigned int num;
1067c478bd9Sstevel@tonic-gate 	char **strs;
1077c478bd9Sstevel@tonic-gate } fru_strlist_t;
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate typedef union
1107c478bd9Sstevel@tonic-gate {
1117c478bd9Sstevel@tonic-gate 	uint32_t raw_data;
1127c478bd9Sstevel@tonic-gate 	struct
1137c478bd9Sstevel@tonic-gate 	{
1147c478bd9Sstevel@tonic-gate 		unsigned encrypted : 1;
1157c478bd9Sstevel@tonic-gate 		unsigned ignore_checksum : 1;
1167c478bd9Sstevel@tonic-gate 		unsigned opaque : 1;
1177c478bd9Sstevel@tonic-gate 		unsigned fixed : 1;
1187c478bd9Sstevel@tonic-gate 		unsigned unused : 13;
1197c478bd9Sstevel@tonic-gate 		unsigned field_perm : 3;
1207c478bd9Sstevel@tonic-gate 		unsigned domain_perm : 3;
1217c478bd9Sstevel@tonic-gate 		unsigned operations_perm : 3;
1227c478bd9Sstevel@tonic-gate 		unsigned engineering_perm : 3;
1237c478bd9Sstevel@tonic-gate 		unsigned repair_perm : 3;
1247c478bd9Sstevel@tonic-gate 	} field;
1257c478bd9Sstevel@tonic-gate } fru_segdesc_t;
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_DELETE_MASK (1<<0)
1287c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_WRITE_MASK (1<<1)
1297c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_READ_MASK (1<<2)
1307c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_RW_MASK ((1<<2) | (1<<1))
1317c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_RD_MASK ((1<<2) | (1<<0))
1327c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_WD_MASK ((1<<1) | (1<<0))
1337c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_PERM_RWD_MASK ((1<<0) | (1<<1) | (1<<2))
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_ALL_RO_MASK 0x000036db
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_FIXED_MASK (1<<28)
1387c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_OPAQUE_MASK (1<<29)
1397c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_IGNORECHECKSUM_MASK (1<<30)
1407c478bd9Sstevel@tonic-gate #define	FRU_SEGDESC_ENCRYPTED_MASK (1<<31)
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate /* segment descriptor field perm. */
1437c478bd9Sstevel@tonic-gate #define	SEGMENT_READ	4
1447c478bd9Sstevel@tonic-gate #define	SEGMENT_WRITE	2
1457c478bd9Sstevel@tonic-gate #define	SEGMENT_DELETE	1
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate typedef union
1487c478bd9Sstevel@tonic-gate {
1497c478bd9Sstevel@tonic-gate 	uint32_t all_bits;
1507c478bd9Sstevel@tonic-gate 	struct
1517c478bd9Sstevel@tonic-gate 	{
1527c478bd9Sstevel@tonic-gate 		uint32_t read_only : 1;
1537c478bd9Sstevel@tonic-gate 		unsigned : 7;
1547c478bd9Sstevel@tonic-gate 		unsigned : 8;
1557c478bd9Sstevel@tonic-gate 		unsigned : 8;
1567c478bd9Sstevel@tonic-gate 		unsigned : 8;
1577c478bd9Sstevel@tonic-gate 	} field;
1587c478bd9Sstevel@tonic-gate } fru_seg_hwdesc_t;
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate #define	FRU_SEGNAMELEN 2
1617c478bd9Sstevel@tonic-gate typedef struct {
1627c478bd9Sstevel@tonic-gate 	uint32_t version;
1637c478bd9Sstevel@tonic-gate 	char name[FRU_SEGNAMELEN + 1]; /* +1 to include '\0' byte. */
1647c478bd9Sstevel@tonic-gate 	fru_segdesc_t desc;
1657c478bd9Sstevel@tonic-gate 	uint32_t size;
1667c478bd9Sstevel@tonic-gate 	uint32_t address; /* used for fixed segments (0 otherwise) */
1677c478bd9Sstevel@tonic-gate 	fru_seg_hwdesc_t hw_desc;
1687c478bd9Sstevel@tonic-gate } fru_segdef_t;
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate /* Fru enumerations */
1717c478bd9Sstevel@tonic-gate typedef struct {
1727c478bd9Sstevel@tonic-gate 	uint64_t value;
1737c478bd9Sstevel@tonic-gate 	char *text;
1747c478bd9Sstevel@tonic-gate } fru_enum_t;
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate /* Element/Field level operations */
1777c478bd9Sstevel@tonic-gate #define	FRU_ELEMDEF_REV 1
1787c478bd9Sstevel@tonic-gate typedef struct {
1797c478bd9Sstevel@tonic-gate 	uint32_t version;
1807c478bd9Sstevel@tonic-gate 	fru_datatype_t data_type;
1817c478bd9Sstevel@tonic-gate 	fru_which_t tagged;
1827c478bd9Sstevel@tonic-gate 	size_t data_length; /* in Bytes or Bits depending on data_type */
1837c478bd9Sstevel@tonic-gate 	fru_displaytype_t disp_type;
1847c478bd9Sstevel@tonic-gate 	fru_which_t purgeable;
1857c478bd9Sstevel@tonic-gate 	fru_which_t relocatable;
1867c478bd9Sstevel@tonic-gate 	unsigned int enum_count; /* number of enum values in table */
1877c478bd9Sstevel@tonic-gate 	fru_enum_t *enum_table; /* enum strings or sub-elements depending on */
1887c478bd9Sstevel@tonic-gate 					/* the data_type */
1897c478bd9Sstevel@tonic-gate 	unsigned int iteration_count;
1907c478bd9Sstevel@tonic-gate 	fru_itertype_t iteration_type;
1917c478bd9Sstevel@tonic-gate 	char *example_string;
1927c478bd9Sstevel@tonic-gate } fru_elemdef_t;
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate /* Data Source operations */
1957c478bd9Sstevel@tonic-gate fru_errno_t fru_open_data_source(const char *name, ...);
1967c478bd9Sstevel@tonic-gate fru_errno_t fru_close_data_source(void);
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate /* Tree operations */
1997c478bd9Sstevel@tonic-gate fru_errno_t fru_get_root(fru_nodehdl_t *handle);
2007c478bd9Sstevel@tonic-gate fru_errno_t fru_get_child(fru_nodehdl_t handle, fru_nodehdl_t *child);
2017c478bd9Sstevel@tonic-gate fru_errno_t fru_get_peer(fru_nodehdl_t handle, fru_nodehdl_t *peer);
2027c478bd9Sstevel@tonic-gate fru_errno_t fru_get_parent(fru_nodehdl_t handle, fru_nodehdl_t *parent);
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate /* Node information functions */
2057c478bd9Sstevel@tonic-gate fru_errno_t fru_get_name_from_hdl(fru_nodehdl_t handle, char **name);
2067c478bd9Sstevel@tonic-gate fru_errno_t fru_get_node_type(fru_nodehdl_t handle, fru_node_t *type);
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate /* Segment Operations */
2097c478bd9Sstevel@tonic-gate fru_errno_t fru_list_segments(fru_nodehdl_t container, fru_strlist_t *list);
2107c478bd9Sstevel@tonic-gate fru_errno_t fru_create_segment(fru_nodehdl_t container, fru_segdef_t *def);
2117c478bd9Sstevel@tonic-gate fru_errno_t fru_remove_segment(fru_nodehdl_t container, const char *seg_name);
2127c478bd9Sstevel@tonic-gate fru_errno_t fru_get_segment_def(fru_nodehdl_t container, const char *seg_name,
2137c478bd9Sstevel@tonic-gate 				fru_segdef_t *definition);
2147c478bd9Sstevel@tonic-gate fru_errno_t fru_list_elems_in(fru_nodehdl_t container, const char *seg_name,
2157c478bd9Sstevel@tonic-gate 				fru_strlist_t *list);
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate /* Data operations */
2187c478bd9Sstevel@tonic-gate fru_errno_t fru_read_field(fru_nodehdl_t container,
2197c478bd9Sstevel@tonic-gate 			char **seg_name, /* IN/OUT */
2207c478bd9Sstevel@tonic-gate 			unsigned int   instance,
2217c478bd9Sstevel@tonic-gate 			const char *field_path,
2227c478bd9Sstevel@tonic-gate 			void **data,
2237c478bd9Sstevel@tonic-gate 			size_t *data_len,
2247c478bd9Sstevel@tonic-gate 			char **found_path);
2257c478bd9Sstevel@tonic-gate fru_errno_t fru_update_field(fru_nodehdl_t container,
2267c478bd9Sstevel@tonic-gate 				char *seg_name,
2277c478bd9Sstevel@tonic-gate 				unsigned int instance,
2287c478bd9Sstevel@tonic-gate 				const char *field_path,
2297c478bd9Sstevel@tonic-gate 				void *data,
2307c478bd9Sstevel@tonic-gate 				size_t length);
2317c478bd9Sstevel@tonic-gate fru_errno_t fru_get_num_iterations(fru_nodehdl_t container,
2327c478bd9Sstevel@tonic-gate 					char **seg_name, /* IN/OUT */
2337c478bd9Sstevel@tonic-gate 					unsigned int instance,
2347c478bd9Sstevel@tonic-gate 					const char *iter_path,
2357c478bd9Sstevel@tonic-gate 					int *num_there,
2367c478bd9Sstevel@tonic-gate 					char **found_path);
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate /* Tagged Element operations */
2397c478bd9Sstevel@tonic-gate fru_errno_t fru_add_element(fru_nodehdl_t container, const char *seg_name,
2407c478bd9Sstevel@tonic-gate 				const char *element);
2417c478bd9Sstevel@tonic-gate fru_errno_t fru_delete_element(fru_nodehdl_t container, const char *seg_name,
2427c478bd9Sstevel@tonic-gate 				unsigned int instance, const char *element);
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate /* General library support */
2457c478bd9Sstevel@tonic-gate fru_errno_t fru_get_definition(const char *element_name,
2467c478bd9Sstevel@tonic-gate 				fru_elemdef_t *definition);
2477c478bd9Sstevel@tonic-gate fru_errno_t fru_get_registry(fru_strlist_t *list);
2487c478bd9Sstevel@tonic-gate fru_errno_t fru_get_tagged_parents(const char *elem_name,
2497c478bd9Sstevel@tonic-gate 				fru_strlist_t *parents);
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate /* Structure destroy functions */
2527c478bd9Sstevel@tonic-gate fru_errno_t fru_destroy_strlist(fru_strlist_t *list);
2537c478bd9Sstevel@tonic-gate fru_errno_t fru_destroy_elemdef(fru_elemdef_t *def);
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate /* Enum to String Conversions */
2567c478bd9Sstevel@tonic-gate const char *fru_strerror(fru_errno_t errnum);
2577c478bd9Sstevel@tonic-gate const char *get_displaytype_str(fru_displaytype_t e);
2587c478bd9Sstevel@tonic-gate const char *get_datatype_str(fru_datatype_t e);
2597c478bd9Sstevel@tonic-gate const char *get_which_str(fru_which_t e);
2607c478bd9Sstevel@tonic-gate const char *get_itertype_str(fru_itertype_t e);
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2637c478bd9Sstevel@tonic-gate }
2647c478bd9Sstevel@tonic-gate #endif
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate #endif /* _LIBFRU_H */
267