apic_introp.c revision d12abe7ce2663ac39e686a14960eb4febf560195
/*
* 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"
/*
* Has code for Advanced DDI interrupt framework support.
*/
#include "apic.h"
#include <sys/ddi_impldefs.h>
#include <sys/mach_intr.h>
#include <sys/sysmacros.h>
#include <sys/pci_intr_lib.h>
/*
* Local Function Prototypes
*/
int apic_pci_msi_enable_vector(dev_info_t *, int, int,
int, int, int);
static int apic_get_pending(apic_irq_t *, int);
static void apic_clear_mask(apic_irq_t *);
static void apic_set_mask(apic_irq_t *);
static uchar_t apic_find_multi_vectors(int, int);
int apic_navail_vector(dev_info_t *, int);
int apic_alloc_vectors(dev_info_t *, int, int, int, int);
void apic_free_vectors(dev_info_t *, int, int, int, int);
psm_intr_op_t, int *);
extern int intr_clear(void);
extern void intr_restore(uint_t);
extern int apic_allocate_irq(int);
/*
* 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;
int apic_multi_msi_max = 2;
extern int apic_max_device_irq;
extern int apic_min_device_irq;
extern lock_t apic_ioapic_lock;
extern kmutex_t airq_mutex;
extern apic_cpus_info_t *apic_cpus;
extern int apic_first_avail_irq;
/*
* apic_pci_msi_enable_vector:
* XXX: MSI-X support
*/
/* ARGSUSED */
int
int count, int target_apic_id)
{
"\tdriver = %s, inum=0x%x vector=0x%x apicid=0x%x\n", (void *)dip,
return (PSM_FAILURE);
/* MSI Address */
/* MSI Data: MSI is edge triggered according to spec */
if (type == DDI_INTR_TYPE_MSI) {
/* Set the bits to inform how many MSIs are enabled */
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);
}
return (PSM_SUCCESS);
}
/*
* 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 ((i == T_FASTTRAP) || (i == APIC_SPUR_INTR))
break;
count++;
i++;
}
}
return (navail);
}
static uchar_t
{
navail = 0;
/* It has to be contiguous */
navail = 0;
start = i;
while ((apic_vector_to_irq[i] == APIC_RESV_IRQ) &&
(i < highest)) {
if ((i == T_FASTTRAP) || (i == APIC_SPUR_INTR))
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++) {
continue;
if (DDI_INTR_IS_MSI_OR_MSIX(type)) {
return (irqp);
} else
return (irqp);
}
}
return (NULL);
}
/*
* 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;
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 iflag;
(void *)irqp));
iflag = intr_clear();
/* clear mask */
}
/*
* This function will mask the interrupt on the I/O APIC
*/
static void
{
int intin_no;
int iflag;
iflag = intr_clear();
/* mask it */
}
/*
*/
int
{
int rcount, i;
short idx;
/* for MSI/X only */
if (!DDI_INTR_IS_MSI_OR_MSIX(type))
return (0);
"inum=0x%x pri=0x%x count=0x%x\n",
if (count > 1) {
if (apic_multi_msi_enable == 0)
count = 1;
else if (count > apic_multi_msi_max)
}
break;
}
if (start == 0) {
/* no vector available */
return (0);
}
for (i = 0; i < rcount; i++) {
(uchar_t)-1) {
"apic_allocate_irq failed\n"));
return (i);
}
#ifdef DEBUG
"apic_vector_to_irq is not APIC_RESV_IRQ\n"));
#endif
irqptr->airq_share_id = 0;
if (i == 0) /* they all bound to the same cpu */
0xff, 0xff);
else
"dip=0x%p vector=0x%x origirq=0x%x pri=0x%x\n", irqno,
}
return (rcount);
}
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;
}
}
}
/*
* 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);
}
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);
}
/*
* 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
*/
int
{
return (PSM_FAILURE);
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 the "inum"th entry in the MSI-X table */
(inum * PCI_MSIX_VECTOR_SIZE);
/* Reset the "data" and "addr" bits */
}
return (PSM_SUCCESS);
}
/*
* apic_pci_msi_enable_mode:
*/
int
{
return (PSM_FAILURE);
if (type == DDI_INTR_TYPE_MSI) {
if ((msi_ctrl & PCI_MSI_ENABLE_BIT))
return (PSM_SUCCESS);
} else if (type == DDI_INTR_TYPE_MSIX) {
if (msi_ctrl & PCI_MSIX_ENABLE_BIT)
return (PSM_SUCCESS);
/* Offset into "inum"th entry in the MSI-X table & clear mask */
}
return (PSM_SUCCESS);
}
/*
* apic_pci_msi_disable_mode:
*/
int
{
return (PSM_FAILURE);
if (type == DDI_INTR_TYPE_MSI) {
if (!(msi_ctrl & PCI_MSI_ENABLE_BIT))
return (PSM_SUCCESS);
} else if (type == DDI_INTR_TYPE_MSIX) {
if (!(msi_ctrl & PCI_MSIX_ENABLE_BIT))
return (PSM_SUCCESS);
/* Offset into "inum"th entry in the MSI-X table & mask it */
}
return (PSM_SUCCESS);
}
/*
* 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 count_vec;
int cpu;
int old_priority;
int new_priority;
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)
else
break;
break;
case PSM_INTR_OP_FREE_VECTORS:
break;
break;
case PSM_INTR_OP_XLATE_VECTOR:
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:
/* First, check if "hdlp->ih_scratch1" vectors exist? */
return (PSM_FAILURE);
/* Now allocate the vectors */
/* Did we get fewer vectors? */
return (PSM_FAILURE);
}
/* Finally, free the previously allocated vectors */
break;
case PSM_INTR_OP_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(cpu)) {
return (PSM_FAILURE);
}
/* Convert the vector to the irq using vector_to_irq table. */
return (PSM_FAILURE);
}
if (ret) {
return (PSM_FAILURE);
}
*result = 0;
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_SET_CAP:
default:
return (PSM_FAILURE);
}
return (PSM_SUCCESS);
}