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_PARSE_H 28 #define _TOPO_PARSE_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #include <sys/types.h> 33 #include <libxml/parser.h> 34 #include <libnvpair.h> 35 #include <fm/libtopo.h> 36 #include <fm/topo_mod.h> 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 #define TOPO_DTD_PATH "/usr/share/lib/xml/dtd/topology.dtd.1" 43 44 /* 45 * Plenty of room to hold string representation of an instance 46 * number 47 */ 48 #define MAXINSTSTRLEN 64 49 50 /* 51 * Forward declaration 52 */ 53 struct tf_rdata; 54 struct tf_info; 55 56 /* 57 * This structure summarizes an enumerator as described by an xml 58 * topology file. 59 */ 60 typedef struct tf_edata { 61 char *te_name; /* name of the enumerator, if any */ 62 topo_stability_t te_stab; /* stability of the enumerator, if any */ 63 topo_version_t te_vers; /* version of the enumerator, if any */ 64 } tf_edata_t; 65 66 /* properties and dependents off of an instance or a range */ 67 typedef struct tf_pad { 68 int tpad_pgcnt; /* number of property-groups of node */ 69 int tpad_dcnt; /* number of dependents groups of node */ 70 nvlist_t **tpad_pgs; /* property-groups as nvlists */ 71 struct tf_rdata *tpad_child; /* children ranges */ 72 struct tf_rdata *tpad_sibs; /* sibling ranges */ 73 } tf_pad_t; 74 75 typedef struct tf_idata { 76 struct tf_idata *ti_next; /* next instance */ 77 topo_instance_t ti_i; /* hard instance */ 78 tnode_t *ti_tn; /* topology node representing the instance */ 79 tf_pad_t *ti_pad; /* properties and dependents */ 80 } tf_idata_t; 81 82 /* 83 * This structure summarizes a topology node range as described by a 84 * topology file. 85 */ 86 typedef struct tf_rdata { 87 struct tf_rdata *rd_next; /* for linking a group of tf_rdatas */ 88 int rd_cnt; /* number of tf_rdatas in the list */ 89 struct tf_info *rd_finfo; /* pointer back to .xml file details */ 90 topo_mod_t *rd_mod; /* pointer to loaded enumerator */ 91 tnode_t *rd_pn; /* parent topology node */ 92 char *rd_name; /* node name */ 93 int rd_min; /* minimum instance number of node */ 94 int rd_max; /* maximum instance number of node */ 95 tf_edata_t *rd_einfo; /* enumerator information, if any */ 96 struct tf_idata *rd_instances; /* hard instances */ 97 tf_pad_t *rd_pad; /* properties and dependents */ 98 /* 99 * true, if this range xml element contains any child xml 100 * node elements. 101 * We use this to determine whether or not we should apply 102 * property map changes to all of the nodes in a given range 103 * or just a specific node. 104 * 105 */ 106 int contains_node_ele; 107 } tf_rdata_t; 108 109 /* 110 * While we're parsing we need a handy way to pass around the data 111 * related to what we're currently parsing, what topology nodes may be 112 * affected, etc. 113 */ 114 typedef struct tf_info { 115 char *tf_scheme; /* scheme of topology in file */ 116 /* UUID ? */ 117 uint_t tf_flags; /* behavior modifiers (see values below) */ 118 xmlDocPtr tf_xdoc; /* the parsed xml doc */ 119 tf_rdata_t *tf_rd; /* data for forming topology nodes */ 120 } tf_info_t; 121 122 #define TF_LIVE 0x1 /* Parsing should create topology nodes */ 123 #define TF_BIN 0x2 /* Parsing should create intermediate binary */ 124 #define TF_PROPMAP 0x4 /* XML file loaded from a propmap element */ 125 126 /* 127 * We store properties using nvlists as an intermediate form. The 128 * following defines are names for fields in this intermediate form. 129 */ 130 #define INV_IMMUTE "prop-immutable" 131 #define INV_PGRP_ALLPROPS "propgrp-props" 132 #define INV_PGRP_NAME "propgrp-name" 133 #define INV_PGRP_NPROP "propgrp-numprops" 134 #define INV_PGRP_NMSTAB "propgrp-name-stability" 135 #define INV_PGRP_DSTAB "propgrp-data-stability" 136 #define INV_PGRP_VER "propgrp-version" 137 #define INV_PNAME "prop-name" 138 #define INV_PVAL "prop-val" 139 #define INV_PVALTYPE "prop-valtype" 140 141 /* 142 * Valid .xml element and attribute names 143 */ 144 #define Argval "argval" 145 #define Children "children" 146 #define Dependents "dependents" 147 #define Facility "facility" 148 #define FMRI "fmri" 149 #define Grouping "grouping" 150 #define Immutable "immutable" 151 #define Indicator "indicator" 152 #define Instance "instance" 153 #define Int32 "int32" 154 #define Int64 "int64" 155 #define Ipmi "ipmi" 156 #define Mutable "mutable" 157 #define Name "name" 158 #define Propname "propname" 159 #define Proptype "proptype" 160 #define Provider "provider" 161 #define Range "range" 162 #define Scheme "scheme" 163 #define Set "set" 164 #define Setlist "setlist" 165 #define Sensor "sensor" 166 #define Siblings "siblings" 167 #define Static "static" 168 #define String "string" 169 #define Topology "topology" 170 #define Type "type" 171 #define UInt32 "uint32" 172 #define UInt32_Arr "uint32arr" 173 #define UInt64 "uint64" 174 #define Value "value" 175 #define Verify "verify" 176 #define Version "version" 177 #define Min "min" 178 #define Max "max" 179 180 #define Enum_meth "enum-method" 181 #define Prop_meth "propmethod" 182 #define Propgrp "propgroup" 183 #define Propval "propval" 184 #define Propmap "propmap" 185 186 #define Node "node" 187 #define Hc "hc" 188 189 #define True "true" 190 #define False "false" 191 192 #define Namestab "name-stability" 193 #define Datastab "data-stability" 194 195 #define Evolving "Evolving" 196 #define External "External" 197 #define Internal "Internal" 198 #define Obsolete "Obsolete" 199 #define Private "Private" 200 #define Stable "Stable" 201 #define Standard "Standard" 202 #define Unstable "Unstable" 203 204 extern tf_idata_t *tf_idata_lookup(tf_idata_t *, topo_instance_t); 205 extern tf_rdata_t *tf_rdata_new(topo_mod_t *, 206 tf_info_t *, xmlNodePtr, tnode_t *); 207 extern tf_idata_t *tf_idata_new(topo_mod_t *, topo_instance_t, tnode_t *); 208 extern tf_info_t *topo_xml_read(topo_mod_t *, const char *, const char *); 209 extern tf_info_t *tf_info_new(topo_mod_t *, xmlDocPtr, xmlChar *); 210 extern tf_pad_t *tf_pad_new(topo_mod_t *, int, int); 211 extern void topo_xml_cleanup(topo_mod_t *, tf_info_t *); 212 extern void tf_rdata_free(topo_mod_t *, tf_rdata_t *); 213 extern void tf_edata_free(topo_mod_t *, tf_edata_t *); 214 extern void tf_idata_free(topo_mod_t *, tf_idata_t *); 215 extern void tf_info_free(topo_mod_t *, tf_info_t *); 216 extern void tf_pad_free(topo_mod_t *, tf_pad_t *); 217 extern int topo_xml_range_process(topo_mod_t *, xmlNodePtr, tf_rdata_t *); 218 extern int topo_xml_enum(topo_mod_t *, tf_info_t *, tnode_t *); 219 extern int tf_idata_insert(tf_idata_t **, tf_idata_t *); 220 extern int xmlattr_to_int(topo_mod_t *, xmlNodePtr, const char *, uint64_t *); 221 extern int xmlattr_to_stab(topo_mod_t *, xmlNodePtr, const char *, 222 topo_stability_t *); 223 224 #ifdef __cplusplus 225 } 226 #endif 227 228 #endif /* _TOPO_PARSE_H */ 229