xref: /onnv-gate/usr/src/lib/fm/topo/libtopo/common/topo_tree.h (revision 10462:ec0e4f3134ef)
11414Scindi /*
21414Scindi  * CDDL HEADER START
31414Scindi  *
41414Scindi  * The contents of this file are subject to the terms of the
51414Scindi  * Common Development and Distribution License (the "License").
61414Scindi  * You may not use this file except in compliance with the License.
71414Scindi  *
81414Scindi  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91414Scindi  * or http://www.opensolaris.org/os/licensing.
101414Scindi  * See the License for the specific language governing permissions
111414Scindi  * and limitations under the License.
121414Scindi  *
131414Scindi  * When distributing Covered Code, include this CDDL HEADER in each
141414Scindi  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151414Scindi  * If applicable, add the following below this CDDL HEADER, with the
161414Scindi  * fields enclosed by brackets "[]" replaced with your own identifying
171414Scindi  * information: Portions Copyright [yyyy] [name of copyright owner]
181414Scindi  *
191414Scindi  * CDDL HEADER END
201414Scindi  */
211414Scindi 
221414Scindi /*
23*9632SEric.Schrock@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
241414Scindi  * Use is subject to license terms.
251414Scindi  */
261414Scindi 
271414Scindi #ifndef _TOPO_TREE_H
281414Scindi #define	_TOPO_TREE_H
291414Scindi 
301414Scindi #include <fm/topo_mod.h>
311414Scindi 
326070Srobj #include <libipmi.h>
336070Srobj 
341414Scindi #include <topo_list.h>
351414Scindi #include <topo_prop.h>
364087Scindi #include <topo_method.h>
371414Scindi 
381414Scindi #ifdef __cplusplus
391414Scindi extern "C" {
401414Scindi #endif
411414Scindi 
421414Scindi typedef struct topo_modhash topo_modhash_t;
431414Scindi 
441414Scindi typedef struct topo_range {
451414Scindi 	topo_instance_t	tr_min;
461414Scindi 	topo_instance_t tr_max;
471414Scindi } topo_range_t;
481414Scindi 
491414Scindi typedef struct topo_nodehash {
501414Scindi 	topo_list_t th_list;		/* next/prev pointers */
511414Scindi 	tnode_t **th_nodearr;		/* node array */
521414Scindi 	uint_t th_arrlen;		/* size of node array */
531414Scindi 	char *th_name;			/* name for all nodes in this hash */
541414Scindi 	topo_mod_t *th_enum;		/* enumerator module */
551414Scindi 	topo_range_t th_range;		/* instance ranges for nodes */
561414Scindi } topo_nodehash_t;
571414Scindi 
581414Scindi struct topo_node {
591414Scindi 	pthread_mutex_t	tn_lock;	/* lock protecting members */
601414Scindi 	char *tn_name;			/* Node name */
611414Scindi 	topo_instance_t tn_instance;	/* Node instance */
621414Scindi 	int tn_state;			/* node state (see below) */
631414Scindi 	int tn_fflags;			/* fmri flags (see libtopo.h) */
641414Scindi 	struct topo_node *tn_parent;	/* Node parent */
651414Scindi 	topo_nodehash_t *tn_phash;	/* parent hash bucket for this node */
661414Scindi 	topo_hdl_t *tn_hdl;		/* topo handle pointer */
671414Scindi 	topo_mod_t *tn_enum;		/* Enumerator module */
681414Scindi 	topo_list_t tn_children;	/* hash table of child nodes */
691414Scindi 	topo_list_t tn_pgroups;		/* Property group list */
701414Scindi 	topo_list_t tn_methods;		/* Registered method list */
711414Scindi 	void *tn_priv;			/* Private enumerator data */
721414Scindi 	int tn_refs;			/* node reference count */
731414Scindi };
741414Scindi 
751414Scindi #define	TOPO_NODE_INIT		0x0001
761414Scindi #define	TOPO_NODE_ROOT		0x0002
771414Scindi #define	TOPO_NODE_BOUND		0x0004
781414Scindi #define	TOPO_NODE_LINKED	0x0008
791414Scindi 
801414Scindi typedef struct topo_tree {
811414Scindi 	topo_list_t tt_list;		/* next/prev pointers */
823062Scindi 	char *tt_scheme;		/* scheme name */
833062Scindi 	topo_mod_t *tt_mod;		/* builtin enumerator mod */
843062Scindi 	struct topo_node *tt_root;	/* root node */
851414Scindi 	topo_walk_t *tt_walk;		/* private walker */
861414Scindi } ttree_t;
871414Scindi 
881414Scindi struct topo_walk {
891414Scindi 	struct topo_hdl *tw_thp;	/* Topo handle pointer */
901414Scindi 	struct topo_node *tw_root;	/* Root node of current walk */
911414Scindi 	struct topo_node *tw_node;	/* Current walker node */
924087Scindi 	int (*tw_cb)();			/* Walker callback function */
931414Scindi 	void *tw_pdata;			/* Private callback data */
944087Scindi 	topo_mod_t *tw_mod;		/* module if walking from plugin */
951414Scindi };
961414Scindi 
971414Scindi typedef struct topo_alloc {
981414Scindi 	int ta_flags;
991414Scindi 	nv_alloc_t ta_nva;
1001414Scindi 	nv_alloc_ops_t ta_nvops;
1011414Scindi 	void *(*ta_alloc)(size_t, int);
1021414Scindi 	void *(*ta_zalloc)(size_t, int);
1031414Scindi 	void (*ta_free)(void *, size_t);
1041414Scindi } topo_alloc_t;
1051414Scindi 
1061414Scindi struct topo_hdl {
1071414Scindi 	pthread_mutex_t	th_lock;	/* lock protecting hdl */
1081414Scindi 	char *th_uuid;			/* uuid of snapshot */
1091414Scindi 	char *th_rootdir;		/* Root directory of plugin paths */
1103062Scindi 	char *th_platform;		/* platform name */
1113062Scindi 	char *th_isa;			/* isa name */
1123062Scindi 	char *th_machine;		/* machine name */
1133062Scindi 	char *th_product;		/* product name */
1143062Scindi 	di_node_t th_di;		/* handle  to root of devinfo tree */
1153062Scindi 	di_prom_handle_t th_pi;		/* handle to root of prom tree */
1161414Scindi 	topo_modhash_t *th_modhash;	/* Module hash */
1171414Scindi 	topo_list_t th_trees;		/* Scheme-specific topo tree list */
1181414Scindi 	topo_alloc_t *th_alloc;		/* allocators */
1191414Scindi 	int th_errno;			/* errno */
1201414Scindi 	int th_debug;			/* Debug mask */
1211414Scindi 	int th_dbout;			/* Debug channel */
1226070Srobj 	ipmi_handle_t *th_ipmi;		/* IPMI handle */
1237462SEric.Schrock@Sun.COM 	pthread_mutex_t th_ipmi_lock;	/* IPMI lock */
124*9632SEric.Schrock@Sun.COM 	smbios_hdl_t *th_smbios;	/* SMBIOS handle */
1251414Scindi };
1261414Scindi 
1271414Scindi #define	TOPO_UUID_SIZE	37	/* libuuid limit + 1 */
1281414Scindi 
1291414Scindi extern ttree_t *topo_tree_create(topo_hdl_t *, topo_mod_t *, const char *);
1303062Scindi extern void topo_tree_destroy(ttree_t *);
1311414Scindi extern int topo_tree_enum_all(topo_hdl_t *);
1321414Scindi 
1331414Scindi extern void topo_node_lock(tnode_t *);
1341414Scindi extern void topo_node_unlock(tnode_t *);
1351414Scindi extern void topo_node_hold(tnode_t *);
1361414Scindi extern void topo_node_rele(tnode_t *);
1371414Scindi extern tnode_t *topo_node_lookup(tnode_t *, const char *, topo_instance_t);
1381414Scindi extern int topo_node_hash(topo_nodehash_t *, topo_instance_t);
1391414Scindi 
1401414Scindi extern int topo_walk_bottomup(topo_walk_t *, int);
1414087Scindi extern topo_walk_t *topo_node_walk_init(topo_hdl_t *, topo_mod_t *, tnode_t *,
1424087Scindi     topo_walk_cb_t, void *, int *);
1431414Scindi 
1441414Scindi #ifdef __cplusplus
1451414Scindi }
1461414Scindi #endif
1471414Scindi 
1481414Scindi #endif	/* _TOPO_TREE_H */
149