pci_common.c revision 70025d765b044c6d8594bb965a2247a61e991a99
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2005 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/pci_intr_lib.h>
#include <sys/sysmacros.h>
#include <sys/pci_tools.h>
/*
* Function prototypes
*/
static int pci_get_nintrs(dev_info_t *, int, int *);
/* 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);
}
/*
* pci_get_nintrs:
* Figure out how many interrupts the device supports
*/
static int
{
int ret;
*nintrs = 0;
if (DDI_INTR_IS_MSI_OR_MSIX(type))
else {
ret = DDI_FAILURE;
"interrupts", -1) != -1) {
*nintrs = 1;
ret = DDI_SUCCESS;
}
}
return (ret);
}
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;
int behavior;
"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) {
/* MSI or MSI-X is supported, OR it in */
"rdip: 0x%p supported types: 0x%x\n", (void *)rdip,
*(int *)result));
}
break;
case DDI_INTROP_NINTRS:
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
/* 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)) {
if (msix_p &&
--msix_p->msix_intrs_in_use == 0) {
}
}
}
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 < hdlp->ih_scratch1; 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 < hdlp->ih_scratch1; 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;
case DDI_INTROP_NAVAIL:
/* Priority in the handle not initialized yet */
} else {
*(int *)result = 1;
}
*(int *)result));
break;
default:
}
return (DDI_SUCCESS);
}
static int
{
int vector;
/* Translate the interrupt if needed */
/* translate the interrupt if needed */
/* Add the interrupt handler */
return (DDI_FAILURE);
return (DDI_SUCCESS);
}
static void
{
int vector;
/* 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);
}