1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Copyright 2020 Joyent, Inc.
*/
#ifndef _TOPO_MOD_H
#define _TOPO_MOD_H
#include <fm/libtopo.h>
#include <fm/topo_hc.h>
#include <libipmi.h>
#include <libnvpair.h>
#include <libdevinfo.h>
#include <smbios.h>
#include <pcidb.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Enumerator and method supplier module API
*/
typedef struct topo_mod topo_mod_t;
typedef int topo_method_f(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *,
nvlist_t **);
typedef int topo_enum_f(topo_mod_t *, tnode_t *, const char *, topo_instance_t,
topo_instance_t, void *, void *);
typedef void topo_release_f(topo_mod_t *, tnode_t *);
typedef struct topo_method {
const char *tm_name; /* Method name */
const char *tm_desc; /* Method description */
const topo_version_t tm_version; /* Method version */
const topo_stability_t tm_stability; /* Attributes of method */
topo_method_f *tm_func; /* Method function */
} topo_method_t;
typedef struct topo_modops {
topo_enum_f *tmo_enum; /* enumeration op */
topo_release_f *tmo_release; /* resource release op */
} topo_modops_t;
typedef struct topo_mod_info {
const char *tmi_desc; /* module description */
const char *tmi_scheme; /* enumeration scheme type */
topo_version_t tmi_version; /* module version */
const topo_modops_t *tmi_ops; /* module ops vector */
} topo_modinfo_t;
extern topo_mod_t *topo_mod_load(topo_mod_t *, const char *, topo_version_t);
extern void topo_mod_unload(topo_mod_t *);
extern int topo_mod_register(topo_mod_t *, const topo_modinfo_t *,
topo_version_t);
extern void topo_mod_unregister(topo_mod_t *);
extern int topo_mod_enumerate(topo_mod_t *, tnode_t *, const char *,
const char *, topo_instance_t, topo_instance_t, void *);
extern int topo_mod_enummap(topo_mod_t *mod, tnode_t *, const char *,
const char *);
extern char *topo_mod_product(topo_mod_t *);
extern void topo_mod_release(topo_mod_t *, tnode_t *);
extern void topo_mod_setspecific(topo_mod_t *, void *);
extern void *topo_mod_getspecific(topo_mod_t *);
extern nvlist_t *topo_mod_cpufmri(topo_mod_t *, int, uint32_t, uint8_t,
const char *);
extern nvlist_t *topo_mod_devfmri(topo_mod_t *, int, const char *,
const char *);
extern nvlist_t *topo_mod_hcfmri(topo_mod_t *, tnode_t *, int, const char *,
topo_instance_t, nvlist_t *, nvlist_t *, const char *, const char *,
const char *);
extern nvlist_t *topo_mod_memfmri(topo_mod_t *, int, uint64_t, uint64_t,
const char *, int);
extern nvlist_t *topo_mod_modfmri(topo_mod_t *, int, const char *);
extern nvlist_t *topo_mod_pkgfmri(topo_mod_t *, int, const char *);
extern nvlist_t *topo_mod_swfmri(topo_mod_t *, int,
char *, char *, nvlist_t *,
char *, char *, char *, char *, int64_t,
char *, char *, int64_t, char *, int64_t, char **, uint_t);
extern int topo_mod_nvl2str(topo_mod_t *, nvlist_t *, char **);
extern int topo_mod_str2nvl(topo_mod_t *, const char *, nvlist_t **);
extern int topo_prop_setmutable(tnode_t *node, const char *pgname,
const char *pname, int *err);
extern int topo_prop_setnonvolatile(tnode_t *node, const char *pgname,
const char *pname, int *err);
/*
* Snapshot walker support
*/
typedef int (*topo_mod_walk_cb_t)(topo_mod_t *, tnode_t *, void *);
extern topo_walk_t *topo_mod_walk_init(topo_mod_t *, tnode_t *,
topo_mod_walk_cb_t, void *, int *);
/*
* Flags for topo_mod_memfmri
*/
#define TOPO_MEMFMRI_PA 0x0001 /* Valid physical address */
#define TOPO_MEMFMRI_OFFSET 0x0002 /* Valid offset */
extern int topo_method_register(topo_mod_t *, tnode_t *, const topo_method_t *);
extern void topo_method_unregister(topo_mod_t *, tnode_t *, const char *);
extern void topo_method_unregister_all(topo_mod_t *, tnode_t *);
extern di_node_t topo_mod_devinfo(topo_mod_t *);
extern ipmi_handle_t *topo_mod_ipmi_hold(topo_mod_t *);
extern void topo_mod_ipmi_rele(topo_mod_t *);
extern smbios_hdl_t *topo_mod_smbios(topo_mod_t *);
extern pcidb_hdl_t *topo_mod_pcidb(topo_mod_t *);
extern di_prom_handle_t topo_mod_prominfo(topo_mod_t *);
extern nvlist_t *topo_mod_auth(topo_mod_t *, tnode_t *);
extern int topo_method_sensor_failure(topo_mod_t *, tnode_t *, topo_version_t,
nvlist_t *, nvlist_t **);
/*
* FMRI methods
*/
#define TOPO_METH_LABEL "topo_label"
#define TOPO_METH_LABEL_DESC "label constructor"
#define TOPO_METH_LABEL_VERSION0 0
#define TOPO_METH_LABEL_VERSION TOPO_METH_LABEL_VERSION0
#define TOPO_METH_LABEL_ARG_NVL "label-specific"
#define TOPO_METH_LABEL_RET_STR "label-string"
#define TOPO_METH_PRESENT "topo_present"
#define TOPO_METH_PRESENT_DESC "presence indicator"
#define TOPO_METH_PRESENT_VERSION0 0
#define TOPO_METH_PRESENT_VERSION TOPO_METH_PRESENT_VERSION0
#define TOPO_METH_PRESENT_RET "present-ret"
#define TOPO_METH_REPLACED "topo_replaced"
#define TOPO_METH_REPLACED_DESC "replaced indicator"
#define TOPO_METH_REPLACED_VERSION0 0
#define TOPO_METH_REPLACED_VERSION TOPO_METH_REPLACED_VERSION0
#define TOPO_METH_REPLACED_RET "replaced-ret"
#define TOPO_METH_UNUSABLE "topo_unusable"
#define TOPO_METH_UNUSABLE_DESC "unusable indicator"
#define TOPO_METH_UNUSABLE_VERSION0 0
#define TOPO_METH_UNUSABLE_VERSION TOPO_METH_UNUSABLE_VERSION0
#define TOPO_METH_UNUSABLE_RET "unusable-ret"
#define TOPO_METH_SERVICE_STATE "topo_service_state"
#define TOPO_METH_SERVICE_STATE_DESC "service_state indicator"
#define TOPO_METH_SERVICE_STATE_VERSION0 0
#define TOPO_METH_SERVICE_STATE_VERSION TOPO_METH_SERVICE_STATE_VERSION0
#define TOPO_METH_SERVICE_STATE_RET "service_state-ret"
#define TOPO_METH_RETIRE "topo_retire"
#define TOPO_METH_RETIRE_DESC "retire action"
#define TOPO_METH_RETIRE_VERSION0 0
#define TOPO_METH_RETIRE_VERSION TOPO_METH_RETIRE_VERSION0
#define TOPO_METH_RETIRE_RET "retire-ret"
#define TOPO_METH_UNRETIRE "topo_unretire"
#define TOPO_METH_UNRETIRE_DESC "unretire action"
#define TOPO_METH_UNRETIRE_VERSION0 0
#define TOPO_METH_UNRETIRE_VERSION TOPO_METH_UNRETIRE_VERSION0
#define TOPO_METH_UNRETIRE_RET "unretire-ret"
#define TOPO_METH_EXPAND "topo_expand"
#define TOPO_METH_EXPAND_DESC "expand FMRI"
#define TOPO_METH_EXPAND_VERSION0 0
#define TOPO_METH_EXPAND_VERSION TOPO_METH_EXPAND_VERSION0
#define TOPO_METH_CONTAINS "topo_contains"
#define TOPO_METH_CONTAINS_DESC "FMRI contains sub-FMRI"
#define TOPO_METH_CONTAINS_VERSION0 0
#define TOPO_METH_CONTAINS_VERSION TOPO_METH_CONTAINS_VERSION0
#define TOPO_METH_CONTAINS_RET "contains-return"
#define TOPO_METH_FMRI_ARG_FMRI "fmri"
#define TOPO_METH_FMRI_ARG_SUBFMRI "sub-fmri"
#define TOPO_METH_ASRU_COMPUTE "topo_asru_compute"
#define TOPO_METH_ASRU_COMPUTE_VERSION 0
#define TOPO_METH_ASRU_COMPUTE_DESC "Dynamic ASRU constructor"
#define TOPO_METH_FRU_COMPUTE "topo_fru_compute"
#define TOPO_METH_FRU_COMPUTE_VERSION 0
#define TOPO_METH_FRU_COMPUTE_DESC "Dynamic FRU constructor"
#define TOPO_METH_DISK_STATUS "topo_disk_status"
#define TOPO_METH_DISK_STATUS_VERSION 0
#define TOPO_METH_DISK_STATUS_DESC "Disk status"
#define TOPO_METH_SENSOR_FAILURE "topo_sensor_failure"
#define TOPO_METH_SENSOR_FAILURE_VERSION 0
#define TOPO_METH_SENSOR_FAILURE_DESC "Sensor failure state"
#define TOPO_PROP_METH_DESC "Dynamic Property method"
#define TOPO_METH_IPMI_ENTITY "ipmi_entity"
#define TOPO_METH_FAC_ENUM_DESC "Facility Enumerator"
extern void *topo_mod_alloc(topo_mod_t *, size_t);
extern void *topo_mod_zalloc(topo_mod_t *, size_t);
extern void topo_mod_free(topo_mod_t *, void *, size_t);
extern char *topo_mod_strdup(topo_mod_t *, const char *);
extern void topo_mod_strfree(topo_mod_t *, char *);
extern void topo_mod_strfreev(topo_mod_t *, char **, uint_t);
extern int topo_mod_nvalloc(topo_mod_t *, nvlist_t **, uint_t);
extern int topo_mod_nvdup(topo_mod_t *, nvlist_t *, nvlist_t **);
extern void topo_mod_clrdebug(topo_mod_t *);
extern void topo_mod_setdebug(topo_mod_t *);
extern void topo_mod_dprintf(topo_mod_t *, const char *, ...);
extern const char *topo_mod_errmsg(topo_mod_t *);
extern int topo_mod_errno(topo_mod_t *);
extern char *topo_mod_clean_str(topo_mod_t *, const char *);
/*
* Topo node utilities: callable from module enumeration, topo_mod_enumerate()
*/
extern int topo_node_range_create(topo_mod_t *, tnode_t *, const char *,
topo_instance_t, topo_instance_t);
extern void topo_node_range_destroy(tnode_t *, const char *);
extern tnode_t *topo_node_bind(topo_mod_t *, tnode_t *, const char *,
topo_instance_t, nvlist_t *);
extern tnode_t *topo_node_facbind(topo_mod_t *, tnode_t *, const char *,
const char *);
extern void topo_node_unbind(tnode_t *);
extern void topo_node_setspecific(tnode_t *, void *);
extern void *topo_node_getspecific(tnode_t *);
extern int topo_node_asru_set(tnode_t *node, nvlist_t *, int, int *);
extern int topo_node_fru_set(tnode_t *node, nvlist_t *, int, int *);
extern int topo_node_label_set(tnode_t *node, const char *, int *);
#define TOPO_ASRU_COMPUTE 0x0001 /* Compute ASRU dynamically */
#define TOPO_FRU_COMPUTE 0x0002 /* Compute FRU dynamically */
extern int topo_prop_inherit(tnode_t *, const char *, const char *, int *);
extern int topo_pgroup_create(tnode_t *, const topo_pgroup_info_t *, int *);
/*
* Topo property method registration
*/
extern int topo_prop_method_register(tnode_t *, const char *, const char *,
topo_type_t, const char *, const nvlist_t *, int *);
extern void topo_prop_method_unregister(tnode_t *, const char *, const char *);
extern tnode_t *topo_mod_create_ufm(topo_mod_t *, tnode_t *, const char *,
topo_ufm_slot_info_t *);
extern tnode_t *topo_mod_create_ufm_slot(topo_mod_t *, tnode_t *,
topo_ufm_slot_info_t *);
/*
* This enum definition is used to define a set of error tags associated with
* the module api error conditions. The shell script mkerror.sh is
* used to parse this file and create a corresponding topo_error.c source file.
* If you do something other than add a new error tag here, you may need to
* update the mkerror shell script as it is based upon simple regexps.
*/
typedef enum topo_mod_errno {
EMOD_UNKNOWN = 2000, /* unknown libtopo error */
EMOD_NOMEM, /* module memory limit exceeded */
EMOD_PARTIAL_ENUM, /* module completed partial enumeration */
EMOD_METHOD_INVAL, /* method arguments invalid */
EMOD_METHOD_NOTSUP, /* method not supported */
EMOD_FMRI_NVL, /* nvlist allocation failure for FMRI */
EMOD_FMRI_VERSION, /* invalid FMRI scheme version */
EMOD_FMRI_MALFORM, /* malformed FMRI */
EMOD_NODE_BOUND, /* node already bound */
EMOD_NODE_DUP, /* duplicate node */
EMOD_NODE_NOENT, /* node not found */
EMOD_NODE_RANGE, /* invalid node range */
EMOD_VER_ABI, /* registered with invalid ABI version */
EMOD_VER_OLD, /* attempt to load obsolete module */
EMOD_VER_NEW, /* attempt to load a newer module */
EMOD_NVL_INVAL, /* invalid nvlist */
EMOD_NONCANON, /* non-canonical component name requested */
EMOD_MOD_NOENT, /* module lookup failed */
EMOD_UKNOWN_ENUM, /* unknown enumeration error */
EMOD_DIGRAPH_MAXSZ, /* max digraph size exceeded */
EMOD_END /* end of mod errno list (to ease auto-merge) */
} topo_mod_errno_t;
extern int topo_mod_seterrno(topo_mod_t *, int);
/*
* Function used by a module to try and open a file based on FM's search path.
*/
extern int topo_mod_file_search(topo_mod_t *, const char *file, int oflags);
extern topo_method_f topo_mod_hc_occupied;
/*
* Directed Graph topology interfaces
*/
extern topo_digraph_t *topo_digraph_new(topo_hdl_t *, topo_mod_t *,
const char *);
extern void topo_digraph_destroy(topo_digraph_t *);
extern topo_vertex_t *topo_vertex_new(topo_mod_t *, const char *,
topo_instance_t);
extern void topo_vertex_destroy(topo_mod_t *mod, topo_vertex_t *vtx);
extern int topo_edge_new(topo_mod_t *, topo_vertex_t *, topo_vertex_t *);
#ifdef __cplusplus
}
#endif
#endif /* _TOPO_MOD_H */
|