empty_slot.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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.h"
  12. #include "sysbus.h"
  13. #include "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. typedef struct EmptySlot {
  22. SysBusDevice busdev;
  23. MemoryRegion iomem;
  24. uint64_t size;
  25. } EmptySlot;
  26. static uint64_t empty_slot_read(void *opaque, target_phys_addr_t addr,
  27. unsigned size)
  28. {
  29. DPRINTF("read from " TARGET_FMT_plx "\n", addr);
  30. return 0;
  31. }
  32. static void empty_slot_write(void *opaque, target_phys_addr_t addr,
  33. uint64_t val, unsigned size)
  34. {
  35. DPRINTF("write 0x%x to " TARGET_FMT_plx "\n", (unsigned)val, addr);
  36. }
  37. static const MemoryRegionOps empty_slot_ops = {
  38. .read = empty_slot_read,
  39. .write = empty_slot_write,
  40. .endianness = DEVICE_NATIVE_ENDIAN,
  41. };
  42. void empty_slot_init(target_phys_addr_t addr, uint64_t slot_size)
  43. {
  44. if (slot_size > 0) {
  45. /* Only empty slots larger than 0 byte need handling. */
  46. DeviceState *dev;
  47. SysBusDevice *s;
  48. EmptySlot *e;
  49. dev = qdev_create(NULL, "empty_slot");
  50. s = sysbus_from_qdev(dev);
  51. e = FROM_SYSBUS(EmptySlot, s);
  52. e->size = slot_size;
  53. qdev_init_nofail(dev);
  54. sysbus_mmio_map(s, 0, addr);
  55. }
  56. }
  57. static int empty_slot_init1(SysBusDevice *dev)
  58. {
  59. EmptySlot *s = FROM_SYSBUS(EmptySlot, dev);
  60. memory_region_init_io(&s->iomem, &empty_slot_ops, s,
  61. "empty-slot", s->size);
  62. sysbus_init_mmio(dev, &s->iomem);
  63. return 0;
  64. }
  65. static void empty_slot_class_init(ObjectClass *klass, void *data)
  66. {
  67. SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
  68. k->init = empty_slot_init1;
  69. }
  70. static TypeInfo empty_slot_info = {
  71. .name = "empty_slot",
  72. .parent = TYPE_SYS_BUS_DEVICE,
  73. .instance_size = sizeof(EmptySlot),
  74. .class_init = empty_slot_class_init,
  75. };
  76. static void empty_slot_register_types(void)
  77. {
  78. type_register_static(&empty_slot_info);
  79. }
  80. type_init(empty_slot_register_types)