hc.c revision 1db96d3b343c9ab3090da5b745f1cd9de2f192ef
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * See the License for the specific language governing permissions
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * and limitations under the License.
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 * CDDL HEADER END
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Use is subject to license terms.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int hc_enum(topo_mod_t *, tnode_t *, const char *, topo_instance_t,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_instance_t, void *, void *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int hc_fmri_nvl2str(topo_mod_t *, tnode_t *, topo_version_t,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int hc_fmri_str2nvl(topo_mod_t *, tnode_t *, topo_version_t,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int hc_compare(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *,
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic int hc_fmri_present(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *,
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephhstatic int hc_fmri_replaced(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *,
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic int hc_fmri_unusable(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Yestatic int hc_fmri_expand(topo_mod_t *, tnode_t *, topo_version_t,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Yestatic int hc_fmri_retire(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Yestatic int hc_fmri_unretire(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Yestatic int hc_fmri_service_state(topo_mod_t *, tnode_t *, topo_version_t,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int hc_fmri_create_meth(topo_mod_t *, tnode_t *, topo_version_t,
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic int hc_fmri_prop_get(topo_mod_t *, tnode_t *, topo_version_t,
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic int hc_fmri_prop_set(topo_mod_t *, tnode_t *, topo_version_t,
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic int hc_fmri_pgrp_get(topo_mod_t *, tnode_t *, topo_version_t,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robjstatic int hc_fmri_facility(topo_mod_t *, tnode_t *, topo_version_t,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic nvlist_t *hc_fmri_create(topo_mod_t *, nvlist_t *, int, const char *,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_instance_t inst, const nvlist_t *, const char *, const char *,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi const char *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi { TOPO_METH_NVL2STR, TOPO_METH_NVL2STR_DESC, TOPO_METH_NVL2STR_VERSION,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi { TOPO_METH_STR2NVL, TOPO_METH_STR2NVL_DESC, TOPO_METH_STR2NVL_VERSION,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi { TOPO_METH_COMPARE, TOPO_METH_COMPARE_DESC, TOPO_METH_COMPARE_VERSION,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi { TOPO_METH_PRESENT, TOPO_METH_PRESENT_DESC, TOPO_METH_PRESENT_VERSION,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye TOPO_METH_EXPAND_VERSION, TOPO_STABILITY_INTERNAL,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye TOPO_METH_RETIRE_VERSION, TOPO_STABILITY_INTERNAL,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye { TOPO_METH_UNRETIRE, TOPO_METH_UNRETIRE_DESC,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye TOPO_METH_UNRETIRE_VERSION, TOPO_STABILITY_INTERNAL,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye { TOPO_METH_SERVICE_STATE, TOPO_METH_SERVICE_STATE_DESC,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye TOPO_METH_SERVICE_STATE_VERSION, TOPO_STABILITY_INTERNAL,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi { TOPO_METH_FMRI, TOPO_METH_FMRI_DESC, TOPO_METH_FMRI_VERSION,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindistatic int hc_ncanon = sizeof (hc_canon) / sizeof (hcc_t);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Turn on module debugging output
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (topo_mod_register(mod, &hc_info, TOPO_VERSION) != 0) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (0);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (topo_pgroup_create(node, &auth_pgroup, &err) != 0) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * Inherit if we can, it saves memory
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj if ((topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (nvlist_lookup_string(auth, FM_FMRI_AUTH_PRODUCT, &prod)
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj if ((topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (nvlist_lookup_string(auth, FM_FMRI_AUTH_CHASSIS, &csn) == 0)
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj if ((topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_SERVER,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (nvlist_lookup_string(auth, FM_FMRI_AUTH_SERVER, &server)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (void) topo_prop_set_string(node, TOPO_PGROUP_SYSTEM, TOPO_PROP_ISA,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (void) topo_prop_set_string(node, TOPO_PGROUP_SYSTEM, TOPO_PROP_MACHINE,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
0eb822a1c0c2bea495647510b75f77f0e57633ebcindihc_enum(topo_mod_t *mod, tnode_t *pnode, const char *name, topo_instance_t min,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Register root node methods
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi "Request to enumerate %s component with an "
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi "ambiguous instance number, min (%d) != max (%d).\n",
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi nvl = hc_fmri_create(mod, pfmri, FM_HC_SCHEME_VERSION, name, min,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((node = topo_node_bind(mod, pnode, name, min, nvl)) == NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
47911a7d5f24c2fc37e7b5bcc696fe32e750c16ccy * Set FRU for the motherboard node
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
c40d7343efa60b18ad1ceb316eb337caeea79046cindifmri_compare(topo_mod_t *mod, nvlist_t *nv1, nvlist_t *nv2)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi v1 > FM_HC_SCHEME_VERSION || v2 > FM_HC_SCHEME_VERSION)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi err = nvlist_lookup_nvlist_array(nv1, FM_FMRI_HC_LIST, &hcp1, &nhcp1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi err |= nvlist_lookup_nvlist_array(nv2, FM_FMRI_HC_LIST, &hcp2, &nhcp2);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (i = 0; i < nhcp1; i++) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_lookup_string(hcp1[i], FM_FMRI_HC_NAME, &nm1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_lookup_string(hcp2[i], FM_FMRI_HC_NAME, &nm2);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_lookup_string(hcp1[i], FM_FMRI_HC_ID, &id1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_lookup_string(hcp2[i], FM_FMRI_HC_ID, &id2);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nm1 == NULL || nm2 == NULL || id1 == NULL || id2 == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * Finally, check if the FMRI's represent a facility node. If so, then
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * verify that the facilty type ("sensor"|"indicator") and facility
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * name match.
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj (void) nvlist_lookup_nvlist(nv1, FM_FMRI_FACILITY, &f1);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj (void) nvlist_lookup_nvlist(nv2, FM_FMRI_FACILITY, &f2);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (1);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (0);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj if (nvlist_lookup_string(f1, FM_FMRI_FACILITY_NAME, &f1str) == 0 &&
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj nvlist_lookup_string(f2, FM_FMRI_FACILITY_NAME, &f2str) == 0 &&
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj nvlist_lookup_string(f1, FM_FMRI_FACILITY_TYPE, &f1str) == 0 &&
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj nvlist_lookup_string(f2, FM_FMRI_FACILITY_TYPE, &f2str) == 0 &&
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (1);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi/*ARGSUSED*/
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_compare(topo_mod_t *mod, tnode_t *node, topo_version_t version,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_lookup_nvlist(in, TOPO_METH_FMRI_ARG_NV1, &nv1) != 0 ||
12cc75c814f0c017004a9bbc96429911e008601bcindi nvlist_lookup_nvlist(in, TOPO_METH_FMRI_ARG_NV2, &nv2) != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_mod_nvalloc(mod, out, NV_UNIQUE_NAME) == 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 ||
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* Get authority, if present */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi err = nvlist_lookup_nvlist(nvl, FM_FMRI_AUTHORITY, &anvl);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((err = nvlist_lookup_string(nvl, FM_FMRI_HC_ROOT, &root)) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi err = nvlist_lookup_nvlist_array(nvl, FM_FMRI_HC_LIST, &hcprs, &hcnprs);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_lookup_string(nvl, FM_FMRI_HC_SERIAL_ID, &serial);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_lookup_string(nvl, FM_FMRI_HC_PART, &part);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_lookup_string(nvl, FM_FMRI_HC_REVISION, &rev);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* hc:// */
74a31ce69a88d851777ca840d31ec610ce9ecab3timh topo_fmristr_build(&size, buf, buflen, FM_FMRI_SCHEME_HC, NULL, "://");
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* authority, if any */
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi buf, buflen, aprod, ":" FM_FMRI_AUTH_PRODUCT "=", NULL);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi buf, buflen, achas, ":" FM_FMRI_AUTH_CHASSIS "=", NULL);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi buf, buflen, adom, ":" FM_FMRI_AUTH_DOMAIN "=", NULL);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi buf, buflen, asrvr, ":" FM_FMRI_AUTH_SERVER "=", NULL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* hardware-id part */
74a31ce69a88d851777ca840d31ec610ce9ecab3timh buf, buflen, serial, ":" FM_FMRI_HC_SERIAL_ID "=", NULL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* separating slash */
74a31ce69a88d851777ca840d31ec610ce9ecab3timh topo_fmristr_build(&size, buf, buflen, "/", NULL, NULL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* hc-root */
74a31ce69a88d851777ca840d31ec610ce9ecab3timh topo_fmristr_build(&size, buf, buflen, root, NULL, NULL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* all the pairs */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (i = 0; i < hcnprs; i++) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_lookup_string(hcprs[i], FM_FMRI_HC_NAME, &nm);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_lookup_string(hcprs[i], FM_FMRI_HC_ID, &id);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
74a31ce69a88d851777ca840d31ec610ce9ecab3timh topo_fmristr_build(&size, buf, buflen, id, NULL, NULL);
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye /* append offset/physaddr if it exists in hc-specific */
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if (nvlist_lookup_nvlist(nvl, FM_FMRI_HC_SPECIFIC, &hcsp) == 0) {
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if (nvlist_lookup_uint64(hcsp, FM_FMRI_HC_SPECIFIC_OFFSET,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye "asru-" FM_FMRI_HC_SPECIFIC_OFFSET, &val) == 0)
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye "asru-" FM_FMRI_HC_SPECIFIC_PHYSADDR, &val) == 0)
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye (void) snprintf(hexstr, sizeof (hexstr), "%llx", val);
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye topo_fmristr_build(&size, buf, buflen, "/", NULL, NULL);
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye topo_fmristr_build(&size, buf, buflen, "=", hcsn,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * If the nvlist represents a facility node, then we append the
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * facility type and name to the end of the string representation using
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * the format below:
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * ?<ftype>=<fname>
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj if (nvlist_lookup_nvlist(nvl, FM_FMRI_FACILITY, &fnvl) == 0) {
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (0);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj topo_fmristr_build(&size, buf, buflen, "?", NULL, NULL);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj topo_fmristr_build(&size, buf, buflen, "=", ftype, fname);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindihc_fmri_nvl2str(topo_mod_t *mod, tnode_t *node, topo_version_t version,
12cc75c814f0c017004a9bbc96429911e008601bcindi if (topo_mod_nvalloc(mod, &fmristr, NV_UNIQUE_NAME) != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_add_string(fmristr, "fmri-string", name) != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindihc_base_fmri_create(topo_mod_t *mod, const nvlist_t *auth, const char *part,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Create base HC nvlist
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (topo_mod_nvalloc(mod, &fmri, NV_UNIQUE_NAME) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi err = nvlist_add_uint8(fmri, FM_VERSION, FM_HC_SCHEME_VERSION);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi err |= nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_HC);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (err != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Add optional payload members
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_add_string(fmri, FM_FMRI_HC_SERIAL_ID, serial);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_add_string(fmri, FM_FMRI_HC_PART, part);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_add_string(fmri, FM_FMRI_HC_REVISION, rev);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Count equal signs and slashes to determine how many
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * hc-pairs will be present in the final FMRI. There should
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * be at least as many slashes as equal signs. There can be
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * more, though if the string after an = includes them.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Do we appear to have a well-formed string version of the FMRI?
12cc75c814f0c017004a9bbc96429911e008601bcindi if ((pa = topo_mod_zalloc(mod, npairs * sizeof (nvlist_t *))) == NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * We go through a pretty complicated procedure to find the
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * name and id for each pair. That's because, unfortunately,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * we have some ids that can have slashes within them. So
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * we can't just search for the next slash after the equal sign
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * and decide that starts a new pair. Instead we have to find
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * an equal sign for the next pair and work our way back to the
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * slash from there.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (i = 0; i < npairs; i++) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_mod_nvalloc(mod, &pa[i], NV_UNIQUE_NAME) < 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_add_string(pa[i], FM_FMRI_HC_NAME, cname) ||
12cc75c814f0c017004a9bbc96429911e008601bcindi for (i = 0; i < npairs; i++)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindimake_hc_auth(topo_mod_t *mod, char *fmri, char **serial, char **part,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (-1);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * Make sure there are a valid authority members
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (0);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * The first colon we encounter must occur before the
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * first slash
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * Return possible serial, part and revision
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (0);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (-1);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * This function creates an nvlist to represent the facility portion of an
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * hc-scheme node, given a string representation of the fmri. This is called by
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * hc_fmri_str2nvl. If the string does not contain a facility component
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * (e.g. ?<ftype>=<fname>) then it bails early and returns 0.
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * On failure it returns -1 and sets the topo mod errno
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robjmake_facility(topo_mod_t *mod, char *str, nvlist_t **nvl)
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (0);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj if (nvlist_add_string(nf, FM_FMRI_FACILITY_NAME, fname) != 0 ||
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj nvlist_add_string(nf, FM_FMRI_FACILITY_TYPE, ftype) != 0) {
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindihc_fmri_str2nvl(topo_mod_t *mod, tnode_t *node, topo_version_t version,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye char *serial = NULL, *part = NULL, *rev = NULL, *hcsn = NULL;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_string(in, "fmri-string", &str) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* We're expecting a string version of an hc scheme FMRI */
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj if (make_hc_auth(mod, str, &serial, &part, &rev, &auth) < 0)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((nf = hc_base_fmri_create(mod, auth, part, rev, serial)) == NULL)
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye * If the last pair in hc-list is offset or physaddr, we move
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye * it to hc-specific.
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye (void) nvlist_lookup_string(pa[npairs - 1], FM_FMRI_HC_NAME, &hcsn);
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if (strcmp(hcsn, FM_FMRI_HC_SPECIFIC_OFFSET) == 0 ||
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye strcmp(hcsn, FM_FMRI_HC_SPECIFIC_PHYSADDR) == 0) {
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye (void) nvlist_lookup_string(pa[npairs - 1], FM_FMRI_HC_ID,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if (topo_mod_nvalloc(mod, &hcsp, NV_UNIQUE_NAME) != 0)
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if (nvlist_add_uint64(hcsp, hcsn, val) != 0 ||
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye nvlist_add_nvlist(nf, FM_FMRI_HC_SPECIFIC, hcsp) != 0) {
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if ((e = nvlist_add_uint32(nf, FM_FMRI_HC_LIST_SZ, n)) == 0)
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye e = nvlist_add_nvlist_array(nf, FM_FMRI_HC_LIST, pa, n);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (e != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_mod_dprintf(mod, "construction of new hc nvl failed");
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * Clean-up
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (i = 0; i < npairs; i++)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (i = 0; i < npairs; i++)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindihc_list_create(topo_mod_t *mod, const char *name, char *inst)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (err != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindihc_create_seterror(topo_mod_t *mod, nvlist_t **hcl, int n, nvlist_t *fmri,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (i = 0; i < n + 1; ++i)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_mod_free(mod, hcl, sizeof (nvlist_t *) * (n + 1));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_mod_dprintf(mod, "unable to create hc FMRI: %s\n",
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Only enumerate elements with correct canonical names
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi for (i = 0; i < hc_ncanon; i++) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindihc_fmri_create(topo_mod_t *mod, nvlist_t *pfmri, int version, const char *name,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_instance_t inst, const nvlist_t *auth, const char *part,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Check that the requested name is in our canonical list
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Copy the parent's HC_LIST
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_nvlist_array(pfmri, FM_FMRI_HC_LIST,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi hcl = topo_mod_zalloc(mod, sizeof (nvlist_t *) * (pelems + 1));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (i = 0; i < pelems; ++i)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((hcl[i] = hc_list_create(mod, name, str)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((fmri = hc_base_fmri_create(mod, auth, part, rev, serial)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_add_nvlist_array(fmri, FM_FMRI_HC_LIST, hcl, pelems + 1)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_mod_free(mod, hcl, sizeof (nvlist_t *) * (pelems + 1));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
0eb822a1c0c2bea495647510b75f77f0e57633ebcindihc_fmri_create_meth(topo_mod_t *mod, tnode_t *node, topo_version_t version,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* First the must-have fields */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_string(in, TOPO_METH_FMRI_ARG_NAME, &name) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_uint32(in, TOPO_METH_FMRI_ARG_INST, &inst) != 0)
89c0ae934a35c2ab26de63e1d9fba6bcb04c6306cindi * args is optional
89c0ae934a35c2ab26de63e1d9fba6bcb04c6306cindi if ((ret = nvlist_lookup_nvlist(in, TOPO_METH_FMRI_ARG_NVL, &args))
89c0ae934a35c2ab26de63e1d9fba6bcb04c6306cindi /* And then optional arguments */
89c0ae934a35c2ab26de63e1d9fba6bcb04c6306cindi (void) nvlist_lookup_nvlist(args, TOPO_METH_FMRI_ARG_PARENT,
89c0ae934a35c2ab26de63e1d9fba6bcb04c6306cindi (void) nvlist_lookup_nvlist(args, TOPO_METH_FMRI_ARG_AUTH,
89c0ae934a35c2ab26de63e1d9fba6bcb04c6306cindi (void) nvlist_lookup_string(args, TOPO_METH_FMRI_ARG_PART,
89c0ae934a35c2ab26de63e1d9fba6bcb04c6306cindi (void) nvlist_lookup_string(args, TOPO_METH_FMRI_ARG_REV, &rev);
89c0ae934a35c2ab26de63e1d9fba6bcb04c6306cindi (void) nvlist_lookup_string(args, TOPO_METH_FMRI_ARG_SER,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *out = hc_fmri_create(mod, pfmri, version, name, inst, auth, part,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
940d71d237794874e18a0eb72f6564821a823517eschrock * Returns true if the given node is beneath the specified FMRI. This uses
940d71d237794874e18a0eb72f6564821a823517eschrock * the TOPO_METH_CONTAINS method, because some enumerators (such as external
940d71d237794874e18a0eb72f6564821a823517eschrock * enclosures) may want to do a comparison based on chassis WWN instead of the
940d71d237794874e18a0eb72f6564821a823517eschrock * instance ID. If this comparison function fails or is not supported, then we
940d71d237794874e18a0eb72f6564821a823517eschrock * fall back to a direct name/instance comparison.
940d71d237794874e18a0eb72f6564821a823517eschrockhc_match(topo_mod_t *mod, tnode_t *node, nvlist_t *fmri, const char *name,
940d71d237794874e18a0eb72f6564821a823517eschrock return (-1);
940d71d237794874e18a0eb72f6564821a823517eschrock if (topo_mod_nvalloc(mod, &arg, NV_UNIQUE_NAME) != 0 ||
940d71d237794874e18a0eb72f6564821a823517eschrock return (-1);
940d71d237794874e18a0eb72f6564821a823517eschrock TOPO_METH_CONTAINS_VERSION, arg, &nvl, &err) != 0) {
940d71d237794874e18a0eb72f6564821a823517eschrock return (-1);
940d71d237794874e18a0eb72f6564821a823517eschrock if (nvlist_lookup_uint32(nvl, TOPO_METH_CONTAINS_RET,
940d71d237794874e18a0eb72f6564821a823517eschrock return (-1);
940d71d237794874e18a0eb72f6564821a823517eschrock return (0);
940d71d237794874e18a0eb72f6564821a823517eschrock * Ideally, we should just be able to call topo_walk_bysibling(). But that
940d71d237794874e18a0eb72f6564821a823517eschrock * code assumes that the name/instance pair will match, so we need to
940d71d237794874e18a0eb72f6564821a823517eschrock * explicitly iterate over children of the parent looking for a matching value.
940d71d237794874e18a0eb72f6564821a823517eschrockhc_walk_sibling(topo_mod_t *mod, tnode_t *node, struct hc_walk *hwp,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Generic walker for the hc-scheme topo tree. This function uses the
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * hierachical nature of the hc-scheme to efficiently step through
78432d5ed5122db8b0bbfa41e00d063bf8ae7171cy * the topo hc tree. Node lookups are done by topo_walk_byid() and
78432d5ed5122db8b0bbfa41e00d063bf8ae7171cy * topo_walk_bysibling() at each component level to avoid unnecessary
78432d5ed5122db8b0bbfa41e00d063bf8ae7171cy * traversal of the tree. hc_walker() never returns TOPO_WALK_NEXT, so
78432d5ed5122db8b0bbfa41e00d063bf8ae7171cy * whether TOPO_WALK_CHILD or TOPO_WALK_SIBLING is specified by
78432d5ed5122db8b0bbfa41e00d063bf8ae7171cy * topo_walk_step() doesn't affect the traversal.
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj "complete: terminate walk\n");
c40d7343efa60b18ad1ceb316eb337caeea79046cindi err = nvlist_lookup_string(hwp->hcw_list[i], FM_FMRI_HC_NAME, &name);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi err |= nvlist_lookup_string(hwp->hcw_list[i], FM_FMRI_HC_ID, &id);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (err != 0) {
940d71d237794874e18a0eb72f6564821a823517eschrock * Check to see if our node matches the requested FMRI. If it doesn't
940d71d237794874e18a0eb72f6564821a823517eschrock * (because the enumerator determines matching based on something other
940d71d237794874e18a0eb72f6564821a823517eschrock * than name/instance, or because we're at the first level below the
940d71d237794874e18a0eb72f6564821a823517eschrock * root), then iterate over siblings to find the matching node.
940d71d237794874e18a0eb72f6564821a823517eschrock if (hc_match(mod, node, hwp->hcw_fmri, name, inst, &match) != 0)
940d71d237794874e18a0eb72f6564821a823517eschrock return (hc_walk_sibling(mod, node, hwp, name, inst));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_mod_dprintf(mod, "hc_walker: walking node:%s=%d for hc:"
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_instance(node), name, inst, i, hwp->hcw_end);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * We are at the end of the hc-list. Now, check for
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * a facility leaf and walk one more time.
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj if (err != 0) {
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * Otherwise, this is the node we're looking for.
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj if ((err = hwp->hcw_cb(mod, node, hwp->hcw_priv)) != 0) {
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj "complete: terminate walk\n");
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * Move on to the next component in the hc-list
c40d7343efa60b18ad1ceb316eb337caeea79046cindi err = nvlist_lookup_string(hwp->hcw_list[i], FM_FMRI_HC_NAME, &name);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi err |= nvlist_lookup_string(hwp->hcw_list[i], FM_FMRI_HC_ID, &id);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (err != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic struct hc_walk *
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_walk_init(topo_mod_t *mod, tnode_t *node, nvlist_t *rsrc,
918a0d8ae0916c29c35aae9b95c22b02a0c6e390robj if ((hwp = topo_mod_alloc(mod, sizeof (struct hc_walk))) == NULL) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_lookup_nvlist_array(rsrc, FM_FMRI_HC_LIST, &hwp->hcw_list,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj topo_mod_dprintf(mod, "hc_walk_init: failed to lookup %s "
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj if ((ret = nvlist_lookup_nvlist(rsrc, FM_FMRI_FACILITY, &hwp->hcw_fac))
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj topo_mod_dprintf(mod, "hc_walk_init: unexpected error "
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((wp = topo_mod_walk_init(mod, node, hc_walker, (void *)hwp, &err))
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj topo_mod_dprintf(mod, "hc_walk_init: topo_mod_walk_init failed "
c40d7343efa60b18ad1ceb316eb337caeea79046cindi const char *pl_pgroup;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi const char *pl_pname;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi/*ARGSUSED*/
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_prop_get(topo_mod_t *mod, tnode_t *node, void *pdata)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi struct prop_lookup *plp = (struct prop_lookup *)pdata;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) topo_prop_getprop(node, plp->pl_pgroup, plp->pl_pname,
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_fmri_prop_get(topo_mod_t *mod, tnode_t *node, topo_version_t version,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((plp = topo_mod_alloc(mod, sizeof (struct prop_lookup))) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi err |= nvlist_lookup_nvlist(in, TOPO_PROP_RESOURCE, &plp->pl_rsrc);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (err != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Private args to prop method are optional
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((err = nvlist_lookup_nvlist(in, TOPO_PROP_PARGS, &plp->pl_args))
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((hwp = hc_walk_init(mod, node, plp->pl_rsrc, hc_prop_get,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi/*ARGSUSED*/
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_pgrp_get(topo_mod_t *mod, tnode_t *node, void *pdata)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi struct prop_lookup *plp = (struct prop_lookup *)pdata;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) topo_prop_getpgrp(node, plp->pl_pgroup, &plp->pl_prop, &err);
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_fmri_pgrp_get(topo_mod_t *mod, tnode_t *node, topo_version_t version,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((plp = topo_mod_alloc(mod, sizeof (struct prop_lookup))) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi err |= nvlist_lookup_nvlist(in, TOPO_PROP_RESOURCE, &plp->pl_rsrc);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (err != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((hwp = hc_walk_init(mod, node, plp->pl_rsrc, hc_pgrp_get,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi/*ARGSUSED*/
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_prop_setprop(topo_mod_t *mod, tnode_t *node, void *pdata)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi struct prop_lookup *plp = (struct prop_lookup *)pdata;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) topo_prop_setprop(node, plp->pl_pgroup, plp->pl_prop,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi/*ARGSUSED*/
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_fmri_prop_set(topo_mod_t *mod, tnode_t *node, topo_version_t version,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((plp = topo_mod_alloc(mod, sizeof (struct prop_lookup))) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi err |= nvlist_lookup_nvlist(in, TOPO_PROP_RESOURCE, &plp->pl_rsrc);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi err |= nvlist_lookup_nvlist(in, TOPO_PROP_VAL, &plp->pl_prop);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi err |= nvlist_lookup_int32(in, TOPO_PROP_FLAG, &plp->pl_flag);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (err != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Private args to prop method are optional
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((err = nvlist_lookup_nvlist(in, TOPO_PROP_PARGS, &plp->pl_args))
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((hwp = hc_walk_init(mod, node, plp->pl_rsrc, hc_prop_setprop,
7793aa8b1cb26c7fc1397aa9db2364098fc25543Eric Schrockhc_auth_changed(nvlist_t *nva, nvlist_t *nvb, const char *propname)
7793aa8b1cb26c7fc1397aa9db2364098fc25543Eric Schrock if (nvlist_lookup_string(nva, propname, &stra) != 0 ||
7793aa8b1cb26c7fc1397aa9db2364098fc25543Eric Schrock nvlist_lookup_string(nvb, propname, &strb) != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_is_present(topo_mod_t *mod, tnode_t *node, void *pdata)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * check with the enumerator that created this FMRI
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * (topo node)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_PRESENT_VERSION, hap->ha_fmri, &hap->ha_nvl,
7793aa8b1cb26c7fc1397aa9db2364098fc25543Eric Schrock * If the method exists but failed for some other reason,
7793aa8b1cb26c7fc1397aa9db2364098fc25543Eric Schrock * propagate the error as making any decision over presence is
7793aa8b1cb26c7fc1397aa9db2364098fc25543Eric Schrock * impossible.
7793aa8b1cb26c7fc1397aa9db2364098fc25543Eric Schrock * Check the authority information. If the part id or serial
7793aa8b1cb26c7fc1397aa9db2364098fc25543Eric Schrock * number doesn't match, then it isn't the same FMRI.
7793aa8b1cb26c7fc1397aa9db2364098fc25543Eric Schrock * Otherwise, assume presence.
7793aa8b1cb26c7fc1397aa9db2364098fc25543Eric Schrock if (topo_node_resource(node, &rsrc, &err) != 0)
7793aa8b1cb26c7fc1397aa9db2364098fc25543Eric Schrock if (topo_mod_nvalloc(mod, &hap->ha_nvl, NV_UNIQUE_NAME) != 0)
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_fmri_present(topo_mod_t *mod, tnode_t *node, topo_version_t version,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((hap = topo_mod_alloc(mod, sizeof (struct hc_args))) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((hwp = hc_walk_init(mod, node, hap->ha_fmri, hc_is_present,
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephhhc_is_replaced(topo_mod_t *mod, tnode_t *node, void *pdata)
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh * check with the enumerator that created this FMRI
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh * (topo node)
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh TOPO_METH_REPLACED_VERSION, hap->ha_fmri, &hap->ha_nvl,
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh * enumerator didn't provide "replaced" method - so
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh * try "present" method
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh TOPO_METH_PRESENT_VERSION, hap->ha_fmri, &hap->ha_nvl,
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh /* no present method either - assume present */
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh return (0);
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh return (0);
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephhhc_fmri_replaced(topo_mod_t *mod, tnode_t *node, topo_version_t version,
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh return (topo_mod_seterrno(mod, ETOPO_METHOD_VERNEW));
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh if ((hap = topo_mod_alloc(mod, sizeof (struct hc_args))) == NULL)
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh if ((hwp = hc_walk_init(mod, node, hap->ha_fmri, hc_is_replaced,
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_unusable(topo_mod_t *mod, tnode_t *node, void *pdata)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * check with the enumerator that created this FMRI
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * (topo node)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_UNUSABLE_VERSION, hap->ha_fmri, &hap->ha_nvl,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Err on the side of caution and return usable
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_mod_nvalloc(mod, &hap->ha_nvl, NV_UNIQUE_NAME) == 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_fmri_unusable(topo_mod_t *mod, tnode_t *node, topo_version_t version,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((hap = topo_mod_alloc(mod, sizeof (struct hc_args))) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((hwp = hc_walk_init(mod, node, hap->ha_fmri, hc_unusable,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj const char *fl_fac_type;
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * Lookup the specified facility node. Return with an error if we can't
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * find it.
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj if (topo_node_facility(mod->tm_hdl, node, flp->fl_fac_type,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj topo_mod_dprintf(mod, "hc_fac_get: topo_node_facility "
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj "failed\n");
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * Invoke user's callback for each facility node in the topo list,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * passing in a pointer to the facility node
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj for (tmp = topo_list_next(&faclist.tf_list); tmp != NULL;
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj while ((tmp = topo_list_next(&faclist.tf_list)) != NULL) {
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robjhc_fmri_facility(topo_mod_t *mod, tnode_t *node, topo_version_t version,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj if ((flp = topo_mod_alloc(mod, sizeof (struct fac_lookup))) == NULL)
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * lookup arguments: hw resource, facility type, facility subtype,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * callback and callback args
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj err = nvlist_lookup_nvlist(in, TOPO_PROP_RESOURCE, &flp->fl_rsrc);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj err |= nvlist_lookup_uint32(in, "type", &flp->fl_fac_subtype);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj err |= nvlist_lookup_uint64(in, "callback", &flp->fl_callback);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj err |= nvlist_lookup_uint32(in, "callback", &flp->fl_callback);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj if (err != 0) {
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj topo_mod_dprintf(mod, "hc_fmri_facility: failed to construct "
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj "walker arg nvlist\n");
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj if ((hwp = hc_walk_init(mod, node, flp->fl_rsrc, hc_fac_get,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj topo_mod_dprintf(mod, "hc_fmri_facility: failed to initialize "
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj "hc walker\n");
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye/* ARGSUSED */
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Yehc_expand(topo_mod_t *mod, tnode_t *node, void *pdata)
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye const char **namep;
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye struct hc_args *hap = (struct hc_args *)pdata;
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye const char *names[] = {
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if (topo_node_resource(node, &nvl, &err) != 0)
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye for (namep = names; *namep != NULL; namep++) {
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if (nvlist_lookup_string(nvl, *namep, &node_val) != 0)
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if (nvlist_lookup_string(hap->ha_fmri, *namep, &in_val) == 0) {
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if (nvlist_add_string(hap->ha_fmri, *namep, node_val) != 0) {
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye/* ARGSUSED */
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Yehc_fmri_expand(topo_mod_t *mod, tnode_t *node, topo_version_t version,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye return (topo_mod_seterrno(mod, ETOPO_METHOD_VERNEW));
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if ((hap = topo_mod_alloc(mod, sizeof (struct hc_args))) == NULL)
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if ((hwp = hc_walk_init(mod, node, hap->ha_fmri, hc_expand,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if (topo_walk_step(hwp->hcw_wp, TOPO_WALK_CHILD) ==
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye topo_mod_free(mod, hwp, sizeof (struct hc_walk));
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye /* expand method should not return out nvlist */
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye topo_mod_free(mod, hap, sizeof (struct hc_args));
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Yehc_retire_subr(topo_mod_t *mod, tnode_t *node, void *pdata)
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye struct hc_args *hap = (struct hc_args *)pdata;
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye topo_mod_dprintf(mod, "hc_retire_subr: invoking method %s\n",
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye * check with the enumerator that created this FMRI
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye * (topo node)
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye rc = topo_method_invoke(node, hap->ha_method_name,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye hap->ha_method_ver, hap->ha_fmri, &hap->ha_nvl, &err);
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye topo_mod_dprintf(mod, "hc_retire_subr: invoking method %s "
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Yehc_fmri_retire_subr(topo_mod_t *mod, tnode_t *node, char *method_name,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye topo_version_t builtin_version, topo_version_t version, nvlist_t *in,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye return (topo_mod_seterrno(mod, ETOPO_METHOD_VERNEW));
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if ((hap = topo_mod_alloc(mod, sizeof (struct hc_args))) == NULL)
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if ((hwp = hc_walk_init(mod, node, hap->ha_fmri, hc_retire_subr,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if (topo_walk_step(hwp->hcw_wp, TOPO_WALK_CHILD) ==
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye topo_mod_free(mod, hwp, sizeof (struct hc_walk));
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye topo_mod_free(mod, hap, sizeof (struct hc_args));
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Yehc_fmri_retire(topo_mod_t *mod, tnode_t *node, topo_version_t version,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye return (hc_fmri_retire_subr(mod, node, TOPO_METH_RETIRE,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Yehc_fmri_unretire(topo_mod_t *mod, tnode_t *node, topo_version_t version,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye return (hc_fmri_retire_subr(mod, node, TOPO_METH_UNRETIRE,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye TOPO_METH_UNRETIRE_VERSION, version, in, out));
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Yehc_fmri_service_state(topo_mod_t *mod, tnode_t *node, topo_version_t version,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye return (hc_fmri_retire_subr(mod, node, TOPO_METH_SERVICE_STATE,