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 /* 23e5dcf7beSRobert Johnston * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 247aec1d6eScindi * Use is subject to license terms. 257aec1d6eScindi */ 267aec1d6eScindi 277aec1d6eScindi #ifndef _TOPO_MOD_H 287aec1d6eScindi #define _TOPO_MOD_H 297aec1d6eScindi 307aec1d6eScindi #include <fm/libtopo.h> 310eb822a1Scindi #include <fm/topo_hc.h> 322eeaed14Srobj #include <libipmi.h> 337aec1d6eScindi #include <libnvpair.h> 340eb822a1Scindi #include <libdevinfo.h> 35*738c43b5SEric Schrock #include <smbios.h> 367aec1d6eScindi 377aec1d6eScindi #ifdef __cplusplus 387aec1d6eScindi extern "C" { 397aec1d6eScindi #endif 407aec1d6eScindi 417aec1d6eScindi /* 427aec1d6eScindi * Enumerator and method supplier module API 437aec1d6eScindi */ 447aec1d6eScindi typedef struct topo_mod topo_mod_t; 457aec1d6eScindi 467aec1d6eScindi typedef int topo_method_f(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *, 477aec1d6eScindi nvlist_t **); 487aec1d6eScindi typedef int topo_enum_f(topo_mod_t *, tnode_t *, const char *, topo_instance_t, 490eb822a1Scindi topo_instance_t, void *, void *); 507aec1d6eScindi typedef void topo_release_f(topo_mod_t *, tnode_t *); 517aec1d6eScindi 527aec1d6eScindi typedef struct topo_method { 537aec1d6eScindi const char *tm_name; /* Method name */ 547aec1d6eScindi const char *tm_desc; /* Method description */ 557aec1d6eScindi const topo_version_t tm_version; /* Method version */ 567aec1d6eScindi const topo_stability_t tm_stability; /* Attributes of method */ 577aec1d6eScindi topo_method_f *tm_func; /* Method function */ 587aec1d6eScindi } topo_method_t; 597aec1d6eScindi 600eb822a1Scindi typedef struct topo_modops { 610eb822a1Scindi topo_enum_f *tmo_enum; /* enumeration op */ 620eb822a1Scindi topo_release_f *tmo_release; /* resource release op */ 630eb822a1Scindi } topo_modops_t; 640eb822a1Scindi 657aec1d6eScindi typedef struct topo_mod_info { 660eb822a1Scindi const char *tmi_desc; /* module description */ 670eb822a1Scindi const char *tmi_scheme; /* enumeration scheme type */ 680eb822a1Scindi topo_version_t tmi_version; /* module version */ 690eb822a1Scindi const topo_modops_t *tmi_ops; /* module ops vector */ 707aec1d6eScindi } topo_modinfo_t; 717aec1d6eScindi 720eb822a1Scindi extern topo_mod_t *topo_mod_load(topo_mod_t *, const char *, topo_version_t); 737aec1d6eScindi extern void topo_mod_unload(topo_mod_t *); 740eb822a1Scindi extern int topo_mod_register(topo_mod_t *, const topo_modinfo_t *, 750eb822a1Scindi topo_version_t); 767aec1d6eScindi extern void topo_mod_unregister(topo_mod_t *); 777aec1d6eScindi extern int topo_mod_enumerate(topo_mod_t *, tnode_t *, const char *, 780eb822a1Scindi const char *, topo_instance_t, topo_instance_t, void *); 790eb822a1Scindi extern int topo_mod_enummap(topo_mod_t *mod, tnode_t *, const char *, 800eb822a1Scindi const char *); 817aec1d6eScindi extern void topo_mod_release(topo_mod_t *, tnode_t *); 820eb822a1Scindi extern void topo_mod_setspecific(topo_mod_t *, void *); 830eb822a1Scindi extern void *topo_mod_getspecific(topo_mod_t *); 840eb822a1Scindi 850eb822a1Scindi extern nvlist_t *topo_mod_cpufmri(topo_mod_t *, int, uint32_t, uint8_t, 860eb822a1Scindi const char *); 870eb822a1Scindi extern nvlist_t *topo_mod_devfmri(topo_mod_t *, int, const char *, 880eb822a1Scindi const char *); 890eb822a1Scindi extern nvlist_t *topo_mod_hcfmri(topo_mod_t *, tnode_t *, int, const char *, 900eb822a1Scindi topo_instance_t, nvlist_t *, nvlist_t *, const char *, const char *, 910eb822a1Scindi const char *); 920eb822a1Scindi extern nvlist_t *topo_mod_memfmri(topo_mod_t *, int, uint64_t, uint64_t, 930eb822a1Scindi const char *, int); 940eb822a1Scindi extern nvlist_t *topo_mod_modfmri(topo_mod_t *, int, const char *); 950eb822a1Scindi extern nvlist_t *topo_mod_pkgfmri(topo_mod_t *, int, const char *); 960eb822a1Scindi extern int topo_mod_nvl2str(topo_mod_t *, nvlist_t *, char **); 970eb822a1Scindi extern int topo_mod_str2nvl(topo_mod_t *, const char *, nvlist_t **); 98825ba0f2Srobj extern int topo_prop_setmutable(tnode_t *node, const char *pgname, 99825ba0f2Srobj const char *pname, int *err); 100e5dcf7beSRobert Johnston extern int topo_prop_setnonvolatile(tnode_t *node, const char *pgname, 101e5dcf7beSRobert Johnston const char *pname, int *err); 102c40d7343Scindi /* 103c40d7343Scindi * Snapshot walker support 104c40d7343Scindi */ 105c40d7343Scindi typedef int (*topo_mod_walk_cb_t)(topo_mod_t *, tnode_t *, void *); 106c40d7343Scindi 107c40d7343Scindi extern topo_walk_t *topo_mod_walk_init(topo_mod_t *, tnode_t *, 108c40d7343Scindi topo_mod_walk_cb_t, void *, int *); 109c40d7343Scindi 1100eb822a1Scindi /* 1110eb822a1Scindi * Flags for topo_mod_memfmri 1120eb822a1Scindi */ 1130eb822a1Scindi #define TOPO_MEMFMRI_PA 0x0001 /* Valid physical address */ 1140eb822a1Scindi #define TOPO_MEMFMRI_OFFSET 0x0002 /* Valid offset */ 1157aec1d6eScindi 1167aec1d6eScindi extern int topo_method_register(topo_mod_t *, tnode_t *, const topo_method_t *); 1177aec1d6eScindi extern void topo_method_unregister(topo_mod_t *, tnode_t *, const char *); 1187aec1d6eScindi extern void topo_method_unregister_all(topo_mod_t *, tnode_t *); 1197aec1d6eScindi 1200eb822a1Scindi extern di_node_t topo_mod_devinfo(topo_mod_t *); 1210b1b4412SEric Schrock extern ipmi_handle_t *topo_mod_ipmi_hold(topo_mod_t *); 1220b1b4412SEric Schrock extern void topo_mod_ipmi_rele(topo_mod_t *); 123*738c43b5SEric Schrock extern smbios_hdl_t *topo_mod_smbios(topo_mod_t *); 1240eb822a1Scindi extern di_prom_handle_t topo_mod_prominfo(topo_mod_t *); 1250eb822a1Scindi extern nvlist_t *topo_mod_auth(topo_mod_t *, tnode_t *); 1260eb822a1Scindi 127e5dcf7beSRobert Johnston extern int topo_method_sensor_failure(topo_mod_t *, tnode_t *, topo_version_t, 128e5dcf7beSRobert Johnston nvlist_t *, nvlist_t **); 129e5dcf7beSRobert Johnston 1307aec1d6eScindi /* 1317aec1d6eScindi * FMRI methods 1327aec1d6eScindi */ 1337aec1d6eScindi #define TOPO_METH_LABEL "topo_label" 134c40d7343Scindi #define TOPO_METH_LABEL_DESC "label constructor" 1350eb822a1Scindi #define TOPO_METH_LABEL_VERSION0 0 1360eb822a1Scindi #define TOPO_METH_LABEL_VERSION TOPO_METH_LABEL_VERSION0 137825ba0f2Srobj #define TOPO_METH_LABEL_ARG_NVL "label-specific" 138825ba0f2Srobj #define TOPO_METH_LABEL_RET_STR "label-string" 1390eb822a1Scindi 1407aec1d6eScindi #define TOPO_METH_PRESENT "topo_present" 141c40d7343Scindi #define TOPO_METH_PRESENT_DESC "presence indicator" 1420eb822a1Scindi #define TOPO_METH_PRESENT_VERSION0 0 1430eb822a1Scindi #define TOPO_METH_PRESENT_VERSION TOPO_METH_PRESENT_VERSION0 1440eb822a1Scindi #define TOPO_METH_PRESENT_RET "present-ret" 1450eb822a1Scindi 14625c6ff4bSstephh #define TOPO_METH_REPLACED "topo_replaced" 14725c6ff4bSstephh #define TOPO_METH_REPLACED_DESC "replaced indicator" 14825c6ff4bSstephh #define TOPO_METH_REPLACED_VERSION0 0 14925c6ff4bSstephh #define TOPO_METH_REPLACED_VERSION TOPO_METH_REPLACED_VERSION0 15025c6ff4bSstephh #define TOPO_METH_REPLACED_RET "replaced-ret" 15125c6ff4bSstephh 152dd566498Svn #define TOPO_METH_UNUSABLE "topo_unusable" 153c40d7343Scindi #define TOPO_METH_UNUSABLE_DESC "unusable indicator" 154dd566498Svn #define TOPO_METH_UNUSABLE_VERSION0 0 155dd566498Svn #define TOPO_METH_UNUSABLE_VERSION TOPO_METH_UNUSABLE_VERSION0 156dd566498Svn #define TOPO_METH_UNUSABLE_RET "unusable-ret" 157dd566498Svn 15825c6ff4bSstephh #define TOPO_METH_SERVICE_STATE "topo_service_state" 15925c6ff4bSstephh #define TOPO_METH_SERVICE_STATE_DESC "service_state indicator" 16025c6ff4bSstephh #define TOPO_METH_SERVICE_STATE_VERSION0 0 16125c6ff4bSstephh #define TOPO_METH_SERVICE_STATE_VERSION TOPO_METH_SERVICE_STATE_VERSION0 16225c6ff4bSstephh #define TOPO_METH_SERVICE_STATE_RET "service_state-ret" 16325c6ff4bSstephh 164e4b86885SCheng Sean Ye #define TOPO_METH_RETIRE "topo_retire" 165e4b86885SCheng Sean Ye #define TOPO_METH_RETIRE_DESC "retire action" 166e4b86885SCheng Sean Ye #define TOPO_METH_RETIRE_VERSION0 0 167e4b86885SCheng Sean Ye #define TOPO_METH_RETIRE_VERSION TOPO_METH_RETIRE_VERSION0 168e4b86885SCheng Sean Ye #define TOPO_METH_RETIRE_RET "retire-ret" 169e4b86885SCheng Sean Ye 170e4b86885SCheng Sean Ye #define TOPO_METH_UNRETIRE "topo_unretire" 171e4b86885SCheng Sean Ye #define TOPO_METH_UNRETIRE_DESC "unretire action" 172e4b86885SCheng Sean Ye #define TOPO_METH_UNRETIRE_VERSION0 0 173e4b86885SCheng Sean Ye #define TOPO_METH_UNRETIRE_VERSION TOPO_METH_UNRETIRE_VERSION0 174e4b86885SCheng Sean Ye #define TOPO_METH_UNRETIRE_RET "unretire-ret" 175e4b86885SCheng Sean Ye 176dd566498Svn #define TOPO_METH_EXPAND "topo_expand" 177dd566498Svn #define TOPO_METH_EXPAND_DESC "expand FMRI" 178dd566498Svn #define TOPO_METH_EXPAND_VERSION0 0 179dd566498Svn #define TOPO_METH_EXPAND_VERSION TOPO_METH_EXPAND_VERSION0 180dd566498Svn 18170818f58Stsien #define TOPO_METH_CONTAINS "topo_contains" 18270818f58Stsien #define TOPO_METH_CONTAINS_DESC "FMRI contains sub-FMRI" 18370818f58Stsien #define TOPO_METH_CONTAINS_VERSION0 0 18470818f58Stsien #define TOPO_METH_CONTAINS_VERSION TOPO_METH_CONTAINS_VERSION0 18570818f58Stsien #define TOPO_METH_CONTAINS_RET "contains-return" 18670818f58Stsien #define TOPO_METH_FMRI_ARG_FMRI "fmri" 18770818f58Stsien #define TOPO_METH_FMRI_ARG_SUBFMRI "sub-fmri" 18870818f58Stsien 1890eb822a1Scindi #define TOPO_METH_ASRU_COMPUTE "topo_asru_compute" 1900eb822a1Scindi #define TOPO_METH_ASRU_COMPUTE_VERSION 0 1910eb822a1Scindi #define TOPO_METH_ASRU_COMPUTE_DESC "Dynamic ASRU constructor" 1920eb822a1Scindi 1930eb822a1Scindi #define TOPO_METH_FRU_COMPUTE "topo_fru_compute" 1940eb822a1Scindi #define TOPO_METH_FRU_COMPUTE_VERSION 0 1950eb822a1Scindi #define TOPO_METH_FRU_COMPUTE_DESC "Dynamic FRU constructor" 1967aec1d6eScindi 19724db4641Seschrock #define TOPO_METH_DISK_STATUS "topo_disk_status" 19824db4641Seschrock #define TOPO_METH_DISK_STATUS_VERSION 0 19924db4641Seschrock #define TOPO_METH_DISK_STATUS_DESC "Disk status" 20024db4641Seschrock 201e5dcf7beSRobert Johnston #define TOPO_METH_SENSOR_FAILURE "topo_sensor_failure" 202e5dcf7beSRobert Johnston #define TOPO_METH_SENSOR_FAILURE_VERSION 0 203e5dcf7beSRobert Johnston #define TOPO_METH_SENSOR_FAILURE_DESC "Sensor failure state" 204e5dcf7beSRobert Johnston 205825ba0f2Srobj #define TOPO_PROP_METH_DESC "Dynamic Property method" 206825ba0f2Srobj 207825ba0f2Srobj #define TOPO_METH_IPMI_ENTITY "ipmi_entity" 208825ba0f2Srobj #define TOPO_METH_FAC_ENUM_DESC "Facility Enumerator" 209825ba0f2Srobj 2107aec1d6eScindi extern void *topo_mod_alloc(topo_mod_t *, size_t); 2117aec1d6eScindi extern void *topo_mod_zalloc(topo_mod_t *, size_t); 2127aec1d6eScindi extern void topo_mod_free(topo_mod_t *, void *, size_t); 2137aec1d6eScindi extern char *topo_mod_strdup(topo_mod_t *, const char *); 2147aec1d6eScindi extern void topo_mod_strfree(topo_mod_t *, char *); 2157aec1d6eScindi extern int topo_mod_nvalloc(topo_mod_t *, nvlist_t **, uint_t); 2167aec1d6eScindi extern int topo_mod_nvdup(topo_mod_t *, nvlist_t *, nvlist_t **); 2177aec1d6eScindi 2187aec1d6eScindi extern void topo_mod_clrdebug(topo_mod_t *); 2190eb822a1Scindi extern void topo_mod_setdebug(topo_mod_t *); 2207aec1d6eScindi extern void topo_mod_dprintf(topo_mod_t *, const char *, ...); 2217aec1d6eScindi extern const char *topo_mod_errmsg(topo_mod_t *); 2227aec1d6eScindi extern int topo_mod_errno(topo_mod_t *); 2237aec1d6eScindi 2247aec1d6eScindi /* 2257aec1d6eScindi * Topo node utilities: callable from module enumeration, topo_mod_enumerate() 2267aec1d6eScindi */ 2277aec1d6eScindi extern int topo_node_range_create(topo_mod_t *, tnode_t *, const char *, 2287aec1d6eScindi topo_instance_t, topo_instance_t); 2297aec1d6eScindi extern void topo_node_range_destroy(tnode_t *, const char *); 2307aec1d6eScindi extern tnode_t *topo_node_bind(topo_mod_t *, tnode_t *, const char *, 2310eb822a1Scindi topo_instance_t, nvlist_t *); 232825ba0f2Srobj extern tnode_t *topo_node_facbind(topo_mod_t *, tnode_t *, const char *, 233825ba0f2Srobj const char *); 2347aec1d6eScindi extern void topo_node_unbind(tnode_t *); 2350eb822a1Scindi extern void topo_node_setspecific(tnode_t *, void *); 2360eb822a1Scindi extern void *topo_node_getspecific(tnode_t *); 2370eb822a1Scindi extern int topo_node_asru_set(tnode_t *node, nvlist_t *, int, int *); 2380eb822a1Scindi extern int topo_node_fru_set(tnode_t *node, nvlist_t *, int, int *); 2390eb822a1Scindi extern int topo_node_label_set(tnode_t *node, char *, int *); 2400eb822a1Scindi 2410eb822a1Scindi #define TOPO_ASRU_COMPUTE 0x0001 /* Compute ASRU dynamically */ 2420eb822a1Scindi #define TOPO_FRU_COMPUTE 0x0002 /* Compute FRU dynamically */ 2437aec1d6eScindi 244c40d7343Scindi extern int topo_prop_inherit(tnode_t *, const char *, const char *, int *); 245c40d7343Scindi extern int topo_pgroup_create(tnode_t *, const topo_pgroup_info_t *, int *); 246c40d7343Scindi 247c40d7343Scindi /* 248c40d7343Scindi * Topo property method registration 249c40d7343Scindi */ 250c40d7343Scindi extern int topo_prop_method_register(tnode_t *, const char *, const char *, 251c40d7343Scindi topo_type_t, const char *, const nvlist_t *, int *); 252c40d7343Scindi extern void topo_prop_method_unregister(tnode_t *, const char *, const char *); 253c40d7343Scindi 2547aec1d6eScindi /* 2557aec1d6eScindi * This enum definition is used to define a set of error tags associated with 2560eb822a1Scindi * the module api error conditions. The shell script mkerror.sh is 2577aec1d6eScindi * used to parse this file and create a corresponding topo_error.c source file. 2587aec1d6eScindi * If you do something other than add a new error tag here, you may need to 2597aec1d6eScindi * update the mkerror shell script as it is based upon simple regexps. 2607aec1d6eScindi */ 2617aec1d6eScindi typedef enum topo_mod_errno { 2627aec1d6eScindi EMOD_UNKNOWN = 2000, /* unknown libtopo error */ 2637aec1d6eScindi EMOD_NOMEM, /* module memory limit exceeded */ 2647aec1d6eScindi EMOD_PARTIAL_ENUM, /* module completed partial enumeration */ 2657aec1d6eScindi EMOD_METHOD_INVAL, /* method arguments invalid */ 2667aec1d6eScindi EMOD_METHOD_NOTSUP, /* method not supported */ 2677aec1d6eScindi EMOD_FMRI_NVL, /* nvlist allocation failure for FMRI */ 2687aec1d6eScindi EMOD_FMRI_VERSION, /* invalid FMRI scheme version */ 2697aec1d6eScindi EMOD_FMRI_MALFORM, /* malformed FMRI */ 270825ba0f2Srobj EMOD_NODE_BOUND, /* node already bound */ 271825ba0f2Srobj EMOD_NODE_DUP, /* duplicate node */ 272825ba0f2Srobj EMOD_NODE_NOENT, /* node not found */ 273825ba0f2Srobj EMOD_NODE_RANGE, /* invalid node range */ 2740eb822a1Scindi EMOD_VER_ABI, /* registered with invalid ABI version */ 2750eb822a1Scindi EMOD_VER_OLD, /* attempt to load obsolete module */ 2760eb822a1Scindi EMOD_VER_NEW, /* attempt to load a newer module */ 2777aec1d6eScindi EMOD_NVL_INVAL, /* invalid nvlist */ 2787aec1d6eScindi EMOD_NONCANON, /* non-canonical component name requested */ 2790eb822a1Scindi EMOD_MOD_NOENT, /* module lookup failed */ 2800eb822a1Scindi EMOD_UKNOWN_ENUM, /* unknown enumeration error */ 2817aec1d6eScindi EMOD_END /* end of mod errno list (to ease auto-merge) */ 2827aec1d6eScindi } topo_mod_errno_t; 2837aec1d6eScindi 2847aec1d6eScindi extern int topo_mod_seterrno(topo_mod_t *, int); 2857aec1d6eScindi 2867aec1d6eScindi #ifdef __cplusplus 2877aec1d6eScindi } 2887aec1d6eScindi #endif 2897aec1d6eScindi 2907aec1d6eScindi #endif /* _TOPO_MOD_H */ 291