pcifn_enum.c revision 88df2d76721d60b8b7cad14f9380446d06569f7c
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * CDDL HEADER START
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner * The contents of this file are subject to the terms of the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Common Development and Distribution License (the "License").
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * You may not use this file except in compliance with the License.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * or http://www.opensolaris.org/os/licensing.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * See the License for the specific language governing permissions
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * and limitations under the License.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * When distributing Covered Code, include this CDDL HEADER in each
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * If applicable, add the following below this CDDL HEADER, with the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * fields enclosed by brackets "[]" replaced with your own identifying
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * information: Portions Copyright [yyyy] [name of copyright owner]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * CDDL HEADER END
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Use is subject to license terms.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#pragma ident "%Z%%M% %I% %E% SMI"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include <limits.h>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include <fm/libtopo.h>
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#include "did.h"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include "did_props.h"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include "pcifn_enum.h"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic topo_mod_t *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinmodule_load(topo_mod_t *mp, tnode_t *parent, const char *name)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin topo_mod_t *rp = NULL;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char *plat, *mach;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char *path;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char *rootdir;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int err;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin plat = mach = NULL;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (topo_prop_get_string(parent,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin TOPO_PGROUP_SYSTEM, TOPO_PROP_PLATFORM, &plat, &err) < 0) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (void) topo_mod_seterrno(mp, err);
return (NULL);
}
if (topo_prop_get_string(parent,
TOPO_PGROUP_SYSTEM, TOPO_PROP_MACHINE, &mach, &err) < 0) {
(void) topo_mod_seterrno(mp, err);
return (NULL);
}
path = topo_mod_alloc(mp, PATH_MAX);
rootdir = topo_mod_rootdir(mp);
(void) snprintf(path, PATH_MAX,
PATH_TEMPLATE, rootdir ? rootdir : "", plat, name);
if ((rp = topo_mod_load(mp, path)) == NULL) {
topo_mod_dprintf(mp, "Unable to load %s.\n", path);
(void) snprintf(path, PATH_MAX,
PATH_TEMPLATE, rootdir ? rootdir : "", mach, name);
if ((rp = topo_mod_load(mp, path)) == NULL)
topo_mod_dprintf(mp, "Unable to load %s.\n", path);
}
topo_mod_strfree(mp, plat);
topo_mod_strfree(mp, mach);
topo_mod_free(mp, path, PATH_MAX);
return (rp);
}
static int
module_run(topo_mod_t *mp, tnode_t *parent, pfn_enum_t *ep)
{
char *ccstr;
uint_t cc;
int e;
/*
* Extract the class code of the PCI function and make sure
* it matches the type that the module cares about.
*/
if (topo_prop_get_string(parent,
TOPO_PGROUP_PCI, TOPO_PROP_CLASS, &ccstr, &e) < 0)
return (0);
if (sscanf(ccstr, "%x", &cc) != 1) {
topo_mod_strfree(mp, ccstr);
return (0);
}
topo_mod_strfree(mp, ccstr);
cc = cc >> 16;
if (cc != ep->pfne_class)
return (0);
return (topo_mod_enumerate(mp, parent,
ep->pfne_modname, ep->pfne_childname,
ep->pfne_imin, ep->pfne_imax));
}
int
pcifn_enum(topo_mod_t *mp, tnode_t *node)
{
int rv = 0;
int i;
topo_mod_dprintf(mp, "Enumerating beneath pci(ex) function.\n");
for (i = 0; i < Pcifn_enumerator_count; i++) {
if (Pcifn_enumerators[i].pfne_loaded == 0)
continue;
if (Pcifn_enumerators[i].pfne_loaded < 0) {
Pcifn_enumerators[i].pfne_mod = module_load(mp,
node, Pcifn_enumerators[i].pfne_modname);
if (Pcifn_enumerators[i].pfne_mod == NULL) {
Pcifn_enumerators[i].pfne_loaded = 0;
continue;
}
Pcifn_enumerators[i].pfne_loaded = 1;
}
if (module_run(mp, node, &Pcifn_enumerators[i]) != 0)
rv = -1;
}
return (rv);
}