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