xive.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright 2016,2017 IBM Corporation.
  4. */
  5. #ifndef _ASM_POWERPC_XIVE_H
  6. #define _ASM_POWERPC_XIVE_H
  7. #include <asm/opal-api.h>
  8. #define XIVE_INVALID_VP 0xffffffff
  9. #ifdef CONFIG_PPC_XIVE
  10. /*
  11. * Thread Interrupt Management Area (TIMA)
  12. *
  13. * This is a global MMIO region divided in 4 pages of varying access
  14. * permissions, providing access to per-cpu interrupt management
  15. * functions. It always identifies the CPU doing the access based
  16. * on the PowerBus initiator ID, thus we always access via the
  17. * same offset regardless of where the code is executing
  18. */
  19. extern void __iomem *xive_tima;
  20. extern unsigned long xive_tima_os;
  21. /*
  22. * Offset in the TM area of our current execution level (provided by
  23. * the backend)
  24. */
  25. extern u32 xive_tima_offset;
  26. /*
  27. * Per-irq data (irq_get_handler_data for normal IRQs), IPIs
  28. * have it stored in the xive_cpu structure. We also cache
  29. * for normal interrupts the current target CPU.
  30. *
  31. * This structure is setup by the backend for each interrupt.
  32. */
  33. struct xive_irq_data {
  34. u64 flags;
  35. u64 eoi_page;
  36. void __iomem *eoi_mmio;
  37. u64 trig_page;
  38. void __iomem *trig_mmio;
  39. u32 esb_shift;
  40. int src_chip;
  41. u32 hw_irq;
  42. /* Setup/used by frontend */
  43. int target;
  44. /*
  45. * saved_p means that there is a queue entry for this interrupt
  46. * in some CPU's queue (not including guest vcpu queues), even
  47. * if P is not set in the source ESB.
  48. * stale_p means that there is no queue entry for this interrupt
  49. * in some CPU's queue, even if P is set in the source ESB.
  50. */
  51. bool saved_p;
  52. bool stale_p;
  53. };
  54. #define XIVE_IRQ_FLAG_STORE_EOI 0x01
  55. #define XIVE_IRQ_FLAG_LSI 0x02
  56. /* #define XIVE_IRQ_FLAG_SHIFT_BUG 0x04 */ /* P9 DD1.0 workaround */
  57. /* #define XIVE_IRQ_FLAG_MASK_FW 0x08 */ /* P9 DD1.0 workaround */
  58. /* #define XIVE_IRQ_FLAG_EOI_FW 0x10 */ /* P9 DD1.0 workaround */
  59. #define XIVE_IRQ_FLAG_H_INT_ESB 0x20
  60. /* Special flag set by KVM for excalation interrupts */
  61. #define XIVE_IRQ_FLAG_NO_EOI 0x80
  62. #define XIVE_INVALID_CHIP_ID -1
  63. /* A queue tracking structure in a CPU */
  64. struct xive_q {
  65. __be32 *qpage;
  66. u32 msk;
  67. u32 idx;
  68. u32 toggle;
  69. u64 eoi_phys;
  70. u32 esc_irq;
  71. atomic_t count;
  72. atomic_t pending_count;
  73. u64 guest_qaddr;
  74. u32 guest_qshift;
  75. };
  76. /* Global enable flags for the XIVE support */
  77. extern bool __xive_enabled;
  78. static inline bool xive_enabled(void) { return __xive_enabled; }
  79. bool xive_spapr_init(void);
  80. bool xive_native_init(void);
  81. void xive_smp_probe(void);
  82. int xive_smp_prepare_cpu(unsigned int cpu);
  83. void xive_smp_setup_cpu(void);
  84. void xive_smp_disable_cpu(void);
  85. void xive_teardown_cpu(void);
  86. void xive_shutdown(void);
  87. void xive_flush_interrupt(void);
  88. /* xmon hook */
  89. void xmon_xive_do_dump(int cpu);
  90. int xmon_xive_get_irq_config(u32 hw_irq, struct irq_data *d);
  91. void xmon_xive_get_irq_all(void);
  92. /* APIs used by KVM */
  93. u32 xive_native_default_eq_shift(void);
  94. u32 xive_native_alloc_vp_block(u32 max_vcpus);
  95. void xive_native_free_vp_block(u32 vp_base);
  96. int xive_native_populate_irq_data(u32 hw_irq,
  97. struct xive_irq_data *data);
  98. void xive_cleanup_irq_data(struct xive_irq_data *xd);
  99. void xive_irq_free_data(unsigned int virq);
  100. void xive_native_free_irq(u32 irq);
  101. int xive_native_configure_irq(u32 hw_irq, u32 target, u8 prio, u32 sw_irq);
  102. int xive_native_configure_queue(u32 vp_id, struct xive_q *q, u8 prio,
  103. __be32 *qpage, u32 order, bool can_escalate);
  104. void xive_native_disable_queue(u32 vp_id, struct xive_q *q, u8 prio);
  105. void xive_native_sync_source(u32 hw_irq);
  106. void xive_native_sync_queue(u32 hw_irq);
  107. bool is_xive_irq(struct irq_chip *chip);
  108. int xive_native_enable_vp(u32 vp_id, bool single_escalation);
  109. int xive_native_disable_vp(u32 vp_id);
  110. int xive_native_get_vp_info(u32 vp_id, u32 *out_cam_id, u32 *out_chip_id);
  111. bool xive_native_has_single_escalation(void);
  112. bool xive_native_has_save_restore(void);
  113. int xive_native_get_queue_info(u32 vp_id, uint32_t prio,
  114. u64 *out_qpage,
  115. u64 *out_qsize,
  116. u64 *out_qeoi_page,
  117. u32 *out_escalate_irq,
  118. u64 *out_qflags);
  119. int xive_native_get_queue_state(u32 vp_id, uint32_t prio, u32 *qtoggle,
  120. u32 *qindex);
  121. int xive_native_set_queue_state(u32 vp_id, uint32_t prio, u32 qtoggle,
  122. u32 qindex);
  123. int xive_native_get_vp_state(u32 vp_id, u64 *out_state);
  124. bool xive_native_has_queue_state_support(void);
  125. extern u32 xive_native_alloc_irq_on_chip(u32 chip_id);
  126. static inline u32 xive_native_alloc_irq(void)
  127. {
  128. return xive_native_alloc_irq_on_chip(OPAL_XIVE_ANY_CHIP);
  129. }
  130. #else
  131. static inline bool xive_enabled(void) { return false; }
  132. static inline bool xive_spapr_init(void) { return false; }
  133. static inline bool xive_native_init(void) { return false; }
  134. static inline void xive_smp_probe(void) { }
  135. static inline int xive_smp_prepare_cpu(unsigned int cpu) { return -EINVAL; }
  136. static inline void xive_smp_setup_cpu(void) { }
  137. static inline void xive_smp_disable_cpu(void) { }
  138. static inline void xive_shutdown(void) { }
  139. static inline void xive_flush_interrupt(void) { }
  140. static inline u32 xive_native_alloc_vp_block(u32 max_vcpus) { return XIVE_INVALID_VP; }
  141. static inline void xive_native_free_vp_block(u32 vp_base) { }
  142. #endif
  143. #endif /* _ASM_POWERPC_XIVE_H */