simba.c revision 15e1afcd5e908ae29b1e6018838638befdc225a2
/*
* 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.
*/
/*
* PCI to PCI bus bridge nexus driver
*/
#include <sys/autoconf.h>
#include <sys/ddi_impldefs.h>
#include <sys/ddi_subrdefs.h>
static uint_t simba_debug_flags = 0;
#define D_IDENTIFY 0x00000001
#define D_ATTACH 0x00000002
#define D_DETACH 0x00000004
#define D_MAP 0x00000008
#define D_CTLOPS 0x00000010
#define D_G_ISPEC 0x00000020
#define D_A_ISPEC 0x00000040
#define D_INIT_CLD 0x00400000
#define D_FAULT 0x00000080
#define DEBUG0(f, s) if ((f)& simba_debug_flags) \
#define DEBUG1(f, s, a) if ((f)& simba_debug_flags) \
#define DEBUG2(f, s, a, b) if ((f)& simba_debug_flags) \
#define DEBUG3(f, s, a, b, c) if ((f)& simba_debug_flags) \
#define DEBUG4(f, s, a, b, c, d) if ((f)& simba_debug_flags) \
#define DEBUG5(f, s, a, b, c, d, e) if ((f)& simba_debug_flags) \
#else
#define DEBUG0(f, s)
#define DEBUG1(f, s, a)
#define DEBUG2(f, s, a, b)
#define DEBUG3(f, s, a, b, c)
#define DEBUG4(f, s, a, b, c, d)
#define DEBUG5(f, s, a, b, c, d, e)
#endif
/*
* The variable controls the default setting of the command register
* for pci devices. See simba_initchild() for details.
*/
void *, void *);
struct bus_ops simba_bus_ops = {
0,
0,
0,
0,
0,
0,
NULL,
0,
};
static struct cb_ops simba_cb_ops = {
simba_open, /* open */
simba_close, /* close */
nulldev, /* strategy */
nulldev, /* print */
nulldev, /* dump */
nulldev, /* read */
nulldev, /* write */
simba_ioctl, /* ioctl */
nodev, /* devmap */
nodev, /* mmap */
nodev, /* segmap */
nochpoll, /* poll */
ddi_prop_op, /* cb_prop_op */
NULL, /* streamtab */
CB_REV, /* rev */
nodev, /* int (*cb_aread)() */
nodev /* int (*cb_awrite)() */
};
static int simba_probe(dev_info_t *);
DEVO_REV, /* devo_rev */
0, /* refcnt */
simba_info, /* info */
nulldev, /* identify */
simba_probe, /* probe */
simba_attach, /* attach */
simba_detach, /* detach */
nulldev, /* reset */
&simba_cb_ops, /* driver operations */
&simba_bus_ops, /* bus operations */
NULL,
ddi_quiesce_not_supported, /* devo_quiesce */
};
/*
* Module linkage information for the kernel.
*/
&mod_driverops, /* Type of module */
"SIMBA PCI to PCI bridge nexus driver",
&simba_ops, /* driver ops */
};
static struct modlinkage modlinkage = {
(void *)&modldrv,
};
/*
* Simba specific error state structure
*/
struct simba_errstate {
char *error;
int bridge_secondary;
};
struct simba_cfg_state {
};
/*
* soft state pointer and structure template:
*/
static void *simba_state;
typedef struct {
/*
* configuration register state for the bus:
*/
/*
* cpr support:
*/
struct simba_cfg_state *simba_config_state_p;
int fm_cap;
#define SIMBA_SOFT_STATE_CLOSED 0x00
#define SIMBA_SOFT_STATE_OPEN 0x01
#define SIMBA_SOFT_STATE_OPEN_EXCL 0x02
/*
* The following variable enables a workaround for the following obp bug:
*
* 1234181 - obp should set latency timer registers in pci
* configuration header
*
* Until this bug gets fixed in the obp, the following workaround should
* be enabled.
*/
/*
* The following variable enables a workaround for an obp bug to be
* submitted. A bug requesting a workaround fof this problem has
* been filed:
*
* 1235094 - need workarounds on positron nexus drivers to set cache
* line size registers
*
* Until this bug gets fixed in the obp, the following workaround should
* be enabled.
*/
/*
* forward function declarations:
*/
static void simba_uninitchild(dev_info_t *);
const void *impl_data);
int
_init(void)
{
int e;
return (e);
}
int
_fini(void)
{
int e;
if ((e = mod_remove(&modlinkage)) == 0)
return (e);
}
int
{
}
/*ARGSUSED*/
static int
{
int instance;
instance);
switch (infocmd) {
default:
return (DDI_FAILURE);
case DDI_INFO_DEVT2INSTANCE:
return (DDI_SUCCESS);
case DDI_INFO_DEVT2DEVINFO:
return (DDI_FAILURE);
return (DDI_SUCCESS);
}
}
/*ARGSUSED*/
static int
{
return (DDI_PROBE_SUCCESS);
}
/*ARGSUSED*/
static int
{
int instance;
switch (cmd) {
case DDI_ATTACH:
/*
* Make sure the "device_type" property exists.
*/
"device_type", "pci");
/*
* Allocate and get soft state structure.
*/
return (DDI_FAILURE);
instance);
/*
* create minor node for devctl interfaces
*/
DDI_NT_NEXUS, 0) != DDI_SUCCESS) {
return (DDI_FAILURE);
}
DDI_SUCCESS) {
return (DDI_FAILURE);
}
/*
* Simba cache line size is 64 bytes and hardwired.
*/
/*
* Initialize FMA support
*/
/*
* Call parent to get it's capablity
*/
return (DDI_SUCCESS);
case DDI_RESUME:
/*
* Get the soft state structure for the bridge.
*/
simba = (simba_devstate_t *)
return (DDI_SUCCESS);
}
return (DDI_FAILURE);
}
/*ARGSUSED*/
static int
{
simba = (simba_devstate_t *)
switch (cmd) {
case DDI_DETACH:
return (DDI_SUCCESS);
case DDI_SUSPEND:
return (DDI_SUCCESS);
}
return (DDI_FAILURE);
}
/*ARGSUSED*/
static int
{
register dev_info_t *pdip;
}
/*
* Registered error handling callback with our parent
*/
static int
{
struct simba_errstate simba_err;
int ret = 0;
return (ret);
}
static char *ops[] =
{
"DDI_CTLOPS_DMAPMAPC",
"DDI_CTLOPS_INITCHILD",
"DDI_CTLOPS_UNINITCHILD",
"DDI_CTLOPS_REPORTDEV",
"DDI_CTLOPS_REPORTINT",
"DDI_CTLOPS_REGSIZE",
"DDI_CTLOPS_NREGS",
"DDI_CTLOPS_RESERVED0",
"DDI_CTLOPS_SIDDEV",
"DDI_CTLOPS_SLAVEONLY",
"DDI_CTLOPS_AFFINITY",
"DDI_CTLOPS_IOMIN",
"DDI_CTLOPS_PTOB",
"DDI_CTLOPS_BTOP",
"DDI_CTLOPS_BTOPR",
"DDI_CTLOPS_RESERVED1",
"DDI_CTLOPS_RESERVED2",
"DDI_CTLOPS_RESERVED3",
"DDI_CTLOPS_RESERVED4",
"DDI_CTLOPS_RESERVED5",
"DDI_CTLOPS_DVMAPAGESIZE",
"DDI_CTLOPS_POWER",
"DDI_CTLOPS_ATTACH",
"DDI_CTLOPS_DETACH",
"DDI_CTLOPS_POKE",
"DDI_CTLOPS_PEEK"
};
#endif
/*ARGSUSED*/
static int
{
int reglen;
int rn;
int totreg;
"simba_ctlops(): dip=%p rdip=%p ctlop=%x-%s arg=%p result=%p",
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:
return (DDI_SUCCESS);
case DDI_CTLOPS_SIDDEV:
return (DDI_SUCCESS);
case DDI_CTLOPS_REGSIZE:
case DDI_CTLOPS_NREGS:
if (rdip == (dev_info_t *)0)
return (DDI_FAILURE);
break;
default:
}
*(int *)result = 0;
return (DDI_FAILURE);
if (ctlop == DDI_CTLOPS_NREGS)
else if (ctlop == DDI_CTLOPS_REGSIZE) {
return (DDI_FAILURE);
}
}
return (DDI_SUCCESS);
}
static int
{
if (ndi_dev_is_persistent_node(child) == 0) {
char **unit_addr;
/* name .conf nodes by "unit-address" property" */
return (DDI_FAILURE);
}
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/* name hardware nodes by "reg" property */
(int **)&pci_rp, &n) != DDI_SUCCESS)
return (DDI_FAILURE);
/* get the device identifications */
if (func != 0)
else
return (DDI_SUCCESS);
}
static int
{
char name[MAXNAMELEN];
int i;
uint_t n;
/*
* 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;
DDI_SUCCESS) {
"cannot merge prototype from %s.conf",
return (DDI_NOT_WELL_FORMED);
}
return (DDI_NOT_WELL_FORMED);
/*
* Try to merge the properties from this prototype
* node into real h/w nodes.
*/
/*
* Merged ok - return failure to remove the node.
*/
return (DDI_FAILURE);
}
/* workaround for ddivs to run under PCI */
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);
}
/*
* Initialize real h/w nodes
*/
return (DDI_FAILURE);
return (DDI_FAILURE);
}
/*
* Determine the configuration header type.
*/
/*
* Support for the "command-preserve" property.
*/
DDI_PROP_DONTPASS, "command-preserve", 0);
/* clean up all PCI child devices status register */
/*
* If the device has a primary bus control register then program it
* based on the settings in the command register.
*/
}
/*
* Initialize cache-line-size configuration register if needed.
*/
"cache-line-size", 0) == 0) {
if (n != 0)
"cache-line-size", n);
}
/*
* Initialize latency timer configuration registers if needed.
*/
"latency-timer", 0) == 0) {
} else {
}
if (n != 0)
"latency-timer", n);
}
return (DDI_SUCCESS);
}
static void
{
/*
* Strip the node to properly convert it back to prototype form
*/
}
/*
* simba_save_config_regs
*
* This routine saves the state of the configuration registers of all
* the child nodes of each PBM.
*
* used by: simba_detach() on suspends
*
* return value: none
*/
static void
{
int i;
struct simba_cfg_state *statep;
if (i_ddi_devi_attached(dip))
i++;
}
if (!i)
return;
if (!simba_p->simba_config_state_p) {
return;
}
simba_p->config_state_index = i;
if (!i_ddi_devi_attached(dip)) {
continue;
}
continue;
}
dip);
/*
* Simba specific.
*/
statep->bus_number =
}
statep++;
}
}
/*
* simba_restore_config_regs
*
* This routine restores the state of the configuration registers of all
* the child nodes of each PBM.
*
* used by: simba_attach() on resume
*
* return value: none
*/
static void
{
int i;
if (!simba_p->config_state_index)
return;
if (!dip) {
"%s%d: skipping bad dev info (%d)\n",
i);
continue;
}
dip,
continue;
}
/*
* Simba specific.
*/
statep->bus_number);
}
}
simba_p->config_state_index = 0;
}
/* ARGSUSED */
static int
{
/*
* Make sure the open is for the right file type.
*/
return (EINVAL);
/*
* Get the soft state structure for the device.
*/
return (ENXIO);
/*
* Handle the open by tracking the device state.
*/
return (EBUSY);
}
} else {
return (EBUSY);
}
}
return (0);
}
/* ARGSUSED */
static int
{
return (EINVAL);
return (ENXIO);
return (0);
}
/*
* simba_ioctl: devctl hotplug controls
*/
/* ARGSUSED */
static int
int *rvalp)
{
struct devctl_iocdata *dcp;
int rv = 0;
return (ENXIO);
/*
* We can use the generic implementation for these ioctls
*/
switch (cmd) {
case DEVCTL_DEVICE_GETSTATE:
case DEVCTL_DEVICE_ONLINE:
case DEVCTL_DEVICE_OFFLINE:
case DEVCTL_BUS_GETSTATE:
}
/*
* read devctl ioctl data
*/
return (EFAULT);
switch (cmd) {
case DEVCTL_DEVICE_RESET:
break;
case DEVCTL_BUS_QUIESCE:
if (bus_state == BUS_QUIESCED)
break;
break;
case DEVCTL_BUS_UNQUIESCE:
if (bus_state == BUS_ACTIVE)
break;
break;
case DEVCTL_BUS_RESET:
break;
case DEVCTL_BUS_RESETALL:
break;
default:
}
return (rv);
}
/*
* Initialize FMA resources for children devices. Called when
* child calls ddi_fm_init().
*/
/*ARGSUSED*/
static int
{
}
static void
{
}
/* ARGSUSED */
static void
{
}