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 * Used by topo_node_facility() to determine whether or not this node's 83 * facilities have been enumerated. This is to avoid unecessarily re-running 84 * the facility enumeration method on this node (which can be expensive) 85 */ 86 #define TOPO_FACILITIES_BOUND 0x0010 87 88 typedef struct topo_tree { 89 topo_list_t tt_list; /* next/prev pointers */ 90 char *tt_scheme; /* scheme name */ 91 topo_mod_t *tt_mod; /* builtin enumerator mod */ 92 struct topo_node *tt_root; /* root node */ 93 topo_walk_t *tt_walk; /* private walker */ 94 } ttree_t; 95 96 struct topo_walk { 97 struct topo_hdl *tw_thp; /* Topo handle pointer */ 98 struct topo_node *tw_root; /* Root node of current walk */ 99 struct topo_node *tw_node; /* Current walker node */ 100 int (*tw_cb)(); /* Walker callback function */ 101 void *tw_pdata; /* Private callback data */ 102 topo_mod_t *tw_mod; /* module if walking from plugin */ 103 }; 104 105 typedef struct topo_alloc { 106 int ta_flags; 107 nv_alloc_t ta_nva; 108 nv_alloc_ops_t ta_nvops; 109 void *(*ta_alloc)(size_t, int); 110 void *(*ta_zalloc)(size_t, int); 111 void (*ta_free)(void *, size_t); 112 } topo_alloc_t; 113 114 struct topo_hdl { 115 pthread_mutex_t th_lock; /* lock protecting hdl */ 116 char *th_uuid; /* uuid of snapshot */ 117 char *th_rootdir; /* Root directory of plugin paths */ 118 char *th_platform; /* platform name */ 119 char *th_isa; /* isa name */ 120 char *th_machine; /* machine name */ 121 char *th_product; /* product name */ 122 di_node_t th_di; /* handle to root of devinfo tree */ 123 di_prom_handle_t th_pi; /* handle to root of prom tree */ 124 topo_modhash_t *th_modhash; /* Module hash */ 125 topo_list_t th_trees; /* Scheme-specific topo tree list */ 126 topo_alloc_t *th_alloc; /* allocators */ 127 int th_errno; /* errno */ 128 int th_debug; /* Debug mask */ 129 int th_dbout; /* Debug channel */ 130 ipmi_handle_t *th_ipmi; /* IPMI handle */ 131 }; 132 133 #define TOPO_UUID_SIZE 37 /* libuuid limit + 1 */ 134 #define SMB_DEFAULT1 "To Be Filled By O.E.M." 135 #define SMB_DEFAULT2 "Not Available At This Time" 136 137 extern ttree_t *topo_tree_create(topo_hdl_t *, topo_mod_t *, const char *); 138 extern void topo_tree_destroy(ttree_t *); 139 extern int topo_tree_enum_all(topo_hdl_t *); 140 141 extern void topo_node_lock(tnode_t *); 142 extern void topo_node_unlock(tnode_t *); 143 extern void topo_node_hold(tnode_t *); 144 extern void topo_node_rele(tnode_t *); 145 extern tnode_t *topo_node_lookup(tnode_t *, const char *, topo_instance_t); 146 extern int topo_node_hash(topo_nodehash_t *, topo_instance_t); 147 148 extern int topo_walk_bottomup(topo_walk_t *, int); 149 extern topo_walk_t *topo_node_walk_init(topo_hdl_t *, topo_mod_t *, tnode_t *, 150 topo_walk_cb_t, void *, int *); 151 152 #ifdef __cplusplus 153 } 154 #endif 155 156 #endif /* _TOPO_TREE_H */ 157