/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved.
*/
/*
* Host to PCI-Express local bus driver
*/
#include <sys/pci_impl.h>
#include <sys/pcie_impl.h>
#include <sys/sysmacros.h>
#include <sys/ddi_intr.h>
/*
* Helper Macros
*/
ah_platform_private)-> \
/*
* Bus Operation functions
*/
void *, void *);
ddi_intr_handle_impl_t *, void *);
/*
* Disable URs and Received MA for all PCIe devices. Until x86 SW is changed so
* that random drivers do not do PIO accesses on devices that it does not own,
* these error bits must be disabled. SERR must also be disabled if URs have
* been masked.
*/
NULL,
NULL,
NULL,
NULL,
0, /* (*bus_get_eventcookie)(); */
0, /* (*bus_add_eventcall)(); */
0, /* (*bus_remove_eventcall)(); */
0, /* (*bus_post_event)(); */
0, /* (*bus_intr_ctl)(); */
0, /* (*bus_config)(); */
0, /* (*bus_unconfig)(); */
npe_fm_init, /* (*bus_fm_init)(); */
NULL, /* (*bus_fm_fini)(); */
NULL, /* (*bus_fm_access_enter)(); */
NULL, /* (*bus_fm_access_exit)(); */
NULL, /* (*bus_power)(); */
npe_intr_ops, /* (*bus_intr_op)(); */
pcie_hp_common_ops /* (*bus_hp_op)(); */
};
npe_open, /* open */
npe_close, /* close */
nodev, /* strategy */
nodev, /* print */
nodev, /* dump */
nodev, /* read */
nodev, /* write */
npe_ioctl, /* ioctl */
nodev, /* devmap */
nodev, /* mmap */
nodev, /* segmap */
nochpoll, /* poll */
pcie_prop_op, /* cb_prop_op */
NULL, /* streamtab */
CB_REV, /* rev */
nodev, /* int (*cb_aread)() */
nodev /* int (*cb_awrite)() */
};
/*
* Device Node Operation functions
*/
DEVO_REV, /* devo_rev */
0, /* refcnt */
npe_info, /* info */
nulldev, /* identify */
nulldev, /* probe */
npe_attach, /* attach */
npe_detach, /* detach */
nulldev, /* reset */
&npe_cb_ops, /* driver operations */
&npe_bus_ops, /* bus operations */
NULL, /* power */
ddi_quiesce_not_needed, /* quiesce */
};
/*
* Internal routines in support of particular npe_ctlops.
*/
/*
* External support routine
*/
/*
* Module linkage information for the kernel.
*/
&mod_driverops, /* Type of module */
"Host to PCIe nexus driver", /* Name of module */
&npe_ops, /* driver ops */
};
(void *)&modldrv,
};
/* Save minimal state. */
void *npe_statep;
int
_init(void)
{
int e;
/*
* Initialize per-pci bus soft state pointer.
*/
if (e != 0)
return (e);
if ((e = mod_install(&modlinkage)) != 0)
return (e);
}
int
_fini(void)
{
int rc;
if (rc != 0)
return (rc);
return (rc);
}
int
{
}
/*ARGSUSED*/
static int
{
switch (cmd) {
case DDI_INFO_DEVT2INSTANCE:
break;
case DDI_INFO_DEVT2DEVINFO:
ret = DDI_FAILURE;
break;
}
break;
default:
ret = DDI_FAILURE;
break;
}
return (ret);
}
/*ARGSUSED*/
static int
{
if (cmd == DDI_RESUME) {
/*
* the system might still be able to resume even if this fails
*/
(void) npe_restore_htconfig_children(devi);
return (DDI_SUCCESS);
}
/*
* We must do this here in order to ensure that all top level devices
* get their HyperTransport MSI mapping regs programmed first.
* "Memory controller" and "hostbridge" class devices are leaf devices
* that may affect MSI translation functionality for devices
*
* This will also program HT MSI mapping registers on root buses
* devices (basically sitting on an HT bus) that are not dependent
* on the aforementioned HT devices for MSI translation.
*/
"pciex") != DDI_PROP_SUCCESS) {
}
return (DDI_FAILURE);
goto fail1;
/* Second arg: initialize for pci_express root nexus */
goto fail2;
}
return (DDI_SUCCESS);
(void) pcie_uninit(devi);
return (DDI_FAILURE);
}
/*ARGSUSED*/
static int
{
switch (cmd) {
case DDI_DETACH:
/* Uninitialize pcitool support. */
return (DDI_FAILURE);
return (DDI_SUCCESS);
case DDI_SUSPEND:
/*
* this fails
*/
(void) npe_save_htconfig_children(devi);
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
}
/*
* Configure the access handle for standard configuration space
* access (see pci_fm_acc_setup for code that initializes the
* access-function pointers).
*/
static int
{
int ret;
DDI_SUCCESS) {
!= DDI_DEFAULT_ACC) {
}
}
return (ret);
}
static int
{
int rnumber;
int length;
int space;
int retval;
/*
* check for register number
*/
case DDI_MT_REGSPEC:
return (DDI_FAILURE);
break;
case DDI_MT_RNUMBER:
/*
* get ALL "reg" properties for dip, select the one of
* of interest. In x86, "assigned-addresses" property
* is identical to the "reg" property, so there is no
* need to cross check the two to determine the physical
* address of the registers.
* This routine still performs some validity checks to
* make sure that everything is okay.
*/
return (DDI_FAILURE);
/*
* validate the register number.
*/
length /= (sizeof (pci_regspec_t) / sizeof (int));
return (DDI_FAILURE);
}
/*
* copy the required entry.
*/
/*
* free the memory allocated by ddi_prop_lookup_int_array
*/
return (DDI_FAILURE);
break;
default:
return (DDI_ME_INVAL);
}
/*
* check for unmap and unlock of address space
*/
switch (space) {
case PCI_ADDR_IO:
break;
case PCI_ADDR_CONFIG:
/*
* space mapping (memory-mapped config space mappings
* would have the DDI_ACCATTR_CPU_VADDR bit set in the
* acc_attr), undo that setup here.
*/
!= DDI_DEFAULT_ACC) {
(void *)mp->map_handlep);
}
return (DDI_SUCCESS);
}
/* FALLTHROUGH */
case PCI_ADDR_MEM64:
/*
* MEM64 requires special treatment on map, to check
* that the device is below 4G. On unmap, however,
* we can assume that everything is OK... the map
* must have succeeded.
*/
/* FALLTHROUGH */
case PCI_ADDR_MEM32:
reg.regspec_bustype = 0;
break;
default:
return (DDI_FAILURE);
}
/*
* Adjust offset and length
* A non-zero length means override the one in the regspec.
*/
if (len != 0)
(void *)mp->map_handlep);
}
return (retval);
}
/* check for user mapping request - not legal for Config */
return (DDI_FAILURE);
}
/*
* Note that pci_fm_acc_setup() is called to serve two purposes
* i) enable legacy PCI I/O style config space access
* ii) register with FMA
*/
if (space == PCI_ADDR_CONFIG) {
/* Can't map config space without a handle */
return (DDI_FAILURE);
/* record the device address for future reference */
/* Check if MMCFG is supported */
if (!npe_is_mmcfg_supported(rdip)) {
}
if (nelem != 4 ||
/*
* Invalid property or Doesn't contain the
* requested bus; fall back to standard
*/
} else {
}
} else {
/*
* Couldn't find the MMCFG property -- fall back to
* standard config access
*/
}
}
/*
* range check
*/
return (DDI_FAILURE);
/*
* Adjust offset and length
* A non-zero length means override the one in the regspec.
*/
if (len != 0)
/*
* convert the pci regsec into the generic regspec used by the
* parent root nexus driver.
*/
switch (space) {
case PCI_ADDR_IO:
break;
case PCI_ADDR_CONFIG:
case PCI_ADDR_MEM64:
/*
* We can't handle 64-bit devices that are mapped above
* 4G or that are larger than 4G.
*/
return (DDI_FAILURE);
/*
* Other than that, we can treat them as 32-bit mappings
*/
/* FALLTHROUGH */
case PCI_ADDR_MEM32:
reg.regspec_bustype = 0;
break;
default:
return (DDI_FAILURE);
}
if (retval == DDI_SUCCESS) {
/*
* For config space gets force use of cautious access routines.
* These will handle default and protected mode accesses too.
*/
if (space == PCI_ADDR_CONFIG) {
}
}
}
return (retval);
}
/*ARGSUSED*/
static int
{
int rn;
int totreg;
switch (ctlop) {
case DDI_CTLOPS_REPORTDEV:
if (rdip == (dev_info_t *)0)
return (DDI_FAILURE);
return (DDI_SUCCESS);
case DDI_CTLOPS_INITCHILD:
case DDI_CTLOPS_UNINITCHILD:
case DDI_CTLOPS_SIDDEV:
return (DDI_SUCCESS);
case DDI_CTLOPS_REGSIZE:
case DDI_CTLOPS_NREGS:
if (rdip == (dev_info_t *)0)
return (DDI_FAILURE);
*(int *)result = 0;
®len) != DDI_PROP_SUCCESS) {
return (DDI_FAILURE);
}
if (ctlop == DDI_CTLOPS_NREGS)
else if (ctlop == DDI_CTLOPS_REGSIZE) {
return (DDI_FAILURE);
}
}
return (DDI_SUCCESS);
case DDI_CTLOPS_POWER:
{
/*
* We currently understand reporting of PCI_PM_IDLESPEED
* capability. Everything else is passed up.
*/
return (DDI_SUCCESS);
break;
}
case DDI_CTLOPS_PEEK:
case DDI_CTLOPS_POKE:
/* X86 systems support PME wakeup from suspended state */
case DDI_CTLOPS_ATTACH:
return (DDI_SUCCESS);
(void) pcie_postattach_child(rdip);
}
/* only do this for immediate children */
/* Not good, better stop now. */
"Couldn't pre-resume device %p",
(void *) dip);
/* NOTREACHED */
}
return (DDI_SUCCESS);
case DDI_CTLOPS_DETACH:
return (DDI_SUCCESS);
/* only do this for immediate children */
return (DDI_FAILURE);
return (DDI_SUCCESS);
default:
break;
}
}
/*
* npe_intr_ops
*/
static int
{
}
static int
{
/*
* Do not bind drivers to empty bridges.
* Fail above, if the bridge is found to be hotplug capable
*/
return (DDI_FAILURE);
return (DDI_FAILURE);
/*
* Pseudo nodes indicate a prototype node with per-instance
* properties to be merged into the real h/w device node.
* The interpretation of the unit-address is DD[,F]
* where DD is the device id and F is the function.
*/
if (ndi_dev_is_persistent_node(child) == 0) {
extern int pci_allow_pseudo_children;
/*
* Try to merge the properties from this prototype
* node into real h/w nodes.
*/
DDI_SUCCESS) {
/*
* Merged ok - return failure to remove the node.
*/
return (DDI_FAILURE);
}
/* workaround for DDIVS to run under PCI Express */
if (pci_allow_pseudo_children) {
/*
* If the "interrupts" property doesn't exist,
* this must be the ddivs no-intr case, and it returns
* DDI_SUCCESS instead of DDI_FAILURE.
*/
return (DDI_SUCCESS);
/*
* Create the ddi_parent_private_data for a pseudo
* child.
*/
return (DDI_SUCCESS);
}
/*
* The child was not merged into a h/w node,
* but there's not much we can do with it other
* than return failure to cause the node to be removed.
*/
return (DDI_NOT_WELL_FORMED);
}
"interrupts", -1) != -1)
else
/* Disable certain errors on PCIe drivers for x86 platforms */
/*
* If URs are disabled, mask SERRs as well, otherwise the system will
* still be notified of URs
*/
if (npe_aer_uce_mask & PCIE_AER_UCE_UR)
}
if (bus_p) {
/* Disable AER for certain NVIDIA Chipsets */
if ((vendor_id == NVIDIA_VENDOR_ID) &&
(device_id == NVIDIA_CK804_DEVICE_ID) &&
bus_p->bus_aer_off = 0;
(void) pcie_initchild(child);
}
return (DDI_SUCCESS);
}
static int
{
/*
* Strip the node to properly convert it back to prototype form
*/
return (DDI_SUCCESS);
}
static int
{
int rv;
/*
* Make sure the open is for the right file type.
*/
return (EINVAL);
return (ENXIO);
switch (PCI_MINOR_NUM_TO_PCI_DEVNUM(minor)) {
case PCI_TOOL_REG_MINOR_NUM:
case PCI_TOOL_INTR_MINOR_NUM:
break;
default:
/* Handle devctl ioctls */
return (rv);
}
/* Handle pcitool ioctls */
return (EBUSY);
}
} else {
return (EBUSY);
}
}
return (0);
}
static int
{
int rv;
return (ENXIO);
switch (PCI_MINOR_NUM_TO_PCI_DEVNUM(minor)) {
case PCI_TOOL_REG_MINOR_NUM:
case PCI_TOOL_INTR_MINOR_NUM:
break;
default:
/* Handle devctl ioctls */
return (rv);
}
/* Handle pcitool ioctls */
return (0);
}
static int
{
return (ENXIO);
switch (PCI_MINOR_NUM_TO_PCI_DEVNUM(minor)) {
case PCI_TOOL_REG_MINOR_NUM:
case PCI_TOOL_INTR_MINOR_NUM:
/* To handle pcitool related ioctls */
break;
default:
/* To handle devctl and hotplug related ioctls */
rvalp);
break;
}
return (ret);
}
/*ARGSUSED*/
static int
{
}
/*ARGSUSED*/
static int
{
/*
* On current x86 systems, npe's callback does not get called for failed
* loads. If in the future this feature is used, the fault PA should be
* logged in the derr->fme_bus_specific field. The appropriate PCIe
* error handling code should be called and needs to be coordinated with
* safe access handling.
*/
return (DDI_FM_OK);
}