a31148363f598def767ac48c5d82e1572e44b935Gerry Liu/*
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * CDDL HEADER START
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu *
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * The contents of this file are subject to the terms of the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Common Development and Distribution License (the "License").
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * You may not use this file except in compliance with the License.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu *
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * or http://www.opensolaris.org/os/licensing.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * See the License for the specific language governing permissions
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * and limitations under the License.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu *
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * When distributing Covered Code, include this CDDL HEADER in each
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * If applicable, add the following below this CDDL HEADER, with the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * fields enclosed by brackets "[]" replaced with your own identifying
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * information: Portions Copyright [yyyy] [name of copyright owner]
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu *
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * CDDL HEADER END
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu/*
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Copyright (c) 2010, Intel Corporation.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * All rights reserved.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu#include <sys/types.h>
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu#include <sys/atomic.h>
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu#include <sys/sunddi.h>
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu#include <sys/sunndi.h>
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu#include <sys/acpi/acpi.h>
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu#include <sys/acpica.h>
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu#include <sys/acpidev.h>
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu#include <sys/acpidev_rsc.h>
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu#include <sys/acpidev_dr.h>
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu#include <sys/acpidev_impl.h>
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liustatic ACPI_STATUS acpidev_pci_probe(acpidev_walk_info_t *infop);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu/*
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Default class driver for PCI/PCIEX Host Bridge devices.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liuacpidev_class_t acpidev_class_pci = {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu 0, /* adc_refcnt */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ACPIDEV_CLASS_REV1, /* adc_version */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ACPIDEV_CLASS_ID_PCI, /* adc_class_id */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "PCI/PCIex Host Bridge", /* adc_class_name */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ACPIDEV_TYPE_PCI, /* adc_dev_type */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu NULL, /* adc_private */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu NULL, /* adc_pre_probe */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu NULL, /* adc_post_probe */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu acpidev_pci_probe, /* adc_probe */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu NULL, /* adc_filter */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu NULL, /* adc_init */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu NULL, /* adc_fini */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu};
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liustatic char *acpidev_pci_device_ids[] = {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ACPIDEV_HID_PCIEX_HOSTBRIDGE,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ACPIDEV_HID_PCI_HOSTBRIDGE,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu};
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liustatic char *acpidev_pciex_device_ids[] = {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ACPIDEV_HID_PCIEX_HOSTBRIDGE,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu};
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liustatic void
a31148363f598def767ac48c5d82e1572e44b935Gerry Liuacpidev_pci_update_status(acpidev_walk_info_t *infop)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu{
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu int status;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dev_info_t *dip = NULL;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu acpidev_data_handle_t dhdl;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dhdl = infop->awi_data;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ASSERT((dhdl->aod_iflag & ACPIDEV_ODF_DEVINFO_CREATED) == 0);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ASSERT((dhdl->aod_iflag & ACPIDEV_ODF_DEVINFO_TAGGED) == 0);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if ((dhdl->aod_iflag & ACPIDEV_ODF_STATUS_VALID) == 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu status = acpidev_query_device_status(infop->awi_hdl);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dhdl->aod_status = status;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dhdl->aod_iflag |= ACPIDEV_ODF_STATUS_VALID;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu } else {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu status = dhdl->aod_status;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu }
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dhdl->aod_level = infop->awi_level;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dhdl->aod_hdl = infop->awi_hdl;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dhdl->aod_class = NULL;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dhdl->aod_class_list = NULL;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (acpidev_match_device_id(infop->awi_info,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ACPIDEV_ARRAY_PARAM(acpidev_pciex_device_ids))) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dhdl->aod_class_id = ACPIDEV_CLASS_ID_PCIEX;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu } else {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dhdl->aod_class_id = ACPIDEV_CLASS_ID_PCI;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu }
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (ACPI_FAILURE(acpica_get_devinfo(infop->awi_hdl, &dip))) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dip = NULL;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu } else {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ASSERT(dip != NULL);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu }
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (acpidev_check_device_enabled(status)) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /*
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Mark the device as DISABLE if no device node created.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * BIOS may hide some special PCI/PCIex buses from OS.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (dip == NULL) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dhdl->aod_dip = NULL;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dhdl->aod_status &= ~ACPI_STA_DEVICE_ENABLED;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu } else {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dhdl->aod_dip = dip;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dhdl->aod_iflag |= ACPIDEV_ODF_DEVINFO_CREATED;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu }
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu } else {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ASSERT(dip == NULL);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dhdl->aod_dip = NULL;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dhdl->aod_status &= ~ACPI_STA_DEVICE_ENABLED;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu }
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu}
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liustatic ACPI_STATUS
a31148363f598def767ac48c5d82e1572e44b935Gerry Liuacpidev_pci_probe(acpidev_walk_info_t *infop)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu{
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ACPI_STATUS rc = AE_OK;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ASSERT(infop != NULL);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ASSERT(infop->awi_hdl != NULL);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ASSERT(infop->awi_info != NULL);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (infop->awi_info->Type != ACPI_TYPE_DEVICE ||
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu acpidev_match_device_id(infop->awi_info,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ACPIDEV_ARRAY_PARAM(acpidev_pci_device_ids)) == B_FALSE) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu return (AE_OK);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu }
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (acpica_get_devcfg_feature(ACPI_DEVCFG_PCI) == 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu return (AE_OK);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu }
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (infop->awi_op_type == ACPIDEV_OP_BOOT_PROBE) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /*
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Check hotplug capability on the first pass.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu acpidev_dr_check(infop);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu } else if (infop->awi_op_type == ACPIDEV_OP_BOOT_REPROBE) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /*
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Check whether the PCI device enumerator has created device
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * nodes for PCI/PCIEX host bridges.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu acpidev_pci_update_status(infop);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu } else if (infop->awi_op_type == ACPIDEV_OP_HOTPLUG_PROBE) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /*
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * No support of PCI/PCIEX host bridge hotplug yet.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * It will come in next phase.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu cmn_err(CE_WARN,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "!acpidev: no support of PCI/PCIEX host bridge hotplug.");
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /*
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Don't block the hot-adding process, just skip it.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu rc = AE_OK;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu } else {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ACPIDEV_DEBUG(CE_WARN, "!acpidev: unknown operation type %u "
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "in acpidev_pci_probe().", infop->awi_op_type);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu rc = AE_BAD_PARAMETER;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu }
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (ACPI_FAILURE(rc) && rc != AE_NOT_EXIST && rc != AE_ALREADY_EXISTS) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu cmn_err(CE_CONT, "?acpidev: failed to process PCI/PCIEX host "
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "bridge object %s.\n", infop->awi_name);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu } else {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu rc = AE_OK;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu }
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu return (rc);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu}