xref: /titanic_44/usr/src/lib/fm/topo/libtopo/common/topo_tree.h (revision 9c94f155585ea35e938fea603bc227c685223abd)
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 2009 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 #include <fm/topo_mod.h>
31 
32 #include <libipmi.h>
33 
34 #include <topo_list.h>
35 #include <topo_prop.h>
36 #include <topo_method.h>
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 typedef struct topo_modhash topo_modhash_t;
43 
44 typedef struct topo_range {
45 	topo_instance_t	tr_min;
46 	topo_instance_t tr_max;
47 } topo_range_t;
48 
49 typedef struct topo_nodehash {
50 	topo_list_t th_list;		/* next/prev pointers */
51 	tnode_t **th_nodearr;		/* node array */
52 	uint_t th_arrlen;		/* size of node array */
53 	char *th_name;			/* name for all nodes in this hash */
54 	topo_mod_t *th_enum;		/* enumerator module */
55 	topo_range_t th_range;		/* instance ranges for nodes */
56 } topo_nodehash_t;
57 
58 struct topo_node {
59 	pthread_mutex_t	tn_lock;	/* lock protecting members */
60 	char *tn_name;			/* Node name */
61 	topo_instance_t tn_instance;	/* Node instance */
62 	int tn_state;			/* node state (see below) */
63 	int tn_fflags;			/* fmri flags (see libtopo.h) */
64 	struct topo_node *tn_parent;	/* Node parent */
65 	topo_nodehash_t *tn_phash;	/* parent hash bucket for this node */
66 	topo_hdl_t *tn_hdl;		/* topo handle pointer */
67 	topo_mod_t *tn_enum;		/* Enumerator module */
68 	topo_list_t tn_children;	/* hash table of child nodes */
69 	topo_list_t tn_pgroups;		/* Property group list */
70 	topo_list_t tn_methods;		/* Registered method list */
71 	void *tn_priv;			/* Private enumerator data */
72 	int tn_refs;			/* node reference count */
73 };
74 
75 #define	TOPO_NODE_INIT		0x0001
76 #define	TOPO_NODE_ROOT		0x0002
77 #define	TOPO_NODE_BOUND		0x0004
78 #define	TOPO_NODE_LINKED	0x0008
79 
80 typedef struct topo_tree {
81 	topo_list_t tt_list;		/* next/prev pointers */
82 	char *tt_scheme;		/* scheme name */
83 	topo_mod_t *tt_mod;		/* builtin enumerator mod */
84 	struct topo_node *tt_root;	/* root node */
85 	topo_walk_t *tt_walk;		/* private walker */
86 } ttree_t;
87 
88 struct topo_walk {
89 	struct topo_hdl *tw_thp;	/* Topo handle pointer */
90 	struct topo_node *tw_root;	/* Root node of current walk */
91 	struct topo_node *tw_node;	/* Current walker node */
92 	int (*tw_cb)();			/* Walker callback function */
93 	void *tw_pdata;			/* Private callback data */
94 	topo_mod_t *tw_mod;		/* module if walking from plugin */
95 };
96 
97 typedef struct topo_alloc {
98 	int ta_flags;
99 	nv_alloc_t ta_nva;
100 	nv_alloc_ops_t ta_nvops;
101 	void *(*ta_alloc)(size_t, int);
102 	void *(*ta_zalloc)(size_t, int);
103 	void (*ta_free)(void *, size_t);
104 } topo_alloc_t;
105 
106 struct topo_hdl {
107 	pthread_mutex_t	th_lock;	/* lock protecting hdl */
108 	char *th_uuid;			/* uuid of snapshot */
109 	char *th_rootdir;		/* Root directory of plugin paths */
110 	char *th_platform;		/* platform name */
111 	char *th_isa;			/* isa name */
112 	char *th_machine;		/* machine name */
113 	char *th_product;		/* product name */
114 	di_node_t th_di;		/* handle  to root of devinfo tree */
115 	di_prom_handle_t th_pi;		/* handle to root of prom tree */
116 	topo_modhash_t *th_modhash;	/* Module hash */
117 	topo_list_t th_trees;		/* Scheme-specific topo tree list */
118 	topo_alloc_t *th_alloc;		/* allocators */
119 	int th_errno;			/* errno */
120 	int th_debug;			/* Debug mask */
121 	int th_dbout;			/* Debug channel */
122 	ipmi_handle_t *th_ipmi;		/* IPMI handle */
123 	pthread_mutex_t th_ipmi_lock;	/* IPMI lock */
124 	smbios_hdl_t *th_smbios;	/* SMBIOS handle */
125 };
126 
127 #define	TOPO_UUID_SIZE	37	/* libuuid limit + 1 */
128 
129 extern ttree_t *topo_tree_create(topo_hdl_t *, topo_mod_t *, const char *);
130 extern void topo_tree_destroy(ttree_t *);
131 extern int topo_tree_enum_all(topo_hdl_t *);
132 
133 extern void topo_node_lock(tnode_t *);
134 extern void topo_node_unlock(tnode_t *);
135 extern void topo_node_hold(tnode_t *);
136 extern void topo_node_rele(tnode_t *);
137 extern tnode_t *topo_node_lookup(tnode_t *, const char *, topo_instance_t);
138 extern int topo_node_hash(topo_nodehash_t *, topo_instance_t);
139 
140 extern int topo_walk_bottomup(topo_walk_t *, int);
141 extern topo_walk_t *topo_node_walk_init(topo_hdl_t *, topo_mod_t *, tnode_t *,
142     topo_walk_cb_t, void *, int *);
143 
144 #ifdef __cplusplus
145 }
146 #endif
147 
148 #endif	/* _TOPO_TREE_H */
149