2
0

xics.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * QEMU PowerPC pSeries Logical Partition (aka sPAPR) hardware System Emulator
  3. *
  4. * PAPR Virtualized Interrupt System, aka ICS/ICP aka xics
  5. *
  6. * Copyright (c) 2010,2011 David Gibson, IBM Corporation.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  21. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #ifndef XICS_H
  28. #define XICS_H
  29. #include "exec/memory.h"
  30. #include "hw/qdev-core.h"
  31. #include "qom/object.h"
  32. #define XICS_IPI 0x2
  33. #define XICS_BUID 0x1
  34. #define XICS_IRQ_BASE (XICS_BUID << 12)
  35. /*
  36. * We currently only support one BUID which is our interrupt base
  37. * (the kernel implementation supports more but we don't exploit
  38. * that yet)
  39. */
  40. typedef struct PnvICPState PnvICPState;
  41. typedef struct ICSStateClass ICSStateClass;
  42. typedef struct ICSState ICSState;
  43. typedef struct ICSIRQState ICSIRQState;
  44. typedef struct XICSFabric XICSFabric;
  45. #define TYPE_ICP "icp"
  46. OBJECT_DECLARE_TYPE(ICPState, ICPStateClass,
  47. ICP)
  48. #define TYPE_PNV_ICP "pnv-icp"
  49. DECLARE_INSTANCE_CHECKER(PnvICPState, PNV_ICP,
  50. TYPE_PNV_ICP)
  51. struct ICPStateClass {
  52. DeviceClass parent_class;
  53. DeviceRealize parent_realize;
  54. };
  55. struct ICPState {
  56. /*< private >*/
  57. DeviceState parent_obj;
  58. /*< public >*/
  59. CPUState *cs;
  60. ICSState *xirr_owner;
  61. uint32_t xirr;
  62. uint8_t pending_priority;
  63. uint8_t mfrr;
  64. qemu_irq output;
  65. XICSFabric *xics;
  66. };
  67. #define ICP_PROP_XICS "xics"
  68. #define ICP_PROP_CPU "cpu"
  69. struct PnvICPState {
  70. ICPState parent_obj;
  71. MemoryRegion mmio;
  72. uint32_t links[3];
  73. };
  74. #define TYPE_ICS "ics"
  75. DECLARE_OBJ_CHECKERS(ICSState, ICSStateClass,
  76. ICS, TYPE_ICS)
  77. struct ICSStateClass {
  78. DeviceClass parent_class;
  79. DeviceRealize parent_realize;
  80. ResettablePhases parent_phases;
  81. void (*reject)(ICSState *s, uint32_t irq);
  82. void (*resend)(ICSState *s);
  83. };
  84. struct ICSState {
  85. /*< private >*/
  86. DeviceState parent_obj;
  87. /*< public >*/
  88. uint32_t nr_irqs;
  89. uint32_t offset;
  90. ICSIRQState *irqs;
  91. XICSFabric *xics;
  92. };
  93. #define ICS_PROP_XICS "xics"
  94. static inline bool ics_valid_irq(ICSState *ics, uint32_t nr)
  95. {
  96. return (nr >= ics->offset) && (nr < (ics->offset + ics->nr_irqs));
  97. }
  98. struct ICSIRQState {
  99. uint32_t server;
  100. uint8_t priority;
  101. uint8_t saved_priority;
  102. #define XICS_STATUS_ASSERTED 0x1
  103. #define XICS_STATUS_SENT 0x2
  104. #define XICS_STATUS_REJECTED 0x4
  105. #define XICS_STATUS_MASKED_PENDING 0x8
  106. #define XICS_STATUS_PRESENTED 0x10
  107. #define XICS_STATUS_QUEUED 0x20
  108. uint8_t status;
  109. /* (flags & XICS_FLAGS_IRQ_MASK) == 0 means the interrupt is not allocated */
  110. #define XICS_FLAGS_IRQ_LSI 0x1
  111. #define XICS_FLAGS_IRQ_MSI 0x2
  112. #define XICS_FLAGS_IRQ_MASK 0x3
  113. uint8_t flags;
  114. };
  115. #define TYPE_XICS_FABRIC "xics-fabric"
  116. #define XICS_FABRIC(obj) \
  117. INTERFACE_CHECK(XICSFabric, (obj), TYPE_XICS_FABRIC)
  118. typedef struct XICSFabricClass XICSFabricClass;
  119. DECLARE_CLASS_CHECKERS(XICSFabricClass, XICS_FABRIC,
  120. TYPE_XICS_FABRIC)
  121. struct XICSFabricClass {
  122. InterfaceClass parent;
  123. ICSState *(*ics_get)(XICSFabric *xi, int irq);
  124. void (*ics_resend)(XICSFabric *xi);
  125. ICPState *(*icp_get)(XICSFabric *xi, int server);
  126. };
  127. ICPState *xics_icp_get(XICSFabric *xi, int server);
  128. /* Internal XICS interfaces */
  129. void icp_set_cppr(ICPState *icp, uint8_t cppr);
  130. void icp_set_mfrr(ICPState *icp, uint8_t mfrr);
  131. uint32_t icp_accept(ICPState *ss);
  132. uint32_t icp_ipoll(ICPState *ss, uint32_t *mfrr);
  133. void icp_eoi(ICPState *icp, uint32_t xirr);
  134. void icp_irq(ICSState *ics, int server, int nr, uint8_t priority);
  135. void icp_reset(ICPState *icp);
  136. void ics_write_xive(ICSState *ics, int nr, int server,
  137. uint8_t priority, uint8_t saved_priority);
  138. void ics_set_irq(void *opaque, int srcno, int val);
  139. static inline bool ics_irq_free(ICSState *ics, uint32_t srcno)
  140. {
  141. return !(ics->irqs[srcno].flags & XICS_FLAGS_IRQ_MASK);
  142. }
  143. void ics_set_irq_type(ICSState *ics, int srcno, bool lsi);
  144. void icp_pic_print_info(ICPState *icp, GString *buf);
  145. void ics_pic_print_info(ICSState *ics, GString *buf);
  146. void ics_resend(ICSState *ics);
  147. void icp_resend(ICPState *ss);
  148. Object *icp_create(Object *cpu, const char *type, XICSFabric *xi,
  149. Error **errp);
  150. void icp_destroy(ICPState *icp);
  151. /* KVM */
  152. void icp_get_kvm_state(ICPState *icp);
  153. int icp_set_kvm_state(ICPState *icp, Error **errp);
  154. void icp_synchronize_state(ICPState *icp);
  155. void icp_kvm_realize(DeviceState *dev, Error **errp);
  156. void ics_get_kvm_state(ICSState *ics);
  157. int ics_set_kvm_state_one(ICSState *ics, int srcno, Error **errp);
  158. int ics_set_kvm_state(ICSState *ics, Error **errp);
  159. void ics_synchronize_state(ICSState *ics);
  160. void ics_kvm_set_irq(ICSState *ics, int srcno, int val);
  161. #endif /* XICS_H */