xen_msi.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (c) 2014 Roger Pau Monné <roger.pau@citrix.com>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS AS IS'' AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  18. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  20. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  21. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  22. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  23. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  24. * SUCH DAMAGE.
  25. */
  26. #include <sys/cdefs.h>
  27. __FBSDID("$FreeBSD$");
  28. #include <sys/param.h>
  29. #include <sys/bus.h>
  30. #include <sys/kernel.h>
  31. #include <sys/limits.h>
  32. #include <sys/lock.h>
  33. #include <sys/malloc.h>
  34. #include <sys/mutex.h>
  35. #include <sys/sx.h>
  36. #include <sys/systm.h>
  37. #include <x86/apicreg.h>
  38. #include <machine/cputypes.h>
  39. #include <machine/md_var.h>
  40. #include <machine/frame.h>
  41. #include <machine/intr_machdep.h>
  42. #include <x86/apicvar.h>
  43. #include <machine/specialreg.h>
  44. #include <dev/pci/pcivar.h>
  45. #include <xen/xen-os.h>
  46. #include <xen/xen_intr.h>
  47. #include <xen/xen_msi.h>
  48. static struct mtx msi_lock;
  49. static u_int msi_last_irq;
  50. void
  51. xen_msi_init(void)
  52. {
  53. MPASS(num_io_irqs > 0);
  54. first_msi_irq = num_io_irqs;
  55. if (num_msi_irqs > UINT_MAX - first_msi_irq)
  56. panic("num_msi_irqs too high");
  57. num_io_irqs = first_msi_irq + num_msi_irqs;
  58. mtx_init(&msi_lock, "msi", NULL, MTX_DEF);
  59. }
  60. /*
  61. * Try to allocate 'count' interrupt sources with contiguous IDT values.
  62. */
  63. int
  64. xen_msi_alloc(device_t dev, int count, int maxcount, int *irqs)
  65. {
  66. int i, ret = 0;
  67. mtx_lock(&msi_lock);
  68. /* If we would exceed the max, give up. */
  69. if (msi_last_irq + count > num_msi_irqs) {
  70. mtx_unlock(&msi_lock);
  71. return (ENXIO);
  72. }
  73. /* Allocate MSI vectors */
  74. for (i = 0; i < count; i++)
  75. irqs[i] = first_msi_irq + msi_last_irq++;
  76. mtx_unlock(&msi_lock);
  77. ret = xen_register_msi(dev, irqs[0], count);
  78. if (ret != 0)
  79. return (ret);
  80. for (i = 0; i < count; i++)
  81. nexus_add_irq(irqs[i]);
  82. return (0);
  83. }
  84. int
  85. xen_msi_release(int *irqs, int count)
  86. {
  87. int i, ret;
  88. for (i = 0; i < count; i++) {
  89. ret = xen_release_msi(irqs[i]);
  90. if (ret != 0)
  91. return (ret);
  92. }
  93. return (0);
  94. }
  95. int
  96. xen_msi_map(int irq, uint64_t *addr, uint32_t *data)
  97. {
  98. return (0);
  99. }
  100. int
  101. xen_msix_alloc(device_t dev, int *irq)
  102. {
  103. return (ENXIO);
  104. }
  105. int
  106. xen_msix_release(int irq)
  107. {
  108. return (ENOENT);
  109. }