xref: /illumos-gate/usr/src/lib/fm/topo/libtopo/common/topo_parse.h (revision 4e93fb0f6383eaac21897dcdae56b87118131e4d)
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 2006 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 
116 /*
117  * We store properties using nvlists as an intermediate form.  The
118  * following defines are names for fields in this intermediate form.
119  */
120 #define	INV_IMMUTE	"prop-immutable"
121 #define	INV_PGRP_ALLPROPS "propgrp-props"
122 #define	INV_PGRP_NAME	"propgrp-name"
123 #define	INV_PGRP_NPROP	"propgrp-numprops"
124 #define	INV_PGRP_NMSTAB	"propgrp-name-stability"
125 #define	INV_PGRP_DSTAB	"propgrp-data-stability"
126 #define	INV_PGRP_VER	"propgrp-version"
127 #define	INV_PNAME	"prop-name"
128 #define	INV_PVAL	"prop-val"
129 #define	INV_PVALTYPE	"prop-valtype"
130 
131 /*
132  * Valid .xml element and attribute names
133  */
134 #define	Children "children"
135 #define	Dependents "dependents"
136 #define	FMRI "fmri"
137 #define	Grouping "grouping"
138 #define	Immutable "immutable"
139 #define	Instance "instance"
140 #define	Int32 "int32"
141 #define	Int64 "int64"
142 #define	Name "name"
143 #define	Path "path"
144 #define	Range "range"
145 #define	Scheme "scheme"
146 #define	Siblings "siblings"
147 #define	Static "static"
148 #define	String "string"
149 #define	Topology "topology"
150 #define	Type "type"
151 #define	UInt32 "uint32"
152 #define	UInt64 "uint64"
153 #define	Value "value"
154 #define	Verify "verify"
155 #define	Version "version"
156 #define	Min "min"
157 #define	Max "max"
158 
159 #define	Enum_meth "enum-method"
160 #define	Propgrp "propgroup"
161 #define	Propval "propval"
162 
163 #define	Node "node"
164 #define	Hc "hc"
165 
166 #define	True "true"
167 #define	False "false"
168 
169 #define	Namestab "name-stability"
170 #define	Datastab "data-stability"
171 
172 #define	Evolving "Evolving"
173 #define	External "External"
174 #define	Internal "Internal"
175 #define	Obsolete "Obsolete"
176 #define	Private "Private"
177 #define	Stable "Stable"
178 #define	Standard "Standard"
179 #define	Unstable "Unstable"
180 
181 extern tf_idata_t *tf_idata_lookup(tf_idata_t *, topo_instance_t);
182 extern tf_rdata_t *tf_rdata_new(topo_mod_t *,
183     tf_info_t *, xmlNodePtr, tnode_t *);
184 extern tf_idata_t *tf_idata_new(topo_mod_t *, topo_instance_t, tnode_t *);
185 extern tf_info_t *topo_xml_read(topo_mod_t *, const char *, const char *);
186 extern tf_info_t *tf_info_new(topo_mod_t *, xmlDocPtr, xmlChar *);
187 extern tf_pad_t *tf_pad_new(topo_mod_t *, int, int);
188 extern void topo_xml_cleanup(topo_mod_t *, tf_info_t *);
189 extern void tf_rdata_free(topo_mod_t *, tf_rdata_t *);
190 extern void tf_edata_free(topo_mod_t *, tf_edata_t *);
191 extern void tf_idata_free(topo_mod_t *, tf_idata_t *);
192 extern void tf_info_free(topo_mod_t *, tf_info_t *);
193 extern void tf_pad_free(topo_mod_t *, tf_pad_t *);
194 extern int topo_xml_range_process(topo_mod_t *, xmlNodePtr, tf_rdata_t *);
195 extern int topo_xml_enum(topo_mod_t *, tf_info_t *, tnode_t *);
196 extern int tf_idata_insert(tf_idata_t **, tf_idata_t *);
197 extern int xmlattr_to_int(topo_mod_t *, xmlNodePtr, const char *, uint64_t *);
198 extern int xmlattr_to_stab(topo_mod_t *, xmlNodePtr, const char *,
199     topo_stability_t *);
200 
201 #ifdef	__cplusplus
202 }
203 #endif
204 
205 #endif	/* _TOPO_PARSE_H */
206