Skip to content

Commit 5d627a9

Browse files
Marc ZyngierKAGA-KOKO
authored andcommitted
PCI: apple: Convert to MSI parent infrastructure
In an effort to move ARM64 away from the legacy MSI setup, convert the Apple PCIe driver to the MSI-parent infrastructure and let each device have its own MSI domain. [ tglx: Moved the struct out of the function call argument ] Signed-off-by: Marc Zyngier <maz@kernel.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Link: https://lore.kernel.org/all/20250513172819.2216709-8-maz@kernel.org
1 parent 0652644 commit 5d627a9

File tree

2 files changed

+24
-46
lines changed

2 files changed

+24
-46
lines changed

drivers/pci/controller/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ config PCIE_APPLE
4040
depends on OF
4141
depends on PCI_MSI
4242
select PCI_HOST_COMMON
43+
select IRQ_MSI_LIB
4344
help
4445
Say Y here if you want to enable PCIe controller support on Apple
4546
system-on-chips, like the Apple M1. This is required for the USB

drivers/pci/controller/pcie-apple.c

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/kernel.h>
2323
#include <linux/iopoll.h>
2424
#include <linux/irqchip/chained_irq.h>
25+
#include <linux/irqchip/irq-msi-lib.h>
2526
#include <linux/irqdomain.h>
2627
#include <linux/list.h>
2728
#include <linux/module.h>
@@ -133,7 +134,6 @@ struct apple_pcie {
133134
struct mutex lock;
134135
struct device *dev;
135136
void __iomem *base;
136-
struct irq_domain *domain;
137137
unsigned long *bitmap;
138138
struct list_head ports;
139139
struct completion event;
@@ -162,27 +162,6 @@ static void rmw_clear(u32 clr, void __iomem *addr)
162162
writel_relaxed(readl_relaxed(addr) & ~clr, addr);
163163
}
164164

165-
static void apple_msi_top_irq_mask(struct irq_data *d)
166-
{
167-
pci_msi_mask_irq(d);
168-
irq_chip_mask_parent(d);
169-
}
170-
171-
static void apple_msi_top_irq_unmask(struct irq_data *d)
172-
{
173-
pci_msi_unmask_irq(d);
174-
irq_chip_unmask_parent(d);
175-
}
176-
177-
static struct irq_chip apple_msi_top_chip = {
178-
.name = "PCIe MSI",
179-
.irq_mask = apple_msi_top_irq_mask,
180-
.irq_unmask = apple_msi_top_irq_unmask,
181-
.irq_eoi = irq_chip_eoi_parent,
182-
.irq_set_affinity = irq_chip_set_affinity_parent,
183-
.irq_set_type = irq_chip_set_type_parent,
184-
};
185-
186165
static void apple_msi_compose_msg(struct irq_data *data, struct msi_msg *msg)
187166
{
188167
msg->address_hi = upper_32_bits(DOORBELL_ADDR);
@@ -226,8 +205,7 @@ static int apple_msi_domain_alloc(struct irq_domain *domain, unsigned int virq,
226205

227206
for (i = 0; i < nr_irqs; i++) {
228207
irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i,
229-
&apple_msi_bottom_chip,
230-
domain->host_data);
208+
&apple_msi_bottom_chip, pcie);
231209
}
232210

233211
return 0;
@@ -251,12 +229,6 @@ static const struct irq_domain_ops apple_msi_domain_ops = {
251229
.free = apple_msi_domain_free,
252230
};
253231

254-
static struct msi_domain_info apple_msi_info = {
255-
.flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS |
256-
MSI_FLAG_MULTI_PCI_MSI | MSI_FLAG_PCI_MSIX),
257-
.chip = &apple_msi_top_chip,
258-
};
259-
260232
static void apple_port_irq_mask(struct irq_data *data)
261233
{
262234
struct apple_pcie_port *port = irq_data_get_irq_chip_data(data);
@@ -595,11 +567,28 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
595567
return 0;
596568
}
597569

570+
static const struct msi_parent_ops apple_msi_parent_ops = {
571+
.supported_flags = (MSI_GENERIC_FLAGS_MASK |
572+
MSI_FLAG_PCI_MSIX |
573+
MSI_FLAG_MULTI_PCI_MSI),
574+
.required_flags = (MSI_FLAG_USE_DEF_DOM_OPS |
575+
MSI_FLAG_USE_DEF_CHIP_OPS |
576+
MSI_FLAG_PCI_MSI_MASK_PARENT),
577+
.chip_flags = MSI_CHIP_FLAG_SET_EOI,
578+
.bus_select_token = DOMAIN_BUS_PCI_MSI,
579+
.init_dev_msi_info = msi_lib_init_dev_msi_info,
580+
};
581+
598582
static int apple_msi_init(struct apple_pcie *pcie)
599583
{
600584
struct fwnode_handle *fwnode = dev_fwnode(pcie->dev);
585+
struct irq_domain_info info = {
586+
.fwnode = fwnode,
587+
.ops = &apple_msi_domain_ops,
588+
.size = pcie->nvecs,
589+
.host_data = pcie,
590+
};
601591
struct of_phandle_args args = {};
602-
struct irq_domain *parent;
603592
int ret;
604593

605594
ret = of_parse_phandle_with_args(to_of_node(fwnode), "msi-ranges",
@@ -619,28 +608,16 @@ static int apple_msi_init(struct apple_pcie *pcie)
619608
if (!pcie->bitmap)
620609
return -ENOMEM;
621610

622-
parent = irq_find_matching_fwspec(&pcie->fwspec, DOMAIN_BUS_WIRED);
623-
if (!parent) {
611+
info.parent = irq_find_matching_fwspec(&pcie->fwspec, DOMAIN_BUS_WIRED);
612+
if (!info.parent) {
624613
dev_err(pcie->dev, "failed to find parent domain\n");
625614
return -ENXIO;
626615
}
627616

628-
parent = irq_domain_create_hierarchy(parent, 0, pcie->nvecs, fwnode,
629-
&apple_msi_domain_ops, pcie);
630-
if (!parent) {
617+
if (!msi_create_parent_irq_domain(&info, &apple_msi_parent_ops)) {
631618
dev_err(pcie->dev, "failed to create IRQ domain\n");
632619
return -ENOMEM;
633620
}
634-
irq_domain_update_bus_token(parent, DOMAIN_BUS_NEXUS);
635-
636-
pcie->domain = pci_msi_create_irq_domain(fwnode, &apple_msi_info,
637-
parent);
638-
if (!pcie->domain) {
639-
dev_err(pcie->dev, "failed to create MSI domain\n");
640-
irq_domain_remove(parent);
641-
return -ENOMEM;
642-
}
643-
644621
return 0;
645622
}
646623

0 commit comments

Comments
 (0)