sysbus.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef HW_SYSBUS_H
  2. #define HW_SYSBUS_H 1
  3. /* Devices attached directly to the main system bus. */
  4. #include "qdev.h"
  5. #include "exec/memory.h"
  6. #define QDEV_MAX_MMIO 32
  7. #define QDEV_MAX_PIO 32
  8. #define QDEV_MAX_IRQ 512
  9. #define TYPE_SYSTEM_BUS "System"
  10. #define SYSTEM_BUS(obj) OBJECT_CHECK(IDEBus, (obj), TYPE_IDE_BUS)
  11. typedef struct SysBusDevice SysBusDevice;
  12. #define TYPE_SYS_BUS_DEVICE "sys-bus-device"
  13. #define SYS_BUS_DEVICE(obj) \
  14. OBJECT_CHECK(SysBusDevice, (obj), TYPE_SYS_BUS_DEVICE)
  15. #define SYS_BUS_DEVICE_CLASS(klass) \
  16. OBJECT_CLASS_CHECK(SysBusDeviceClass, (klass), TYPE_SYS_BUS_DEVICE)
  17. #define SYS_BUS_DEVICE_GET_CLASS(obj) \
  18. OBJECT_GET_CLASS(SysBusDeviceClass, (obj), TYPE_SYS_BUS_DEVICE)
  19. typedef struct SysBusDeviceClass {
  20. DeviceClass parent_class;
  21. int (*init)(SysBusDevice *dev);
  22. } SysBusDeviceClass;
  23. struct SysBusDevice {
  24. DeviceState qdev;
  25. int num_irq;
  26. qemu_irq irqs[QDEV_MAX_IRQ];
  27. qemu_irq *irqp[QDEV_MAX_IRQ];
  28. int num_mmio;
  29. struct {
  30. hwaddr addr;
  31. MemoryRegion *memory;
  32. } mmio[QDEV_MAX_MMIO];
  33. int num_pio;
  34. pio_addr_t pio[QDEV_MAX_PIO];
  35. };
  36. /* Macros to compensate for lack of type inheritance in C. */
  37. #define FROM_SYSBUS(type, dev) DO_UPCAST(type, busdev, dev)
  38. void *sysbus_new(void);
  39. void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
  40. MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
  41. void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
  42. void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
  43. void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size);
  44. void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
  45. void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr);
  46. void sysbus_add_memory(SysBusDevice *dev, hwaddr addr,
  47. MemoryRegion *mem);
  48. void sysbus_add_memory_overlap(SysBusDevice *dev, hwaddr addr,
  49. MemoryRegion *mem, unsigned priority);
  50. void sysbus_del_memory(SysBusDevice *dev, MemoryRegion *mem);
  51. void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
  52. MemoryRegion *mem);
  53. void sysbus_del_io(SysBusDevice *dev, MemoryRegion *mem);
  54. MemoryRegion *sysbus_address_space(SysBusDevice *dev);
  55. /* Legacy helper function for creating devices. */
  56. DeviceState *sysbus_create_varargs(const char *name,
  57. hwaddr addr, ...);
  58. DeviceState *sysbus_try_create_varargs(const char *name,
  59. hwaddr addr, ...);
  60. static inline DeviceState *sysbus_create_simple(const char *name,
  61. hwaddr addr,
  62. qemu_irq irq)
  63. {
  64. return sysbus_create_varargs(name, addr, irq, NULL);
  65. }
  66. static inline DeviceState *sysbus_try_create_simple(const char *name,
  67. hwaddr addr,
  68. qemu_irq irq)
  69. {
  70. return sysbus_try_create_varargs(name, addr, irq, NULL);
  71. }
  72. #endif /* !HW_SYSBUS_H */