empty_slot.c 2.4 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 "hw/hw.h"
  12. #include "hw/sysbus.h"
  13. #include "hw/empty_slot.h"
  14. //#define DEBUG_EMPTY_SLOT
  15. #ifdef DEBUG_EMPTY_SLOT
  16. #define DPRINTF(fmt, ...) \
  17. do { printf("empty_slot: " fmt , ## __VA_ARGS__); } while (0)
  18. #else
  19. #define DPRINTF(fmt, ...) do {} while (0)
  20. #endif
  21. #define TYPE_EMPTY_SLOT "empty_slot"
  22. #define EMPTY_SLOT(obj) OBJECT_CHECK(EmptySlot, (obj), TYPE_EMPTY_SLOT)
  23. typedef struct EmptySlot {
  24. SysBusDevice parent_obj;
  25. MemoryRegion iomem;
  26. uint64_t size;
  27. } EmptySlot;
  28. static uint64_t empty_slot_read(void *opaque, hwaddr addr,
  29. unsigned size)
  30. {
  31. DPRINTF("read from " TARGET_FMT_plx "\n", addr);
  32. return 0;
  33. }
  34. static void empty_slot_write(void *opaque, hwaddr addr,
  35. uint64_t val, unsigned size)
  36. {
  37. DPRINTF("write 0x%x to " TARGET_FMT_plx "\n", (unsigned)val, addr);
  38. }
  39. static const MemoryRegionOps empty_slot_ops = {
  40. .read = empty_slot_read,
  41. .write = empty_slot_write,
  42. .endianness = DEVICE_NATIVE_ENDIAN,
  43. };
  44. void empty_slot_init(hwaddr addr, uint64_t slot_size)
  45. {
  46. if (slot_size > 0) {
  47. /* Only empty slots larger than 0 byte need handling. */
  48. DeviceState *dev;
  49. SysBusDevice *s;
  50. EmptySlot *e;
  51. dev = qdev_create(NULL, TYPE_EMPTY_SLOT);
  52. s = SYS_BUS_DEVICE(dev);
  53. e = EMPTY_SLOT(dev);
  54. e->size = slot_size;
  55. qdev_init_nofail(dev);
  56. sysbus_mmio_map(s, 0, addr);
  57. }
  58. }
  59. static int empty_slot_init1(SysBusDevice *dev)
  60. {
  61. EmptySlot *s = EMPTY_SLOT(dev);
  62. memory_region_init_io(&s->iomem, OBJECT(s), &empty_slot_ops, s,
  63. "empty-slot", s->size);
  64. sysbus_init_mmio(dev, &s->iomem);
  65. return 0;
  66. }
  67. static void empty_slot_class_init(ObjectClass *klass, void *data)
  68. {
  69. SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
  70. k->init = empty_slot_init1;
  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)