2 * Copyright 2006-2007, Michael Ellerman, IBM Corporation.
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
11 #include <linux/irq.h>
12 #include <linux/bitmap.h>
13 #include <linux/msi.h>
16 #include <asm/hw_irq.h>
17 #include <asm/ppc-pci.h>
18 #include <asm/msi_bitmap.h>
20 #include <sysdev/mpic.h>
22 void mpic_msi_reserve_hwirq(struct mpic
*mpic
, irq_hw_number_t hwirq
)
24 /* The mpic calls this even when there is no allocator setup */
25 if (!mpic
->msi_bitmap
.bitmap
)
28 msi_bitmap_reserve_hwirq(&mpic
->msi_bitmap
, hwirq
);
31 #ifdef CONFIG_MPIC_U3_HT_IRQS
32 static int mpic_msi_reserve_u3_hwirqs(struct mpic
*mpic
)
34 irq_hw_number_t hwirq
;
35 const struct irq_domain_ops
*ops
= mpic
->irqhost
->ops
;
36 struct device_node
*np
;
38 struct of_phandle_args oirq
;
40 pr_debug("mpic: found U3, guessing msi allocator setup\n");
42 /* Reserve source numbers we know are reserved in the HW.
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.
48 for (i
= 0; i
< 8; i
++)
49 msi_bitmap_reserve_hwirq(&mpic
->msi_bitmap
, i
);
51 for (i
= 42; i
< 46; i
++)
52 msi_bitmap_reserve_hwirq(&mpic
->msi_bitmap
, i
);
54 for (i
= 100; i
< 105; i
++)
55 msi_bitmap_reserve_hwirq(&mpic
->msi_bitmap
, i
);
57 for (i
= 124; i
< mpic
->num_sources
; i
++)
58 msi_bitmap_reserve_hwirq(&mpic
->msi_bitmap
, i
);
62 while ((np
= of_find_all_nodes(np
))) {
63 pr_debug("mpic: mapping hwirqs for %s\n", np
->full_name
);
66 while (of_irq_parse_one(np
, index
++, &oirq
) == 0) {
67 ops
->xlate(mpic
->irqhost
, NULL
, oirq
.args
,
68 oirq
.args_count
, &hwirq
, &flags
);
69 msi_bitmap_reserve_hwirq(&mpic
->msi_bitmap
, hwirq
);
76 static int mpic_msi_reserve_u3_hwirqs(struct mpic
*mpic
)
82 int mpic_msi_init_allocator(struct mpic
*mpic
)
86 rc
= msi_bitmap_alloc(&mpic
->msi_bitmap
, mpic
->num_sources
,
87 irq_domain_get_of_node(mpic
->irqhost
));
91 rc
= msi_bitmap_reserve_dt_hwirqs(&mpic
->msi_bitmap
);
93 if (mpic
->flags
& MPIC_U3_HT_IRQS
)
94 rc
= mpic_msi_reserve_u3_hwirqs(mpic
);
97 msi_bitmap_free(&mpic
->msi_bitmap
);