mpic_msi.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #include <linux/irq.h>
  11. #include <linux/bitmap.h>
  12. #include <linux/msi.h>
  13. #include <asm/mpic.h>
  14. #include <asm/prom.h>
  15. #include <asm/hw_irq.h>
  16. #include <asm/ppc-pci.h>
  17. #include <asm/msi_bitmap.h>
  18. #include <sysdev/mpic.h>
  19. void mpic_msi_reserve_hwirq(struct mpic *mpic, irq_hw_number_t hwirq)
  20. {
  21. /* The mpic calls this even when there is no allocator setup */
  22. if (!mpic->msi_bitmap.bitmap)
  23. return;
  24. msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, hwirq);
  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;
  30. const struct irq_domain_ops *ops = mpic->irqhost->ops;
  31. struct device_node *np;
  32. int flags, index, i;
  33. struct of_phandle_args oirq;
  34. pr_debug("mpic: found U3, guessing msi allocator setup\n");
  35. /* Reserve source numbers we know are reserved in the HW.
  36. *
  37. * This is a bit of a mix of U3 and U4 reserves but that's going
  38. * to work fine, we have plenty enugh numbers left so let's just
  39. * mark anything we don't like reserved.
  40. */
  41. for (i = 0; i < 8; i++)
  42. msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i);
  43. for (i = 42; i < 46; i++)
  44. msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i);
  45. for (i = 100; i < 105; i++)
  46. msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i);
  47. for (i = 124; i < mpic->num_sources; i++)
  48. msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i);
  49. np = NULL;
  50. while ((np = of_find_all_nodes(np))) {
  51. pr_debug("mpic: mapping hwirqs for %s\n", np->full_name);
  52. index = 0;
  53. while (of_irq_parse_one(np, index++, &oirq) == 0) {
  54. ops->xlate(mpic->irqhost, NULL, oirq.args,
  55. oirq.args_count, &hwirq, &flags);
  56. msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, hwirq);
  57. }
  58. }
  59. return 0;
  60. }
  61. #else
  62. static int mpic_msi_reserve_u3_hwirqs(struct mpic *mpic)
  63. {
  64. return -1;
  65. }
  66. #endif
  67. int mpic_msi_init_allocator(struct mpic *mpic)
  68. {
  69. int rc;
  70. rc = msi_bitmap_alloc(&mpic->msi_bitmap, mpic->num_sources,
  71. irq_domain_get_of_node(mpic->irqhost));
  72. if (rc)
  73. return rc;
  74. rc = msi_bitmap_reserve_dt_hwirqs(&mpic->msi_bitmap);
  75. if (rc > 0) {
  76. if (mpic->flags & MPIC_U3_HT_IRQS)
  77. rc = mpic_msi_reserve_u3_hwirqs(mpic);
  78. if (rc) {
  79. msi_bitmap_free(&mpic->msi_bitmap);
  80. return rc;
  81. }
  82. }
  83. return 0;
  84. }