pci.c revision eae2e508a8e70b1ec407b10bd068c080651bbe5c
/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Host to PCI local bus driver
*/
#include <sys/pci_impl.h>
#include <sys/sysmacros.h>
/* Save minimal state. */
void *pci_statep;
/*
* Bus Operation functions
*/
void *, void *);
ddi_intr_handle_impl_t *, void *);
struct bus_ops pci_bus_ops = {
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)(); */
pci_fm_init, /* (*bus_fm_init)(); */
NULL, /* (*bus_fm_fini)(); */
NULL, /* (*bus_fm_access_enter)(); */
NULL, /* (*bus_fm_access_exit)(); */
NULL, /* (*bus_power)(); */
pci_intr_ops /* (*bus_intr_op)(); */
};
/*
* One goal here is to leverage off of the pcihp.c source without making
* changes to it. Call into it's cb_ops directly if needed, piggybacking
* anything else needed by the pci_tools.c module. Only pci_tools and pcihp
* will be opening PCI nexus driver file descriptors.
*/
caddr_t, int *);
struct cb_ops pci_cb_ops = {
pci_open, /* open */
pci_close, /* close */
nodev, /* strategy */
nodev, /* print */
nodev, /* dump */
nodev, /* read */
nodev, /* write */
pci_ioctl, /* ioctl */
nodev, /* devmap */
nodev, /* mmap */
nodev, /* segmap */
nochpoll, /* poll */
pci_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 */
pci_info, /* info */
nulldev, /* identify */
nulldev, /* probe */
pci_attach, /* attach */
pci_detach, /* detach */
nulldev, /* reset */
&pci_cb_ops, /* driver operations */
&pci_bus_ops /* bus operations */
};
/*
* This variable controls the default setting of the command register
* for pci devices. See pci_initchild() for details.
*/
/*
* Internal routines in support of particular pci_ctlops.
*/
/*
* Module linkage information for the kernel.
*/
&mod_driverops, /* Type of module */
"host to PCI nexus driver %I%",
&pci_ops, /* driver ops */
};
static struct modlinkage modlinkage = {
(void *)&modldrv,
};
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
{
/*
* Use the minor number as constructed by pcihp, as the index value to
* ddi_soft_state_zalloc.
*/
switch (cmd) {
case DDI_ATTACH:
break;
case DDI_RESUME:
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
!= DDI_PROP_SUCCESS) {
}
}
goto bad_soft_state;
}
/*
* Initialize hotplug support on this bus. At minimum
* (for non hotplug bus) this would create ":devctl" minor
* node to support DEVCTL_DEVICE_* and DEVCTL_BUS_* ioctls
* to this bus.
*/
goto bad_pcihp_init;
}
/* Second arg: initialize for pci, not pci_express */
goto bad_pcitool_init;
}
(void *)pcip->pci_fm_ibc);
(void *)pcip->pci_fm_ibc);
}
return (DDI_SUCCESS);
(void) pcihp_uninit(devi);
return (DDI_FAILURE);
}
/*ARGSUSED*/
static int
{
switch (cmd) {
case DDI_DETACH:
}
/* Uninitialize hotplug support on this bus. */
(void) pcihp_uninit(devi);
return (DDI_SUCCESS);
case DDI_SUSPEND:
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
}
static int
{
int rnumber;
int length;
int space;
/*
* 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
*/
/*
* Adjust offset and length
* A non-zero length means override the one in the regspec.
*/
if (len != 0)
switch (space) {
case PCI_ADDR_CONFIG:
/* No work required on unmap of Config space */
return (DDI_SUCCESS);
case PCI_ADDR_IO:
break;
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);
}
}
/* check for user mapping request - not legal for Config */
return (DDI_FAILURE);
}
/*
* check for config space
* On x86, CONFIG is not mapped via MMU and there is
* no endian-ness issues. Set the attr field in the handle to
* indicate that the common routines to call the nexus driver.
*/
if (space == PCI_ADDR_CONFIG) {
/* Can't map config space without a handle */
return (DDI_FAILURE);
/* record the device address for future reference */
}
/*
* 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_MEM64:
/*
* We can't handle 64-bit devices that are mapped above
* 4G or that are larger than 4G.
*/
if (pci_rp->pci_phys_mid != 0 ||
pci_rp->pci_size_hi != 0)
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);
}
}
/*ARGSUSED*/
static int
{
int rn;
int totreg;
struct attachspec *asp;
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);
}
}
case DDI_CTLOPS_PEEK:
case DDI_CTLOPS_POKE:
/* for now only X86 systems support PME wakeup from suspended state */
case DDI_CTLOPS_ATTACH:
return (DDI_FAILURE);
case DDI_CTLOPS_DETACH:
return (DDI_FAILURE);
default:
}
/* NOTREACHED */
}
/*
* pci_intr_ops
*/
static int
{
}
static int
{
char name[80];
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 */
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
/*
* initialize command register
*/
return (DDI_FAILURE);
/*
* Support for the "command-preserve" property.
*/
DDI_PROP_DONTPASS, "command-preserve", 0);
return (DDI_SUCCESS);
}
static int
{
struct ddi_parent_private_data *pdptr;
}
/*
* Strip the node to properly convert it back to prototype form
*/
return (DDI_SUCCESS);
}
/*
* When retrofitting this module for pci_tools, functions such as open, close,
* and ioctl are now pulled into this module. Before this, the functions in
* the pcihp module were referenced directly. Now they are called or
* referenced through the pcihp cb_ops structure from functions in this module.
*/
static int
{
}
static int
{
}
static int
{
return (ENXIO);
}
static int
{
}
static int
{
}
}
/*ARGSUSED*/
static int
{
}
/*ARGSUSED*/
static int
{
return (derr->fme_status);
}