70025d765b044c6d8594bb965a2247a61e991a99johnny/*
70025d765b044c6d8594bb965a2247a61e991a99johnny * CDDL HEADER START
70025d765b044c6d8594bb965a2247a61e991a99johnny *
70025d765b044c6d8594bb965a2247a61e991a99johnny * The contents of this file are subject to the terms of the
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * Common Development and Distribution License (the "License").
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * You may not use this file except in compliance 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/*
fc256490629fe68815f7e0f23cf9b3545720cfacJason Beloro * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
70025d765b044c6d8594bb965a2247a61e991a99johnny * Use is subject to license terms.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny
cd21e7c548ae2a3b5e522244bf798f2a6b4ba02dGarrett D'Amore/*
cd21e7c548ae2a3b5e522244bf798f2a6b4ba02dGarrett D'Amore * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved.
cd21e7c548ae2a3b5e522244bf798f2a6b4ba02dGarrett D'Amore */
cd21e7c548ae2a3b5e522244bf798f2a6b4ba02dGarrett D'Amore
70025d765b044c6d8594bb965a2247a61e991a99johnny/*
70025d765b044c6d8594bb965a2247a61e991a99johnny * Host to PCI-Express local bus driver
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny#include <sys/conf.h>
70025d765b044c6d8594bb965a2247a61e991a99johnny#include <sys/modctl.h>
269473047d747f7815af570197e4ef7322d3632cEvan Yan#include <sys/file.h>
70025d765b044c6d8594bb965a2247a61e991a99johnny#include <sys/pci_impl.h>
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae#include <sys/pcie_impl.h>
70025d765b044c6d8594bb965a2247a61e991a99johnny#include <sys/sysmacros.h>
70025d765b044c6d8594bb965a2247a61e991a99johnny#include <sys/ddi_intr.h>
70025d765b044c6d8594bb965a2247a61e991a99johnny#include <sys/sunndi.h>
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet#include <sys/sunddi.h>
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet#include <sys/ddifm.h>
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet#include <sys/ndifm.h>
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet#include <sys/fm/util.h>
269473047d747f7815af570197e4ef7322d3632cEvan Yan#include <sys/hotplug/pci/pcie_hp.h>
c333dd99c762d509c7eb6cce222221958e23b4c8dm#include <io/pci/pci_tools_ext.h>
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae#include <io/pci/pci_common.h>
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae#include <io/pciex/pcie_nvidia.h>
70025d765b044c6d8594bb965a2247a61e991a99johnny
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg/*
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg * Helper Macros
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg */
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg#define NPE_IS_HANDLE_FOR_STDCFG_ACC(hp) \
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg ((hp) != NULL && \
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg ((ddi_acc_hdl_t *)(hp))->ah_platform_private != NULL && \
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg (((ddi_acc_impl_t *)((ddi_acc_hdl_t *)(hp))-> \
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg ah_platform_private)-> \
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg ahi_acc_attr &(DDI_ACCATTR_CPU_VADDR|DDI_ACCATTR_CONFIG_SPACE)) \
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg == DDI_ACCATTR_CONFIG_SPACE)
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg
70025d765b044c6d8594bb965a2247a61e991a99johnny/*
70025d765b044c6d8594bb965a2247a61e991a99johnny * Bus Operation functions
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int npe_bus_map(dev_info_t *, dev_info_t *, ddi_map_req_t *,
70025d765b044c6d8594bb965a2247a61e991a99johnny off_t, off_t, caddr_t *);
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int npe_ctlops(dev_info_t *, dev_info_t *, ddi_ctl_enum_t,
70025d765b044c6d8594bb965a2247a61e991a99johnny void *, void *);
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int npe_intr_ops(dev_info_t *, dev_info_t *, ddi_intr_op_t,
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_intr_handle_impl_t *, void *);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreetstatic int npe_fm_init(dev_info_t *, dev_info_t *, int,
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ddi_iblock_cookie_t *);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreetstatic int npe_fm_callback(dev_info_t *, ddi_fm_error_t *, const void *);
70025d765b044c6d8594bb965a2247a61e991a99johnny
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae/*
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * Disable URs and Received MA for all PCIe devices. Until x86 SW is changed so
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * that random drivers do not do PIO accesses on devices that it does not own,
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * these error bits must be disabled. SERR must also be disabled if URs have
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * been masked.
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae */
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnaeuint32_t npe_aer_uce_mask = PCIE_AER_UCE_UR;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnaeuint32_t npe_aer_ce_mask = 0;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnaeuint32_t npe_aer_suce_mask = PCIE_AER_SUCE_RCVD_MA;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae
70025d765b044c6d8594bb965a2247a61e991a99johnnystruct bus_ops npe_bus_ops = {
70025d765b044c6d8594bb965a2247a61e991a99johnny BUSO_REV,
70025d765b044c6d8594bb965a2247a61e991a99johnny npe_bus_map,
70025d765b044c6d8594bb965a2247a61e991a99johnny NULL,
70025d765b044c6d8594bb965a2247a61e991a99johnny NULL,
70025d765b044c6d8594bb965a2247a61e991a99johnny NULL,
70025d765b044c6d8594bb965a2247a61e991a99johnny i_ddi_map_fault,
cd21e7c548ae2a3b5e522244bf798f2a6b4ba02dGarrett D'Amore NULL,
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_dma_allochdl,
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_dma_freehdl,
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_dma_bindhdl,
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_dma_unbindhdl,
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_dma_flush,
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_dma_win,
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_dma_mctl,
70025d765b044c6d8594bb965a2247a61e991a99johnny npe_ctlops,
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_bus_prop_op,
269473047d747f7815af570197e4ef7322d3632cEvan Yan 0, /* (*bus_get_eventcookie)(); */
269473047d747f7815af570197e4ef7322d3632cEvan Yan 0, /* (*bus_add_eventcall)(); */
269473047d747f7815af570197e4ef7322d3632cEvan Yan 0, /* (*bus_remove_eventcall)(); */
269473047d747f7815af570197e4ef7322d3632cEvan Yan 0, /* (*bus_post_event)(); */
269473047d747f7815af570197e4ef7322d3632cEvan Yan 0, /* (*bus_intr_ctl)(); */
269473047d747f7815af570197e4ef7322d3632cEvan Yan 0, /* (*bus_config)(); */
269473047d747f7815af570197e4ef7322d3632cEvan Yan 0, /* (*bus_unconfig)(); */
269473047d747f7815af570197e4ef7322d3632cEvan Yan npe_fm_init, /* (*bus_fm_init)(); */
269473047d747f7815af570197e4ef7322d3632cEvan Yan NULL, /* (*bus_fm_fini)(); */
269473047d747f7815af570197e4ef7322d3632cEvan Yan NULL, /* (*bus_fm_access_enter)(); */
269473047d747f7815af570197e4ef7322d3632cEvan Yan NULL, /* (*bus_fm_access_exit)(); */
269473047d747f7815af570197e4ef7322d3632cEvan Yan NULL, /* (*bus_power)(); */
269473047d747f7815af570197e4ef7322d3632cEvan Yan npe_intr_ops, /* (*bus_intr_op)(); */
269473047d747f7815af570197e4ef7322d3632cEvan Yan pcie_hp_common_ops /* (*bus_hp_op)(); */
70025d765b044c6d8594bb965a2247a61e991a99johnny};
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int npe_open(dev_t *, int, int, cred_t *);
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int npe_close(dev_t, int, int, cred_t *);
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int npe_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnnystruct cb_ops npe_cb_ops = {
70025d765b044c6d8594bb965a2247a61e991a99johnny npe_open, /* open */
70025d765b044c6d8594bb965a2247a61e991a99johnny npe_close, /* close */
70025d765b044c6d8594bb965a2247a61e991a99johnny nodev, /* strategy */
70025d765b044c6d8594bb965a2247a61e991a99johnny nodev, /* print */
70025d765b044c6d8594bb965a2247a61e991a99johnny nodev, /* dump */
70025d765b044c6d8594bb965a2247a61e991a99johnny nodev, /* read */
70025d765b044c6d8594bb965a2247a61e991a99johnny nodev, /* write */
70025d765b044c6d8594bb965a2247a61e991a99johnny npe_ioctl, /* ioctl */
70025d765b044c6d8594bb965a2247a61e991a99johnny nodev, /* devmap */
70025d765b044c6d8594bb965a2247a61e991a99johnny nodev, /* mmap */
70025d765b044c6d8594bb965a2247a61e991a99johnny nodev, /* segmap */
70025d765b044c6d8594bb965a2247a61e991a99johnny nochpoll, /* poll */
269473047d747f7815af570197e4ef7322d3632cEvan Yan pcie_prop_op, /* cb_prop_op */
70025d765b044c6d8594bb965a2247a61e991a99johnny NULL, /* streamtab */
70025d765b044c6d8594bb965a2247a61e991a99johnny D_NEW | D_MP | D_HOTPLUG, /* Driver compatibility flag */
70025d765b044c6d8594bb965a2247a61e991a99johnny CB_REV, /* rev */
70025d765b044c6d8594bb965a2247a61e991a99johnny nodev, /* int (*cb_aread)() */
70025d765b044c6d8594bb965a2247a61e991a99johnny nodev /* int (*cb_awrite)() */
70025d765b044c6d8594bb965a2247a61e991a99johnny};
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny/*
70025d765b044c6d8594bb965a2247a61e991a99johnny * Device Node Operation functions
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int npe_attach(dev_info_t *devi, ddi_attach_cmd_t cmd);
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int npe_detach(dev_info_t *devi, ddi_detach_cmd_t cmd);
269473047d747f7815af570197e4ef7322d3632cEvan Yanstatic int npe_info(dev_info_t *, ddi_info_cmd_t, void *, void **);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnnystruct dev_ops npe_ops = {
70025d765b044c6d8594bb965a2247a61e991a99johnny DEVO_REV, /* devo_rev */
70025d765b044c6d8594bb965a2247a61e991a99johnny 0, /* refcnt */
247980bee8b0de250570942681f1567bd54ad984anish npe_info, /* info */
70025d765b044c6d8594bb965a2247a61e991a99johnny nulldev, /* identify */
70025d765b044c6d8594bb965a2247a61e991a99johnny nulldev, /* probe */
70025d765b044c6d8594bb965a2247a61e991a99johnny npe_attach, /* attach */
70025d765b044c6d8594bb965a2247a61e991a99johnny npe_detach, /* detach */
70025d765b044c6d8594bb965a2247a61e991a99johnny nulldev, /* reset */
70025d765b044c6d8594bb965a2247a61e991a99johnny &npe_cb_ops, /* driver operations */
193974072f41a843678abf5f61979c748687e66bSherry Moore &npe_bus_ops, /* bus operations */
193974072f41a843678abf5f61979c748687e66bSherry Moore NULL, /* power */
193974072f41a843678abf5f61979c748687e66bSherry Moore ddi_quiesce_not_needed, /* quiesce */
70025d765b044c6d8594bb965a2247a61e991a99johnny};
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny/*
70025d765b044c6d8594bb965a2247a61e991a99johnny * Internal routines in support of particular npe_ctlops.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int npe_removechild(dev_info_t *child);
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int npe_initchild(dev_info_t *child);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny/*
70025d765b044c6d8594bb965a2247a61e991a99johnny * External support routine
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnnyextern void npe_query_acpi_mcfg(dev_info_t *dip);
337fc9e235877b459e389f54daf9833bbc645439anishextern void npe_ck804_fix_aer_ptr(ddi_acc_handle_t cfg_hdl);
7a23d1009aa28ea040052630547929b9c5eb6ab4anishextern int npe_disable_empty_bridges_workaround(dev_info_t *child);
a2de976fd11ced5331ebe7c3a8ffbaf11f5427cfPavel Potoplyakextern void npe_nvidia_error_workaround(ddi_acc_handle_t cfg_hdl);
a2de976fd11ced5331ebe7c3a8ffbaf11f5427cfPavel Potoplyakextern void npe_intel_error_workaround(ddi_acc_handle_t cfg_hdl);
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldbergextern boolean_t npe_is_mmcfg_supported(dev_info_t *dip);
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayasesextern void npe_enable_htmsi_children(dev_info_t *dip);
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayasesextern int npe_save_htconfig_children(dev_info_t *dip);
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayasesextern int npe_restore_htconfig_children(dev_info_t *dip);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny/*
70025d765b044c6d8594bb965a2247a61e991a99johnny * Module linkage information for the kernel.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic struct modldrv modldrv = {
269473047d747f7815af570197e4ef7322d3632cEvan Yan &mod_driverops, /* Type of module */
269473047d747f7815af570197e4ef7322d3632cEvan Yan "Host to PCIe nexus driver", /* Name of module */
269473047d747f7815af570197e4ef7322d3632cEvan Yan &npe_ops, /* driver ops */
70025d765b044c6d8594bb965a2247a61e991a99johnny};
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic struct modlinkage modlinkage = {
70025d765b044c6d8594bb965a2247a61e991a99johnny MODREV_1,
70025d765b044c6d8594bb965a2247a61e991a99johnny (void *)&modldrv,
70025d765b044c6d8594bb965a2247a61e991a99johnny NULL
70025d765b044c6d8594bb965a2247a61e991a99johnny};
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny/* Save minimal state. */
70025d765b044c6d8594bb965a2247a61e991a99johnnyvoid *npe_statep;
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnnyint
70025d765b044c6d8594bb965a2247a61e991a99johnny_init(void)
70025d765b044c6d8594bb965a2247a61e991a99johnny{
70025d765b044c6d8594bb965a2247a61e991a99johnny int e;
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * Initialize per-pci bus soft state pointer.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny e = ddi_soft_state_init(&npe_statep, sizeof (pci_state_t), 1);
70025d765b044c6d8594bb965a2247a61e991a99johnny if (e != 0)
70025d765b044c6d8594bb965a2247a61e991a99johnny return (e);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny if ((e = mod_install(&modlinkage)) != 0)
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_soft_state_fini(&npe_statep);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny return (e);
70025d765b044c6d8594bb965a2247a61e991a99johnny}
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnnyint
70025d765b044c6d8594bb965a2247a61e991a99johnny_fini(void)
70025d765b044c6d8594bb965a2247a61e991a99johnny{
70025d765b044c6d8594bb965a2247a61e991a99johnny int rc;
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny rc = mod_remove(&modlinkage);
70025d765b044c6d8594bb965a2247a61e991a99johnny if (rc != 0)
70025d765b044c6d8594bb965a2247a61e991a99johnny return (rc);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_soft_state_fini(&npe_statep);
70025d765b044c6d8594bb965a2247a61e991a99johnny return (rc);
70025d765b044c6d8594bb965a2247a61e991a99johnny}
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnnyint
70025d765b044c6d8594bb965a2247a61e991a99johnny_info(struct modinfo *modinfop)
70025d765b044c6d8594bb965a2247a61e991a99johnny{
70025d765b044c6d8594bb965a2247a61e991a99johnny return (mod_info(&modlinkage, modinfop));
70025d765b044c6d8594bb965a2247a61e991a99johnny}
70025d765b044c6d8594bb965a2247a61e991a99johnny
269473047d747f7815af570197e4ef7322d3632cEvan Yan/*ARGSUSED*/
269473047d747f7815af570197e4ef7322d3632cEvan Yanstatic int
269473047d747f7815af570197e4ef7322d3632cEvan Yannpe_info(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
269473047d747f7815af570197e4ef7322d3632cEvan Yan{
269473047d747f7815af570197e4ef7322d3632cEvan Yan minor_t minor = getminor((dev_t)arg);
269473047d747f7815af570197e4ef7322d3632cEvan Yan int instance = PCI_MINOR_NUM_TO_INSTANCE(minor);
269473047d747f7815af570197e4ef7322d3632cEvan Yan pci_state_t *pcip = ddi_get_soft_state(npe_statep, instance);
269473047d747f7815af570197e4ef7322d3632cEvan Yan int ret = DDI_SUCCESS;
269473047d747f7815af570197e4ef7322d3632cEvan Yan
269473047d747f7815af570197e4ef7322d3632cEvan Yan switch (cmd) {
269473047d747f7815af570197e4ef7322d3632cEvan Yan case DDI_INFO_DEVT2INSTANCE:
269473047d747f7815af570197e4ef7322d3632cEvan Yan *result = (void *)(intptr_t)instance;
269473047d747f7815af570197e4ef7322d3632cEvan Yan break;
269473047d747f7815af570197e4ef7322d3632cEvan Yan case DDI_INFO_DEVT2DEVINFO:
269473047d747f7815af570197e4ef7322d3632cEvan Yan if (pcip == NULL) {
269473047d747f7815af570197e4ef7322d3632cEvan Yan ret = DDI_FAILURE;
269473047d747f7815af570197e4ef7322d3632cEvan Yan break;
269473047d747f7815af570197e4ef7322d3632cEvan Yan }
269473047d747f7815af570197e4ef7322d3632cEvan Yan
269473047d747f7815af570197e4ef7322d3632cEvan Yan *result = (void *)pcip->pci_dip;
269473047d747f7815af570197e4ef7322d3632cEvan Yan break;
269473047d747f7815af570197e4ef7322d3632cEvan Yan default:
269473047d747f7815af570197e4ef7322d3632cEvan Yan ret = DDI_FAILURE;
269473047d747f7815af570197e4ef7322d3632cEvan Yan break;
269473047d747f7815af570197e4ef7322d3632cEvan Yan }
269473047d747f7815af570197e4ef7322d3632cEvan Yan
269473047d747f7815af570197e4ef7322d3632cEvan Yan return (ret);
269473047d747f7815af570197e4ef7322d3632cEvan Yan}
269473047d747f7815af570197e4ef7322d3632cEvan Yan
70025d765b044c6d8594bb965a2247a61e991a99johnny/*ARGSUSED*/
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int
70025d765b044c6d8594bb965a2247a61e991a99johnnynpe_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
70025d765b044c6d8594bb965a2247a61e991a99johnny{
269473047d747f7815af570197e4ef7322d3632cEvan Yan int instance = ddi_get_instance(devi);
269473047d747f7815af570197e4ef7322d3632cEvan Yan pci_state_t *pcip = NULL;
70025d765b044c6d8594bb965a2247a61e991a99johnny
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases if (cmd == DDI_RESUME) {
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases /*
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases * the system might still be able to resume even if this fails
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases */
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases (void) npe_restore_htconfig_children(devi);
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf return (DDI_SUCCESS);
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases }
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases /*
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases * We must do this here in order to ensure that all top level devices
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases * get their HyperTransport MSI mapping regs programmed first.
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases * "Memory controller" and "hostbridge" class devices are leaf devices
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases * that may affect MSI translation functionality for devices
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases * connected to the same link/bus.
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases *
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases * This will also program HT MSI mapping registers on root buses
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases * devices (basically sitting on an HT bus) that are not dependent
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases * on the aforementioned HT devices for MSI translation.
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases */
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases npe_enable_htmsi_children(devi);
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf
70025d765b044c6d8594bb965a2247a61e991a99johnny if (ddi_prop_update_string(DDI_DEV_T_NONE, devi, "device_type",
70025d765b044c6d8594bb965a2247a61e991a99johnny "pciex") != DDI_PROP_SUCCESS) {
70025d765b044c6d8594bb965a2247a61e991a99johnny cmn_err(CE_WARN, "npe: 'device_type' prop create failed");
70025d765b044c6d8594bb965a2247a61e991a99johnny }
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny if (ddi_soft_state_zalloc(npe_statep, instance) == DDI_SUCCESS)
70025d765b044c6d8594bb965a2247a61e991a99johnny pcip = ddi_get_soft_state(npe_statep, instance);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny if (pcip == NULL)
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_FAILURE);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny pcip->pci_dip = devi;
269473047d747f7815af570197e4ef7322d3632cEvan Yan pcip->pci_soft_state = PCI_SOFT_STATE_CLOSED;
70025d765b044c6d8594bb965a2247a61e991a99johnny
269473047d747f7815af570197e4ef7322d3632cEvan Yan if (pcie_init(devi, NULL) != DDI_SUCCESS)
269473047d747f7815af570197e4ef7322d3632cEvan Yan goto fail1;
70025d765b044c6d8594bb965a2247a61e991a99johnny
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz /* Second arg: initialize for pci_express root nexus */
269473047d747f7815af570197e4ef7322d3632cEvan Yan if (pcitool_init(devi, B_TRUE) != DDI_SUCCESS)
269473047d747f7815af570197e4ef7322d3632cEvan Yan goto fail2;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet pcip->pci_fmcap = DDI_FM_EREPORT_CAPABLE | DDI_FM_ERRCB_CAPABLE |
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet DDI_FM_ACCCHK_CAPABLE | DDI_FM_DMACHK_CAPABLE;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ddi_fm_init(devi, &pcip->pci_fmcap, &pcip->pci_fm_ibc);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae if (pcip->pci_fmcap & DDI_FM_ERRCB_CAPABLE) {
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ddi_fm_handler_register(devi, npe_fm_callback, NULL);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae }
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae PCIE_DIP2PFD(devi) = kmem_zalloc(sizeof (pf_data_t), KM_SLEEP);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae pcie_rc_init_pfd(devi, PCIE_DIP2PFD(devi));
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny npe_query_acpi_mcfg(devi);
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_report_dev(devi);
c0da627439dfb642fb41ab7d78406fc69d2c64b2Zhi-Jun Robin Fu pcie_fab_init_bus(devi, PCIE_BUS_FINAL);
269473047d747f7815af570197e4ef7322d3632cEvan Yan
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_SUCCESS);
70025d765b044c6d8594bb965a2247a61e991a99johnny
269473047d747f7815af570197e4ef7322d3632cEvan Yanfail2:
269473047d747f7815af570197e4ef7322d3632cEvan Yan (void) pcie_uninit(devi);
269473047d747f7815af570197e4ef7322d3632cEvan Yanfail1:
269473047d747f7815af570197e4ef7322d3632cEvan Yan pcie_rc_fini_bus(devi);
269473047d747f7815af570197e4ef7322d3632cEvan Yan ddi_soft_state_free(npe_statep, instance);
269473047d747f7815af570197e4ef7322d3632cEvan Yan
269473047d747f7815af570197e4ef7322d3632cEvan Yan return (DDI_FAILURE);
70025d765b044c6d8594bb965a2247a61e991a99johnny}
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny/*ARGSUSED*/
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int
70025d765b044c6d8594bb965a2247a61e991a99johnnynpe_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
70025d765b044c6d8594bb965a2247a61e991a99johnny{
70025d765b044c6d8594bb965a2247a61e991a99johnny int instance = ddi_get_instance(devi);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet pci_state_t *pcip;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet pcip = ddi_get_soft_state(npe_statep, ddi_get_instance(devi));
70025d765b044c6d8594bb965a2247a61e991a99johnny
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf switch (cmd) {
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf case DDI_DETACH:
c0da627439dfb642fb41ab7d78406fc69d2c64b2Zhi-Jun Robin Fu pcie_fab_fini_bus(devi, PCIE_BUS_INITIAL);
70025d765b044c6d8594bb965a2247a61e991a99johnny
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf /* Uninitialize pcitool support. */
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf pcitool_uninit(devi);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet
269473047d747f7815af570197e4ef7322d3632cEvan Yan if (pcie_uninit(devi) != DDI_SUCCESS)
269473047d747f7815af570197e4ef7322d3632cEvan Yan return (DDI_FAILURE);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf if (pcip->pci_fmcap & DDI_FM_ERRCB_CAPABLE)
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf ddi_fm_handler_unregister(devi);
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae pcie_rc_fini_pfd(PCIE_DIP2PFD(devi));
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae kmem_free(PCIE_DIP2PFD(devi), sizeof (pf_data_t));
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf ddi_fm_fini(devi);
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf ddi_soft_state_free(npe_statep, instance);
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf return (DDI_SUCCESS);
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf case DDI_SUSPEND:
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases /*
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases * the system might still be able to suspend/resume even if
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases * this fails
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases */
cb7ea99db394f3bd5f4a6c6bf58c8c52df3508f0Jimmy Vetayases (void) npe_save_htconfig_children(devi);
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf return (DDI_SUCCESS);
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf default:
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf return (DDI_FAILURE);
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf }
70025d765b044c6d8594bb965a2247a61e991a99johnny}
70025d765b044c6d8594bb965a2247a61e991a99johnny
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg/*
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg * Configure the access handle for standard configuration space
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg * access (see pci_fm_acc_setup for code that initializes the
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg * access-function pointers).
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg */
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldbergstatic int
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldbergnpe_setup_std_pcicfg_acc(dev_info_t *rdip, ddi_map_req_t *mp,
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg ddi_acc_hdl_t *hp, off_t offset, off_t len)
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg{
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg int ret;
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg if ((ret = pci_fm_acc_setup(hp, offset, len)) ==
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg DDI_SUCCESS) {
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg if (DDI_FM_ACC_ERR_CAP(ddi_fm_capable(rdip)) &&
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg mp->map_handlep->ah_acc.devacc_attr_access
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg != DDI_DEFAULT_ACC) {
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg ndi_fmc_insert(rdip, ACC_HANDLE,
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg (void *)mp->map_handlep, NULL);
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg }
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg }
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg return (ret);
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg}
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int
70025d765b044c6d8594bb965a2247a61e991a99johnnynpe_bus_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp,
70025d765b044c6d8594bb965a2247a61e991a99johnny off_t offset, off_t len, caddr_t *vaddrp)
70025d765b044c6d8594bb965a2247a61e991a99johnny{
70025d765b044c6d8594bb965a2247a61e991a99johnny int rnumber;
70025d765b044c6d8594bb965a2247a61e991a99johnny int length;
70025d765b044c6d8594bb965a2247a61e991a99johnny int space;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ddi_acc_impl_t *ap;
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_acc_hdl_t *hp;
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_map_req_t mr;
70025d765b044c6d8594bb965a2247a61e991a99johnny pci_regspec_t pci_reg;
70025d765b044c6d8594bb965a2247a61e991a99johnny pci_regspec_t *pci_rp;
70025d765b044c6d8594bb965a2247a61e991a99johnny struct regspec reg;
70025d765b044c6d8594bb965a2247a61e991a99johnny pci_acc_cfblk_t *cfp;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet int retval;
5c59319b8761ccd4b952eec8d5caecf298024607Dan Mick int64_t *ecfginfo;
5c59319b8761ccd4b952eec8d5caecf298024607Dan Mick uint_t nelem;
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny mr = *mp; /* Get private copy of request */
70025d765b044c6d8594bb965a2247a61e991a99johnny mp = &mr;
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * check for register number
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny switch (mp->map_type) {
70025d765b044c6d8594bb965a2247a61e991a99johnny case DDI_MT_REGSPEC:
70025d765b044c6d8594bb965a2247a61e991a99johnny pci_reg = *(pci_regspec_t *)(mp->map_obj.rp);
70025d765b044c6d8594bb965a2247a61e991a99johnny pci_rp = &pci_reg;
70025d765b044c6d8594bb965a2247a61e991a99johnny if (pci_common_get_reg_prop(rdip, pci_rp) != DDI_SUCCESS)
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_FAILURE);
70025d765b044c6d8594bb965a2247a61e991a99johnny break;
70025d765b044c6d8594bb965a2247a61e991a99johnny case DDI_MT_RNUMBER:
70025d765b044c6d8594bb965a2247a61e991a99johnny rnumber = mp->map_obj.rnumber;
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * get ALL "reg" properties for dip, select the one of
70025d765b044c6d8594bb965a2247a61e991a99johnny * of interest. In x86, "assigned-addresses" property
70025d765b044c6d8594bb965a2247a61e991a99johnny * is identical to the "reg" property, so there is no
70025d765b044c6d8594bb965a2247a61e991a99johnny * need to cross check the two to determine the physical
70025d765b044c6d8594bb965a2247a61e991a99johnny * address of the registers.
70025d765b044c6d8594bb965a2247a61e991a99johnny * This routine still performs some validity checks to
70025d765b044c6d8594bb965a2247a61e991a99johnny * make sure that everything is okay.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, rdip,
70025d765b044c6d8594bb965a2247a61e991a99johnny DDI_PROP_DONTPASS, "reg", (int **)&pci_rp,
70025d765b044c6d8594bb965a2247a61e991a99johnny (uint_t *)&length) != DDI_PROP_SUCCESS)
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_FAILURE);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * validate the register number.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny length /= (sizeof (pci_regspec_t) / sizeof (int));
70025d765b044c6d8594bb965a2247a61e991a99johnny if (rnumber >= length) {
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_prop_free(pci_rp);
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_FAILURE);
70025d765b044c6d8594bb965a2247a61e991a99johnny }
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * copy the required entry.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny pci_reg = pci_rp[rnumber];
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * free the memory allocated by ddi_prop_lookup_int_array
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_prop_free(pci_rp);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny pci_rp = &pci_reg;
70025d765b044c6d8594bb965a2247a61e991a99johnny if (pci_common_get_reg_prop(rdip, pci_rp) != DDI_SUCCESS)
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_FAILURE);
70025d765b044c6d8594bb965a2247a61e991a99johnny mp->map_type = DDI_MT_REGSPEC;
70025d765b044c6d8594bb965a2247a61e991a99johnny break;
70025d765b044c6d8594bb965a2247a61e991a99johnny default:
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_ME_INVAL);
70025d765b044c6d8594bb965a2247a61e991a99johnny }
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny space = pci_rp->pci_phys_hi & PCI_REG_ADDR_M;
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * check for unmap and unlock of address space
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny if ((mp->map_op == DDI_MO_UNMAP) || (mp->map_op == DDI_MO_UNLOCK)) {
70025d765b044c6d8594bb965a2247a61e991a99johnny switch (space) {
70025d765b044c6d8594bb965a2247a61e991a99johnny case PCI_ADDR_IO:
70025d765b044c6d8594bb965a2247a61e991a99johnny reg.regspec_bustype = 1;
70025d765b044c6d8594bb965a2247a61e991a99johnny break;
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny case PCI_ADDR_CONFIG:
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg /*
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg * If this is an unmap/unlock of a standard config
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg * space mapping (memory-mapped config space mappings
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg * would have the DDI_ACCATTR_CPU_VADDR bit set in the
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg * acc_attr), undo that setup here.
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg */
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg if (NPE_IS_HANDLE_FOR_STDCFG_ACC(mp->map_handlep)) {
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet if (DDI_FM_ACC_ERR_CAP(ddi_fm_capable(rdip)) &&
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet mp->map_handlep->ah_acc.devacc_attr_access
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet != DDI_DEFAULT_ACC) {
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ndi_fmc_remove(rdip, ACC_HANDLE,
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet (void *)mp->map_handlep);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet }
247980bee8b0de250570942681f1567bd54ad984anish return (DDI_SUCCESS);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet }
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet
49fbdd30212f016ddd49c4b5c997b0b827ff0962Erwin T Tsaur pci_rp->pci_size_low = PCIE_CONF_HDR_SIZE;
247980bee8b0de250570942681f1567bd54ad984anish
649d4cce0c8ba57f2c399df82be95a0395cfeef2anish /* FALLTHROUGH */
70025d765b044c6d8594bb965a2247a61e991a99johnny case PCI_ADDR_MEM64:
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * MEM64 requires special treatment on map, to check
70025d765b044c6d8594bb965a2247a61e991a99johnny * that the device is below 4G. On unmap, however,
70025d765b044c6d8594bb965a2247a61e991a99johnny * we can assume that everything is OK... the map
70025d765b044c6d8594bb965a2247a61e991a99johnny * must have succeeded.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny /* FALLTHROUGH */
70025d765b044c6d8594bb965a2247a61e991a99johnny case PCI_ADDR_MEM32:
70025d765b044c6d8594bb965a2247a61e991a99johnny reg.regspec_bustype = 0;
70025d765b044c6d8594bb965a2247a61e991a99johnny break;
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny default:
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_FAILURE);
70025d765b044c6d8594bb965a2247a61e991a99johnny }
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet /*
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * Adjust offset and length
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * A non-zero length means override the one in the regspec.
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet */
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet pci_rp->pci_phys_low += (uint_t)offset;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet if (len != 0)
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet pci_rp->pci_size_low = len;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet
70025d765b044c6d8594bb965a2247a61e991a99johnny reg.regspec_addr = pci_rp->pci_phys_low;
70025d765b044c6d8594bb965a2247a61e991a99johnny reg.regspec_size = pci_rp->pci_size_low;
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny mp->map_obj.rp = &reg;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet retval = ddi_map(dip, mp, (off_t)0, (off_t)0, vaddrp);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet if (DDI_FM_ACC_ERR_CAP(ddi_fm_capable(rdip)) &&
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet mp->map_handlep->ah_acc.devacc_attr_access !=
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet DDI_DEFAULT_ACC) {
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ndi_fmc_remove(rdip, ACC_HANDLE,
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet (void *)mp->map_handlep);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet }
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet return (retval);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny }
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny /* check for user mapping request - not legal for Config */
70025d765b044c6d8594bb965a2247a61e991a99johnny if (mp->map_op == DDI_MO_MAP_HANDLE && space == PCI_ADDR_CONFIG) {
70025d765b044c6d8594bb965a2247a61e991a99johnny cmn_err(CE_NOTE, "npe: Config mapping request from user\n");
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_FAILURE);
70025d765b044c6d8594bb965a2247a61e991a99johnny }
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet /*
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * Note that pci_fm_acc_setup() is called to serve two purposes
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * i) enable legacy PCI I/O style config space access
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * ii) register with FMA
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet */
70025d765b044c6d8594bb965a2247a61e991a99johnny if (space == PCI_ADDR_CONFIG) {
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg
70025d765b044c6d8594bb965a2247a61e991a99johnny /* Can't map config space without a handle */
70025d765b044c6d8594bb965a2247a61e991a99johnny hp = (ddi_acc_hdl_t *)mp->map_handlep;
70025d765b044c6d8594bb965a2247a61e991a99johnny if (hp == NULL)
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_FAILURE);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny /* record the device address for future reference */
70025d765b044c6d8594bb965a2247a61e991a99johnny cfp = (pci_acc_cfblk_t *)&hp->ah_bus_private;
70025d765b044c6d8594bb965a2247a61e991a99johnny cfp->c_busnum = PCI_REG_BUS_G(pci_rp->pci_phys_hi);
70025d765b044c6d8594bb965a2247a61e991a99johnny cfp->c_devnum = PCI_REG_DEV_G(pci_rp->pci_phys_hi);
70025d765b044c6d8594bb965a2247a61e991a99johnny cfp->c_funcnum = PCI_REG_FUNC_G(pci_rp->pci_phys_hi);
70025d765b044c6d8594bb965a2247a61e991a99johnny
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet *vaddrp = (caddr_t)offset;
649d4cce0c8ba57f2c399df82be95a0395cfeef2anish
49fbdd30212f016ddd49c4b5c997b0b827ff0962Erwin T Tsaur /* Check if MMCFG is supported */
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg if (!npe_is_mmcfg_supported(rdip)) {
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg return (npe_setup_std_pcicfg_acc(rdip, mp, hp,
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg offset, len));
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet }
247980bee8b0de250570942681f1567bd54ad984anish
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg
5c59319b8761ccd4b952eec8d5caecf298024607Dan Mick if (ddi_prop_lookup_int64_array(DDI_DEV_T_ANY, rdip, 0,
5c59319b8761ccd4b952eec8d5caecf298024607Dan Mick "ecfg", &ecfginfo, &nelem) == DDI_PROP_SUCCESS) {
649d4cce0c8ba57f2c399df82be95a0395cfeef2anish
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg if (nelem != 4 ||
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg cfp->c_busnum < ecfginfo[2] ||
5c59319b8761ccd4b952eec8d5caecf298024607Dan Mick cfp->c_busnum > ecfginfo[3]) {
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg /*
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg * Invalid property or Doesn't contain the
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg * requested bus; fall back to standard
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg * (I/O-based) config access.
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg */
5c59319b8761ccd4b952eec8d5caecf298024607Dan Mick ddi_prop_free(ecfginfo);
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg return (npe_setup_std_pcicfg_acc(rdip, mp, hp,
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg offset, len));
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg } else {
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg pci_rp->pci_phys_low = ecfginfo[0];
5c59319b8761ccd4b952eec8d5caecf298024607Dan Mick
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg ddi_prop_free(ecfginfo);
70025d765b044c6d8594bb965a2247a61e991a99johnny
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg pci_rp->pci_phys_low += ((cfp->c_busnum << 20) |
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg (cfp->c_devnum) << 15 |
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg (cfp->c_funcnum << 12));
5c59319b8761ccd4b952eec8d5caecf298024607Dan Mick
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg pci_rp->pci_size_low = PCIE_CONF_HDR_SIZE;
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg }
5c59319b8761ccd4b952eec8d5caecf298024607Dan Mick } else {
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg /*
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg * Couldn't find the MMCFG property -- fall back to
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg * standard config access
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg */
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg return (npe_setup_std_pcicfg_acc(rdip, mp, hp,
14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6Seth Goldberg offset, len));
5c59319b8761ccd4b952eec8d5caecf298024607Dan Mick }
70025d765b044c6d8594bb965a2247a61e991a99johnny }
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny length = pci_rp->pci_size_low;
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * range check
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny if ((offset >= length) || (len > length) || (offset + len > length))
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_FAILURE);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * Adjust offset and length
70025d765b044c6d8594bb965a2247a61e991a99johnny * A non-zero length means override the one in the regspec.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny pci_rp->pci_phys_low += (uint_t)offset;
70025d765b044c6d8594bb965a2247a61e991a99johnny if (len != 0)
70025d765b044c6d8594bb965a2247a61e991a99johnny pci_rp->pci_size_low = len;
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * convert the pci regsec into the generic regspec used by the
70025d765b044c6d8594bb965a2247a61e991a99johnny * parent root nexus driver.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny switch (space) {
70025d765b044c6d8594bb965a2247a61e991a99johnny case PCI_ADDR_IO:
70025d765b044c6d8594bb965a2247a61e991a99johnny reg.regspec_bustype = 1;
70025d765b044c6d8594bb965a2247a61e991a99johnny break;
70025d765b044c6d8594bb965a2247a61e991a99johnny case PCI_ADDR_CONFIG:
70025d765b044c6d8594bb965a2247a61e991a99johnny case PCI_ADDR_MEM64:
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * We can't handle 64-bit devices that are mapped above
70025d765b044c6d8594bb965a2247a61e991a99johnny * 4G or that are larger than 4G.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny if (pci_rp->pci_phys_mid != 0 || pci_rp->pci_size_hi != 0)
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_FAILURE);
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * Other than that, we can treat them as 32-bit mappings
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny /* FALLTHROUGH */
70025d765b044c6d8594bb965a2247a61e991a99johnny case PCI_ADDR_MEM32:
70025d765b044c6d8594bb965a2247a61e991a99johnny reg.regspec_bustype = 0;
70025d765b044c6d8594bb965a2247a61e991a99johnny break;
70025d765b044c6d8594bb965a2247a61e991a99johnny default:
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_FAILURE);
70025d765b044c6d8594bb965a2247a61e991a99johnny }
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny reg.regspec_addr = pci_rp->pci_phys_low;
70025d765b044c6d8594bb965a2247a61e991a99johnny reg.regspec_size = pci_rp->pci_size_low;
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny mp->map_obj.rp = &reg;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet retval = ddi_map(dip, mp, (off_t)0, (off_t)0, vaddrp);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet if (retval == DDI_SUCCESS) {
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet /*
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * For config space gets force use of cautious access routines.
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * These will handle default and protected mode accesses too.
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet */
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet if (space == PCI_ADDR_CONFIG) {
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ap = (ddi_acc_impl_t *)mp->map_handlep;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ap->ahi_acc_attr &= ~DDI_ACCATTR_DIRECT;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ap->ahi_acc_attr |= DDI_ACCATTR_CONFIG_SPACE;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ap->ahi_get8 = i_ddi_caut_get8;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ap->ahi_get16 = i_ddi_caut_get16;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ap->ahi_get32 = i_ddi_caut_get32;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ap->ahi_get64 = i_ddi_caut_get64;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ap->ahi_rep_get8 = i_ddi_caut_rep_get8;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ap->ahi_rep_get16 = i_ddi_caut_rep_get16;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ap->ahi_rep_get32 = i_ddi_caut_rep_get32;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ap->ahi_rep_get64 = i_ddi_caut_rep_get64;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet }
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet if (DDI_FM_ACC_ERR_CAP(ddi_fm_capable(rdip)) &&
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet mp->map_handlep->ah_acc.devacc_attr_access !=
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet DDI_DEFAULT_ACC) {
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ndi_fmc_insert(rdip, ACC_HANDLE,
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet (void *)mp->map_handlep, NULL);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet }
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet }
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet return (retval);
70025d765b044c6d8594bb965a2247a61e991a99johnny}
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny
649d4cce0c8ba57f2c399df82be95a0395cfeef2anish
70025d765b044c6d8594bb965a2247a61e991a99johnny/*ARGSUSED*/
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int
70025d765b044c6d8594bb965a2247a61e991a99johnnynpe_ctlops(dev_info_t *dip, dev_info_t *rdip,
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_ctl_enum_t ctlop, void *arg, void *result)
70025d765b044c6d8594bb965a2247a61e991a99johnny{
70025d765b044c6d8594bb965a2247a61e991a99johnny int rn;
70025d765b044c6d8594bb965a2247a61e991a99johnny int totreg;
70025d765b044c6d8594bb965a2247a61e991a99johnny uint_t reglen;
70025d765b044c6d8594bb965a2247a61e991a99johnny pci_regspec_t *drv_regp;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae struct attachspec *asp;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae struct detachspec *dsp;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae pci_state_t *pci_p = ddi_get_soft_state(npe_statep,
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae ddi_get_instance(dip));
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny switch (ctlop) {
70025d765b044c6d8594bb965a2247a61e991a99johnny case DDI_CTLOPS_REPORTDEV:
70025d765b044c6d8594bb965a2247a61e991a99johnny if (rdip == (dev_info_t *)0)
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_FAILURE);
70025d765b044c6d8594bb965a2247a61e991a99johnny cmn_err(CE_CONT, "?PCI Express-device: %s@%s, %s%d\n",
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_node_name(rdip), ddi_get_name_addr(rdip),
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_driver_name(rdip), ddi_get_instance(rdip));
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_SUCCESS);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny case DDI_CTLOPS_INITCHILD:
70025d765b044c6d8594bb965a2247a61e991a99johnny return (npe_initchild((dev_info_t *)arg));
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny case DDI_CTLOPS_UNINITCHILD:
70025d765b044c6d8594bb965a2247a61e991a99johnny return (npe_removechild((dev_info_t *)arg));
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny case DDI_CTLOPS_SIDDEV:
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_SUCCESS);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny case DDI_CTLOPS_REGSIZE:
70025d765b044c6d8594bb965a2247a61e991a99johnny case DDI_CTLOPS_NREGS:
70025d765b044c6d8594bb965a2247a61e991a99johnny if (rdip == (dev_info_t *)0)
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_FAILURE);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny *(int *)result = 0;
70025d765b044c6d8594bb965a2247a61e991a99johnny if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, rdip,
70025d765b044c6d8594bb965a2247a61e991a99johnny DDI_PROP_DONTPASS, "reg", (int **)&drv_regp,
70025d765b044c6d8594bb965a2247a61e991a99johnny &reglen) != DDI_PROP_SUCCESS) {
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_FAILURE);
70025d765b044c6d8594bb965a2247a61e991a99johnny }
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny totreg = (reglen * sizeof (int)) / sizeof (pci_regspec_t);
70025d765b044c6d8594bb965a2247a61e991a99johnny if (ctlop == DDI_CTLOPS_NREGS)
70025d765b044c6d8594bb965a2247a61e991a99johnny *(int *)result = totreg;
70025d765b044c6d8594bb965a2247a61e991a99johnny else if (ctlop == DDI_CTLOPS_REGSIZE) {
70025d765b044c6d8594bb965a2247a61e991a99johnny rn = *(int *)arg;
70025d765b044c6d8594bb965a2247a61e991a99johnny if (rn >= totreg) {
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_prop_free(drv_regp);
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_FAILURE);
70025d765b044c6d8594bb965a2247a61e991a99johnny }
70025d765b044c6d8594bb965a2247a61e991a99johnny *(off_t *)result = drv_regp[rn].pci_size_low;
70025d765b044c6d8594bb965a2247a61e991a99johnny }
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_prop_free(drv_regp);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_SUCCESS);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny case DDI_CTLOPS_POWER:
70025d765b044c6d8594bb965a2247a61e991a99johnny {
70025d765b044c6d8594bb965a2247a61e991a99johnny power_req_t *reqp = (power_req_t *)arg;
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * We currently understand reporting of PCI_PM_IDLESPEED
70025d765b044c6d8594bb965a2247a61e991a99johnny * capability. Everything else is passed up.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny if ((reqp->request_type == PMR_REPORT_PMCAP) &&
70025d765b044c6d8594bb965a2247a61e991a99johnny (reqp->req.report_pmcap_req.cap == PCI_PM_IDLESPEED))
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_SUCCESS);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny break;
70025d765b044c6d8594bb965a2247a61e991a99johnny }
70025d765b044c6d8594bb965a2247a61e991a99johnny
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet case DDI_CTLOPS_PEEK:
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet case DDI_CTLOPS_POKE:
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet return (pci_common_peekpoke(dip, rdip, ctlop, arg, result));
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf /* X86 systems support PME wakeup from suspended state */
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf case DDI_CTLOPS_ATTACH:
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae if (!pcie_is_child(dip, rdip))
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae return (DDI_SUCCESS);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf asp = (struct attachspec *)arg;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae if ((asp->when == DDI_POST) && (asp->result == DDI_SUCCESS)) {
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae pf_init(rdip, (void *)pci_p->pci_fm_ibc, asp->cmd);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae (void) pcie_postattach_child(rdip);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae }
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf /* only do this for immediate children */
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf if (asp->cmd == DDI_RESUME && asp->when == DDI_PRE &&
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf ddi_get_parent(rdip) == dip)
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf if (pci_pre_resume(rdip) != DDI_SUCCESS) {
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf /* Not good, better stop now. */
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf cmn_err(CE_PANIC,
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf "Couldn't pre-resume device %p",
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf (void *) dip);
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf /* NOTREACHED */
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf }
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae return (DDI_SUCCESS);
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf case DDI_CTLOPS_DETACH:
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae if (!pcie_is_child(dip, rdip))
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae return (DDI_SUCCESS);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae dsp = (struct detachspec *)arg;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae if (dsp->when == DDI_PRE)
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae pf_fini(rdip, dsp->cmd);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf /* only do this for immediate children */
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae if (dsp->cmd == DDI_SUSPEND && dsp->when == DDI_POST &&
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf ddi_get_parent(rdip) == dip)
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf if (pci_post_suspend(rdip) != DDI_SUCCESS)
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf return (DDI_FAILURE);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae return (DDI_SUCCESS);
2df1fe9ca32bb227b9158c67f5c00b54c20b10fdrandyf
70025d765b044c6d8594bb965a2247a61e991a99johnny default:
70025d765b044c6d8594bb965a2247a61e991a99johnny break;
70025d765b044c6d8594bb965a2247a61e991a99johnny }
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny return (ddi_ctlops(dip, rdip, ctlop, arg, result));
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny}
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny/*
70025d765b044c6d8594bb965a2247a61e991a99johnny * npe_intr_ops
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int
70025d765b044c6d8594bb965a2247a61e991a99johnnynpe_intr_ops(dev_info_t *pdip, dev_info_t *rdip, ddi_intr_op_t intr_op,
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_intr_handle_impl_t *hdlp, void *result)
70025d765b044c6d8594bb965a2247a61e991a99johnny{
70025d765b044c6d8594bb965a2247a61e991a99johnny return (pci_common_intr_ops(pdip, rdip, intr_op, hdlp, result));
70025d765b044c6d8594bb965a2247a61e991a99johnny}
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int
70025d765b044c6d8594bb965a2247a61e991a99johnnynpe_initchild(dev_info_t *child)
70025d765b044c6d8594bb965a2247a61e991a99johnny{
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae char name[80];
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae pcie_bus_t *bus_p;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae uint32_t regs;
337fc9e235877b459e389f54daf9833bbc645439anish ddi_acc_handle_t cfg_hdl;
70025d765b044c6d8594bb965a2247a61e991a99johnny
7a23d1009aa28ea040052630547929b9c5eb6ab4anish /*
7a23d1009aa28ea040052630547929b9c5eb6ab4anish * Do not bind drivers to empty bridges.
7a23d1009aa28ea040052630547929b9c5eb6ab4anish * Fail above, if the bridge is found to be hotplug capable
7a23d1009aa28ea040052630547929b9c5eb6ab4anish */
7a23d1009aa28ea040052630547929b9c5eb6ab4anish if (npe_disable_empty_bridges_workaround(child) == 1)
7a23d1009aa28ea040052630547929b9c5eb6ab4anish return (DDI_FAILURE);
7a23d1009aa28ea040052630547929b9c5eb6ab4anish
70025d765b044c6d8594bb965a2247a61e991a99johnny if (pci_common_name_child(child, name, 80) != DDI_SUCCESS)
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_FAILURE);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_set_name_addr(child, name);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * Pseudo nodes indicate a prototype node with per-instance
70025d765b044c6d8594bb965a2247a61e991a99johnny * properties to be merged into the real h/w device node.
70025d765b044c6d8594bb965a2247a61e991a99johnny * The interpretation of the unit-address is DD[,F]
70025d765b044c6d8594bb965a2247a61e991a99johnny * where DD is the device id and F is the function.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny if (ndi_dev_is_persistent_node(child) == 0) {
70025d765b044c6d8594bb965a2247a61e991a99johnny extern int pci_allow_pseudo_children;
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_set_parent_data(child, NULL);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * Try to merge the properties from this prototype
70025d765b044c6d8594bb965a2247a61e991a99johnny * node into real h/w nodes.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny if (ndi_merge_node(child, pci_common_name_child) ==
70025d765b044c6d8594bb965a2247a61e991a99johnny DDI_SUCCESS) {
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * Merged ok - return failure to remove the node.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_set_name_addr(child, NULL);
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_FAILURE);
70025d765b044c6d8594bb965a2247a61e991a99johnny }
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny /* workaround for DDIVS to run under PCI Express */
70025d765b044c6d8594bb965a2247a61e991a99johnny if (pci_allow_pseudo_children) {
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * If the "interrupts" property doesn't exist,
70025d765b044c6d8594bb965a2247a61e991a99johnny * this must be the ddivs no-intr case, and it returns
70025d765b044c6d8594bb965a2247a61e991a99johnny * DDI_SUCCESS instead of DDI_FAILURE.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny if (ddi_prop_get_int(DDI_DEV_T_ANY, child,
70025d765b044c6d8594bb965a2247a61e991a99johnny DDI_PROP_DONTPASS, "interrupts", -1) == -1)
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_SUCCESS);
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * Create the ddi_parent_private_data for a pseudo
70025d765b044c6d8594bb965a2247a61e991a99johnny * child.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny pci_common_set_parent_private_data(child);
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_SUCCESS);
70025d765b044c6d8594bb965a2247a61e991a99johnny }
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * The child was not merged into a h/w node,
70025d765b044c6d8594bb965a2247a61e991a99johnny * but there's not much we can do with it other
70025d765b044c6d8594bb965a2247a61e991a99johnny * than return failure to cause the node to be removed.
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny cmn_err(CE_WARN, "!%s@%s: %s.conf properties not merged",
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_get_name(child), ddi_get_name_addr(child),
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_get_name(child));
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_set_name_addr(child, NULL);
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_NOT_WELL_FORMED);
70025d765b044c6d8594bb965a2247a61e991a99johnny }
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny if (ddi_prop_get_int(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS,
70025d765b044c6d8594bb965a2247a61e991a99johnny "interrupts", -1) != -1)
70025d765b044c6d8594bb965a2247a61e991a99johnny pci_common_set_parent_private_data(child);
70025d765b044c6d8594bb965a2247a61e991a99johnny else
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_set_parent_data(child, NULL);
70025d765b044c6d8594bb965a2247a61e991a99johnny
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae /* Disable certain errors on PCIe drivers for x86 platforms */
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae regs = pcie_get_aer_uce_mask() | npe_aer_uce_mask;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae pcie_set_aer_uce_mask(regs);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae regs = pcie_get_aer_ce_mask() | npe_aer_ce_mask;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae pcie_set_aer_ce_mask(regs);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae regs = pcie_get_aer_suce_mask() | npe_aer_suce_mask;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae pcie_set_aer_suce_mask(regs);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * If URs are disabled, mask SERRs as well, otherwise the system will
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * still be notified of URs
70025d765b044c6d8594bb965a2247a61e991a99johnny */
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae if (npe_aer_uce_mask & PCIE_AER_UCE_UR)
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae pcie_set_serr_mask(1);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae
337fc9e235877b459e389f54daf9833bbc645439anish if (pci_config_setup(child, &cfg_hdl) == DDI_SUCCESS) {
337fc9e235877b459e389f54daf9833bbc645439anish npe_ck804_fix_aer_ptr(cfg_hdl);
a2de976fd11ced5331ebe7c3a8ffbaf11f5427cfPavel Potoplyak npe_nvidia_error_workaround(cfg_hdl);
a2de976fd11ced5331ebe7c3a8ffbaf11f5427cfPavel Potoplyak npe_intel_error_workaround(cfg_hdl);
337fc9e235877b459e389f54daf9833bbc645439anish pci_config_teardown(&cfg_hdl);
337fc9e235877b459e389f54daf9833bbc645439anish }
70025d765b044c6d8594bb965a2247a61e991a99johnny
c0da627439dfb642fb41ab7d78406fc69d2c64b2Zhi-Jun Robin Fu bus_p = PCIE_DIP2BUS(child);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae if (bus_p) {
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae uint16_t device_id = (uint16_t)(bus_p->bus_dev_ven_id >> 16);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae uint16_t vendor_id = (uint16_t)(bus_p->bus_dev_ven_id & 0xFFFF);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae uint16_t rev_id = bus_p->bus_rev_id;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae /* Disable AER for certain NVIDIA Chipsets */
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae if ((vendor_id == NVIDIA_VENDOR_ID) &&
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae (device_id == NVIDIA_CK804_DEVICE_ID) &&
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae (rev_id < NVIDIA_CK804_AER_VALID_REVID))
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae bus_p->bus_aer_off = 0;
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae
fc256490629fe68815f7e0f23cf9b3545720cfacJason Beloro pcie_init_dom(child);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae (void) pcie_initchild(child);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae }
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_SUCCESS);
70025d765b044c6d8594bb965a2247a61e991a99johnny}
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int
70025d765b044c6d8594bb965a2247a61e991a99johnnynpe_removechild(dev_info_t *dip)
70025d765b044c6d8594bb965a2247a61e991a99johnny{
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae pcie_uninitchild(dip);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_set_name_addr(dip, NULL);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny /*
70025d765b044c6d8594bb965a2247a61e991a99johnny * Strip the node to properly convert it back to prototype form
70025d765b044c6d8594bb965a2247a61e991a99johnny */
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_remove_minor_node(dip, NULL);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny ddi_prop_remove_all(dip);
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny return (DDI_SUCCESS);
70025d765b044c6d8594bb965a2247a61e991a99johnny}
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int
70025d765b044c6d8594bb965a2247a61e991a99johnnynpe_open(dev_t *devp, int flags, int otyp, cred_t *credp)
70025d765b044c6d8594bb965a2247a61e991a99johnny{
269473047d747f7815af570197e4ef7322d3632cEvan Yan minor_t minor = getminor(*devp);
269473047d747f7815af570197e4ef7322d3632cEvan Yan int instance = PCI_MINOR_NUM_TO_INSTANCE(minor);
269473047d747f7815af570197e4ef7322d3632cEvan Yan pci_state_t *pci_p = ddi_get_soft_state(npe_statep, instance);
269473047d747f7815af570197e4ef7322d3632cEvan Yan int rv;
70025d765b044c6d8594bb965a2247a61e991a99johnny
269473047d747f7815af570197e4ef7322d3632cEvan Yan /*
269473047d747f7815af570197e4ef7322d3632cEvan Yan * Make sure the open is for the right file type.
269473047d747f7815af570197e4ef7322d3632cEvan Yan */
269473047d747f7815af570197e4ef7322d3632cEvan Yan if (otyp != OTYP_CHR)
269473047d747f7815af570197e4ef7322d3632cEvan Yan return (EINVAL);
269473047d747f7815af570197e4ef7322d3632cEvan Yan
269473047d747f7815af570197e4ef7322d3632cEvan Yan if (pci_p == NULL)
269473047d747f7815af570197e4ef7322d3632cEvan Yan return (ENXIO);
269473047d747f7815af570197e4ef7322d3632cEvan Yan
269473047d747f7815af570197e4ef7322d3632cEvan Yan mutex_enter(&pci_p->pci_mutex);
269473047d747f7815af570197e4ef7322d3632cEvan Yan switch (PCI_MINOR_NUM_TO_PCI_DEVNUM(minor)) {
269473047d747f7815af570197e4ef7322d3632cEvan Yan case PCI_TOOL_REG_MINOR_NUM:
269473047d747f7815af570197e4ef7322d3632cEvan Yan case PCI_TOOL_INTR_MINOR_NUM:
269473047d747f7815af570197e4ef7322d3632cEvan Yan break;
269473047d747f7815af570197e4ef7322d3632cEvan Yan default:
269473047d747f7815af570197e4ef7322d3632cEvan Yan /* Handle devctl ioctls */
269473047d747f7815af570197e4ef7322d3632cEvan Yan rv = pcie_open(pci_p->pci_dip, devp, flags, otyp, credp);
269473047d747f7815af570197e4ef7322d3632cEvan Yan mutex_exit(&pci_p->pci_mutex);
269473047d747f7815af570197e4ef7322d3632cEvan Yan return (rv);
269473047d747f7815af570197e4ef7322d3632cEvan Yan }
269473047d747f7815af570197e4ef7322d3632cEvan Yan
269473047d747f7815af570197e4ef7322d3632cEvan Yan /* Handle pcitool ioctls */
269473047d747f7815af570197e4ef7322d3632cEvan Yan if (flags & FEXCL) {
269473047d747f7815af570197e4ef7322d3632cEvan Yan if (pci_p->pci_soft_state != PCI_SOFT_STATE_CLOSED) {
269473047d747f7815af570197e4ef7322d3632cEvan Yan mutex_exit(&pci_p->pci_mutex);
269473047d747f7815af570197e4ef7322d3632cEvan Yan cmn_err(CE_NOTE, "npe_open: busy");
269473047d747f7815af570197e4ef7322d3632cEvan Yan return (EBUSY);
269473047d747f7815af570197e4ef7322d3632cEvan Yan }
269473047d747f7815af570197e4ef7322d3632cEvan Yan pci_p->pci_soft_state = PCI_SOFT_STATE_OPEN_EXCL;
269473047d747f7815af570197e4ef7322d3632cEvan Yan } else {
269473047d747f7815af570197e4ef7322d3632cEvan Yan if (pci_p->pci_soft_state == PCI_SOFT_STATE_OPEN_EXCL) {
269473047d747f7815af570197e4ef7322d3632cEvan Yan mutex_exit(&pci_p->pci_mutex);
269473047d747f7815af570197e4ef7322d3632cEvan Yan cmn_err(CE_NOTE, "npe_open: busy");
269473047d747f7815af570197e4ef7322d3632cEvan Yan return (EBUSY);
269473047d747f7815af570197e4ef7322d3632cEvan Yan }
269473047d747f7815af570197e4ef7322d3632cEvan Yan pci_p->pci_soft_state = PCI_SOFT_STATE_OPEN;
269473047d747f7815af570197e4ef7322d3632cEvan Yan }
269473047d747f7815af570197e4ef7322d3632cEvan Yan mutex_exit(&pci_p->pci_mutex);
269473047d747f7815af570197e4ef7322d3632cEvan Yan
269473047d747f7815af570197e4ef7322d3632cEvan Yan return (0);
70025d765b044c6d8594bb965a2247a61e991a99johnny}
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int
269473047d747f7815af570197e4ef7322d3632cEvan Yannpe_close(dev_t dev, int flags, int otyp, cred_t *credp)
70025d765b044c6d8594bb965a2247a61e991a99johnny{
70025d765b044c6d8594bb965a2247a61e991a99johnny minor_t minor = getminor(dev);
269473047d747f7815af570197e4ef7322d3632cEvan Yan int instance = PCI_MINOR_NUM_TO_INSTANCE(minor);
70025d765b044c6d8594bb965a2247a61e991a99johnny pci_state_t *pci_p = ddi_get_soft_state(npe_statep, instance);
269473047d747f7815af570197e4ef7322d3632cEvan Yan int rv;
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnny if (pci_p == NULL)
70025d765b044c6d8594bb965a2247a61e991a99johnny return (ENXIO);
70025d765b044c6d8594bb965a2247a61e991a99johnny
269473047d747f7815af570197e4ef7322d3632cEvan Yan mutex_enter(&pci_p->pci_mutex);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae
269473047d747f7815af570197e4ef7322d3632cEvan Yan switch (PCI_MINOR_NUM_TO_PCI_DEVNUM(minor)) {
269473047d747f7815af570197e4ef7322d3632cEvan Yan case PCI_TOOL_REG_MINOR_NUM:
269473047d747f7815af570197e4ef7322d3632cEvan Yan case PCI_TOOL_INTR_MINOR_NUM:
269473047d747f7815af570197e4ef7322d3632cEvan Yan break;
269473047d747f7815af570197e4ef7322d3632cEvan Yan default:
269473047d747f7815af570197e4ef7322d3632cEvan Yan /* Handle devctl ioctls */
269473047d747f7815af570197e4ef7322d3632cEvan Yan rv = pcie_close(pci_p->pci_dip, dev, flags, otyp, credp);
269473047d747f7815af570197e4ef7322d3632cEvan Yan mutex_exit(&pci_p->pci_mutex);
269473047d747f7815af570197e4ef7322d3632cEvan Yan return (rv);
269473047d747f7815af570197e4ef7322d3632cEvan Yan }
70025d765b044c6d8594bb965a2247a61e991a99johnny
269473047d747f7815af570197e4ef7322d3632cEvan Yan /* Handle pcitool ioctls */
269473047d747f7815af570197e4ef7322d3632cEvan Yan pci_p->pci_soft_state = PCI_SOFT_STATE_CLOSED;
269473047d747f7815af570197e4ef7322d3632cEvan Yan mutex_exit(&pci_p->pci_mutex);
269473047d747f7815af570197e4ef7322d3632cEvan Yan return (0);
70025d765b044c6d8594bb965a2247a61e991a99johnny}
70025d765b044c6d8594bb965a2247a61e991a99johnny
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int
269473047d747f7815af570197e4ef7322d3632cEvan Yannpe_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp, int *rvalp)
70025d765b044c6d8594bb965a2247a61e991a99johnny{
269473047d747f7815af570197e4ef7322d3632cEvan Yan minor_t minor = getminor(dev);
269473047d747f7815af570197e4ef7322d3632cEvan Yan int instance = PCI_MINOR_NUM_TO_INSTANCE(minor);
269473047d747f7815af570197e4ef7322d3632cEvan Yan pci_state_t *pci_p = ddi_get_soft_state(npe_statep, instance);
269473047d747f7815af570197e4ef7322d3632cEvan Yan int ret = ENOTTY;
269473047d747f7815af570197e4ef7322d3632cEvan Yan
269473047d747f7815af570197e4ef7322d3632cEvan Yan if (pci_p == NULL)
269473047d747f7815af570197e4ef7322d3632cEvan Yan return (ENXIO);
269473047d747f7815af570197e4ef7322d3632cEvan Yan
269473047d747f7815af570197e4ef7322d3632cEvan Yan switch (PCI_MINOR_NUM_TO_PCI_DEVNUM(minor)) {
269473047d747f7815af570197e4ef7322d3632cEvan Yan case PCI_TOOL_REG_MINOR_NUM:
269473047d747f7815af570197e4ef7322d3632cEvan Yan case PCI_TOOL_INTR_MINOR_NUM:
269473047d747f7815af570197e4ef7322d3632cEvan Yan /* To handle pcitool related ioctls */
269473047d747f7815af570197e4ef7322d3632cEvan Yan ret = pci_common_ioctl(pci_p->pci_dip, dev, cmd, arg, mode,
269473047d747f7815af570197e4ef7322d3632cEvan Yan credp, rvalp);
269473047d747f7815af570197e4ef7322d3632cEvan Yan break;
269473047d747f7815af570197e4ef7322d3632cEvan Yan default:
269473047d747f7815af570197e4ef7322d3632cEvan Yan /* To handle devctl and hotplug related ioctls */
269473047d747f7815af570197e4ef7322d3632cEvan Yan ret = pcie_ioctl(pci_p->pci_dip, dev, cmd, arg, mode, credp,
269473047d747f7815af570197e4ef7322d3632cEvan Yan rvalp);
269473047d747f7815af570197e4ef7322d3632cEvan Yan break;
269473047d747f7815af570197e4ef7322d3632cEvan Yan }
269473047d747f7815af570197e4ef7322d3632cEvan Yan
269473047d747f7815af570197e4ef7322d3632cEvan Yan return (ret);
70025d765b044c6d8594bb965a2247a61e991a99johnny}
247980bee8b0de250570942681f1567bd54ad984anish
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet/*ARGSUSED*/
247980bee8b0de250570942681f1567bd54ad984anishstatic int
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreetnpe_fm_init(dev_info_t *dip, dev_info_t *tdip, int cap,
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ddi_iblock_cookie_t *ibc)
247980bee8b0de250570942681f1567bd54ad984anish{
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet pci_state_t *pcip = ddi_get_soft_state(npe_statep,
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ddi_get_instance(dip));
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ASSERT(ibc != NULL);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet *ibc = pcip->pci_fm_ibc;
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet return (pcip->pci_fmcap);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet}
247980bee8b0de250570942681f1567bd54ad984anish
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet/*ARGSUSED*/
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreetstatic int
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreetnpe_fm_callback(dev_info_t *dip, ddi_fm_error_t *derr, const void *no_used)
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet{
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae /*
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * On current x86 systems, npe's callback does not get called for failed
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * loads. If in the future this feature is used, the fault PA should be
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * logged in the derr->fme_bus_specific field. The appropriate PCIe
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * error handling code should be called and needs to be coordinated with
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae * safe access handling.
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae */
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae return (DDI_FM_OK);
247980bee8b0de250570942681f1567bd54ad984anish}