pci_common.c revision a54f81fbf66e3e4c14a94d571c0fe241e4cf2394
/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* File that has code which is common between pci(7d) and npe(7d)
* It shares the following:
* - interrupt code
* - pci_tools ioctl code
* - name_child code
* - set_parent_private_data code
*/
#include <sys/mach_intr.h>
#include <sys/pci_intr_lib.h>
#include <sys/sysmacros.h>
#include <sys/pci_tools.h>
#include <sys/pci_cfgspace.h>
#include <sys/pci_impl.h>
/*
* Function prototypes
*/
/* Extern decalration for pcplusmp module */
psm_intr_op_t, int *);
/*
* pci_name_child:
*
* Assign the address portion of the node name
*/
int
{
char **unit_addr;
uint_t n;
if (ndi_dev_is_persistent_node(child) == 0) {
/*
* For .conf node, use "unit-address" property
*/
return (DDI_FAILURE);
}
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
return (DDI_FAILURE);
}
/* copy the device identifications */
/*
* free the memory allocated by ddi_prop_lookup_int_array
*/
if (func != 0) {
} else {
}
return (DDI_SUCCESS);
}
/*
* Interrupt related code:
*
* The following busop is common to npe and pci drivers
* bus_introp
*/
/*
* Create the ddi_parent_private_data for a pseudo child.
*/
void
{
struct ddi_parent_private_data *pdptr;
(sizeof (struct ddi_parent_private_data) +
}
/*
* pci_get_priority:
* Figure out the priority of the device
*/
static int
{
return (DDI_SUCCESS);
}
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
static int pcie_pci_intr_pri_counter = 0;
/*
* pci_common_intr_ops: bus_intr_op() function for interrupt support
*/
int
{
int priority = 0;
int psm_status = 0;
int pci_status = 0;
int types = 0;
int pciepci = 0;
int i, j, count;
int behavior;
int cap_ptr;
"pci_common_intr_ops: pdip 0x%p, rdip 0x%p, op %x handle 0x%p\n",
/* Process the request */
switch (intr_op) {
/* Fixed supported by default */
*(int *)result = DDI_INTR_TYPE_FIXED;
/* Figure out if MSI or MSI-X is supported? */
return (DDI_SUCCESS);
if (psm_intr_ops != NULL) {
/*
* Only support MSI for now, OR it in
*/
"rdip: 0x%p supported types: 0x%x\n", (void *)rdip,
*(int *)result));
}
break;
case DDI_INTROP_NAVAIL:
case DDI_INTROP_NINTRS:
result) != DDI_SUCCESS)
return (DDI_FAILURE);
} else {
if (*(int *)result == 0)
return (DDI_FAILURE);
}
break;
case DDI_INTROP_ALLOC:
/*
* MSI or MSIX (figure out number of vectors available)
* FIXED interrupts: just return available interrupts
*/
(psm_intr_ops != NULL) &&
/*
* Following check is a special case for 'pcie_pci'.
* This makes sure vectors with the right priority
* are allocated for pcie_pci during ALLOC time.
*/
pciepci = 1;
} else
/*
* Cache in the config handle and cap_ptr
*/
return (DDI_FAILURE);
}
if (i_ddi_get_msi_msix_cap_ptr(rdip) == 0) {
char *prop =
"pci-msi-capid-pointer" :
"pci-msix-capid-pointer";
}
/* verify behavior flag and take appropriate action */
if ((behavior == DDI_INTR_ALLOC_STRICT) &&
"pci_common_intr_ops: behavior %x, "
"couldn't get enough intrs\n", behavior));
return (DDI_EAGAIN);
}
if (msix_p)
msix_p);
}
}
if (pciepci) {
/* update priority in ispec */
if (ispec)
}
/* Figure out if this device supports MASKING */
} else
return (DDI_FAILURE);
break;
case DDI_INTROP_FREE:
(psm_intr_ops != NULL)) {
0) {
rdip)) {
(void) pci_config_teardown(&handle);
}
}
if (msix_p &&
}
}
}
break;
case DDI_INTROP_GETPRI:
/* Get the priority */
return (DDI_FAILURE);
"priority = 0x%x\n", priority));
break;
case DDI_INTROP_SETPRI:
/* Validate the interrupt priority passed */
if (*(int *)result > LOCK_LEVEL)
return (DDI_FAILURE);
/* Ensure that PSM is all initialized */
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
/* Change the priority */
return (DDI_FAILURE);
/* update ispec */
if (ispec)
break;
case DDI_INTROP_ADDISR:
/* update ispec */
if (ispec) {
}
break;
case DDI_INTROP_REMISR:
/* Get the interrupt structure pointer */
if (ispec) {
}
break;
case DDI_INTROP_GETCAP:
/*
* MSI capability register(s)
*/
&pci_status);
/* next check with pcplusmp */
if (psm_intr_ops != NULL)
"psm_status = %x, pci_rval = %x, pci_status = %x\n",
*(int *)result = 0;
return (DDI_FAILURE);
}
if (psm_rval == PSM_SUCCESS)
*(int *)result = psm_status;
if (pci_rval == DDI_SUCCESS)
*(int *)result |= pci_status;
*(int *)result));
break;
case DDI_INTROP_SETCAP:
"SETCAP cap=0x%x\n", *(int *)result));
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
" returned failure\n"));
return (DDI_FAILURE);
}
break;
case DDI_INTROP_ENABLE:
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
return (DDI_FAILURE);
break;
case DDI_INTROP_DISABLE:
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
break;
case DDI_INTROP_BLOCKENABLE:
"BLOCKENABLE\n"));
return (DDI_FAILURE);
}
/* Check if psm_intr_ops is NULL? */
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
for (i = 0; i < count; i++) {
"pci_enable_intr failed for %d\n", i));
for (j = 0; j < i; j++) {
}
return (DDI_FAILURE);
}
}
break;
case DDI_INTROP_BLOCKDISABLE:
"BLOCKDISABLE\n"));
return (DDI_FAILURE);
}
/* Check if psm_intr_ops is present */
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
for (i = 0; i < count; i++) {
}
break;
case DDI_INTROP_SETMASK:
case DDI_INTROP_CLRMASK:
/*
* First handle in the config space
*/
if (intr_op == DDI_INTROP_SETMASK) {
} else {
}
/* For MSI/X; no need to check with pcplusmp */
return (pci_status);
/* For fixed interrupts only: handle config space first */
break;
/* For fixed interrupts only: confer with pcplusmp next */
if (psm_intr_ops != NULL) {
/* If interrupt is shared; do nothing */
return (pci_status);
if (intr_op == DDI_INTROP_SETMASK)
else
}
case DDI_INTROP_GETPENDING:
/*
* MSI capability register(s)
*/
/* On failure; next try with pcplusmp */
"psm_rval = %x, psm_status = %x, pci_rval = %x, "
pci_status));
*(int *)result = 0;
return (DDI_FAILURE);
}
if (psm_rval != PSM_FAILURE)
*(int *)result = psm_status;
else if (pci_rval != DDI_FAILURE)
*(int *)result = pci_status;
*(int *)result));
break;
default:
}
return (DDI_SUCCESS);
}
int
{
if (is_irq)
/*
* For this locally-declared and used handle, ih_private will contain a
* pointer to apic_get_intr_t, not an ihdl_plat_t as used for
* global interrupt handling.
*/
return (DDI_FAILURE);
return (DDI_SUCCESS);
}
int
{
int rval;
if (rval == DDI_SUCCESS)
return (intrinfo.avgi_cpu_id);
else
return (-1);
}
static int
{
int irq;
/* Translate the interrupt if needed */
return (DDI_FAILURE);
/* translate the interrupt if needed */
/* Add the interrupt handler */
return (DDI_FAILURE);
/* Note this really is an irq. */
return (DDI_SUCCESS);
}
static void
{
int irq;
return;
/* translate the interrupt if needed */
/* Disable the interrupt handler */
}
/*
* Miscellaneous library function
*/
int
{
int i;
int number;
int assigned_addr_len;
(phys_hi & PCI_RELOCAT_B))
return (DDI_SUCCESS);
/*
* the "reg" property specifies relocatable, get and interpret the
* "assigned-addresses" property.
*/
"assigned-addresses", (int **)&assigned_addr,
return (DDI_FAILURE);
/*
* Scan the "assigned-addresses" for one that matches the specified
* "reg" property entry.
*/
for (i = 0; i < number; i++) {
phys_hi) {
return (DDI_SUCCESS);
}
}
return (DDI_FAILURE);
}
/*
* For pci_tools
*/
int
{
switch (PCIHP_AP_MINOR_NUM_TO_PCI_DEVNUM(minor)) {
case PCI_TOOL_REG_MINOR_NUM:
switch (cmd) {
case PCITOOL_DEVICE_SET_REG:
case PCITOOL_DEVICE_GET_REG:
/* Require full privileges. */
if (secpolicy_kmdb(credp))
else
break;
case PCITOOL_NEXUS_SET_REG:
case PCITOOL_NEXUS_GET_REG:
/* Require full privileges. */
if (secpolicy_kmdb(credp))
else
break;
}
break;
case PCI_TOOL_INTR_MINOR_NUM:
switch (cmd) {
case PCITOOL_DEVICE_SET_INTR:
/* Require PRIV_SYS_RES_CONFIG, same as psradm */
if (secpolicy_ponline(credp)) {
break;
}
/*FALLTHRU*/
/* These require no special privileges. */
case PCITOOL_DEVICE_GET_INTR:
case PCITOOL_DEVICE_NUM_INTR:
break;
}
break;
/*
* All non-PCItool ioctls go through here, including:
* devctl ioctls with minor number PCIHP_DEVCTL_MINOR and
* those for attachment points with where minor number is the
* device number.
*/
default:
break;
}
return (rv);
}
int
{
int err = DDI_SUCCESS;
/*
* if no handle then this is a poke. We have to return failure here
* as we have no way of knowing whether this is a MEM or IO space access
*/
return (DDI_FAILURE);
/*
* rest of this function is actually for cautious puts
*/
switch (size) {
case sizeof (uint8_t):
break;
case sizeof (uint16_t):
break;
case sizeof (uint32_t):
break;
case sizeof (uint64_t):
break;
default:
err = DDI_FAILURE;
break;
}
switch (size) {
case sizeof (uint8_t):
break;
case sizeof (uint16_t):
break;
case sizeof (uint32_t):
break;
/*
* note the 64-bit case is a dummy
* function - so no need to swap
*/
case sizeof (uint64_t):
break;
default:
err = DDI_FAILURE;
break;
}
} else {
switch (size) {
case sizeof (uint8_t):
break;
case sizeof (uint16_t):
break;
case sizeof (uint32_t):
break;
case sizeof (uint64_t):
break;
default:
err = DDI_FAILURE;
break;
}
}
} else {
switch (size) {
case sizeof (uint8_t):
break;
case sizeof (uint16_t):
break;
case sizeof (uint32_t):
break;
case sizeof (uint64_t):
break;
default:
err = DDI_FAILURE;
break;
}
} else {
switch (size) {
case sizeof (uint8_t):
break;
case sizeof (uint16_t):
break;
case sizeof (uint32_t):
break;
case sizeof (uint64_t):
break;
default:
err = DDI_FAILURE;
break;
}
}
}
if (flags == DDI_DEV_AUTOINCR)
}
return (err);
}
int
{
/* endian-ness check */
return (DDI_FAILURE);
/*
* range check
*/
if ((offset >= PCI_CONF_HDR_SIZE) ||
(len > PCI_CONF_HDR_SIZE) ||
return (DDI_FAILURE);
/*
* always use cautious mechanism for config space gets
*/
} else {
}
return (DDI_SUCCESS);
}
int
{
int err = DDI_SUCCESS;
/*
* if no handle then this is a peek. We have to return failure here
* as we have no way of knowing whether this is a MEM or IO space access
*/
return (DDI_FAILURE);
switch (size) {
case sizeof (uint8_t):
break;
case sizeof (uint16_t):
break;
case sizeof (uint32_t):
break;
case sizeof (uint64_t):
break;
default:
err = DDI_FAILURE;
break;
}
switch (size) {
case sizeof (uint8_t):
break;
case sizeof (uint16_t):
break;
case sizeof (uint32_t):
break;
/*
* note the 64-bit case is a dummy
* function - so no need to swap
*/
case sizeof (uint64_t):
break;
default:
err = DDI_FAILURE;
break;
}
} else {
switch (size) {
case sizeof (uint8_t):
break;
case sizeof (uint16_t):
break;
case sizeof (uint32_t):
break;
case sizeof (uint64_t):
break;
default:
err = DDI_FAILURE;
break;
}
}
} else {
case sizeof (uint8_t):
break;
case sizeof (uint16_t):
break;
case sizeof (uint32_t):
break;
case sizeof (uint64_t):
break;
default:
err = DDI_FAILURE;
break;
}
} else {
case sizeof (uint8_t):
break;
case sizeof (uint16_t):
break;
case sizeof (uint32_t):
break;
case sizeof (uint64_t):
break;
default:
err = DDI_FAILURE;
break;
}
}
}
if (flags == DDI_DEV_AUTOINCR)
}
return (err);
}
/*ARGSUSED*/
int
{
if (ctlop == DDI_CTLOPS_PEEK)
else
}
/*
* These are the get and put functions to be shared with drivers. The
* mutex locking is done inside the functions referenced, rather than
* here, and is thus shared across PCI child drivers and any other
* consumers of PCI config space (such as the ACPI subsystem).
*
* The configuration space addresses come in as pointers. This is fine on
* a 32-bit system, where the VM space and configuration space are the same
* size. It's not such a good idea on a 64-bit system, where memory
* addresses are twice as large as configuration space addresses. At some
* point in the call tree we need to take a stand and say "you are 32-bit
* from this time forth", and this seems like a nice self-contained place.
*/
{
int reg;
reg);
return (rval);
}
void
{
uint8_t *h, *d;
h = host_addr;
d = dev_addr;
if (flags == DDI_DEV_AUTOINCR)
*h++ = pci_config_rd8(hdlp, d++);
else
*h++ = pci_config_rd8(hdlp, d);
}
{
int reg;
reg);
return (rval);
}
void
{
uint16_t *h, *d;
h = host_addr;
d = dev_addr;
if (flags == DDI_DEV_AUTOINCR)
*h++ = pci_config_rd16(hdlp, d++);
else
*h++ = pci_config_rd16(hdlp, d);
}
{
int reg;
return (rval);
}
void
{
uint32_t *h, *d;
h = host_addr;
d = dev_addr;
if (flags == DDI_DEV_AUTOINCR)
*h++ = pci_config_rd32(hdlp, d++);
else
*h++ = pci_config_rd32(hdlp, d);
}
void
{
int reg;
}
void
{
uint8_t *h, *d;
h = host_addr;
d = dev_addr;
if (flags == DDI_DEV_AUTOINCR)
pci_config_wr8(hdlp, d++, *h++);
else
pci_config_wr8(hdlp, d, *h++);
}
void
{
int reg;
}
void
{
uint16_t *h, *d;
h = host_addr;
d = dev_addr;
if (flags == DDI_DEV_AUTOINCR)
pci_config_wr16(hdlp, d++, *h++);
else
pci_config_wr16(hdlp, d, *h++);
}
void
{
int reg;
}
void
{
uint32_t *h, *d;
h = host_addr;
d = dev_addr;
if (flags == DDI_DEV_AUTOINCR)
pci_config_wr32(hdlp, d++, *h++);
else
pci_config_wr32(hdlp, d, *h++);
}
{
dp++;
return (val);
}
void
{
dp++;
}
void
{
if (flags == DDI_DEV_AUTOINCR) {
} else {
}
}
void
{
if (flags == DDI_DEV_AUTOINCR) {
} else {
}
}
/*
* Enable Legacy PCI config space access for the following four north bridges
* Host bridge: AMD HyperTransport Technology Configuration
* Host bridge: AMD Address Map
* Host bridge: AMD DRAM Controller
* Host bridge: AMD Miscellaneous Control
*/
int
{
"vendor-id", -1);
"device-id", -1);
return (0);
return (1);
}