xics_pnv.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * QEMU PowerPC PowerNV Interrupt Control Presenter (ICP) model
  3. *
  4. * Copyright (c) 2017, IBM Corporation.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public License
  8. * as published by the Free Software Foundation; either version 2.1 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "qemu/osdep.h"
  20. #include "qapi/error.h"
  21. #include "qemu/log.h"
  22. #include "qemu/module.h"
  23. #include "hw/ppc/xics.h"
  24. #define ICP_XIRR_POLL 0 /* 1 byte (CPRR) or 4 bytes */
  25. #define ICP_XIRR 4 /* 1 byte (CPRR) or 4 bytes */
  26. #define ICP_MFRR 12 /* 1 byte access only */
  27. #define ICP_LINKA 16 /* unused */
  28. #define ICP_LINKB 20 /* unused */
  29. #define ICP_LINKC 24 /* unused */
  30. static uint64_t pnv_icp_read(void *opaque, hwaddr addr, unsigned width)
  31. {
  32. ICPState *icp = ICP(opaque);
  33. PnvICPState *picp = PNV_ICP(opaque);
  34. bool byte0 = (width == 1 && (addr & 0x3) == 0);
  35. uint64_t val = 0xffffffff;
  36. switch (addr & 0xffc) {
  37. case ICP_XIRR_POLL:
  38. val = icp_ipoll(icp, NULL);
  39. if (byte0) {
  40. val >>= 24;
  41. } else if (width != 4) {
  42. goto bad_access;
  43. }
  44. break;
  45. case ICP_XIRR:
  46. if (byte0) {
  47. val = icp_ipoll(icp, NULL) >> 24;
  48. } else if (width == 4) {
  49. val = icp_accept(icp);
  50. } else {
  51. goto bad_access;
  52. }
  53. break;
  54. case ICP_MFRR:
  55. if (byte0) {
  56. val = icp->mfrr;
  57. } else {
  58. goto bad_access;
  59. }
  60. break;
  61. case ICP_LINKA:
  62. if (width == 4) {
  63. val = picp->links[0];
  64. } else {
  65. goto bad_access;
  66. }
  67. break;
  68. case ICP_LINKB:
  69. if (width == 4) {
  70. val = picp->links[1];
  71. } else {
  72. goto bad_access;
  73. }
  74. break;
  75. case ICP_LINKC:
  76. if (width == 4) {
  77. val = picp->links[2];
  78. } else {
  79. goto bad_access;
  80. }
  81. break;
  82. default:
  83. bad_access:
  84. qemu_log_mask(LOG_GUEST_ERROR, "XICS: Bad ICP access 0x%"
  85. HWADDR_PRIx"/%d\n", addr, width);
  86. }
  87. return val;
  88. }
  89. static void pnv_icp_write(void *opaque, hwaddr addr, uint64_t val,
  90. unsigned width)
  91. {
  92. ICPState *icp = ICP(opaque);
  93. PnvICPState *picp = PNV_ICP(opaque);
  94. bool byte0 = (width == 1 && (addr & 0x3) == 0);
  95. switch (addr & 0xffc) {
  96. case ICP_XIRR:
  97. if (byte0) {
  98. icp_set_cppr(icp, val);
  99. } else if (width == 4) {
  100. icp_eoi(icp, val);
  101. } else {
  102. goto bad_access;
  103. }
  104. break;
  105. case ICP_MFRR:
  106. if (byte0) {
  107. icp_set_mfrr(icp, val);
  108. } else {
  109. goto bad_access;
  110. }
  111. break;
  112. case ICP_LINKA:
  113. if (width == 4) {
  114. picp->links[0] = val;
  115. } else {
  116. goto bad_access;
  117. }
  118. break;
  119. case ICP_LINKB:
  120. if (width == 4) {
  121. picp->links[1] = val;
  122. } else {
  123. goto bad_access;
  124. }
  125. break;
  126. case ICP_LINKC:
  127. if (width == 4) {
  128. picp->links[2] = val;
  129. } else {
  130. goto bad_access;
  131. }
  132. break;
  133. default:
  134. bad_access:
  135. qemu_log_mask(LOG_GUEST_ERROR, "XICS: Bad ICP access 0x%"
  136. HWADDR_PRIx"/%d\n", addr, width);
  137. }
  138. }
  139. static const MemoryRegionOps pnv_icp_ops = {
  140. .read = pnv_icp_read,
  141. .write = pnv_icp_write,
  142. .endianness = DEVICE_BIG_ENDIAN,
  143. .valid = {
  144. .min_access_size = 1,
  145. .max_access_size = 4,
  146. },
  147. .impl = {
  148. .min_access_size = 1,
  149. .max_access_size = 4,
  150. },
  151. };
  152. static void pnv_icp_realize(DeviceState *dev, Error **errp)
  153. {
  154. ICPState *icp = ICP(dev);
  155. PnvICPState *pnv_icp = PNV_ICP(icp);
  156. ICPStateClass *icpc = ICP_GET_CLASS(icp);
  157. Error *local_err = NULL;
  158. icpc->parent_realize(dev, &local_err);
  159. if (local_err) {
  160. error_propagate(errp, local_err);
  161. return;
  162. }
  163. memory_region_init_io(&pnv_icp->mmio, OBJECT(icp), &pnv_icp_ops,
  164. icp, "icp-thread", 0x1000);
  165. }
  166. static void pnv_icp_class_init(ObjectClass *klass, void *data)
  167. {
  168. DeviceClass *dc = DEVICE_CLASS(klass);
  169. ICPStateClass *icpc = ICP_CLASS(klass);
  170. device_class_set_parent_realize(dc, pnv_icp_realize,
  171. &icpc->parent_realize);
  172. dc->desc = "PowerNV ICP";
  173. }
  174. static const TypeInfo pnv_icp_info = {
  175. .name = TYPE_PNV_ICP,
  176. .parent = TYPE_ICP,
  177. .instance_size = sizeof(PnvICPState),
  178. .class_init = pnv_icp_class_init,
  179. .class_size = sizeof(ICPStateClass),
  180. };
  181. static void pnv_icp_register_types(void)
  182. {
  183. type_register_static(&pnv_icp_info);
  184. }
  185. type_init(pnv_icp_register_types)