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 (c) 2018, 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 }; 77 78 #define TOPO_NODE_INIT 0x0001 79 #define TOPO_NODE_ROOT 0x0002 80 #define TOPO_NODE_BOUND 0x0004 81 #define TOPO_NODE_LINKED 0x0008 82 83 typedef struct topo_tree { 84 topo_list_t tt_list; /* next/prev pointers */ 85 char *tt_scheme; /* scheme name */ 86 topo_mod_t *tt_mod; /* builtin enumerator mod */ 87 struct topo_node *tt_root; /* root node */ 88 topo_walk_t *tt_walk; /* private walker */ 89 } ttree_t; 90 91 struct topo_walk { 92 struct topo_hdl *tw_thp; /* Topo handle pointer */ 93 struct topo_node *tw_root; /* Root node of current walk */ 94 struct topo_node *tw_node; /* Current walker node */ 95 int (*tw_cb)(); /* Walker callback function */ 96 void *tw_pdata; /* Private callback data */ 97 topo_mod_t *tw_mod; /* module if walking from plugin */ 98 }; 99 100 typedef struct topo_alloc { 101 int ta_flags; 102 nv_alloc_t ta_nva; 103 nv_alloc_ops_t ta_nvops; 104 void *(*ta_alloc)(size_t, int); 105 void *(*ta_zalloc)(size_t, int); 106 void (*ta_free)(void *, size_t); 107 } topo_alloc_t; 108 109 struct topo_hdl { 110 pthread_mutex_t th_lock; /* lock protecting hdl */ 111 char *th_uuid; /* uuid of snapshot */ 112 char *th_rootdir; /* Root directory of plugin paths */ 113 char *th_platform; /* platform name */ 114 char *th_isa; /* isa name */ 115 char *th_machine; /* machine name */ 116 char *th_product; /* product name */ 117 di_node_t th_di; /* handle to root of devinfo tree */ 118 di_prom_handle_t th_pi; /* handle to root of prom tree */ 119 topo_modhash_t *th_modhash; /* Module hash */ 120 topo_list_t th_trees; /* Scheme-specific topo tree list */ 121 topo_alloc_t *th_alloc; /* allocators */ 122 int th_errno; /* errno */ 123 int th_debug; /* Debug mask */ 124 int th_dbout; /* Debug channel */ 125 ipmi_handle_t *th_ipmi; /* IPMI handle */ 126 pthread_mutex_t th_ipmi_lock; /* IPMI lock */ 127 smbios_hdl_t *th_smbios; /* SMBIOS handle */ 128 pcidb_hdl_t *th_pcidb; /* libpcidb handle */ 129 }; 130 131 #define TOPO_UUID_SIZE 37 /* libuuid limit + 1 */ 132 133 extern ttree_t *topo_tree_create(topo_hdl_t *, topo_mod_t *, const char *); 134 extern void topo_tree_destroy(ttree_t *); 135 extern int topo_tree_enum_all(topo_hdl_t *); 136 137 extern void topo_node_lock(tnode_t *); 138 extern void topo_node_unlock(tnode_t *); 139 extern void topo_node_hold(tnode_t *); 140 extern void topo_node_rele(tnode_t *); 141 extern tnode_t *topo_node_lookup(tnode_t *, const char *, topo_instance_t); 142 extern int topo_node_hash(topo_nodehash_t *, topo_instance_t); 143 144 extern int topo_walk_bottomup(topo_walk_t *, int); 145 extern topo_walk_t *topo_node_walk_init(topo_hdl_t *, topo_mod_t *, tnode_t *, 146 topo_walk_cb_t, void *, int *); 147 148 #ifdef __cplusplus 149 } 150 #endif 151 152 #endif /* _TOPO_TREE_H */ 153