/* * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (C) 2005-2009, 2010 Cavium Networks
*/ #include <linux/kernel.h> #include <linux/init.h> #include <linux/msi.h> #include <linux/spinlock.h> #include <linux/interrupt.h>
/* * Each bit in msi_free_irq_bitmask represents a MSI interrupt that is * in use.
*/ static u64 msi_free_irq_bitmask[4];
/* * Each bit in msi_multiple_irq_bitmask tells that the device using * this bit in msi_free_irq_bitmask is also using the next bit. This * is used so we can disable all of the MSI interrupts when a device * uses multiple.
*/ static u64 msi_multiple_irq_bitmask[4];
/* * This lock controls updates to msi_free_irq_bitmask and * msi_multiple_irq_bitmask.
*/ static DEFINE_SPINLOCK(msi_free_irq_bitmask_lock);
/* * Number of MSI IRQs used. This variable is set up in * the module init time.
*/ staticint msi_irq_size;
/** * arch_setup_msi_irq() - setup MSI IRQs for a device * @dev: Device requesting MSI interrupts * @desc: MSI descriptor * * Called when a driver requests MSI interrupts instead of the * legacy INT A-D. This routine will allocate multiple interrupts * for MSI devices that support them. A device can override this by * programming the MSI control bits [6:4] before calling * pci_enable_msi(). * * Return: %0 on success, non-%0 on error.
*/ int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc)
{ struct msi_msg msg;
u16 control; int configured_private_bits; int request_private_bits; int irq = 0; int irq_step;
u64 search_mask; int index;
if (desc->pci.msi_attrib.is_msix) return -EINVAL;
/* * Read the MSI config to figure out how many IRQs this device * wants. Most devices only want 1, which will give * configured_private_bits and request_private_bits equal 0.
*/
pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &control);
/* * If the number of private bits has been configured then use * that value instead of the requested number. This gives the * driver the chance to override the number of interrupts * before calling pci_enable_msi().
*/
configured_private_bits = (control & PCI_MSI_FLAGS_QSIZE) >> 4; if (configured_private_bits == 0) { /* Nothing is configured, so use the hardware requested size */
request_private_bits = (control & PCI_MSI_FLAGS_QMASK) >> 1;
} else { /* * Use the number of configured bits, assuming the * driver wanted to override the hardware request * value.
*/
request_private_bits = configured_private_bits;
}
/* * The PCI 2.3 spec mandates that there are at most 32 * interrupts. If this device asks for more, only give it one.
*/ if (request_private_bits > 5)
request_private_bits = 0;
try_only_one: /* * The IRQs have to be aligned on a power of two based on the * number being requested.
*/
irq_step = 1 << request_private_bits;
/* Mask with one bit for each IRQ */
search_mask = (1 << irq_step) - 1;
/* * We're going to search msi_free_irq_bitmask_lock for zero * bits. This represents an MSI interrupt number that isn't in * use.
*/
spin_lock(&msi_free_irq_bitmask_lock); for (index = 0; index < msi_irq_size/64; index++) { for (irq = 0; irq < 64; irq += irq_step) { if ((msi_free_irq_bitmask[index] & (search_mask << irq)) == 0) {
msi_free_irq_bitmask[index] |= search_mask << irq;
msi_multiple_irq_bitmask[index] |= (search_mask >> 1) << irq; goto msi_irq_allocated;
}
}
}
msi_irq_allocated:
spin_unlock(&msi_free_irq_bitmask_lock);
/* Make sure the search for available interrupts didn't fail */ if (irq >= 64) { if (request_private_bits) {
pr_err("arch_setup_msi_irq: Unable to find %d free interrupts, trying just one",
1 << request_private_bits);
request_private_bits = 0; goto try_only_one;
} else
panic("arch_setup_msi_irq: Unable to find a free MSI interrupt");
}
switch (octeon_dma_bar_type) { case OCTEON_DMA_BAR_TYPE_SMALL: /* When not using big bar, Bar 0 is based at 128MB */
msg.address_lo =
((128ul << 20) + CVMX_PCI_MSI_RCV) & 0xffffffff;
msg.address_hi = ((128ul << 20) + CVMX_PCI_MSI_RCV) >> 32; break; case OCTEON_DMA_BAR_TYPE_BIG: /* When using big bar, Bar 0 is based at 0 */
msg.address_lo = (0 + CVMX_PCI_MSI_RCV) & 0xffffffff;
msg.address_hi = (0 + CVMX_PCI_MSI_RCV) >> 32; break; case OCTEON_DMA_BAR_TYPE_PCIE: /* When using PCIe, Bar 0 is based at 0 */ /* FIXME CVMX_NPEI_MSI_RCV* other than 0? */
msg.address_lo = (0 + CVMX_NPEI_PCIE_MSI_RCV) & 0xffffffff;
msg.address_hi = (0 + CVMX_NPEI_PCIE_MSI_RCV) >> 32; break; case OCTEON_DMA_BAR_TYPE_PCIE2: /* When using PCIe2, Bar 0 is based at 0 */
msg.address_lo = (0 + CVMX_SLI_PCIE_MSI_RCV) & 0xffffffff;
msg.address_hi = (0 + CVMX_SLI_PCIE_MSI_RCV) >> 32; break; default:
panic("arch_setup_msi_irq: Invalid octeon_dma_bar_type");
}
msg.data = irq - OCTEON_IRQ_MSI_BIT0;
/* Update the number of IRQs the device has available to it */
control &= ~PCI_MSI_FLAGS_QSIZE;
control |= request_private_bits << 4;
pci_write_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, control);
/** * arch_teardown_msi_irq() - release MSI IRQs for a device * @irq: The devices first irq number. There may be multiple in sequence. * * Called when a device no longer needs its MSI interrupts. All * MSI interrupts for the device are freed.
*/ void arch_teardown_msi_irq(unsignedint irq)
{ int number_irqs;
u64 bitmask; int index = 0; int irq0;
if ((irq < OCTEON_IRQ_MSI_BIT0)
|| (irq > msi_irq_size + OCTEON_IRQ_MSI_BIT0))
panic("arch_teardown_msi_irq: Attempted to teardown illegal " "MSI interrupt (%d)", irq);
/* * Count the number of IRQs we need to free by looking at the * msi_multiple_irq_bitmask. Each bit set means that the next * IRQ is also owned by this device.
*/
number_irqs = 0; while ((irq0 + number_irqs < 64) &&
(msi_multiple_irq_bitmask[index]
& (1ull << (irq0 + number_irqs))))
number_irqs++;
number_irqs++; /* Mask with one bit for each IRQ */
bitmask = (1 << number_irqs) - 1; /* Shift the mask to the correct bit location */
bitmask <<= irq0; if ((msi_free_irq_bitmask[index] & bitmask) != bitmask)
panic("arch_teardown_msi_irq: Attempted to teardown MSI " "interrupt (%d) not in use", irq);
/* Checks are done, update the in use bitmask */
spin_lock(&msi_free_irq_bitmask_lock);
msi_free_irq_bitmask[index] &= ~bitmask;
msi_multiple_irq_bitmask[index] &= ~bitmask;
spin_unlock(&msi_free_irq_bitmask_lock);
}
staticvoid octeon_irq_msi_enable_pci(struct irq_data *data)
{ /* * Octeon PCI doesn't have the ability to mask/unmask MSI * interrupts individually. Instead of masking/unmasking them * in groups of 16, we simple assume MSI devices are well * behaved. MSI interrupts are always enable and the ACK is * assumed to be enough
*/
}
staticvoid octeon_irq_msi_disable_pci(struct irq_data *data)
{ /* See comment in enable */
}
/* * Called by the interrupt handling code when an MSI interrupt * occurs.
*/ static irqreturn_t __octeon_msi_do_interrupt(int index, u64 msi_bits)
{ int irq; int bit;
bit = fls64(msi_bits); if (bit) {
bit--; /* Acknowledge it first. */
cvmx_write_csr(msi_rcv_reg[index], 1ull << bit);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.