qemu/include/hw/sysbus.h
<<
>>
Prefs
   1#ifndef HW_SYSBUS_H
   2#define HW_SYSBUS_H 1
   3
   4/* Devices attached directly to the main system bus.  */
   5
   6#include "hw/qdev.h"
   7#include "exec/memory.h"
   8
   9#define QDEV_MAX_MMIO 32
  10#define QDEV_MAX_PIO 32
  11
  12#define TYPE_SYSTEM_BUS "System"
  13#define SYSTEM_BUS(obj) OBJECT_CHECK(BusState, (obj), TYPE_SYSTEM_BUS)
  14
  15typedef struct SysBusDevice SysBusDevice;
  16
  17#define TYPE_SYS_BUS_DEVICE "sys-bus-device"
  18#define SYS_BUS_DEVICE(obj) \
  19     OBJECT_CHECK(SysBusDevice, (obj), TYPE_SYS_BUS_DEVICE)
  20#define SYS_BUS_DEVICE_CLASS(klass) \
  21     OBJECT_CLASS_CHECK(SysBusDeviceClass, (klass), TYPE_SYS_BUS_DEVICE)
  22#define SYS_BUS_DEVICE_GET_CLASS(obj) \
  23     OBJECT_GET_CLASS(SysBusDeviceClass, (obj), TYPE_SYS_BUS_DEVICE)
  24#define SYS_BUS_DEVICE_PARENT_CLASS \
  25     object_class_get_parent(object_class_by_name(TYPE_SYS_BUS_DEVICE))
  26
  27/**
  28 * SysBusDeviceClass:
  29 * @init: Callback function invoked when the #DeviceState.realized property
  30 * is changed to %true. Deprecated, new types inheriting directly from
  31 * TYPE_SYS_BUS_DEVICE should use #DeviceClass.realize instead, new leaf
  32 * types should consult their respective parent type.
  33 *
  34 * SysBusDeviceClass is not overriding #DeviceClass.realize, so derived
  35 * classes overriding it are not required to invoke its implementation.
  36 */
  37
  38#define SYSBUS_DEVICE_GPIO_IRQ "sysbus-irq"
  39
  40typedef struct SysBusDeviceClass {
  41    /*< private >*/
  42    DeviceClass parent_class;
  43    /*< public >*/
  44
  45    int (*init)(SysBusDevice *dev);
  46
  47    /*
  48     * Let the sysbus device format its own non-PIO, non-MMIO unit address.
  49     *
  50     * Sometimes a class of SysBusDevices has neither MMIO nor PIO resources,
  51     * yet instances of it would like to distinguish themselves, in
  52     * OpenFirmware device paths, from other instances of the same class on the
  53     * sysbus. For that end we expose this callback.
  54     *
  55     * The implementation is not supposed to change *@dev, or incur other
  56     * observable change.
  57     *
  58     * The function returns a dynamically allocated string. On error, NULL
  59     * should be returned; the unit address portion of the OFW node will be
  60     * omitted then. (This is not considered a fatal error.)
  61     */
  62    char *(*explicit_ofw_unit_address)(const SysBusDevice *dev);
  63    void (*connect_irq_notifier)(SysBusDevice *dev, qemu_irq irq);
  64} SysBusDeviceClass;
  65
  66struct SysBusDevice {
  67    /*< private >*/
  68    DeviceState parent_obj;
  69    /*< public >*/
  70
  71    int num_mmio;
  72    struct {
  73        hwaddr addr;
  74        MemoryRegion *memory;
  75    } mmio[QDEV_MAX_MMIO];
  76    int num_pio;
  77    uint32_t pio[QDEV_MAX_PIO];
  78};
  79
  80typedef int FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque);
  81
  82void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
  83void sysbus_init_mmio_n(SysBusDevice *dev, MemoryRegion *memory, int n);
  84MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
  85void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
  86void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
  87void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size);
  88
  89
  90bool sysbus_has_irq(SysBusDevice *dev, int n);
  91bool sysbus_has_mmio(SysBusDevice *dev, unsigned int n);
  92void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
  93bool sysbus_is_irq_connected(SysBusDevice *dev, int n);
  94qemu_irq sysbus_get_connected_irq(SysBusDevice *dev, int n);
  95void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr);
  96void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
  97                             int priority);
  98void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
  99                   MemoryRegion *mem);
 100MemoryRegion *sysbus_address_space(SysBusDevice *dev);
 101
 102/* Call func for every dynamically created sysbus device in the system */
 103void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque);
 104
 105/* Legacy helper function for creating devices.  */
 106DeviceState *sysbus_create_varargs(const char *name,
 107                                 hwaddr addr, ...);
 108DeviceState *sysbus_try_create_varargs(const char *name,
 109                                       hwaddr addr, ...);
 110static inline DeviceState *sysbus_create_simple(const char *name,
 111                                              hwaddr addr,
 112                                              qemu_irq irq)
 113{
 114    return sysbus_create_varargs(name, addr, irq, NULL);
 115}
 116
 117static inline DeviceState *sysbus_try_create_simple(const char *name,
 118                                                    hwaddr addr,
 119                                                    qemu_irq irq)
 120{
 121    return sysbus_try_create_varargs(name, addr, irq, NULL);
 122}
 123
 124#endif /* !HW_SYSBUS_H */
 125