hb_i86pc.c revision 00d0963faf2e861a4aef6b1bf28f99a5b2b20755
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER START
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *
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 *
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
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Use is subject to license terms.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#pragma ident "%Z%%M% %I% %E% SMI"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <fm/topo_mod.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <libdevinfo.h>
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet#include <strings.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include "pcibus.h"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include "hostbridge.h"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include "did.h"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include "util.h"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiextern did_hash_t *Didhash;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindihb_process(tnode_t *ptn, topo_instance_t hbi, di_node_t bn)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tnode_t *hb;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (did_create(Didhash, bn, 0, hbi, NO_RC, TRUST_BDF) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((hb = pcihostbridge_declare(ptn, bn, hbi)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (topo_mod_enumerate(HbHdl,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi hb, PCI_BUS, PCI_BUS, 0, MAX_HB_BUSES));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindirc_process(tnode_t *ptn, topo_instance_t hbi, di_node_t bn)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tnode_t *hb;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tnode_t *rc;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (did_create(Didhash, bn, 0, hbi, hbi, TRUST_BDF) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((hb = pciexhostbridge_declare(ptn, bn, hbi)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((rc = pciexrc_declare(hb, bn, hbi)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (topo_mod_enumerate(HbHdl,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi rc, PCI_BUS, PCIEX_BUS, 0, MAX_HB_BUSES));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindipci_hostbridges_find(tnode_t *ptn)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi di_node_t devtree;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi di_node_t pnode;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet di_node_t cnode;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi int hbcnt = 0;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* Scan for buses, top-level devinfo nodes with the right driver */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi devtree = di_init("/", DINFOCPYALL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (devtree == DI_NODE_NIL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_mod_dprintf(HbHdl, "devinfo init failed.");
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_node_range_destroy(ptn, HOSTBRIDGE);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet pnode = di_drv_first_node(PCI, devtree);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet while (pnode != DI_NODE_NIL) {
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet if (hb_process(ptn, hbcnt++, pnode) < 0) {
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet di_fini(devtree);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet topo_node_range_destroy(ptn, HOSTBRIDGE);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet return (topo_mod_seterrno(HbHdl, EMOD_PARTIAL_ENUM));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet pnode = di_drv_next_node(pnode);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi pnode = di_drv_first_node(NPE, devtree);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi while (pnode != DI_NODE_NIL) {
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet for (cnode = di_child_node(pnode); cnode != DI_NODE_NIL;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet cnode = di_sibling_node(cnode)) {
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet if (di_driver_name(cnode) == NULL)
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet continue;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet if (strcmp(di_driver_name(cnode), PCI_PCI) == 0) {
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet if (hb_process(ptn, hbcnt++, cnode) < 0) {
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet di_fini(devtree);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet topo_node_range_destroy(ptn,
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet HOSTBRIDGE);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet return (topo_mod_seterrno(HbHdl,
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet EMOD_PARTIAL_ENUM));
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet }
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet }
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet if (strcmp(di_driver_name(cnode), PCIE_PCI) == 0) {
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet if (rc_process(ptn, hbcnt++, cnode) < 0) {
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet di_fini(devtree);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet topo_node_range_destroy(ptn,
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet HOSTBRIDGE);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet return (topo_mod_seterrno(HbHdl,
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet EMOD_PARTIAL_ENUM));
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet }
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi pnode = di_drv_next_node(pnode);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi di_fini(devtree);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiplatform_hb_enum(tnode_t *parent, const char *name,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_instance_t imin, topo_instance_t imax)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (pci_hostbridges_find(parent));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiplatform_hb_label(tnode_t *node, nvlist_t *in, nvlist_t **out)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (labelmethod_inherit(HbHdl, node, in, out));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}