xref: /illumos-gate/usr/src/lib/fm/topo/libtopo/common/topo_mod.h (revision 6d65bee7bcc62b2d9bdfde6610561ce76c92a908)
17aec1d6eScindi /*
27aec1d6eScindi  * CDDL HEADER START
37aec1d6eScindi  *
47aec1d6eScindi  * The contents of this file are subject to the terms of the
57aec1d6eScindi  * Common Development and Distribution License (the "License").
67aec1d6eScindi  * You may not use this file except in compliance with the License.
77aec1d6eScindi  *
87aec1d6eScindi  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97aec1d6eScindi  * or http://www.opensolaris.org/os/licensing.
107aec1d6eScindi  * See the License for the specific language governing permissions
117aec1d6eScindi  * and limitations under the License.
127aec1d6eScindi  *
137aec1d6eScindi  * When distributing Covered Code, include this CDDL HEADER in each
147aec1d6eScindi  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157aec1d6eScindi  * If applicable, add the following below this CDDL HEADER, with the
167aec1d6eScindi  * fields enclosed by brackets "[]" replaced with your own identifying
177aec1d6eScindi  * information: Portions Copyright [yyyy] [name of copyright owner]
187aec1d6eScindi  *
197aec1d6eScindi  * CDDL HEADER END
207aec1d6eScindi  */
217aec1d6eScindi 
227aec1d6eScindi /*
23f6e214c7SGavin Maltby  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
247aec1d6eScindi  */
25*6d65bee7SRob Johnston /*
26*6d65bee7SRob Johnston  * Copyright (c) 2018, Joyent, Inc. All rights reserved.
27*6d65bee7SRob Johnston  */
287aec1d6eScindi 
297aec1d6eScindi #ifndef _TOPO_MOD_H
307aec1d6eScindi #define	_TOPO_MOD_H
317aec1d6eScindi 
327aec1d6eScindi #include <fm/libtopo.h>
330eb822a1Scindi #include <fm/topo_hc.h>
342eeaed14Srobj #include <libipmi.h>
357aec1d6eScindi #include <libnvpair.h>
360eb822a1Scindi #include <libdevinfo.h>
37738c43b5SEric Schrock #include <smbios.h>
3866d05358SRob Johnston #include <pcidb.h>
397aec1d6eScindi 
407aec1d6eScindi #ifdef __cplusplus
417aec1d6eScindi extern "C" {
427aec1d6eScindi #endif
437aec1d6eScindi 
447aec1d6eScindi /*
457aec1d6eScindi  * Enumerator and method supplier module API
467aec1d6eScindi  */
477aec1d6eScindi typedef struct topo_mod topo_mod_t;
487aec1d6eScindi 
497aec1d6eScindi typedef int topo_method_f(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *,
507aec1d6eScindi     nvlist_t **);
517aec1d6eScindi typedef int topo_enum_f(topo_mod_t *, tnode_t *, const char *, topo_instance_t,
520eb822a1Scindi     topo_instance_t, void *, void *);
537aec1d6eScindi typedef void topo_release_f(topo_mod_t *, tnode_t *);
547aec1d6eScindi 
557aec1d6eScindi typedef struct topo_method {
567aec1d6eScindi 	const char *tm_name;			/* Method name */
577aec1d6eScindi 	const char *tm_desc;			/* Method description */
587aec1d6eScindi 	const topo_version_t tm_version;	/* Method version */
597aec1d6eScindi 	const topo_stability_t tm_stability;	/* Attributes of method */
607aec1d6eScindi 	topo_method_f *tm_func;			/* Method function */
617aec1d6eScindi } topo_method_t;
627aec1d6eScindi 
630eb822a1Scindi typedef struct topo_modops {
640eb822a1Scindi 	topo_enum_f *tmo_enum;		/* enumeration op */
650eb822a1Scindi 	topo_release_f *tmo_release;	/* resource release op */
660eb822a1Scindi } topo_modops_t;
670eb822a1Scindi 
687aec1d6eScindi typedef struct topo_mod_info {
690eb822a1Scindi 	const char *tmi_desc;		/* module description */
700eb822a1Scindi 	const char *tmi_scheme;		/* enumeration scheme type  */
710eb822a1Scindi 	topo_version_t tmi_version;	/* module version */
720eb822a1Scindi 	const topo_modops_t *tmi_ops;	/* module ops vector */
737aec1d6eScindi } topo_modinfo_t;
747aec1d6eScindi 
750eb822a1Scindi extern topo_mod_t *topo_mod_load(topo_mod_t *, const char *, topo_version_t);
767aec1d6eScindi extern void topo_mod_unload(topo_mod_t *);
770eb822a1Scindi extern int topo_mod_register(topo_mod_t *, const topo_modinfo_t *,
780eb822a1Scindi     topo_version_t);
797aec1d6eScindi extern void topo_mod_unregister(topo_mod_t *);
807aec1d6eScindi extern int topo_mod_enumerate(topo_mod_t *, tnode_t *, const char *,
810eb822a1Scindi     const char *, topo_instance_t, topo_instance_t, void *);
820eb822a1Scindi extern int topo_mod_enummap(topo_mod_t *mod, tnode_t *, const char *,
830eb822a1Scindi     const char *);
847aec1d6eScindi extern void topo_mod_release(topo_mod_t *, tnode_t *);
850eb822a1Scindi extern void topo_mod_setspecific(topo_mod_t *, void *);
860eb822a1Scindi extern void *topo_mod_getspecific(topo_mod_t *);
870eb822a1Scindi 
880eb822a1Scindi extern nvlist_t *topo_mod_cpufmri(topo_mod_t *, int, uint32_t, uint8_t,
890eb822a1Scindi     const char *);
900eb822a1Scindi extern nvlist_t *topo_mod_devfmri(topo_mod_t *, int, const char *,
910eb822a1Scindi     const char *);
920eb822a1Scindi extern nvlist_t *topo_mod_hcfmri(topo_mod_t *, tnode_t *, int, const char *,
930eb822a1Scindi     topo_instance_t, nvlist_t *, nvlist_t *, const char *, const char *,
940eb822a1Scindi     const char *);
950eb822a1Scindi extern nvlist_t *topo_mod_memfmri(topo_mod_t *, int, uint64_t, uint64_t,
960eb822a1Scindi     const char *, int);
970eb822a1Scindi extern nvlist_t *topo_mod_modfmri(topo_mod_t *, int, const char *);
980eb822a1Scindi extern nvlist_t *topo_mod_pkgfmri(topo_mod_t *, int, const char *);
99f6e214c7SGavin Maltby extern nvlist_t *topo_mod_swfmri(topo_mod_t *, int,
100f6e214c7SGavin Maltby     char *, char *, nvlist_t *,
101f6e214c7SGavin Maltby     char *, char *, char *, char *, int64_t,
102f6e214c7SGavin Maltby     char *, char *, int64_t, char *, int64_t, char **, uint_t);
1030eb822a1Scindi extern int topo_mod_nvl2str(topo_mod_t *, nvlist_t *, char **);
1040eb822a1Scindi extern int topo_mod_str2nvl(topo_mod_t *, const char *,  nvlist_t **);
105825ba0f2Srobj extern int topo_prop_setmutable(tnode_t *node, const char *pgname,
106825ba0f2Srobj     const char *pname, int *err);
107e5dcf7beSRobert Johnston extern int topo_prop_setnonvolatile(tnode_t *node, const char *pgname,
108e5dcf7beSRobert Johnston     const char *pname, int *err);
109c40d7343Scindi /*
110c40d7343Scindi  * Snapshot walker support
111c40d7343Scindi  */
112c40d7343Scindi typedef int (*topo_mod_walk_cb_t)(topo_mod_t *, tnode_t *, void *);
113c40d7343Scindi 
114c40d7343Scindi extern topo_walk_t *topo_mod_walk_init(topo_mod_t *, tnode_t *,
115c40d7343Scindi     topo_mod_walk_cb_t, void *, int *);
116c40d7343Scindi 
1170eb822a1Scindi /*
1180eb822a1Scindi  * Flags for topo_mod_memfmri
1190eb822a1Scindi  */
1200eb822a1Scindi #define	TOPO_MEMFMRI_PA		0x0001	/* Valid physical address */
1210eb822a1Scindi #define	TOPO_MEMFMRI_OFFSET	0x0002	/* Valid offset */
1227aec1d6eScindi 
1237aec1d6eScindi extern int topo_method_register(topo_mod_t *, tnode_t *, const topo_method_t *);
1247aec1d6eScindi extern void topo_method_unregister(topo_mod_t *, tnode_t *, const char *);
1257aec1d6eScindi extern void topo_method_unregister_all(topo_mod_t *, tnode_t *);
1267aec1d6eScindi 
1270eb822a1Scindi extern di_node_t topo_mod_devinfo(topo_mod_t *);
1280b1b4412SEric Schrock extern ipmi_handle_t *topo_mod_ipmi_hold(topo_mod_t *);
1290b1b4412SEric Schrock extern void topo_mod_ipmi_rele(topo_mod_t *);
130738c43b5SEric Schrock extern smbios_hdl_t *topo_mod_smbios(topo_mod_t *);
13166d05358SRob Johnston extern pcidb_hdl_t *topo_mod_pcidb(topo_mod_t *);
1320eb822a1Scindi extern di_prom_handle_t topo_mod_prominfo(topo_mod_t *);
1330eb822a1Scindi extern nvlist_t *topo_mod_auth(topo_mod_t *, tnode_t *);
1340eb822a1Scindi 
135e5dcf7beSRobert Johnston extern int topo_method_sensor_failure(topo_mod_t *, tnode_t *, topo_version_t,
136e5dcf7beSRobert Johnston     nvlist_t *, nvlist_t **);
137e5dcf7beSRobert Johnston 
1387aec1d6eScindi /*
1397aec1d6eScindi  * FMRI methods
1407aec1d6eScindi  */
1417aec1d6eScindi #define	TOPO_METH_LABEL			"topo_label"
142c40d7343Scindi #define	TOPO_METH_LABEL_DESC		"label constructor"
1430eb822a1Scindi #define	TOPO_METH_LABEL_VERSION0	0
1440eb822a1Scindi #define	TOPO_METH_LABEL_VERSION		TOPO_METH_LABEL_VERSION0
145825ba0f2Srobj #define	TOPO_METH_LABEL_ARG_NVL		"label-specific"
146825ba0f2Srobj #define	TOPO_METH_LABEL_RET_STR		"label-string"
1470eb822a1Scindi 
1487aec1d6eScindi #define	TOPO_METH_PRESENT		"topo_present"
149c40d7343Scindi #define	TOPO_METH_PRESENT_DESC		"presence indicator"
1500eb822a1Scindi #define	TOPO_METH_PRESENT_VERSION0	0
1510eb822a1Scindi #define	TOPO_METH_PRESENT_VERSION	TOPO_METH_PRESENT_VERSION0
1520eb822a1Scindi #define	TOPO_METH_PRESENT_RET		"present-ret"
1530eb822a1Scindi 
15425c6ff4bSstephh #define	TOPO_METH_REPLACED		"topo_replaced"
15525c6ff4bSstephh #define	TOPO_METH_REPLACED_DESC		"replaced indicator"
15625c6ff4bSstephh #define	TOPO_METH_REPLACED_VERSION0	0
15725c6ff4bSstephh #define	TOPO_METH_REPLACED_VERSION	TOPO_METH_REPLACED_VERSION0
15825c6ff4bSstephh #define	TOPO_METH_REPLACED_RET		"replaced-ret"
15925c6ff4bSstephh 
160dd566498Svn #define	TOPO_METH_UNUSABLE		"topo_unusable"
161c40d7343Scindi #define	TOPO_METH_UNUSABLE_DESC		"unusable indicator"
162dd566498Svn #define	TOPO_METH_UNUSABLE_VERSION0	0
163dd566498Svn #define	TOPO_METH_UNUSABLE_VERSION	TOPO_METH_UNUSABLE_VERSION0
164dd566498Svn #define	TOPO_METH_UNUSABLE_RET		"unusable-ret"
165dd566498Svn 
16625c6ff4bSstephh #define	TOPO_METH_SERVICE_STATE		"topo_service_state"
16725c6ff4bSstephh #define	TOPO_METH_SERVICE_STATE_DESC	"service_state indicator"
16825c6ff4bSstephh #define	TOPO_METH_SERVICE_STATE_VERSION0	0
16925c6ff4bSstephh #define	TOPO_METH_SERVICE_STATE_VERSION	TOPO_METH_SERVICE_STATE_VERSION0
17025c6ff4bSstephh #define	TOPO_METH_SERVICE_STATE_RET	"service_state-ret"
17125c6ff4bSstephh 
172e4b86885SCheng Sean Ye #define	TOPO_METH_RETIRE		"topo_retire"
173e4b86885SCheng Sean Ye #define	TOPO_METH_RETIRE_DESC		"retire action"
174e4b86885SCheng Sean Ye #define	TOPO_METH_RETIRE_VERSION0	0
175e4b86885SCheng Sean Ye #define	TOPO_METH_RETIRE_VERSION	TOPO_METH_RETIRE_VERSION0
176e4b86885SCheng Sean Ye #define	TOPO_METH_RETIRE_RET		"retire-ret"
177e4b86885SCheng Sean Ye 
178e4b86885SCheng Sean Ye #define	TOPO_METH_UNRETIRE		"topo_unretire"
179e4b86885SCheng Sean Ye #define	TOPO_METH_UNRETIRE_DESC		"unretire action"
180e4b86885SCheng Sean Ye #define	TOPO_METH_UNRETIRE_VERSION0	0
181e4b86885SCheng Sean Ye #define	TOPO_METH_UNRETIRE_VERSION	TOPO_METH_UNRETIRE_VERSION0
182e4b86885SCheng Sean Ye #define	TOPO_METH_UNRETIRE_RET		"unretire-ret"
183e4b86885SCheng Sean Ye 
184dd566498Svn #define	TOPO_METH_EXPAND		"topo_expand"
185dd566498Svn #define	TOPO_METH_EXPAND_DESC		"expand FMRI"
186dd566498Svn #define	TOPO_METH_EXPAND_VERSION0	0
187dd566498Svn #define	TOPO_METH_EXPAND_VERSION	TOPO_METH_EXPAND_VERSION0
188dd566498Svn 
18970818f58Stsien #define	TOPO_METH_CONTAINS		"topo_contains"
19070818f58Stsien #define	TOPO_METH_CONTAINS_DESC		"FMRI contains sub-FMRI"
19170818f58Stsien #define	TOPO_METH_CONTAINS_VERSION0	0
19270818f58Stsien #define	TOPO_METH_CONTAINS_VERSION	TOPO_METH_CONTAINS_VERSION0
19370818f58Stsien #define	TOPO_METH_CONTAINS_RET		"contains-return"
19470818f58Stsien #define	TOPO_METH_FMRI_ARG_FMRI		"fmri"
19570818f58Stsien #define	TOPO_METH_FMRI_ARG_SUBFMRI	"sub-fmri"
19670818f58Stsien 
1970eb822a1Scindi #define	TOPO_METH_ASRU_COMPUTE		"topo_asru_compute"
1980eb822a1Scindi #define	TOPO_METH_ASRU_COMPUTE_VERSION	0
1990eb822a1Scindi #define	TOPO_METH_ASRU_COMPUTE_DESC	"Dynamic ASRU constructor"
2000eb822a1Scindi 
2010eb822a1Scindi #define	TOPO_METH_FRU_COMPUTE		"topo_fru_compute"
2020eb822a1Scindi #define	TOPO_METH_FRU_COMPUTE_VERSION	0
2030eb822a1Scindi #define	TOPO_METH_FRU_COMPUTE_DESC	"Dynamic FRU constructor"
2047aec1d6eScindi 
20524db4641Seschrock #define	TOPO_METH_DISK_STATUS		"topo_disk_status"
20624db4641Seschrock #define	TOPO_METH_DISK_STATUS_VERSION	0
20724db4641Seschrock #define	TOPO_METH_DISK_STATUS_DESC	"Disk status"
20824db4641Seschrock 
209e5dcf7beSRobert Johnston #define	TOPO_METH_SENSOR_FAILURE	"topo_sensor_failure"
210e5dcf7beSRobert Johnston #define	TOPO_METH_SENSOR_FAILURE_VERSION	0
211e5dcf7beSRobert Johnston #define	TOPO_METH_SENSOR_FAILURE_DESC	"Sensor failure state"
212e5dcf7beSRobert Johnston 
213825ba0f2Srobj #define	TOPO_PROP_METH_DESC		"Dynamic Property method"
214825ba0f2Srobj 
215825ba0f2Srobj #define	TOPO_METH_IPMI_ENTITY		"ipmi_entity"
216825ba0f2Srobj #define	TOPO_METH_FAC_ENUM_DESC		"Facility Enumerator"
217825ba0f2Srobj 
2187aec1d6eScindi extern void *topo_mod_alloc(topo_mod_t *, size_t);
2197aec1d6eScindi extern void *topo_mod_zalloc(topo_mod_t *, size_t);
2207aec1d6eScindi extern void topo_mod_free(topo_mod_t *, void *, size_t);
2217aec1d6eScindi extern char *topo_mod_strdup(topo_mod_t *, const char *);
2227aec1d6eScindi extern void topo_mod_strfree(topo_mod_t *, char *);
2237aec1d6eScindi extern int topo_mod_nvalloc(topo_mod_t *, nvlist_t **, uint_t);
2247aec1d6eScindi extern int topo_mod_nvdup(topo_mod_t *, nvlist_t *, nvlist_t **);
2257aec1d6eScindi 
2267aec1d6eScindi extern void topo_mod_clrdebug(topo_mod_t *);
2270eb822a1Scindi extern void topo_mod_setdebug(topo_mod_t *);
2287aec1d6eScindi extern void topo_mod_dprintf(topo_mod_t *, const char *, ...);
2297aec1d6eScindi extern const char *topo_mod_errmsg(topo_mod_t *);
2307aec1d6eScindi extern int topo_mod_errno(topo_mod_t *);
231*6d65bee7SRob Johnston extern char *topo_mod_clean_str(topo_mod_t *, const char *);
2327aec1d6eScindi 
2337aec1d6eScindi /*
2347aec1d6eScindi  * Topo node utilities: callable from module enumeration, topo_mod_enumerate()
2357aec1d6eScindi  */
2367aec1d6eScindi extern int topo_node_range_create(topo_mod_t *, tnode_t *, const char *,
2377aec1d6eScindi     topo_instance_t, topo_instance_t);
2387aec1d6eScindi extern void topo_node_range_destroy(tnode_t *, const char *);
2397aec1d6eScindi extern tnode_t *topo_node_bind(topo_mod_t *, tnode_t *, const char *,
2400eb822a1Scindi     topo_instance_t, nvlist_t *);
241825ba0f2Srobj extern tnode_t *topo_node_facbind(topo_mod_t *, tnode_t *, const char *,
242825ba0f2Srobj     const char *);
2437aec1d6eScindi extern void topo_node_unbind(tnode_t *);
2440eb822a1Scindi extern void topo_node_setspecific(tnode_t *, void *);
2450eb822a1Scindi extern void *topo_node_getspecific(tnode_t *);
2460eb822a1Scindi extern int topo_node_asru_set(tnode_t *node, nvlist_t *, int, int *);
2470eb822a1Scindi extern int topo_node_fru_set(tnode_t *node, nvlist_t *, int, int *);
2480eb822a1Scindi extern int topo_node_label_set(tnode_t *node, char *, int *);
2490eb822a1Scindi 
2500eb822a1Scindi #define	TOPO_ASRU_COMPUTE	0x0001	/* Compute ASRU dynamically */
2510eb822a1Scindi #define	TOPO_FRU_COMPUTE	0x0002	/* Compute FRU dynamically */
2527aec1d6eScindi 
253c40d7343Scindi extern int topo_prop_inherit(tnode_t *, const char *, const char *, int *);
254c40d7343Scindi extern int topo_pgroup_create(tnode_t *, const topo_pgroup_info_t *, int *);
255c40d7343Scindi 
256c40d7343Scindi /*
257c40d7343Scindi  * Topo property method registration
258c40d7343Scindi  */
259c40d7343Scindi extern int topo_prop_method_register(tnode_t *, const char *, const char *,
260c40d7343Scindi     topo_type_t, const char *, const nvlist_t *, int *);
261c40d7343Scindi extern void topo_prop_method_unregister(tnode_t *, const char *, const char *);
262c40d7343Scindi 
2637aec1d6eScindi /*
2647aec1d6eScindi  * This enum definition is used to define a set of error tags associated with
2650eb822a1Scindi  * the module api error conditions.  The shell script mkerror.sh is
2667aec1d6eScindi  * used to parse this file and create a corresponding topo_error.c source file.
2677aec1d6eScindi  * If you do something other than add a new error tag here, you may need to
2687aec1d6eScindi  * update the mkerror shell script as it is based upon simple regexps.
2697aec1d6eScindi  */
2707aec1d6eScindi typedef enum topo_mod_errno {
2717aec1d6eScindi     EMOD_UNKNOWN = 2000, /* unknown libtopo error */
2727aec1d6eScindi     EMOD_NOMEM,			/* module memory limit exceeded */
2737aec1d6eScindi     EMOD_PARTIAL_ENUM,		/* module completed partial enumeration */
2747aec1d6eScindi     EMOD_METHOD_INVAL,		/* method arguments invalid */
2757aec1d6eScindi     EMOD_METHOD_NOTSUP,		/* method not supported */
2767aec1d6eScindi     EMOD_FMRI_NVL,		/* nvlist allocation failure for FMRI */
2777aec1d6eScindi     EMOD_FMRI_VERSION,		/* invalid FMRI scheme version */
2787aec1d6eScindi     EMOD_FMRI_MALFORM,		/* malformed FMRI */
279825ba0f2Srobj     EMOD_NODE_BOUND,		/* node already bound */
280825ba0f2Srobj     EMOD_NODE_DUP,		/* duplicate node */
281825ba0f2Srobj     EMOD_NODE_NOENT,		/* node not found */
282825ba0f2Srobj     EMOD_NODE_RANGE,		/* invalid node range */
2830eb822a1Scindi     EMOD_VER_ABI,		/* registered with invalid ABI version */
2840eb822a1Scindi     EMOD_VER_OLD,		/* attempt to load obsolete module */
2850eb822a1Scindi     EMOD_VER_NEW,		/* attempt to load a newer module */
2867aec1d6eScindi     EMOD_NVL_INVAL,		/* invalid nvlist */
2877aec1d6eScindi     EMOD_NONCANON,		/* non-canonical component name requested */
2880eb822a1Scindi     EMOD_MOD_NOENT,		/* module lookup failed */
2890eb822a1Scindi     EMOD_UKNOWN_ENUM,		/* unknown enumeration error */
2907aec1d6eScindi     EMOD_END			/* end of mod errno list (to ease auto-merge) */
2917aec1d6eScindi } topo_mod_errno_t;
2927aec1d6eScindi 
2937aec1d6eScindi extern int topo_mod_seterrno(topo_mod_t *, int);
2947aec1d6eScindi 
2957aec1d6eScindi #ifdef	__cplusplus
2967aec1d6eScindi }
2977aec1d6eScindi #endif
2987aec1d6eScindi 
2997aec1d6eScindi #endif	/* _TOPO_MOD_H */
300