empty_slot.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 "hw/qdev-properties.h"
  14. #include "hw/misc/empty_slot.h"
  15. #include "qapi/error.h"
  16. #include "trace.h"
  17. #include "qom/object.h"
  18. #define TYPE_EMPTY_SLOT "empty_slot"
  19. OBJECT_DECLARE_SIMPLE_TYPE(EmptySlot, EMPTY_SLOT)
  20. struct EmptySlot {
  21. SysBusDevice parent_obj;
  22. MemoryRegion iomem;
  23. char *name;
  24. uint64_t size;
  25. };
  26. static uint64_t empty_slot_read(void *opaque, hwaddr addr,
  27. unsigned size)
  28. {
  29. EmptySlot *s = EMPTY_SLOT(opaque);
  30. trace_empty_slot_write(addr, size << 1, 0, size, s->name);
  31. return 0;
  32. }
  33. static void empty_slot_write(void *opaque, hwaddr addr,
  34. uint64_t val, unsigned size)
  35. {
  36. EmptySlot *s = EMPTY_SLOT(opaque);
  37. trace_empty_slot_write(addr, size << 1, val, size, s->name);
  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(const char *name, 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. dev = qdev_new(TYPE_EMPTY_SLOT);
  50. qdev_prop_set_uint64(dev, "size", slot_size);
  51. sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
  52. sysbus_mmio_map_overlap(SYS_BUS_DEVICE(dev), 0, addr, -10000);
  53. }
  54. }
  55. static void empty_slot_realize(DeviceState *dev, Error **errp)
  56. {
  57. EmptySlot *s = EMPTY_SLOT(dev);
  58. if (s->name == NULL) {
  59. s->name = g_strdup("empty-slot");
  60. }
  61. memory_region_init_io(&s->iomem, OBJECT(s), &empty_slot_ops, s,
  62. s->name, s->size);
  63. sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
  64. }
  65. static const Property empty_slot_properties[] = {
  66. DEFINE_PROP_UINT64("size", EmptySlot, size, 0),
  67. DEFINE_PROP_STRING("name", EmptySlot, name),
  68. };
  69. static void empty_slot_class_init(ObjectClass *klass, void *data)
  70. {
  71. DeviceClass *dc = DEVICE_CLASS(klass);
  72. dc->realize = empty_slot_realize;
  73. device_class_set_props(dc, empty_slot_properties);
  74. set_bit(DEVICE_CATEGORY_MISC, dc->categories);
  75. }
  76. static const TypeInfo empty_slot_info = {
  77. .name = TYPE_EMPTY_SLOT,
  78. .parent = TYPE_SYS_BUS_DEVICE,
  79. .instance_size = sizeof(EmptySlot),
  80. .class_init = empty_slot_class_init,
  81. };
  82. static void empty_slot_register_types(void)
  83. {
  84. type_register_static(&empty_slot_info);
  85. }
  86. type_init(empty_slot_register_types)