7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER START
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * The contents of this file are subject to the terms of the
724365f7556fc4201fdb11766ebc6bd918523130sethg * Common Development and Distribution License (the "License").
724365f7556fc4201fdb11766ebc6bd918523130sethg * You may not use this file except in compliance with the License.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * See the License for the specific language governing permissions
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * and limitations under the License.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * When distributing Covered Code, include this CDDL HEADER in each
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * If applicable, add the following below this CDDL HEADER, with the
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * fields enclosed by brackets "[]" replaced with your own identifying
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * information: Portions Copyright [yyyy] [name of copyright owner]
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER END
c93c462eec9d46f84d567abf52eb29a27c2e134bCheng Sean Ye * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Use is subject to license terms.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Topology Trees
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Toplogy trees are instantiated for each builtin (FMRI) scheme specified
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * in topo_builtin.c. Each ttree_t data structure contains the
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * skeleton of the topology tree (scheme, root node, and file information).
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * The root node of a topology does not represent any FMRI but rather serves
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * as the entry point for topology access interfaces. The file information
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * provides a handle to access static .xml files that seed scheme-specifc
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * topologies
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Topology trees will remain unpopulated until topo_snap_hold() is called.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * At that time, a ttree_t structure is allocated and added to the list
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * trees maintained in topo_hdl_t. Builtin scheme-specific enumerators are
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * called upon to create nodes that represent FMRIs for resources present in the
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * system. If a <scheme>-topology.xml file exists in a standard file
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * location, the file is used to seed the topology while the rest is
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * dynamically created by the builtin or helper enumerator modules.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * For example, the 'hc' tree is enumerated by the hc enumerator (hc.c)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * after the hc-topology.xml is read from /usr/platform/`uname -i`/lib/fm/topo,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * /usr/platform/`uname -r`/lib/fm/topo, or /usr/lib/fm/topo. Each node
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * is created with a properly formatted hc FMRI resource.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Toplogy trees are released and deallocated when topo_snap_hold is called.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Upon return from topo_snap_rele(), all node resources are deallocated
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * and all that remains is the ttree_t structure containing the root node.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiset_create_error(topo_hdl_t *thp, ttree_t *tp, int err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_tree_create(topo_hdl_t *thp, topo_mod_t *mod, const char *scheme)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((tp = topo_mod_zalloc(mod, sizeof (ttree_t))) == NULL)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((tp->tt_scheme = topo_mod_strdup(mod, scheme)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Initialize a private walker for internal use
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((tp->tt_walk = topo_mod_zalloc(mod, sizeof (topo_walk_t))) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Create the root of this tree: LINKED but never BOUND
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((rp = topo_mod_zalloc(mod, sizeof (tnode_t))) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_create_error(thp, tp, 0)); /* th_errno set */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_mod_hold(mod); /* released when root node destroyed */
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_mod_free(mod, tp->tt_walk, sizeof (topo_walk_t));
724365f7556fc4201fdb11766ebc6bd918523130sethg * Deallocate this last, because a pointer alias for tt_scheme
724365f7556fc4201fdb11766ebc6bd918523130sethg * (stored in the root node's name field) may be used in
724365f7556fc4201fdb11766ebc6bd918523130sethg * topo_node_rele().
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * Attempt to enumerate the tree from a topology map in the
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * following order:
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * <product-name>-<scheme>-topology
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * <platform-name>-<scheme>-topology (uname -i)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * <machine-name>-<scheme>-topology (uname -m)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * <scheme>-topology
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * Trim any SUNW, from the product or platform name
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * before loading file
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi "topology map found for the %s "
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);