apic_introp.c revision 86a9c507121ec77a92601d8844a5ca82373cd4aa
/*
* 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.
*/
/*
* Has code for Advanced DDI interrupt framework support.
*/
#include <sys/archsystm.h>
#include <sys/ddi_impldefs.h>
#include <sys/mach_intr.h>
#include <sys/sysmacros.h>
#include <sys/pci_intr_lib.h>
/*
* Local Function Prototypes
*/
/*
* MSI support flag:
* reflects whether MSI is supported at APIC level
*
* 0 = default value - don't know and need to call apic_check_msi_support()
* to find out then set it accordingly
* 1 = supported
* -1 = not supported
*/
int apic_support_msi = 0;
/* Multiple vector support for MSI */
int apic_multi_msi_enable = 1;
/* Multiple vector support for MSI-X */
int apic_msix_enable = 1;
/*
* apic_pci_msi_enable_vector:
* XXX: MSI-X support
*/
/* ARGSUSED */
void
int count, int target_apic_id)
{
#if !defined(__xpv)
#endif /* ! __xpv */
"\tdriver = %s, inum=0x%x vector=0x%x apicid=0x%x\n", (void *)dip,
#if !defined(__xpv)
/* MSI Address */
/* MSI Data: MSI is edge triggered according to spec */
#else
/* MSI Address */
msi_addr = (MSI_ADDR_HDR |
/* MSI Data: MSI is edge triggered according to spec */
#endif /* ! __xpv */
if (type == DDI_INTR_TYPE_MSI) {
/* Set the bits to inform how many MSIs are enabled */
#if !defined(__xpv)
/*
* Only set vector if not on hypervisor
*/
if (msi_ctrl & PCI_MSI_64BIT_MASK) {
} else {
}
} else if (type == DDI_INTR_TYPE_MSIX) {
/* Offset into the "inum"th entry in the MSI-X table */
(inum * PCI_MSIX_VECTOR_SIZE);
#endif /* ! __xpv */
}
}
#if !defined(__xpv)
/*
* This function returns the no. of vectors available for the pri.
* dip is not used at this moment. If we really don't need that,
* it will be removed.
*/
/*ARGSUSED*/
int
{
/* It has to be contiguous */
count = 0;
while ((apic_vector_to_irq[i] == APIC_RESV_IRQ) &&
(i < highest)) {
if (APIC_CHECK_RESERVE_VECTORS(i))
break;
count++;
i++;
}
}
return (navail);
}
#endif /* ! __xpv */
/*
* Finds "count" contiguous MSI vectors starting at the proper alignment
* at "pri".
* Caller needs to make sure that count has to be power of 2 and should not
* be < 1.
*/
{
navail = 0;
/*
* msibits is the no. of lower order message data bits for the
* allocated MSI vectors and is used to calculate the aligned
* starting vector
*/
/* It has to be contiguous */
navail = 0;
/*
* starting vector has to be aligned accordingly for
* multiple MSIs
*/
if (msibits)
start = i;
while ((apic_vector_to_irq[i] == APIC_RESV_IRQ) &&
(i < highest)) {
if (APIC_CHECK_RESERVE_VECTORS(i))
break;
navail++;
return (start);
i++;
}
}
return (0);
}
/*
* It finds the apic_irq_t associates with the dip, ispec and type.
*/
{
int i;
for (i = apic_min_device_irq; i <= apic_max_device_irq; i++) {
if (type == DDI_INTR_TYPE_MSI) {
if (irqp->airq_mps_intr_index ==
return (irqp);
} else if (type == DDI_INTR_TYPE_MSIX) {
if (irqp->airq_mps_intr_index ==
return (irqp);
} else
return (irqp);
}
}
}
return (NULL);
}
#if !defined(__xpv)
/*
* This function will return the pending bit of the irqp.
* It either comes from the IRR register of the APIC or the RDT
* entry of the I/O APIC.
* For the IRR to work, it needs to be to its binding CPU
*/
static int
{
int intin_no;
int apic_ix;
type));
/* need to get on the bound cpu */
/* check I/O APIC for fixed interrupt */
AV_PENDING) ? 1 : 0;
}
return (pending);
}
/*
* This function will clear the mask for the interrupt on the I/O APIC
*/
static void
{
int intin_no;
int apic_ix;
(void *)irqp));
iflag = intr_clear();
/* clear mask */
}
/*
* This function will mask the interrupt on the I/O APIC
*/
static void
{
int intin_no;
int apic_ix;
iflag = intr_clear();
/* mask it */
}
void
{
int i;
"count: %x pri: %x type: %x\n",
/* for MSI/X only */
if (!DDI_INTR_IS_MSI_OR_MSIX(type))
return;
for (i = 0; i < count; i++) {
"dip=0x%p inum=0x%x pri=0x%x apic_find_irq() "
continue;
}
}
}
#endif /* ! __xpv */
/*
* check whether the system supports MSI
*
* If PCI-E capability is found, then this must be a PCI-E system.
* Since MSI is required for PCI-E system, it returns PSM_SUCCESS
* to indicate this system supports MSI.
*/
int
{
char dev_type[16];
int dev_len;
/*
* check whether the first level children of root_node have
* PCI-E capability
*/
" driver: %s, binding: %s, nodename: %s\n", (void *)cdip,
ddi_node_name(cdip)));
!= DDI_PROP_SUCCESS)
continue;
return (PSM_SUCCESS);
}
/* MSI is not supported on this system */
"device_type found\n"));
return (PSM_FAILURE);
}
#if !defined(__xpv)
/*
* apic_pci_msi_unconfigure:
*
* This and next two interfaces are copied from pci_intr_lib.c
* Do ensure that these two files stay in sync.
* These needed to be copied over here to avoid a deadlock situation on
* certain mp systems that use MSI interrupts.
*
* IMPORTANT regards next three interfaces:
* i) are called only for MSI/X interrupts.
* ii) called with interrupts disabled, and must not block
*/
void
{
if (type == DDI_INTR_TYPE_MSI) {
msi_ctrl &= (~PCI_MSI_MME_MASK);
if (msi_ctrl & PCI_MSI_64BIT_MASK) {
cap_ptr + PCI_MSI_64BIT_DATA, 0);
} else {
cap_ptr + PCI_MSI_32BIT_DATA, 0);
}
} else if (type == DDI_INTR_TYPE_MSIX) {
/* Offset into "inum"th entry in the MSI-X table & mask it */
/* Offset into the "inum"th entry in the MSI-X table */
(inum * PCI_MSIX_VECTOR_SIZE);
/* Reset the "data" and "addr" bits */
}
}
#endif /* __xpv */
/*
* apic_pci_msi_enable_mode:
*/
void
{
if (type == DDI_INTR_TYPE_MSI) {
if ((msi_ctrl & PCI_MSI_ENABLE_BIT))
return;
} else if (type == DDI_INTR_TYPE_MSIX) {
/* Offset into "inum"th entry in the MSI-X table & clear mask */
if (!(msi_ctrl & PCI_MSIX_ENABLE_BIT)) {
msi_ctrl);
}
}
}
/*
* apic_pci_msi_disable_mode:
*/
void
{
if (type == DDI_INTR_TYPE_MSI) {
if (!(msi_ctrl & PCI_MSI_ENABLE_BIT))
return;
} else if (type == DDI_INTR_TYPE_MSIX) {
if (msi_ctrl & PCI_MSIX_ENABLE_BIT) {
msi_ctrl);
}
}
}
#if !defined(__xpv)
static int
{
int ret;
return (PSM_FAILURE);
}
/* Fail if this is an MSI intr and is part of a group. */
return (PSM_FAILURE);
}
iflag = intr_clear();
if (ret) {
return (PSM_FAILURE);
}
/*
* keep tracking the default interrupt cpu binding
*/
*result = 0;
return (PSM_SUCCESS);
}
static int
{
int i;
int cap_ptr;
int msi_mask_off;
int num_vectors = 0;
/*
* Take mutex to insure that table doesn't change out from underneath
* us while we're playing with it.
*/
/* A "group" of 1 */
if (num_vectors == 1) {
}
goto set_grp_intr_done;
}
"set_grp: base vec not part of a grp or not aligned: "
goto set_grp_intr_done;
}
num_vectors));
/*
* All IRQ entries in the table for the given device will be not
* shared. Since they are not shared, the dip in the table will
* be true to the device of interest.
*/
for (i = 1; i < num_vectors; i++) {
goto set_grp_intr_done;
}
#ifdef DEBUG
/* Sanity check: CPU and dip is the same for all entries. */
"set_grp: cpu or dip for vec 0x%x difft than for "
" cpu: %d vs %d, dip: 0x%p vs 0x%p\n", orig_cpu,
goto set_grp_intr_done;
}
#endif /* DEBUG */
}
/* MSI Per vector masking is supported. */
if (msi_ctrl & PCI_MSI_PVM_MASK) {
if (msi_ctrl & PCI_MSI_64BIT_MASK)
else
"set_grp: pvm supported. Mask set to 0x%x\n",
}
iflag = intr_clear();
/*
* Do the first rebind and check for errors. Apic_rebind_all returns
* an error if the CPU is not accepting interrupts. If the first one
* succeeds they all will.
*/
else {
for (i = 1; i < num_vectors; i++) {
}
*result = 0; /* SUCCESS */
}
/* Reenable vectors if per vector masking is supported. */
if (msi_ctrl & PCI_MSI_PVM_MASK) {
"set_grp: pvm supported. Mask restored to 0x%x\n",
}
if (*result != 0)
return (PSM_FAILURE);
return (PSM_SUCCESS);
}
#else /* __xpv */
/*
* We let the hypervisor deal with msi configutation
* so just stub this out.
*/
/* ARGSUSED */
void
{
}
#endif /* __xpv */
int
{
int i;
/*
* Convert the vecirq arg to an irq using vector_to_irq table
* if the arg is a vector. Pass thru if already an irq.
*/
else
return (PSM_FAILURE);
}
/* Get the (temp) cpu from apic_irq table, indexed by irq. */
/* Return user bound info for intrd. */
}
}
if (intr_params_p->avgi_req_flags &
/* Get number of devices from apic_irq table shared field. */
/* Some devices have NULL dip. Don't count these. */
if (intr_params_p->avgi_num_devs > 0) {
i++;
}
/* There are no viable dips to return. */
if (intr_params_p->avgi_num_devs == 0)
else { /* Return list of dips */
/* Allocate space in array for that number of devs. */
sizeof (dev_info_t *),
KM_SLEEP);
/*
* Loop through the device list of the autovec table
* filling in the dip array.
*
* Note that the autovect table may have some special
* entries which contain NULL dips. These will be
* ignored.
*/
intr_params_p->avgi_dip_list[i++] =
}
}
return (PSM_SUCCESS);
}
#if !defined(__xpv)
/*
* This function provides external interface to the nexus for all
* functionalities related to the new DDI interrupt framework.
*
* Input:
* dip - pointer to the dev_info structure of the requested device
* hdlp - pointer to the internal interrupt handle structure for the
* requested interrupt
* intr_op - opcode for this call
* result - pointer to the integer that will hold the result to be
* passed back if return value is PSM_SUCCESS
*
* Output:
* return value is either PSM_SUCCESS or PSM_FAILURE
*/
int
{
int cap;
int count_vec;
int old_priority;
int new_priority;
int new_cpu;
switch (intr_op) {
case PSM_INTR_OP_CHECK_MSI:
/*
* Check MSI/X is supported or not at APIC level and
* masked off the MSI/X bits in hdlp->ih_type if not
* supported before return. If MSI/X is supported,
* leave the ih_type unchanged and return.
*
* hdlp->ih_type passed in from the nexus has all the
* interrupt types supported by the device.
*/
if (apic_support_msi == 0) {
/*
* if apic_support_msi is not set, call
* apic_check_msi_support() to check whether msi
* is supported first
*/
if (apic_check_msi_support() == PSM_SUCCESS)
apic_support_msi = 1;
else
apic_support_msi = -1;
}
if (apic_support_msi == 1) {
if (apic_msix_enable)
else
} else
break;
else
break;
case PSM_INTR_OP_FREE_VECTORS:
break;
break;
case PSM_INTR_OP_XLATE_VECTOR:
if (*result == -1)
return (PSM_FAILURE);
break;
case PSM_INTR_OP_GET_PENDING:
return (PSM_FAILURE);
break;
case PSM_INTR_OP_CLEAR_MASK:
return (PSM_FAILURE);
return (PSM_FAILURE);
break;
case PSM_INTR_OP_SET_MASK:
return (PSM_FAILURE);
return (PSM_FAILURE);
break;
case PSM_INTR_OP_GET_CAP:
break;
case PSM_INTR_OP_GET_SHARED:
return (PSM_FAILURE);
return (PSM_FAILURE);
break;
case PSM_INTR_OP_SET_PRI:
return (PSM_SUCCESS);
}
/* Now allocate the vectors */
/* SET_PRI does not support the case of multiple MSI */
return (PSM_FAILURE);
1, new_priority,
} else {
1, new_priority,
}
/* Did we get new vectors? */
if (!count_vec)
return (PSM_FAILURE);
/* Finally, free the previously allocated vectors */
break;
case PSM_INTR_OP_SET_CPU:
case PSM_INTR_OP_GRP_SET_CPU:
/*
* The interrupt handle given here has been allocated
* specifically for this command, and ih_private carries
* a CPU value.
*/
if (!apic_cpu_in_range(new_cpu)) {
"[grp_]set_cpu: cpu out of range: %d\n", new_cpu));
return (PSM_FAILURE);
}
"[grp_]set_cpu: vector out of range: %d\n",
return (PSM_FAILURE);
}
if (intr_op == PSM_INTR_OP_SET_CPU) {
return (PSM_FAILURE);
} else {
result) != PSM_SUCCESS)
return (PSM_FAILURE);
}
break;
case PSM_INTR_OP_GET_INTR:
/*
* The interrupt handle given here has been allocated
* specifically for this command, and ih_private carries
* a pointer to a apic_get_intr_t.
*/
return (PSM_FAILURE);
break;
case PSM_INTR_OP_APIC_TYPE:
break;
case PSM_INTR_OP_SET_CAP:
default:
return (PSM_FAILURE);
}
return (PSM_SUCCESS);
}
#endif /* !__xpv */