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