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