xref: /titanic_41/usr/src/lib/fm/topo/libtopo/common/libtopo.h (revision 22337b4b3c8a2b9db615e524e0e9e1fbd3dc71bf)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _LIBTOPO_H
28 #define	_LIBTOPO_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/nvpair.h>
33 #include <stdio.h>
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #define	TOPO_VERSION	1	/* Library ABI Interface Version */
40 
41 typedef struct topo_hdl topo_hdl_t;
42 typedef struct topo_node tnode_t;
43 typedef struct topo_walk topo_walk_t;
44 typedef int32_t topo_instance_t;
45 typedef uint32_t topo_version_t;
46 
47 /*
48  * The following functions, error codes and data structures are private
49  * to libtopo snapshot consumers and enumerator modules.
50  */
51 extern topo_hdl_t *topo_open(int, const char *, int *);
52 extern void topo_close(topo_hdl_t *);
53 extern char *topo_snap_hold(topo_hdl_t *, const char *, int *);
54 extern void topo_snap_release(topo_hdl_t *);
55 
56 /*
57  * Snapshot walker support
58  */
59 typedef int (*topo_walk_cb_t)(topo_hdl_t *, tnode_t *, void *);
60 
61 extern topo_walk_t *topo_walk_init(topo_hdl_t *, const char *, topo_walk_cb_t,
62     void *, int *);
63 extern int topo_walk_step(topo_walk_t *, int);
64 extern void topo_walk_fini(topo_walk_t *);
65 
66 /*
67  * Walk status returned from walker
68  */
69 #define	TOPO_WALK_ERR		-1
70 #define	TOPO_WALK_NEXT		0
71 #define	TOPO_WALK_TERMINATE	1
72 
73 /*
74  * Types of walks: depth-first (child) or breadth-first (sibling)
75  */
76 #define	TOPO_WALK_CHILD		0x0001
77 #define	TOPO_WALK_SIBLING	0x0002
78 
79 /*
80  * FMRI helper routines
81  */
82 extern int topo_fmri_present(topo_hdl_t *, nvlist_t *, int *);
83 extern int topo_fmri_contains(topo_hdl_t *, nvlist_t *, nvlist_t *, int *);
84 extern int topo_fmri_expand(topo_hdl_t *, nvlist_t *, int *);
85 extern int topo_fmri_unusable(topo_hdl_t *, nvlist_t *, int *);
86 extern int topo_fmri_nvl2str(topo_hdl_t *, nvlist_t *, char **, int *);
87 extern int topo_fmri_str2nvl(topo_hdl_t *, const char *, nvlist_t **, int *);
88 extern int topo_fmri_asru(topo_hdl_t *, nvlist_t *, nvlist_t **, int *);
89 extern int topo_fmri_fru(topo_hdl_t *, nvlist_t *, nvlist_t **,
90     int *);
91 extern int topo_fmri_label(topo_hdl_t *, nvlist_t *, char **, int *);
92 extern int topo_fmri_compare(topo_hdl_t *, nvlist_t *, nvlist_t *, int *);
93 
94 /*
95  * Topo node utilities: callable from topo_walk_step() callback or module
96  * enumeration, topo_mod_enumerate()
97  */
98 extern char *topo_node_name(tnode_t *);
99 extern topo_instance_t topo_node_instance(tnode_t *);
100 extern tnode_t *topo_node_parent(tnode_t *);
101 extern void *topo_node_private(tnode_t *);
102 extern int topo_node_asru(tnode_t *, nvlist_t **, nvlist_t *, int *);
103 extern int topo_node_fru(tnode_t *, nvlist_t **, nvlist_t *, int *);
104 extern int topo_node_resource(tnode_t *, nvlist_t **, int *);
105 extern int topo_node_label(tnode_t *, char **, int *);
106 extern int topo_method_invoke(tnode_t *node, const char *, topo_version_t,
107     nvlist_t *, nvlist_t **, int *);
108 
109 extern int topo_prop_get_int32(tnode_t *, const char *, const char *,
110     int32_t *, int *);
111 extern int topo_prop_get_uint32(tnode_t *, const char *, const char *,
112     uint32_t *, int *);
113 extern int topo_prop_get_int64(tnode_t *, const char *, const char *,
114     int64_t *, int *);
115 extern int topo_prop_get_uint64(tnode_t *, const char *, const char *,
116     uint64_t *, int *);
117 extern int topo_prop_get_string(tnode_t *, const char *, const char *,
118     char **, int *);
119 extern int topo_prop_get_fmri(tnode_t *, const char *, const char *,
120     nvlist_t **, int *);
121 extern int topo_prop_get_int32_array(tnode_t *, const char *, const char *,
122     int32_t **, uint_t *, int *);
123 extern int topo_prop_get_uint32_array(tnode_t *, const char *, const char *,
124     uint32_t **, uint_t *, int *);
125 extern int topo_prop_get_int64_array(tnode_t *, const char *, const char *,
126     int64_t **, uint_t *, int *);
127 extern int topo_prop_get_uint64_array(tnode_t *, const char *, const char *,
128     uint64_t **, uint_t *, int *);
129 extern int topo_prop_get_string_array(tnode_t *, const char *, const char *,
130     char ***, uint_t *, int *);
131 extern int topo_prop_get_fmri_array(tnode_t *, const char *, const char *,
132     nvlist_t ***, uint_t *, int *);
133 
134 #define	TOPO_PROP_IMMUTABLE	0
135 #define	TOPO_PROP_MUTABLE	1
136 
137 /* Protocol property group and property names */
138 #define	TOPO_PGROUP_PROTOCOL	"protocol"	/* Required property group */
139 #define	TOPO_PROP_RESOURCE	"resource"	/* resource FMRI */
140 #define	TOPO_PROP_ASRU		"ASRU"		/* ASRU FMRI */
141 #define	TOPO_PROP_FRU		"FRU"		/* FRU FMRI */
142 #define	TOPO_PROP_MOD		"module"	/* software module FMRI */
143 #define	TOPO_PROP_PKG		"package"	/* software package FMRI */
144 #define	TOPO_PROP_LABEL		"label"		/*  property LABEL */
145 
146 /*
147  * System property group
148  */
149 #define	TOPO_PGROUP_SYSTEM	"system"
150 #define	TOPO_PROP_ISA		"isa"
151 #define	TOPO_PROP_MACHINE	"machine"
152 
153 /*
154  * These enum definitions are used to define a set of error tags associated with
155  * libtopo error conditions occuring during the adminstration of
156  * properties, invocation of methods and fmri-based queries.  The shell script
157  * mkerror.sh is used to parse this file and create a corresponding topo_error.c
158  * source file.
159  *
160  * If you do something other than add a new error tag here, you may need to
161  * update the mkerror shell script as it is based upon simple regexps.
162  */
163 typedef enum topo_prop_errno {
164     ETOPO_PROP_UNKNOWN = 3000, /* unknown topo prop error */
165     ETOPO_PROP_NOENT,   /* undefined property or property group */
166     ETOPO_PROP_DEFD,    /* static property already defined */
167     ETOPO_PROP_NOMEM,   /* memory limit exceeded during property allocation */
168     ETOPO_PROP_TYPE,    /* invalid property type */
169     ETOPO_PROP_NAME,    /* invalid property name */
170     ETOPO_PROP_NOINHERIT, /* can not inherit property */
171     ETOPO_PROP_NVL,	/* malformed property nvlist */
172     ETOPO_PROP_METHOD,	/* get property method failed */
173     ETOPO_PROP_END	/* end of prop errno list (to ease auto-merge) */
174 } topo_prop_errno_t;
175 
176 typedef enum topo_method_errno {
177     ETOPO_METHOD_UNKNOWN = 3100, /* unknown topo method error */
178     ETOPO_METHOD_INVAL,		/* invalid method registration */
179     ETOPO_METHOD_NOTSUP,	/* method not supported */
180     ETOPO_METHOD_FAIL,		/* method failed */
181     ETOPO_METHOD_VEROLD,	/* app is compiled to use obsolete method */
182     ETOPO_METHOD_VERNEW,	/* app is compiled to use obsolete method */
183     ETOPO_METHOD_NOMEM,		/* memory limit exceeded during method op */
184     ETOPO_METHOD_DEFD,		/* method op already defined */
185     ETOPO_METHOD_END		/* end of method errno list */
186 } topo_method_errno_t;
187 
188 typedef enum topo_fmri_errno {
189     ETOPO_FMRI_UNKNOWN = 3200, /* unknown topo fmri error */
190     ETOPO_FMRI_NVL,		/* nvlist allocation failure for FMRI */
191     ETOPO_FMRI_VERSION,		/* invalid FMRI scheme version */
192     ETOPO_FMRI_MALFORM,		/* malformed FMRI */
193     ETOPO_FMRI_NOMEM,		/* memory limit exceeded */
194     ETOPO_FMRI_END		/* end of fmri errno list */
195 } topo_fmri_errno_t;
196 
197 typedef enum topo_hdl_errno {
198     ETOPO_HDL_UNKNOWN = 3300,	/* unknown topo handle error */
199     ETOPO_HDL_ABIVER,		/* handle opened with invalid ABI version */
200     ETOPO_HDL_SNAP,		/* snapshot already taken */
201     ETOPO_HDL_INVAL,		/* invalid argument specified */
202     ETOPO_HDL_UUID,		/* uuid already set */
203     ETOPO_HDL_NOMEM,		/* memory limit exceeded */
204     ETOPO_HDL_END		/* end of handle errno list */
205 } topo_hdl_errno_t;
206 
207 extern const char *topo_strerror(int);
208 extern void topo_hdl_strfree(topo_hdl_t *, char *);
209 extern void topo_debug_set(topo_hdl_t *, const char *, const char *);
210 
211 /*
212  * The following functions and data structures to support property
213  * observability are private to the fmtopo command.
214  */
215 
216 /*
217  * Each topology node advertises the name and data stability of each of its
218  * modules and properties. (see attributes(5)).
219  */
220 
221 /*
222  * Topo stability attributes
223  */
224 typedef enum topo_stability {
225 	TOPO_STABILITY_UNKNOWN = 0,	/* private to libtopo */
226 	TOPO_STABILITY_INTERNAL,	/* private to libtopo */
227 	TOPO_STABILITY_PRIVATE,		/* private to Sun */
228 	TOPO_STABILITY_OBSOLETE,	/* scheduled for removal */
229 	TOPO_STABILITY_EXTERNAL,	/* not controlled by Sun */
230 	TOPO_STABILITY_UNSTABLE,	/* new or rapidly changing */
231 	TOPO_STABILITY_EVOLVING,	/* less rapidly changing */
232 	TOPO_STABILITY_STABLE,		/* mature interface from Sun */
233 	TOPO_STABILITY_STANDARD		/* industry standard */
234 } topo_stability_t;
235 
236 #define	TOPO_STABILITY_MAX	TOPO_STABILITY_STANDARD	/* max valid stab */
237 
238 typedef struct topo_pgroup_info {
239 	const char *tpi_name;		/* property group name */
240 	topo_stability_t tpi_namestab;	/* stability of group name */
241 	topo_stability_t tpi_datastab;	/* stability of all property values */
242 	topo_version_t tpi_version;	/* version of pgroup definition */
243 } topo_pgroup_info_t;
244 
245 extern topo_stability_t topo_name2stability(const char *);
246 extern const char *topo_stability2name(topo_stability_t);
247 extern void topo_pgroup_destroy(tnode_t *, const char *);
248 extern topo_pgroup_info_t *topo_pgroup_info(tnode_t *, const char *, int *);
249 
250 typedef enum {
251 	TOPO_TYPE_INVALID = 0,
252 	TOPO_TYPE_BOOLEAN,	/* boolean */
253 	TOPO_TYPE_INT32,	/* int32_t */
254 	TOPO_TYPE_UINT32,	/* uint32_t */
255 	TOPO_TYPE_INT64,	/* int64_t */
256 	TOPO_TYPE_UINT64,	/* uint64_t */
257 	TOPO_TYPE_STRING,	/* const char* */
258 	TOPO_TYPE_TIME,		/* uint64_t */
259 	TOPO_TYPE_SIZE,		/* uint64_t */
260 	TOPO_TYPE_FMRI,		/* nvlist_t */
261 	TOPO_TYPE_INT32_ARRAY,	/* array of int32_t */
262 	TOPO_TYPE_UINT32_ARRAY,	/* array of uint32_t */
263 	TOPO_TYPE_INT64_ARRAY,	/* array of int64_t */
264 	TOPO_TYPE_UINT64_ARRAY,	/* array of uint64_t */
265 	TOPO_TYPE_STRING_ARRAY,	/* array of const char* */
266 	TOPO_TYPE_FMRI_ARRAY	/* array of nvlist_t */
267 } topo_type_t;
268 
269 extern nvlist_t *topo_prop_getprops(tnode_t *, int *err);
270 extern int topo_prop_getprop(tnode_t *, const char *, const char *,
271     nvlist_t *, nvlist_t **, int *);
272 extern int topo_prop_getpgrp(tnode_t *, const char *, nvlist_t **, int *);
273 extern int topo_prop_setprop(tnode_t *, const char *, nvlist_t *,
274     int, nvlist_t *, int *);
275 extern int topo_fmri_getprop(topo_hdl_t *, nvlist_t *, const char *,
276     const char *, nvlist_t *,  nvlist_t **, int *);
277 extern int topo_fmri_getpgrp(topo_hdl_t *, nvlist_t *, const char *,
278     nvlist_t **, int *);
279 extern int topo_fmri_setprop(topo_hdl_t *, nvlist_t *, const char *,
280     nvlist_t *, int, nvlist_t *, int *);
281 
282 /* Property node NVL names used in topo_prop_getprops */
283 #define	TOPO_PROP_GROUP		"property-group"
284 #define	TOPO_PROP_GROUP_NAME	"property-group-name"
285 #define	TOPO_PROP_GROUP_DSTAB	"property-group-data-stability"
286 #define	TOPO_PROP_GROUP_NSTAB	"property-group-name-stability"
287 #define	TOPO_PROP_GROUP_VERSION	"property-group-version"
288 #define	TOPO_PROP_VAL		"property"
289 #define	TOPO_PROP_VAL_NAME	"property-name"
290 #define	TOPO_PROP_VAL_VAL	"property-value"
291 #define	TOPO_PROP_VAL_TYPE	"property-type"
292 #define	TOPO_PROP_FLAG		"property-flag"
293 
294 /*
295  * ARGS list used in topo property methods
296  */
297 #define	TOPO_PROP_ARGS	"args"
298 #define	TOPO_PROP_PARGS	"private-args"
299 
300 extern int topo_xml_print(topo_hdl_t *, FILE *, const char *scheme, int *);
301 
302 extern void *topo_hdl_alloc(topo_hdl_t *, size_t);
303 extern void *topo_hdl_zalloc(topo_hdl_t *, size_t);
304 extern void topo_hdl_free(topo_hdl_t *, void *, size_t);
305 extern int topo_hdl_nvalloc(topo_hdl_t *, nvlist_t **, uint_t);
306 extern int topo_hdl_nvdup(topo_hdl_t *, nvlist_t *, nvlist_t **);
307 extern char *topo_hdl_strdup(topo_hdl_t *, const char *);
308 
309 #ifdef __cplusplus
310 }
311 #endif
312 
313 #endif /* _LIBTOPO_H */
314