iotkit-sysinfo.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * ARM IoTKit system information block
  3. *
  4. * Copyright (c) 2018 Linaro Limited
  5. * Written by Peter Maydell
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 or
  9. * (at your option) any later version.
  10. */
  11. /*
  12. * This is a model of the "system information block" which is part of the
  13. * Arm IoTKit and documented in
  14. * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
  15. * It consists of 2 read-only version/config registers, plus the
  16. * usual ID registers.
  17. */
  18. #include "qemu/osdep.h"
  19. #include "qemu/log.h"
  20. #include "qemu/module.h"
  21. #include "trace.h"
  22. #include "qapi/error.h"
  23. #include "hw/sysbus.h"
  24. #include "hw/registerfields.h"
  25. #include "hw/misc/iotkit-sysinfo.h"
  26. #include "hw/qdev-properties.h"
  27. REG32(SYS_VERSION, 0x0)
  28. REG32(SYS_CONFIG, 0x4)
  29. REG32(PID4, 0xfd0)
  30. REG32(PID5, 0xfd4)
  31. REG32(PID6, 0xfd8)
  32. REG32(PID7, 0xfdc)
  33. REG32(PID0, 0xfe0)
  34. REG32(PID1, 0xfe4)
  35. REG32(PID2, 0xfe8)
  36. REG32(PID3, 0xfec)
  37. REG32(CID0, 0xff0)
  38. REG32(CID1, 0xff4)
  39. REG32(CID2, 0xff8)
  40. REG32(CID3, 0xffc)
  41. /* PID/CID values */
  42. static const int sysinfo_id[] = {
  43. 0x04, 0x00, 0x00, 0x00, /* PID4..PID7 */
  44. 0x58, 0xb8, 0x0b, 0x00, /* PID0..PID3 */
  45. 0x0d, 0xf0, 0x05, 0xb1, /* CID0..CID3 */
  46. };
  47. static uint64_t iotkit_sysinfo_read(void *opaque, hwaddr offset,
  48. unsigned size)
  49. {
  50. IoTKitSysInfo *s = IOTKIT_SYSINFO(opaque);
  51. uint64_t r;
  52. switch (offset) {
  53. case A_SYS_VERSION:
  54. r = s->sys_version;
  55. break;
  56. case A_SYS_CONFIG:
  57. r = s->sys_config;
  58. break;
  59. case A_PID4 ... A_CID3:
  60. r = sysinfo_id[(offset - A_PID4) / 4];
  61. break;
  62. default:
  63. qemu_log_mask(LOG_GUEST_ERROR,
  64. "IoTKit SysInfo read: bad offset %x\n", (int)offset);
  65. r = 0;
  66. break;
  67. }
  68. trace_iotkit_sysinfo_read(offset, r, size);
  69. return r;
  70. }
  71. static void iotkit_sysinfo_write(void *opaque, hwaddr offset,
  72. uint64_t value, unsigned size)
  73. {
  74. trace_iotkit_sysinfo_write(offset, value, size);
  75. qemu_log_mask(LOG_GUEST_ERROR,
  76. "IoTKit SysInfo: write to RO offset 0x%x\n", (int)offset);
  77. }
  78. static const MemoryRegionOps iotkit_sysinfo_ops = {
  79. .read = iotkit_sysinfo_read,
  80. .write = iotkit_sysinfo_write,
  81. .endianness = DEVICE_LITTLE_ENDIAN,
  82. /* byte/halfword accesses are just zero-padded on reads and writes */
  83. .impl.min_access_size = 4,
  84. .impl.max_access_size = 4,
  85. .valid.min_access_size = 1,
  86. .valid.max_access_size = 4,
  87. };
  88. static Property iotkit_sysinfo_props[] = {
  89. DEFINE_PROP_UINT32("SYS_VERSION", IoTKitSysInfo, sys_version, 0),
  90. DEFINE_PROP_UINT32("SYS_CONFIG", IoTKitSysInfo, sys_config, 0),
  91. DEFINE_PROP_END_OF_LIST()
  92. };
  93. static void iotkit_sysinfo_init(Object *obj)
  94. {
  95. SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
  96. IoTKitSysInfo *s = IOTKIT_SYSINFO(obj);
  97. memory_region_init_io(&s->iomem, obj, &iotkit_sysinfo_ops,
  98. s, "iotkit-sysinfo", 0x1000);
  99. sysbus_init_mmio(sbd, &s->iomem);
  100. }
  101. static void iotkit_sysinfo_class_init(ObjectClass *klass, void *data)
  102. {
  103. DeviceClass *dc = DEVICE_CLASS(klass);
  104. /*
  105. * This device has no guest-modifiable state and so it
  106. * does not need a reset function or VMState.
  107. */
  108. dc->props = iotkit_sysinfo_props;
  109. }
  110. static const TypeInfo iotkit_sysinfo_info = {
  111. .name = TYPE_IOTKIT_SYSINFO,
  112. .parent = TYPE_SYS_BUS_DEVICE,
  113. .instance_size = sizeof(IoTKitSysInfo),
  114. .instance_init = iotkit_sysinfo_init,
  115. .class_init = iotkit_sysinfo_class_init,
  116. };
  117. static void iotkit_sysinfo_register_types(void)
  118. {
  119. type_register_static(&iotkit_sysinfo_info);
  120. }
  121. type_init(iotkit_sysinfo_register_types);