xref: /illumos-gate/usr/src/lib/fm/topo/libtopo/common/libtopo.h (revision 4e93fb0f6383eaac21897dcdae56b87118131e4d)
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 2006 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  * Topo stability attributes
49  *
50  * Each topology node advertises the name and data stability of each of its
51  * modules and properties. (see attributes(5))
52  */
53 
54 typedef enum topo_stability {
55 	TOPO_STABILITY_UNKNOWN = 0,	/* private to libtopo */
56 	TOPO_STABILITY_INTERNAL,	/* private to libtopo */
57 	TOPO_STABILITY_PRIVATE,		/* private to Sun */
58 	TOPO_STABILITY_OBSOLETE,	/* scheduled for removal */
59 	TOPO_STABILITY_EXTERNAL,	/* not controlled by Sun */
60 	TOPO_STABILITY_UNSTABLE,	/* new or rapidly changing */
61 	TOPO_STABILITY_EVOLVING,	/* less rapidly changing */
62 	TOPO_STABILITY_STABLE,		/* mature interface from Sun */
63 	TOPO_STABILITY_STANDARD		/* industry standard */
64 } topo_stability_t;
65 
66 #define	TOPO_STABILITY_MAX	TOPO_STABILITY_STANDARD	/* max valid stab */
67 
68 typedef enum {
69 	TOPO_TYPE_INVALID = 0,
70 	TOPO_TYPE_BOOLEAN,	/* boolean */
71 	TOPO_TYPE_INT32,	/* int32_t */
72 	TOPO_TYPE_UINT32,	/* uint32_t */
73 	TOPO_TYPE_INT64,	/* int64_t */
74 	TOPO_TYPE_UINT64,	/* uint64_t */
75 	TOPO_TYPE_STRING,	/* const char* */
76 	TOPO_TYPE_TIME,		/* uint64_t */
77 	TOPO_TYPE_SIZE,		/* uint64_t */
78 	TOPO_TYPE_FMRI,		/* nvlist_t */
79 	TOPO_TYPE_INT32_ARRAY,	/* array of int32_t */
80 	TOPO_TYPE_UINT32_ARRAY,	/* array of uint32_t */
81 	TOPO_TYPE_INT64_ARRAY,	/* array of int64_t */
82 	TOPO_TYPE_UINT64_ARRAY,	/* array of uint64_t */
83 	TOPO_TYPE_STRING_ARRAY,	/* array of const char* */
84 	TOPO_TYPE_FMRI_ARRAY	/* array of nvlist_t */
85 } topo_type_t;
86 
87 typedef struct topo_pgroup_info {
88 	const char *tpi_name;		/* property group name */
89 	topo_stability_t tpi_namestab;	/* stability of group name */
90 	topo_stability_t tpi_datastab;	/* stability of all property values */
91 	topo_version_t tpi_version;	/* version of pgroup definition */
92 } topo_pgroup_info_t;
93 
94 extern topo_stability_t topo_name2stability(const char *);
95 extern const char *topo_stability2name(topo_stability_t);
96 
97 extern topo_hdl_t *topo_open(int, const char *, int *);
98 extern void topo_close(topo_hdl_t *);
99 extern char *topo_snap_hold(topo_hdl_t *, const char *, int *);
100 extern void topo_snap_release(topo_hdl_t *);
101 extern int topo_xml_print(topo_hdl_t *, FILE *, const char *scheme, int *);
102 
103 /*
104  * Snapshot walker support
105  */
106 typedef int (*topo_walk_cb_t)(topo_hdl_t *, tnode_t *, void *);
107 
108 extern topo_walk_t *topo_walk_init(topo_hdl_t *, const char *, topo_walk_cb_t,
109     void *, int *);
110 extern int topo_walk_step(topo_walk_t *, int);
111 extern void topo_walk_fini(topo_walk_t *);
112 
113 #define	TOPO_WALK_ERR		-1
114 #define	TOPO_WALK_NEXT		0
115 #define	TOPO_WALK_TERMINATE	1
116 
117 #define	TOPO_WALK_CHILD		0x0001
118 #define	TOPO_WALK_SIBLING	0x0002
119 
120 /*
121  * FMRI helper routines
122  */
123 extern int topo_fmri_present(topo_hdl_t *, nvlist_t *, int *);
124 extern int topo_fmri_contains(topo_hdl_t *, nvlist_t *, nvlist_t *, int *);
125 extern int topo_fmri_unusable(topo_hdl_t *, nvlist_t *, int *);
126 extern int topo_fmri_nvl2str(topo_hdl_t *, nvlist_t *, char **, int *);
127 extern int topo_fmri_str2nvl(topo_hdl_t *, const char *, nvlist_t **, int *);
128 extern int topo_fmri_asru(topo_hdl_t *, nvlist_t *, nvlist_t **, int *);
129 extern int topo_fmri_fru(topo_hdl_t *, nvlist_t *, nvlist_t **,
130     int *);
131 extern int topo_fmri_label(topo_hdl_t *, nvlist_t *, char **, int *);
132 extern int topo_fmri_compare(topo_hdl_t *, nvlist_t *, nvlist_t *, int *);
133 extern int topo_fmri_invoke(topo_hdl_t *, nvlist_t *, topo_walk_cb_t, void *,
134     int *);
135 
136 /*
137  * Topo node utilities: callable from topo_walk_step() callback or module
138  * enumeration, topo_mod_enumerate()
139  */
140 extern char *topo_node_name(tnode_t *);
141 extern topo_instance_t topo_node_instance(tnode_t *);
142 extern void *topo_node_private(tnode_t *);
143 extern int topo_node_asru(tnode_t *, nvlist_t **, nvlist_t *, int *);
144 extern int topo_node_fru(tnode_t *, nvlist_t **, nvlist_t *, int *);
145 extern int topo_node_resource(tnode_t *, nvlist_t **, int *);
146 extern int topo_node_label(tnode_t *, char **, int *);
147 extern int topo_method_invoke(tnode_t *node, const char *, topo_version_t,
148     nvlist_t *, nvlist_t **, int *);
149 
150 extern int topo_pgroup_create(tnode_t *, const topo_pgroup_info_t *, int *);
151 extern void topo_pgroup_destroy(tnode_t *, const char *);
152 extern topo_pgroup_info_t *topo_pgroup_info(tnode_t *, const char *, int *);
153 extern int topo_prop_get_int32(tnode_t *, const char *, const char *,
154     int32_t *, int *);
155 extern int topo_prop_get_uint32(tnode_t *, const char *, const char *,
156     uint32_t *, int *);
157 extern int topo_prop_get_int64(tnode_t *, const char *, const char *,
158     int64_t *, int *);
159 extern int topo_prop_get_uint64(tnode_t *, const char *, const char *,
160     uint64_t *, int *);
161 extern int topo_prop_get_string(tnode_t *, const char *, const char *,
162     char **, int *);
163 extern int topo_prop_get_fmri(tnode_t *, const char *, const char *,
164     nvlist_t **, int *);
165 extern int topo_prop_get_int32_array(tnode_t *, const char *, const char *,
166     int32_t **, uint_t *, int *);
167 extern int topo_prop_get_uint32_array(tnode_t *, const char *, const char *,
168     uint32_t **, uint_t *, int *);
169 extern int topo_prop_get_int64_array(tnode_t *, const char *, const char *,
170     int64_t **, uint_t *, int *);
171 extern int topo_prop_get_uint64_array(tnode_t *, const char *, const char *,
172     uint64_t **, uint_t *, int *);
173 extern int topo_prop_get_string_array(tnode_t *, const char *, const char *,
174     char ***, uint_t *, int *);
175 extern int topo_prop_get_fmri_array(tnode_t *, const char *, const char *,
176     nvlist_t ***, uint_t *, int *);
177 extern int topo_prop_set_int32(tnode_t *, const char *, const char *, int,
178     int32_t, int *);
179 extern int topo_prop_set_uint32(tnode_t *, const char *, const char *, int,
180     uint32_t, int *);
181 extern int topo_prop_set_int64(tnode_t *, const char *, const char *,
182     int, int64_t, int *);
183 extern int topo_prop_set_uint64(tnode_t *, const char *, const char *,
184     int, uint64_t, int *);
185 extern int topo_prop_set_string(tnode_t *, const char *, const char *,
186     int, const char *, int *);
187 extern int topo_prop_set_fmri(tnode_t *, const char *, const char *,
188     int, const nvlist_t *, int *);
189 extern int topo_prop_set_int32_array(tnode_t *, const char *, const char *, int,
190     int32_t *, uint_t, int *);
191 extern int topo_prop_set_uint32_array(tnode_t *, const char *, const char *,
192     int, uint32_t *, uint_t, int *);
193 extern int topo_prop_set_int64_array(tnode_t *, const char *, const char *,
194     int, int64_t *, uint_t, int *);
195 extern int topo_prop_set_uint64_array(tnode_t *, const char *, const char *,
196     int, uint64_t *, uint_t, int *);
197 extern int topo_prop_set_string_array(tnode_t *, const char *, const char *,
198     int, const char **, uint_t, int *);
199 extern int topo_prop_set_fmri_array(tnode_t *, const char *, const char *,
200     int, const nvlist_t **, uint_t, int *);
201 extern nvlist_t *topo_prop_getprops(tnode_t *, int *err);
202 extern int topo_prop_inherit(tnode_t *, const char *, const char *, int *);
203 
204 #define	TOPO_PROP_IMMUTABLE	0
205 #define	TOPO_PROP_MUTABLE	1
206 
207 /* Protocol property group and property names */
208 #define	TOPO_PGROUP_PROTOCOL	"protocol"	/* Required property group */
209 #define	TOPO_PROP_RESOURCE	"resource"	/* resource FMRI */
210 #define	TOPO_PROP_ASRU		"ASRU"		/* ASRU FMRI */
211 #define	TOPO_PROP_FRU		"FRU"		/* FRU FMRI */
212 #define	TOPO_PROP_MOD		"module"	/* software module FMRI */
213 #define	TOPO_PROP_PKG		"package"	/* software package FMRI */
214 #define	TOPO_PROP_LABEL		"label"		/*  property LABEL */
215 
216 /*
217  * System property group
218  */
219 #define	TOPO_PGROUP_SYSTEM	"system"
220 #define	TOPO_PROP_ISA		"isa"
221 #define	TOPO_PROP_MACHINE	"machine"
222 
223 /* Property node NVL names used in topo_prop_getprops */
224 #define	TOPO_PROP_GROUP		"property-group"
225 #define	TOPO_PROP_GROUP_NAME	"property-group-name"
226 #define	TOPO_PROP_GROUP_DSTAB	"property-group-data-stability"
227 #define	TOPO_PROP_GROUP_NSTAB	"property-group-name-stability"
228 #define	TOPO_PROP_GROUP_VERSION	"property-group-version"
229 #define	TOPO_PROP_VAL		"property"
230 #define	TOPO_PROP_VAL_NAME	"property-name"
231 #define	TOPO_PROP_VAL_VAL	"property-value"
232 #define	TOPO_PROP_VAL_TYPE	"property-type"
233 
234 /*
235  * This enum definition is used to define a set of error tags associated with
236  * the libtopo various error conditions occuring during the adminstration of
237  * properties.  The shell script mkerror.sh is
238  * used to parse this file and create a corresponding topo_error.c source file.
239  * If you do something other than add a new error tag here, you may need to
240  * update the mkerror shell script as it is based upon simple regexps.
241  */
242 typedef enum topo_prop_errno {
243     ETOPO_PROP_UNKNOWN = 3000, /* unknown topo prop error */
244     ETOPO_PROP_NOENT,   /* undefined property or property group */
245     ETOPO_PROP_DEFD,    /* static property already defined */
246     ETOPO_PROP_NOMEM,   /* memory limit exceeded during property allocation */
247     ETOPO_PROP_TYPE,    /* invalid property type */
248     ETOPO_PROP_NOINHERIT, /* can not inherit property */
249     ETOPO_PROP_NVL,	/* malformed property nvlist */
250     ETOPO_PROP_END	/* end of prop errno list (to ease auto-merge) */
251 } topo_prop_errno_t;
252 
253 extern const char *topo_strerror(int);
254 extern void topo_debug_set(topo_hdl_t *, const char *, const char *);
255 extern void *topo_hdl_alloc(topo_hdl_t *, size_t);
256 extern void *topo_hdl_zalloc(topo_hdl_t *, size_t);
257 extern void topo_hdl_free(topo_hdl_t *, void *, size_t);
258 extern int topo_hdl_nvalloc(topo_hdl_t *, nvlist_t **, uint_t);
259 extern int topo_hdl_nvdup(topo_hdl_t *, nvlist_t *, nvlist_t **);
260 extern char *topo_hdl_strdup(topo_hdl_t *, const char *);
261 extern void topo_hdl_strfree(topo_hdl_t *, char *);
262 
263 #ifdef __cplusplus
264 }
265 #endif
266 
267 #endif /* _LIBTOPO_H */
268