blob: 1d48a5385905a8ce96290f10064546a39efed403 [file] [log] [blame]
Michael Ellermana7de7c72007-05-08 12:58:36 +10001/*
2 * Copyright 2006-2007, Michael Ellerman, IBM Corporation.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; version 2 of the
7 * License.
8 *
9 */
10
11#include <linux/irq.h>
Michael Ellermana7de7c72007-05-08 12:58:36 +100012#include <linux/bitmap.h>
13#include <linux/msi.h>
14#include <asm/mpic.h>
15#include <asm/prom.h>
16#include <asm/hw_irq.h>
17#include <asm/ppc-pci.h>
Michael Ellerman25235f72008-08-06 09:10:03 +100018#include <asm/msi_bitmap.h>
Michael Ellermana7de7c72007-05-08 12:58:36 +100019
Michael Ellerman8fa29d22008-05-08 14:27:11 +100020#include <sysdev/mpic.h>
Michael Ellermana7de7c72007-05-08 12:58:36 +100021
Michael Ellermana7de7c72007-05-08 12:58:36 +100022void mpic_msi_reserve_hwirq(struct mpic *mpic, irq_hw_number_t hwirq)
23{
Michael Ellermana7de7c72007-05-08 12:58:36 +100024 /* The mpic calls this even when there is no allocator setup */
Michael Ellerman25235f72008-08-06 09:10:03 +100025 if (!mpic->msi_bitmap.bitmap)
Michael Ellermana7de7c72007-05-08 12:58:36 +100026 return;
27
Michael Ellerman25235f72008-08-06 09:10:03 +100028 msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, hwirq);
Michael Ellermana7de7c72007-05-08 12:58:36 +100029}
30
31#ifdef CONFIG_MPIC_U3_HT_IRQS
32static int mpic_msi_reserve_u3_hwirqs(struct mpic *mpic)
33{
34 irq_hw_number_t hwirq;
Grant Likelya18dc812012-01-26 12:12:14 -070035 const struct irq_domain_ops *ops = mpic->irqhost->ops;
Michael Ellermana7de7c72007-05-08 12:58:36 +100036 struct device_node *np;
37 int flags, index, i;
Grant Likely530210c2013-09-15 16:39:11 +010038 struct of_phandle_args oirq;
Michael Ellermana7de7c72007-05-08 12:58:36 +100039
40 pr_debug("mpic: found U3, guessing msi allocator setup\n");
41
Benjamin Herrenschmidt7a96c6b2009-12-14 15:31:13 +000042 /* Reserve source numbers we know are reserved in the HW.
43 *
44 * This is a bit of a mix of U3 and U4 reserves but that's going
45 * to work fine, we have plenty enugh numbers left so let's just
46 * mark anything we don't like reserved.
47 */
Michael Ellermana7de7c72007-05-08 12:58:36 +100048 for (i = 0; i < 8; i++)
Michael Ellerman25235f72008-08-06 09:10:03 +100049 msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i);
Michael Ellermana7de7c72007-05-08 12:58:36 +100050
51 for (i = 42; i < 46; i++)
Michael Ellerman25235f72008-08-06 09:10:03 +100052 msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i);
Michael Ellermana7de7c72007-05-08 12:58:36 +100053
54 for (i = 100; i < 105; i++)
Michael Ellerman25235f72008-08-06 09:10:03 +100055 msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i);
Michael Ellermana7de7c72007-05-08 12:58:36 +100056
Kyle Moffett50196092011-12-22 10:19:12 +000057 for (i = 124; i < mpic->num_sources; i++)
Benjamin Herrenschmidt7a96c6b2009-12-14 15:31:13 +000058 msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i);
59
60
Michael Ellermana7de7c72007-05-08 12:58:36 +100061 np = NULL;
62 while ((np = of_find_all_nodes(np))) {
63 pr_debug("mpic: mapping hwirqs for %s\n", np->full_name);
64
65 index = 0;
Grant Likely0c02c802013-09-19 11:22:36 -050066 while (of_irq_parse_one(np, index++, &oirq) == 0) {
Grant Likely530210c2013-09-15 16:39:11 +010067 ops->xlate(mpic->irqhost, NULL, oirq.args,
68 oirq.args_count, &hwirq, &flags);
Michael Ellerman25235f72008-08-06 09:10:03 +100069 msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, hwirq);
Michael Ellermana7de7c72007-05-08 12:58:36 +100070 }
71 }
72
73 return 0;
74}
75#else
76static int mpic_msi_reserve_u3_hwirqs(struct mpic *mpic)
77{
78 return -1;
79}
80#endif
81
Michael Ellermana7de7c72007-05-08 12:58:36 +100082int mpic_msi_init_allocator(struct mpic *mpic)
83{
Michael Ellerman25235f72008-08-06 09:10:03 +100084 int rc;
Michael Ellermana7de7c72007-05-08 12:58:36 +100085
Kyle Moffett50196092011-12-22 10:19:12 +000086 rc = msi_bitmap_alloc(&mpic->msi_bitmap, mpic->num_sources,
Marc Zyngier5d4c9bc2015-10-13 12:51:29 +010087 irq_domain_get_of_node(mpic->irqhost));
Michael Ellerman25235f72008-08-06 09:10:03 +100088 if (rc)
89 return rc;
Michael Ellermana7de7c72007-05-08 12:58:36 +100090
Michael Ellerman25235f72008-08-06 09:10:03 +100091 rc = msi_bitmap_reserve_dt_hwirqs(&mpic->msi_bitmap);
92 if (rc > 0) {
Michael Ellermana7de7c72007-05-08 12:58:36 +100093 if (mpic->flags & MPIC_U3_HT_IRQS)
94 rc = mpic_msi_reserve_u3_hwirqs(mpic);
95
Michael Ellerman25235f72008-08-06 09:10:03 +100096 if (rc) {
97 msi_bitmap_free(&mpic->msi_bitmap);
98 return rc;
99 }
Michael Ellermana7de7c72007-05-08 12:58:36 +1000100 }
101
102 return 0;
Michael Ellermana7de7c72007-05-08 12:58:36 +1000103}