Skip to content

Commit cd76137

Browse files
lumagbjorn-helgaas
authored andcommitted
PCI: dwc: Handle MSIs routed to multiple GIC interrupts
On some Qualcomm platforms each group of 32 MSI vectors is routed to a separate GIC interrupt. Implement support for such configurations by parsing "msi0" ... "msiX" interrupts and attaching them to the chained handler. Note that if DT doesn't list an array of MSI interrupts and uses a single "msi" IRQ, the driver will limit the number of supported MSI vectors to 32. Link: https://lore.kernel.org/r/20220707134733.2436629-5-dmitry.baryshkov@linaro.org Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Rob Herring <robh@kernel.org> Reviewed-by: Johan Hovold <johan+linaro@kernel.org> Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
1 parent db38834 commit cd76137

1 file changed

Lines changed: 58 additions & 3 deletions

File tree

drivers/pci/controller/dwc/pcie-designware-host.c

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,46 @@ static void dw_pcie_msi_init(struct dw_pcie_rp *pp)
291291
dw_pcie_writel_dbi(pci, PCIE_MSI_ADDR_HI, upper_32_bits(msi_target));
292292
}
293293

294+
static int dw_pcie_parse_split_msi_irq(struct dw_pcie_rp *pp)
295+
{
296+
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
297+
struct device *dev = pci->dev;
298+
struct platform_device *pdev = to_platform_device(dev);
299+
u32 ctrl, max_vectors;
300+
int irq;
301+
302+
/* Parse any "msiX" IRQs described in the devicetree */
303+
for (ctrl = 0; ctrl < MAX_MSI_CTRLS; ctrl++) {
304+
char msi_name[] = "msiX";
305+
306+
msi_name[3] = '0' + ctrl;
307+
irq = platform_get_irq_byname_optional(pdev, msi_name);
308+
if (irq == -ENXIO)
309+
break;
310+
if (irq < 0)
311+
return dev_err_probe(dev, irq,
312+
"Failed to parse MSI IRQ '%s'\n",
313+
msi_name);
314+
315+
pp->msi_irq[ctrl] = irq;
316+
}
317+
318+
/* If no "msiX" IRQs, caller should fallback to "msi" IRQ */
319+
if (ctrl == 0)
320+
return -ENXIO;
321+
322+
max_vectors = ctrl * MAX_MSI_IRQS_PER_CTRL;
323+
if (pp->num_vectors > max_vectors) {
324+
dev_warn(dev, "Exceeding number of MSI vectors, limiting to %u\n",
325+
max_vectors);
326+
pp->num_vectors = max_vectors;
327+
}
328+
if (!pp->num_vectors)
329+
pp->num_vectors = max_vectors;
330+
331+
return 0;
332+
}
333+
294334
static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp)
295335
{
296336
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
@@ -299,10 +339,19 @@ static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp)
299339
int ret;
300340
u32 ctrl, num_ctrls;
301341

302-
num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL;
303-
for (ctrl = 0; ctrl < num_ctrls; ctrl++)
342+
for (ctrl = 0; ctrl < MAX_MSI_CTRLS; ctrl++)
304343
pp->irq_mask[ctrl] = ~0;
305344

345+
if (!pp->msi_irq[0]) {
346+
ret = dw_pcie_parse_split_msi_irq(pp);
347+
if (ret < 0 && ret != -ENXIO)
348+
return ret;
349+
}
350+
351+
if (!pp->num_vectors)
352+
pp->num_vectors = MSI_DEF_NUM_VECTORS;
353+
num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL;
354+
306355
if (!pp->msi_irq[0]) {
307356
pp->msi_irq[0] = platform_get_irq_byname_optional(pdev, "msi");
308357
if (pp->msi_irq[0] < 0) {
@@ -312,6 +361,8 @@ static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp)
312361
}
313362
}
314363

364+
dev_dbg(dev, "Using %d MSI vectors\n", pp->num_vectors);
365+
315366
pp->msi_irq_chip = &dw_pci_msi_bottom_irq_chip;
316367

317368
ret = dw_pcie_allocate_domains(pp);
@@ -410,7 +461,11 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp)
410461
of_property_read_bool(np, "msi-parent") ||
411462
of_property_read_bool(np, "msi-map"));
412463

413-
if (!pp->num_vectors) {
464+
/*
465+
* For the has_msi_ctrl case the default assignment is handled
466+
* in the dw_pcie_msi_host_init().
467+
*/
468+
if (!pp->has_msi_ctrl && !pp->num_vectors) {
414469
pp->num_vectors = MSI_DEF_NUM_VECTORS;
415470
} else if (pp->num_vectors > MAX_MSI_IRQS) {
416471
dev_err(dev, "Invalid number of vectors\n");

0 commit comments

Comments
 (0)