mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

- Switch the MSI decriptor locking to lock guards - Replace a broken and naive implementation of PCI/MSI-X control word updates in the PCI/TPH driver with a properly serialized variant in the PCI/MSI core code. - Remove the MSI descriptor abuse in the SCCI/UFS/QCOM driver by replacing the direct access to the MSI descriptors with the proper API function calls. People will never understand that APIs exist for a reason... - Provide core infrastructre for the upcoming PCI endpoint library extensions. Currently limited to ARM GICv3+, but in theory extensible to other architectures. - Provide a MSI domain::teardown() callback, which allows drivers to undo the effects of the prepare() callback. - Move the MSI domain::prepare() callback invocation to domain creation time to avoid redundant (and in case of ARM/GIC-V3-ITS confusing) invocations on every allocation. In combination with the new teardown callback this removes some ugly hacks in the GIC-V3-ITS driver, which pretended to work around the short comings of the core code so far. With this update the code is correct by design and implementation. - Make the irqchip MSI library globally available, provide a MSI parent domain creation helper and convert a bunch of (PCI/)MSI drivers over to the modern MSI parent mechanism. This is the first step to get rid of at least one incarnation of the three PCI/MSI management schemes. - The usual small cleanups and improvements -----BEGIN PGP SIGNATURE----- iQJHBAABCgAxFiEEQp8+kY+LLUocC4bMphj1TA10mKEFAmgzgFsTHHRnbHhAbGlu dXRyb25peC5kZQAKCRCmGPVMDXSYoR0KD/402K12tlI/D70H2aTG25dbTx+dkVk+ pKpJz0985uUlLJiPCR54dZL0ofcfRU+CdjEIf1I+6TPshtg6IWLJCfqu7OWVPYzz 2lJDO0yeUGwJqc0CIa1vttvJWvcUcxfWBX/ZSkOIM5avaXqSwRwsFNfd7TQ+T+eG 79VS1yyW197mUva53ekSF2voa8EEPWfEslAjoX1dRg5d4viAxaLtKm/KpBqo1oPh Eb+E67xEWiIonvWNdr1AOisxnbi19PyDo1xnftgBToaeXXYBodNrNIAfAkx40YUZ IZQLHvhZ91x15hXYIS4Cz1RXqPECbu/tHxs4AFUgGvqdgJUF89wzI3C21ymrKA6E tDlWfpIcuE3vV/bsqj1gHGL5G5m1tyBRgIdIAOOmMoTHvwp5rrQtuZzpuqzGmEzj iVIHnn5m08kRpOZQc7+PlxQMh3eunEyj9WWG49EJgoAnJPb5lou4shTwBUheHcKm NXxKsfo4x5C+WehGTxv80UlnMcK3Yh/TuWf2OPR6QuT2iHP2VL5jyHjIs0ICn0cp 1tvSJtdc1rgvk/4Vn4lu5eyVaTx5ZAH8ZXNQfwwBTWTp3ZyAW+7GkaCq3LPaNJoZ 4LWpgZ5gs6wT+1XNT3boKdns81VolmeTI8P1ciQKpUtaTt6Cy9P/i2az/J+BCS4U Fn5Qqk08PHGrUQ== =OBMj -----END PGP SIGNATURE----- Merge tag 'irq-msi-2025-05-25' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip Pull MSI updates from Thomas Gleixner: "Updates for the MSI subsystem (core code and PCI): - Switch the MSI descriptor locking to lock guards - Replace a broken and naive implementation of PCI/MSI-X control word updates in the PCI/TPH driver with a properly serialized variant in the PCI/MSI core code. - Remove the MSI descriptor abuse in the SCCI/UFS/QCOM driver by replacing the direct access to the MSI descriptors with the proper API function calls. People will never understand that APIs exist for a reason... - Provide core infrastructre for the upcoming PCI endpoint library extensions. Currently limited to ARM GICv3+, but in theory extensible to other architectures. - Provide a MSI domain::teardown() callback, which allows drivers to undo the effects of the prepare() callback. - Move the MSI domain::prepare() callback invocation to domain creation time to avoid redundant (and in case of ARM/GIC-V3-ITS confusing) invocations on every allocation. In combination with the new teardown callback this removes some ugly hacks in the GIC-V3-ITS driver, which pretended to work around the short comings of the core code so far. With this update the code is correct by design and implementation. - Make the irqchip MSI library globally available, provide a MSI parent domain creation helper and convert a bunch of (PCI/)MSI drivers over to the modern MSI parent mechanism. This is the first step to get rid of at least one incarnation of the three PCI/MSI management schemes. - The usual small cleanups and improvements" * tag 'irq-msi-2025-05-25' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (33 commits) PCI/MSI: Use bool for MSI enable state tracking PCI: tegra: Convert to MSI parent infrastructure PCI: xgene: Convert to MSI parent infrastructure PCI: apple: Convert to MSI parent infrastructure irqchip/msi-lib: Honour the MSI_FLAG_NO_AFFINITY flag irqchip/mvebu: Convert to msi_create_parent_irq_domain() helper irqchip/gic: Convert to msi_create_parent_irq_domain() helper genirq/msi: Add helper for creating MSI-parent irq domains irqchip: Make irq-msi-lib.h globally available irqchip/gic-v3-its: Use allocation size from the prepare call genirq/msi: Engage the .msi_teardown() callback on domain removal genirq/msi: Move prepare() call to per-device allocation irqchip/gic-v3-its: Implement .msi_teardown() callback genirq/msi: Add .msi_teardown() callback as the reverse of .msi_prepare() irqchip/gic-v3-its: Add support for device tree msi-map and msi-mask dt-bindings: PCI: pci-ep: Add support for iommu-map and msi-map irqchip/gic-v3-its: Set IRQ_DOMAIN_FLAG_MSI_IMMUTABLE for ITS irqdomain: Add IRQ_DOMAIN_FLAG_MSI_IMMUTABLE and irq_domain_is_msi_immutable() platform-msi: Add msi_remove_device_irq_domain() in platform_device_msi_free_irqs_all() genirq/msi: Rename msi_[un]lock_descs() ...
229 lines
5.7 KiB
C
229 lines
5.7 KiB
C
/*
|
|
* Copyright (C) 2016 Marvell
|
|
*
|
|
* Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
|
|
*
|
|
* This file is licensed under the terms of the GNU General Public
|
|
* License version 2. This program is licensed "as is" without any
|
|
* warranty of any kind, whether express or implied.
|
|
*/
|
|
|
|
#define pr_fmt(fmt) "GIC-ODMI: " fmt
|
|
|
|
#include <linux/irq.h>
|
|
#include <linux/irqchip.h>
|
|
#include <linux/irqdomain.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/msi.h>
|
|
#include <linux/of_address.h>
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/irqchip/irq-msi-lib.h>
|
|
|
|
#include <dt-bindings/interrupt-controller/arm-gic.h>
|
|
|
|
#define GICP_ODMIN_SET 0x40
|
|
#define GICP_ODMI_INT_NUM_SHIFT 12
|
|
#define GICP_ODMIN_GM_EP_R0 0x110
|
|
#define GICP_ODMIN_GM_EP_R1 0x114
|
|
#define GICP_ODMIN_GM_EA_R0 0x108
|
|
#define GICP_ODMIN_GM_EA_R1 0x118
|
|
|
|
/*
|
|
* We don't support the group events, so we simply have 8 interrupts
|
|
* per frame.
|
|
*/
|
|
#define NODMIS_SHIFT 3
|
|
#define NODMIS_PER_FRAME (1 << NODMIS_SHIFT)
|
|
#define NODMIS_MASK (NODMIS_PER_FRAME - 1)
|
|
|
|
struct odmi_data {
|
|
struct resource res;
|
|
void __iomem *base;
|
|
unsigned int spi_base;
|
|
};
|
|
|
|
static struct odmi_data *odmis;
|
|
static unsigned long *odmis_bm;
|
|
static unsigned int odmis_count;
|
|
|
|
/* Protects odmis_bm */
|
|
static DEFINE_SPINLOCK(odmis_bm_lock);
|
|
|
|
static void odmi_compose_msi_msg(struct irq_data *d, struct msi_msg *msg)
|
|
{
|
|
struct odmi_data *odmi;
|
|
phys_addr_t addr;
|
|
unsigned int odmin;
|
|
|
|
if (WARN_ON(d->hwirq >= odmis_count * NODMIS_PER_FRAME))
|
|
return;
|
|
|
|
odmi = &odmis[d->hwirq >> NODMIS_SHIFT];
|
|
odmin = d->hwirq & NODMIS_MASK;
|
|
|
|
addr = odmi->res.start + GICP_ODMIN_SET;
|
|
|
|
msg->address_hi = upper_32_bits(addr);
|
|
msg->address_lo = lower_32_bits(addr);
|
|
msg->data = odmin << GICP_ODMI_INT_NUM_SHIFT;
|
|
}
|
|
|
|
static struct irq_chip odmi_irq_chip = {
|
|
.name = "ODMI",
|
|
.irq_mask = irq_chip_mask_parent,
|
|
.irq_unmask = irq_chip_unmask_parent,
|
|
.irq_eoi = irq_chip_eoi_parent,
|
|
.irq_set_affinity = irq_chip_set_affinity_parent,
|
|
.irq_compose_msi_msg = odmi_compose_msi_msg,
|
|
};
|
|
|
|
static int odmi_irq_domain_alloc(struct irq_domain *domain, unsigned int virq,
|
|
unsigned int nr_irqs, void *args)
|
|
{
|
|
struct odmi_data *odmi = NULL;
|
|
struct irq_fwspec fwspec;
|
|
struct irq_data *d;
|
|
unsigned int hwirq, odmin;
|
|
int ret;
|
|
|
|
spin_lock(&odmis_bm_lock);
|
|
hwirq = find_first_zero_bit(odmis_bm, NODMIS_PER_FRAME * odmis_count);
|
|
if (hwirq >= NODMIS_PER_FRAME * odmis_count) {
|
|
spin_unlock(&odmis_bm_lock);
|
|
return -ENOSPC;
|
|
}
|
|
|
|
__set_bit(hwirq, odmis_bm);
|
|
spin_unlock(&odmis_bm_lock);
|
|
|
|
odmi = &odmis[hwirq >> NODMIS_SHIFT];
|
|
odmin = hwirq & NODMIS_MASK;
|
|
|
|
fwspec.fwnode = domain->parent->fwnode;
|
|
fwspec.param_count = 3;
|
|
fwspec.param[0] = GIC_SPI;
|
|
fwspec.param[1] = odmi->spi_base - 32 + odmin;
|
|
fwspec.param[2] = IRQ_TYPE_EDGE_RISING;
|
|
|
|
ret = irq_domain_alloc_irqs_parent(domain, virq, 1, &fwspec);
|
|
if (ret) {
|
|
pr_err("Cannot allocate parent IRQ\n");
|
|
spin_lock(&odmis_bm_lock);
|
|
__clear_bit(odmin, odmis_bm);
|
|
spin_unlock(&odmis_bm_lock);
|
|
return ret;
|
|
}
|
|
|
|
/* Configure the interrupt line to be edge */
|
|
d = irq_domain_get_irq_data(domain->parent, virq);
|
|
d->chip->irq_set_type(d, IRQ_TYPE_EDGE_RISING);
|
|
|
|
irq_domain_set_hwirq_and_chip(domain, virq, hwirq,
|
|
&odmi_irq_chip, NULL);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void odmi_irq_domain_free(struct irq_domain *domain,
|
|
unsigned int virq, unsigned int nr_irqs)
|
|
{
|
|
struct irq_data *d = irq_domain_get_irq_data(domain, virq);
|
|
|
|
if (d->hwirq >= odmis_count * NODMIS_PER_FRAME) {
|
|
pr_err("Failed to teardown msi. Invalid hwirq %lu\n", d->hwirq);
|
|
return;
|
|
}
|
|
|
|
irq_domain_free_irqs_parent(domain, virq, nr_irqs);
|
|
|
|
/* Actually free the MSI */
|
|
spin_lock(&odmis_bm_lock);
|
|
__clear_bit(d->hwirq, odmis_bm);
|
|
spin_unlock(&odmis_bm_lock);
|
|
}
|
|
|
|
static const struct irq_domain_ops odmi_domain_ops = {
|
|
.select = msi_lib_irq_domain_select,
|
|
.alloc = odmi_irq_domain_alloc,
|
|
.free = odmi_irq_domain_free,
|
|
};
|
|
|
|
#define ODMI_MSI_FLAGS_REQUIRED (MSI_FLAG_USE_DEF_DOM_OPS | \
|
|
MSI_FLAG_USE_DEF_CHIP_OPS)
|
|
|
|
#define ODMI_MSI_FLAGS_SUPPORTED (MSI_GENERIC_FLAGS_MASK)
|
|
|
|
static const struct msi_parent_ops odmi_msi_parent_ops = {
|
|
.supported_flags = ODMI_MSI_FLAGS_SUPPORTED,
|
|
.required_flags = ODMI_MSI_FLAGS_REQUIRED,
|
|
.chip_flags = MSI_CHIP_FLAG_SET_EOI,
|
|
.bus_select_token = DOMAIN_BUS_GENERIC_MSI,
|
|
.bus_select_mask = MATCH_PLATFORM_MSI,
|
|
.prefix = "ODMI-",
|
|
.init_dev_msi_info = msi_lib_init_dev_msi_info,
|
|
};
|
|
|
|
static int __init mvebu_odmi_init(struct device_node *node,
|
|
struct device_node *parent)
|
|
{
|
|
struct irq_domain_info info = {
|
|
.fwnode = of_fwnode_handle(node),
|
|
.ops = &odmi_domain_ops,
|
|
.size = odmis_count * NODMIS_PER_FRAME,
|
|
.parent = irq_find_host(parent),
|
|
};
|
|
int ret, i;
|
|
|
|
if (of_property_read_u32(node, "marvell,odmi-frames", &odmis_count))
|
|
return -EINVAL;
|
|
|
|
odmis = kcalloc(odmis_count, sizeof(struct odmi_data), GFP_KERNEL);
|
|
if (!odmis)
|
|
return -ENOMEM;
|
|
|
|
odmis_bm = bitmap_zalloc(odmis_count * NODMIS_PER_FRAME, GFP_KERNEL);
|
|
if (!odmis_bm) {
|
|
ret = -ENOMEM;
|
|
goto err_alloc;
|
|
}
|
|
|
|
for (i = 0; i < odmis_count; i++) {
|
|
struct odmi_data *odmi = &odmis[i];
|
|
|
|
ret = of_address_to_resource(node, i, &odmi->res);
|
|
if (ret)
|
|
goto err_unmap;
|
|
|
|
odmi->base = of_io_request_and_map(node, i, "odmi");
|
|
if (IS_ERR(odmi->base)) {
|
|
ret = PTR_ERR(odmi->base);
|
|
goto err_unmap;
|
|
}
|
|
|
|
if (of_property_read_u32_index(node, "marvell,spi-base",
|
|
i, &odmi->spi_base)) {
|
|
ret = -EINVAL;
|
|
goto err_unmap;
|
|
}
|
|
}
|
|
|
|
if (msi_create_parent_irq_domain(&info, &odmi_msi_parent_ops))
|
|
return 0;
|
|
|
|
ret = -ENOMEM;
|
|
|
|
err_unmap:
|
|
for (i = 0; i < odmis_count; i++) {
|
|
struct odmi_data *odmi = &odmis[i];
|
|
|
|
if (odmi->base && !IS_ERR(odmi->base))
|
|
iounmap(odmis[i].base);
|
|
}
|
|
bitmap_free(odmis_bm);
|
|
err_alloc:
|
|
kfree(odmis);
|
|
return ret;
|
|
}
|
|
|
|
IRQCHIP_DECLARE(mvebu_odmi, "marvell,odmi-controller", mvebu_odmi_init);
|