unimp.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* "Unimplemented" device
  2. *
  3. * This is a dummy device which accepts and logs all accesses.
  4. * It's useful for stubbing out regions of an SoC or board
  5. * map which correspond to devices that have not yet been
  6. * implemented. This is often sufficient to placate initial
  7. * guest device driver probing such that the system will
  8. * come up.
  9. *
  10. * Copyright Linaro Limited, 2017
  11. * Written by Peter Maydell
  12. */
  13. #include "qemu/osdep.h"
  14. #include "hw/sysbus.h"
  15. #include "hw/misc/unimp.h"
  16. #include "qemu/log.h"
  17. #include "qemu/module.h"
  18. #include "qapi/error.h"
  19. static uint64_t unimp_read(void *opaque, hwaddr offset, unsigned size)
  20. {
  21. UnimplementedDeviceState *s = UNIMPLEMENTED_DEVICE(opaque);
  22. qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
  23. "(size %d, offset 0x%0*" HWADDR_PRIx ")\n",
  24. s->name, size, s->offset_fmt_width, offset);
  25. return 0;
  26. }
  27. static void unimp_write(void *opaque, hwaddr offset,
  28. uint64_t value, unsigned size)
  29. {
  30. UnimplementedDeviceState *s = UNIMPLEMENTED_DEVICE(opaque);
  31. qemu_log_mask(LOG_UNIMP, "%s: unimplemented device write "
  32. "(size %d, offset 0x%0*" HWADDR_PRIx
  33. ", value 0x%0*" PRIx64 ")\n",
  34. s->name, size, s->offset_fmt_width, offset, size << 1, value);
  35. }
  36. static const MemoryRegionOps unimp_ops = {
  37. .read = unimp_read,
  38. .write = unimp_write,
  39. .impl.min_access_size = 1,
  40. .impl.max_access_size = 8,
  41. .valid.min_access_size = 1,
  42. .valid.max_access_size = 8,
  43. .endianness = DEVICE_NATIVE_ENDIAN,
  44. };
  45. static void unimp_realize(DeviceState *dev, Error **errp)
  46. {
  47. UnimplementedDeviceState *s = UNIMPLEMENTED_DEVICE(dev);
  48. if (s->size == 0) {
  49. error_setg(errp, "property 'size' not specified or zero");
  50. return;
  51. }
  52. if (s->name == NULL) {
  53. error_setg(errp, "property 'name' not specified");
  54. return;
  55. }
  56. s->offset_fmt_width = DIV_ROUND_UP(64 - clz64(s->size - 1), 4);
  57. memory_region_init_io(&s->iomem, OBJECT(s), &unimp_ops, s,
  58. s->name, s->size);
  59. sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem);
  60. }
  61. static Property unimp_properties[] = {
  62. DEFINE_PROP_UINT64("size", UnimplementedDeviceState, size, 0),
  63. DEFINE_PROP_STRING("name", UnimplementedDeviceState, name),
  64. DEFINE_PROP_END_OF_LIST(),
  65. };
  66. static void unimp_class_init(ObjectClass *klass, void *data)
  67. {
  68. DeviceClass *dc = DEVICE_CLASS(klass);
  69. dc->realize = unimp_realize;
  70. device_class_set_props(dc, unimp_properties);
  71. }
  72. static const TypeInfo unimp_info = {
  73. .name = TYPE_UNIMPLEMENTED_DEVICE,
  74. .parent = TYPE_SYS_BUS_DEVICE,
  75. .instance_size = sizeof(UnimplementedDeviceState),
  76. .class_init = unimp_class_init,
  77. };
  78. static void unimp_register_types(void)
  79. {
  80. type_register_static(&unimp_info);
  81. }
  82. type_init(unimp_register_types)