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