empty_slot.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * QEMU Empty Slot
  3. *
  4. * The empty_slot device emulates known to a bus but not connected devices.
  5. *
  6. * Copyright (c) 2010 Artyom Tarasenko
  7. *
  8. * This code is licensed under the GNU GPL v2 or (at your option) any later
  9. * version.
  10. */
  11. #include "qemu/osdep.h"
  12. #include "hw/sysbus.h"
  13. #include "qemu/module.h"
  14. #include "hw/empty_slot.h"
  15. //#define DEBUG_EMPTY_SLOT
  16. #ifdef DEBUG_EMPTY_SLOT
  17. #define DPRINTF(fmt, ...) \
  18. do { printf("empty_slot: " fmt , ## __VA_ARGS__); } while (0)
  19. #else
  20. #define DPRINTF(fmt, ...) do {} while (0)
  21. #endif
  22. #define TYPE_EMPTY_SLOT "empty_slot"
  23. #define EMPTY_SLOT(obj) OBJECT_CHECK(EmptySlot, (obj), TYPE_EMPTY_SLOT)
  24. typedef struct EmptySlot {
  25. SysBusDevice parent_obj;
  26. MemoryRegion iomem;
  27. uint64_t size;
  28. } EmptySlot;
  29. static uint64_t empty_slot_read(void *opaque, hwaddr addr,
  30. unsigned size)
  31. {
  32. DPRINTF("read from " TARGET_FMT_plx "\n", addr);
  33. return 0;
  34. }
  35. static void empty_slot_write(void *opaque, hwaddr addr,
  36. uint64_t val, unsigned size)
  37. {
  38. DPRINTF("write 0x%x to " TARGET_FMT_plx "\n", (unsigned)val, addr);
  39. }
  40. static const MemoryRegionOps empty_slot_ops = {
  41. .read = empty_slot_read,
  42. .write = empty_slot_write,
  43. .endianness = DEVICE_NATIVE_ENDIAN,
  44. };
  45. void empty_slot_init(hwaddr addr, uint64_t slot_size)
  46. {
  47. if (slot_size > 0) {
  48. /* Only empty slots larger than 0 byte need handling. */
  49. DeviceState *dev;
  50. SysBusDevice *s;
  51. EmptySlot *e;
  52. dev = qdev_create(NULL, TYPE_EMPTY_SLOT);
  53. s = SYS_BUS_DEVICE(dev);
  54. e = EMPTY_SLOT(dev);
  55. e->size = slot_size;
  56. qdev_init_nofail(dev);
  57. sysbus_mmio_map(s, 0, addr);
  58. }
  59. }
  60. static void empty_slot_realize(DeviceState *dev, Error **errp)
  61. {
  62. EmptySlot *s = EMPTY_SLOT(dev);
  63. memory_region_init_io(&s->iomem, OBJECT(s), &empty_slot_ops, s,
  64. "empty-slot", s->size);
  65. sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
  66. }
  67. static void empty_slot_class_init(ObjectClass *klass, void *data)
  68. {
  69. DeviceClass *dc = DEVICE_CLASS(klass);
  70. dc->realize = empty_slot_realize;
  71. }
  72. static const TypeInfo empty_slot_info = {
  73. .name = TYPE_EMPTY_SLOT,
  74. .parent = TYPE_SYS_BUS_DEVICE,
  75. .instance_size = sizeof(EmptySlot),
  76. .class_init = empty_slot_class_init,
  77. };
  78. static void empty_slot_register_types(void)
  79. {
  80. type_register_static(&empty_slot_info);
  81. }
  82. type_init(empty_slot_register_types)