npe_misc.c revision 70025d765b044c6d8594bb965a2247a61e991a99
70025d765b044c6d8594bb965a2247a61e991a99johnny/*
70025d765b044c6d8594bb965a2247a61e991a99johnny * CDDL HEADER START
70025d765b044c6d8594bb965a2247a61e991a99johnny *
70025d765b044c6d8594bb965a2247a61e991a99johnny * The contents of this file are subject to the terms of the
70025d765b044c6d8594bb965a2247a61e991a99johnny * Common Development and Distribution License, Version 1.0 only
70025d765b044c6d8594bb965a2247a61e991a99johnny * (the "License"). You may not use this file except in compliance
70025d765b044c6d8594bb965a2247a61e991a99johnny * with the License.
70025d765b044c6d8594bb965a2247a61e991a99johnny *
70025d765b044c6d8594bb965a2247a61e991a99johnny * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
70025d765b044c6d8594bb965a2247a61e991a99johnny * or http://www.opensolaris.org/os/licensing.
70025d765b044c6d8594bb965a2247a61e991a99johnny * See the License for the specific language governing permissions
70025d765b044c6d8594bb965a2247a61e991a99johnny * and limitations under the License.
70025d765b044c6d8594bb965a2247a61e991a99johnny *
70025d765b044c6d8594bb965a2247a61e991a99johnny * When distributing Covered Code, include this CDDL HEADER in each
70025d765b044c6d8594bb965a2247a61e991a99johnny * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
70025d765b044c6d8594bb965a2247a61e991a99johnny * If applicable, add the following below this CDDL HEADER, with the
70025d765b044c6d8594bb965a2247a61e991a99johnny * fields enclosed by brackets "[]" replaced with your own identifying
70025d765b044c6d8594bb965a2247a61e991a99johnny * information: Portions Copyright [yyyy] [name of copyright owner]
70025d765b044c6d8594bb965a2247a61e991a99johnny *
70025d765b044c6d8594bb965a2247a61e991a99johnny * CDDL HEADER END
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny/*
70025d765b044c6d8594bb965a2247a61e991a99johnny * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
70025d765b044c6d8594bb965a2247a61e991a99johnny * Use is subject to license terms.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny#pragma ident "%Z%%M% %I% %E% SMI"
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny/*
70025d765b044c6d8594bb965a2247a61e991a99johnny * Library file that has miscellaneous support for npe(7d)
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny#include <sys/conf.h>
70025d765b044c6d8594bb965a2247a61e991a99johnny#include <sys/pci.h>
70025d765b044c6d8594bb965a2247a61e991a99johnny#include <sys/sunndi.h>
70025d765b044c6d8594bb965a2247a61e991a99johnny#include <sys/acpi/acpi.h>
70025d765b044c6d8594bb965a2247a61e991a99johnny#include <sys/acpi/acpi_pci.h>
70025d765b044c6d8594bb965a2247a61e991a99johnny#include <sys/acpica.h>
70025d765b044c6d8594bb965a2247a61e991a99johnny#include <io/pciex/pcie_ck804_boot.h>
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny/*
70025d765b044c6d8594bb965a2247a61e991a99johnny * Prototype declaration
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnnyvoid npe_query_acpi_mcfg(dev_info_t *dip);
70025d765b044c6d8594bb965a2247a61e991a99johnnyvoid npe_ck804_fix_aer_ptr(dev_info_t *child);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny/*
70025d765b044c6d8594bb965a2247a61e991a99johnny * Default ecfga base address
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnnyint64_t npe_default_ecfga_base = 0xE0000000;
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny/*
70025d765b044c6d8594bb965a2247a61e991a99johnny * Query the MCFG table using ACPI. If MCFG is found, setup the
70025d765b044c6d8594bb965a2247a61e991a99johnny * 'ecfga-base-address' (Enhanced Configuration Access base address)
70025d765b044c6d8594bb965a2247a61e991a99johnny * property accordingly. Otherwise, set the value of the property
70025d765b044c6d8594bb965a2247a61e991a99johnny * to the default value.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnnyvoid
70025d765b044c6d8594bb965a2247a61e991a99johnnynpe_query_acpi_mcfg(dev_info_t *dip)
70025d765b044c6d8594bb965a2247a61e991a99johnny{
70025d765b044c6d8594bb965a2247a61e991a99johnny MCFG_TABLE *mcfgp;
70025d765b044c6d8594bb965a2247a61e991a99johnny CFG_BASE_ADDR_ALLOC *cfg_baap;
70025d765b044c6d8594bb965a2247a61e991a99johnny char *cfg_baa_endp;
70025d765b044c6d8594bb965a2247a61e991a99johnny uint64_t ecfga_base;
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny /* Query the MCFG table using ACPI */
70025d765b044c6d8594bb965a2247a61e991a99johnny if (AcpiGetFirmwareTable(MCFG_SIG, 1, ACPI_LOGICAL_ADDRESSING,
70025d765b044c6d8594bb965a2247a61e991a99johnny (ACPI_TABLE_HEADER **)&mcfgp) == AE_OK) {
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny cfg_baap = (CFG_BASE_ADDR_ALLOC *)mcfgp->CfgBaseAddrAllocList;
70025d765b044c6d8594bb965a2247a61e991a99johnny cfg_baa_endp = ((char *)mcfgp) + mcfgp->Length;
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny while ((char *)cfg_baap < cfg_baa_endp) {
70025d765b044c6d8594bb965a2247a61e991a99johnny ecfga_base = ACPI_GET_ADDRESS(cfg_baap->base_addr);
70025d765b044c6d8594bb965a2247a61e991a99johnny if (ecfga_base != (uint64_t)0) {
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * Setup the 'ecfga-base-address' property to
70025d765b044c6d8594bb965a2247a61e991a99johnny * the base_addr found in the MCFG and return.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny (void) ndi_prop_update_int64(DDI_DEV_T_NONE,
70025d765b044c6d8594bb965a2247a61e991a99johnny dip, "ecfga-base-address", ecfga_base);
70025d765b044c6d8594bb965a2247a61e991a99johnny return;
70025d765b044c6d8594bb965a2247a61e991a99johnny }
70025d765b044c6d8594bb965a2247a61e991a99johnny cfg_baap++;
70025d765b044c6d8594bb965a2247a61e991a99johnny }
70025d765b044c6d8594bb965a2247a61e991a99johnny }
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * If MCFG is not found or ecfga_base is not found in MCFG table,
70025d765b044c6d8594bb965a2247a61e991a99johnny * set the 'ecfga-base-address' property to the default value.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny (void) ndi_prop_update_int64(DDI_DEV_T_NONE, dip,
70025d765b044c6d8594bb965a2247a61e991a99johnny "ecfga-base-address", npe_default_ecfga_base);
70025d765b044c6d8594bb965a2247a61e991a99johnny}
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny/*
70025d765b044c6d8594bb965a2247a61e991a99johnny * Enable reporting of AER capability next pointer.
70025d765b044c6d8594bb965a2247a61e991a99johnny * This needs to be done only for CK8-04 devices
70025d765b044c6d8594bb965a2247a61e991a99johnny * by setting NV_XVR_VEND_CYA1 (offset 0xf40) bit 13
70025d765b044c6d8594bb965a2247a61e991a99johnny * NOTE: BIOS is disabling this, it needs to be enabled temporarily
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnnyvoid
70025d765b044c6d8594bb965a2247a61e991a99johnnynpe_ck804_fix_aer_ptr(dev_info_t *child)
70025d765b044c6d8594bb965a2247a61e991a99johnny{
70025d765b044c6d8594bb965a2247a61e991a99johnny ushort_t vid, did, cya1;
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_acc_handle_t config_handle;
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny if (pci_config_setup(child, &config_handle) != DDI_SUCCESS)
70025d765b044c6d8594bb965a2247a61e991a99johnny return;
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny vid = pci_config_get16(config_handle, PCI_CONF_VENID);
70025d765b044c6d8594bb965a2247a61e991a99johnny if (vid != NVIDIA_CK804_VENDOR_ID) {
70025d765b044c6d8594bb965a2247a61e991a99johnny pci_config_teardown(&config_handle);
70025d765b044c6d8594bb965a2247a61e991a99johnny return;
70025d765b044c6d8594bb965a2247a61e991a99johnny }
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny did = pci_config_get16(config_handle, PCI_CONF_DEVID);
70025d765b044c6d8594bb965a2247a61e991a99johnny if (did != NVIDIA_CK804_DEVICE_ID) {
70025d765b044c6d8594bb965a2247a61e991a99johnny pci_config_teardown(&config_handle);
70025d765b044c6d8594bb965a2247a61e991a99johnny return;
70025d765b044c6d8594bb965a2247a61e991a99johnny }
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny cya1 = pci_config_get16(config_handle, NVIDIA_CK804_VEND_CYA1_OFF);
70025d765b044c6d8594bb965a2247a61e991a99johnny if (!(cya1 & ~NVIDIA_CK804_VEND_CYA1_ERPT_MASK))
70025d765b044c6d8594bb965a2247a61e991a99johnny (void) pci_config_put16(config_handle,
70025d765b044c6d8594bb965a2247a61e991a99johnny NVIDIA_CK804_VEND_CYA1_OFF,
70025d765b044c6d8594bb965a2247a61e991a99johnny cya1 | NVIDIA_CK804_VEND_CYA1_ERPT_VAL);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny pci_config_teardown(&config_handle);
70025d765b044c6d8594bb965a2247a61e991a99johnny}