topo_parse.h revision 7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fe
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#ifndef _TOPO_PARSE_H
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#define _TOPO_PARSE_H
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#pragma ident "%Z%%M% %I% %E% SMI"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <sys/types.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <libxml/parser.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <libnvpair.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <fm/libtopo.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#ifdef __cplusplus
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiextern "C" {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#endif
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#define TOPO_DTD_PATH "topology.dtd.1"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#define TOPO_FILE "topology.xml"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#define TOPO_PLATFORM_PATH "%susr/platform/%s/lib/fm/topo/%s"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#define TOPO_COMMON_PATH "%susr/lib/fm/topo/%s"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Plenty of room to hold string representation of an instance
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * number
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#define MAXINSTSTRLEN 64
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Forward declaration
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistruct tf_rdata;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistruct tf_info;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * This structure summarizes an enumerator as described by an xml
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * topology file.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditypedef struct tf_edata {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi char *te_name; /* name of the enumerator, if any */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi char *te_path; /* path to the enumerator, if any */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_stability_t te_stab; /* stability of the enumerator, if any */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi int te_vers; /* version of the enumerator, if any */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi int te_amcnt; /* number of apply-methods */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi nvlist_t **te_ams; /* apply-methods */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi} tf_edata_t;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/* properties and dependents off of an instance or a range */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditypedef struct tf_pad {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi int tpad_pgcnt; /* number of property-groups of node */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi int tpad_dcnt; /* number of dependents groups of node */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi nvlist_t **tpad_pgs; /* property-groups as nvlists */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi struct tf_rdata *tpad_child; /* children ranges */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi struct tf_rdata *tpad_sibs; /* sibling ranges */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi} tf_pad_t;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditypedef struct tf_idata {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi struct tf_idata *ti_next; /* next instance */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_instance_t ti_i; /* hard instance */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tnode_t *ti_tn; /* topology node representing the instance */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_pad_t *ti_pad; /* properties and dependents */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi} tf_idata_t;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * This structure summarizes a topology node range as described by a
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * topology file.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditypedef struct tf_rdata {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi struct tf_rdata *rd_next; /* for linking a group of tf_rdatas */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi int rd_cnt; /* number of tf_rdatas in the list */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi struct tf_info *rd_finfo; /* pointer back to .xml file details */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_mod_t *rd_mod; /* pointer to loaded enumerator */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tnode_t *rd_pn; /* parent topology node */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi char *rd_name; /* node name */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi int rd_min; /* minimum instance number of node */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi int rd_max; /* maximum instance number of node */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_edata_t *rd_einfo; /* enumerator information, if any */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi struct tf_idata *rd_instances; /* hard instances */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_pad_t *rd_pad; /* properties and dependents */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi} tf_rdata_t;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * While we're parsing we need a handy way to pass around the data
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * related to what we're currently parsing, what topology nodes may be
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * affected, etc.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditypedef struct tf_info {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi char *tf_fn; /* name of file read */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi char *tf_scheme; /* scheme of topology in file */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* UUID ? */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi uint_t tf_flags; /* behavior modifiers (see values below) */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi xmlDocPtr tf_xdoc; /* the parsed xml doc */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_rdata_t *tf_rd; /* data for forming topology nodes */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi} tf_info_t;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#define TF_LIVE 0x1 /* Parsing should create topology nodes */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#define TF_BIN 0x2 /* Parsing should create intermediate binary */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * We store properties using nvlists as an intermediate form. The
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * following defines are names for fields in this intermediate form.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#define INV_IMMUTE "prop-immutable"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#define INV_PGRP_ALLPROPS "propgrp-props"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#define INV_PGRP_NAME "propgrp-name"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#define INV_PGRP_NPROP "propgrp-numprops"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#define INV_PGRP_STAB "propgrp-name-stability"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#define INV_PNAME "prop-name"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#define INV_PVAL "prop-val"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#define INV_PVALTYPE "prop-valtype"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiextern tf_idata_t *tf_idata_lookup(topo_mod_t *, tf_idata_t *, topo_instance_t);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiextern tf_rdata_t *tf_rdata_new(topo_mod_t *,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tf_info_t *, xmlNodePtr, tnode_t *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiextern tf_idata_t *tf_idata_new(topo_mod_t *, topo_instance_t, tnode_t *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiextern tf_info_t *topo_xml_read(topo_mod_t *, const char *, const char *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiextern tf_info_t *tf_info_new(topo_mod_t *,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi const char *, xmlDocPtr, xmlChar *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiextern tf_pad_t *tf_pad_new(topo_mod_t *, int, int);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiextern void topo_xml_cleanup(topo_mod_t *, tf_info_t *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiextern void tf_rdata_free(topo_mod_t *, tf_rdata_t *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiextern void tf_edata_free(topo_mod_t *, tf_edata_t *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiextern void tf_idata_free(topo_mod_t *, tf_idata_t *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiextern void tf_info_free(topo_mod_t *, tf_info_t *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiextern void tf_pad_free(topo_mod_t *, tf_pad_t *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiextern int topo_xml_range_process(topo_mod_t *, xmlNodePtr, tf_rdata_t *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiextern int topo_xml_enum(topo_mod_t *, tf_info_t *, tnode_t *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiextern int tf_idata_insert(topo_mod_t *, tf_idata_t **, tf_idata_t *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiextern int xmlattr_to_int(topo_mod_t *, xmlNodePtr, const char *, uint64_t *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiextern int xmlattr_to_stab(topo_mod_t *, xmlNodePtr, topo_stability_t *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#ifdef __cplusplus
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#endif
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#endif /* _TOPO_PARSE_H */