pnv_nest_pervasive.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * QEMU PowerPC nest pervasive common chiplet model
  3. *
  4. * Copyright (c) 2023, IBM Corporation.
  5. *
  6. * SPDX-License-Identifier: GPL-2.0-or-later
  7. */
  8. #include "qemu/osdep.h"
  9. #include "qemu/log.h"
  10. #include "hw/qdev-properties.h"
  11. #include "hw/ppc/pnv.h"
  12. #include "hw/ppc/pnv_xscom.h"
  13. #include "hw/ppc/pnv_nest_pervasive.h"
  14. /*
  15. * Status, configuration, and control units in POWER chips is provided
  16. * by the pervasive subsystem, which connects registers to the SCOM bus,
  17. * which can be programmed by processor cores, other units on the chip,
  18. * BMCs, or other POWER chips.
  19. *
  20. * A POWER10 chip is divided into logical units called chiplets. Chiplets
  21. * are broadly divided into "core chiplets" (with the processor cores) and
  22. * "nest chiplets" (with everything else). Each chiplet has an attachment
  23. * to the pervasive bus (PIB) and with chiplet-specific registers.
  24. * All nest chiplets have a common basic set of registers.
  25. *
  26. * This model will provide the registers functionality for common registers of
  27. * nest unit (PB Chiplet, PCI Chiplets, MC Chiplet, PAU Chiplets)
  28. *
  29. * Currently this model provide the read/write functionality of chiplet control
  30. * scom registers.
  31. */
  32. #define CPLT_CONF0 0x08
  33. #define CPLT_CONF0_OR 0x18
  34. #define CPLT_CONF0_CLEAR 0x28
  35. #define CPLT_CONF1 0x09
  36. #define CPLT_CONF1_OR 0x19
  37. #define CPLT_CONF1_CLEAR 0x29
  38. #define CPLT_STAT0 0x100
  39. #define CPLT_MASK0 0x101
  40. #define CPLT_PROTECT_MODE 0x3FE
  41. #define CPLT_ATOMIC_CLOCK 0x3FF
  42. static uint64_t pnv_chiplet_ctrl_read(void *opaque, hwaddr addr, unsigned size)
  43. {
  44. PnvNestChipletPervasive *nest_pervasive = PNV_NEST_CHIPLET_PERVASIVE(
  45. opaque);
  46. uint32_t reg = addr >> 3;
  47. uint64_t val = ~0ull;
  48. /* CPLT_CTRL0 to CPLT_CTRL5 */
  49. for (int i = 0; i < PNV_CPLT_CTRL_SIZE; i++) {
  50. if (reg == i) {
  51. return nest_pervasive->control_regs.cplt_ctrl[i];
  52. } else if ((reg == (i + 0x10)) || (reg == (i + 0x20))) {
  53. qemu_log_mask(LOG_GUEST_ERROR, "%s: Write only register, ignoring "
  54. "xscom read at 0x%" PRIx32 "\n",
  55. __func__, reg);
  56. return val;
  57. }
  58. }
  59. switch (reg) {
  60. case CPLT_CONF0:
  61. val = nest_pervasive->control_regs.cplt_cfg0;
  62. break;
  63. case CPLT_CONF0_OR:
  64. case CPLT_CONF0_CLEAR:
  65. qemu_log_mask(LOG_GUEST_ERROR, "%s: Write only register, ignoring "
  66. "xscom read at 0x%" PRIx32 "\n",
  67. __func__, reg);
  68. break;
  69. case CPLT_CONF1:
  70. val = nest_pervasive->control_regs.cplt_cfg1;
  71. break;
  72. case CPLT_CONF1_OR:
  73. case CPLT_CONF1_CLEAR:
  74. qemu_log_mask(LOG_GUEST_ERROR, "%s: Write only register, ignoring "
  75. "xscom read at 0x%" PRIx32 "\n",
  76. __func__, reg);
  77. break;
  78. case CPLT_STAT0:
  79. val = nest_pervasive->control_regs.cplt_stat0;
  80. break;
  81. case CPLT_MASK0:
  82. val = nest_pervasive->control_regs.cplt_mask0;
  83. break;
  84. case CPLT_PROTECT_MODE:
  85. val = nest_pervasive->control_regs.ctrl_protect_mode;
  86. break;
  87. case CPLT_ATOMIC_CLOCK:
  88. val = nest_pervasive->control_regs.ctrl_atomic_lock;
  89. break;
  90. default:
  91. qemu_log_mask(LOG_UNIMP, "%s: Chiplet_control_regs: Invalid xscom "
  92. "read at 0x%" PRIx32 "\n", __func__, reg);
  93. }
  94. return val;
  95. }
  96. static void pnv_chiplet_ctrl_write(void *opaque, hwaddr addr,
  97. uint64_t val, unsigned size)
  98. {
  99. PnvNestChipletPervasive *nest_pervasive = PNV_NEST_CHIPLET_PERVASIVE(
  100. opaque);
  101. uint32_t reg = addr >> 3;
  102. /* CPLT_CTRL0 to CPLT_CTRL5 */
  103. for (int i = 0; i < PNV_CPLT_CTRL_SIZE; i++) {
  104. if (reg == i) {
  105. nest_pervasive->control_regs.cplt_ctrl[i] = val;
  106. return;
  107. } else if (reg == (i + 0x10)) {
  108. nest_pervasive->control_regs.cplt_ctrl[i] |= val;
  109. return;
  110. } else if (reg == (i + 0x20)) {
  111. nest_pervasive->control_regs.cplt_ctrl[i] &= ~val;
  112. return;
  113. }
  114. }
  115. switch (reg) {
  116. case CPLT_CONF0:
  117. nest_pervasive->control_regs.cplt_cfg0 = val;
  118. break;
  119. case CPLT_CONF0_OR:
  120. nest_pervasive->control_regs.cplt_cfg0 |= val;
  121. break;
  122. case CPLT_CONF0_CLEAR:
  123. nest_pervasive->control_regs.cplt_cfg0 &= ~val;
  124. break;
  125. case CPLT_CONF1:
  126. nest_pervasive->control_regs.cplt_cfg1 = val;
  127. break;
  128. case CPLT_CONF1_OR:
  129. nest_pervasive->control_regs.cplt_cfg1 |= val;
  130. break;
  131. case CPLT_CONF1_CLEAR:
  132. nest_pervasive->control_regs.cplt_cfg1 &= ~val;
  133. break;
  134. case CPLT_STAT0:
  135. nest_pervasive->control_regs.cplt_stat0 = val;
  136. break;
  137. case CPLT_MASK0:
  138. nest_pervasive->control_regs.cplt_mask0 = val;
  139. break;
  140. case CPLT_PROTECT_MODE:
  141. nest_pervasive->control_regs.ctrl_protect_mode = val;
  142. break;
  143. case CPLT_ATOMIC_CLOCK:
  144. nest_pervasive->control_regs.ctrl_atomic_lock = val;
  145. break;
  146. default:
  147. qemu_log_mask(LOG_UNIMP, "%s: Chiplet_control_regs: Invalid xscom "
  148. "write at 0x%" PRIx32 "\n",
  149. __func__, reg);
  150. }
  151. }
  152. static const MemoryRegionOps pnv_nest_pervasive_control_xscom_ops = {
  153. .read = pnv_chiplet_ctrl_read,
  154. .write = pnv_chiplet_ctrl_write,
  155. .valid.min_access_size = 8,
  156. .valid.max_access_size = 8,
  157. .impl.min_access_size = 8,
  158. .impl.max_access_size = 8,
  159. .endianness = DEVICE_BIG_ENDIAN,
  160. };
  161. static void pnv_nest_pervasive_realize(DeviceState *dev, Error **errp)
  162. {
  163. PnvNestChipletPervasive *nest_pervasive = PNV_NEST_CHIPLET_PERVASIVE(dev);
  164. /* Chiplet control scoms */
  165. pnv_xscom_region_init(&nest_pervasive->xscom_ctrl_regs_mr,
  166. OBJECT(nest_pervasive),
  167. &pnv_nest_pervasive_control_xscom_ops,
  168. nest_pervasive, "xscom-pervasive-control",
  169. PNV10_XSCOM_CHIPLET_CTRL_REGS_SIZE);
  170. }
  171. static void pnv_nest_pervasive_class_init(ObjectClass *klass, void *data)
  172. {
  173. DeviceClass *dc = DEVICE_CLASS(klass);
  174. dc->desc = "PowerNV nest pervasive chiplet";
  175. dc->realize = pnv_nest_pervasive_realize;
  176. }
  177. static const TypeInfo pnv_nest_pervasive_info = {
  178. .name = TYPE_PNV_NEST_CHIPLET_PERVASIVE,
  179. .parent = TYPE_DEVICE,
  180. .instance_size = sizeof(PnvNestChipletPervasive),
  181. .class_init = pnv_nest_pervasive_class_init,
  182. .interfaces = (InterfaceInfo[]) {
  183. { TYPE_PNV_XSCOM_INTERFACE },
  184. { }
  185. }
  186. };
  187. static void pnv_nest_pervasive_register_types(void)
  188. {
  189. type_register_static(&pnv_nest_pervasive_info);
  190. }
  191. type_init(pnv_nest_pervasive_register_types);