sysbus.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 "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. target_phys_addr_t 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 sysbus_from_qdev(dev) ((SysBusDevice *)(dev))
  38. #define FROM_SYSBUS(type, dev) DO_UPCAST(type, busdev, dev)
  39. void *sysbus_new(void);
  40. void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
  41. MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
  42. void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
  43. void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
  44. void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size);
  45. void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
  46. void sysbus_mmio_map(SysBusDevice *dev, int n, target_phys_addr_t addr);
  47. void sysbus_add_memory(SysBusDevice *dev, target_phys_addr_t addr,
  48. MemoryRegion *mem);
  49. void sysbus_add_memory_overlap(SysBusDevice *dev, target_phys_addr_t addr,
  50. MemoryRegion *mem, unsigned priority);
  51. void sysbus_del_memory(SysBusDevice *dev, MemoryRegion *mem);
  52. void sysbus_add_io(SysBusDevice *dev, target_phys_addr_t addr,
  53. MemoryRegion *mem);
  54. void sysbus_del_io(SysBusDevice *dev, MemoryRegion *mem);
  55. MemoryRegion *sysbus_address_space(SysBusDevice *dev);
  56. /* Legacy helper function for creating devices. */
  57. DeviceState *sysbus_create_varargs(const char *name,
  58. target_phys_addr_t addr, ...);
  59. DeviceState *sysbus_try_create_varargs(const char *name,
  60. target_phys_addr_t addr, ...);
  61. static inline DeviceState *sysbus_create_simple(const char *name,
  62. target_phys_addr_t addr,
  63. qemu_irq irq)
  64. {
  65. return sysbus_create_varargs(name, addr, irq, NULL);
  66. }
  67. static inline DeviceState *sysbus_try_create_simple(const char *name,
  68. target_phys_addr_t addr,
  69. qemu_irq irq)
  70. {
  71. return sysbus_try_create_varargs(name, addr, irq, NULL);
  72. }
  73. #endif /* !HW_SYSBUS_H */