hc.c revision c40d7343efa60b18ad1ceb316eb337caeea79046
/*
*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <alloca.h>
#include <limits.h>
#include <fm/topo_mod.h>
#include <sys/systeminfo.h>
#include <sys/systeminfo.h>
#include <topo_method.h>
#include <topo_subr.h>
#include <topo_prop.h>
#include <hc.h>
topo_instance_t, void *, void *);
nvlist_t **);
nvlist_t **);
nvlist_t **);
const char *);
const topo_method_t hc_methods[] = {
{ NULL }
};
static const topo_modops_t hc_ops =
{ hc_enum, hc_release };
static const topo_modinfo_t hc_info =
{ BRANCH, TOPO_STABILITY_PRIVATE },
{ CMP, TOPO_STABILITY_PRIVATE },
{ CHIP, TOPO_STABILITY_PRIVATE },
{ CPU, TOPO_STABILITY_PRIVATE },
{ DIMM, TOPO_STABILITY_PRIVATE },
{ DISK, TOPO_STABILITY_PRIVATE },
{ NIU, TOPO_STABILITY_PRIVATE },
{ NIUFN, TOPO_STABILITY_PRIVATE },
{ RANK, TOPO_STABILITY_PRIVATE },
{ XAUI, TOPO_STABILITY_PRIVATE },
};
int
{
/*
* Turn on module debugging output
*/
if (getenv("TOPOHCDEBUG"))
if (version != HC_VERSION)
return (-1); /* mod errno already set */
}
return (0);
}
void
{
}
static const topo_pgroup_info_t sys_pgroup = {
1
};
static const topo_pgroup_info_t auth_pgroup = {
1
};
static void
{
int err;
char isa[MAXNAMELEN];
return;
if (err != ETOPO_PROP_DEFD)
return;
}
/*
* Inherit if we can, it saves memory
*/
&err) != 0) {
== 0)
&err);
}
&err) != 0) {
&err);
}
&err) != 0) {
== 0)
&err);
}
return;
isa[0] = '\0';
}
/*ARGSUSED*/
int
{
int err;
/*
* Register root node methods
*/
return (0);
}
"Request to enumerate %s component with an "
"ambiguous instance number, min (%d) != max (%d).\n",
}
return (-1);
}
return (-1);
}
return (0);
}
/*ARGSUSED*/
static void
{
}
static int
{
int err, i;
if (err != 0)
return (0);
for (i = 0; i < nhcp1; i++) {
continue;
return (0);
}
return (1);
}
/*ARGSUSED*/
static int
{
int ret;
if (version > TOPO_METH_COMPARE_VERSION)
if (ret < 0)
return (-1);
compare) == 0)
return (0);
else
nvlist_free(*out);
}
return (-1);
}
static ssize_t
{
int more_auth = 0;
int err, i;
return (-1);
/* Get authority, if present */
return (-1);
return (-1);
return (-1);
(void) nvlist_lookup_string(anvl,
(void) nvlist_lookup_string(anvl,
(void) nvlist_lookup_string(anvl,
(void) nvlist_lookup_string(anvl,
(void) nvlist_lookup_string(anvl,
more_auth++;
more_auth++;
more_auth++;
more_auth++;
more_auth++;
}
/* hc:// */
/* authority, if any */
/* hardware-id part */
/* separating slash */
/* hc-root */
/* all the pairs */
for (i = 0; i < hcnprs; i++) {
if (i > 0)
return (0);
}
return (size);
}
/*ARGSUSED*/
static int
{
if (version > TOPO_METH_NVL2STR_VERSION)
}
}
return (0);
}
static nvlist_t *
{
int err = 0;
/*
* Create base HC nvlist
*/
return (NULL);
if (err != 0) {
return (NULL);
}
/*
* Add optional payload members
*/
return (fmri);
}
static nvlist_t **
{
char *find;
int nslashes = 0;
int npairs = 0;
int i;
return (NULL);
/*
* Count equal signs and slashes to determine how many
* hc-pairs will be present in the final FMRI. There should
* be at least as many slashes as equal signs. There can be
* more, though if the string after an = includes them.
*/
return (NULL);
npairs++;
}
nslashes++;
}
/*
* Do we appear to have a well-formed string version of the FMRI?
*/
return (NULL);
}
return (NULL);
}
/*
* We go through a pretty complicated procedure to find the
* name and id for each pair. That's because, unfortunately,
* we have some ids that can have slashes within them. So
* we can't just search for the next slash after the equal sign
* and decide that starts a new pair. Instead we have to find
* an equal sign for the next pair and work our way back to the
* slash from there.
*/
for (i = 0; i < npairs; i++) {
break;
startn++;
break;
*starti = '\0';
break;
*starti++ = '=';
*endi = '\0';
break;
*endi = '=';
*endi2 = '\0';
break;
*endi2 = '/';
} else {
break;
}
break;
break;
}
if (i < npairs) {
while (i >= 0)
return (NULL);
}
return (pa);
}
void
{
return;
/*
* Make sure there are a valid authority members
*/
return;
}
/*
* The first colon we encounter must occur before the
* first slash
*/
return;
do {
break;
break;
*starti = '\0';
break;
break;
break;
*endi = '\0';
break;
}
/*
* Return possible serial, part and revision
*/
} else {
NV_UNIQUE_NAME) == 0) {
}
} else {
}
}
}
/*ARGSUSED*/
static int
{
char *str;
int npairs;
int i, e;
if (version > TOPO_METH_STR2NVL_VERSION)
/* We're expecting a string version of an hc scheme FMRI */
goto hcfmbail;
if (e != 0) {
goto hcfmbail;
}
for (i = 0; i < npairs; i++)
nvlist_free(pa[i]);
return (0);
for (i = 0; i < npairs; i++)
nvlist_free(pa[i]);
}
static nvlist_t *
{
int err;
return (NULL);
if (err != 0) {
return (NULL);
}
return (hc);
}
static nvlist_t *
int err)
{
int i;
for (i = 0; i < n + 1; ++i)
nvlist_free(hcl[i]);
}
return (NULL);
}
static int
{
int i;
return (1);
/*
* Only enumerate elements with correct canonical names
*/
for (i = 0; i < hc_ncanon; i++) {
break;
}
if (i >= hc_ncanon) {
name);
return (0);
} else {
return (1);
}
}
static nvlist_t *
{
int i;
if (version > FM_HC_SCHEME_VERSION)
return (hc_create_seterror(mod,
else if (version < FM_HC_SCHEME_VERSION)
return (hc_create_seterror(mod,
/*
* Check that the requested name is in our canonical list
*/
return (hc_create_seterror(mod,
/*
* Copy the parent's HC_LIST
*/
return (hc_create_seterror(mod,
}
EMOD_NOMEM));
for (i = 0; i < pelems; ++i)
return (hc_create_seterror(mod,
return (hc_create_seterror(mod,
return (hc_create_seterror(mod,
!= 0)
return (hc_create_seterror(mod,
for (i = 0; i < pelems + 1; ++i) {
nvlist_free(hcl[i]);
}
}
return (fmri);
}
/*ARGSUSED*/
static int
{
int ret;
if (version > TOPO_METH_FMRI_VERSION)
/* First the must-have fields */
/*
* args is optional
*/
!= 0) {
} else {
/* And then optional arguments */
&pfmri);
&auth);
&part);
&serial);
}
return (-1);
return (0);
}
struct hc_walk {
void *hcw_priv;
};
/*
* Generic walker for the hc-scheme topo tree. This function uses the
* hierachical nature of the hc-scheme to step through efficiently through
* the topo hc tree. Node lookups are done by topo_walk_byid() at each
* component level to avoid unnecessary traversal of the tree.
*
*/
static int
{
int i, err;
return (TOPO_WALK_TERMINATE);
}
if (err != 0) {
return (TOPO_WALK_ERR);
}
/*
* We are at the end of the hc-list. Verify that
*/
!= 0) {
return (TOPO_WALK_ERR);
}
"complete: terminate walk\n");
return (TOPO_WALK_TERMINATE);
} else {
return (TOPO_WALK_TERMINATE);
}
}
if (err != 0) {
return (TOPO_WALK_ERR);
}
inst);
}
static struct hc_walk *
{
int err;
&sz) != 0) {
return (NULL);
}
== NULL) {
return (NULL);
}
return (hwp);
}
struct prop_lookup {
const char *pl_pgroup;
const char *pl_pname;
int pl_flag;
};
/*ARGSUSED*/
static int
{
int err = 0;
return (err);
}
static int
{
int err;
struct prop_lookup *plp;
if (err != 0) {
}
/*
* Private args to prop method are optional
*/
!= 0) {
} else {
}
}
err = -1;
else
err = 0;
} else {
err = -1;
}
return (err);
}
/*ARGSUSED*/
static int
{
int err = 0;
return (err);
}
static int
{
int err;
struct prop_lookup *plp;
if (err != 0) {
}
err = -1;
else
err = 0;
} else {
err = -1;
}
return (err);
}
/*ARGSUSED*/
static int
{
int err = 0;
return (err);
}
/*ARGSUSED*/
static int
{
int err;
struct prop_lookup *plp;
if (err != 0) {
}
/*
* Private args to prop method are optional
*/
!= 0) {
else
}
err = -1;
else
err = 0;
} else {
err = -1;
}
return (err);
}
struct hc_args {
};
static int
{
int err;
/*
* check with the enumerator that created this FMRI
* (topo node)
*/
&err) < 0) {
/*
* Err on the side of caution and return present
*/
TOPO_METH_PRESENT_RET, 1) == 0)
return (0);
return (ETOPO_PROP_NVL);
}
return (err);
}
static int
{
int err;
if (version > TOPO_METH_PRESENT_VERSION)
err = -1;
else
err = 0;
} else {
err = -1;
}
return (err);
}
static int
{
int err;
/*
* check with the enumerator that created this FMRI
* (topo node)
*/
&err) < 0) {
/*
* Err on the side of caution and return usable
*/
TOPO_METH_UNUSABLE_RET, 0) == 0)
return (0);
return (ETOPO_PROP_NVL);
}
return (err);
}
static int
{
int err;
err = -1;
else
err = 0;
} else {
err = -1;
}
return (err);
}