unimp.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 const Property unimp_properties[] = {
  62. DEFINE_PROP_UINT64("size", UnimplementedDeviceState, size, 0),
  63. DEFINE_PROP_STRING("name", UnimplementedDeviceState, name),
  64. };
  65. static void unimp_class_init(ObjectClass *klass, void *data)
  66. {
  67. DeviceClass *dc = DEVICE_CLASS(klass);
  68. dc->realize = unimp_realize;
  69. device_class_set_props(dc, unimp_properties);
  70. }
  71. static const TypeInfo unimp_info = {
  72. .name = TYPE_UNIMPLEMENTED_DEVICE,
  73. .parent = TYPE_SYS_BUS_DEVICE,
  74. .instance_size = sizeof(UnimplementedDeviceState),
  75. .class_init = unimp_class_init,
  76. };
  77. static void unimp_register_types(void)
  78. {
  79. type_register_static(&unimp_info);
  80. }
  81. type_init(unimp_register_types)