empty_slot.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. uint64_t size;
  24. } EmptySlot;
  25. static uint32_t empty_slot_readl(void *opaque, target_phys_addr_t addr)
  26. {
  27. DPRINTF("read from " TARGET_FMT_plx "\n", addr);
  28. return 0;
  29. }
  30. static void empty_slot_writel(void *opaque, target_phys_addr_t addr,
  31. uint32_t val)
  32. {
  33. DPRINTF("write 0x%x to " TARGET_FMT_plx "\n", val, addr);
  34. }
  35. CPUReadMemoryFunc * const empty_slot_read[3] = {
  36. empty_slot_readl,
  37. empty_slot_readl,
  38. empty_slot_readl,
  39. };
  40. static CPUWriteMemoryFunc * const empty_slot_write[3] = {
  41. empty_slot_writel,
  42. empty_slot_writel,
  43. empty_slot_writel,
  44. };
  45. void empty_slot_init(target_phys_addr_t 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, "empty_slot");
  53. s = sysbus_from_qdev(dev);
  54. e = FROM_SYSBUS(EmptySlot, s);
  55. e->size = slot_size;
  56. qdev_init_nofail(dev);
  57. sysbus_mmio_map(s, 0, addr);
  58. }
  59. }
  60. static int empty_slot_init1(SysBusDevice *dev)
  61. {
  62. EmptySlot *s = FROM_SYSBUS(EmptySlot, dev);
  63. ram_addr_t empty_slot_offset;
  64. empty_slot_offset = cpu_register_io_memory(empty_slot_read,
  65. empty_slot_write, s,
  66. DEVICE_NATIVE_ENDIAN);
  67. sysbus_init_mmio(dev, s->size, empty_slot_offset | IO_MEM_RAM);
  68. return 0;
  69. }
  70. static SysBusDeviceInfo empty_slot_info = {
  71. .init = empty_slot_init1,
  72. .qdev.name = "empty_slot",
  73. .qdev.size = sizeof(EmptySlot),
  74. };
  75. static void empty_slot_register_devices(void)
  76. {
  77. sysbus_register_withprop(&empty_slot_info);
  78. }
  79. device_init(empty_slot_register_devices);