xref: /titanic_51/usr/src/lib/fm/topo/libtopo/common/libtopo.h (revision 27c48ed935c6a5f6015c6534b98e3090b1ddfdb6)
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 void *topo_node_private(tnode_t *);
101 extern int topo_node_asru(tnode_t *, nvlist_t **, nvlist_t *, int *);
102 extern int topo_node_fru(tnode_t *, nvlist_t **, nvlist_t *, int *);
103 extern int topo_node_resource(tnode_t *, nvlist_t **, int *);
104 extern int topo_node_label(tnode_t *, char **, int *);
105 extern int topo_method_invoke(tnode_t *node, const char *, topo_version_t,
106     nvlist_t *, nvlist_t **, int *);
107 
108 extern int topo_prop_get_int32(tnode_t *, const char *, const char *,
109     int32_t *, int *);
110 extern int topo_prop_get_uint32(tnode_t *, const char *, const char *,
111     uint32_t *, int *);
112 extern int topo_prop_get_int64(tnode_t *, const char *, const char *,
113     int64_t *, int *);
114 extern int topo_prop_get_uint64(tnode_t *, const char *, const char *,
115     uint64_t *, int *);
116 extern int topo_prop_get_string(tnode_t *, const char *, const char *,
117     char **, int *);
118 extern int topo_prop_get_fmri(tnode_t *, const char *, const char *,
119     nvlist_t **, int *);
120 extern int topo_prop_get_int32_array(tnode_t *, const char *, const char *,
121     int32_t **, uint_t *, int *);
122 extern int topo_prop_get_uint32_array(tnode_t *, const char *, const char *,
123     uint32_t **, uint_t *, int *);
124 extern int topo_prop_get_int64_array(tnode_t *, const char *, const char *,
125     int64_t **, uint_t *, int *);
126 extern int topo_prop_get_uint64_array(tnode_t *, const char *, const char *,
127     uint64_t **, uint_t *, int *);
128 extern int topo_prop_get_string_array(tnode_t *, const char *, const char *,
129     char ***, uint_t *, int *);
130 extern int topo_prop_get_fmri_array(tnode_t *, const char *, const char *,
131     nvlist_t ***, uint_t *, int *);
132 
133 #define	TOPO_PROP_IMMUTABLE	0
134 #define	TOPO_PROP_MUTABLE	1
135 
136 /* Protocol property group and property names */
137 #define	TOPO_PGROUP_PROTOCOL	"protocol"	/* Required property group */
138 #define	TOPO_PROP_RESOURCE	"resource"	/* resource FMRI */
139 #define	TOPO_PROP_ASRU		"ASRU"		/* ASRU FMRI */
140 #define	TOPO_PROP_FRU		"FRU"		/* FRU FMRI */
141 #define	TOPO_PROP_MOD		"module"	/* software module FMRI */
142 #define	TOPO_PROP_PKG		"package"	/* software package FMRI */
143 #define	TOPO_PROP_LABEL		"label"		/*  property LABEL */
144 
145 /*
146  * System property group
147  */
148 #define	TOPO_PGROUP_SYSTEM	"system"
149 #define	TOPO_PROP_ISA		"isa"
150 #define	TOPO_PROP_MACHINE	"machine"
151 
152 /*
153  * These enum definitions are used to define a set of error tags associated with
154  * libtopo error conditions occuring during the adminstration of
155  * properties, invocation of methods and fmri-based queries.  The shell script
156  * mkerror.sh is used to parse this file and create a corresponding topo_error.c
157  * source file.
158  *
159  * If you do something other than add a new error tag here, you may need to
160  * update the mkerror shell script as it is based upon simple regexps.
161  */
162 typedef enum topo_prop_errno {
163     ETOPO_PROP_UNKNOWN = 3000, /* unknown topo prop error */
164     ETOPO_PROP_NOENT,   /* undefined property or property group */
165     ETOPO_PROP_DEFD,    /* static property already defined */
166     ETOPO_PROP_NOMEM,   /* memory limit exceeded during property allocation */
167     ETOPO_PROP_TYPE,    /* invalid property type */
168     ETOPO_PROP_NAME,    /* invalid property name */
169     ETOPO_PROP_NOINHERIT, /* can not inherit property */
170     ETOPO_PROP_NVL,	/* malformed property nvlist */
171     ETOPO_PROP_METHOD,	/* get property method failed */
172     ETOPO_PROP_END	/* end of prop errno list (to ease auto-merge) */
173 } topo_prop_errno_t;
174 
175 typedef enum topo_method_errno {
176     ETOPO_METHOD_UNKNOWN = 3100, /* unknown topo method error */
177     ETOPO_METHOD_INVAL,		/* invalid method registration */
178     ETOPO_METHOD_NOTSUP,	/* method not supported */
179     ETOPO_METHOD_FAIL,		/* method failed */
180     ETOPO_METHOD_VEROLD,	/* app is compiled to use obsolete method */
181     ETOPO_METHOD_VERNEW,	/* app is compiled to use obsolete method */
182     ETOPO_METHOD_NOMEM,		/* memory limit exceeded during method op */
183     ETOPO_METHOD_DEFD,		/* method op already defined */
184     ETOPO_METHOD_END		/* end of method errno list */
185 } topo_method_errno_t;
186 
187 typedef enum topo_fmri_errno {
188     ETOPO_FMRI_UNKNOWN = 3200, /* unknown topo fmri error */
189     ETOPO_FMRI_NVL,		/* nvlist allocation failure for FMRI */
190     ETOPO_FMRI_VERSION,		/* invalid FMRI scheme version */
191     ETOPO_FMRI_MALFORM,		/* malformed FMRI */
192     ETOPO_FMRI_NOMEM,		/* memory limit exceeded */
193     ETOPO_FMRI_END		/* end of fmri errno list */
194 } topo_fmri_errno_t;
195 
196 typedef enum topo_hdl_errno {
197     ETOPO_HDL_UNKNOWN = 3300,	/* unknown topo handle error */
198     ETOPO_HDL_ABIVER,		/* handle opened with invalid ABI version */
199     ETOPO_HDL_SNAP,		/* snapshot already taken */
200     ETOPO_HDL_INVAL,		/* invalid argument specified */
201     ETOPO_HDL_UUID,		/* uuid already set */
202     ETOPO_HDL_NOMEM,		/* memory limit exceeded */
203     ETOPO_HDL_END		/* end of handle errno list */
204 } topo_hdl_errno_t;
205 
206 extern const char *topo_strerror(int);
207 extern void topo_hdl_strfree(topo_hdl_t *, char *);
208 extern void topo_debug_set(topo_hdl_t *, const char *, const char *);
209 
210 /*
211  * The following functions and data structures to support property
212  * observability are private to the fmtopo command.
213  */
214 
215 /*
216  * Each topology node advertises the name and data stability of each of its
217  * modules and properties. (see attributes(5)).
218  */
219 
220 /*
221  * Topo stability attributes
222  */
223 typedef enum topo_stability {
224 	TOPO_STABILITY_UNKNOWN = 0,	/* private to libtopo */
225 	TOPO_STABILITY_INTERNAL,	/* private to libtopo */
226 	TOPO_STABILITY_PRIVATE,		/* private to Sun */
227 	TOPO_STABILITY_OBSOLETE,	/* scheduled for removal */
228 	TOPO_STABILITY_EXTERNAL,	/* not controlled by Sun */
229 	TOPO_STABILITY_UNSTABLE,	/* new or rapidly changing */
230 	TOPO_STABILITY_EVOLVING,	/* less rapidly changing */
231 	TOPO_STABILITY_STABLE,		/* mature interface from Sun */
232 	TOPO_STABILITY_STANDARD		/* industry standard */
233 } topo_stability_t;
234 
235 #define	TOPO_STABILITY_MAX	TOPO_STABILITY_STANDARD	/* max valid stab */
236 
237 typedef struct topo_pgroup_info {
238 	const char *tpi_name;		/* property group name */
239 	topo_stability_t tpi_namestab;	/* stability of group name */
240 	topo_stability_t tpi_datastab;	/* stability of all property values */
241 	topo_version_t tpi_version;	/* version of pgroup definition */
242 } topo_pgroup_info_t;
243 
244 extern topo_stability_t topo_name2stability(const char *);
245 extern const char *topo_stability2name(topo_stability_t);
246 extern void topo_pgroup_destroy(tnode_t *, const char *);
247 extern topo_pgroup_info_t *topo_pgroup_info(tnode_t *, const char *, int *);
248 
249 typedef enum {
250 	TOPO_TYPE_INVALID = 0,
251 	TOPO_TYPE_BOOLEAN,	/* boolean */
252 	TOPO_TYPE_INT32,	/* int32_t */
253 	TOPO_TYPE_UINT32,	/* uint32_t */
254 	TOPO_TYPE_INT64,	/* int64_t */
255 	TOPO_TYPE_UINT64,	/* uint64_t */
256 	TOPO_TYPE_STRING,	/* const char* */
257 	TOPO_TYPE_TIME,		/* uint64_t */
258 	TOPO_TYPE_SIZE,		/* uint64_t */
259 	TOPO_TYPE_FMRI,		/* nvlist_t */
260 	TOPO_TYPE_INT32_ARRAY,	/* array of int32_t */
261 	TOPO_TYPE_UINT32_ARRAY,	/* array of uint32_t */
262 	TOPO_TYPE_INT64_ARRAY,	/* array of int64_t */
263 	TOPO_TYPE_UINT64_ARRAY,	/* array of uint64_t */
264 	TOPO_TYPE_STRING_ARRAY,	/* array of const char* */
265 	TOPO_TYPE_FMRI_ARRAY	/* array of nvlist_t */
266 } topo_type_t;
267 
268 extern nvlist_t *topo_prop_getprops(tnode_t *, int *err);
269 extern int topo_prop_getprop(tnode_t *, const char *, const char *,
270     nvlist_t *, nvlist_t **, int *);
271 extern int topo_prop_getpgrp(tnode_t *, const char *, nvlist_t **, int *);
272 extern int topo_prop_setprop(tnode_t *, const char *, nvlist_t *,
273     int, nvlist_t *, int *);
274 extern int topo_fmri_getprop(topo_hdl_t *, nvlist_t *, const char *,
275     const char *, nvlist_t *,  nvlist_t **, int *);
276 extern int topo_fmri_getpgrp(topo_hdl_t *, nvlist_t *, const char *,
277     nvlist_t **, int *);
278 extern int topo_fmri_setprop(topo_hdl_t *, nvlist_t *, const char *,
279     nvlist_t *, int, nvlist_t *, int *);
280 
281 /* Property node NVL names used in topo_prop_getprops */
282 #define	TOPO_PROP_GROUP		"property-group"
283 #define	TOPO_PROP_GROUP_NAME	"property-group-name"
284 #define	TOPO_PROP_GROUP_DSTAB	"property-group-data-stability"
285 #define	TOPO_PROP_GROUP_NSTAB	"property-group-name-stability"
286 #define	TOPO_PROP_GROUP_VERSION	"property-group-version"
287 #define	TOPO_PROP_VAL		"property"
288 #define	TOPO_PROP_VAL_NAME	"property-name"
289 #define	TOPO_PROP_VAL_VAL	"property-value"
290 #define	TOPO_PROP_VAL_TYPE	"property-type"
291 #define	TOPO_PROP_FLAG		"property-flag"
292 
293 /*
294  * ARGS list used in topo property methods
295  */
296 #define	TOPO_PROP_ARGS	"args"
297 #define	TOPO_PROP_PARGS	"private-args"
298 
299 extern int topo_xml_print(topo_hdl_t *, FILE *, const char *scheme, int *);
300 
301 extern void *topo_hdl_alloc(topo_hdl_t *, size_t);
302 extern void *topo_hdl_zalloc(topo_hdl_t *, size_t);
303 extern void topo_hdl_free(topo_hdl_t *, void *, size_t);
304 extern int topo_hdl_nvalloc(topo_hdl_t *, nvlist_t **, uint_t);
305 extern int topo_hdl_nvdup(topo_hdl_t *, nvlist_t *, nvlist_t **);
306 extern char *topo_hdl_strdup(topo_hdl_t *, const char *);
307 
308 #ifdef __cplusplus
309 }
310 #endif
311 
312 #endif /* _LIBTOPO_H */
313