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