Commit 49fbfdc2 authored by Thomas Gleixner's avatar Thomas Gleixner

soc: ti: ti_sci_inta_msi: Rework MSI descriptor allocation

Protect the allocation properly and use the core allocation and free
mechanism.

No functional change intended.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Tested-by: default avatarNishanth Menon <nm@ti.com>
Reviewed-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/20211206210748.737904583@linutronix.de
parent 68e31835
...@@ -51,6 +51,7 @@ struct irq_domain *ti_sci_inta_msi_create_irq_domain(struct fwnode_handle *fwnod ...@@ -51,6 +51,7 @@ struct irq_domain *ti_sci_inta_msi_create_irq_domain(struct fwnode_handle *fwnod
struct irq_domain *domain; struct irq_domain *domain;
ti_sci_inta_msi_update_chip_ops(info); ti_sci_inta_msi_update_chip_ops(info);
info->flags |= MSI_FLAG_FREE_MSI_DESCS;
domain = msi_create_irq_domain(fwnode, info, parent); domain = msi_create_irq_domain(fwnode, info, parent);
if (domain) if (domain)
...@@ -60,50 +61,32 @@ struct irq_domain *ti_sci_inta_msi_create_irq_domain(struct fwnode_handle *fwnod ...@@ -60,50 +61,32 @@ struct irq_domain *ti_sci_inta_msi_create_irq_domain(struct fwnode_handle *fwnod
} }
EXPORT_SYMBOL_GPL(ti_sci_inta_msi_create_irq_domain); EXPORT_SYMBOL_GPL(ti_sci_inta_msi_create_irq_domain);
static void ti_sci_inta_msi_free_descs(struct device *dev)
{
struct msi_desc *desc, *tmp;
list_for_each_entry_safe(desc, tmp, dev_to_msi_list(dev), list) {
list_del(&desc->list);
free_msi_entry(desc);
}
}
static int ti_sci_inta_msi_alloc_descs(struct device *dev, static int ti_sci_inta_msi_alloc_descs(struct device *dev,
struct ti_sci_resource *res) struct ti_sci_resource *res)
{ {
struct msi_desc *msi_desc; struct msi_desc msi_desc;
int set, i, count = 0; int set, i, count = 0;
memset(&msi_desc, 0, sizeof(msi_desc));
msi_desc.nvec_used = 1;
for (set = 0; set < res->sets; set++) { for (set = 0; set < res->sets; set++) {
for (i = 0; i < res->desc[set].num; i++) { for (i = 0; i < res->desc[set].num; i++, count++) {
msi_desc = alloc_msi_entry(dev, 1, NULL); msi_desc.msi_index = res->desc[set].start + i;
if (!msi_desc) { if (msi_add_msi_desc(dev, &msi_desc))
ti_sci_inta_msi_free_descs(dev); goto fail;
return -ENOMEM;
}
msi_desc->msi_index = res->desc[set].start + i;
INIT_LIST_HEAD(&msi_desc->list);
list_add_tail(&msi_desc->list, dev_to_msi_list(dev));
count++;
} }
for (i = 0; i < res->desc[set].num_sec; i++) {
msi_desc = alloc_msi_entry(dev, 1, NULL); for (i = 0; i < res->desc[set].num_sec; i++, count++) {
if (!msi_desc) { msi_desc.msi_index = res->desc[set].start_sec + i;
ti_sci_inta_msi_free_descs(dev); if (msi_add_msi_desc(dev, &msi_desc))
return -ENOMEM; goto fail;
}
msi_desc->msi_index = res->desc[set].start_sec + i;
INIT_LIST_HEAD(&msi_desc->list);
list_add_tail(&msi_desc->list, dev_to_msi_list(dev));
count++;
} }
} }
return count; return count;
fail:
msi_free_msi_descs(dev);
return -ENOMEM;
} }
int ti_sci_inta_msi_domain_alloc_irqs(struct device *dev, int ti_sci_inta_msi_domain_alloc_irqs(struct device *dev,
...@@ -124,20 +107,18 @@ int ti_sci_inta_msi_domain_alloc_irqs(struct device *dev, ...@@ -124,20 +107,18 @@ int ti_sci_inta_msi_domain_alloc_irqs(struct device *dev,
if (ret) if (ret)
return ret; return ret;
msi_lock_descs(dev);
nvec = ti_sci_inta_msi_alloc_descs(dev, res); nvec = ti_sci_inta_msi_alloc_descs(dev, res);
if (nvec <= 0) if (nvec <= 0) {
return nvec; ret = nvec;
goto unlock;
ret = msi_domain_alloc_irqs(msi_domain, dev, nvec);
if (ret) {
dev_err(dev, "Failed to allocate IRQs %d\n", ret);
goto cleanup;
} }
return 0; ret = msi_domain_alloc_irqs_descs_locked(msi_domain, dev, nvec);
if (ret)
cleanup: dev_err(dev, "Failed to allocate IRQs %d\n", ret);
ti_sci_inta_msi_free_descs(&pdev->dev); unlock:
msi_unlock_descs(dev);
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(ti_sci_inta_msi_domain_alloc_irqs); EXPORT_SYMBOL_GPL(ti_sci_inta_msi_domain_alloc_irqs);
...@@ -145,6 +126,5 @@ EXPORT_SYMBOL_GPL(ti_sci_inta_msi_domain_alloc_irqs); ...@@ -145,6 +126,5 @@ EXPORT_SYMBOL_GPL(ti_sci_inta_msi_domain_alloc_irqs);
void ti_sci_inta_msi_domain_free_irqs(struct device *dev) void ti_sci_inta_msi_domain_free_irqs(struct device *dev)
{ {
msi_domain_free_irqs(dev->msi.domain, dev); msi_domain_free_irqs(dev->msi.domain, dev);
ti_sci_inta_msi_free_descs(dev);
} }
EXPORT_SYMBOL_GPL(ti_sci_inta_msi_domain_free_irqs); EXPORT_SYMBOL_GPL(ti_sci_inta_msi_domain_free_irqs);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment