blob: 1d44eee80fa1275c5527967a4edf3a57f5f53f7f [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;
35 struct irq_host_ops *ops = mpic->irqhost->ops;
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
42 /* Reserve source numbers we know are reserved in the HW */
43 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
52 np = NULL;
53 while ((np = of_find_all_nodes(np))) {
54 pr_debug("mpic: mapping hwirqs for %s\n", np->full_name);
55
56 index = 0;
57 while (of_irq_map_one(np, index++, &oirq) == 0) {
58 ops->xlate(mpic->irqhost, NULL, oirq.specifier,
59 oirq.size, &hwirq, &flags);
Michael Ellerman25235f72008-08-06 09:10:03 +100060 msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, hwirq);
Michael Ellermana7de7c72007-05-08 12:58:36 +100061 }
62 }
63
64 return 0;
65}
66#else
67static int mpic_msi_reserve_u3_hwirqs(struct mpic *mpic)
68{
69 return -1;
70}
71#endif
72
Michael Ellermana7de7c72007-05-08 12:58:36 +100073int mpic_msi_init_allocator(struct mpic *mpic)
74{
Michael Ellerman25235f72008-08-06 09:10:03 +100075 int rc;
Michael Ellermana7de7c72007-05-08 12:58:36 +100076
Michael Ellerman25235f72008-08-06 09:10:03 +100077 rc = msi_bitmap_alloc(&mpic->msi_bitmap, mpic->irq_count,
78 mpic->irqhost->of_node);
79 if (rc)
80 return rc;
Michael Ellermana7de7c72007-05-08 12:58:36 +100081
Michael Ellerman25235f72008-08-06 09:10:03 +100082 rc = msi_bitmap_reserve_dt_hwirqs(&mpic->msi_bitmap);
83 if (rc > 0) {
Michael Ellermana7de7c72007-05-08 12:58:36 +100084 if (mpic->flags & MPIC_U3_HT_IRQS)
85 rc = mpic_msi_reserve_u3_hwirqs(mpic);
86
Michael Ellerman25235f72008-08-06 09:10:03 +100087 if (rc) {
88 msi_bitmap_free(&mpic->msi_bitmap);
89 return rc;
90 }
Michael Ellermana7de7c72007-05-08 12:58:36 +100091 }
92
93 return 0;
Michael Ellermana7de7c72007-05-08 12:58:36 +100094}