xref: /illumos-gate/usr/src/lib/fm/topo/libtopo/common/topo_module.h (revision a07094369b21309434206d9b3601d162693466fc)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _TOPO_MODULE_H
28 #define	_TOPO_MODULE_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <fm/topo_mod.h>
33 
34 #include <topo_list.h>
35 #include <topo_tree.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 typedef struct topo_modops {
42 	int (*mop_init)(struct topo_mod *);
43 	int (*mop_fini)(struct topo_mod *);
44 } topo_modops_t;
45 
46 #define	TOPO_HASH_BUCKETS	3
47 
48 struct topo_modhash {
49 	pthread_mutex_t mh_lock;	/* hash lock */
50 	struct topo_mod **mh_hash;	/* hash bucket array */
51 	uint_t mh_hashlen;		/* size of hash bucket array */
52 	uint_t mh_nelems;		/* number of modules in hash */
53 };
54 
55 struct topo_mod {
56 	pthread_mutex_t tm_lock;	/* Lock for tm_cv/owner/flags/refs */
57 	pthread_cond_t tm_cv;		/* Module condition variable */
58 	uint_t tm_busy;			/* Busy indicator */
59 	struct topo_mod *tm_next;	/* Next module in hash chain */
60 	topo_hdl_t *tm_hdl;		/* Topo handle for this module */
61 	topo_alloc_t *tm_alloc;		/* Allocators */
62 	char *tm_name;			/* Basename of module */
63 	char *tm_path;			/* Full pathname of module file */
64 	char *tm_rootdir;		/* Relative root directory of module */
65 	void *tm_priv;			/* Module private data */
66 	topo_version_t tm_version;	/* Module ABI version */
67 	topo_stability_t tm_stability;	/* SMI stability level */
68 	uint_t tm_refs;			/* Module reference count */
69 	uint_t tm_flags;		/* Miscellaneous flags (see below) */
70 	uint_t tm_debug;		/* Debug printf mask */
71 	void *tm_data;			/* Private rtld/builtin data */
72 	topo_modops_t *tm_mops;		/* Module class ops vector */
73 	topo_modinfo_t *tm_info;	/* Module info registered with handle */
74 	int tm_errno;			/* Module error */
75 };
76 
77 #define	TOPO_MOD_INIT	0x001		/* Module init completed */
78 #define	TOPO_MOD_FINI	0x002		/* Module fini completed */
79 #define	TOPO_MOD_REG	0x004		/* topo_modinfo_t registered */
80 #define	TOPO_MOD_UNREG	0x008		/* Module unregistered */
81 
82 extern const topo_modops_t topo_bltin_ops;
83 extern const topo_modops_t topo_rtld_ops;
84 
85 extern void topo_mod_enter(topo_mod_t *);
86 extern void topo_mod_exit(topo_mod_t *);
87 extern void topo_mod_hold(topo_mod_t *);
88 extern void topo_mod_rele(topo_mod_t *);
89 
90 extern topo_modhash_t *topo_modhash_create(topo_hdl_t *);
91 extern void topo_modhash_destroy(topo_hdl_t *);
92 extern topo_mod_t *topo_modhash_lookup(topo_modhash_t *, const char *);
93 extern topo_mod_t *topo_modhash_load(topo_hdl_t *, const char *,
94     const topo_modops_t *);
95 extern void topo_modhash_unload(topo_mod_t *);
96 extern void topo_modhash_unload_all(topo_hdl_t *);
97 
98 extern void topo_mod_release(topo_mod_t *, tnode_t *);
99 extern topo_mod_t *topo_mod_lookup(topo_hdl_t *, const char *);
100 
101 #ifdef __cplusplus
102 }
103 #endif
104 
105 #endif	/* _TOPO_MODULE_H */
106