xref: /illumos-gate/usr/src/lib/fm/topo/libtopo/common/topo_parse.h (revision 95efa359b507db290a2484b8f615822b1e06096f)
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	Argval "argval"
134 #define	Children "children"
135 #define	Dependents "dependents"
136 #define	Facility	"facility"
137 #define	FMRI "fmri"
138 #define	Grouping "grouping"
139 #define	Immutable "immutable"
140 #define	Indicator	"indicator"
141 #define	Instance "instance"
142 #define	Int32 "int32"
143 #define	Int64 "int64"
144 #define	Ipmi	"ipmi"
145 #define	Mutable "mutable"
146 #define	Name "name"
147 #define	Nonvolatile "nonvolatile"
148 #define	Propname "propname"
149 #define	Proptype "proptype"
150 #define	Provider "provider"
151 #define	Range "range"
152 #define	Scheme "scheme"
153 #define	Set "set"
154 #define	Setlist "setlist"
155 #define	Sensor	"sensor"
156 #define	Siblings "siblings"
157 #define	Static "static"
158 #define	String "string"
159 #define	Topology "topology"
160 #define	Type "type"
161 #define	UInt32 "uint32"
162 #define	UInt32_Arr "uint32arr"
163 #define	UInt64 "uint64"
164 #define	Value "value"
165 #define	Verify "verify"
166 #define	Version "version"
167 #define	Min "min"
168 #define	Max "max"
169 
170 #define	Enum_meth "enum-method"
171 #define	Prop_meth "propmethod"
172 #define	Propgrp "propgroup"
173 #define	Propval "propval"
174 #define	Propmap "propmap"
175 
176 #define	Node "node"
177 #define	Hc "hc"
178 
179 #define	True "true"
180 #define	False "false"
181 
182 #define	Namestab "name-stability"
183 #define	Datastab "data-stability"
184 
185 #define	Evolving "Evolving"
186 #define	External "External"
187 #define	Internal "Internal"
188 #define	Obsolete "Obsolete"
189 #define	Private "Private"
190 #define	Stable "Stable"
191 #define	Standard "Standard"
192 #define	Unstable "Unstable"
193 
194 extern tf_idata_t *tf_idata_lookup(tf_idata_t *, topo_instance_t);
195 extern tf_rdata_t *tf_rdata_new(topo_mod_t *,
196     tf_info_t *, xmlNodePtr, tnode_t *);
197 extern tf_idata_t *tf_idata_new(topo_mod_t *, topo_instance_t, tnode_t *);
198 extern tf_info_t *topo_xml_read(topo_mod_t *, const char *, const char *);
199 extern tf_info_t *tf_info_new(topo_mod_t *, xmlDocPtr, xmlChar *);
200 extern tf_pad_t *tf_pad_new(topo_mod_t *, int, int);
201 extern void topo_xml_cleanup(topo_mod_t *, tf_info_t *);
202 extern void tf_rdata_free(topo_mod_t *, tf_rdata_t *);
203 extern void tf_edata_free(topo_mod_t *, tf_edata_t *);
204 extern void tf_idata_free(topo_mod_t *, tf_idata_t *);
205 extern void tf_info_free(topo_mod_t *, tf_info_t *);
206 extern void tf_pad_free(topo_mod_t *, tf_pad_t *);
207 extern int topo_xml_range_process(topo_mod_t *, xmlNodePtr, tf_rdata_t *);
208 extern int topo_xml_enum(topo_mod_t *, tf_info_t *, tnode_t *);
209 extern int tf_idata_insert(tf_idata_t **, tf_idata_t *);
210 extern int xmlattr_to_int(topo_mod_t *, xmlNodePtr, const char *, uint64_t *);
211 extern int xmlattr_to_stab(topo_mod_t *, xmlNodePtr, const char *,
212     topo_stability_t *);
213 
214 #ifdef	__cplusplus
215 }
216 #endif
217 
218 #endif	/* _TOPO_PARSE_H */
219