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