17aec1d6eScindi /*
27aec1d6eScindi  * CDDL HEADER START
37aec1d6eScindi  *
47aec1d6eScindi  * The contents of this file are subject to the terms of the
57aec1d6eScindi  * Common Development and Distribution License (the "License").
67aec1d6eScindi  * You may not use this file except in compliance with the License.
77aec1d6eScindi  *
87aec1d6eScindi  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97aec1d6eScindi  * or http://www.opensolaris.org/os/licensing.
107aec1d6eScindi  * See the License for the specific language governing permissions
117aec1d6eScindi  * and limitations under the License.
127aec1d6eScindi  *
137aec1d6eScindi  * When distributing Covered Code, include this CDDL HEADER in each
147aec1d6eScindi  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157aec1d6eScindi  * If applicable, add the following below this CDDL HEADER, with the
167aec1d6eScindi  * fields enclosed by brackets "[]" replaced with your own identifying
177aec1d6eScindi  * information: Portions Copyright [yyyy] [name of copyright owner]
187aec1d6eScindi  *
197aec1d6eScindi  * CDDL HEADER END
207aec1d6eScindi  */
217aec1d6eScindi 
227aec1d6eScindi /*
23738c43b5SEric Schrock  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247aec1d6eScindi  * Use is subject to license terms.
257aec1d6eScindi  */
2666d05358SRob Johnston /*
27*c5591576SRob Johnston  * Copyright 2020 Joyent, Inc.
2866d05358SRob Johnston  */
297aec1d6eScindi 
307aec1d6eScindi #ifndef _TOPO_TREE_H
317aec1d6eScindi #define	_TOPO_TREE_H
327aec1d6eScindi 
337aec1d6eScindi #include <fm/topo_mod.h>
347aec1d6eScindi 
352eeaed14Srobj #include <libipmi.h>
362eeaed14Srobj 
377aec1d6eScindi #include <topo_list.h>
387aec1d6eScindi #include <topo_prop.h>
39c40d7343Scindi #include <topo_method.h>
407aec1d6eScindi 
417aec1d6eScindi #ifdef __cplusplus
427aec1d6eScindi extern "C" {
437aec1d6eScindi #endif
447aec1d6eScindi 
457aec1d6eScindi typedef struct topo_modhash topo_modhash_t;
467aec1d6eScindi 
477aec1d6eScindi typedef struct topo_range {
487aec1d6eScindi 	topo_instance_t	tr_min;
497aec1d6eScindi 	topo_instance_t tr_max;
507aec1d6eScindi } topo_range_t;
517aec1d6eScindi 
527aec1d6eScindi typedef struct topo_nodehash {
537aec1d6eScindi 	topo_list_t th_list;		/* next/prev pointers */
547aec1d6eScindi 	tnode_t **th_nodearr;		/* node array */
557aec1d6eScindi 	uint_t th_arrlen;		/* size of node array */
567aec1d6eScindi 	char *th_name;			/* name for all nodes in this hash */
577aec1d6eScindi 	topo_mod_t *th_enum;		/* enumerator module */
587aec1d6eScindi 	topo_range_t th_range;		/* instance ranges for nodes */
597aec1d6eScindi } topo_nodehash_t;
607aec1d6eScindi 
617aec1d6eScindi struct topo_node {
627aec1d6eScindi 	pthread_mutex_t	tn_lock;	/* lock protecting members */
637aec1d6eScindi 	char *tn_name;			/* Node name */
647aec1d6eScindi 	topo_instance_t tn_instance;	/* Node instance */
657aec1d6eScindi 	int tn_state;			/* node state (see below) */
667aec1d6eScindi 	int tn_fflags;			/* fmri flags (see libtopo.h) */
677aec1d6eScindi 	struct topo_node *tn_parent;	/* Node parent */
687aec1d6eScindi 	topo_nodehash_t *tn_phash;	/* parent hash bucket for this node */
697aec1d6eScindi 	topo_hdl_t *tn_hdl;		/* topo handle pointer */
707aec1d6eScindi 	topo_mod_t *tn_enum;		/* Enumerator module */
717aec1d6eScindi 	topo_list_t tn_children;	/* hash table of child nodes */
727aec1d6eScindi 	topo_list_t tn_pgroups;		/* Property group list */
737aec1d6eScindi 	topo_list_t tn_methods;		/* Registered method list */
747aec1d6eScindi 	void *tn_priv;			/* Private enumerator data */
757aec1d6eScindi 	int tn_refs;			/* node reference count */
76*c5591576SRob Johnston 	topo_vertex_t *tn_vtx;		/* NULL for tree topologies */
777aec1d6eScindi };
787aec1d6eScindi 
797aec1d6eScindi #define	TOPO_NODE_INIT		0x0001
807aec1d6eScindi #define	TOPO_NODE_ROOT		0x0002
817aec1d6eScindi #define	TOPO_NODE_BOUND		0x0004
827aec1d6eScindi #define	TOPO_NODE_LINKED	0x0008
837aec1d6eScindi 
847aec1d6eScindi typedef struct topo_tree {
857aec1d6eScindi 	topo_list_t tt_list;		/* next/prev pointers */
860eb822a1Scindi 	char *tt_scheme;		/* scheme name */
870eb822a1Scindi 	topo_mod_t *tt_mod;		/* builtin enumerator mod */
880eb822a1Scindi 	struct topo_node *tt_root;	/* root node */
897aec1d6eScindi 	topo_walk_t *tt_walk;		/* private walker */
907aec1d6eScindi } ttree_t;
917aec1d6eScindi 
927aec1d6eScindi struct topo_walk {
937aec1d6eScindi 	struct topo_hdl *tw_thp;	/* Topo handle pointer */
947aec1d6eScindi 	struct topo_node *tw_root;	/* Root node of current walk */
957aec1d6eScindi 	struct topo_node *tw_node;	/* Current walker node */
96c40d7343Scindi 	int (*tw_cb)();			/* Walker callback function */
977aec1d6eScindi 	void *tw_pdata;			/* Private callback data */
98c40d7343Scindi 	topo_mod_t *tw_mod;		/* module if walking from plugin */
997aec1d6eScindi };
1007aec1d6eScindi 
1017aec1d6eScindi typedef struct topo_alloc {
1027aec1d6eScindi 	int ta_flags;
1037aec1d6eScindi 	nv_alloc_t ta_nva;
1047aec1d6eScindi 	nv_alloc_ops_t ta_nvops;
1057aec1d6eScindi 	void *(*ta_alloc)(size_t, int);
1067aec1d6eScindi 	void *(*ta_zalloc)(size_t, int);
1077aec1d6eScindi 	void (*ta_free)(void *, size_t);
1087aec1d6eScindi } topo_alloc_t;
1097aec1d6eScindi 
1107aec1d6eScindi struct topo_hdl {
1117aec1d6eScindi 	pthread_mutex_t	th_lock;	/* lock protecting hdl */
1127aec1d6eScindi 	char *th_uuid;			/* uuid of snapshot */
1137aec1d6eScindi 	char *th_rootdir;		/* Root directory of plugin paths */
1140eb822a1Scindi 	char *th_platform;		/* platform name */
1150eb822a1Scindi 	char *th_isa;			/* isa name */
1160eb822a1Scindi 	char *th_machine;		/* machine name */
1170eb822a1Scindi 	char *th_product;		/* product name */
1180eb822a1Scindi 	di_node_t th_di;		/* handle  to root of devinfo tree */
1190eb822a1Scindi 	di_prom_handle_t th_pi;		/* handle to root of prom tree */
1207aec1d6eScindi 	topo_modhash_t *th_modhash;	/* Module hash */
1217aec1d6eScindi 	topo_list_t th_trees;		/* Scheme-specific topo tree list */
122*c5591576SRob Johnston 	topo_list_t th_digraphs;	/* Scheme-specific topo digraph list */
1237aec1d6eScindi 	topo_alloc_t *th_alloc;		/* allocators */
1247aec1d6eScindi 	int th_errno;			/* errno */
1257aec1d6eScindi 	int th_debug;			/* Debug mask */
1267aec1d6eScindi 	int th_dbout;			/* Debug channel */
1272eeaed14Srobj 	ipmi_handle_t *th_ipmi;		/* IPMI handle */
1280b1b4412SEric Schrock 	pthread_mutex_t th_ipmi_lock;	/* IPMI lock */
129738c43b5SEric Schrock 	smbios_hdl_t *th_smbios;	/* SMBIOS handle */
13066d05358SRob Johnston 	pcidb_hdl_t *th_pcidb;		/* libpcidb handle */
1317aec1d6eScindi };
1327aec1d6eScindi 
1337aec1d6eScindi #define	TOPO_UUID_SIZE	37	/* libuuid limit + 1 */
1347aec1d6eScindi 
1357aec1d6eScindi extern ttree_t *topo_tree_create(topo_hdl_t *, topo_mod_t *, const char *);
1360eb822a1Scindi extern void topo_tree_destroy(ttree_t *);
1377aec1d6eScindi extern int topo_tree_enum_all(topo_hdl_t *);
1387aec1d6eScindi 
1397aec1d6eScindi extern void topo_node_lock(tnode_t *);
1407aec1d6eScindi extern void topo_node_unlock(tnode_t *);
1417aec1d6eScindi extern void topo_node_hold(tnode_t *);
1427aec1d6eScindi extern void topo_node_rele(tnode_t *);
1437aec1d6eScindi extern tnode_t *topo_node_lookup(tnode_t *, const char *, topo_instance_t);
1447aec1d6eScindi extern int topo_node_hash(topo_nodehash_t *, topo_instance_t);
1457aec1d6eScindi 
1467aec1d6eScindi extern int topo_walk_bottomup(topo_walk_t *, int);
147c40d7343Scindi extern topo_walk_t *topo_node_walk_init(topo_hdl_t *, topo_mod_t *, tnode_t *,
148c40d7343Scindi     topo_walk_cb_t, void *, int *);
1497aec1d6eScindi 
1507aec1d6eScindi #ifdef __cplusplus
1517aec1d6eScindi }
1527aec1d6eScindi #endif
1537aec1d6eScindi 
1547aec1d6eScindi #endif	/* _TOPO_TREE_H */
155