7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER START
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * The contents of this file are subject to the terms of the
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm * Common Development and Distribution License (the "License").
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm * You may not use this file except in compliance with the License.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * or http://www.opensolaris.org/os/licensing.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * See the License for the specific language governing permissions
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * and limitations under the License.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *
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 *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER END
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*
1db96d3b343c9ab3090da5b745f1cd9de2f192efCheng Sean Ye * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Use is subject to license terms.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <assert.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <pthread.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <strings.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <sys/fm/protocol.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <topo_alloc.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <topo_error.h>
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi#include <topo_method.h>
c40d7343efa60b18ad1ceb316eb337caeea79046cindi#include <topo_prop.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <topo_protocol.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <topo_subr.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <libtopo.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindiint
c40d7343efa60b18ad1ceb316eb337caeea79046cinditopo_node_asru(tnode_t *node, nvlist_t **asru, nvlist_t *priv, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_t *prop, *ap;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_prop_getprop(node, TOPO_PGROUP_PROTOCOL,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_PROP_ASRU, priv, &prop, err) < 0)
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_lookup_nvlist(prop, TOPO_PROP_VAL_VAL, &ap) != 0 ||
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_hdl_nvdup(node->tn_hdl, ap, asru) < 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *err = ETOPO_PROP_NVL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(prop);
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm return (-1);
8a40a695ee676a322b094e9afe5375567bfb51e3gavinm }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(prop);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
c40d7343efa60b18ad1ceb316eb337caeea79046cinditopo_node_fru(tnode_t *node, nvlist_t **fru, nvlist_t *priv, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_t *prop, *fp;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_prop_getprop(node, TOPO_PGROUP_PROTOCOL, TOPO_PROP_FRU,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi priv, &prop, err) < 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_lookup_nvlist(prop, TOPO_PROP_VAL_VAL, &fp) != 0 ||
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_hdl_nvdup(node->tn_hdl, fp, fru) < 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *err = ETOPO_PROP_NVL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(prop);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(prop);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_node_resource(tnode_t *node, nvlist_t **resource, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (topo_prop_get_fmri(node, TOPO_PGROUP_PROTOCOL,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_PROP_RESOURCE, resource, err));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_node_label(tnode_t *node, char **label, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (topo_prop_get_string(node, TOPO_PGROUP_PROTOCOL,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_PROP_LABEL, label, err));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_node_asru_set(tnode_t *node, nvlist_t *asru, int flag, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /*
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Inherit ASRU property from our parent if asru not specified
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (asru == NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (topo_prop_inherit(node, TOPO_PGROUP_PROTOCOL,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_PROP_ASRU, err) < 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (flag & TOPO_ASRU_COMPUTE) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_prop_method_register(node, TOPO_PGROUP_PROTOCOL,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_PROP_ASRU, TOPO_TYPE_FMRI, TOPO_METH_ASRU_COMPUTE,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi asru, err) < 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi } else {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (topo_prop_set_fmri(node, TOPO_PGROUP_PROTOCOL,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_PROP_ASRU, TOPO_PROP_IMMUTABLE, asru, err) < 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_node_fru_set(tnode_t *node, nvlist_t *fru, int flag, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /*
1db96d3b343c9ab3090da5b745f1cd9de2f192efCheng Sean Ye * Inherit FRU property from our parent if not specified
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (fru == NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (topo_prop_inherit(node, TOPO_PGROUP_PROTOCOL, TOPO_PROP_FRU,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi err) < 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
1db96d3b343c9ab3090da5b745f1cd9de2f192efCheng Sean Ye } else if (flag & TOPO_FRU_COMPUTE) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_prop_method_register(node, TOPO_PGROUP_PROTOCOL,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_PROP_FRU, TOPO_TYPE_FMRI, TOPO_METH_FRU_COMPUTE,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi fru, err) < 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi } else {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (topo_prop_set_fmri(node, TOPO_PGROUP_PROTOCOL,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_PROP_FRU, TOPO_PROP_IMMUTABLE, fru, err) < 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_node_label_set(tnode_t *node, char *label, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /*
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Inherit FRU property from our parent if * not specified
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (label == NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (topo_prop_inherit(node, TOPO_PGROUP_PROTOCOL,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_PROP_LABEL, err) < 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi } else {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (topo_prop_set_string(node, TOPO_PGROUP_PROTOCOL,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_PROP_LABEL, TOPO_PROP_IMMUTABLE, label, err) < 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}