xref: /illumos-gate/usr/src/lib/fm/topo/libtopo/common/libtopo.h (revision 7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fe)
1*7aec1d6eScindi /*
2*7aec1d6eScindi  * CDDL HEADER START
3*7aec1d6eScindi  *
4*7aec1d6eScindi  * The contents of this file are subject to the terms of the
5*7aec1d6eScindi  * Common Development and Distribution License (the "License").
6*7aec1d6eScindi  * You may not use this file except in compliance with the License.
7*7aec1d6eScindi  *
8*7aec1d6eScindi  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*7aec1d6eScindi  * or http://www.opensolaris.org/os/licensing.
10*7aec1d6eScindi  * See the License for the specific language governing permissions
11*7aec1d6eScindi  * and limitations under the License.
12*7aec1d6eScindi  *
13*7aec1d6eScindi  * When distributing Covered Code, include this CDDL HEADER in each
14*7aec1d6eScindi  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*7aec1d6eScindi  * If applicable, add the following below this CDDL HEADER, with the
16*7aec1d6eScindi  * fields enclosed by brackets "[]" replaced with your own identifying
17*7aec1d6eScindi  * information: Portions Copyright [yyyy] [name of copyright owner]
18*7aec1d6eScindi  *
19*7aec1d6eScindi  * CDDL HEADER END
20*7aec1d6eScindi  */
21*7aec1d6eScindi 
22*7aec1d6eScindi /*
23*7aec1d6eScindi  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24*7aec1d6eScindi  * Use is subject to license terms.
25*7aec1d6eScindi  */
26*7aec1d6eScindi 
27*7aec1d6eScindi #ifndef _LIBTOPO_H
28*7aec1d6eScindi #define	_LIBTOPO_H
29*7aec1d6eScindi 
30*7aec1d6eScindi #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7aec1d6eScindi 
32*7aec1d6eScindi #include <sys/nvpair.h>
33*7aec1d6eScindi 
34*7aec1d6eScindi #ifdef __cplusplus
35*7aec1d6eScindi extern "C" {
36*7aec1d6eScindi #endif
37*7aec1d6eScindi 
38*7aec1d6eScindi #define	TOPO_VERSION	1	/* Library ABI Interface Version */
39*7aec1d6eScindi 
40*7aec1d6eScindi typedef struct topo_hdl topo_hdl_t;
41*7aec1d6eScindi typedef struct topo_node tnode_t;
42*7aec1d6eScindi typedef struct topo_walk topo_walk_t;
43*7aec1d6eScindi typedef int32_t topo_instance_t;
44*7aec1d6eScindi typedef uint32_t topo_version_t;
45*7aec1d6eScindi 
46*7aec1d6eScindi /*
47*7aec1d6eScindi  * Topo stability attributes
48*7aec1d6eScindi  *
49*7aec1d6eScindi  * Each topology node advertises the name and data stability of each of its
50*7aec1d6eScindi  * modules and properties. (see attributes(5))
51*7aec1d6eScindi  */
52*7aec1d6eScindi 
53*7aec1d6eScindi typedef enum topo_stability {
54*7aec1d6eScindi 	TOPO_STABILITY_INTERNAL = 0,	/* private to libtopo */
55*7aec1d6eScindi 	TOPO_STABILITY_PRIVATE,		/* private to Sun */
56*7aec1d6eScindi 	TOPO_STABILITY_OBSOLETE,	/* scheduled for removal */
57*7aec1d6eScindi 	TOPO_STABILITY_EXTERNAL,	/* not controlled by Sun */
58*7aec1d6eScindi 	TOPO_STABILITY_UNSTABLE,	/* new or rapidly changing */
59*7aec1d6eScindi 	TOPO_STABILITY_EVOLVING,	/* less rapidly changing */
60*7aec1d6eScindi 	TOPO_STABILITY_STABLE,		/* mature interface from Sun */
61*7aec1d6eScindi 	TOPO_STABILITY_STANDARD,	/* industry standard */
62*7aec1d6eScindi 	TOPO_STABILITY_MAX		/* end */
63*7aec1d6eScindi } topo_stability_t;
64*7aec1d6eScindi 
65*7aec1d6eScindi #define	TOPO_STABILITY_MAX   TOPO_STABILITY_STANDARD /* max valid stability */
66*7aec1d6eScindi 
67*7aec1d6eScindi typedef enum {
68*7aec1d6eScindi 	TOPO_TYPE_INVALID = 0,
69*7aec1d6eScindi 	TOPO_TYPE_BOOLEAN,	/* boolean */
70*7aec1d6eScindi 	TOPO_TYPE_INT32,	/* int32_t */
71*7aec1d6eScindi 	TOPO_TYPE_UINT32,	/* uint32_t */
72*7aec1d6eScindi 	TOPO_TYPE_INT64,	/* int64_t */
73*7aec1d6eScindi 	TOPO_TYPE_UINT64,	/* uint64_t */
74*7aec1d6eScindi 	TOPO_TYPE_STRING,	/* const char* */
75*7aec1d6eScindi 	TOPO_TYPE_TIME,		/* uint64_t */
76*7aec1d6eScindi 	TOPO_TYPE_SIZE,		/* uint64_t */
77*7aec1d6eScindi 	TOPO_TYPE_FMRI		/* nvlist_t */
78*7aec1d6eScindi } topo_type_t;
79*7aec1d6eScindi 
80*7aec1d6eScindi typedef int (*topo_walk_cb_t)(topo_hdl_t *, tnode_t *, void *);
81*7aec1d6eScindi 
82*7aec1d6eScindi extern topo_hdl_t *topo_open(int, const char *, int *);
83*7aec1d6eScindi extern void topo_close(topo_hdl_t *);
84*7aec1d6eScindi extern char *topo_snap_hold(topo_hdl_t *, const char *, int *);
85*7aec1d6eScindi extern void topo_snap_release(topo_hdl_t *);
86*7aec1d6eScindi extern topo_walk_t *topo_walk_init(topo_hdl_t *, const char *, topo_walk_cb_t,
87*7aec1d6eScindi     void *, int *);
88*7aec1d6eScindi extern int topo_walk_step(topo_walk_t *, int);
89*7aec1d6eScindi extern void topo_walk_fini(topo_walk_t *);
90*7aec1d6eScindi 
91*7aec1d6eScindi #define	TOPO_WALK_ERR		-1
92*7aec1d6eScindi #define	TOPO_WALK_NEXT		0
93*7aec1d6eScindi #define	TOPO_WALK_TERMINATE	1
94*7aec1d6eScindi 
95*7aec1d6eScindi #define	TOPO_WALK_CHILD		0x0001
96*7aec1d6eScindi #define	TOPO_WALK_SIBLING	0x0002
97*7aec1d6eScindi 
98*7aec1d6eScindi extern int topo_fmri_present(topo_hdl_t *, nvlist_t *, int *);
99*7aec1d6eScindi extern int topo_fmri_contains(topo_hdl_t *, nvlist_t *, nvlist_t *, int *);
100*7aec1d6eScindi extern int topo_fmri_unusable(topo_hdl_t *, nvlist_t *, int *);
101*7aec1d6eScindi extern int topo_fmri_nvl2str(topo_hdl_t *, nvlist_t *, char **, int *);
102*7aec1d6eScindi extern int topo_fmri_str2nvl(topo_hdl_t *, const char *, nvlist_t **, int *);
103*7aec1d6eScindi extern int topo_fmri_asru(topo_hdl_t *, nvlist_t *, nvlist_t **, int *);
104*7aec1d6eScindi extern int topo_fmri_fru(topo_hdl_t *, nvlist_t *, nvlist_t **,
105*7aec1d6eScindi     int *);
106*7aec1d6eScindi extern int topo_fmri_compare(topo_hdl_t *, nvlist_t *, nvlist_t *, int *);
107*7aec1d6eScindi extern int topo_fmri_invoke(topo_hdl_t *, nvlist_t *, topo_walk_cb_t, void *,
108*7aec1d6eScindi     int *);
109*7aec1d6eScindi extern nvlist_t *topo_fmri_create(topo_hdl_t *, const char *, const char *,
110*7aec1d6eScindi     topo_instance_t, nvlist_t *, int *);
111*7aec1d6eScindi 
112*7aec1d6eScindi /*
113*7aec1d6eScindi  * Topo node utilities: callable from topo_walk_step() callback or module
114*7aec1d6eScindi  * enumeration, topo_mod_enumerate()
115*7aec1d6eScindi  */
116*7aec1d6eScindi extern char *topo_node_name(tnode_t *);
117*7aec1d6eScindi extern topo_instance_t topo_node_instance(tnode_t *);
118*7aec1d6eScindi extern void *topo_node_private(tnode_t *);
119*7aec1d6eScindi extern int topo_node_asru(tnode_t *, nvlist_t **, nvlist_t *, int *);
120*7aec1d6eScindi extern int topo_node_fru(tnode_t *, nvlist_t **, nvlist_t *, int *);
121*7aec1d6eScindi extern int topo_node_resource(tnode_t *, nvlist_t **, int *);
122*7aec1d6eScindi extern int topo_node_label(tnode_t *, char **, int *);
123*7aec1d6eScindi extern int topo_node_asru_set(tnode_t *node, nvlist_t *, int, int *);
124*7aec1d6eScindi extern int topo_node_fru_set(tnode_t *node, nvlist_t *, int, int *);
125*7aec1d6eScindi extern int topo_node_label_set(tnode_t *node, char *, int *);
126*7aec1d6eScindi extern int topo_method_invoke(tnode_t *node, const char *, topo_version_t,
127*7aec1d6eScindi     nvlist_t *, nvlist_t **, int *);
128*7aec1d6eScindi 
129*7aec1d6eScindi extern int topo_pgroup_create(tnode_t *, const char *, topo_stability_t, int *);
130*7aec1d6eScindi extern void topo_pgroup_destroy(tnode_t *, const char *);
131*7aec1d6eScindi extern int topo_prop_get_int32(tnode_t *, const char *, const char *,
132*7aec1d6eScindi     int32_t *, int *);
133*7aec1d6eScindi extern int topo_prop_get_uint32(tnode_t *, const char *, const char *,
134*7aec1d6eScindi     uint32_t *, int *);
135*7aec1d6eScindi extern int topo_prop_get_int64(tnode_t *, const char *, const char *,
136*7aec1d6eScindi     int64_t *, int *);
137*7aec1d6eScindi extern int topo_prop_get_uint64(tnode_t *, const char *, const char *,
138*7aec1d6eScindi     uint64_t *, int *);
139*7aec1d6eScindi extern int topo_prop_get_string(tnode_t *, const char *, const char *,
140*7aec1d6eScindi     char **, int *);
141*7aec1d6eScindi extern int topo_prop_get_fmri(tnode_t *, const char *, const char *,
142*7aec1d6eScindi     nvlist_t **, int *);
143*7aec1d6eScindi extern int topo_prop_set_int32(tnode_t *, const char *, const char *, int,
144*7aec1d6eScindi     int32_t, int *);
145*7aec1d6eScindi extern int topo_prop_set_uint32(tnode_t *, const char *, const char *, int,
146*7aec1d6eScindi     uint32_t, int *);
147*7aec1d6eScindi extern int topo_prop_set_int64(tnode_t *, const char *, const char *,
148*7aec1d6eScindi     int, int64_t, int *);
149*7aec1d6eScindi extern int topo_prop_set_uint64(tnode_t *, const char *, const char *,
150*7aec1d6eScindi     int, uint64_t, int *);
151*7aec1d6eScindi extern int topo_prop_set_string(tnode_t *, const char *, const char *,
152*7aec1d6eScindi     int, const char *, int *);
153*7aec1d6eScindi extern int topo_prop_set_fmri(tnode_t *, const char *, const char *,
154*7aec1d6eScindi     int, const nvlist_t *, int *);
155*7aec1d6eScindi extern int topo_prop_stability(tnode_t *, const char *, topo_stability_t *);
156*7aec1d6eScindi extern nvlist_t *topo_prop_get_all(topo_hdl_t *, tnode_t *);
157*7aec1d6eScindi extern int topo_prop_inherit(tnode_t *, const char *, const char *, int *);
158*7aec1d6eScindi 
159*7aec1d6eScindi #define	TOPO_PROP_SET_ONCE	0
160*7aec1d6eScindi #define	TOPO_PROP_SET_MULTIPLE	1
161*7aec1d6eScindi 
162*7aec1d6eScindi #define	TOPO_ASRU_COMPUTE	0x0001  /* Compute ASRU dynamically */
163*7aec1d6eScindi #define	TOPO_FRU_COMPUTE	0x0002  /* Compute FRU dynamically */
164*7aec1d6eScindi 
165*7aec1d6eScindi /* Protocol property group and property names */
166*7aec1d6eScindi #define	TOPO_PGROUP_PROTOCOL	"protocol"	/* Required property group */
167*7aec1d6eScindi #define	TOPO_PROP_RESOURCE	"resource"	/* resource FMRI */
168*7aec1d6eScindi #define	TOPO_PROP_ASRU		"ASRU"		/* ASRU FMRI */
169*7aec1d6eScindi #define	TOPO_PROP_FRU		"FRU"		/* FRU FMRI */
170*7aec1d6eScindi #define	TOPO_PROP_MOD		"module"	/* software module FMRI */
171*7aec1d6eScindi #define	TOPO_PROP_PKG		"package"	/* software package FMRI */
172*7aec1d6eScindi #define	TOPO_PROP_LABEL		"label"		/*  property LABEL */
173*7aec1d6eScindi 
174*7aec1d6eScindi /*
175*7aec1d6eScindi  * Legacy TOPO property group: this group supports legacy platform.topo
176*7aec1d6eScindi  * property names
177*7aec1d6eScindi  */
178*7aec1d6eScindi #define	TOPO_PGROUP_LEGACY	"legacy"	/* Legacy property group */
179*7aec1d6eScindi #define	TOPO_PROP_PLATASRU	"PLAT-ASRU"
180*7aec1d6eScindi #define	TOPO_PROP_PLATFRU	"PLAT-FRU"
181*7aec1d6eScindi 
182*7aec1d6eScindi /*
183*7aec1d6eScindi  * System property group
184*7aec1d6eScindi  */
185*7aec1d6eScindi #define	TOPO_PGROUP_SYSTEM	"system"
186*7aec1d6eScindi #define	TOPO_PROP_PLATFORM	"platform"
187*7aec1d6eScindi #define	TOPO_PROP_ISA		"isa"
188*7aec1d6eScindi #define	TOPO_PROP_MACHINE	"machine"
189*7aec1d6eScindi 
190*7aec1d6eScindi /* Property node NVL names */
191*7aec1d6eScindi #define	TOPO_PROP_GROUP		"property-group"
192*7aec1d6eScindi #define	TOPO_PROP_GROUP_NAME	"property-group-name"
193*7aec1d6eScindi #define	TOPO_PROP_VAL		"property"
194*7aec1d6eScindi #define	TOPO_PROP_VAL_NAME	"property-name"
195*7aec1d6eScindi #define	TOPO_PROP_VAL_VAL	"property-value"
196*7aec1d6eScindi 
197*7aec1d6eScindi extern const char *topo_strerror(int);
198*7aec1d6eScindi extern void topo_debug_set(topo_hdl_t *, int, char *);
199*7aec1d6eScindi extern void *topo_hdl_alloc(topo_hdl_t *, size_t);
200*7aec1d6eScindi extern void *topo_hdl_zalloc(topo_hdl_t *, size_t);
201*7aec1d6eScindi extern void topo_hdl_free(topo_hdl_t *, void *, size_t);
202*7aec1d6eScindi extern int topo_hdl_nvalloc(topo_hdl_t *, nvlist_t **, uint_t);
203*7aec1d6eScindi extern int topo_hdl_nvdup(topo_hdl_t *, nvlist_t *, nvlist_t **);
204*7aec1d6eScindi extern char *topo_hdl_strdup(topo_hdl_t *, const char *);
205*7aec1d6eScindi extern void topo_hdl_strfree(topo_hdl_t *, char *);
206*7aec1d6eScindi 
207*7aec1d6eScindi #define	TOPO_DBG_ERR	0x0001	/* enable error handling debug messages */
208*7aec1d6eScindi #define	TOPO_DBG_MOD	0x0002	/* enable module subsystem debug messages */
209*7aec1d6eScindi #define	TOPO_DBG_LOG	0x0004	/* enable log subsystem debug messages */
210*7aec1d6eScindi #define	TOPO_DBG_WALK	0x0008	/* enable walker subsystem debug messages */
211*7aec1d6eScindi #define	TOPO_DBG_TREE	0x0010	/* enable tree subsystem debug messages */
212*7aec1d6eScindi #define	TOPO_DBG_ALL	0xffff	/* enable all debug modes */
213*7aec1d6eScindi 
214*7aec1d6eScindi #ifdef __cplusplus
215*7aec1d6eScindi }
216*7aec1d6eScindi #endif
217*7aec1d6eScindi 
218*7aec1d6eScindi #endif /* _LIBTOPO_H */
219