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 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _TOPO_TREE_H
28 #define	_TOPO_TREE_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_prop.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 typedef struct topo_modhash topo_modhash_t;
42 
43 typedef struct topo_range {
44 	topo_instance_t	tr_min;
45 	topo_instance_t tr_max;
46 } topo_range_t;
47 
48 typedef struct topo_nodehash {
49 	topo_list_t th_list;		/* next/prev pointers */
50 	tnode_t **th_nodearr;		/* node array */
51 	uint_t th_arrlen;		/* size of node array */
52 	char *th_name;			/* name for all nodes in this hash */
53 	topo_mod_t *th_enum;		/* enumerator module */
54 	topo_range_t th_range;		/* instance ranges for nodes */
55 } topo_nodehash_t;
56 
57 typedef struct topo_imethod {
58 	topo_list_t tim_list;		/* next/prev pointers */
59 	pthread_mutex_t tim_lock;	/* method entry lock */
60 	pthread_cond_t	tim_cv;		/* method entry cv */
61 	uint_t tim_busy;		/* method entry busy indicator */
62 	char *tim_name;			/* Method name */
63 	topo_version_t tim_version;	/* Method version */
64 	topo_stability_t tim_stability;	/* SMI stability of method */
65 	char *tim_desc;			/* Method description */
66 	topo_method_f *tim_func;	/* Method function */
67 	struct topo_mod *tim_mod;	/* Ptr to controlling module */
68 } topo_imethod_t;
69 
70 struct topo_node {
71 	pthread_mutex_t	tn_lock;	/* lock protecting members */
72 	char *tn_name;			/* Node name */
73 	topo_instance_t tn_instance;	/* Node instance */
74 	int tn_state;			/* node state (see below) */
75 	int tn_fflags;			/* fmri flags (see libtopo.h) */
76 	struct topo_node *tn_parent;	/* Node parent */
77 	topo_nodehash_t *tn_phash;	/* parent hash bucket for this node */
78 	topo_hdl_t *tn_hdl;		/* topo handle pointer */
79 	topo_mod_t *tn_enum;		/* Enumerator module */
80 	topo_list_t tn_children;	/* hash table of child nodes */
81 	topo_list_t tn_pgroups;		/* Property group list */
82 	topo_list_t tn_methods;		/* Registered method list */
83 	void *tn_priv;			/* Private enumerator data */
84 	int tn_refs;			/* node reference count */
85 };
86 
87 #define	TOPO_NODE_INIT		0x0001
88 #define	TOPO_NODE_ROOT		0x0002
89 #define	TOPO_NODE_BOUND		0x0004
90 #define	TOPO_NODE_LINKED	0x0008
91 
92 typedef struct topo_tree {
93 	topo_list_t tt_list;		/* next/prev pointers */
94 	char *tt_scheme;		/* scheme name */
95 	topo_mod_t *tt_mod;		/* builtin enumerator mod */
96 	struct topo_node *tt_root;	/* root node */
97 	topo_walk_t *tt_walk;		/* private walker */
98 } ttree_t;
99 
100 struct topo_walk {
101 	struct topo_hdl *tw_thp;	/* Topo handle pointer */
102 	struct topo_node *tw_root;	/* Root node of current walk */
103 	struct topo_node *tw_node;	/* Current walker node */
104 	topo_walk_cb_t tw_cb;		/* Walker callback function */
105 	void *tw_pdata;			/* Private callback data */
106 };
107 
108 typedef struct topo_alloc {
109 	int ta_flags;
110 	nv_alloc_t ta_nva;
111 	nv_alloc_ops_t ta_nvops;
112 	void *(*ta_alloc)(size_t, int);
113 	void *(*ta_zalloc)(size_t, int);
114 	void (*ta_free)(void *, size_t);
115 } topo_alloc_t;
116 
117 struct topo_hdl {
118 	pthread_mutex_t	th_lock;	/* lock protecting hdl */
119 	char *th_uuid;			/* uuid of snapshot */
120 	char *th_rootdir;		/* Root directory of plugin paths */
121 	char *th_platform;		/* platform name */
122 	char *th_isa;			/* isa name */
123 	char *th_machine;		/* machine name */
124 	char *th_product;		/* product name */
125 	di_node_t th_di;		/* handle  to root of devinfo tree */
126 	di_prom_handle_t th_pi;		/* handle to root of prom tree */
127 	topo_modhash_t *th_modhash;	/* Module hash */
128 	topo_list_t th_trees;		/* Scheme-specific topo tree list */
129 	topo_alloc_t *th_alloc;		/* allocators */
130 	int th_errno;			/* errno */
131 	int th_debug;			/* Debug mask */
132 	int th_dbout;			/* Debug channel */
133 };
134 
135 #define	TOPO_UUID_SIZE	37	/* libuuid limit + 1 */
136 #define	SMB_DEFAULT1	"To Be Filled By O.E.M."
137 #define	SMB_DEFAULT2	"Not Available At This Time"
138 
139 extern ttree_t *topo_tree_create(topo_hdl_t *, topo_mod_t *, const char *);
140 extern void topo_tree_destroy(ttree_t *);
141 extern int topo_tree_enum_all(topo_hdl_t *);
142 
143 extern void topo_node_lock(tnode_t *);
144 extern void topo_node_unlock(tnode_t *);
145 extern void topo_node_hold(tnode_t *);
146 extern void topo_node_rele(tnode_t *);
147 extern tnode_t *topo_node_lookup(tnode_t *, const char *, topo_instance_t);
148 extern int topo_node_hash(topo_nodehash_t *, topo_instance_t);
149 
150 extern int topo_walk_bottomup(topo_walk_t *, int);
151 
152 #ifdef __cplusplus
153 }
154 #endif
155 
156 #endif	/* _TOPO_TREE_H */
157