Commit f21a8b1b authored by Thomas Petazzoni's avatar Thomas Petazzoni Committed by Bjorn Helgaas

PCI: aardvark: Move to MSI handling using generic MSI support

The MSI support introduced with the initial Aardvark driver was based
on the msi_controller structure and the of_pci_msi_chip_add() /
of_pci_find_msi_chip_by_node() API, which are being deprecated in
favor of the generic MSI support.

Update the Aardvark driver to use the generic MSI support.
Signed-off-by: default avatarThomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Acked-by: default avatarMarc Zyngier <marc.zyngier@arm.com>
parent 688769f6
...@@ -200,10 +200,12 @@ struct advk_pcie { ...@@ -200,10 +200,12 @@ struct advk_pcie {
struct list_head resources; struct list_head resources;
struct irq_domain *irq_domain; struct irq_domain *irq_domain;
struct irq_chip irq_chip; struct irq_chip irq_chip;
struct msi_controller msi;
struct irq_domain *msi_domain; struct irq_domain *msi_domain;
struct irq_domain *msi_inner_domain;
struct irq_chip msi_bottom_irq_chip;
struct irq_chip msi_irq_chip; struct irq_chip msi_irq_chip;
DECLARE_BITMAP(msi_irq_in_use, MSI_IRQ_NUM); struct msi_domain_info msi_domain_info;
DECLARE_BITMAP(msi_used, MSI_IRQ_NUM);
struct mutex msi_used_lock; struct mutex msi_used_lock;
u16 msi_msg; u16 msi_msg;
int root_bus_nr; int root_bus_nr;
...@@ -545,94 +547,64 @@ static struct pci_ops advk_pcie_ops = { ...@@ -545,94 +547,64 @@ static struct pci_ops advk_pcie_ops = {
.write = advk_pcie_wr_conf, .write = advk_pcie_wr_conf,
}; };
static int advk_pcie_alloc_msi(struct advk_pcie *pcie) static void advk_msi_irq_compose_msi_msg(struct irq_data *data,
struct msi_msg *msg)
{ {
int hwirq; struct advk_pcie *pcie = irq_data_get_irq_chip_data(data);
phys_addr_t msi_msg = virt_to_phys(&pcie->msi_msg);
mutex_lock(&pcie->msi_used_lock); msg->address_lo = lower_32_bits(msi_msg);
hwirq = find_first_zero_bit(pcie->msi_irq_in_use, MSI_IRQ_NUM); msg->address_hi = upper_32_bits(msi_msg);
if (hwirq >= MSI_IRQ_NUM) msg->data = data->irq;
hwirq = -ENOSPC;
else
set_bit(hwirq, pcie->msi_irq_in_use);
mutex_unlock(&pcie->msi_used_lock);
return hwirq;
} }
static void advk_pcie_free_msi(struct advk_pcie *pcie, int hwirq) static int advk_msi_set_affinity(struct irq_data *irq_data,
const struct cpumask *mask, bool force)
{ {
struct device *dev = &pcie->pdev->dev; return -EINVAL;
mutex_lock(&pcie->msi_used_lock);
if (!test_bit(hwirq, pcie->msi_irq_in_use))
dev_err(dev, "trying to free unused MSI#%d\n", hwirq);
else
clear_bit(hwirq, pcie->msi_irq_in_use);
mutex_unlock(&pcie->msi_used_lock);
} }
static int advk_pcie_setup_msi_irq(struct msi_controller *chip, static int advk_msi_irq_domain_alloc(struct irq_domain *domain,
struct pci_dev *pdev, unsigned int virq,
struct msi_desc *desc) unsigned int nr_irqs, void *args)
{ {
struct advk_pcie *pcie = pdev->bus->sysdata; struct advk_pcie *pcie = domain->host_data;
struct msi_msg msg; int hwirq, i;
int virq, hwirq;
phys_addr_t msi_msg_phys;
/* We support MSI, but not MSI-X */
if (desc->msi_attrib.is_msix)
return -EINVAL;
hwirq = advk_pcie_alloc_msi(pcie);
if (hwirq < 0)
return hwirq;
virq = irq_create_mapping(pcie->msi_domain, hwirq); mutex_lock(&pcie->msi_used_lock);
if (!virq) { hwirq = bitmap_find_next_zero_area(pcie->msi_used, MSI_IRQ_NUM,
advk_pcie_free_msi(pcie, hwirq); 0, nr_irqs, 0);
return -EINVAL; if (hwirq >= MSI_IRQ_NUM) {
mutex_unlock(&pcie->msi_used_lock);
return -ENOSPC;
} }
irq_set_msi_desc(virq, desc); bitmap_set(pcie->msi_used, hwirq, nr_irqs);
mutex_unlock(&pcie->msi_used_lock);
msi_msg_phys = virt_to_phys(&pcie->msi_msg);
msg.address_lo = lower_32_bits(msi_msg_phys);
msg.address_hi = upper_32_bits(msi_msg_phys);
msg.data = virq;
pci_write_msi_msg(virq, &msg);
return 0;
}
static void advk_pcie_teardown_msi_irq(struct msi_controller *chip, for (i = 0; i < nr_irqs; i++)
unsigned int irq) irq_domain_set_info(domain, virq + i, hwirq + i,
{ &pcie->msi_bottom_irq_chip,
struct irq_data *d = irq_get_irq_data(irq); domain->host_data, handle_simple_irq,
struct msi_desc *msi = irq_data_get_msi_desc(d); NULL, NULL);
struct advk_pcie *pcie = msi_desc_to_pci_sysdata(msi);
unsigned long hwirq = d->hwirq;
irq_dispose_mapping(irq); return hwirq;
advk_pcie_free_msi(pcie, hwirq);
} }
static int advk_pcie_msi_map(struct irq_domain *domain, static void advk_msi_irq_domain_free(struct irq_domain *domain,
unsigned int virq, irq_hw_number_t hw) unsigned int virq, unsigned int nr_irqs)
{ {
struct irq_data *d = irq_domain_get_irq_data(domain, virq);
struct advk_pcie *pcie = domain->host_data; struct advk_pcie *pcie = domain->host_data;
irq_set_chip_and_handler(virq, &pcie->msi_irq_chip, mutex_lock(&pcie->msi_used_lock);
handle_simple_irq); bitmap_clear(pcie->msi_used, d->hwirq, nr_irqs);
mutex_unlock(&pcie->msi_used_lock);
return 0;
} }
static const struct irq_domain_ops advk_pcie_msi_irq_ops = { static const struct irq_domain_ops advk_msi_domain_ops = {
.map = advk_pcie_msi_map, .alloc = advk_msi_irq_domain_alloc,
.free = advk_msi_irq_domain_free,
}; };
static void advk_pcie_irq_mask(struct irq_data *d) static void advk_pcie_irq_mask(struct irq_data *d)
...@@ -680,30 +652,25 @@ static int advk_pcie_init_msi_irq_domain(struct advk_pcie *pcie) ...@@ -680,30 +652,25 @@ static int advk_pcie_init_msi_irq_domain(struct advk_pcie *pcie)
{ {
struct device *dev = &pcie->pdev->dev; struct device *dev = &pcie->pdev->dev;
struct device_node *node = dev->of_node; struct device_node *node = dev->of_node;
struct irq_chip *msi_irq_chip; struct irq_chip *bottom_ic, *msi_ic;
struct msi_controller *msi; struct msi_domain_info *msi_di;
phys_addr_t msi_msg_phys; phys_addr_t msi_msg_phys;
int ret;
msi_irq_chip = &pcie->msi_irq_chip;
msi_irq_chip->name = devm_kasprintf(dev, GFP_KERNEL, "%s-msi", mutex_init(&pcie->msi_used_lock);
dev_name(dev));
if (!msi_irq_chip->name)
return -ENOMEM;
msi_irq_chip->irq_enable = pci_msi_unmask_irq; bottom_ic = &pcie->msi_bottom_irq_chip;
msi_irq_chip->irq_disable = pci_msi_mask_irq;
msi_irq_chip->irq_mask = pci_msi_mask_irq;
msi_irq_chip->irq_unmask = pci_msi_unmask_irq;
msi = &pcie->msi; bottom_ic->name = "MSI";
bottom_ic->irq_compose_msi_msg = advk_msi_irq_compose_msi_msg;
bottom_ic->irq_set_affinity = advk_msi_set_affinity;
msi->setup_irq = advk_pcie_setup_msi_irq; msi_ic = &pcie->msi_irq_chip;
msi->teardown_irq = advk_pcie_teardown_msi_irq; msi_ic->name = "advk-MSI";
msi->of_node = node;
mutex_init(&pcie->msi_used_lock); msi_di = &pcie->msi_domain_info;
msi_di->flags = MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS |
MSI_FLAG_MULTI_PCI_MSI;
msi_di->chip = msi_ic;
msi_msg_phys = virt_to_phys(&pcie->msi_msg); msi_msg_phys = virt_to_phys(&pcie->msi_msg);
...@@ -712,16 +679,18 @@ static int advk_pcie_init_msi_irq_domain(struct advk_pcie *pcie) ...@@ -712,16 +679,18 @@ static int advk_pcie_init_msi_irq_domain(struct advk_pcie *pcie)
advk_writel(pcie, upper_32_bits(msi_msg_phys), advk_writel(pcie, upper_32_bits(msi_msg_phys),
PCIE_MSI_ADDR_HIGH_REG); PCIE_MSI_ADDR_HIGH_REG);
pcie->msi_domain = pcie->msi_inner_domain =
irq_domain_add_linear(NULL, MSI_IRQ_NUM, irq_domain_add_linear(NULL, MSI_IRQ_NUM,
&advk_pcie_msi_irq_ops, pcie); &advk_msi_domain_ops, pcie);
if (!pcie->msi_domain) if (!pcie->msi_inner_domain)
return -ENOMEM; return -ENOMEM;
ret = of_pci_msi_chip_add(msi); pcie->msi_domain =
if (ret < 0) { pci_msi_create_irq_domain(of_node_to_fwnode(node),
irq_domain_remove(pcie->msi_domain); msi_di, pcie->msi_inner_domain);
return ret; if (!pcie->msi_domain) {
irq_domain_remove(pcie->msi_inner_domain);
return -ENOMEM;
} }
return 0; return 0;
...@@ -729,8 +698,8 @@ static int advk_pcie_init_msi_irq_domain(struct advk_pcie *pcie) ...@@ -729,8 +698,8 @@ static int advk_pcie_init_msi_irq_domain(struct advk_pcie *pcie)
static void advk_pcie_remove_msi_irq_domain(struct advk_pcie *pcie) static void advk_pcie_remove_msi_irq_domain(struct advk_pcie *pcie)
{ {
of_pci_msi_chip_remove(&pcie->msi);
irq_domain_remove(pcie->msi_domain); irq_domain_remove(pcie->msi_domain);
irq_domain_remove(pcie->msi_inner_domain);
} }
static int advk_pcie_init_irq_domain(struct advk_pcie *pcie) static int advk_pcie_init_irq_domain(struct advk_pcie *pcie)
...@@ -917,8 +886,6 @@ static int advk_pcie_probe(struct platform_device *pdev) ...@@ -917,8 +886,6 @@ static int advk_pcie_probe(struct platform_device *pdev)
struct advk_pcie *pcie; struct advk_pcie *pcie;
struct resource *res; struct resource *res;
struct pci_bus *bus, *child; struct pci_bus *bus, *child;
struct msi_controller *msi;
struct device_node *msi_node;
int ret, irq; int ret, irq;
pcie = devm_kzalloc(dev, sizeof(struct advk_pcie), GFP_KERNEL); pcie = devm_kzalloc(dev, sizeof(struct advk_pcie), GFP_KERNEL);
...@@ -962,14 +929,8 @@ static int advk_pcie_probe(struct platform_device *pdev) ...@@ -962,14 +929,8 @@ static int advk_pcie_probe(struct platform_device *pdev)
return ret; return ret;
} }
msi_node = of_parse_phandle(dev->of_node, "msi-parent", 0); bus = pci_scan_root_bus(dev, 0, &advk_pcie_ops,
if (msi_node) pcie, &pcie->resources);
msi = of_pci_find_msi_chip_by_node(msi_node);
else
msi = NULL;
bus = pci_scan_root_bus_msi(dev, 0, &advk_pcie_ops,
pcie, &pcie->resources, &pcie->msi);
if (!bus) { if (!bus) {
advk_pcie_remove_msi_irq_domain(pcie); advk_pcie_remove_msi_irq_domain(pcie);
advk_pcie_remove_irq_domain(pcie); advk_pcie_remove_irq_domain(pcie);
......
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