Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 1 | /* |
| 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 Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 12 | #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 Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 18 | #include <asm/msi_bitmap.h> |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 19 | |
Michael Ellerman | 8fa29d2 | 2008-05-08 14:27:11 +1000 | [diff] [blame] | 20 | #include <sysdev/mpic.h> |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 21 | |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 22 | void mpic_msi_reserve_hwirq(struct mpic *mpic, irq_hw_number_t hwirq) |
| 23 | { |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 24 | /* The mpic calls this even when there is no allocator setup */ |
Michael Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 25 | if (!mpic->msi_bitmap.bitmap) |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 26 | return; |
| 27 | |
Michael Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 28 | msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, hwirq); |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | #ifdef CONFIG_MPIC_U3_HT_IRQS |
| 32 | static int mpic_msi_reserve_u3_hwirqs(struct mpic *mpic) |
| 33 | { |
| 34 | irq_hw_number_t hwirq; |
Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 35 | const struct irq_domain_ops *ops = mpic->irqhost->ops; |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 36 | struct device_node *np; |
| 37 | int flags, index, i; |
| 38 | struct of_irq oirq; |
| 39 | |
| 40 | pr_debug("mpic: found U3, guessing msi allocator setup\n"); |
| 41 | |
Benjamin Herrenschmidt | 7a96c6b | 2009-12-14 15:31:13 +0000 | [diff] [blame] | 42 | /* 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 Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 48 | for (i = 0; i < 8; i++) |
Michael Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 49 | msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i); |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 50 | |
| 51 | for (i = 42; i < 46; i++) |
Michael Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 52 | msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i); |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 53 | |
| 54 | for (i = 100; i < 105; i++) |
Michael Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 55 | msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i); |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 56 | |
Kyle Moffett | 5019609 | 2011-12-22 10:19:12 +0000 | [diff] [blame] | 57 | for (i = 124; i < mpic->num_sources; i++) |
Benjamin Herrenschmidt | 7a96c6b | 2009-12-14 15:31:13 +0000 | [diff] [blame] | 58 | msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i); |
| 59 | |
| 60 | |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 61 | 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; |
| 66 | while (of_irq_map_one(np, index++, &oirq) == 0) { |
| 67 | ops->xlate(mpic->irqhost, NULL, oirq.specifier, |
| 68 | oirq.size, &hwirq, &flags); |
Michael Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 69 | msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, hwirq); |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | #else |
| 76 | static int mpic_msi_reserve_u3_hwirqs(struct mpic *mpic) |
| 77 | { |
| 78 | return -1; |
| 79 | } |
| 80 | #endif |
| 81 | |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 82 | int mpic_msi_init_allocator(struct mpic *mpic) |
| 83 | { |
Michael Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 84 | int rc; |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 85 | |
Kyle Moffett | 5019609 | 2011-12-22 10:19:12 +0000 | [diff] [blame] | 86 | rc = msi_bitmap_alloc(&mpic->msi_bitmap, mpic->num_sources, |
Michael Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 87 | mpic->irqhost->of_node); |
| 88 | if (rc) |
| 89 | return rc; |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 90 | |
Michael Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 91 | rc = msi_bitmap_reserve_dt_hwirqs(&mpic->msi_bitmap); |
| 92 | if (rc > 0) { |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 93 | if (mpic->flags & MPIC_U3_HT_IRQS) |
| 94 | rc = mpic_msi_reserve_u3_hwirqs(mpic); |
| 95 | |
Michael Ellerman | 25235f7 | 2008-08-06 09:10:03 +1000 | [diff] [blame] | 96 | if (rc) { |
| 97 | msi_bitmap_free(&mpic->msi_bitmap); |
| 98 | return rc; |
| 99 | } |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | return 0; |
Michael Ellerman | a7de7c7 | 2007-05-08 12:58:36 +1000 | [diff] [blame] | 103 | } |