xref: /illumos-gate/usr/src/lib/fm/topo/libtopo/common/topo_module.h (revision 9164a50bf932130cbb5097a16f6986873ce0e6e5)
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  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _TOPO_MODULE_H
27 #define	_TOPO_MODULE_H
28 
29 #include <fm/topo_mod.h>
30 
31 #include <topo_list.h>
32 #include <topo_tree.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 typedef struct topo_imodops {
39 	int (*mop_init)(struct topo_mod *, topo_version_t version);
40 	int (*mop_fini)(struct topo_mod *);
41 } topo_imodops_t;
42 
43 #define	TOPO_HASH_BUCKETS	3
44 
45 struct topo_modhash {
46 	pthread_mutex_t mh_lock;	/* hash lock */
47 	struct topo_mod **mh_hash;	/* hash bucket array */
48 	uint_t mh_hashlen;		/* size of hash bucket array */
49 	uint_t mh_nelems;		/* number of modules in hash */
50 };
51 
52 typedef struct topo_imod_info {
53 	char *tmi_desc;			/* module description */
54 	char *tmi_scheme;		/* enumeration scheme-type */
55 	topo_version_t tmi_version;	/* module version */
56 	topo_modops_t *tmi_ops;		/* module ops vector */
57 } topo_imodinfo_t;
58 
59 struct topo_mod {
60 	pthread_mutex_t tm_lock;	/* Lock for tm_cv/owner/flags/refs */
61 	pthread_cond_t tm_cv;		/* Module condition variable */
62 	uint_t tm_busy;			/* Busy indicator */
63 	struct topo_mod *tm_next;	/* Next module in hash chain */
64 	topo_hdl_t *tm_hdl;		/* Topo handle for this module */
65 	topo_alloc_t *tm_alloc;		/* Allocators */
66 	char *tm_name;			/* Basename of module */
67 	char *tm_path;			/* Full pathname of module file */
68 	char *tm_rootdir;		/* Relative root directory of module */
69 	void *tm_priv;			/* Module private data */
70 	uint_t tm_refs;			/* Module reference count */
71 	uint_t tm_flags;		/* Miscellaneous flags (see below) */
72 	uint_t tm_debug;		/* Debug printf mask */
73 	void *tm_data;			/* Private rtld/builtin data */
74 	topo_imodops_t *tm_mops;	/* Module class ops vector */
75 	topo_imodinfo_t *tm_info;	/* Module info registered with handle */
76 	int tm_errno;			/* Module error */
77 };
78 
79 #define	TOPO_MOD_INIT	0x001		/* Module init completed */
80 #define	TOPO_MOD_FINI	0x002		/* Module fini completed */
81 #define	TOPO_MOD_REG	0x004		/* topo_modinfo_t registered */
82 #define	TOPO_MOD_UNREG	0x008		/* Module unregistered */
83 
84 extern const topo_imodops_t topo_rtld_ops;
85 
86 extern void topo_mod_enter(topo_mod_t *);
87 extern void topo_mod_exit(topo_mod_t *);
88 extern void topo_mod_hold(topo_mod_t *);
89 extern void topo_mod_rele(topo_mod_t *);
90 
91 extern topo_modhash_t *topo_modhash_create(topo_hdl_t *);
92 extern void topo_modhash_destroy(topo_hdl_t *);
93 extern topo_mod_t *topo_modhash_lookup(topo_modhash_t *, const char *);
94 extern topo_mod_t *topo_modhash_load(topo_hdl_t *, const char *, const char *,
95     const topo_imodops_t *, topo_version_t);
96 extern void topo_modhash_unload(topo_mod_t *);
97 extern void topo_modhash_unload_all(topo_hdl_t *);
98 
99 extern void topo_mod_release(topo_mod_t *, tnode_t *);
100 extern topo_mod_t *topo_mod_lookup(topo_hdl_t *, const char *, int);
101 
102 #ifdef __cplusplus
103 }
104 #endif
105 
106 #endif	/* _TOPO_MODULE_H */
107