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 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 #define TOPO_DTD_PATH "topology.dtd.1" 42 #define TOPO_FILE "topology.xml" 43 #define TOPO_PLATFORM_PATH "%susr/platform/%s/lib/fm/topo/%s" 44 #define TOPO_COMMON_PATH "%susr/lib/fm/topo/%s" 45 46 /* 47 * Plenty of room to hold string representation of an instance 48 * number 49 */ 50 #define MAXINSTSTRLEN 64 51 52 /* 53 * Forward declaration 54 */ 55 struct tf_rdata; 56 struct tf_info; 57 58 /* 59 * This structure summarizes an enumerator as described by an xml 60 * topology file. 61 */ 62 typedef struct tf_edata { 63 char *te_name; /* name of the enumerator, if any */ 64 char *te_path; /* path to the enumerator, if any */ 65 topo_stability_t te_stab; /* stability of the enumerator, if any */ 66 int te_vers; /* version of the enumerator, if any */ 67 int te_amcnt; /* number of apply-methods */ 68 nvlist_t **te_ams; /* apply-methods */ 69 } tf_edata_t; 70 71 /* properties and dependents off of an instance or a range */ 72 typedef struct tf_pad { 73 int tpad_pgcnt; /* number of property-groups of node */ 74 int tpad_dcnt; /* number of dependents groups of node */ 75 nvlist_t **tpad_pgs; /* property-groups as nvlists */ 76 struct tf_rdata *tpad_child; /* children ranges */ 77 struct tf_rdata *tpad_sibs; /* sibling ranges */ 78 } tf_pad_t; 79 80 typedef struct tf_idata { 81 struct tf_idata *ti_next; /* next instance */ 82 topo_instance_t ti_i; /* hard instance */ 83 tnode_t *ti_tn; /* topology node representing the instance */ 84 tf_pad_t *ti_pad; /* properties and dependents */ 85 } tf_idata_t; 86 87 /* 88 * This structure summarizes a topology node range as described by a 89 * topology file. 90 */ 91 typedef struct tf_rdata { 92 struct tf_rdata *rd_next; /* for linking a group of tf_rdatas */ 93 int rd_cnt; /* number of tf_rdatas in the list */ 94 struct tf_info *rd_finfo; /* pointer back to .xml file details */ 95 topo_mod_t *rd_mod; /* pointer to loaded enumerator */ 96 tnode_t *rd_pn; /* parent topology node */ 97 char *rd_name; /* node name */ 98 int rd_min; /* minimum instance number of node */ 99 int rd_max; /* maximum instance number of node */ 100 tf_edata_t *rd_einfo; /* enumerator information, if any */ 101 struct tf_idata *rd_instances; /* hard instances */ 102 tf_pad_t *rd_pad; /* properties and dependents */ 103 } tf_rdata_t; 104 105 /* 106 * While we're parsing we need a handy way to pass around the data 107 * related to what we're currently parsing, what topology nodes may be 108 * affected, etc. 109 */ 110 typedef struct tf_info { 111 char *tf_fn; /* name of file read */ 112 char *tf_scheme; /* scheme of topology in file */ 113 /* UUID ? */ 114 uint_t tf_flags; /* behavior modifiers (see values below) */ 115 xmlDocPtr tf_xdoc; /* the parsed xml doc */ 116 tf_rdata_t *tf_rd; /* data for forming topology nodes */ 117 } tf_info_t; 118 119 #define TF_LIVE 0x1 /* Parsing should create topology nodes */ 120 #define TF_BIN 0x2 /* Parsing should create intermediate binary */ 121 122 /* 123 * We store properties using nvlists as an intermediate form. The 124 * following defines are names for fields in this intermediate form. 125 */ 126 #define INV_IMMUTE "prop-immutable" 127 #define INV_PGRP_ALLPROPS "propgrp-props" 128 #define INV_PGRP_NAME "propgrp-name" 129 #define INV_PGRP_NPROP "propgrp-numprops" 130 #define INV_PGRP_STAB "propgrp-name-stability" 131 #define INV_PNAME "prop-name" 132 #define INV_PVAL "prop-val" 133 #define INV_PVALTYPE "prop-valtype" 134 135 extern tf_idata_t *tf_idata_lookup(topo_mod_t *, tf_idata_t *, topo_instance_t); 136 extern tf_rdata_t *tf_rdata_new(topo_mod_t *, 137 tf_info_t *, xmlNodePtr, tnode_t *); 138 extern tf_idata_t *tf_idata_new(topo_mod_t *, topo_instance_t, tnode_t *); 139 extern tf_info_t *topo_xml_read(topo_mod_t *, const char *, const char *); 140 extern tf_info_t *tf_info_new(topo_mod_t *, 141 const char *, xmlDocPtr, xmlChar *); 142 extern tf_pad_t *tf_pad_new(topo_mod_t *, int, int); 143 extern void topo_xml_cleanup(topo_mod_t *, tf_info_t *); 144 extern void tf_rdata_free(topo_mod_t *, tf_rdata_t *); 145 extern void tf_edata_free(topo_mod_t *, tf_edata_t *); 146 extern void tf_idata_free(topo_mod_t *, tf_idata_t *); 147 extern void tf_info_free(topo_mod_t *, tf_info_t *); 148 extern void tf_pad_free(topo_mod_t *, tf_pad_t *); 149 extern int topo_xml_range_process(topo_mod_t *, xmlNodePtr, tf_rdata_t *); 150 extern int topo_xml_enum(topo_mod_t *, tf_info_t *, tnode_t *); 151 extern int tf_idata_insert(topo_mod_t *, tf_idata_t **, tf_idata_t *); 152 extern int xmlattr_to_int(topo_mod_t *, xmlNodePtr, const char *, uint64_t *); 153 extern int xmlattr_to_stab(topo_mod_t *, xmlNodePtr, topo_stability_t *); 154 155 #ifdef __cplusplus 156 } 157 #endif 158 159 #endif /* _TOPO_PARSE_H */ 160