2019-06-04 16:11:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2014-10-27 16:12:02 +08:00
|
|
|
/*
|
|
|
|
* Support of MSI, HPET and DMAR interrupts.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1997, 1998, 1999, 2000, 2009 Ingo Molnar, Hajnalka Szabo
|
|
|
|
* Moved from arch/x86/kernel/apic/io_apic.c.
|
2015-04-13 14:11:35 +08:00
|
|
|
* Jiang Liu <jiang.liu@linux.intel.com>
|
|
|
|
* Convert to hierarchical irqdomain
|
2014-10-27 16:12:02 +08:00
|
|
|
*/
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/interrupt.h>
|
2018-07-29 18:15:33 +08:00
|
|
|
#include <linux/irq.h>
|
2014-10-27 16:12:02 +08:00
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/dmar.h>
|
|
|
|
#include <linux/hpet.h>
|
|
|
|
#include <linux/msi.h>
|
2015-04-14 10:30:09 +08:00
|
|
|
#include <asm/irqdomain.h>
|
2014-10-27 16:12:02 +08:00
|
|
|
#include <asm/msidef.h>
|
|
|
|
#include <asm/hpet.h>
|
|
|
|
#include <asm/hw_irq.h>
|
|
|
|
#include <asm/apic.h>
|
|
|
|
#include <asm/irq_remapping.h>
|
|
|
|
|
2015-04-13 14:11:35 +08:00
|
|
|
static struct irq_domain *msi_default_domain;
|
|
|
|
|
2020-01-31 22:26:52 +08:00
|
|
|
static void __irq_msi_compose_msg(struct irq_cfg *cfg, struct msi_msg *msg)
|
2015-04-13 14:11:34 +08:00
|
|
|
{
|
|
|
|
msg->address_hi = MSI_ADDR_BASE_HI;
|
|
|
|
|
|
|
|
if (x2apic_enabled())
|
|
|
|
msg->address_hi |= MSI_ADDR_EXT_DEST_ID(cfg->dest_apicid);
|
|
|
|
|
|
|
|
msg->address_lo =
|
|
|
|
MSI_ADDR_BASE_LO |
|
|
|
|
((apic->irq_dest_mode == 0) ?
|
|
|
|
MSI_ADDR_DEST_MODE_PHYSICAL :
|
|
|
|
MSI_ADDR_DEST_MODE_LOGICAL) |
|
2017-12-28 18:33:33 +08:00
|
|
|
MSI_ADDR_REDIRECTION_CPU |
|
2015-04-13 14:11:34 +08:00
|
|
|
MSI_ADDR_DEST_ID(cfg->dest_apicid);
|
|
|
|
|
|
|
|
msg->data =
|
|
|
|
MSI_DATA_TRIGGER_EDGE |
|
|
|
|
MSI_DATA_LEVEL_ASSERT |
|
2017-12-28 18:33:33 +08:00
|
|
|
MSI_DATA_DELIVERY_FIXED |
|
2015-04-13 14:11:34 +08:00
|
|
|
MSI_DATA_VECTOR(cfg->vector);
|
|
|
|
}
|
|
|
|
|
2020-08-26 19:16:33 +08:00
|
|
|
void x86_vector_msi_compose_msg(struct irq_data *data, struct msi_msg *msg)
|
2020-01-31 22:26:52 +08:00
|
|
|
{
|
|
|
|
__irq_msi_compose_msg(irqd_cfg(data), msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void irq_msi_update_msg(struct irq_data *irqd, struct irq_cfg *cfg)
|
|
|
|
{
|
|
|
|
struct msi_msg msg[2] = { [1] = { }, };
|
|
|
|
|
|
|
|
__irq_msi_compose_msg(cfg, msg);
|
|
|
|
irq_data_get_irq_chip(irqd)->irq_write_msi_msg(irqd, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
msi_set_affinity(struct irq_data *irqd, const struct cpumask *mask, bool force)
|
|
|
|
{
|
|
|
|
struct irq_cfg old_cfg, *cfg = irqd_cfg(irqd);
|
|
|
|
struct irq_data *parent = irqd->parent_data;
|
|
|
|
unsigned int cpu;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Save the current configuration */
|
|
|
|
cpu = cpumask_first(irq_data_get_effective_affinity_mask(irqd));
|
|
|
|
old_cfg = *cfg;
|
|
|
|
|
|
|
|
/* Allocate a new target vector */
|
|
|
|
ret = parent->chip->irq_set_affinity(parent, mask, force);
|
|
|
|
if (ret < 0 || ret == IRQ_SET_MASK_OK_DONE)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For non-maskable and non-remapped MSI interrupts the migration
|
|
|
|
* to a different destination CPU and a different vector has to be
|
|
|
|
* done careful to handle the possible stray interrupt which can be
|
|
|
|
* caused by the non-atomic update of the address/data pair.
|
|
|
|
*
|
|
|
|
* Direct update is possible when:
|
|
|
|
* - The MSI is maskable (remapped MSI does not use this code path)).
|
|
|
|
* The quirk bit is not set in this case.
|
|
|
|
* - The new vector is the same as the old vector
|
|
|
|
* - The old vector is MANAGED_IRQ_SHUTDOWN_VECTOR (interrupt starts up)
|
|
|
|
* - The new destination CPU is the same as the old destination CPU
|
|
|
|
*/
|
|
|
|
if (!irqd_msi_nomask_quirk(irqd) ||
|
|
|
|
cfg->vector == old_cfg.vector ||
|
|
|
|
old_cfg.vector == MANAGED_IRQ_SHUTDOWN_VECTOR ||
|
|
|
|
cfg->dest_apicid == old_cfg.dest_apicid) {
|
|
|
|
irq_msi_update_msg(irqd, cfg);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Paranoia: Validate that the interrupt target is the local
|
|
|
|
* CPU.
|
|
|
|
*/
|
|
|
|
if (WARN_ON_ONCE(cpu != smp_processor_id())) {
|
|
|
|
irq_msi_update_msg(irqd, cfg);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Redirect the interrupt to the new vector on the current CPU
|
|
|
|
* first. This might cause a spurious interrupt on this vector if
|
|
|
|
* the device raises an interrupt right between this update and the
|
|
|
|
* update to the final destination CPU.
|
|
|
|
*
|
|
|
|
* If the vector is in use then the installed device handler will
|
|
|
|
* denote it as spurious which is no harm as this is a rare event
|
|
|
|
* and interrupt handlers have to cope with spurious interrupts
|
|
|
|
* anyway. If the vector is unused, then it is marked so it won't
|
2020-05-22 04:05:37 +08:00
|
|
|
* trigger the 'No irq handler for vector' warning in
|
|
|
|
* common_interrupt().
|
2020-01-31 22:26:52 +08:00
|
|
|
*
|
|
|
|
* This requires to hold vector lock to prevent concurrent updates to
|
|
|
|
* the affected vector.
|
|
|
|
*/
|
|
|
|
lock_vector_lock();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark the new target vector on the local CPU if it is currently
|
|
|
|
* unused. Reuse the VECTOR_RETRIGGERED state which is also used in
|
|
|
|
* the CPU hotplug path for a similar purpose. This cannot be
|
|
|
|
* undone here as the current CPU has interrupts disabled and
|
|
|
|
* cannot handle the interrupt before the whole set_affinity()
|
|
|
|
* section is done. In the CPU unplug case, the current CPU is
|
|
|
|
* about to vanish and will not handle any interrupts anymore. The
|
|
|
|
* vector is cleaned up when the CPU comes online again.
|
|
|
|
*/
|
|
|
|
if (IS_ERR_OR_NULL(this_cpu_read(vector_irq[cfg->vector])))
|
|
|
|
this_cpu_write(vector_irq[cfg->vector], VECTOR_RETRIGGERED);
|
|
|
|
|
|
|
|
/* Redirect it to the new vector on the local CPU temporarily */
|
|
|
|
old_cfg.vector = cfg->vector;
|
|
|
|
irq_msi_update_msg(irqd, &old_cfg);
|
|
|
|
|
|
|
|
/* Now transition it to the target CPU */
|
|
|
|
irq_msi_update_msg(irqd, cfg);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All interrupts after this point are now targeted at the new
|
|
|
|
* vector/CPU.
|
|
|
|
*
|
|
|
|
* Drop vector lock before testing whether the temporary assignment
|
|
|
|
* to the local CPU was hit by an interrupt raised in the device,
|
|
|
|
* because the retrigger function acquires vector lock again.
|
|
|
|
*/
|
|
|
|
unlock_vector_lock();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether the transition raced with a device interrupt and
|
|
|
|
* is pending in the local APICs IRR. It is safe to do this outside
|
|
|
|
* of vector lock as the irq_desc::lock of this interrupt is still
|
|
|
|
* held and interrupts are disabled: The check is not accessing the
|
|
|
|
* underlying vector store. It's just checking the local APIC's
|
|
|
|
* IRR.
|
|
|
|
*/
|
|
|
|
if (lapic_vector_set_in_irr(cfg->vector))
|
|
|
|
irq_data_get_irq_chip(irqd)->irq_retrigger(irqd);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-27 16:12:02 +08:00
|
|
|
/*
|
|
|
|
* IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices,
|
|
|
|
* which implement the MSI or MSI-X Capability Structure.
|
|
|
|
*/
|
2015-04-13 14:11:35 +08:00
|
|
|
static struct irq_chip pci_msi_controller = {
|
2014-10-27 16:12:02 +08:00
|
|
|
.name = "PCI-MSI",
|
|
|
|
.irq_unmask = pci_msi_unmask_irq,
|
|
|
|
.irq_mask = pci_msi_mask_irq,
|
2015-04-13 14:11:35 +08:00
|
|
|
.irq_ack = irq_chip_ack_parent,
|
|
|
|
.irq_retrigger = irq_chip_retrigger_hierarchy,
|
2020-01-31 22:26:52 +08:00
|
|
|
.irq_set_affinity = msi_set_affinity,
|
2014-10-27 16:12:02 +08:00
|
|
|
.flags = IRQCHIP_SKIP_SET_WAKE,
|
|
|
|
};
|
|
|
|
|
2015-04-13 14:11:35 +08:00
|
|
|
int native_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
|
2014-10-27 16:12:02 +08:00
|
|
|
{
|
2015-04-13 14:11:35 +08:00
|
|
|
struct irq_domain *domain;
|
|
|
|
struct irq_alloc_info info;
|
2014-10-27 16:12:02 +08:00
|
|
|
|
2015-04-13 14:11:35 +08:00
|
|
|
init_irq_alloc_info(&info, NULL);
|
2020-08-26 19:16:35 +08:00
|
|
|
info.type = X86_IRQ_ALLOC_TYPE_PCI_MSI;
|
2014-10-27 16:12:02 +08:00
|
|
|
|
2015-04-13 14:11:35 +08:00
|
|
|
domain = irq_remapping_get_irq_domain(&info);
|
|
|
|
if (domain == NULL)
|
|
|
|
domain = msi_default_domain;
|
|
|
|
if (domain == NULL)
|
|
|
|
return -ENOSYS;
|
2014-10-27 16:12:02 +08:00
|
|
|
|
2017-02-09 01:17:44 +08:00
|
|
|
return msi_domain_alloc_irqs(domain, &dev->dev, nvec);
|
2015-04-13 14:11:35 +08:00
|
|
|
}
|
2014-10-27 16:12:02 +08:00
|
|
|
|
2015-04-13 14:11:35 +08:00
|
|
|
void native_teardown_msi_irq(unsigned int irq)
|
|
|
|
{
|
|
|
|
irq_domain_free_irqs(irq, 1);
|
|
|
|
}
|
2014-10-27 16:12:02 +08:00
|
|
|
|
2015-04-13 14:11:35 +08:00
|
|
|
static irq_hw_number_t pci_msi_get_hwirq(struct msi_domain_info *info,
|
|
|
|
msi_alloc_info_t *arg)
|
|
|
|
{
|
2020-08-26 19:16:46 +08:00
|
|
|
return arg->hwirq;
|
2015-04-13 14:11:35 +08:00
|
|
|
}
|
2014-10-27 16:12:02 +08:00
|
|
|
|
2015-12-11 01:52:59 +08:00
|
|
|
int pci_msi_prepare(struct irq_domain *domain, struct device *dev, int nvec,
|
|
|
|
msi_alloc_info_t *arg)
|
2015-04-13 14:11:35 +08:00
|
|
|
{
|
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
|
|
struct msi_desc *desc = first_pci_msi_entry(pdev);
|
|
|
|
|
|
|
|
init_irq_alloc_info(arg, NULL);
|
|
|
|
if (desc->msi_attrib.is_msix) {
|
2020-08-26 19:16:35 +08:00
|
|
|
arg->type = X86_IRQ_ALLOC_TYPE_PCI_MSIX;
|
2015-04-13 14:11:35 +08:00
|
|
|
} else {
|
2020-08-26 19:16:35 +08:00
|
|
|
arg->type = X86_IRQ_ALLOC_TYPE_PCI_MSI;
|
2015-04-13 14:11:35 +08:00
|
|
|
arg->flags |= X86_IRQ_ALLOC_CONTIGUOUS_VECTORS;
|
|
|
|
}
|
2014-10-27 16:12:02 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-12-11 01:52:59 +08:00
|
|
|
EXPORT_SYMBOL_GPL(pci_msi_prepare);
|
2014-10-27 16:12:02 +08:00
|
|
|
|
2015-12-11 01:52:59 +08:00
|
|
|
void pci_msi_set_desc(msi_alloc_info_t *arg, struct msi_desc *desc)
|
2014-10-27 16:12:02 +08:00
|
|
|
{
|
2020-08-26 19:16:46 +08:00
|
|
|
arg->desc = desc;
|
|
|
|
arg->hwirq = pci_msi_domain_calc_hwirq(desc);
|
2015-04-13 14:11:35 +08:00
|
|
|
}
|
2015-12-11 01:52:59 +08:00
|
|
|
EXPORT_SYMBOL_GPL(pci_msi_set_desc);
|
2014-10-27 16:12:02 +08:00
|
|
|
|
2015-04-13 14:11:35 +08:00
|
|
|
static struct msi_domain_ops pci_msi_domain_ops = {
|
|
|
|
.get_hwirq = pci_msi_get_hwirq,
|
|
|
|
.msi_prepare = pci_msi_prepare,
|
|
|
|
.set_desc = pci_msi_set_desc,
|
|
|
|
};
|
2014-10-27 16:12:02 +08:00
|
|
|
|
2015-04-13 14:11:35 +08:00
|
|
|
static struct msi_domain_info pci_msi_domain_info = {
|
|
|
|
.flags = MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS |
|
2015-04-13 14:11:46 +08:00
|
|
|
MSI_FLAG_PCI_MSIX,
|
2015-04-13 14:11:35 +08:00
|
|
|
.ops = &pci_msi_domain_ops,
|
|
|
|
.chip = &pci_msi_controller,
|
|
|
|
.handler = handle_edge_irq,
|
|
|
|
.handler_name = "edge",
|
|
|
|
};
|
2014-10-27 16:12:02 +08:00
|
|
|
|
2017-06-20 07:37:14 +08:00
|
|
|
void __init arch_init_msi_domain(struct irq_domain *parent)
|
2015-04-13 14:11:35 +08:00
|
|
|
{
|
2017-06-20 07:37:14 +08:00
|
|
|
struct fwnode_handle *fn;
|
|
|
|
|
2015-04-13 14:11:35 +08:00
|
|
|
if (disable_apic)
|
|
|
|
return;
|
2014-10-27 16:12:02 +08:00
|
|
|
|
2017-06-20 07:37:14 +08:00
|
|
|
fn = irq_domain_alloc_named_fwnode("PCI-MSI");
|
|
|
|
if (fn) {
|
|
|
|
msi_default_domain =
|
|
|
|
pci_msi_create_irq_domain(fn, &pci_msi_domain_info,
|
|
|
|
parent);
|
|
|
|
}
|
2020-07-09 17:53:06 +08:00
|
|
|
if (!msi_default_domain) {
|
|
|
|
irq_domain_free_fwnode(fn);
|
2015-04-13 14:11:35 +08:00
|
|
|
pr_warn("failed to initialize irqdomain for MSI/MSI-x.\n");
|
2020-07-09 17:53:06 +08:00
|
|
|
} else {
|
2020-01-31 22:26:52 +08:00
|
|
|
msi_default_domain->flags |= IRQ_DOMAIN_MSI_NOMASK_QUIRK;
|
2020-07-09 17:53:06 +08:00
|
|
|
}
|
2014-10-27 16:12:02 +08:00
|
|
|
}
|
|
|
|
|
2015-04-13 14:11:35 +08:00
|
|
|
#ifdef CONFIG_IRQ_REMAP
|
2015-04-13 14:11:46 +08:00
|
|
|
static struct irq_chip pci_msi_ir_controller = {
|
|
|
|
.name = "IR-PCI-MSI",
|
|
|
|
.irq_unmask = pci_msi_unmask_irq,
|
|
|
|
.irq_mask = pci_msi_mask_irq,
|
|
|
|
.irq_ack = irq_chip_ack_parent,
|
|
|
|
.irq_retrigger = irq_chip_retrigger_hierarchy,
|
|
|
|
.flags = IRQCHIP_SKIP_SET_WAKE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct msi_domain_info pci_msi_ir_domain_info = {
|
|
|
|
.flags = MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS |
|
|
|
|
MSI_FLAG_MULTI_PCI_MSI | MSI_FLAG_PCI_MSIX,
|
|
|
|
.ops = &pci_msi_domain_ops,
|
|
|
|
.chip = &pci_msi_ir_controller,
|
|
|
|
.handler = handle_edge_irq,
|
|
|
|
.handler_name = "edge",
|
|
|
|
};
|
|
|
|
|
2017-06-20 07:37:10 +08:00
|
|
|
struct irq_domain *arch_create_remap_msi_irq_domain(struct irq_domain *parent,
|
|
|
|
const char *name, int id)
|
|
|
|
{
|
|
|
|
struct fwnode_handle *fn;
|
|
|
|
struct irq_domain *d;
|
|
|
|
|
|
|
|
fn = irq_domain_alloc_named_id_fwnode(name, id);
|
|
|
|
if (!fn)
|
|
|
|
return NULL;
|
|
|
|
d = pci_msi_create_irq_domain(fn, &pci_msi_ir_domain_info, parent);
|
2020-07-09 17:53:06 +08:00
|
|
|
if (!d)
|
|
|
|
irq_domain_free_fwnode(fn);
|
2017-06-20 07:37:10 +08:00
|
|
|
return d;
|
|
|
|
}
|
2015-04-13 14:11:35 +08:00
|
|
|
#endif
|
2014-10-27 16:12:02 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_DMAR_TABLE
|
2015-04-13 14:11:48 +08:00
|
|
|
static void dmar_msi_write_msg(struct irq_data *data, struct msi_msg *msg)
|
|
|
|
{
|
|
|
|
dmar_msi_write(data->irq, msg);
|
|
|
|
}
|
|
|
|
|
2015-04-13 14:11:42 +08:00
|
|
|
static struct irq_chip dmar_msi_controller = {
|
2015-04-13 14:11:45 +08:00
|
|
|
.name = "DMAR-MSI",
|
2014-10-27 16:12:02 +08:00
|
|
|
.irq_unmask = dmar_msi_unmask,
|
|
|
|
.irq_mask = dmar_msi_mask,
|
2015-04-13 14:11:42 +08:00
|
|
|
.irq_ack = irq_chip_ack_parent,
|
2015-04-13 14:11:49 +08:00
|
|
|
.irq_set_affinity = msi_domain_set_affinity,
|
2015-04-13 14:11:42 +08:00
|
|
|
.irq_retrigger = irq_chip_retrigger_hierarchy,
|
2015-04-13 14:11:48 +08:00
|
|
|
.irq_write_msi_msg = dmar_msi_write_msg,
|
2014-10-27 16:12:02 +08:00
|
|
|
.flags = IRQCHIP_SKIP_SET_WAKE,
|
|
|
|
};
|
|
|
|
|
2015-04-13 14:11:49 +08:00
|
|
|
static irq_hw_number_t dmar_msi_get_hwirq(struct msi_domain_info *info,
|
|
|
|
msi_alloc_info_t *arg)
|
2015-04-13 14:11:42 +08:00
|
|
|
{
|
2020-08-26 19:16:43 +08:00
|
|
|
return arg->hwirq;
|
2015-04-13 14:11:42 +08:00
|
|
|
}
|
|
|
|
|
2015-04-13 14:11:49 +08:00
|
|
|
static int dmar_msi_init(struct irq_domain *domain,
|
|
|
|
struct msi_domain_info *info, unsigned int virq,
|
|
|
|
irq_hw_number_t hwirq, msi_alloc_info_t *arg)
|
2015-04-13 14:11:42 +08:00
|
|
|
{
|
2020-08-26 19:16:43 +08:00
|
|
|
irq_domain_set_info(domain, virq, arg->devid, info->chip, NULL,
|
|
|
|
handle_edge_irq, arg->data, "edge");
|
2015-04-13 14:11:42 +08:00
|
|
|
|
2015-04-13 14:11:49 +08:00
|
|
|
return 0;
|
2015-04-13 14:11:42 +08:00
|
|
|
}
|
|
|
|
|
2015-04-13 14:11:49 +08:00
|
|
|
static struct msi_domain_ops dmar_msi_domain_ops = {
|
|
|
|
.get_hwirq = dmar_msi_get_hwirq,
|
|
|
|
.msi_init = dmar_msi_init,
|
|
|
|
};
|
2015-04-13 14:11:42 +08:00
|
|
|
|
2015-04-13 14:11:49 +08:00
|
|
|
static struct msi_domain_info dmar_msi_domain_info = {
|
|
|
|
.ops = &dmar_msi_domain_ops,
|
|
|
|
.chip = &dmar_msi_controller,
|
2015-04-13 14:11:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct irq_domain *dmar_get_irq_domain(void)
|
|
|
|
{
|
|
|
|
static struct irq_domain *dmar_domain;
|
|
|
|
static DEFINE_MUTEX(dmar_lock);
|
2017-06-20 07:37:14 +08:00
|
|
|
struct fwnode_handle *fn;
|
2015-04-13 14:11:42 +08:00
|
|
|
|
|
|
|
mutex_lock(&dmar_lock);
|
2017-06-20 07:37:14 +08:00
|
|
|
if (dmar_domain)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
fn = irq_domain_alloc_named_fwnode("DMAR-MSI");
|
|
|
|
if (fn) {
|
|
|
|
dmar_domain = msi_create_irq_domain(fn, &dmar_msi_domain_info,
|
2015-04-13 14:11:49 +08:00
|
|
|
x86_vector_domain);
|
2020-07-09 17:53:06 +08:00
|
|
|
if (!dmar_domain)
|
|
|
|
irq_domain_free_fwnode(fn);
|
2017-06-20 07:37:14 +08:00
|
|
|
}
|
|
|
|
out:
|
2015-04-13 14:11:42 +08:00
|
|
|
mutex_unlock(&dmar_lock);
|
|
|
|
return dmar_domain;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dmar_alloc_hwirq(int id, int node, void *arg)
|
|
|
|
{
|
|
|
|
struct irq_domain *domain = dmar_get_irq_domain();
|
|
|
|
struct irq_alloc_info info;
|
|
|
|
|
|
|
|
if (!domain)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
init_irq_alloc_info(&info, NULL);
|
|
|
|
info.type = X86_IRQ_ALLOC_TYPE_DMAR;
|
2020-08-26 19:16:43 +08:00
|
|
|
info.devid = id;
|
|
|
|
info.data = arg;
|
2015-04-13 14:11:29 +08:00
|
|
|
|
2015-04-13 14:11:42 +08:00
|
|
|
return irq_domain_alloc_irqs(domain, 1, node, &info);
|
2015-04-13 14:11:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void dmar_free_hwirq(int irq)
|
|
|
|
{
|
|
|
|
irq_domain_free_irqs(irq, 1);
|
|
|
|
}
|
2014-10-27 16:12:02 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MSI message composition
|
|
|
|
*/
|
|
|
|
#ifdef CONFIG_HPET_TIMER
|
2015-04-13 14:11:34 +08:00
|
|
|
static inline int hpet_dev_id(struct irq_domain *domain)
|
|
|
|
{
|
2015-04-13 14:11:49 +08:00
|
|
|
struct msi_domain_info *info = msi_get_domain_info(domain);
|
2014-10-27 16:12:02 +08:00
|
|
|
|
2015-04-13 14:11:49 +08:00
|
|
|
return (int)(long)info->data;
|
2014-10-27 16:12:02 +08:00
|
|
|
}
|
|
|
|
|
2015-04-13 14:11:48 +08:00
|
|
|
static void hpet_msi_write_msg(struct irq_data *data, struct msi_msg *msg)
|
|
|
|
{
|
2015-06-01 16:05:18 +08:00
|
|
|
hpet_msi_write(irq_data_get_irq_handler_data(data), msg);
|
2015-04-13 14:11:48 +08:00
|
|
|
}
|
|
|
|
|
2016-08-09 07:29:06 +08:00
|
|
|
static struct irq_chip hpet_msi_controller __ro_after_init = {
|
2015-04-13 14:11:45 +08:00
|
|
|
.name = "HPET-MSI",
|
2014-10-27 16:12:02 +08:00
|
|
|
.irq_unmask = hpet_msi_unmask,
|
|
|
|
.irq_mask = hpet_msi_mask,
|
2015-04-13 14:11:34 +08:00
|
|
|
.irq_ack = irq_chip_ack_parent,
|
2015-04-13 14:11:49 +08:00
|
|
|
.irq_set_affinity = msi_domain_set_affinity,
|
2015-04-13 14:11:34 +08:00
|
|
|
.irq_retrigger = irq_chip_retrigger_hierarchy,
|
2015-04-13 14:11:48 +08:00
|
|
|
.irq_write_msi_msg = hpet_msi_write_msg,
|
2014-10-27 16:12:02 +08:00
|
|
|
.flags = IRQCHIP_SKIP_SET_WAKE,
|
|
|
|
};
|
|
|
|
|
2015-04-13 14:11:49 +08:00
|
|
|
static irq_hw_number_t hpet_msi_get_hwirq(struct msi_domain_info *info,
|
|
|
|
msi_alloc_info_t *arg)
|
2015-04-13 14:11:34 +08:00
|
|
|
{
|
2020-08-26 19:16:41 +08:00
|
|
|
return arg->hwirq;
|
2015-04-13 14:11:34 +08:00
|
|
|
}
|
|
|
|
|
2015-04-13 14:11:49 +08:00
|
|
|
static int hpet_msi_init(struct irq_domain *domain,
|
|
|
|
struct msi_domain_info *info, unsigned int virq,
|
|
|
|
irq_hw_number_t hwirq, msi_alloc_info_t *arg)
|
2015-04-13 14:11:34 +08:00
|
|
|
{
|
2015-04-13 14:11:49 +08:00
|
|
|
irq_set_status_flags(virq, IRQ_MOVE_PCNTXT);
|
2020-08-26 19:16:41 +08:00
|
|
|
irq_domain_set_info(domain, virq, arg->hwirq, info->chip, NULL,
|
|
|
|
handle_edge_irq, arg->data, "edge");
|
2015-04-13 14:11:34 +08:00
|
|
|
|
2015-04-13 14:11:49 +08:00
|
|
|
return 0;
|
2015-04-13 14:11:34 +08:00
|
|
|
}
|
|
|
|
|
2015-04-13 14:11:49 +08:00
|
|
|
static void hpet_msi_free(struct irq_domain *domain,
|
|
|
|
struct msi_domain_info *info, unsigned int virq)
|
2015-04-13 14:11:34 +08:00
|
|
|
{
|
2015-04-13 14:11:49 +08:00
|
|
|
irq_clear_status_flags(virq, IRQ_MOVE_PCNTXT);
|
2015-04-13 14:11:34 +08:00
|
|
|
}
|
|
|
|
|
2015-04-13 14:11:49 +08:00
|
|
|
static struct msi_domain_ops hpet_msi_domain_ops = {
|
|
|
|
.get_hwirq = hpet_msi_get_hwirq,
|
|
|
|
.msi_init = hpet_msi_init,
|
|
|
|
.msi_free = hpet_msi_free,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct msi_domain_info hpet_msi_domain_info = {
|
|
|
|
.ops = &hpet_msi_domain_ops,
|
|
|
|
.chip = &hpet_msi_controller,
|
2015-04-13 14:11:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct irq_domain *hpet_create_irq_domain(int hpet_id)
|
|
|
|
{
|
2015-04-13 14:11:49 +08:00
|
|
|
struct msi_domain_info *domain_info;
|
2017-06-20 07:37:14 +08:00
|
|
|
struct irq_domain *parent, *d;
|
|
|
|
struct irq_alloc_info info;
|
|
|
|
struct fwnode_handle *fn;
|
2015-04-13 14:11:34 +08:00
|
|
|
|
|
|
|
if (x86_vector_domain == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2015-04-13 14:11:49 +08:00
|
|
|
domain_info = kzalloc(sizeof(*domain_info), GFP_KERNEL);
|
|
|
|
if (!domain_info)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
*domain_info = hpet_msi_domain_info;
|
|
|
|
domain_info->data = (void *)(long)hpet_id;
|
|
|
|
|
2015-04-13 14:11:34 +08:00
|
|
|
init_irq_alloc_info(&info, NULL);
|
2020-08-26 19:16:36 +08:00
|
|
|
info.type = X86_IRQ_ALLOC_TYPE_HPET_GET_PARENT;
|
2020-08-26 19:16:41 +08:00
|
|
|
info.devid = hpet_id;
|
2020-08-26 19:16:39 +08:00
|
|
|
parent = irq_remapping_get_irq_domain(&info);
|
2020-08-26 19:16:33 +08:00
|
|
|
if (parent == NULL)
|
2015-04-13 14:11:34 +08:00
|
|
|
parent = x86_vector_domain;
|
2020-08-26 19:16:33 +08:00
|
|
|
else
|
2015-04-13 14:11:46 +08:00
|
|
|
hpet_msi_controller.name = "IR-HPET-MSI";
|
2015-04-13 14:11:34 +08:00
|
|
|
|
2017-06-20 07:37:14 +08:00
|
|
|
fn = irq_domain_alloc_named_id_fwnode(hpet_msi_controller.name,
|
|
|
|
hpet_id);
|
|
|
|
if (!fn) {
|
|
|
|
kfree(domain_info);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
d = msi_create_irq_domain(fn, domain_info, parent);
|
2020-07-09 17:53:06 +08:00
|
|
|
if (!d) {
|
|
|
|
irq_domain_free_fwnode(fn);
|
|
|
|
kfree(domain_info);
|
|
|
|
}
|
2017-06-20 07:37:14 +08:00
|
|
|
return d;
|
2015-04-13 14:11:34 +08:00
|
|
|
}
|
|
|
|
|
2019-06-23 21:24:03 +08:00
|
|
|
int hpet_assign_irq(struct irq_domain *domain, struct hpet_channel *hc,
|
2015-04-13 14:11:34 +08:00
|
|
|
int dev_num)
|
|
|
|
{
|
|
|
|
struct irq_alloc_info info;
|
|
|
|
|
|
|
|
init_irq_alloc_info(&info, NULL);
|
|
|
|
info.type = X86_IRQ_ALLOC_TYPE_HPET;
|
2020-08-26 19:16:41 +08:00
|
|
|
info.data = hc;
|
|
|
|
info.devid = hpet_dev_id(domain);
|
|
|
|
info.hwirq = dev_num;
|
2015-04-13 14:11:34 +08:00
|
|
|
|
2015-05-11 17:56:49 +08:00
|
|
|
return irq_domain_alloc_irqs(domain, 1, NUMA_NO_NODE, &info);
|
2015-04-13 14:11:34 +08:00
|
|
|
}
|
2014-10-27 16:12:02 +08:00
|
|
|
#endif
|