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