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