xref: /onnv-gate/usr/src/lib/fm/topo/libtopo/common/topo_module.h (revision 3062:46d280f5351d)
11414Scindi /*
21414Scindi  * CDDL HEADER START
31414Scindi  *
41414Scindi  * The contents of this file are subject to the terms of the
5*3062Scindi  * Common Development and Distribution License (the "License").
6*3062Scindi  * You may not use this file except in compliance with the License.
71414Scindi  *
81414Scindi  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91414Scindi  * or http://www.opensolaris.org/os/licensing.
101414Scindi  * See the License for the specific language governing permissions
111414Scindi  * and limitations under the License.
121414Scindi  *
131414Scindi  * When distributing Covered Code, include this CDDL HEADER in each
141414Scindi  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151414Scindi  * If applicable, add the following below this CDDL HEADER, with the
161414Scindi  * fields enclosed by brackets "[]" replaced with your own identifying
171414Scindi  * information: Portions Copyright [yyyy] [name of copyright owner]
181414Scindi  *
191414Scindi  * CDDL HEADER END
201414Scindi  */
211414Scindi /*
221414Scindi  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
231414Scindi  * Use is subject to license terms.
241414Scindi  */
251414Scindi 
261414Scindi #ifndef _TOPO_MODULE_H
271414Scindi #define	_TOPO_MODULE_H
281414Scindi 
291414Scindi #pragma ident	"%Z%%M%	%I%	%E% SMI"
301414Scindi 
311414Scindi #include <fm/topo_mod.h>
321414Scindi 
331414Scindi #include <topo_list.h>
341414Scindi #include <topo_tree.h>
351414Scindi 
361414Scindi #ifdef __cplusplus
371414Scindi extern "C" {
381414Scindi #endif
391414Scindi 
40*3062Scindi typedef struct topo_imodops {
41*3062Scindi 	int (*mop_init)(struct topo_mod *, topo_version_t version);
421414Scindi 	int (*mop_fini)(struct topo_mod *);
43*3062Scindi } topo_imodops_t;
441414Scindi 
451414Scindi #define	TOPO_HASH_BUCKETS	3
461414Scindi 
471414Scindi struct topo_modhash {
481414Scindi 	pthread_mutex_t mh_lock;	/* hash lock */
491414Scindi 	struct topo_mod **mh_hash;	/* hash bucket array */
501414Scindi 	uint_t mh_hashlen;		/* size of hash bucket array */
511414Scindi 	uint_t mh_nelems;		/* number of modules in hash */
521414Scindi };
531414Scindi 
54*3062Scindi typedef struct topo_imod_info {
55*3062Scindi 	char *tmi_desc;			/* module description */
56*3062Scindi 	char *tmi_scheme;		/* enumeration scheme-type */
57*3062Scindi 	topo_version_t tmi_version;	/* module version */
58*3062Scindi 	topo_modops_t *tmi_ops;		/* module ops vector */
59*3062Scindi } topo_imodinfo_t;
60*3062Scindi 
611414Scindi struct topo_mod {
621414Scindi 	pthread_mutex_t tm_lock;	/* Lock for tm_cv/owner/flags/refs */
631414Scindi 	pthread_cond_t tm_cv;		/* Module condition variable */
641414Scindi 	uint_t tm_busy;			/* Busy indicator */
651414Scindi 	struct topo_mod *tm_next;	/* Next module in hash chain */
661414Scindi 	topo_hdl_t *tm_hdl;		/* Topo handle for this module */
671414Scindi 	topo_alloc_t *tm_alloc;		/* Allocators */
681414Scindi 	char *tm_name;			/* Basename of module */
691414Scindi 	char *tm_path;			/* Full pathname of module file */
701414Scindi 	char *tm_rootdir;		/* Relative root directory of module */
711414Scindi 	void *tm_priv;			/* Module private data */
721414Scindi 	uint_t tm_refs;			/* Module reference count */
731414Scindi 	uint_t tm_flags;		/* Miscellaneous flags (see below) */
741414Scindi 	uint_t tm_debug;		/* Debug printf mask */
751414Scindi 	void *tm_data;			/* Private rtld/builtin data */
76*3062Scindi 	topo_imodops_t *tm_mops;	/* Module class ops vector */
77*3062Scindi 	topo_imodinfo_t *tm_info;	/* Module info registered with handle */
781414Scindi 	int tm_errno;			/* Module error */
791414Scindi };
801414Scindi 
811414Scindi #define	TOPO_MOD_INIT	0x001		/* Module init completed */
821414Scindi #define	TOPO_MOD_FINI	0x002		/* Module fini completed */
831414Scindi #define	TOPO_MOD_REG	0x004		/* topo_modinfo_t registered */
841414Scindi #define	TOPO_MOD_UNREG	0x008		/* Module unregistered */
851414Scindi 
86*3062Scindi extern const topo_imodops_t topo_rtld_ops;
871414Scindi 
881414Scindi extern void topo_mod_enter(topo_mod_t *);
891414Scindi extern void topo_mod_exit(topo_mod_t *);
901414Scindi extern void topo_mod_hold(topo_mod_t *);
911414Scindi extern void topo_mod_rele(topo_mod_t *);
921414Scindi 
931414Scindi extern topo_modhash_t *topo_modhash_create(topo_hdl_t *);
941414Scindi extern void topo_modhash_destroy(topo_hdl_t *);
951414Scindi extern topo_mod_t *topo_modhash_lookup(topo_modhash_t *, const char *);
96*3062Scindi extern topo_mod_t *topo_modhash_load(topo_hdl_t *, const char *, const char *,
97*3062Scindi     const topo_imodops_t *, topo_version_t);
981414Scindi extern void topo_modhash_unload(topo_mod_t *);
991414Scindi extern void topo_modhash_unload_all(topo_hdl_t *);
1001414Scindi 
1011414Scindi extern void topo_mod_release(topo_mod_t *, tnode_t *);
102*3062Scindi extern topo_mod_t *topo_mod_lookup(topo_hdl_t *, const char *, int);
1031414Scindi 
1041414Scindi #ifdef __cplusplus
1051414Scindi }
1061414Scindi #endif
1071414Scindi 
1081414Scindi #endif	/* _TOPO_MODULE_H */
109