2006-04-10 22:17:48 -04:00
|
|
|
/*
|
|
|
|
* 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) 2006 Silicon Graphics, Inc. All Rights Reserved.
|
|
|
|
*/
|
|
|
|
|
2006-04-14 17:03:54 -04:00
|
|
|
#include <linux/types.h>
|
2006-10-04 05:16:59 -04:00
|
|
|
#include <linux/irq.h>
|
2006-04-14 17:03:54 -04:00
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/cpumask.h>
|
2006-10-04 05:16:59 -04:00
|
|
|
#include <linux/msi.h>
|
2006-04-14 17:03:54 -04:00
|
|
|
|
|
|
|
#include <asm/sn/addrs.h>
|
|
|
|
#include <asm/sn/intr.h>
|
|
|
|
#include <asm/sn/pcibus_provider_defs.h>
|
|
|
|
#include <asm/sn/pcidev.h>
|
|
|
|
#include <asm/sn/nodepda.h>
|
|
|
|
|
|
|
|
struct sn_msi_info {
|
|
|
|
u64 pci_addr;
|
|
|
|
struct sn_irq_info *sn_irq_info;
|
|
|
|
};
|
|
|
|
|
2006-10-04 05:16:59 -04:00
|
|
|
static struct sn_msi_info sn_msi_info[NR_IRQS];
|
|
|
|
|
|
|
|
static struct irq_chip sn_msi_chip;
|
2006-04-14 17:03:54 -04:00
|
|
|
|
2006-10-04 05:16:59 -04:00
|
|
|
void sn_teardown_msi_irq(unsigned int irq)
|
2006-04-14 17:03:54 -04:00
|
|
|
{
|
|
|
|
nasid_t nasid;
|
|
|
|
int widget;
|
|
|
|
struct pci_dev *pdev;
|
|
|
|
struct pcidev_info *sn_pdev;
|
|
|
|
struct sn_irq_info *sn_irq_info;
|
|
|
|
struct pcibus_bussoft *bussoft;
|
|
|
|
struct sn_pcibus_provider *provider;
|
|
|
|
|
2006-10-04 05:16:34 -04:00
|
|
|
sn_irq_info = sn_msi_info[irq].sn_irq_info;
|
2006-04-14 17:03:54 -04:00
|
|
|
if (sn_irq_info == NULL || sn_irq_info->irq_int_bit >= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sn_pdev = (struct pcidev_info *)sn_irq_info->irq_pciioinfo;
|
|
|
|
pdev = sn_pdev->pdi_linux_pcidev;
|
|
|
|
provider = SN_PCIDEV_BUSPROVIDER(pdev);
|
|
|
|
|
|
|
|
(*provider->dma_unmap)(pdev,
|
2006-10-04 05:16:34 -04:00
|
|
|
sn_msi_info[irq].pci_addr,
|
2006-04-14 17:03:54 -04:00
|
|
|
PCI_DMA_FROMDEVICE);
|
2006-10-04 05:16:34 -04:00
|
|
|
sn_msi_info[irq].pci_addr = 0;
|
2006-04-14 17:03:54 -04:00
|
|
|
|
|
|
|
bussoft = SN_PCIDEV_BUSSOFT(pdev);
|
|
|
|
nasid = NASID_GET(bussoft->bs_base);
|
|
|
|
widget = (nasid & 1) ?
|
|
|
|
TIO_SWIN_WIDGETNUM(bussoft->bs_base) :
|
|
|
|
SWIN_WIDGETNUM(bussoft->bs_base);
|
|
|
|
|
|
|
|
sn_intr_free(nasid, widget, sn_irq_info);
|
2006-10-04 05:16:34 -04:00
|
|
|
sn_msi_info[irq].sn_irq_info = NULL;
|
2006-04-14 17:03:54 -04:00
|
|
|
|
2007-01-28 14:56:37 -05:00
|
|
|
destroy_irq(irq);
|
2006-04-14 17:03:54 -04:00
|
|
|
}
|
2006-04-10 22:17:48 -04:00
|
|
|
|
2007-01-28 14:56:37 -05:00
|
|
|
int sn_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *entry)
|
2006-04-10 22:17:48 -04:00
|
|
|
{
|
2006-10-04 05:16:59 -04:00
|
|
|
struct msi_msg msg;
|
2006-04-14 17:03:54 -04:00
|
|
|
int widget;
|
|
|
|
int status;
|
|
|
|
nasid_t nasid;
|
|
|
|
u64 bus_addr;
|
|
|
|
struct sn_irq_info *sn_irq_info;
|
|
|
|
struct pcibus_bussoft *bussoft = SN_PCIDEV_BUSSOFT(pdev);
|
|
|
|
struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev);
|
2007-01-28 14:56:37 -05:00
|
|
|
int irq;
|
2006-04-14 17:03:54 -04:00
|
|
|
|
2006-10-04 05:16:59 -04:00
|
|
|
if (!entry->msi_attrib.is_64)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2006-04-14 17:03:54 -04:00
|
|
|
if (bussoft == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (provider == NULL || provider->dma_map_consistent == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2007-01-28 14:56:37 -05:00
|
|
|
irq = create_irq();
|
|
|
|
if (irq < 0)
|
|
|
|
return irq;
|
|
|
|
|
|
|
|
set_irq_msi(irq, entry);
|
2006-04-14 17:03:54 -04:00
|
|
|
/*
|
|
|
|
* Set up the vector plumbing. Let the prom (via sn_intr_alloc)
|
|
|
|
* decide which cpu to direct this msi at by default.
|
|
|
|
*/
|
|
|
|
|
|
|
|
nasid = NASID_GET(bussoft->bs_base);
|
|
|
|
widget = (nasid & 1) ?
|
|
|
|
TIO_SWIN_WIDGETNUM(bussoft->bs_base) :
|
|
|
|
SWIN_WIDGETNUM(bussoft->bs_base);
|
|
|
|
|
|
|
|
sn_irq_info = kzalloc(sizeof(struct sn_irq_info), GFP_KERNEL);
|
2007-01-28 14:56:37 -05:00
|
|
|
if (! sn_irq_info) {
|
|
|
|
destroy_irq(irq);
|
2006-04-14 17:03:54 -04:00
|
|
|
return -ENOMEM;
|
2007-01-28 14:56:37 -05:00
|
|
|
}
|
2006-04-14 17:03:54 -04:00
|
|
|
|
2006-10-04 05:16:34 -04:00
|
|
|
status = sn_intr_alloc(nasid, widget, sn_irq_info, irq, -1, -1);
|
2006-04-14 17:03:54 -04:00
|
|
|
if (status) {
|
|
|
|
kfree(sn_irq_info);
|
2007-01-28 14:56:37 -05:00
|
|
|
destroy_irq(irq);
|
2006-04-14 17:03:54 -04:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
sn_irq_info->irq_int_bit = -1; /* mark this as an MSI irq */
|
|
|
|
sn_irq_fixup(pdev, sn_irq_info);
|
|
|
|
|
|
|
|
/* Prom probably should fill these in, but doesn't ... */
|
|
|
|
sn_irq_info->irq_bridge_type = bussoft->bs_asic_type;
|
|
|
|
sn_irq_info->irq_bridge = (void *)bussoft->bs_base;
|
|
|
|
|
2006-04-10 22:17:48 -04:00
|
|
|
/*
|
2006-04-14 17:03:54 -04:00
|
|
|
* Map the xio address into bus space
|
2006-04-10 22:17:48 -04:00
|
|
|
*/
|
2006-04-14 17:03:54 -04:00
|
|
|
bus_addr = (*provider->dma_map_consistent)(pdev,
|
|
|
|
sn_irq_info->irq_xtalkaddr,
|
|
|
|
sizeof(sn_irq_info->irq_xtalkaddr),
|
|
|
|
SN_DMA_MSI|SN_DMA_ADDR_XIO);
|
|
|
|
if (! bus_addr) {
|
|
|
|
sn_intr_free(nasid, widget, sn_irq_info);
|
|
|
|
kfree(sn_irq_info);
|
2007-01-28 14:56:37 -05:00
|
|
|
destroy_irq(irq);
|
2006-04-14 17:03:54 -04:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2006-10-04 05:16:34 -04:00
|
|
|
sn_msi_info[irq].sn_irq_info = sn_irq_info;
|
|
|
|
sn_msi_info[irq].pci_addr = bus_addr;
|
2006-04-14 17:03:54 -04:00
|
|
|
|
2006-10-04 05:16:59 -04:00
|
|
|
msg.address_hi = (u32)(bus_addr >> 32);
|
|
|
|
msg.address_lo = (u32)(bus_addr & 0x00000000ffffffff);
|
2006-04-14 17:03:54 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* In the SN platform, bit 16 is a "send vector" bit which
|
|
|
|
* must be present in order to move the vector through the system.
|
|
|
|
*/
|
2006-10-04 05:16:59 -04:00
|
|
|
msg.data = 0x100 + irq;
|
2006-04-14 17:03:54 -04:00
|
|
|
|
2006-10-04 05:16:59 -04:00
|
|
|
write_msi_msg(irq, &msg);
|
|
|
|
set_irq_chip_and_handler(irq, &sn_msi_chip, handle_edge_irq);
|
|
|
|
|
2007-01-28 14:56:37 -05:00
|
|
|
return irq;
|
2006-04-14 17:03:54 -04:00
|
|
|
}
|
|
|
|
|
2006-10-04 05:16:59 -04:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
static void sn_set_msi_irq_affinity(unsigned int irq, cpumask_t cpu_mask)
|
2006-04-14 17:03:54 -04:00
|
|
|
{
|
2006-10-04 05:16:59 -04:00
|
|
|
struct msi_msg msg;
|
2006-04-14 17:03:54 -04:00
|
|
|
int slice;
|
|
|
|
nasid_t nasid;
|
|
|
|
u64 bus_addr;
|
|
|
|
struct pci_dev *pdev;
|
|
|
|
struct pcidev_info *sn_pdev;
|
|
|
|
struct sn_irq_info *sn_irq_info;
|
|
|
|
struct sn_irq_info *new_irq_info;
|
|
|
|
struct sn_pcibus_provider *provider;
|
2006-10-04 05:16:34 -04:00
|
|
|
unsigned int cpu;
|
2006-04-14 17:03:54 -04:00
|
|
|
|
2006-10-04 05:16:34 -04:00
|
|
|
cpu = first_cpu(cpu_mask);
|
|
|
|
sn_irq_info = sn_msi_info[irq].sn_irq_info;
|
2006-04-14 17:03:54 -04:00
|
|
|
if (sn_irq_info == NULL || sn_irq_info->irq_int_bit >= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release XIO resources for the old MSI PCI address
|
|
|
|
*/
|
|
|
|
|
2006-10-04 05:16:59 -04:00
|
|
|
read_msi_msg(irq, &msg);
|
2006-04-14 17:03:54 -04:00
|
|
|
sn_pdev = (struct pcidev_info *)sn_irq_info->irq_pciioinfo;
|
|
|
|
pdev = sn_pdev->pdi_linux_pcidev;
|
|
|
|
provider = SN_PCIDEV_BUSPROVIDER(pdev);
|
|
|
|
|
2006-10-04 05:16:59 -04:00
|
|
|
bus_addr = (u64)(msg.address_hi) << 32 | (u64)(msg.address_lo);
|
2006-04-14 17:03:54 -04:00
|
|
|
(*provider->dma_unmap)(pdev, bus_addr, PCI_DMA_FROMDEVICE);
|
2006-10-04 05:16:34 -04:00
|
|
|
sn_msi_info[irq].pci_addr = 0;
|
2006-04-14 17:03:54 -04:00
|
|
|
|
|
|
|
nasid = cpuid_to_nasid(cpu);
|
|
|
|
slice = cpuid_to_slice(cpu);
|
|
|
|
|
|
|
|
new_irq_info = sn_retarget_vector(sn_irq_info, nasid, slice);
|
2006-10-04 05:16:34 -04:00
|
|
|
sn_msi_info[irq].sn_irq_info = new_irq_info;
|
2006-04-14 17:03:54 -04:00
|
|
|
if (new_irq_info == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map the xio address into bus space
|
|
|
|
*/
|
|
|
|
|
|
|
|
bus_addr = (*provider->dma_map_consistent)(pdev,
|
|
|
|
new_irq_info->irq_xtalkaddr,
|
|
|
|
sizeof(new_irq_info->irq_xtalkaddr),
|
|
|
|
SN_DMA_MSI|SN_DMA_ADDR_XIO);
|
|
|
|
|
2006-10-04 05:16:34 -04:00
|
|
|
sn_msi_info[irq].pci_addr = bus_addr;
|
2006-10-04 05:16:59 -04:00
|
|
|
msg.address_hi = (u32)(bus_addr >> 32);
|
|
|
|
msg.address_lo = (u32)(bus_addr & 0x00000000ffffffff);
|
|
|
|
|
|
|
|
write_msi_msg(irq, &msg);
|
|
|
|
set_native_irq_info(irq, cpu_mask);
|
2006-04-14 17:03:54 -04:00
|
|
|
}
|
2006-10-04 05:16:59 -04:00
|
|
|
#endif /* CONFIG_SMP */
|
2006-04-14 17:03:54 -04:00
|
|
|
|
2006-10-04 05:16:59 -04:00
|
|
|
static void sn_ack_msi_irq(unsigned int irq)
|
|
|
|
{
|
|
|
|
move_native_irq(irq);
|
|
|
|
ia64_eoi();
|
|
|
|
}
|
2006-04-14 17:03:54 -04:00
|
|
|
|
2006-10-04 05:16:59 -04:00
|
|
|
static int sn_msi_retrigger_irq(unsigned int irq)
|
2006-04-14 17:03:54 -04:00
|
|
|
{
|
2006-10-04 05:16:59 -04:00
|
|
|
unsigned int vector = irq;
|
|
|
|
ia64_resend_irq(vector);
|
2006-04-14 17:03:54 -04:00
|
|
|
|
2006-10-04 05:16:59 -04:00
|
|
|
return 1;
|
2006-04-10 22:17:48 -04:00
|
|
|
}
|
2006-10-04 05:16:59 -04:00
|
|
|
|
|
|
|
static struct irq_chip sn_msi_chip = {
|
|
|
|
.name = "PCI-MSI",
|
|
|
|
.mask = mask_msi_irq,
|
|
|
|
.unmask = unmask_msi_irq,
|
|
|
|
.ack = sn_ack_msi_irq,
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
.set_affinity = sn_set_msi_irq_affinity,
|
|
|
|
#endif
|
|
|
|
.retrigger = sn_msi_retrigger_irq,
|
|
|
|
};
|