xref: /illumos-gate/usr/src/lib/fm/topo/libtopo/common/topo_mod.h (revision a07094369b21309434206d9b3601d162693466fc)
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 _TOPO_MOD_H
28 #define	_TOPO_MOD_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <fm/libtopo.h>
33 #include <libnvpair.h>
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 /*
40  * Enumerator and method supplier module API
41  */
42 typedef struct topo_mod topo_mod_t;
43 
44 typedef int topo_method_f(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *,
45     nvlist_t **);
46 typedef int topo_enum_f(topo_mod_t *, tnode_t *, const char *, topo_instance_t,
47     topo_instance_t, void *);
48 typedef void topo_release_f(topo_mod_t *, tnode_t *);
49 
50 typedef struct topo_method {
51 	const char *tm_name;			/* Method name */
52 	const char *tm_desc;			/* Method description */
53 	const topo_version_t tm_version;	/* Method version */
54 	const topo_stability_t tm_stability;	/* Attributes of method */
55 	topo_method_f *tm_func;			/* Method function */
56 } topo_method_t;
57 
58 typedef struct topo_mod_info {
59 	char *tmi_desc;			/* Client module description */
60 	topo_version_t tmi_version;	/* Client module version */
61 	topo_enum_f *tmi_enum;		/* enumerator function */
62 	topo_release_f *tmi_release;	/* de-enumerator function */
63 } topo_modinfo_t;
64 
65 extern topo_mod_t *topo_mod_load(topo_mod_t *, const char *);
66 extern void topo_mod_unload(topo_mod_t *);
67 extern int topo_mod_register(topo_mod_t *, const topo_modinfo_t *, void *);
68 extern void topo_mod_unregister(topo_mod_t *);
69 extern int topo_mod_enumerate(topo_mod_t *, tnode_t *, const char *,
70     const char *, topo_instance_t, topo_instance_t);
71 extern void topo_mod_release(topo_mod_t *, tnode_t *);
72 extern char *topo_mod_rootdir(topo_mod_t *);
73 extern void *topo_mod_private(topo_mod_t *);
74 extern topo_hdl_t *topo_mod_handle(topo_mod_t *);
75 
76 extern int topo_method_register(topo_mod_t *, tnode_t *, const topo_method_t *);
77 extern void topo_method_unregister(topo_mod_t *, tnode_t *, const char *);
78 extern void topo_method_unregister_all(topo_mod_t *, tnode_t *);
79 
80 /*
81  * FMRI methods
82  */
83 #define	TOPO_METH_ASRU_COMPUTE		"topo_asru_compute"
84 #define	TOPO_METH_FRU_COMPUTE		"topo_fru_compute"
85 #define	TOPO_METH_FMRI			"topo_fmri"
86 #define	TOPO_METH_LABEL			"topo_label"
87 #define	TOPO_METH_NVL2STR		"topo_nvl2str"
88 #define	TOPO_METH_STR2NVL		"topo_str2nvl"
89 #define	TOPO_METH_PRESENT		"topo_present"
90 #define	TOPO_METH_CONTAINS		"topo_contains"
91 #define	TOPO_METH_UNUSABLE		"topo_unusable"
92 #define	TOPO_METH_EXPAND		"topo_expand"
93 #define	TOPO_METH_COMPARE		"topo_compare"
94 
95 #define	TOPO_METH_FMRI_VERSION			0
96 #define	TOPO_METH_LABEL_VERSION			0
97 #define	TOPO_METH_FRU_COMPUTE_VERSION		0
98 #define	TOPO_METH_ASRU_COMPUTE_VERSION		0
99 #define	TOPO_METH_NVL2STR_VERSION		0
100 #define	TOPO_METH_STR2NVL_VERSION		0
101 #define	TOPO_METH_PRESENT_VERSION		0
102 #define	TOPO_METH_CONTAINS_VERSION		0
103 #define	TOPO_METH_UNUSABLE_VERSION		0
104 #define	TOPO_METH_EXPAND_VERSION		0
105 #define	TOPO_METH_COMPARE_VERSION		0
106 
107 #define	TOPO_METH_ASRU_COMPUTE_DESC		"Dynamic ASRU constructor"
108 #define	TOPO_METH_FRU_COMPUTE_DESC		"Dynamic FRU constructor"
109 #define	TOPO_METH_FMRI_DESC			"Dynamic FMRI constructor"
110 #define	TOPO_METH_LABEL_DESC			"Dynamic label discovery"
111 #define	TOPO_METH_NVL2STR_DESC			"FMRI to string"
112 #define	TOPO_METH_STR2NVL_DESC			"string to FMRI"
113 #define	TOPO_METH_PRESENT_DESC			"FMRI is present"
114 #define	TOPO_METH_CONTAINS_DESC			"FMRI contains sub-FMRI"
115 #define	TOPO_METH_UNUSABLE_DESC			"FMRI is unusable"
116 #define	TOPO_METH_EXPAND_DESC			"expand FMRI"
117 #define	TOPO_METH_COMPARE_DESC			"compare two FMRIs"
118 
119 #define	TOPO_METH_FMRI_ARG_NAME		"child-name"
120 #define	TOPO_METH_FMRI_ARG_INST		"child-inst"
121 #define	TOPO_METH_FMRI_ARG_NVL		"args"
122 #define	TOPO_METH_FMRI_ARG_PARENT	"parent-fmri"
123 #define	TOPO_METH_FMRI_ARG_AUTH		"auth"
124 #define	TOPO_METH_FMRI_ARG_PART		"part"
125 #define	TOPO_METH_FMRI_ARG_REV		"rev"
126 #define	TOPO_METH_FMRI_ARG_SER		"serial"
127 
128 #define	TOPO_METH_LABEL_ARG_NVL		"label-private"
129 #define	TOPO_METH_LABEL_RET_STR		"label-string"
130 
131 extern void *topo_mod_alloc(topo_mod_t *, size_t);
132 extern void *topo_mod_zalloc(topo_mod_t *, size_t);
133 extern void topo_mod_free(topo_mod_t *, void *, size_t);
134 extern char *topo_mod_strdup(topo_mod_t *, const char *);
135 extern void topo_mod_strfree(topo_mod_t *, char *);
136 extern int topo_mod_nvalloc(topo_mod_t *, nvlist_t **, uint_t);
137 extern int topo_mod_nvdup(topo_mod_t *, nvlist_t *, nvlist_t **);
138 
139 extern void topo_mod_clrdebug(topo_mod_t *);
140 extern void topo_mod_setdebug(topo_mod_t *, int);
141 extern void topo_mod_dprintf(topo_mod_t *, const char *, ...);
142 extern const char *topo_mod_errmsg(topo_mod_t *);
143 extern int topo_mod_errno(topo_mod_t *);
144 
145 /*
146  * Topo node utilities: callable from module enumeration, topo_mod_enumerate()
147  */
148 extern int topo_node_range_create(topo_mod_t *, tnode_t *, const char *,
149     topo_instance_t, topo_instance_t);
150 extern void topo_node_range_destroy(tnode_t *, const char *);
151 extern tnode_t *topo_node_bind(topo_mod_t *, tnode_t *, const char *,
152     topo_instance_t, nvlist_t *, void *);
153 extern void topo_node_unbind(tnode_t *);
154 
155 /*
156  * This enum definition is used to define a set of error tags associated with
157  * the fmd daemon's various error conditions.  The shell script mkerror.sh is
158  * used to parse this file and create a corresponding topo_error.c source file.
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_mod_errno {
163     EMOD_UNKNOWN = 2000, /* unknown libtopo error */
164     EMOD_NOMEM,			/* module memory limit exceeded */
165     EMOD_PARTIAL_ENUM,		/* module completed partial enumeration */
166     EMOD_METHOD_INVAL,		/* method arguments invalid */
167     EMOD_METHOD_NOTSUP,		/* method not supported */
168     EMOD_FMRI_NVL,		/* nvlist allocation failure for FMRI */
169     EMOD_FMRI_VERSION,		/* invalid FMRI scheme version */
170     EMOD_FMRI_MALFORM,		/* malformed FMRI */
171     EMOD_VER_OLD,		/* module compiled using an obsolete topo ABI */
172     EMOD_VER_NEW,		/* module is compiled using a newer topo ABI */
173     EMOD_NVL_INVAL,		/* invalid nvlist */
174     EMOD_NONCANON,		/* non-canonical component name requested */
175     EMOD_END			/* end of mod errno list (to ease auto-merge) */
176 } topo_mod_errno_t;
177 
178 extern int topo_mod_seterrno(topo_mod_t *, int);
179 
180 #ifdef	__cplusplus
181 }
182 #endif
183 
184 #endif	/* _TOPO_MOD_H */
185