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.
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.
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]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #include <libxml/parser.h>
28 #include <fm/libtopo.h>
29 #include <topo_alloc.h>
30 #include <topo_error.h>
31 #include <topo_parse.h>
32 #include <topo_subr.h>
35 tf_info_new(topo_mod_t
*mp
, xmlDocPtr doc
, xmlChar
*scheme
)
39 if ((r
= topo_mod_zalloc(mp
, sizeof (tf_info_t
))) == NULL
)
41 r
->tf_flags
= TF_LIVE
;
42 if ((r
->tf_scheme
= topo_mod_strdup(mp
, (char *)scheme
)) == NULL
) {
51 tf_info_free(topo_mod_t
*mp
, tf_info_t
*p
)
53 if (p
->tf_xdoc
!= NULL
)
54 xmlFreeDoc(p
->tf_xdoc
);
55 if (p
->tf_scheme
!= NULL
)
56 topo_mod_strfree(mp
, p
->tf_scheme
);
57 tf_rdata_free(mp
, p
->tf_rd
);
58 topo_mod_free(mp
, p
, sizeof (tf_info_t
));
62 tf_rdata_new(topo_mod_t
*mp
, tf_info_t
*xinfo
, xmlNodePtr n
, tnode_t
*troot
)
68 topo_dprintf(mp
->tm_hdl
, TOPO_DBG_XML
, "new rdata\n");
69 if ((r
= topo_mod_zalloc(mp
, sizeof (tf_rdata_t
))) == NULL
) {
70 (void) topo_mod_seterrno(mp
, ETOPO_NOMEM
);
74 if ((name
= xmlGetProp(n
, (xmlChar
*)Name
)) == NULL
) {
75 (void) topo_mod_seterrno(mp
, ETOPO_PRSR_NOATTR
);
78 if ((r
->rd_name
= topo_mod_strdup(mp
, (char *)name
)) == NULL
) {
79 (void) topo_mod_seterrno(mp
, ETOPO_NOMEM
);
82 if (xmlattr_to_int(mp
, n
, Min
, &ui
) < 0)
85 if (xmlattr_to_int(mp
, n
, Max
, &ui
) < 0)
88 if (r
->rd_min
< 0 || r
->rd_max
< 0 || r
->rd_max
< r
->rd_min
) {
89 (void) topo_mod_seterrno(mp
, ETOPO_PRSR_BADRNG
);
95 if (topo_xml_range_process(mp
, n
, r
) < 0)
104 tf_rdata_free(mp
, r
);
109 tf_rdata_free(topo_mod_t
*mp
, tf_rdata_t
*p
)
113 tf_rdata_free(mp
, p
->rd_next
);
114 if (p
->rd_name
!= NULL
)
115 topo_mod_strfree(mp
, p
->rd_name
);
116 tf_edata_free(mp
, p
->rd_einfo
);
117 tf_idata_free(mp
, p
->rd_instances
);
118 tf_pad_free(mp
, p
->rd_pad
);
119 topo_mod_free(mp
, p
, sizeof (tf_rdata_t
));
123 tf_idata_new(topo_mod_t
*mp
, topo_instance_t i
, tnode_t
*tn
)
127 topo_dprintf(mp
->tm_hdl
, TOPO_DBG_XML
, "new idata %d\n", i
);
128 if ((r
= topo_mod_zalloc(mp
, sizeof (tf_idata_t
))) == NULL
)
136 tf_idata_free(topo_mod_t
*mp
, tf_idata_t
*p
)
140 tf_idata_free(mp
, p
->ti_next
);
141 tf_pad_free(mp
, p
->ti_pad
);
142 topo_mod_free(mp
, p
, sizeof (tf_idata_t
));
146 tf_idata_insert(tf_idata_t
**head
, tf_idata_t
*ni
)
151 for (l
= *head
; l
!= NULL
; l
= l
->ti_next
) {
152 if (ni
->ti_i
< l
->ti_i
)
165 tf_idata_lookup(tf_idata_t
*head
, topo_instance_t i
)
168 for (f
= head
; f
!= NULL
; f
= f
->ti_next
)
175 tf_pad_new(topo_mod_t
*mp
, int pcnt
, int dcnt
)
179 topo_dprintf(mp
->tm_hdl
, TOPO_DBG_XML
, "new pad p=%d, d=%d\n",
181 if ((r
= topo_mod_zalloc(mp
, sizeof (tf_pad_t
))) == NULL
)
183 r
->tpad_pgcnt
= pcnt
;
189 tf_pad_free(topo_mod_t
*mp
, tf_pad_t
*p
)
194 if (p
->tpad_pgs
!= NULL
) {
195 for (n
= 0; n
< p
->tpad_pgcnt
; n
++)
196 nvlist_free(p
->tpad_pgs
[n
]);
198 p
->tpad_pgs
, p
->tpad_pgcnt
* sizeof (nvlist_t
*));
200 tf_rdata_free(mp
, p
->tpad_child
);
201 tf_rdata_free(mp
, p
->tpad_sibs
);
202 topo_mod_free(mp
, p
, sizeof (tf_pad_t
));
206 tf_edata_free(topo_mod_t
*mp
, tf_edata_t
*p
)
210 if (p
->te_name
!= NULL
)
212 topo_mod_free(mp
, p
, sizeof (tf_edata_t
));