11414Scindi /* 21414Scindi * CDDL HEADER START 31414Scindi * 41414Scindi * The contents of this file are subject to the terms of the 51414Scindi * Common Development and Distribution License (the "License"). 61414Scindi * You may not use this file except in compliance with the License. 71414Scindi * 81414Scindi * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 91414Scindi * or http://www.opensolaris.org/os/licensing. 101414Scindi * See the License for the specific language governing permissions 111414Scindi * and limitations under the License. 121414Scindi * 131414Scindi * When distributing Covered Code, include this CDDL HEADER in each 141414Scindi * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 151414Scindi * If applicable, add the following below this CDDL HEADER, with the 161414Scindi * fields enclosed by brackets "[]" replaced with your own identifying 171414Scindi * information: Portions Copyright [yyyy] [name of copyright owner] 181414Scindi * 191414Scindi * CDDL HEADER END 201414Scindi */ 211414Scindi 221414Scindi /* 238526SRobert.Johnston@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 241414Scindi * Use is subject to license terms. 251414Scindi */ 261414Scindi 271414Scindi #ifndef _TOPO_PARSE_H 281414Scindi #define _TOPO_PARSE_H 291414Scindi 301414Scindi #include <sys/types.h> 311414Scindi #include <libxml/parser.h> 321414Scindi #include <libnvpair.h> 331414Scindi #include <fm/libtopo.h> 343062Scindi #include <fm/topo_mod.h> 351414Scindi 361414Scindi #ifdef __cplusplus 371414Scindi extern "C" { 381414Scindi #endif 391414Scindi 403062Scindi #define TOPO_DTD_PATH "/usr/share/lib/xml/dtd/topology.dtd.1" 411414Scindi 421414Scindi /* 431414Scindi * Plenty of room to hold string representation of an instance 441414Scindi * number 451414Scindi */ 461414Scindi #define MAXINSTSTRLEN 64 471414Scindi 481414Scindi /* 491414Scindi * Forward declaration 501414Scindi */ 511414Scindi struct tf_rdata; 521414Scindi struct tf_info; 531414Scindi 541414Scindi /* 551414Scindi * This structure summarizes an enumerator as described by an xml 561414Scindi * topology file. 571414Scindi */ 581414Scindi typedef struct tf_edata { 591414Scindi char *te_name; /* name of the enumerator, if any */ 601414Scindi topo_stability_t te_stab; /* stability of the enumerator, if any */ 613062Scindi topo_version_t te_vers; /* version of the enumerator, if any */ 621414Scindi } tf_edata_t; 631414Scindi 641414Scindi /* properties and dependents off of an instance or a range */ 651414Scindi typedef struct tf_pad { 661414Scindi int tpad_pgcnt; /* number of property-groups of node */ 671414Scindi int tpad_dcnt; /* number of dependents groups of node */ 681414Scindi nvlist_t **tpad_pgs; /* property-groups as nvlists */ 691414Scindi struct tf_rdata *tpad_child; /* children ranges */ 701414Scindi struct tf_rdata *tpad_sibs; /* sibling ranges */ 711414Scindi } tf_pad_t; 721414Scindi 731414Scindi typedef struct tf_idata { 741414Scindi struct tf_idata *ti_next; /* next instance */ 751414Scindi topo_instance_t ti_i; /* hard instance */ 761414Scindi tnode_t *ti_tn; /* topology node representing the instance */ 771414Scindi tf_pad_t *ti_pad; /* properties and dependents */ 781414Scindi } tf_idata_t; 791414Scindi 801414Scindi /* 811414Scindi * This structure summarizes a topology node range as described by a 821414Scindi * topology file. 831414Scindi */ 841414Scindi typedef struct tf_rdata { 851414Scindi struct tf_rdata *rd_next; /* for linking a group of tf_rdatas */ 861414Scindi int rd_cnt; /* number of tf_rdatas in the list */ 871414Scindi struct tf_info *rd_finfo; /* pointer back to .xml file details */ 881414Scindi topo_mod_t *rd_mod; /* pointer to loaded enumerator */ 891414Scindi tnode_t *rd_pn; /* parent topology node */ 901414Scindi char *rd_name; /* node name */ 911414Scindi int rd_min; /* minimum instance number of node */ 921414Scindi int rd_max; /* maximum instance number of node */ 931414Scindi tf_edata_t *rd_einfo; /* enumerator information, if any */ 941414Scindi struct tf_idata *rd_instances; /* hard instances */ 951414Scindi tf_pad_t *rd_pad; /* properties and dependents */ 961414Scindi } tf_rdata_t; 971414Scindi 981414Scindi /* 991414Scindi * While we're parsing we need a handy way to pass around the data 1001414Scindi * related to what we're currently parsing, what topology nodes may be 1011414Scindi * affected, etc. 1021414Scindi */ 1031414Scindi typedef struct tf_info { 1041414Scindi char *tf_scheme; /* scheme of topology in file */ 1051414Scindi /* UUID ? */ 1061414Scindi uint_t tf_flags; /* behavior modifiers (see values below) */ 1071414Scindi xmlDocPtr tf_xdoc; /* the parsed xml doc */ 1081414Scindi tf_rdata_t *tf_rd; /* data for forming topology nodes */ 1091414Scindi } tf_info_t; 1101414Scindi 1115068Srobj #define TF_LIVE 0x1 /* Parsing should create topology nodes */ 1125068Srobj #define TF_BIN 0x2 /* Parsing should create intermediate binary */ 1135068Srobj #define TF_PROPMAP 0x4 /* XML file loaded from a propmap element */ 1141414Scindi 1151414Scindi /* 1161414Scindi * We store properties using nvlists as an intermediate form. The 1171414Scindi * following defines are names for fields in this intermediate form. 1181414Scindi */ 1191414Scindi #define INV_IMMUTE "prop-immutable" 1201414Scindi #define INV_PGRP_ALLPROPS "propgrp-props" 1211414Scindi #define INV_PGRP_NAME "propgrp-name" 1221414Scindi #define INV_PGRP_NPROP "propgrp-numprops" 1233062Scindi #define INV_PGRP_NMSTAB "propgrp-name-stability" 1243062Scindi #define INV_PGRP_DSTAB "propgrp-data-stability" 1253062Scindi #define INV_PGRP_VER "propgrp-version" 1261414Scindi #define INV_PNAME "prop-name" 1271414Scindi #define INV_PVAL "prop-val" 1281414Scindi #define INV_PVALTYPE "prop-valtype" 1291414Scindi 1303062Scindi /* 1313062Scindi * Valid .xml element and attribute names 1323062Scindi */ 133*10234SRobert.Johnston@Sun.COM #define Argitem "argitem" 1345068Srobj #define Argval "argval" 1353062Scindi #define Children "children" 1363062Scindi #define Dependents "dependents" 1377243Srobj #define Facility "facility" 1383062Scindi #define FMRI "fmri" 139*10234SRobert.Johnston@Sun.COM #define FMRI_Arr "fmri_array" 1403062Scindi #define Grouping "grouping" 1413062Scindi #define Immutable "immutable" 1427243Srobj #define Indicator "indicator" 1433062Scindi #define Instance "instance" 1443062Scindi #define Int32 "int32" 145*10234SRobert.Johnston@Sun.COM #define Int32_Arr "int32_array" 1463062Scindi #define Int64 "int64" 147*10234SRobert.Johnston@Sun.COM #define Int64_Arr "int64_array" 1487243Srobj #define Ipmi "ipmi" 1497243Srobj #define Mutable "mutable" 1503062Scindi #define Name "name" 1518526SRobert.Johnston@Sun.COM #define Nonvolatile "nonvolatile" 152*10234SRobert.Johnston@Sun.COM #define Propitem "propitem" 1535068Srobj #define Propname "propname" 1545068Srobj #define Proptype "proptype" 1557243Srobj #define Provider "provider" 1563062Scindi #define Range "range" 1573062Scindi #define Scheme "scheme" 1585068Srobj #define Set "set" 1596070Srobj #define Setlist "setlist" 1607243Srobj #define Sensor "sensor" 1613062Scindi #define Siblings "siblings" 1623062Scindi #define Static "static" 1633062Scindi #define String "string" 164*10234SRobert.Johnston@Sun.COM #define String_Arr "string_array" 1653062Scindi #define Topology "topology" 1663062Scindi #define Type "type" 1673062Scindi #define UInt32 "uint32" 168*10234SRobert.Johnston@Sun.COM #define UInt32_Arr "uint32_array" 1693062Scindi #define UInt64 "uint64" 170*10234SRobert.Johnston@Sun.COM #define UInt64_Arr "uint64_array" 1713062Scindi #define Value "value" 1723062Scindi #define Verify "verify" 1733062Scindi #define Version "version" 1743062Scindi #define Min "min" 1753062Scindi #define Max "max" 1763062Scindi 1773062Scindi #define Enum_meth "enum-method" 1785068Srobj #define Prop_meth "propmethod" 1793062Scindi #define Propgrp "propgroup" 1803062Scindi #define Propval "propval" 1815068Srobj #define Propmap "propmap" 1823062Scindi 1833062Scindi #define Node "node" 1843062Scindi #define Hc "hc" 1853062Scindi 1863062Scindi #define True "true" 1873062Scindi #define False "false" 1883062Scindi 1893062Scindi #define Namestab "name-stability" 1903062Scindi #define Datastab "data-stability" 1913062Scindi 1923062Scindi #define Evolving "Evolving" 1933062Scindi #define External "External" 1943062Scindi #define Internal "Internal" 1953062Scindi #define Obsolete "Obsolete" 1963062Scindi #define Private "Private" 1973062Scindi #define Stable "Stable" 1983062Scindi #define Standard "Standard" 1993062Scindi #define Unstable "Unstable" 2003062Scindi 2013062Scindi extern tf_idata_t *tf_idata_lookup(tf_idata_t *, topo_instance_t); 2021414Scindi extern tf_rdata_t *tf_rdata_new(topo_mod_t *, 2031414Scindi tf_info_t *, xmlNodePtr, tnode_t *); 2041414Scindi extern tf_idata_t *tf_idata_new(topo_mod_t *, topo_instance_t, tnode_t *); 2051414Scindi extern tf_info_t *topo_xml_read(topo_mod_t *, const char *, const char *); 2063062Scindi extern tf_info_t *tf_info_new(topo_mod_t *, xmlDocPtr, xmlChar *); 2071414Scindi extern tf_pad_t *tf_pad_new(topo_mod_t *, int, int); 2081414Scindi extern void topo_xml_cleanup(topo_mod_t *, tf_info_t *); 2091414Scindi extern void tf_rdata_free(topo_mod_t *, tf_rdata_t *); 2101414Scindi extern void tf_edata_free(topo_mod_t *, tf_edata_t *); 2111414Scindi extern void tf_idata_free(topo_mod_t *, tf_idata_t *); 2121414Scindi extern void tf_info_free(topo_mod_t *, tf_info_t *); 2131414Scindi extern void tf_pad_free(topo_mod_t *, tf_pad_t *); 2141414Scindi extern int topo_xml_range_process(topo_mod_t *, xmlNodePtr, tf_rdata_t *); 2151414Scindi extern int topo_xml_enum(topo_mod_t *, tf_info_t *, tnode_t *); 2163062Scindi extern int tf_idata_insert(tf_idata_t **, tf_idata_t *); 2171414Scindi extern int xmlattr_to_int(topo_mod_t *, xmlNodePtr, const char *, uint64_t *); 2183062Scindi extern int xmlattr_to_stab(topo_mod_t *, xmlNodePtr, const char *, 2193062Scindi topo_stability_t *); 2201414Scindi 2211414Scindi #ifdef __cplusplus 2221414Scindi } 2231414Scindi #endif 2241414Scindi 2251414Scindi #endif /* _TOPO_PARSE_H */ 226