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