mchp_pfsoc_sysreg.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Microchip PolarFire SoC SYSREG 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_sysreg.h"
  29. #define ENVM_CR 0xb8
  30. #define MESSAGE_INT 0x118c
  31. static uint64_t mchp_pfsoc_sysreg_read(void *opaque, hwaddr offset,
  32. unsigned size)
  33. {
  34. uint32_t val = 0;
  35. switch (offset) {
  36. case ENVM_CR:
  37. /* Indicate the eNVM is running at the configured divider rate */
  38. val = BIT(6);
  39. break;
  40. default:
  41. qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
  42. "(size %d, offset 0x%" HWADDR_PRIx ")\n",
  43. __func__, size, offset);
  44. break;
  45. }
  46. return val;
  47. }
  48. static void mchp_pfsoc_sysreg_write(void *opaque, hwaddr offset,
  49. uint64_t value, unsigned size)
  50. {
  51. MchpPfSoCSysregState *s = opaque;
  52. switch (offset) {
  53. case MESSAGE_INT:
  54. qemu_irq_lower(s->irq);
  55. break;
  56. default:
  57. qemu_log_mask(LOG_UNIMP, "%s: unimplemented device write "
  58. "(size %d, value 0x%" PRIx64
  59. ", offset 0x%" HWADDR_PRIx ")\n",
  60. __func__, size, value, offset);
  61. }
  62. }
  63. static const MemoryRegionOps mchp_pfsoc_sysreg_ops = {
  64. .read = mchp_pfsoc_sysreg_read,
  65. .write = mchp_pfsoc_sysreg_write,
  66. .endianness = DEVICE_LITTLE_ENDIAN,
  67. };
  68. static void mchp_pfsoc_sysreg_realize(DeviceState *dev, Error **errp)
  69. {
  70. MchpPfSoCSysregState *s = MCHP_PFSOC_SYSREG(dev);
  71. memory_region_init_io(&s->sysreg, OBJECT(dev),
  72. &mchp_pfsoc_sysreg_ops, s,
  73. "mchp.pfsoc.sysreg",
  74. MCHP_PFSOC_SYSREG_REG_SIZE);
  75. sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->sysreg);
  76. sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq);
  77. }
  78. static void mchp_pfsoc_sysreg_class_init(ObjectClass *klass, void *data)
  79. {
  80. DeviceClass *dc = DEVICE_CLASS(klass);
  81. dc->desc = "Microchip PolarFire SoC SYSREG module";
  82. dc->realize = mchp_pfsoc_sysreg_realize;
  83. }
  84. static const TypeInfo mchp_pfsoc_sysreg_info = {
  85. .name = TYPE_MCHP_PFSOC_SYSREG,
  86. .parent = TYPE_SYS_BUS_DEVICE,
  87. .instance_size = sizeof(MchpPfSoCSysregState),
  88. .class_init = mchp_pfsoc_sysreg_class_init,
  89. };
  90. static void mchp_pfsoc_sysreg_register_types(void)
  91. {
  92. type_register_static(&mchp_pfsoc_sysreg_info);
  93. }
  94. type_init(mchp_pfsoc_sysreg_register_types)