2
0

sysbus.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #ifndef HW_SYSBUS_H
  2. #define HW_SYSBUS_H
  3. /* Devices attached directly to the main system bus. */
  4. #include "hw/qdev-core.h"
  5. #include "exec/memory.h"
  6. #include "qom/object.h"
  7. #define QDEV_MAX_MMIO 32
  8. #define QDEV_MAX_PIO 32
  9. #define TYPE_SYSTEM_BUS "System"
  10. DECLARE_INSTANCE_CHECKER(BusState, SYSTEM_BUS,
  11. TYPE_SYSTEM_BUS)
  12. #define TYPE_SYS_BUS_DEVICE "sys-bus-device"
  13. OBJECT_DECLARE_TYPE(SysBusDevice, SysBusDeviceClass,
  14. SYS_BUS_DEVICE)
  15. #define TYPE_DYNAMIC_SYS_BUS_DEVICE "dynamic-sysbus-device"
  16. /**
  17. * SysBusDeviceClass:
  18. *
  19. * SysBusDeviceClass is not overriding #DeviceClass.realize, so derived
  20. * classes overriding it are not required to invoke its implementation.
  21. */
  22. #define SYSBUS_DEVICE_GPIO_IRQ "sysbus-irq"
  23. struct SysBusDeviceClass {
  24. /*< private >*/
  25. DeviceClass parent_class;
  26. /*
  27. * Let the sysbus device format its own non-PIO, non-MMIO unit address.
  28. *
  29. * Sometimes a class of SysBusDevices has neither MMIO nor PIO resources,
  30. * yet instances of it would like to distinguish themselves, in
  31. * OpenFirmware device paths, from other instances of the same class on the
  32. * sysbus. For that end we expose this callback.
  33. *
  34. * The implementation is not supposed to change *@dev, or incur other
  35. * observable change.
  36. *
  37. * The function returns a dynamically allocated string. On error, NULL
  38. * should be returned; the unit address portion of the OFW node will be
  39. * omitted then. (This is not considered a fatal error.)
  40. */
  41. char *(*explicit_ofw_unit_address)(const SysBusDevice *dev);
  42. void (*connect_irq_notifier)(SysBusDevice *dev, qemu_irq irq);
  43. };
  44. struct SysBusDevice {
  45. /*< private >*/
  46. DeviceState parent_obj;
  47. /*< public >*/
  48. int num_mmio;
  49. struct {
  50. hwaddr addr;
  51. MemoryRegion *memory;
  52. } mmio[QDEV_MAX_MMIO];
  53. int num_pio;
  54. uint32_t pio[QDEV_MAX_PIO];
  55. };
  56. typedef void FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque);
  57. void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
  58. MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
  59. void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
  60. void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
  61. void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size);
  62. bool sysbus_has_irq(SysBusDevice *dev, int n);
  63. bool sysbus_has_mmio(SysBusDevice *dev, unsigned int n);
  64. void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
  65. bool sysbus_is_irq_connected(SysBusDevice *dev, int n);
  66. qemu_irq sysbus_get_connected_irq(SysBusDevice *dev, int n);
  67. void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr);
  68. void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
  69. int priority);
  70. bool sysbus_realize(SysBusDevice *dev, Error **errp);
  71. bool sysbus_realize_and_unref(SysBusDevice *dev, Error **errp);
  72. /* Call func for every dynamically created sysbus device in the system */
  73. void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque);
  74. /* Legacy helper function for creating devices. */
  75. DeviceState *sysbus_create_varargs(const char *name,
  76. hwaddr addr, ...);
  77. static inline DeviceState *sysbus_create_simple(const char *name,
  78. hwaddr addr,
  79. qemu_irq irq)
  80. {
  81. return sysbus_create_varargs(name, addr, irq, NULL);
  82. }
  83. #endif /* HW_SYSBUS_H */