2
0

mchp_pfsoc_ioscb.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /*
  2. * Microchip PolarFire SoC IOSCB module emulation
  3. *
  4. * Copyright (c) 2020 Wind River Systems, Inc.
  5. *
  6. * Author:
  7. * Bin Meng <bin.meng@windriver.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 or
  12. * (at your option) version 3 of the License.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, see <http://www.gnu.org/licenses/>.
  21. */
  22. #include "qemu/osdep.h"
  23. #include "qemu/bitops.h"
  24. #include "qemu/log.h"
  25. #include "qapi/error.h"
  26. #include "hw/irq.h"
  27. #include "hw/sysbus.h"
  28. #include "hw/misc/mchp_pfsoc_ioscb.h"
  29. /*
  30. * The whole IOSCB module registers map into the system address at 0x3000_0000,
  31. * named as "System Port 0 (AXI-D0)".
  32. */
  33. #define IOSCB_WHOLE_REG_SIZE 0x10000000
  34. #define IOSCB_SUBMOD_REG_SIZE 0x1000
  35. #define IOSCB_CCC_REG_SIZE 0x2000000
  36. #define IOSCB_CTRL_REG_SIZE 0x800
  37. #define IOSCB_QSPIXIP_REG_SIZE 0x200
  38. /*
  39. * There are many sub-modules in the IOSCB module.
  40. * See Microchip PolarFire SoC documentation (Register_Map.zip),
  41. * Register Map/PF_SoC_RegMap_V1_1/MPFS250T/mpfs250t_ioscb_memmap_dri.htm
  42. *
  43. * The following are sub-modules offsets that are of concern.
  44. */
  45. #define IOSCB_LANE01_BASE 0x06500000
  46. #define IOSCB_LANE23_BASE 0x06510000
  47. #define IOSCB_CTRL_BASE 0x07020000
  48. #define IOSCB_QSPIXIP_BASE 0x07020100
  49. #define IOSCB_MAILBOX_BASE 0x07020800
  50. #define IOSCB_CFG_BASE 0x07080000
  51. #define IOSCB_CCC_BASE 0x08000000
  52. #define IOSCB_PLL_MSS_BASE 0x0E001000
  53. #define IOSCB_CFM_MSS_BASE 0x0E002000
  54. #define IOSCB_PLL_DDR_BASE 0x0E010000
  55. #define IOSCB_BC_DDR_BASE 0x0E020000
  56. #define IOSCB_IO_CALIB_DDR_BASE 0x0E040000
  57. #define IOSCB_PLL_SGMII_BASE 0x0E080000
  58. #define IOSCB_DLL_SGMII_BASE 0x0E100000
  59. #define IOSCB_CFM_SGMII_BASE 0x0E200000
  60. #define IOSCB_BC_SGMII_BASE 0x0E400000
  61. #define IOSCB_IO_CALIB_SGMII_BASE 0x0E800000
  62. static uint64_t mchp_pfsoc_dummy_read(void *opaque, hwaddr offset,
  63. unsigned size)
  64. {
  65. qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
  66. "(size %d, offset 0x%" HWADDR_PRIx ")\n",
  67. __func__, size, offset);
  68. return 0;
  69. }
  70. static void mchp_pfsoc_dummy_write(void *opaque, hwaddr offset,
  71. uint64_t value, unsigned size)
  72. {
  73. qemu_log_mask(LOG_UNIMP, "%s: unimplemented device write "
  74. "(size %d, value 0x%" PRIx64
  75. ", offset 0x%" HWADDR_PRIx ")\n",
  76. __func__, size, value, offset);
  77. }
  78. static const MemoryRegionOps mchp_pfsoc_dummy_ops = {
  79. .read = mchp_pfsoc_dummy_read,
  80. .write = mchp_pfsoc_dummy_write,
  81. .endianness = DEVICE_LITTLE_ENDIAN,
  82. };
  83. /* All PLL modules in IOSCB have the same register layout */
  84. #define PLL_CTRL 0x04
  85. static uint64_t mchp_pfsoc_pll_read(void *opaque, hwaddr offset,
  86. unsigned size)
  87. {
  88. uint32_t val = 0;
  89. switch (offset) {
  90. case PLL_CTRL:
  91. /* PLL is locked */
  92. val = BIT(25);
  93. break;
  94. default:
  95. qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
  96. "(size %d, offset 0x%" HWADDR_PRIx ")\n",
  97. __func__, size, offset);
  98. break;
  99. }
  100. return val;
  101. }
  102. static const MemoryRegionOps mchp_pfsoc_pll_ops = {
  103. .read = mchp_pfsoc_pll_read,
  104. .write = mchp_pfsoc_dummy_write,
  105. .endianness = DEVICE_LITTLE_ENDIAN,
  106. };
  107. /* IO_CALIB_DDR submodule */
  108. #define IO_CALIB_DDR_IOC_REG1 0x08
  109. static uint64_t mchp_pfsoc_io_calib_ddr_read(void *opaque, hwaddr offset,
  110. unsigned size)
  111. {
  112. uint32_t val = 0;
  113. switch (offset) {
  114. case IO_CALIB_DDR_IOC_REG1:
  115. /* calibration completed */
  116. val = BIT(2);
  117. break;
  118. default:
  119. qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
  120. "(size %d, offset 0x%" HWADDR_PRIx ")\n",
  121. __func__, size, offset);
  122. break;
  123. }
  124. return val;
  125. }
  126. static const MemoryRegionOps mchp_pfsoc_io_calib_ddr_ops = {
  127. .read = mchp_pfsoc_io_calib_ddr_read,
  128. .write = mchp_pfsoc_dummy_write,
  129. .endianness = DEVICE_LITTLE_ENDIAN,
  130. };
  131. #define SERVICES_CR 0x50
  132. #define SERVICES_SR 0x54
  133. #define SERVICES_STATUS_SHIFT 16
  134. static uint64_t mchp_pfsoc_ctrl_read(void *opaque, hwaddr offset,
  135. unsigned size)
  136. {
  137. uint32_t val = 0;
  138. switch (offset) {
  139. case SERVICES_SR:
  140. /*
  141. * Although some services have no error codes, most do. All services
  142. * that do implement errors, begin their error codes at 1. Treat all
  143. * service requests as failures & return 1.
  144. * See the "PolarFire® FPGA and PolarFire SoC FPGA System Services"
  145. * user guide for more information on service error codes.
  146. */
  147. val = 1u << SERVICES_STATUS_SHIFT;
  148. break;
  149. default:
  150. qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
  151. "(size %d, offset 0x%" HWADDR_PRIx ")\n",
  152. __func__, size, offset);
  153. }
  154. return val;
  155. }
  156. static void mchp_pfsoc_ctrl_write(void *opaque, hwaddr offset,
  157. uint64_t value, unsigned size)
  158. {
  159. MchpPfSoCIoscbState *s = opaque;
  160. switch (offset) {
  161. case SERVICES_CR:
  162. qemu_irq_raise(s->irq);
  163. break;
  164. default:
  165. qemu_log_mask(LOG_UNIMP, "%s: unimplemented device write "
  166. "(size %d, value 0x%" PRIx64
  167. ", offset 0x%" HWADDR_PRIx ")\n",
  168. __func__, size, value, offset);
  169. }
  170. }
  171. static const MemoryRegionOps mchp_pfsoc_ctrl_ops = {
  172. .read = mchp_pfsoc_ctrl_read,
  173. .write = mchp_pfsoc_ctrl_write,
  174. .endianness = DEVICE_LITTLE_ENDIAN,
  175. };
  176. static void mchp_pfsoc_ioscb_realize(DeviceState *dev, Error **errp)
  177. {
  178. MchpPfSoCIoscbState *s = MCHP_PFSOC_IOSCB(dev);
  179. SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
  180. memory_region_init(&s->container, OBJECT(s),
  181. "mchp.pfsoc.ioscb", IOSCB_WHOLE_REG_SIZE);
  182. sysbus_init_mmio(sbd, &s->container);
  183. /* add subregions for all sub-modules in IOSCB */
  184. memory_region_init_io(&s->lane01, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
  185. "mchp.pfsoc.ioscb.lane01", IOSCB_SUBMOD_REG_SIZE);
  186. memory_region_add_subregion(&s->container, IOSCB_LANE01_BASE, &s->lane01);
  187. memory_region_init_io(&s->lane23, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
  188. "mchp.pfsoc.ioscb.lane23", IOSCB_SUBMOD_REG_SIZE);
  189. memory_region_add_subregion(&s->container, IOSCB_LANE23_BASE, &s->lane23);
  190. memory_region_init_io(&s->ctrl, OBJECT(s), &mchp_pfsoc_ctrl_ops, s,
  191. "mchp.pfsoc.ioscb.ctrl", IOSCB_CTRL_REG_SIZE);
  192. memory_region_add_subregion(&s->container, IOSCB_CTRL_BASE, &s->ctrl);
  193. memory_region_init_io(&s->qspixip, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
  194. "mchp.pfsoc.ioscb.qspixip", IOSCB_QSPIXIP_REG_SIZE);
  195. memory_region_add_subregion(&s->container, IOSCB_QSPIXIP_BASE, &s->qspixip);
  196. memory_region_init_io(&s->mailbox, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
  197. "mchp.pfsoc.ioscb.mailbox", IOSCB_SUBMOD_REG_SIZE);
  198. memory_region_add_subregion(&s->container, IOSCB_MAILBOX_BASE, &s->mailbox);
  199. memory_region_init_io(&s->cfg, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
  200. "mchp.pfsoc.ioscb.cfg", IOSCB_SUBMOD_REG_SIZE);
  201. memory_region_add_subregion(&s->container, IOSCB_CFG_BASE, &s->cfg);
  202. memory_region_init_io(&s->ccc, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
  203. "mchp.pfsoc.ioscb.ccc", IOSCB_CCC_REG_SIZE);
  204. memory_region_add_subregion(&s->container, IOSCB_CCC_BASE, &s->ccc);
  205. memory_region_init_io(&s->pll_mss, OBJECT(s), &mchp_pfsoc_pll_ops, s,
  206. "mchp.pfsoc.ioscb.pll_mss", IOSCB_SUBMOD_REG_SIZE);
  207. memory_region_add_subregion(&s->container, IOSCB_PLL_MSS_BASE, &s->pll_mss);
  208. memory_region_init_io(&s->cfm_mss, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
  209. "mchp.pfsoc.ioscb.cfm_mss", IOSCB_SUBMOD_REG_SIZE);
  210. memory_region_add_subregion(&s->container, IOSCB_CFM_MSS_BASE, &s->cfm_mss);
  211. memory_region_init_io(&s->pll_ddr, OBJECT(s), &mchp_pfsoc_pll_ops, s,
  212. "mchp.pfsoc.ioscb.pll_ddr", IOSCB_SUBMOD_REG_SIZE);
  213. memory_region_add_subregion(&s->container, IOSCB_PLL_DDR_BASE, &s->pll_ddr);
  214. memory_region_init_io(&s->bc_ddr, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
  215. "mchp.pfsoc.ioscb.bc_ddr", IOSCB_SUBMOD_REG_SIZE);
  216. memory_region_add_subregion(&s->container, IOSCB_BC_DDR_BASE, &s->bc_ddr);
  217. memory_region_init_io(&s->io_calib_ddr, OBJECT(s),
  218. &mchp_pfsoc_io_calib_ddr_ops, s,
  219. "mchp.pfsoc.ioscb.io_calib_ddr",
  220. IOSCB_SUBMOD_REG_SIZE);
  221. memory_region_add_subregion(&s->container, IOSCB_IO_CALIB_DDR_BASE,
  222. &s->io_calib_ddr);
  223. memory_region_init_io(&s->pll_sgmii, OBJECT(s), &mchp_pfsoc_pll_ops, s,
  224. "mchp.pfsoc.ioscb.pll_sgmii", IOSCB_SUBMOD_REG_SIZE);
  225. memory_region_add_subregion(&s->container, IOSCB_PLL_SGMII_BASE,
  226. &s->pll_sgmii);
  227. memory_region_init_io(&s->dll_sgmii, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
  228. "mchp.pfsoc.ioscb.dll_sgmii", IOSCB_SUBMOD_REG_SIZE);
  229. memory_region_add_subregion(&s->container, IOSCB_DLL_SGMII_BASE,
  230. &s->dll_sgmii);
  231. memory_region_init_io(&s->cfm_sgmii, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
  232. "mchp.pfsoc.ioscb.cfm_sgmii", IOSCB_SUBMOD_REG_SIZE);
  233. memory_region_add_subregion(&s->container, IOSCB_CFM_SGMII_BASE,
  234. &s->cfm_sgmii);
  235. memory_region_init_io(&s->bc_sgmii, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
  236. "mchp.pfsoc.ioscb.bc_sgmii", IOSCB_SUBMOD_REG_SIZE);
  237. memory_region_add_subregion(&s->container, IOSCB_BC_SGMII_BASE,
  238. &s->bc_sgmii);
  239. memory_region_init_io(&s->io_calib_sgmii, OBJECT(s), &mchp_pfsoc_dummy_ops,
  240. s, "mchp.pfsoc.ioscb.io_calib_sgmii",
  241. IOSCB_SUBMOD_REG_SIZE);
  242. memory_region_add_subregion(&s->container, IOSCB_IO_CALIB_SGMII_BASE,
  243. &s->io_calib_sgmii);
  244. sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq);
  245. }
  246. static void mchp_pfsoc_ioscb_class_init(ObjectClass *klass, void *data)
  247. {
  248. DeviceClass *dc = DEVICE_CLASS(klass);
  249. dc->desc = "Microchip PolarFire SoC IOSCB modules";
  250. dc->realize = mchp_pfsoc_ioscb_realize;
  251. }
  252. static const TypeInfo mchp_pfsoc_ioscb_info = {
  253. .name = TYPE_MCHP_PFSOC_IOSCB,
  254. .parent = TYPE_SYS_BUS_DEVICE,
  255. .instance_size = sizeof(MchpPfSoCIoscbState),
  256. .class_init = mchp_pfsoc_ioscb_class_init,
  257. };
  258. static void mchp_pfsoc_ioscb_register_types(void)
  259. {
  260. type_register_static(&mchp_pfsoc_ioscb_info);
  261. }
  262. type_init(mchp_pfsoc_ioscb_register_types)