2006-04-11 02:17:48 +00:00
|
|
|
/*
|
|
|
|
* MSI hooks for standard x86 apic
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/irq.h>
|
2006-10-04 09:16:59 +00:00
|
|
|
#include <linux/msi.h>
|
2008-10-17 19:14:13 +00:00
|
|
|
#include <linux/dmar.h>
|
2006-06-26 12:00:02 +00:00
|
|
|
#include <asm/smp.h>
|
2009-02-16 07:14:48 +00:00
|
|
|
#include <asm/msidef.h>
|
2006-04-11 02:17:48 +00:00
|
|
|
|
2006-10-04 09:16:59 +00:00
|
|
|
static struct irq_chip ia64_msi_chip;
|
2006-04-11 02:17:48 +00:00
|
|
|
|
2006-10-04 09:16:59 +00:00
|
|
|
#ifdef CONFIG_SMP
|
2011-02-04 19:18:43 +00:00
|
|
|
static int ia64_set_msi_irq_affinity(struct irq_data *idata,
|
|
|
|
const cpumask_t *cpu_mask, bool force)
|
2006-04-11 02:17:48 +00:00
|
|
|
{
|
2006-10-04 09:16:59 +00:00
|
|
|
struct msi_msg msg;
|
2007-07-17 12:22:48 +00:00
|
|
|
u32 addr, data;
|
2014-03-04 20:43:38 +00:00
|
|
|
int cpu = cpumask_first_and(cpu_mask, cpu_online_mask);
|
2011-02-04 19:18:43 +00:00
|
|
|
unsigned int irq = idata->irq;
|
2006-10-04 09:16:59 +00:00
|
|
|
|
2008-02-25 05:32:22 +00:00
|
|
|
if (irq_prepare_move(irq, cpu))
|
2009-04-28 00:59:21 +00:00
|
|
|
return -1;
|
2007-07-17 12:22:33 +00:00
|
|
|
|
2015-06-01 08:05:42 +00:00
|
|
|
__get_cached_msi_msg(irq_data_get_msi_desc(idata), &msg);
|
2006-04-11 02:17:48 +00:00
|
|
|
|
2006-10-04 09:16:59 +00:00
|
|
|
addr = msg.address_lo;
|
2009-02-16 07:14:48 +00:00
|
|
|
addr &= MSI_ADDR_DEST_ID_MASK;
|
|
|
|
addr |= MSI_ADDR_DEST_ID_CPU(cpu_physical_id(cpu));
|
2006-10-04 09:16:59 +00:00
|
|
|
msg.address_lo = addr;
|
2006-04-11 02:17:48 +00:00
|
|
|
|
2007-07-17 12:22:48 +00:00
|
|
|
data = msg.data;
|
|
|
|
data &= MSI_DATA_VECTOR_MASK;
|
|
|
|
data |= MSI_DATA_VECTOR(irq_to_vector(irq));
|
|
|
|
msg.data = data;
|
|
|
|
|
2014-11-09 15:10:34 +00:00
|
|
|
pci_write_msi_msg(irq, &msg);
|
2015-07-13 20:42:46 +00:00
|
|
|
cpumask_copy(irq_data_get_affinity_mask(idata), cpumask_of(cpu));
|
2009-04-28 00:59:21 +00:00
|
|
|
|
|
|
|
return 0;
|
2006-04-11 02:17:48 +00:00
|
|
|
}
|
2006-10-04 09:16:59 +00:00
|
|
|
#endif /* CONFIG_SMP */
|
2006-04-11 02:17:48 +00:00
|
|
|
|
2007-01-28 19:56:37 +00:00
|
|
|
int ia64_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc)
|
2006-04-11 02:17:48 +00:00
|
|
|
{
|
2006-10-04 09:16:59 +00:00
|
|
|
struct msi_msg msg;
|
2006-04-11 02:17:48 +00:00
|
|
|
unsigned long dest_phys_id;
|
2007-03-26 00:38:42 +00:00
|
|
|
int irq, vector;
|
2006-04-11 02:17:48 +00:00
|
|
|
|
2007-01-28 19:56:37 +00:00
|
|
|
irq = create_irq();
|
|
|
|
if (irq < 0)
|
|
|
|
return irq;
|
|
|
|
|
2011-03-25 20:06:09 +00:00
|
|
|
irq_set_msi_desc(irq, desc);
|
2015-03-05 00:18:49 +00:00
|
|
|
dest_phys_id = cpu_physical_id(cpumask_any_and(&(irq_to_domain(irq)),
|
|
|
|
cpu_online_mask));
|
2007-04-06 07:51:12 +00:00
|
|
|
vector = irq_to_vector(irq);
|
2006-04-11 02:17:48 +00:00
|
|
|
|
2006-10-04 09:16:59 +00:00
|
|
|
msg.address_hi = 0;
|
|
|
|
msg.address_lo =
|
2006-10-04 09:16:34 +00:00
|
|
|
MSI_ADDR_HEADER |
|
2009-02-16 07:14:48 +00:00
|
|
|
MSI_ADDR_DEST_MODE_PHYS |
|
2006-10-04 09:16:34 +00:00
|
|
|
MSI_ADDR_REDIRECTION_CPU |
|
2009-02-16 07:14:48 +00:00
|
|
|
MSI_ADDR_DEST_ID_CPU(dest_phys_id);
|
2006-04-11 02:17:48 +00:00
|
|
|
|
2006-10-04 09:16:59 +00:00
|
|
|
msg.data =
|
2006-10-04 09:16:34 +00:00
|
|
|
MSI_DATA_TRIGGER_EDGE |
|
2006-04-11 02:17:48 +00:00
|
|
|
MSI_DATA_LEVEL_ASSERT |
|
|
|
|
MSI_DATA_DELIVERY_FIXED |
|
|
|
|
MSI_DATA_VECTOR(vector);
|
|
|
|
|
2014-11-09 15:10:34 +00:00
|
|
|
pci_write_msi_msg(irq, &msg);
|
2011-03-25 20:06:09 +00:00
|
|
|
irq_set_chip_and_handler(irq, &ia64_msi_chip, handle_edge_irq);
|
2006-10-04 09:16:59 +00:00
|
|
|
|
2007-10-30 07:01:49 +00:00
|
|
|
return 0;
|
2006-04-11 02:17:48 +00:00
|
|
|
}
|
|
|
|
|
2006-10-04 09:16:59 +00:00
|
|
|
void ia64_teardown_msi_irq(unsigned int irq)
|
2006-04-11 02:17:48 +00:00
|
|
|
{
|
2007-01-28 19:56:37 +00:00
|
|
|
destroy_irq(irq);
|
2006-04-11 02:17:48 +00:00
|
|
|
}
|
|
|
|
|
2011-02-04 19:18:43 +00:00
|
|
|
static void ia64_ack_msi_irq(struct irq_data *data)
|
2006-10-04 09:16:59 +00:00
|
|
|
{
|
2011-02-04 19:18:43 +00:00
|
|
|
irq_complete_move(data->irq);
|
2011-03-25 19:36:55 +00:00
|
|
|
irq_move_irq(data);
|
2006-10-04 09:16:59 +00:00
|
|
|
ia64_eoi();
|
|
|
|
}
|
|
|
|
|
2011-02-04 19:18:43 +00:00
|
|
|
static int ia64_msi_retrigger_irq(struct irq_data *data)
|
2006-10-04 09:16:59 +00:00
|
|
|
{
|
2011-02-04 19:18:43 +00:00
|
|
|
unsigned int vector = irq_to_vector(data->irq);
|
2006-10-04 09:16:59 +00:00
|
|
|
ia64_resend_irq(vector);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-04-11 02:17:48 +00:00
|
|
|
/*
|
2006-10-04 09:16:59 +00:00
|
|
|
* Generic ops used on most IA64 platforms.
|
2006-04-11 02:17:48 +00:00
|
|
|
*/
|
2006-10-04 09:16:59 +00:00
|
|
|
static struct irq_chip ia64_msi_chip = {
|
2011-02-04 19:18:43 +00:00
|
|
|
.name = "PCI-MSI",
|
2014-11-23 11:23:20 +00:00
|
|
|
.irq_mask = pci_msi_mask_irq,
|
|
|
|
.irq_unmask = pci_msi_unmask_irq,
|
2011-02-04 19:18:43 +00:00
|
|
|
.irq_ack = ia64_ack_msi_irq,
|
2006-10-04 09:16:59 +00:00
|
|
|
#ifdef CONFIG_SMP
|
2011-02-04 19:18:43 +00:00
|
|
|
.irq_set_affinity = ia64_set_msi_irq_affinity,
|
2006-10-04 09:16:59 +00:00
|
|
|
#endif
|
2011-02-04 19:18:43 +00:00
|
|
|
.irq_retrigger = ia64_msi_retrigger_irq,
|
2006-04-11 02:17:48 +00:00
|
|
|
};
|
2006-10-04 09:16:59 +00:00
|
|
|
|
|
|
|
|
2007-01-28 19:56:37 +00:00
|
|
|
int arch_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc)
|
2006-10-04 09:16:59 +00:00
|
|
|
{
|
|
|
|
if (platform_setup_msi_irq)
|
2007-01-28 19:56:37 +00:00
|
|
|
return platform_setup_msi_irq(pdev, desc);
|
2006-10-04 09:16:59 +00:00
|
|
|
|
2007-01-28 19:56:37 +00:00
|
|
|
return ia64_setup_msi_irq(pdev, desc);
|
2006-10-04 09:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void arch_teardown_msi_irq(unsigned int irq)
|
|
|
|
{
|
|
|
|
if (platform_teardown_msi_irq)
|
|
|
|
return platform_teardown_msi_irq(irq);
|
|
|
|
|
|
|
|
return ia64_teardown_msi_irq(irq);
|
|
|
|
}
|
2008-10-17 19:14:13 +00:00
|
|
|
|
2011-08-24 00:05:25 +00:00
|
|
|
#ifdef CONFIG_INTEL_IOMMU
|
2008-10-17 19:14:13 +00:00
|
|
|
#ifdef CONFIG_SMP
|
2011-02-04 19:18:43 +00:00
|
|
|
static int dmar_msi_set_affinity(struct irq_data *data,
|
|
|
|
const struct cpumask *mask, bool force)
|
2008-10-17 19:14:13 +00:00
|
|
|
{
|
2011-02-04 19:18:43 +00:00
|
|
|
unsigned int irq = data->irq;
|
2008-10-17 19:14:13 +00:00
|
|
|
struct irq_cfg *cfg = irq_cfg + irq;
|
|
|
|
struct msi_msg msg;
|
2014-03-04 20:43:38 +00:00
|
|
|
int cpu = cpumask_first_and(mask, cpu_online_mask);
|
2008-10-17 19:14:13 +00:00
|
|
|
|
|
|
|
if (irq_prepare_move(irq, cpu))
|
2009-04-28 00:59:21 +00:00
|
|
|
return -1;
|
2008-10-17 19:14:13 +00:00
|
|
|
|
|
|
|
dmar_msi_read(irq, &msg);
|
|
|
|
|
|
|
|
msg.data &= ~MSI_DATA_VECTOR_MASK;
|
|
|
|
msg.data |= MSI_DATA_VECTOR(cfg->vector);
|
2009-02-16 07:14:48 +00:00
|
|
|
msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
|
|
|
|
msg.address_lo |= MSI_ADDR_DEST_ID_CPU(cpu_physical_id(cpu));
|
2008-10-17 19:14:13 +00:00
|
|
|
|
|
|
|
dmar_msi_write(irq, &msg);
|
2015-07-13 20:42:46 +00:00
|
|
|
cpumask_copy(irq_data_get_affinity_mask(data), mask);
|
2009-04-28 00:59:21 +00:00
|
|
|
|
|
|
|
return 0;
|
2008-10-17 19:14:13 +00:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_SMP */
|
|
|
|
|
2009-06-10 19:45:01 +00:00
|
|
|
static struct irq_chip dmar_msi_type = {
|
2008-10-17 19:14:13 +00:00
|
|
|
.name = "DMAR_MSI",
|
2010-09-28 15:15:11 +00:00
|
|
|
.irq_unmask = dmar_msi_unmask,
|
|
|
|
.irq_mask = dmar_msi_mask,
|
2011-02-04 19:18:43 +00:00
|
|
|
.irq_ack = ia64_ack_msi_irq,
|
2008-10-17 19:14:13 +00:00
|
|
|
#ifdef CONFIG_SMP
|
2011-02-04 19:18:43 +00:00
|
|
|
.irq_set_affinity = dmar_msi_set_affinity,
|
2008-10-17 19:14:13 +00:00
|
|
|
#endif
|
2011-02-04 19:18:43 +00:00
|
|
|
.irq_retrigger = ia64_msi_retrigger_irq,
|
2008-10-17 19:14:13 +00:00
|
|
|
};
|
|
|
|
|
2015-04-13 06:11:41 +00:00
|
|
|
static void
|
2008-10-17 19:14:13 +00:00
|
|
|
msi_compose_msg(struct pci_dev *pdev, unsigned int irq, struct msi_msg *msg)
|
|
|
|
{
|
|
|
|
struct irq_cfg *cfg = irq_cfg + irq;
|
|
|
|
unsigned dest;
|
|
|
|
|
2015-03-05 00:18:49 +00:00
|
|
|
dest = cpu_physical_id(cpumask_first_and(&(irq_to_domain(irq)),
|
|
|
|
cpu_online_mask));
|
2008-10-17 19:14:13 +00:00
|
|
|
|
|
|
|
msg->address_hi = 0;
|
|
|
|
msg->address_lo =
|
|
|
|
MSI_ADDR_HEADER |
|
2009-02-16 07:14:48 +00:00
|
|
|
MSI_ADDR_DEST_MODE_PHYS |
|
2008-10-17 19:14:13 +00:00
|
|
|
MSI_ADDR_REDIRECTION_CPU |
|
2009-02-16 07:14:48 +00:00
|
|
|
MSI_ADDR_DEST_ID_CPU(dest);
|
2008-10-17 19:14:13 +00:00
|
|
|
|
|
|
|
msg->data =
|
|
|
|
MSI_DATA_TRIGGER_EDGE |
|
|
|
|
MSI_DATA_LEVEL_ASSERT |
|
|
|
|
MSI_DATA_DELIVERY_FIXED |
|
|
|
|
MSI_DATA_VECTOR(cfg->vector);
|
|
|
|
}
|
|
|
|
|
2015-04-13 06:11:41 +00:00
|
|
|
int dmar_alloc_hwirq(int id, int node, void *arg)
|
2008-10-17 19:14:13 +00:00
|
|
|
{
|
2015-04-13 06:11:41 +00:00
|
|
|
int irq;
|
2008-10-17 19:14:13 +00:00
|
|
|
struct msi_msg msg;
|
|
|
|
|
2015-04-13 06:11:41 +00:00
|
|
|
irq = create_irq();
|
|
|
|
if (irq > 0) {
|
|
|
|
irq_set_handler_data(irq, arg);
|
|
|
|
irq_set_chip_and_handler_name(irq, &dmar_msi_type,
|
|
|
|
handle_edge_irq, "edge");
|
|
|
|
msi_compose_msg(NULL, irq, &msg);
|
|
|
|
dmar_msi_write(irq, &msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return irq;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dmar_free_hwirq(int irq)
|
|
|
|
{
|
|
|
|
irq_set_handler_data(irq, NULL);
|
|
|
|
destroy_irq(irq);
|
2008-10-17 19:14:13 +00:00
|
|
|
}
|
2011-08-24 00:05:25 +00:00
|
|
|
#endif /* CONFIG_INTEL_IOMMU */
|
2008-10-17 19:14:13 +00:00
|
|
|
|