events_internal.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Xen Event Channels (internal header)
  3. *
  4. * Copyright (C) 2013 Citrix Systems R&D Ltd.
  5. *
  6. * This source code is licensed under the GNU General Public License,
  7. * Version 2 or later. See the file COPYING for more details.
  8. */
  9. #ifndef __EVENTS_INTERNAL_H__
  10. #define __EVENTS_INTERNAL_H__
  11. /* Interrupt types. */
  12. enum xen_irq_type {
  13. IRQT_UNBOUND = 0,
  14. IRQT_PIRQ,
  15. IRQT_VIRQ,
  16. IRQT_IPI,
  17. IRQT_EVTCHN
  18. };
  19. /*
  20. * Packed IRQ information:
  21. * type - enum xen_irq_type
  22. * event channel - irq->event channel mapping
  23. * cpu - cpu this event channel is bound to
  24. * index - type-specific information:
  25. * PIRQ - vector, with MSB being "needs EIO", or physical IRQ of the HVM
  26. * guest, or GSI (real passthrough IRQ) of the device.
  27. * VIRQ - virq number
  28. * IPI - IPI vector
  29. * EVTCHN -
  30. */
  31. struct irq_info {
  32. struct list_head list;
  33. int refcnt;
  34. enum xen_irq_type type; /* type */
  35. unsigned irq;
  36. unsigned int evtchn; /* event channel */
  37. unsigned short cpu; /* cpu bound */
  38. union {
  39. unsigned short virq;
  40. enum ipi_vector ipi;
  41. struct {
  42. unsigned short pirq;
  43. unsigned short gsi;
  44. unsigned char vector;
  45. unsigned char flags;
  46. uint16_t domid;
  47. } pirq;
  48. } u;
  49. };
  50. #define PIRQ_NEEDS_EOI (1 << 0)
  51. #define PIRQ_SHAREABLE (1 << 1)
  52. #define PIRQ_MSI_GROUP (1 << 2)
  53. struct evtchn_ops {
  54. unsigned (*max_channels)(void);
  55. unsigned (*nr_channels)(void);
  56. int (*setup)(struct irq_info *info);
  57. void (*bind_to_cpu)(struct irq_info *info, unsigned cpu);
  58. void (*clear_pending)(unsigned port);
  59. void (*set_pending)(unsigned port);
  60. bool (*is_pending)(unsigned port);
  61. bool (*test_and_set_mask)(unsigned port);
  62. void (*mask)(unsigned port);
  63. void (*unmask)(unsigned port);
  64. void (*handle_events)(unsigned cpu);
  65. void (*resume)(void);
  66. };
  67. extern const struct evtchn_ops *evtchn_ops;
  68. extern int **evtchn_to_irq;
  69. int get_evtchn_to_irq(unsigned int evtchn);
  70. struct irq_info *info_for_irq(unsigned irq);
  71. unsigned cpu_from_irq(unsigned irq);
  72. unsigned cpu_from_evtchn(unsigned int evtchn);
  73. static inline unsigned xen_evtchn_max_channels(void)
  74. {
  75. return evtchn_ops->max_channels();
  76. }
  77. /*
  78. * Do any ABI specific setup for a bound event channel before it can
  79. * be unmasked and used.
  80. */
  81. static inline int xen_evtchn_port_setup(struct irq_info *info)
  82. {
  83. if (evtchn_ops->setup)
  84. return evtchn_ops->setup(info);
  85. return 0;
  86. }
  87. static inline void xen_evtchn_port_bind_to_cpu(struct irq_info *info,
  88. unsigned cpu)
  89. {
  90. evtchn_ops->bind_to_cpu(info, cpu);
  91. }
  92. static inline void clear_evtchn(unsigned port)
  93. {
  94. evtchn_ops->clear_pending(port);
  95. }
  96. static inline void set_evtchn(unsigned port)
  97. {
  98. evtchn_ops->set_pending(port);
  99. }
  100. static inline bool test_evtchn(unsigned port)
  101. {
  102. return evtchn_ops->is_pending(port);
  103. }
  104. static inline bool test_and_set_mask(unsigned port)
  105. {
  106. return evtchn_ops->test_and_set_mask(port);
  107. }
  108. static inline void mask_evtchn(unsigned port)
  109. {
  110. return evtchn_ops->mask(port);
  111. }
  112. static inline void unmask_evtchn(unsigned port)
  113. {
  114. return evtchn_ops->unmask(port);
  115. }
  116. static inline void xen_evtchn_handle_events(unsigned cpu)
  117. {
  118. return evtchn_ops->handle_events(cpu);
  119. }
  120. static inline void xen_evtchn_resume(void)
  121. {
  122. if (evtchn_ops->resume)
  123. evtchn_ops->resume();
  124. }
  125. void xen_evtchn_2l_init(void);
  126. int xen_evtchn_fifo_init(void);
  127. #endif /* #ifndef __EVENTS_INTERNAL_H__ */