blob: 4695c04320aebf3b01fb362b8958bb58cce160b6 [file] [log] [blame]
Thomas Gleixnerb886d83c2019-06-01 10:08:55 +02001// SPDX-License-Identifier: GPL-2.0-only
Michael Ellermana7de7c72007-05-08 12:58:36 +10002/*
3 * Copyright 2006-2007, Michael Ellerman, IBM Corporation.
Michael Ellermana7de7c72007-05-08 12:58:36 +10004 */
5
6#include <linux/irq.h>
Michael Ellermana7de7c72007-05-08 12:58:36 +10007#include <linux/bitmap.h>
8#include <linux/msi.h>
9#include <asm/mpic.h>
10#include <asm/prom.h>
11#include <asm/hw_irq.h>
12#include <asm/ppc-pci.h>
Michael Ellerman25235f72008-08-06 09:10:03 +100013#include <asm/msi_bitmap.h>
Michael Ellermana7de7c72007-05-08 12:58:36 +100014
Michael Ellerman8fa29d22008-05-08 14:27:11 +100015#include <sysdev/mpic.h>
Michael Ellermana7de7c72007-05-08 12:58:36 +100016
Michael Ellermana7de7c72007-05-08 12:58:36 +100017void mpic_msi_reserve_hwirq(struct mpic *mpic, irq_hw_number_t hwirq)
18{
Michael Ellermana7de7c72007-05-08 12:58:36 +100019 /* The mpic calls this even when there is no allocator setup */
Michael Ellerman25235f72008-08-06 09:10:03 +100020 if (!mpic->msi_bitmap.bitmap)
Michael Ellermana7de7c72007-05-08 12:58:36 +100021 return;
22
Michael Ellerman25235f72008-08-06 09:10:03 +100023 msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, hwirq);
Michael Ellermana7de7c72007-05-08 12:58:36 +100024}
25
26#ifdef CONFIG_MPIC_U3_HT_IRQS
27static int mpic_msi_reserve_u3_hwirqs(struct mpic *mpic)
28{
29 irq_hw_number_t hwirq;
Grant Likelya18dc812012-01-26 12:12:14 -070030 const struct irq_domain_ops *ops = mpic->irqhost->ops;
Michael Ellermana7de7c72007-05-08 12:58:36 +100031 struct device_node *np;
32 int flags, index, i;
Grant Likely530210c2013-09-15 16:39:11 +010033 struct of_phandle_args oirq;
Michael Ellermana7de7c72007-05-08 12:58:36 +100034
35 pr_debug("mpic: found U3, guessing msi allocator setup\n");
36
Benjamin Herrenschmidt7a96c6b2009-12-14 15:31:13 +000037 /* Reserve source numbers we know are reserved in the HW.
38 *
39 * This is a bit of a mix of U3 and U4 reserves but that's going
40 * to work fine, we have plenty enugh numbers left so let's just
41 * mark anything we don't like reserved.
42 */
Michael Ellermana7de7c72007-05-08 12:58:36 +100043 for (i = 0; i < 8; i++)
Michael Ellerman25235f72008-08-06 09:10:03 +100044 msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i);
Michael Ellermana7de7c72007-05-08 12:58:36 +100045
46 for (i = 42; i < 46; i++)
Michael Ellerman25235f72008-08-06 09:10:03 +100047 msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i);
Michael Ellermana7de7c72007-05-08 12:58:36 +100048
49 for (i = 100; i < 105; i++)
Michael Ellerman25235f72008-08-06 09:10:03 +100050 msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i);
Michael Ellermana7de7c72007-05-08 12:58:36 +100051
Kyle Moffett50196092011-12-22 10:19:12 +000052 for (i = 124; i < mpic->num_sources; i++)
Benjamin Herrenschmidt7a96c6b2009-12-14 15:31:13 +000053 msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i);
54
55
Michael Ellermana7de7c72007-05-08 12:58:36 +100056 np = NULL;
57 while ((np = of_find_all_nodes(np))) {
Rob Herringb7c670d2017-08-21 10:16:47 -050058 pr_debug("mpic: mapping hwirqs for %pOF\n", np);
Michael Ellermana7de7c72007-05-08 12:58:36 +100059
60 index = 0;
Grant Likely0c02c802013-09-19 11:22:36 -050061 while (of_irq_parse_one(np, index++, &oirq) == 0) {
Grant Likely530210c2013-09-15 16:39:11 +010062 ops->xlate(mpic->irqhost, NULL, oirq.args,
63 oirq.args_count, &hwirq, &flags);
Michael Ellerman25235f72008-08-06 09:10:03 +100064 msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, hwirq);
Michael Ellermana7de7c72007-05-08 12:58:36 +100065 }
66 }
67
68 return 0;
69}
70#else
71static int mpic_msi_reserve_u3_hwirqs(struct mpic *mpic)
72{
73 return -1;
74}
75#endif
76
Michael Ellermana7de7c72007-05-08 12:58:36 +100077int mpic_msi_init_allocator(struct mpic *mpic)
78{
Michael Ellerman25235f72008-08-06 09:10:03 +100079 int rc;
Michael Ellermana7de7c72007-05-08 12:58:36 +100080
Kyle Moffett50196092011-12-22 10:19:12 +000081 rc = msi_bitmap_alloc(&mpic->msi_bitmap, mpic->num_sources,
Marc Zyngier5d4c9bc2015-10-13 12:51:29 +010082 irq_domain_get_of_node(mpic->irqhost));
Michael Ellerman25235f72008-08-06 09:10:03 +100083 if (rc)
84 return rc;
Michael Ellermana7de7c72007-05-08 12:58:36 +100085
Michael Ellerman25235f72008-08-06 09:10:03 +100086 rc = msi_bitmap_reserve_dt_hwirqs(&mpic->msi_bitmap);
87 if (rc > 0) {
Michael Ellermana7de7c72007-05-08 12:58:36 +100088 if (mpic->flags & MPIC_U3_HT_IRQS)
89 rc = mpic_msi_reserve_u3_hwirqs(mpic);
90
Michael Ellerman25235f72008-08-06 09:10:03 +100091 if (rc) {
92 msi_bitmap_free(&mpic->msi_bitmap);
93 return rc;
94 }
Michael Ellermana7de7c72007-05-08 12:58:36 +100095 }
96
97 return 0;
Michael Ellermana7de7c72007-05-08 12:58:36 +100098}