Thomas Gleixner | b886d83c | 2019-06-01 10:08:55 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2006-2007, Michael Ellerman, IBM Corporation. |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <linux/irq.h> |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 7 | #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 Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 13 | #include <asm/msi_bitmap.h> |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 14 | |
Michael Ellerman | 8fa29d2 | 2008-05-08 14:27:11 +1000 | [diff] [blame] | 15 | #include <sysdev/mpic.h> |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 16 | |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 17 | void mpic_msi_reserve_hwirq(struct mpic *mpic, irq_hw_number_t hwirq) |
| 18 | { |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 19 | /* The mpic calls this even when there is no allocator setup */ |
Michael Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 20 | if (!mpic->msi_bitmap.bitmap) |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 21 | return; |
| 22 | |
Michael Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 23 | msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, hwirq); |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | #ifdef CONFIG_MPIC_U3_HT_IRQS |
| 27 | static int mpic_msi_reserve_u3_hwirqs(struct mpic *mpic) |
| 28 | { |
| 29 | irq_hw_number_t hwirq; |
Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 30 | const struct irq_domain_ops *ops = mpic->irqhost->ops; |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 31 | struct device_node *np; |
| 32 | int flags, index, i; |
Grant Likely | 530210c | 2013-09-15 16:39:11 +0100 | [diff] [blame] | 33 | struct of_phandle_args oirq; |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 34 | |
| 35 | pr_debug("mpic: found U3, guessing msi allocator setup\n"); |
| 36 | |
Benjamin Herrenschmidt | 7a96c6b | 2009-12-14 15:31:13 +0000 | [diff] [blame] | 37 | /* 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 Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 43 | for (i = 0; i < 8; i++) |
Michael Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 44 | msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i); |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 45 | |
| 46 | for (i = 42; i < 46; i++) |
Michael Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 47 | msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i); |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 48 | |
| 49 | for (i = 100; i < 105; i++) |
Michael Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 50 | msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i); |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 51 | |
Kyle Moffett | 5019609 | 2011-12-22 10:19:12 +0000 | [diff] [blame] | 52 | for (i = 124; i < mpic->num_sources; i++) |
Benjamin Herrenschmidt | 7a96c6b | 2009-12-14 15:31:13 +0000 | [diff] [blame] | 53 | msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i); |
| 54 | |
| 55 | |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 56 | np = NULL; |
| 57 | while ((np = of_find_all_nodes(np))) { |
Rob Herring | b7c670d | 2017-08-21 10:16:47 -0500 | [diff] [blame] | 58 | pr_debug("mpic: mapping hwirqs for %pOF\n", np); |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 59 | |
| 60 | index = 0; |
Grant Likely | 0c02c80 | 2013-09-19 11:22:36 -0500 | [diff] [blame] | 61 | while (of_irq_parse_one(np, index++, &oirq) == 0) { |
Grant Likely | 530210c | 2013-09-15 16:39:11 +0100 | [diff] [blame] | 62 | ops->xlate(mpic->irqhost, NULL, oirq.args, |
| 63 | oirq.args_count, &hwirq, &flags); |
Michael Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 64 | msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, hwirq); |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 65 | } |
| 66 | } |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | #else |
| 71 | static int mpic_msi_reserve_u3_hwirqs(struct mpic *mpic) |
| 72 | { |
| 73 | return -1; |
| 74 | } |
| 75 | #endif |
| 76 | |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 77 | int mpic_msi_init_allocator(struct mpic *mpic) |
| 78 | { |
Michael Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 79 | int rc; |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 80 | |
Kyle Moffett | 5019609 | 2011-12-22 10:19:12 +0000 | [diff] [blame] | 81 | rc = msi_bitmap_alloc(&mpic->msi_bitmap, mpic->num_sources, |
Marc Zyngier | 5d4c9bc | 2015-10-13 12:51:29 +0100 | [diff] [blame] | 82 | irq_domain_get_of_node(mpic->irqhost)); |
Michael Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 83 | if (rc) |
| 84 | return rc; |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 85 | |
Michael Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 86 | rc = msi_bitmap_reserve_dt_hwirqs(&mpic->msi_bitmap); |
| 87 | if (rc > 0) { |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 88 | if (mpic->flags & MPIC_U3_HT_IRQS) |
| 89 | rc = mpic_msi_reserve_u3_hwirqs(mpic); |
| 90 | |
Michael Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 91 | if (rc) { |
| 92 | msi_bitmap_free(&mpic->msi_bitmap); |
| 93 | return rc; |
| 94 | } |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | return 0; |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 98 | } |