xref: /titanic_50/usr/src/lib/libpicl/picl.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_PICL_H
28 #define	_PICL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * PICL Interface
38  */
39 
40 #include <sys/types.h>
41 
42 #define	PICL_VERSION_1	0x1
43 
44 /*
45  * A PICL handle
46  */
47 typedef uint64_t picl_nodehdl_t;
48 typedef uint64_t picl_prophdl_t;
49 
50 /*
51  * Maximum length of a property name
52  */
53 #define	PICL_PROPNAMELEN_MAX	256
54 #define	PICL_CLASSNAMELEN_MAX	(PICL_PROPNAMELEN_MAX - sizeof ("__"))
55 
56 /*
57  * Maximum size of a property value
58  */
59 #define	PICL_PROPSIZE_MAX	(512 * 1024)
60 
61 /*
62  * PICL property access modes
63  */
64 #define	PICL_READ		0x1
65 #define	PICL_WRITE		0x2
66 /* Not seen by clients */
67 #define	PICL_VOLATILE		0x4
68 
69 /*
70  * PICL error numbers
71  */
72 typedef enum {
73 	PICL_SUCCESS = 0x0,
74 	PICL_FAILURE,		/* general failure */
75 	PICL_NORESPONSE,	/* No response */
76 	PICL_UNKNOWNSERVICE,	/* unknown PICL service */
77 	PICL_NOTINITIALIZED,	/* interface not initialized */
78 	PICL_INVALIDARG,	/* invalid arguments passed */
79 	PICL_VALUETOOBIG,	/* value too big for buffer */
80 	PICL_PROPNOTFOUND,	/* property not found */
81 	PICL_NOTTABLE,		/* not a table */
82 	PICL_NOTNODE,		/* not a node */
83 	PICL_NOTPROP,		/* not a prop */
84 	PICL_ENDOFLIST,		/* end of list */
85 	PICL_PROPEXISTS,	/* prop already exists */
86 	PICL_NOTWRITABLE,	/* not writable */
87 	PICL_PERMDENIED,	/* permission denied */
88 	PICL_INVALIDHANDLE,	/* invalid handle */
89 	PICL_STALEHANDLE,	/* stale handle */
90 	PICL_NOTSUPPORTED,	/* version not supported */
91 	PICL_TIMEDOUT,		/* timed out */
92 	PICL_CANTDESTROY,	/* cannot destroy */
93 	PICL_TREEBUSY,		/* too busy to lock tree */
94 	PICL_CANTPARENT,	/* already has a parent */
95 	PICL_RESERVEDNAME,	/* property name is reserved */
96 	PICL_INVREFERENCE,	/* Invalid reference value */
97 	PICL_WALK_CONTINUE,	/* continue walking tree */
98 	PICL_WALK_TERMINATE,	/* stop walking tree */
99 	PICL_NODENOTFOUND,	/* node not found */
100 	PICL_NOSPACE,		/* not enough space available */
101 	PICL_NOTREADABLE,	/* property not readable */
102 	PICL_PROPVALUNAVAILABLE	/* property value unavailable */
103 } picl_errno_t;
104 
105 /*
106  * PICL property types
107  */
108 typedef	enum {
109 	PICL_PTYPE_UNKNOWN = 0x0,
110 	PICL_PTYPE_VOID,		/* exists or not */
111 	PICL_PTYPE_INT,			/* scalar */
112 	PICL_PTYPE_UNSIGNED_INT,	/* scalar */
113 	PICL_PTYPE_FLOAT,		/* scalar */
114 	PICL_PTYPE_REFERENCE,		/* reference handle */
115 	PICL_PTYPE_TABLE,		/* table handle */
116 	PICL_PTYPE_TIMESTAMP,		/* time stamp */
117 	PICL_PTYPE_BYTEARRAY,		/* array of bytes */
118 	PICL_PTYPE_CHARSTRING		/* nul terminated array of chars */
119 } picl_prop_type_t;
120 
121 typedef struct {
122 	picl_prop_type_t	type;
123 	unsigned int		accessmode;	/* always == PICL_READ */
124 	size_t			size;		/* item size or string size */
125 	char			name[PICL_PROPNAMELEN_MAX];
126 } picl_propinfo_t;
127 
128 /*
129  * -------------------------------------
130  * Function prototypes of PICL Interface
131  * -------------------------------------
132  */
133 
134 extern	int  picl_initialize(void);
135 extern	int  picl_shutdown(void);
136 extern	int  picl_get_root(picl_nodehdl_t *nodehandle);
137 extern	int  picl_get_propval(picl_prophdl_t proph, void *valbuf,
138 		size_t sz);
139 extern	int  picl_get_propval_by_name(picl_nodehdl_t nodeh,
140 		const char *propname, void *valbuf, size_t sz);
141 extern	int  picl_set_propval(picl_prophdl_t proph, void *valbuf,
142 		size_t sz);
143 extern	int  picl_set_propval_by_name(picl_nodehdl_t nodeh,
144 		const char *propname, void *valbuf, size_t sz);
145 extern  int  picl_get_propinfo(picl_prophdl_t proph, picl_propinfo_t *pi);
146 extern	int  picl_get_first_prop(picl_nodehdl_t nodeh, picl_prophdl_t *proph);
147 extern	int  picl_get_next_prop(picl_prophdl_t proph, picl_prophdl_t *nexth);
148 extern	int  picl_get_prop_by_name(picl_nodehdl_t nodeh, const char *nm,
149 			picl_prophdl_t *ph);
150 extern	int  picl_get_next_by_row(picl_prophdl_t thish, picl_prophdl_t *proph);
151 extern	int  picl_get_next_by_col(picl_prophdl_t thish, picl_prophdl_t *proph);
152 extern	int  picl_wait(unsigned int secs);
153 extern	char *picl_strerror(int err);
154 extern	int  picl_walk_tree_by_class(picl_nodehdl_t rooth,
155 		const char *classname, void *c_args,
156 		int (*callback_fn)(picl_nodehdl_t hdl, void *args));
157 extern	int  picl_get_propinfo_by_name(picl_nodehdl_t nodeh, const char *pname,
158 		picl_propinfo_t *pinfo, picl_prophdl_t *proph);
159 
160 extern	int  picl_find_node(picl_nodehdl_t rooth, char *pname,
161 		picl_prop_type_t ptype, void *pval, size_t valsize,
162 		picl_nodehdl_t *retnodeh);
163 
164 extern	int  picl_get_node_by_path(const char *piclpath, picl_nodehdl_t *nodeh);
165 
166 extern	int  picl_get_frutree_parent(picl_nodehdl_t devh, picl_nodehdl_t *fruh);
167 
168 /*
169  * Standard PICL names: properties and nodes
170  */
171 #define	PICL_NODE_ROOT		"/"
172 #define	PICL_NODE_PLATFORM	"platform"
173 #define	PICL_NODE_OBP		"obp"
174 #define	PICL_NODE_FRUTREE	"frutree"
175 
176 #define	PICL_PROP_NAME		"name"
177 #define	PICL_PROP_CLASSNAME	"_class"
178 #define	PICL_PROP_PARENT	"_parent"
179 #define	PICL_PROP_CHILD		"_child"
180 #define	PICL_PROP_PEER		"_peer"
181 
182 #define	PICL_CLASS_PICL		"picl"
183 
184 #ifdef	__cplusplus
185 }
186 #endif
187 
188 #endif	/* _PICL_H */
189