17aec1d6eScindi /*
27aec1d6eScindi  * CDDL HEADER START
37aec1d6eScindi  *
47aec1d6eScindi  * The contents of this file are subject to the terms of the
57aec1d6eScindi  * Common Development and Distribution License (the "License").
67aec1d6eScindi  * You may not use this file except in compliance with the License.
77aec1d6eScindi  *
87aec1d6eScindi  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97aec1d6eScindi  * or http://www.opensolaris.org/os/licensing.
107aec1d6eScindi  * See the License for the specific language governing permissions
117aec1d6eScindi  * and limitations under the License.
127aec1d6eScindi  *
137aec1d6eScindi  * When distributing Covered Code, include this CDDL HEADER in each
147aec1d6eScindi  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157aec1d6eScindi  * If applicable, add the following below this CDDL HEADER, with the
167aec1d6eScindi  * fields enclosed by brackets "[]" replaced with your own identifying
177aec1d6eScindi  * information: Portions Copyright [yyyy] [name of copyright owner]
187aec1d6eScindi  *
197aec1d6eScindi  * CDDL HEADER END
207aec1d6eScindi  */
217aec1d6eScindi 
227aec1d6eScindi /*
23e5dcf7beSRobert Johnston  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247aec1d6eScindi  * Use is subject to license terms.
257aec1d6eScindi  */
26*c184cb88SRob Johnston /*
27*c184cb88SRob Johnston  * Copyright (c) 2018, Joyent, Inc. All rights reserved.
28*c184cb88SRob Johnston  */
297aec1d6eScindi 
307aec1d6eScindi #ifndef _TOPO_PARSE_H
317aec1d6eScindi #define	_TOPO_PARSE_H
327aec1d6eScindi 
337aec1d6eScindi #include <sys/types.h>
347aec1d6eScindi #include <libxml/parser.h>
357aec1d6eScindi #include <libnvpair.h>
367aec1d6eScindi #include <fm/libtopo.h>
370eb822a1Scindi #include <fm/topo_mod.h>
387aec1d6eScindi 
397aec1d6eScindi #ifdef	__cplusplus
407aec1d6eScindi extern "C" {
417aec1d6eScindi #endif
427aec1d6eScindi 
430eb822a1Scindi #define	TOPO_DTD_PATH	"/usr/share/lib/xml/dtd/topology.dtd.1"
447aec1d6eScindi 
457aec1d6eScindi /*
467aec1d6eScindi  * Plenty of room to hold string representation of an instance
477aec1d6eScindi  * number
487aec1d6eScindi  */
497aec1d6eScindi #define	MAXINSTSTRLEN	64
507aec1d6eScindi 
517aec1d6eScindi /*
527aec1d6eScindi  * Forward declaration
537aec1d6eScindi  */
547aec1d6eScindi struct tf_rdata;
557aec1d6eScindi struct tf_info;
567aec1d6eScindi 
577aec1d6eScindi /*
587aec1d6eScindi  * This structure summarizes an enumerator as described by an xml
597aec1d6eScindi  * topology file.
607aec1d6eScindi  */
617aec1d6eScindi typedef struct tf_edata {
627aec1d6eScindi 	char *te_name;		/* name of the enumerator, if any */
637aec1d6eScindi 	topo_stability_t te_stab; /* stability of the enumerator, if any */
640eb822a1Scindi 	topo_version_t te_vers;		/* version of the enumerator, if any */
657aec1d6eScindi } tf_edata_t;
667aec1d6eScindi 
677aec1d6eScindi /* properties and dependents off of an instance or a range */
687aec1d6eScindi typedef struct tf_pad {
697aec1d6eScindi 	int tpad_pgcnt;		/* number of property-groups of node */
707aec1d6eScindi 	int tpad_dcnt;		/* number of dependents groups of node */
717aec1d6eScindi 	nvlist_t **tpad_pgs;	/* property-groups as nvlists */
727aec1d6eScindi 	struct tf_rdata *tpad_child; /* children ranges */
737aec1d6eScindi 	struct tf_rdata *tpad_sibs; /* sibling ranges */
747aec1d6eScindi } tf_pad_t;
757aec1d6eScindi 
767aec1d6eScindi typedef struct tf_idata {
777aec1d6eScindi 	struct tf_idata *ti_next; /* next instance */
787aec1d6eScindi 	topo_instance_t ti_i;	/* hard instance */
797aec1d6eScindi 	tnode_t *ti_tn;		/* topology node representing the instance */
807aec1d6eScindi 	tf_pad_t *ti_pad;	/* properties and dependents */
817aec1d6eScindi } tf_idata_t;
827aec1d6eScindi 
837aec1d6eScindi /*
847aec1d6eScindi  * This structure summarizes a topology node range as described by a
857aec1d6eScindi  * topology file.
867aec1d6eScindi  */
877aec1d6eScindi typedef struct tf_rdata {
887aec1d6eScindi 	struct tf_rdata *rd_next; /* for linking a group of tf_rdatas */
897aec1d6eScindi 	int rd_cnt;		/* number of tf_rdatas in the list */
907aec1d6eScindi 	struct tf_info *rd_finfo; /* pointer back to .xml file details */
917aec1d6eScindi 	topo_mod_t *rd_mod;	/* pointer to loaded enumerator */
927aec1d6eScindi 	tnode_t *rd_pn;		/* parent topology node */
937aec1d6eScindi 	char *rd_name;		/* node name */
947aec1d6eScindi 	int rd_min;		/* minimum instance number of node */
957aec1d6eScindi 	int rd_max;		/* maximum instance number of node */
967aec1d6eScindi 	tf_edata_t *rd_einfo;	/* enumerator information, if any */
977aec1d6eScindi 	struct tf_idata *rd_instances; /* hard instances */
987aec1d6eScindi 	tf_pad_t *rd_pad;	/* properties and dependents */
997aec1d6eScindi } tf_rdata_t;
1007aec1d6eScindi 
1017aec1d6eScindi /*
1027aec1d6eScindi  * While we're parsing we need a handy way to pass around the data
1037aec1d6eScindi  * related to what we're currently parsing, what topology nodes may be
1047aec1d6eScindi  * affected, etc.
1057aec1d6eScindi  */
1067aec1d6eScindi typedef struct tf_info {
1077aec1d6eScindi 	char *tf_scheme;	/* scheme of topology in file */
1087aec1d6eScindi 	/* UUID ? */
1097aec1d6eScindi 	uint_t tf_flags;	/* behavior modifiers (see values below) */
1107aec1d6eScindi 	xmlDocPtr tf_xdoc;	/* the parsed xml doc */
1117aec1d6eScindi 	tf_rdata_t *tf_rd;	/* data for forming topology nodes */
1127aec1d6eScindi } tf_info_t;
1137aec1d6eScindi 
1144557a2a1Srobj #define	TF_LIVE		0x1	/* Parsing should create topology nodes */
1154557a2a1Srobj #define	TF_BIN		0x2	/* Parsing should create intermediate binary */
1164557a2a1Srobj #define	TF_PROPMAP	0x4	/* XML file loaded from a propmap element */
1177aec1d6eScindi 
1187aec1d6eScindi /*
1197aec1d6eScindi  * We store properties using nvlists as an intermediate form.  The
1207aec1d6eScindi  * following defines are names for fields in this intermediate form.
1217aec1d6eScindi  */
1227aec1d6eScindi #define	INV_IMMUTE	"prop-immutable"
1237aec1d6eScindi #define	INV_PGRP_ALLPROPS "propgrp-props"
1247aec1d6eScindi #define	INV_PGRP_NAME	"propgrp-name"
1257aec1d6eScindi #define	INV_PGRP_NPROP	"propgrp-numprops"
1260eb822a1Scindi #define	INV_PGRP_NMSTAB	"propgrp-name-stability"
1270eb822a1Scindi #define	INV_PGRP_DSTAB	"propgrp-data-stability"
1280eb822a1Scindi #define	INV_PGRP_VER	"propgrp-version"
1297aec1d6eScindi #define	INV_PNAME	"prop-name"
1307aec1d6eScindi #define	INV_PVAL	"prop-val"
1317aec1d6eScindi #define	INV_PVALTYPE	"prop-valtype"
1327aec1d6eScindi 
1330eb822a1Scindi /*
1340eb822a1Scindi  * Valid .xml element and attribute names
1350eb822a1Scindi  */
13688045cffSRobert Johnston #define	Argitem "argitem"
1374557a2a1Srobj #define	Argval "argval"
1380eb822a1Scindi #define	Children "children"
1390eb822a1Scindi #define	Dependents "dependents"
140*c184cb88SRob Johnston #define	Double	"double"
141825ba0f2Srobj #define	Facility	"facility"
1420eb822a1Scindi #define	FMRI "fmri"
14388045cffSRobert Johnston #define	FMRI_Arr "fmri_array"
1440eb822a1Scindi #define	Grouping "grouping"
1450eb822a1Scindi #define	Immutable "immutable"
146825ba0f2Srobj #define	Indicator	"indicator"
1470eb822a1Scindi #define	Instance "instance"
1480eb822a1Scindi #define	Int32 "int32"
14988045cffSRobert Johnston #define	Int32_Arr "int32_array"
1500eb822a1Scindi #define	Int64 "int64"
15188045cffSRobert Johnston #define	Int64_Arr "int64_array"
152825ba0f2Srobj #define	Ipmi	"ipmi"
153825ba0f2Srobj #define	Mutable "mutable"
1540eb822a1Scindi #define	Name "name"
155e5dcf7beSRobert Johnston #define	Nonvolatile "nonvolatile"
15688045cffSRobert Johnston #define	Propitem "propitem"
1574557a2a1Srobj #define	Propname "propname"
1584557a2a1Srobj #define	Proptype "proptype"
159825ba0f2Srobj #define	Provider "provider"
1600eb822a1Scindi #define	Range "range"
1610eb822a1Scindi #define	Scheme "scheme"
1624557a2a1Srobj #define	Set "set"
1632eeaed14Srobj #define	Setlist "setlist"
164825ba0f2Srobj #define	Sensor	"sensor"
1650eb822a1Scindi #define	Siblings "siblings"
1660eb822a1Scindi #define	Static "static"
1670eb822a1Scindi #define	String "string"
16888045cffSRobert Johnston #define	String_Arr "string_array"
1690eb822a1Scindi #define	Topology "topology"
1700eb822a1Scindi #define	Type "type"
1710eb822a1Scindi #define	UInt32 "uint32"
17288045cffSRobert Johnston #define	UInt32_Arr "uint32_array"
1730eb822a1Scindi #define	UInt64 "uint64"
17488045cffSRobert Johnston #define	UInt64_Arr "uint64_array"
1750eb822a1Scindi #define	Value "value"
1760eb822a1Scindi #define	Verify "verify"
1770eb822a1Scindi #define	Version "version"
1780eb822a1Scindi #define	Min "min"
1790eb822a1Scindi #define	Max "max"
1800eb822a1Scindi 
1810eb822a1Scindi #define	Enum_meth "enum-method"
1824557a2a1Srobj #define	Prop_meth "propmethod"
1830eb822a1Scindi #define	Propgrp "propgroup"
1840eb822a1Scindi #define	Propval "propval"
1854557a2a1Srobj #define	Propmap "propmap"
1860eb822a1Scindi 
1870eb822a1Scindi #define	Node "node"
1880eb822a1Scindi #define	Hc "hc"
1890eb822a1Scindi 
1900eb822a1Scindi #define	True "true"
1910eb822a1Scindi #define	False "false"
1920eb822a1Scindi 
1930eb822a1Scindi #define	Namestab "name-stability"
1940eb822a1Scindi #define	Datastab "data-stability"
1950eb822a1Scindi 
1960eb822a1Scindi #define	Evolving "Evolving"
1970eb822a1Scindi #define	External "External"
1980eb822a1Scindi #define	Internal "Internal"
1990eb822a1Scindi #define	Obsolete "Obsolete"
2000eb822a1Scindi #define	Private "Private"
2010eb822a1Scindi #define	Stable "Stable"
2020eb822a1Scindi #define	Standard "Standard"
2030eb822a1Scindi #define	Unstable "Unstable"
2040eb822a1Scindi 
2050eb822a1Scindi extern tf_idata_t *tf_idata_lookup(tf_idata_t *, topo_instance_t);
2067aec1d6eScindi extern tf_rdata_t *tf_rdata_new(topo_mod_t *,
2077aec1d6eScindi     tf_info_t *, xmlNodePtr, tnode_t *);
2087aec1d6eScindi extern tf_idata_t *tf_idata_new(topo_mod_t *, topo_instance_t, tnode_t *);
2097aec1d6eScindi extern tf_info_t *topo_xml_read(topo_mod_t *, const char *, const char *);
2100eb822a1Scindi extern tf_info_t *tf_info_new(topo_mod_t *, xmlDocPtr, xmlChar *);
2117aec1d6eScindi extern tf_pad_t *tf_pad_new(topo_mod_t *, int, int);
2127aec1d6eScindi extern void topo_xml_cleanup(topo_mod_t *, tf_info_t *);
2137aec1d6eScindi extern void tf_rdata_free(topo_mod_t *, tf_rdata_t *);
2147aec1d6eScindi extern void tf_edata_free(topo_mod_t *, tf_edata_t *);
2157aec1d6eScindi extern void tf_idata_free(topo_mod_t *, tf_idata_t *);
2167aec1d6eScindi extern void tf_info_free(topo_mod_t *, tf_info_t *);
2177aec1d6eScindi extern void tf_pad_free(topo_mod_t *, tf_pad_t *);
2187aec1d6eScindi extern int topo_xml_range_process(topo_mod_t *, xmlNodePtr, tf_rdata_t *);
2197aec1d6eScindi extern int topo_xml_enum(topo_mod_t *, tf_info_t *, tnode_t *);
2200eb822a1Scindi extern int tf_idata_insert(tf_idata_t **, tf_idata_t *);
2217aec1d6eScindi extern int xmlattr_to_int(topo_mod_t *, xmlNodePtr, const char *, uint64_t *);
2220eb822a1Scindi extern int xmlattr_to_stab(topo_mod_t *, xmlNodePtr, const char *,
2230eb822a1Scindi     topo_stability_t *);
2247aec1d6eScindi 
2257aec1d6eScindi #ifdef	__cplusplus
2267aec1d6eScindi }
2277aec1d6eScindi #endif
2287aec1d6eScindi 
2297aec1d6eScindi #endif	/* _TOPO_PARSE_H */
230