7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER START
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * The contents of this file are subject to the terms of the
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Common Development and Distribution License (the "License").
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * You may not use this file except in compliance with the License.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * or http://www.opensolaris.org/os/licensing.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * See the License for the specific language governing permissions
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * and limitations under the License.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * When distributing Covered Code, include this CDDL HEADER in each
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * If applicable, add the following below this CDDL HEADER, with the
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * fields enclosed by brackets "[]" replaced with your own identifying
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * information: Portions Copyright [yyyy] [name of copyright owner]
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER END
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Use is subject to license terms.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <libxml/parser.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <fm/libtopo.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <topo_alloc.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <topo_error.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <topo_parse.h>
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi#include <topo_subr.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditf_info_t *
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditf_info_new(topo_mod_t *mp, xmlDocPtr doc, xmlChar *scheme)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_info_t *r;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((r = topo_mod_zalloc(mp, sizeof (tf_info_t))) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (NULL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi r->tf_flags = TF_LIVE;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((r->tf_scheme = topo_mod_strdup(mp, (char *)scheme)) == NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_info_free(mp, r);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (NULL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi r->tf_xdoc = doc;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (r);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindivoid
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditf_info_free(topo_mod_t *mp, tf_info_t *p)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (p->tf_xdoc != NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi xmlFreeDoc(p->tf_xdoc);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (p->tf_scheme != NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_mod_strfree(mp, p->tf_scheme);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_rdata_free(mp, p->tf_rd);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_mod_free(mp, p, sizeof (tf_info_t));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditf_rdata_t *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditf_rdata_new(topo_mod_t *mp, tf_info_t *xinfo, xmlNodePtr n, tnode_t *troot)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_rdata_t *r;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi uint64_t ui;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi xmlChar *name = NULL;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_dprintf(mp->tm_hdl, TOPO_DBG_XML, "new rdata\n");
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((r = topo_mod_zalloc(mp, sizeof (tf_rdata_t))) == NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) topo_mod_seterrno(mp, ETOPO_NOMEM);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (NULL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi r->rd_pn = troot;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((name = xmlGetProp(n, (xmlChar *)Name)) == NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) topo_mod_seterrno(mp, ETOPO_PRSR_NOATTR);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi goto rdata_nogood;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((r->rd_name = topo_mod_strdup(mp, (char *)name)) == NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) topo_mod_seterrno(mp, ETOPO_NOMEM);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi goto rdata_nogood;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (xmlattr_to_int(mp, n, Min, &ui) < 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi goto rdata_nogood;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi r->rd_min = (int)ui;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (xmlattr_to_int(mp, n, Max, &ui) < 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi goto rdata_nogood;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi r->rd_max = (int)ui;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (r->rd_min < 0 || r->rd_max < 0 || r->rd_max < r->rd_min) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) topo_mod_seterrno(mp, ETOPO_PRSR_BADRNG);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi goto rdata_nogood;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi r->rd_finfo = xinfo;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi r->rd_mod = mp;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (topo_xml_range_process(mp, n, r) < 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi goto rdata_nogood;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi xmlFree(name);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (r);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindirdata_nogood:
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (name != NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi xmlFree(name);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_rdata_free(mp, r);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (NULL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindivoid
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditf_rdata_free(topo_mod_t *mp, tf_rdata_t *p)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (p == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_rdata_free(mp, p->rd_next);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (p->rd_name != NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_mod_strfree(mp, p->rd_name);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_edata_free(mp, p->rd_einfo);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_idata_free(mp, p->rd_instances);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_pad_free(mp, p->rd_pad);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_mod_free(mp, p, sizeof (tf_rdata_t));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditf_idata_t *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditf_idata_new(topo_mod_t *mp, topo_instance_t i, tnode_t *tn)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_idata_t *r;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_dprintf(mp->tm_hdl, TOPO_DBG_XML, "new idata %d\n", i);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((r = topo_mod_zalloc(mp, sizeof (tf_idata_t))) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (NULL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi r->ti_tn = tn;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi r->ti_i = i;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (r);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindivoid
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditf_idata_free(topo_mod_t *mp, tf_idata_t *p)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (p == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_idata_free(mp, p->ti_next);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_pad_free(mp, p->ti_pad);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_mod_free(mp, p, sizeof (tf_idata_t));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditf_idata_insert(tf_idata_t **head, tf_idata_t *ni)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_idata_t *l, *p;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi p = NULL;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (l = *head; l != NULL; l = l->ti_next) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (ni->ti_i < l->ti_i)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi break;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi p = l;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi ni->ti_next = l;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (p == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *head = ni;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi else
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi p->ti_next = ni;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditf_idata_t *
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditf_idata_lookup(tf_idata_t *head, topo_instance_t i)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_idata_t *f;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (f = head; f != NULL; f = f->ti_next)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (i == f->ti_i)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi break;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (f);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditf_pad_t *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditf_pad_new(topo_mod_t *mp, int pcnt, int dcnt)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_pad_t *r;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_dprintf(mp->tm_hdl, TOPO_DBG_XML, "new pad p=%d, d=%d\n",
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi pcnt, dcnt);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((r = topo_mod_zalloc(mp, sizeof (tf_pad_t))) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (NULL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi r->tpad_pgcnt = pcnt;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi r->tpad_dcnt = dcnt;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (r);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindivoid
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditf_pad_free(topo_mod_t *mp, tf_pad_t *p)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi int n;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (p == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (p->tpad_pgs != NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (n = 0; n < p->tpad_pgcnt; n++)
aab83bb83be7342f6cfccaed8d5fe0b2f404855dJosef 'Jeff' Sipek nvlist_free(p->tpad_pgs[n]);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_mod_free(mp,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi p->tpad_pgs, p->tpad_pgcnt * sizeof (nvlist_t *));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_rdata_free(mp, p->tpad_child);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_rdata_free(mp, p->tpad_sibs);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_mod_free(mp, p, sizeof (tf_pad_t));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindivoid
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditf_edata_free(topo_mod_t *mp, tf_edata_t *p)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (p == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (p->te_name != NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi xmlFree(p->te_name);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_mod_free(mp, p, sizeof (tf_edata_t));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}