11414Scindi /* 21414Scindi * CDDL HEADER START 31414Scindi * 41414Scindi * The contents of this file are subject to the terms of the 51414Scindi * Common Development and Distribution License (the "License"). 61414Scindi * You may not use this file except in compliance with the License. 71414Scindi * 81414Scindi * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 91414Scindi * or http://www.opensolaris.org/os/licensing. 101414Scindi * See the License for the specific language governing permissions 111414Scindi * and limitations under the License. 121414Scindi * 131414Scindi * When distributing Covered Code, include this CDDL HEADER in each 141414Scindi * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 151414Scindi * If applicable, add the following below this CDDL HEADER, with the 161414Scindi * fields enclosed by brackets "[]" replaced with your own identifying 171414Scindi * information: Portions Copyright [yyyy] [name of copyright owner] 181414Scindi * 191414Scindi * CDDL HEADER END 201414Scindi */ 211414Scindi 221414Scindi /* 23*12967Sgavin.maltby@oracle.com * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. 241414Scindi */ 251414Scindi 261414Scindi #ifndef _TOPO_MOD_H 271414Scindi #define _TOPO_MOD_H 281414Scindi 291414Scindi #include <fm/libtopo.h> 303062Scindi #include <fm/topo_hc.h> 316070Srobj #include <libipmi.h> 321414Scindi #include <libnvpair.h> 333062Scindi #include <libdevinfo.h> 349632SEric.Schrock@Sun.COM #include <smbios.h> 351414Scindi 361414Scindi #ifdef __cplusplus 371414Scindi extern "C" { 381414Scindi #endif 391414Scindi 401414Scindi /* 411414Scindi * Enumerator and method supplier module API 421414Scindi */ 431414Scindi typedef struct topo_mod topo_mod_t; 441414Scindi 451414Scindi typedef int topo_method_f(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *, 461414Scindi nvlist_t **); 471414Scindi typedef int topo_enum_f(topo_mod_t *, tnode_t *, const char *, topo_instance_t, 483062Scindi topo_instance_t, void *, void *); 491414Scindi typedef void topo_release_f(topo_mod_t *, tnode_t *); 501414Scindi 511414Scindi typedef struct topo_method { 521414Scindi const char *tm_name; /* Method name */ 531414Scindi const char *tm_desc; /* Method description */ 541414Scindi const topo_version_t tm_version; /* Method version */ 551414Scindi const topo_stability_t tm_stability; /* Attributes of method */ 561414Scindi topo_method_f *tm_func; /* Method function */ 571414Scindi } topo_method_t; 581414Scindi 593062Scindi typedef struct topo_modops { 603062Scindi topo_enum_f *tmo_enum; /* enumeration op */ 613062Scindi topo_release_f *tmo_release; /* resource release op */ 623062Scindi } topo_modops_t; 633062Scindi 641414Scindi typedef struct topo_mod_info { 653062Scindi const char *tmi_desc; /* module description */ 663062Scindi const char *tmi_scheme; /* enumeration scheme type */ 673062Scindi topo_version_t tmi_version; /* module version */ 683062Scindi const topo_modops_t *tmi_ops; /* module ops vector */ 691414Scindi } topo_modinfo_t; 701414Scindi 713062Scindi extern topo_mod_t *topo_mod_load(topo_mod_t *, const char *, topo_version_t); 721414Scindi extern void topo_mod_unload(topo_mod_t *); 733062Scindi extern int topo_mod_register(topo_mod_t *, const topo_modinfo_t *, 743062Scindi topo_version_t); 751414Scindi extern void topo_mod_unregister(topo_mod_t *); 761414Scindi extern int topo_mod_enumerate(topo_mod_t *, tnode_t *, const char *, 773062Scindi const char *, topo_instance_t, topo_instance_t, void *); 783062Scindi extern int topo_mod_enummap(topo_mod_t *mod, tnode_t *, const char *, 793062Scindi const char *); 801414Scindi extern void topo_mod_release(topo_mod_t *, tnode_t *); 813062Scindi extern void topo_mod_setspecific(topo_mod_t *, void *); 823062Scindi extern void *topo_mod_getspecific(topo_mod_t *); 833062Scindi 843062Scindi extern nvlist_t *topo_mod_cpufmri(topo_mod_t *, int, uint32_t, uint8_t, 853062Scindi const char *); 863062Scindi extern nvlist_t *topo_mod_devfmri(topo_mod_t *, int, const char *, 873062Scindi const char *); 883062Scindi extern nvlist_t *topo_mod_hcfmri(topo_mod_t *, tnode_t *, int, const char *, 893062Scindi topo_instance_t, nvlist_t *, nvlist_t *, const char *, const char *, 903062Scindi const char *); 913062Scindi extern nvlist_t *topo_mod_memfmri(topo_mod_t *, int, uint64_t, uint64_t, 923062Scindi const char *, int); 933062Scindi extern nvlist_t *topo_mod_modfmri(topo_mod_t *, int, const char *); 943062Scindi extern nvlist_t *topo_mod_pkgfmri(topo_mod_t *, int, const char *); 95*12967Sgavin.maltby@oracle.com extern nvlist_t *topo_mod_swfmri(topo_mod_t *, int, 96*12967Sgavin.maltby@oracle.com char *, char *, nvlist_t *, 97*12967Sgavin.maltby@oracle.com char *, char *, char *, char *, int64_t, 98*12967Sgavin.maltby@oracle.com char *, char *, int64_t, char *, int64_t, char **, uint_t); 993062Scindi extern int topo_mod_nvl2str(topo_mod_t *, nvlist_t *, char **); 1003062Scindi extern int topo_mod_str2nvl(topo_mod_t *, const char *, nvlist_t **); 1017243Srobj extern int topo_prop_setmutable(tnode_t *node, const char *pgname, 1027243Srobj const char *pname, int *err); 1038526SRobert.Johnston@Sun.COM extern int topo_prop_setnonvolatile(tnode_t *node, const char *pgname, 1048526SRobert.Johnston@Sun.COM const char *pname, int *err); 1053062Scindi /* 1064087Scindi * Snapshot walker support 1074087Scindi */ 1084087Scindi typedef int (*topo_mod_walk_cb_t)(topo_mod_t *, tnode_t *, void *); 1094087Scindi 1104087Scindi extern topo_walk_t *topo_mod_walk_init(topo_mod_t *, tnode_t *, 1114087Scindi topo_mod_walk_cb_t, void *, int *); 1124087Scindi 1134087Scindi /* 1143062Scindi * Flags for topo_mod_memfmri 1153062Scindi */ 1163062Scindi #define TOPO_MEMFMRI_PA 0x0001 /* Valid physical address */ 1173062Scindi #define TOPO_MEMFMRI_OFFSET 0x0002 /* Valid offset */ 1181414Scindi 1191414Scindi extern int topo_method_register(topo_mod_t *, tnode_t *, const topo_method_t *); 1201414Scindi extern void topo_method_unregister(topo_mod_t *, tnode_t *, const char *); 1211414Scindi extern void topo_method_unregister_all(topo_mod_t *, tnode_t *); 1221414Scindi 1233062Scindi extern di_node_t topo_mod_devinfo(topo_mod_t *); 1247462SEric.Schrock@Sun.COM extern ipmi_handle_t *topo_mod_ipmi_hold(topo_mod_t *); 1257462SEric.Schrock@Sun.COM extern void topo_mod_ipmi_rele(topo_mod_t *); 1269632SEric.Schrock@Sun.COM extern smbios_hdl_t *topo_mod_smbios(topo_mod_t *); 1273062Scindi extern di_prom_handle_t topo_mod_prominfo(topo_mod_t *); 1283062Scindi extern nvlist_t *topo_mod_auth(topo_mod_t *, tnode_t *); 1293062Scindi 1308526SRobert.Johnston@Sun.COM extern int topo_method_sensor_failure(topo_mod_t *, tnode_t *, topo_version_t, 1318526SRobert.Johnston@Sun.COM nvlist_t *, nvlist_t **); 1328526SRobert.Johnston@Sun.COM 1331414Scindi /* 1341414Scindi * FMRI methods 1351414Scindi */ 1361414Scindi #define TOPO_METH_LABEL "topo_label" 1374087Scindi #define TOPO_METH_LABEL_DESC "label constructor" 1383062Scindi #define TOPO_METH_LABEL_VERSION0 0 1393062Scindi #define TOPO_METH_LABEL_VERSION TOPO_METH_LABEL_VERSION0 1407243Srobj #define TOPO_METH_LABEL_ARG_NVL "label-specific" 1417243Srobj #define TOPO_METH_LABEL_RET_STR "label-string" 1421414Scindi 1433062Scindi #define TOPO_METH_PRESENT "topo_present" 1444087Scindi #define TOPO_METH_PRESENT_DESC "presence indicator" 1453062Scindi #define TOPO_METH_PRESENT_VERSION0 0 1463062Scindi #define TOPO_METH_PRESENT_VERSION TOPO_METH_PRESENT_VERSION0 1473062Scindi #define TOPO_METH_PRESENT_RET "present-ret" 1481414Scindi 1497275Sstephh #define TOPO_METH_REPLACED "topo_replaced" 1507275Sstephh #define TOPO_METH_REPLACED_DESC "replaced indicator" 1517275Sstephh #define TOPO_METH_REPLACED_VERSION0 0 1527275Sstephh #define TOPO_METH_REPLACED_VERSION TOPO_METH_REPLACED_VERSION0 1537275Sstephh #define TOPO_METH_REPLACED_RET "replaced-ret" 1547275Sstephh 1553681Svn83148 #define TOPO_METH_UNUSABLE "topo_unusable" 1564087Scindi #define TOPO_METH_UNUSABLE_DESC "unusable indicator" 1573681Svn83148 #define TOPO_METH_UNUSABLE_VERSION0 0 1583681Svn83148 #define TOPO_METH_UNUSABLE_VERSION TOPO_METH_UNUSABLE_VERSION0 1593681Svn83148 #define TOPO_METH_UNUSABLE_RET "unusable-ret" 1603681Svn83148 1617275Sstephh #define TOPO_METH_SERVICE_STATE "topo_service_state" 1627275Sstephh #define TOPO_METH_SERVICE_STATE_DESC "service_state indicator" 1637275Sstephh #define TOPO_METH_SERVICE_STATE_VERSION0 0 1647275Sstephh #define TOPO_METH_SERVICE_STATE_VERSION TOPO_METH_SERVICE_STATE_VERSION0 1657275Sstephh #define TOPO_METH_SERVICE_STATE_RET "service_state-ret" 1667275Sstephh 1677532SSean.Ye@Sun.COM #define TOPO_METH_RETIRE "topo_retire" 1687532SSean.Ye@Sun.COM #define TOPO_METH_RETIRE_DESC "retire action" 1697532SSean.Ye@Sun.COM #define TOPO_METH_RETIRE_VERSION0 0 1707532SSean.Ye@Sun.COM #define TOPO_METH_RETIRE_VERSION TOPO_METH_RETIRE_VERSION0 1717532SSean.Ye@Sun.COM #define TOPO_METH_RETIRE_RET "retire-ret" 1727532SSean.Ye@Sun.COM 1737532SSean.Ye@Sun.COM #define TOPO_METH_UNRETIRE "topo_unretire" 1747532SSean.Ye@Sun.COM #define TOPO_METH_UNRETIRE_DESC "unretire action" 1757532SSean.Ye@Sun.COM #define TOPO_METH_UNRETIRE_VERSION0 0 1767532SSean.Ye@Sun.COM #define TOPO_METH_UNRETIRE_VERSION TOPO_METH_UNRETIRE_VERSION0 1777532SSean.Ye@Sun.COM #define TOPO_METH_UNRETIRE_RET "unretire-ret" 1787532SSean.Ye@Sun.COM 1793681Svn83148 #define TOPO_METH_EXPAND "topo_expand" 1803681Svn83148 #define TOPO_METH_EXPAND_DESC "expand FMRI" 1813681Svn83148 #define TOPO_METH_EXPAND_VERSION0 0 1823681Svn83148 #define TOPO_METH_EXPAND_VERSION TOPO_METH_EXPAND_VERSION0 1833681Svn83148 1846828Stsien #define TOPO_METH_CONTAINS "topo_contains" 1856828Stsien #define TOPO_METH_CONTAINS_DESC "FMRI contains sub-FMRI" 1866828Stsien #define TOPO_METH_CONTAINS_VERSION0 0 1876828Stsien #define TOPO_METH_CONTAINS_VERSION TOPO_METH_CONTAINS_VERSION0 1886828Stsien #define TOPO_METH_CONTAINS_RET "contains-return" 1896828Stsien #define TOPO_METH_FMRI_ARG_FMRI "fmri" 1906828Stsien #define TOPO_METH_FMRI_ARG_SUBFMRI "sub-fmri" 1916828Stsien 1923062Scindi #define TOPO_METH_ASRU_COMPUTE "topo_asru_compute" 1933062Scindi #define TOPO_METH_ASRU_COMPUTE_VERSION 0 1943062Scindi #define TOPO_METH_ASRU_COMPUTE_DESC "Dynamic ASRU constructor" 1951414Scindi 1963062Scindi #define TOPO_METH_FRU_COMPUTE "topo_fru_compute" 1973062Scindi #define TOPO_METH_FRU_COMPUTE_VERSION 0 1983062Scindi #define TOPO_METH_FRU_COMPUTE_DESC "Dynamic FRU constructor" 1991414Scindi 2004198Seschrock #define TOPO_METH_DISK_STATUS "topo_disk_status" 2014198Seschrock #define TOPO_METH_DISK_STATUS_VERSION 0 2024198Seschrock #define TOPO_METH_DISK_STATUS_DESC "Disk status" 2034198Seschrock 2048526SRobert.Johnston@Sun.COM #define TOPO_METH_SENSOR_FAILURE "topo_sensor_failure" 2058526SRobert.Johnston@Sun.COM #define TOPO_METH_SENSOR_FAILURE_VERSION 0 2068526SRobert.Johnston@Sun.COM #define TOPO_METH_SENSOR_FAILURE_DESC "Sensor failure state" 2078526SRobert.Johnston@Sun.COM 2087243Srobj #define TOPO_PROP_METH_DESC "Dynamic Property method" 2097243Srobj 2107243Srobj #define TOPO_METH_IPMI_ENTITY "ipmi_entity" 2117243Srobj #define TOPO_METH_FAC_ENUM_DESC "Facility Enumerator" 2127243Srobj 2131414Scindi extern void *topo_mod_alloc(topo_mod_t *, size_t); 2141414Scindi extern void *topo_mod_zalloc(topo_mod_t *, size_t); 2151414Scindi extern void topo_mod_free(topo_mod_t *, void *, size_t); 2161414Scindi extern char *topo_mod_strdup(topo_mod_t *, const char *); 2171414Scindi extern void topo_mod_strfree(topo_mod_t *, char *); 2181414Scindi extern int topo_mod_nvalloc(topo_mod_t *, nvlist_t **, uint_t); 2191414Scindi extern int topo_mod_nvdup(topo_mod_t *, nvlist_t *, nvlist_t **); 2201414Scindi 2211414Scindi extern void topo_mod_clrdebug(topo_mod_t *); 2223062Scindi extern void topo_mod_setdebug(topo_mod_t *); 2231414Scindi extern void topo_mod_dprintf(topo_mod_t *, const char *, ...); 2241414Scindi extern const char *topo_mod_errmsg(topo_mod_t *); 2251414Scindi extern int topo_mod_errno(topo_mod_t *); 2261414Scindi 2271414Scindi /* 2281414Scindi * Topo node utilities: callable from module enumeration, topo_mod_enumerate() 2291414Scindi */ 2301414Scindi extern int topo_node_range_create(topo_mod_t *, tnode_t *, const char *, 2311414Scindi topo_instance_t, topo_instance_t); 2321414Scindi extern void topo_node_range_destroy(tnode_t *, const char *); 2331414Scindi extern tnode_t *topo_node_bind(topo_mod_t *, tnode_t *, const char *, 2343062Scindi topo_instance_t, nvlist_t *); 2357243Srobj extern tnode_t *topo_node_facbind(topo_mod_t *, tnode_t *, const char *, 2367243Srobj const char *); 2371414Scindi extern void topo_node_unbind(tnode_t *); 2383062Scindi extern void topo_node_setspecific(tnode_t *, void *); 2393062Scindi extern void *topo_node_getspecific(tnode_t *); 2403062Scindi extern int topo_node_asru_set(tnode_t *node, nvlist_t *, int, int *); 2413062Scindi extern int topo_node_fru_set(tnode_t *node, nvlist_t *, int, int *); 2423062Scindi extern int topo_node_label_set(tnode_t *node, char *, int *); 2433062Scindi 2443062Scindi #define TOPO_ASRU_COMPUTE 0x0001 /* Compute ASRU dynamically */ 2453062Scindi #define TOPO_FRU_COMPUTE 0x0002 /* Compute FRU dynamically */ 2461414Scindi 2474087Scindi extern int topo_prop_inherit(tnode_t *, const char *, const char *, int *); 2484087Scindi extern int topo_pgroup_create(tnode_t *, const topo_pgroup_info_t *, int *); 2494087Scindi 2504087Scindi /* 2514087Scindi * Topo property method registration 2524087Scindi */ 2534087Scindi extern int topo_prop_method_register(tnode_t *, const char *, const char *, 2544087Scindi topo_type_t, const char *, const nvlist_t *, int *); 2554087Scindi extern void topo_prop_method_unregister(tnode_t *, const char *, const char *); 2564087Scindi 2574087Scindi /* 2581414Scindi * This enum definition is used to define a set of error tags associated with 2593062Scindi * the module api error conditions. The shell script mkerror.sh is 2601414Scindi * used to parse this file and create a corresponding topo_error.c source file. 2611414Scindi * If you do something other than add a new error tag here, you may need to 2621414Scindi * update the mkerror shell script as it is based upon simple regexps. 2631414Scindi */ 2641414Scindi typedef enum topo_mod_errno { 2651414Scindi EMOD_UNKNOWN = 2000, /* unknown libtopo error */ 2661414Scindi EMOD_NOMEM, /* module memory limit exceeded */ 2671414Scindi EMOD_PARTIAL_ENUM, /* module completed partial enumeration */ 2681414Scindi EMOD_METHOD_INVAL, /* method arguments invalid */ 2691414Scindi EMOD_METHOD_NOTSUP, /* method not supported */ 2701414Scindi EMOD_FMRI_NVL, /* nvlist allocation failure for FMRI */ 2711414Scindi EMOD_FMRI_VERSION, /* invalid FMRI scheme version */ 2721414Scindi EMOD_FMRI_MALFORM, /* malformed FMRI */ 2737243Srobj EMOD_NODE_BOUND, /* node already bound */ 2747243Srobj EMOD_NODE_DUP, /* duplicate node */ 2757243Srobj EMOD_NODE_NOENT, /* node not found */ 2767243Srobj EMOD_NODE_RANGE, /* invalid node range */ 2773062Scindi EMOD_VER_ABI, /* registered with invalid ABI version */ 2783062Scindi EMOD_VER_OLD, /* attempt to load obsolete module */ 2793062Scindi EMOD_VER_NEW, /* attempt to load a newer module */ 2801414Scindi EMOD_NVL_INVAL, /* invalid nvlist */ 2811414Scindi EMOD_NONCANON, /* non-canonical component name requested */ 2823062Scindi EMOD_MOD_NOENT, /* module lookup failed */ 2833062Scindi EMOD_UKNOWN_ENUM, /* unknown enumeration error */ 2841414Scindi EMOD_END /* end of mod errno list (to ease auto-merge) */ 2851414Scindi } topo_mod_errno_t; 2861414Scindi 2871414Scindi extern int topo_mod_seterrno(topo_mod_t *, int); 2881414Scindi 2891414Scindi #ifdef __cplusplus 2901414Scindi } 2911414Scindi #endif 2921414Scindi 2931414Scindi #endif /* _TOPO_MOD_H */ 294