2019-06-01 16:08:55 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2007-05-08 10:58:36 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2006-2007, Michael Ellerman, IBM Corporation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/irq.h>
|
|
|
|
#include <linux/bitmap.h>
|
|
|
|
#include <linux/msi.h>
|
|
|
|
#include <asm/mpic.h>
|
|
|
|
#include <asm/prom.h>
|
|
|
|
#include <asm/hw_irq.h>
|
|
|
|
#include <asm/ppc-pci.h>
|
2008-08-06 07:10:03 +08:00
|
|
|
#include <asm/msi_bitmap.h>
|
2007-05-08 10:58:36 +08:00
|
|
|
|
2008-05-08 12:27:11 +08:00
|
|
|
#include <sysdev/mpic.h>
|
2007-05-08 10:58:36 +08:00
|
|
|
|
|
|
|
void mpic_msi_reserve_hwirq(struct mpic *mpic, irq_hw_number_t hwirq)
|
|
|
|
{
|
|
|
|
/* The mpic calls this even when there is no allocator setup */
|
2008-08-06 07:10:03 +08:00
|
|
|
if (!mpic->msi_bitmap.bitmap)
|
2007-05-08 10:58:36 +08:00
|
|
|
return;
|
|
|
|
|
2008-08-06 07:10:03 +08:00
|
|
|
msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, hwirq);
|
2007-05-08 10:58:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_MPIC_U3_HT_IRQS
|
|
|
|
static int mpic_msi_reserve_u3_hwirqs(struct mpic *mpic)
|
|
|
|
{
|
|
|
|
irq_hw_number_t hwirq;
|
2012-01-27 03:12:14 +08:00
|
|
|
const struct irq_domain_ops *ops = mpic->irqhost->ops;
|
2007-05-08 10:58:36 +08:00
|
|
|
struct device_node *np;
|
|
|
|
int flags, index, i;
|
2013-09-15 23:39:11 +08:00
|
|
|
struct of_phandle_args oirq;
|
2007-05-08 10:58:36 +08:00
|
|
|
|
|
|
|
pr_debug("mpic: found U3, guessing msi allocator setup\n");
|
|
|
|
|
2009-12-14 23:31:13 +08:00
|
|
|
/* Reserve source numbers we know are reserved in the HW.
|
|
|
|
*
|
|
|
|
* This is a bit of a mix of U3 and U4 reserves but that's going
|
|
|
|
* to work fine, we have plenty enugh numbers left so let's just
|
|
|
|
* mark anything we don't like reserved.
|
|
|
|
*/
|
2007-05-08 10:58:36 +08:00
|
|
|
for (i = 0; i < 8; i++)
|
2008-08-06 07:10:03 +08:00
|
|
|
msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i);
|
2007-05-08 10:58:36 +08:00
|
|
|
|
|
|
|
for (i = 42; i < 46; i++)
|
2008-08-06 07:10:03 +08:00
|
|
|
msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i);
|
2007-05-08 10:58:36 +08:00
|
|
|
|
|
|
|
for (i = 100; i < 105; i++)
|
2008-08-06 07:10:03 +08:00
|
|
|
msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i);
|
2007-05-08 10:58:36 +08:00
|
|
|
|
2011-12-22 18:19:12 +08:00
|
|
|
for (i = 124; i < mpic->num_sources; i++)
|
2009-12-14 23:31:13 +08:00
|
|
|
msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i);
|
|
|
|
|
|
|
|
|
2007-05-08 10:58:36 +08:00
|
|
|
np = NULL;
|
|
|
|
while ((np = of_find_all_nodes(np))) {
|
2017-08-21 23:16:47 +08:00
|
|
|
pr_debug("mpic: mapping hwirqs for %pOF\n", np);
|
2007-05-08 10:58:36 +08:00
|
|
|
|
|
|
|
index = 0;
|
2013-09-20 00:22:36 +08:00
|
|
|
while (of_irq_parse_one(np, index++, &oirq) == 0) {
|
2013-09-15 23:39:11 +08:00
|
|
|
ops->xlate(mpic->irqhost, NULL, oirq.args,
|
|
|
|
oirq.args_count, &hwirq, &flags);
|
2008-08-06 07:10:03 +08:00
|
|
|
msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, hwirq);
|
2007-05-08 10:58:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static int mpic_msi_reserve_u3_hwirqs(struct mpic *mpic)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int mpic_msi_init_allocator(struct mpic *mpic)
|
|
|
|
{
|
2008-08-06 07:10:03 +08:00
|
|
|
int rc;
|
2007-05-08 10:58:36 +08:00
|
|
|
|
2011-12-22 18:19:12 +08:00
|
|
|
rc = msi_bitmap_alloc(&mpic->msi_bitmap, mpic->num_sources,
|
2015-10-13 19:51:29 +08:00
|
|
|
irq_domain_get_of_node(mpic->irqhost));
|
2008-08-06 07:10:03 +08:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
2007-05-08 10:58:36 +08:00
|
|
|
|
2008-08-06 07:10:03 +08:00
|
|
|
rc = msi_bitmap_reserve_dt_hwirqs(&mpic->msi_bitmap);
|
|
|
|
if (rc > 0) {
|
2007-05-08 10:58:36 +08:00
|
|
|
if (mpic->flags & MPIC_U3_HT_IRQS)
|
|
|
|
rc = mpic_msi_reserve_u3_hwirqs(mpic);
|
|
|
|
|
2008-08-06 07:10:03 +08:00
|
|
|
if (rc) {
|
|
|
|
msi_bitmap_free(&mpic->msi_bitmap);
|
|
|
|
return rc;
|
|
|
|
}
|
2007-05-08 10:58:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|