17aec1d6eScindi /* 27aec1d6eScindi * CDDL HEADER START 37aec1d6eScindi * 47aec1d6eScindi * The contents of this file are subject to the terms of the 57aec1d6eScindi * Common Development and Distribution License (the "License"). 67aec1d6eScindi * You may not use this file except in compliance with the License. 77aec1d6eScindi * 87aec1d6eScindi * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97aec1d6eScindi * or http://www.opensolaris.org/os/licensing. 107aec1d6eScindi * See the License for the specific language governing permissions 117aec1d6eScindi * and limitations under the License. 127aec1d6eScindi * 137aec1d6eScindi * When distributing Covered Code, include this CDDL HEADER in each 147aec1d6eScindi * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157aec1d6eScindi * If applicable, add the following below this CDDL HEADER, with the 167aec1d6eScindi * fields enclosed by brackets "[]" replaced with your own identifying 177aec1d6eScindi * information: Portions Copyright [yyyy] [name of copyright owner] 187aec1d6eScindi * 197aec1d6eScindi * CDDL HEADER END 207aec1d6eScindi */ 217aec1d6eScindi 227aec1d6eScindi /* 237aec1d6eScindi * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 247aec1d6eScindi * Use is subject to license terms. 257aec1d6eScindi */ 267aec1d6eScindi 277aec1d6eScindi #ifndef _LIBTOPO_H 287aec1d6eScindi #define _LIBTOPO_H 297aec1d6eScindi 307aec1d6eScindi #pragma ident "%Z%%M% %I% %E% SMI" 317aec1d6eScindi 327aec1d6eScindi #include <sys/nvpair.h> 33*0eb822a1Scindi #include <stdio.h> 347aec1d6eScindi 357aec1d6eScindi #ifdef __cplusplus 367aec1d6eScindi extern "C" { 377aec1d6eScindi #endif 387aec1d6eScindi 397aec1d6eScindi #define TOPO_VERSION 1 /* Library ABI Interface Version */ 407aec1d6eScindi 417aec1d6eScindi typedef struct topo_hdl topo_hdl_t; 427aec1d6eScindi typedef struct topo_node tnode_t; 437aec1d6eScindi typedef struct topo_walk topo_walk_t; 447aec1d6eScindi typedef int32_t topo_instance_t; 457aec1d6eScindi typedef uint32_t topo_version_t; 467aec1d6eScindi 477aec1d6eScindi /* 487aec1d6eScindi * Topo stability attributes 497aec1d6eScindi * 507aec1d6eScindi * Each topology node advertises the name and data stability of each of its 517aec1d6eScindi * modules and properties. (see attributes(5)) 527aec1d6eScindi */ 537aec1d6eScindi 547aec1d6eScindi typedef enum topo_stability { 55*0eb822a1Scindi TOPO_STABILITY_UNKNOWN = 0, /* private to libtopo */ 56*0eb822a1Scindi TOPO_STABILITY_INTERNAL, /* private to libtopo */ 577aec1d6eScindi TOPO_STABILITY_PRIVATE, /* private to Sun */ 587aec1d6eScindi TOPO_STABILITY_OBSOLETE, /* scheduled for removal */ 597aec1d6eScindi TOPO_STABILITY_EXTERNAL, /* not controlled by Sun */ 607aec1d6eScindi TOPO_STABILITY_UNSTABLE, /* new or rapidly changing */ 617aec1d6eScindi TOPO_STABILITY_EVOLVING, /* less rapidly changing */ 627aec1d6eScindi TOPO_STABILITY_STABLE, /* mature interface from Sun */ 63*0eb822a1Scindi TOPO_STABILITY_STANDARD /* industry standard */ 647aec1d6eScindi } topo_stability_t; 657aec1d6eScindi 66*0eb822a1Scindi #define TOPO_STABILITY_MAX TOPO_STABILITY_STANDARD /* max valid stab */ 677aec1d6eScindi 687aec1d6eScindi typedef enum { 697aec1d6eScindi TOPO_TYPE_INVALID = 0, 707aec1d6eScindi TOPO_TYPE_BOOLEAN, /* boolean */ 717aec1d6eScindi TOPO_TYPE_INT32, /* int32_t */ 727aec1d6eScindi TOPO_TYPE_UINT32, /* uint32_t */ 737aec1d6eScindi TOPO_TYPE_INT64, /* int64_t */ 747aec1d6eScindi TOPO_TYPE_UINT64, /* uint64_t */ 757aec1d6eScindi TOPO_TYPE_STRING, /* const char* */ 767aec1d6eScindi TOPO_TYPE_TIME, /* uint64_t */ 777aec1d6eScindi TOPO_TYPE_SIZE, /* uint64_t */ 78*0eb822a1Scindi TOPO_TYPE_FMRI, /* nvlist_t */ 79*0eb822a1Scindi TOPO_TYPE_INT32_ARRAY, /* array of int32_t */ 80*0eb822a1Scindi TOPO_TYPE_UINT32_ARRAY, /* array of uint32_t */ 81*0eb822a1Scindi TOPO_TYPE_INT64_ARRAY, /* array of int64_t */ 82*0eb822a1Scindi TOPO_TYPE_UINT64_ARRAY, /* array of uint64_t */ 83*0eb822a1Scindi TOPO_TYPE_STRING_ARRAY, /* array of const char* */ 84*0eb822a1Scindi TOPO_TYPE_FMRI_ARRAY /* array of nvlist_t */ 857aec1d6eScindi } topo_type_t; 867aec1d6eScindi 87*0eb822a1Scindi typedef struct topo_pgroup_info { 88*0eb822a1Scindi const char *tpi_name; /* property group name */ 89*0eb822a1Scindi topo_stability_t tpi_namestab; /* stability of group name */ 90*0eb822a1Scindi topo_stability_t tpi_datastab; /* stability of all property values */ 91*0eb822a1Scindi topo_version_t tpi_version; /* version of pgroup definition */ 92*0eb822a1Scindi } topo_pgroup_info_t; 93*0eb822a1Scindi 94*0eb822a1Scindi extern topo_stability_t topo_name2stability(const char *); 95*0eb822a1Scindi extern const char *topo_stability2name(topo_stability_t); 967aec1d6eScindi 977aec1d6eScindi extern topo_hdl_t *topo_open(int, const char *, int *); 987aec1d6eScindi extern void topo_close(topo_hdl_t *); 997aec1d6eScindi extern char *topo_snap_hold(topo_hdl_t *, const char *, int *); 1007aec1d6eScindi extern void topo_snap_release(topo_hdl_t *); 101*0eb822a1Scindi extern int topo_xml_print(topo_hdl_t *, FILE *, const char *scheme, int *); 102*0eb822a1Scindi 103*0eb822a1Scindi /* 104*0eb822a1Scindi * Snapshot walker support 105*0eb822a1Scindi */ 106*0eb822a1Scindi typedef int (*topo_walk_cb_t)(topo_hdl_t *, tnode_t *, void *); 107*0eb822a1Scindi 1087aec1d6eScindi extern topo_walk_t *topo_walk_init(topo_hdl_t *, const char *, topo_walk_cb_t, 1097aec1d6eScindi void *, int *); 1107aec1d6eScindi extern int topo_walk_step(topo_walk_t *, int); 1117aec1d6eScindi extern void topo_walk_fini(topo_walk_t *); 1127aec1d6eScindi 1137aec1d6eScindi #define TOPO_WALK_ERR -1 1147aec1d6eScindi #define TOPO_WALK_NEXT 0 1157aec1d6eScindi #define TOPO_WALK_TERMINATE 1 1167aec1d6eScindi 1177aec1d6eScindi #define TOPO_WALK_CHILD 0x0001 1187aec1d6eScindi #define TOPO_WALK_SIBLING 0x0002 1197aec1d6eScindi 120*0eb822a1Scindi /* 121*0eb822a1Scindi * FMRI helper routines 122*0eb822a1Scindi */ 1237aec1d6eScindi extern int topo_fmri_present(topo_hdl_t *, nvlist_t *, int *); 1247aec1d6eScindi extern int topo_fmri_contains(topo_hdl_t *, nvlist_t *, nvlist_t *, int *); 1257aec1d6eScindi extern int topo_fmri_unusable(topo_hdl_t *, nvlist_t *, int *); 1267aec1d6eScindi extern int topo_fmri_nvl2str(topo_hdl_t *, nvlist_t *, char **, int *); 1277aec1d6eScindi extern int topo_fmri_str2nvl(topo_hdl_t *, const char *, nvlist_t **, int *); 1287aec1d6eScindi extern int topo_fmri_asru(topo_hdl_t *, nvlist_t *, nvlist_t **, int *); 1297aec1d6eScindi extern int topo_fmri_fru(topo_hdl_t *, nvlist_t *, nvlist_t **, 1307aec1d6eScindi int *); 1317aec1d6eScindi extern int topo_fmri_compare(topo_hdl_t *, nvlist_t *, nvlist_t *, int *); 1327aec1d6eScindi extern int topo_fmri_invoke(topo_hdl_t *, nvlist_t *, topo_walk_cb_t, void *, 1337aec1d6eScindi int *); 1347aec1d6eScindi extern nvlist_t *topo_fmri_create(topo_hdl_t *, const char *, const char *, 1357aec1d6eScindi topo_instance_t, nvlist_t *, int *); 1367aec1d6eScindi 1377aec1d6eScindi /* 1387aec1d6eScindi * Topo node utilities: callable from topo_walk_step() callback or module 1397aec1d6eScindi * enumeration, topo_mod_enumerate() 1407aec1d6eScindi */ 1417aec1d6eScindi extern char *topo_node_name(tnode_t *); 1427aec1d6eScindi extern topo_instance_t topo_node_instance(tnode_t *); 1437aec1d6eScindi extern void *topo_node_private(tnode_t *); 1447aec1d6eScindi extern int topo_node_asru(tnode_t *, nvlist_t **, nvlist_t *, int *); 1457aec1d6eScindi extern int topo_node_fru(tnode_t *, nvlist_t **, nvlist_t *, int *); 1467aec1d6eScindi extern int topo_node_resource(tnode_t *, nvlist_t **, int *); 1477aec1d6eScindi extern int topo_node_label(tnode_t *, char **, int *); 1487aec1d6eScindi extern int topo_method_invoke(tnode_t *node, const char *, topo_version_t, 1497aec1d6eScindi nvlist_t *, nvlist_t **, int *); 1507aec1d6eScindi 151*0eb822a1Scindi extern int topo_pgroup_create(tnode_t *, const topo_pgroup_info_t *, int *); 1527aec1d6eScindi extern void topo_pgroup_destroy(tnode_t *, const char *); 153*0eb822a1Scindi extern topo_pgroup_info_t *topo_pgroup_info(tnode_t *, const char *, int *); 1547aec1d6eScindi extern int topo_prop_get_int32(tnode_t *, const char *, const char *, 1557aec1d6eScindi int32_t *, int *); 1567aec1d6eScindi extern int topo_prop_get_uint32(tnode_t *, const char *, const char *, 1577aec1d6eScindi uint32_t *, int *); 1587aec1d6eScindi extern int topo_prop_get_int64(tnode_t *, const char *, const char *, 1597aec1d6eScindi int64_t *, int *); 1607aec1d6eScindi extern int topo_prop_get_uint64(tnode_t *, const char *, const char *, 1617aec1d6eScindi uint64_t *, int *); 1627aec1d6eScindi extern int topo_prop_get_string(tnode_t *, const char *, const char *, 1637aec1d6eScindi char **, int *); 1647aec1d6eScindi extern int topo_prop_get_fmri(tnode_t *, const char *, const char *, 1657aec1d6eScindi nvlist_t **, int *); 166*0eb822a1Scindi extern int topo_prop_get_int32_array(tnode_t *, const char *, const char *, 167*0eb822a1Scindi int32_t **, uint_t *, int *); 168*0eb822a1Scindi extern int topo_prop_get_uint32_array(tnode_t *, const char *, const char *, 169*0eb822a1Scindi uint32_t **, uint_t *, int *); 170*0eb822a1Scindi extern int topo_prop_get_int64_array(tnode_t *, const char *, const char *, 171*0eb822a1Scindi int64_t **, uint_t *, int *); 172*0eb822a1Scindi extern int topo_prop_get_uint64_array(tnode_t *, const char *, const char *, 173*0eb822a1Scindi uint64_t **, uint_t *, int *); 174*0eb822a1Scindi extern int topo_prop_get_string_array(tnode_t *, const char *, const char *, 175*0eb822a1Scindi char ***, uint_t *, int *); 176*0eb822a1Scindi extern int topo_prop_get_fmri_array(tnode_t *, const char *, const char *, 177*0eb822a1Scindi nvlist_t ***, uint_t *, int *); 1787aec1d6eScindi extern int topo_prop_set_int32(tnode_t *, const char *, const char *, int, 1797aec1d6eScindi int32_t, int *); 1807aec1d6eScindi extern int topo_prop_set_uint32(tnode_t *, const char *, const char *, int, 1817aec1d6eScindi uint32_t, int *); 1827aec1d6eScindi extern int topo_prop_set_int64(tnode_t *, const char *, const char *, 1837aec1d6eScindi int, int64_t, int *); 1847aec1d6eScindi extern int topo_prop_set_uint64(tnode_t *, const char *, const char *, 1857aec1d6eScindi int, uint64_t, int *); 1867aec1d6eScindi extern int topo_prop_set_string(tnode_t *, const char *, const char *, 1877aec1d6eScindi int, const char *, int *); 1887aec1d6eScindi extern int topo_prop_set_fmri(tnode_t *, const char *, const char *, 1897aec1d6eScindi int, const nvlist_t *, int *); 190*0eb822a1Scindi extern int topo_prop_set_int32_array(tnode_t *, const char *, const char *, int, 191*0eb822a1Scindi int32_t *, uint_t, int *); 192*0eb822a1Scindi extern int topo_prop_set_uint32_array(tnode_t *, const char *, const char *, 193*0eb822a1Scindi int, uint32_t *, uint_t, int *); 194*0eb822a1Scindi extern int topo_prop_set_int64_array(tnode_t *, const char *, const char *, 195*0eb822a1Scindi int, int64_t *, uint_t, int *); 196*0eb822a1Scindi extern int topo_prop_set_uint64_array(tnode_t *, const char *, const char *, 197*0eb822a1Scindi int, uint64_t *, uint_t, int *); 198*0eb822a1Scindi extern int topo_prop_set_string_array(tnode_t *, const char *, const char *, 199*0eb822a1Scindi int, const char **, uint_t, int *); 200*0eb822a1Scindi extern int topo_prop_set_fmri_array(tnode_t *, const char *, const char *, 201*0eb822a1Scindi int, const nvlist_t **, uint_t, int *); 202*0eb822a1Scindi extern nvlist_t *topo_prop_getprops(tnode_t *, int *err); 2037aec1d6eScindi extern int topo_prop_inherit(tnode_t *, const char *, const char *, int *); 2047aec1d6eScindi 205*0eb822a1Scindi #define TOPO_PROP_IMMUTABLE 0 206*0eb822a1Scindi #define TOPO_PROP_MUTABLE 1 2077aec1d6eScindi 2087aec1d6eScindi /* Protocol property group and property names */ 2097aec1d6eScindi #define TOPO_PGROUP_PROTOCOL "protocol" /* Required property group */ 2107aec1d6eScindi #define TOPO_PROP_RESOURCE "resource" /* resource FMRI */ 2117aec1d6eScindi #define TOPO_PROP_ASRU "ASRU" /* ASRU FMRI */ 2127aec1d6eScindi #define TOPO_PROP_FRU "FRU" /* FRU FMRI */ 2137aec1d6eScindi #define TOPO_PROP_MOD "module" /* software module FMRI */ 2147aec1d6eScindi #define TOPO_PROP_PKG "package" /* software package FMRI */ 2157aec1d6eScindi #define TOPO_PROP_LABEL "label" /* property LABEL */ 2167aec1d6eScindi 2177aec1d6eScindi /* 2187aec1d6eScindi * System property group 2197aec1d6eScindi */ 2207aec1d6eScindi #define TOPO_PGROUP_SYSTEM "system" 2217aec1d6eScindi #define TOPO_PROP_ISA "isa" 2227aec1d6eScindi #define TOPO_PROP_MACHINE "machine" 2237aec1d6eScindi 224*0eb822a1Scindi /* Property node NVL names used in topo_prop_getprops */ 2257aec1d6eScindi #define TOPO_PROP_GROUP "property-group" 2267aec1d6eScindi #define TOPO_PROP_GROUP_NAME "property-group-name" 227*0eb822a1Scindi #define TOPO_PROP_GROUP_DSTAB "property-group-data-stability" 228*0eb822a1Scindi #define TOPO_PROP_GROUP_NSTAB "property-group-name-stability" 229*0eb822a1Scindi #define TOPO_PROP_GROUP_VERSION "property-group-version" 2307aec1d6eScindi #define TOPO_PROP_VAL "property" 2317aec1d6eScindi #define TOPO_PROP_VAL_NAME "property-name" 2327aec1d6eScindi #define TOPO_PROP_VAL_VAL "property-value" 233*0eb822a1Scindi #define TOPO_PROP_VAL_TYPE "property-type" 234*0eb822a1Scindi 235*0eb822a1Scindi /* 236*0eb822a1Scindi * This enum definition is used to define a set of error tags associated with 237*0eb822a1Scindi * the libtopo various error conditions occuring during the adminstration of 238*0eb822a1Scindi * properties. The shell script mkerror.sh is 239*0eb822a1Scindi * used to parse this file and create a corresponding topo_error.c source file. 240*0eb822a1Scindi * If you do something other than add a new error tag here, you may need to 241*0eb822a1Scindi * update the mkerror shell script as it is based upon simple regexps. 242*0eb822a1Scindi */ 243*0eb822a1Scindi typedef enum topo_prop_errno { 244*0eb822a1Scindi ETOPO_PROP_UNKNOWN = 3000, /* unknown topo prop error */ 245*0eb822a1Scindi ETOPO_PROP_NOENT, /* undefined property or property group */ 246*0eb822a1Scindi ETOPO_PROP_DEFD, /* static property already defined */ 247*0eb822a1Scindi ETOPO_PROP_NOMEM, /* memory limit exceeded during property allocation */ 248*0eb822a1Scindi ETOPO_PROP_TYPE, /* invalid property type */ 249*0eb822a1Scindi ETOPO_PROP_NOINHERIT, /* can not inherit property */ 250*0eb822a1Scindi ETOPO_PROP_NVL, /* malformed property nvlist */ 251*0eb822a1Scindi ETOPO_PROP_END /* end of prop errno list (to ease auto-merge) */ 252*0eb822a1Scindi } topo_prop_errno_t; 2537aec1d6eScindi 2547aec1d6eScindi extern const char *topo_strerror(int); 255*0eb822a1Scindi extern void topo_debug_set(topo_hdl_t *, const char *, const char *); 2567aec1d6eScindi extern void *topo_hdl_alloc(topo_hdl_t *, size_t); 2577aec1d6eScindi extern void *topo_hdl_zalloc(topo_hdl_t *, size_t); 2587aec1d6eScindi extern void topo_hdl_free(topo_hdl_t *, void *, size_t); 2597aec1d6eScindi extern int topo_hdl_nvalloc(topo_hdl_t *, nvlist_t **, uint_t); 2607aec1d6eScindi extern int topo_hdl_nvdup(topo_hdl_t *, nvlist_t *, nvlist_t **); 2617aec1d6eScindi extern char *topo_hdl_strdup(topo_hdl_t *, const char *); 2627aec1d6eScindi extern void topo_hdl_strfree(topo_hdl_t *, char *); 2637aec1d6eScindi 2647aec1d6eScindi #ifdef __cplusplus 2657aec1d6eScindi } 2667aec1d6eScindi #endif 2677aec1d6eScindi 2687aec1d6eScindi #endif /* _LIBTOPO_H */ 269