2
0

unimp.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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%" HWADDR_PRIx ")\n",
  24. s->name, size, 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, value 0x%" PRIx64
  33. ", offset 0x%" HWADDR_PRIx ")\n",
  34. s->name, size, value, offset);
  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. memory_region_init_io(&s->iomem, OBJECT(s), &unimp_ops, s,
  57. s->name, s->size);
  58. sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem);
  59. }
  60. static Property unimp_properties[] = {
  61. DEFINE_PROP_UINT64("size", UnimplementedDeviceState, size, 0),
  62. DEFINE_PROP_STRING("name", UnimplementedDeviceState, name),
  63. DEFINE_PROP_END_OF_LIST(),
  64. };
  65. static void unimp_class_init(ObjectClass *klass, void *data)
  66. {
  67. DeviceClass *dc = DEVICE_CLASS(klass);
  68. dc->realize = unimp_realize;
  69. dc->props = 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)