2009-05-15 01:35:06 +04:00
|
|
|
#ifndef HW_SYSBUS_H
|
2016-06-29 16:29:06 +03:00
|
|
|
#define HW_SYSBUS_H
|
2009-05-15 01:35:06 +04:00
|
|
|
|
|
|
|
/* Devices attached directly to the main system bus. */
|
|
|
|
|
2019-08-12 08:23:51 +03:00
|
|
|
#include "hw/qdev-core.h"
|
2012-12-17 21:19:49 +04:00
|
|
|
#include "exec/memory.h"
|
2009-05-15 01:35:06 +04:00
|
|
|
|
2009-07-12 23:21:36 +04:00
|
|
|
#define QDEV_MAX_MMIO 32
|
2010-12-08 14:35:00 +03:00
|
|
|
#define QDEV_MAX_PIO 32
|
2009-05-15 01:35:06 +04:00
|
|
|
|
2012-05-02 11:00:20 +04:00
|
|
|
#define TYPE_SYSTEM_BUS "System"
|
2014-11-11 12:37:59 +03:00
|
|
|
#define SYSTEM_BUS(obj) OBJECT_CHECK(BusState, (obj), TYPE_SYSTEM_BUS)
|
2012-05-02 11:00:20 +04:00
|
|
|
|
2009-05-15 01:35:06 +04:00
|
|
|
typedef struct SysBusDevice SysBusDevice;
|
|
|
|
|
2012-01-24 23:12:29 +04:00
|
|
|
#define TYPE_SYS_BUS_DEVICE "sys-bus-device"
|
|
|
|
#define SYS_BUS_DEVICE(obj) \
|
|
|
|
OBJECT_CHECK(SysBusDevice, (obj), TYPE_SYS_BUS_DEVICE)
|
|
|
|
#define SYS_BUS_DEVICE_CLASS(klass) \
|
|
|
|
OBJECT_CLASS_CHECK(SysBusDeviceClass, (klass), TYPE_SYS_BUS_DEVICE)
|
|
|
|
#define SYS_BUS_DEVICE_GET_CLASS(obj) \
|
|
|
|
OBJECT_GET_CLASS(SysBusDeviceClass, (obj), TYPE_SYS_BUS_DEVICE)
|
|
|
|
|
2013-07-01 14:18:17 +04:00
|
|
|
/**
|
|
|
|
* SysBusDeviceClass:
|
|
|
|
*
|
|
|
|
* SysBusDeviceClass is not overriding #DeviceClass.realize, so derived
|
|
|
|
* classes overriding it are not required to invoke its implementation.
|
|
|
|
*/
|
2014-09-26 09:24:15 +04:00
|
|
|
|
|
|
|
#define SYSBUS_DEVICE_GPIO_IRQ "sysbus-irq"
|
|
|
|
|
2012-01-24 23:12:29 +04:00
|
|
|
typedef struct SysBusDeviceClass {
|
2013-07-01 14:18:17 +04:00
|
|
|
/*< private >*/
|
2012-01-24 23:12:29 +04:00
|
|
|
DeviceClass parent_class;
|
2015-06-19 05:40:16 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Let the sysbus device format its own non-PIO, non-MMIO unit address.
|
|
|
|
*
|
|
|
|
* Sometimes a class of SysBusDevices has neither MMIO nor PIO resources,
|
|
|
|
* yet instances of it would like to distinguish themselves, in
|
|
|
|
* OpenFirmware device paths, from other instances of the same class on the
|
|
|
|
* sysbus. For that end we expose this callback.
|
|
|
|
*
|
|
|
|
* The implementation is not supposed to change *@dev, or incur other
|
|
|
|
* observable change.
|
|
|
|
*
|
|
|
|
* The function returns a dynamically allocated string. On error, NULL
|
|
|
|
* should be returned; the unit address portion of the OFW node will be
|
|
|
|
* omitted then. (This is not considered a fatal error.)
|
|
|
|
*/
|
|
|
|
char *(*explicit_ofw_unit_address)(const SysBusDevice *dev);
|
2015-07-06 21:15:14 +03:00
|
|
|
void (*connect_irq_notifier)(SysBusDevice *dev, qemu_irq irq);
|
2012-01-24 23:12:29 +04:00
|
|
|
} SysBusDeviceClass;
|
|
|
|
|
2009-05-15 01:35:06 +04:00
|
|
|
struct SysBusDevice {
|
2013-07-27 18:40:42 +04:00
|
|
|
/*< private >*/
|
|
|
|
DeviceState parent_obj;
|
|
|
|
/*< public >*/
|
|
|
|
|
2009-05-15 01:35:06 +04:00
|
|
|
int num_mmio;
|
|
|
|
struct {
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr;
|
2011-07-26 15:26:21 +04:00
|
|
|
MemoryRegion *memory;
|
2009-05-15 01:35:06 +04:00
|
|
|
} mmio[QDEV_MAX_MMIO];
|
2010-12-08 14:35:00 +03:00
|
|
|
int num_pio;
|
2016-03-16 12:20:34 +03:00
|
|
|
uint32_t pio[QDEV_MAX_PIO];
|
2009-05-15 01:35:06 +04:00
|
|
|
};
|
|
|
|
|
2016-09-21 08:23:53 +03:00
|
|
|
typedef void FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque);
|
2014-09-24 15:06:57 +04:00
|
|
|
|
2011-11-27 13:38:10 +04:00
|
|
|
void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
|
2011-08-28 20:22:17 +04:00
|
|
|
MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
|
2009-05-15 01:35:06 +04:00
|
|
|
void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
|
|
|
|
void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
|
2016-03-16 12:20:34 +03:00
|
|
|
void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size);
|
2009-05-15 01:35:06 +04:00
|
|
|
|
|
|
|
|
2014-09-24 14:32:17 +04:00
|
|
|
bool sysbus_has_irq(SysBusDevice *dev, int n);
|
2014-09-24 14:36:30 +04:00
|
|
|
bool sysbus_has_mmio(SysBusDevice *dev, unsigned int n);
|
2009-05-15 01:35:06 +04:00
|
|
|
void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
|
2014-09-24 14:32:17 +04:00
|
|
|
bool sysbus_is_irq_connected(SysBusDevice *dev, int n);
|
|
|
|
qemu_irq sysbus_get_connected_irq(SysBusDevice *dev, int n);
|
2012-10-23 14:30:10 +04:00
|
|
|
void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr);
|
2013-02-22 07:58:44 +04:00
|
|
|
void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
|
2013-09-16 12:21:14 +04:00
|
|
|
int priority);
|
2019-05-13 11:42:39 +03:00
|
|
|
void sysbus_mmio_unmap(SysBusDevice *dev, int n);
|
2012-10-23 14:30:10 +04:00
|
|
|
void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
|
2011-07-24 18:12:11 +04:00
|
|
|
MemoryRegion *mem);
|
2011-12-08 17:57:34 +04:00
|
|
|
MemoryRegion *sysbus_address_space(SysBusDevice *dev);
|
2009-05-15 01:35:06 +04:00
|
|
|
|
2018-07-16 15:59:19 +03:00
|
|
|
/**
|
|
|
|
* sysbus_init_child_obj:
|
|
|
|
* @parent: The parent object
|
|
|
|
* @childname: Used as name of the "child<>" property in the parent
|
|
|
|
* @child: A pointer to the memory to be used for the object.
|
|
|
|
* @childsize: The maximum size available at @child for the object.
|
|
|
|
* @childtype: The name of the type of the object to instantiate.
|
|
|
|
*
|
|
|
|
* This function will initialize an object and attach it to the main system
|
|
|
|
* bus. The memory for the object should have already been allocated. The
|
|
|
|
* object will then be added as child to the given parent. The returned object
|
|
|
|
* has a reference count of 1 (for the "child<...>" property from the parent),
|
|
|
|
* so the object will be finalized automatically when the parent gets removed.
|
|
|
|
*/
|
|
|
|
void sysbus_init_child_obj(Object *parent, const char *childname, void *child,
|
|
|
|
size_t childsize, const char *childtype);
|
|
|
|
|
2014-09-24 15:06:57 +04:00
|
|
|
/* Call func for every dynamically created sysbus device in the system */
|
|
|
|
void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque);
|
|
|
|
|
2009-05-15 01:35:06 +04:00
|
|
|
/* Legacy helper function for creating devices. */
|
|
|
|
DeviceState *sysbus_create_varargs(const char *name,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr, ...);
|
2019-10-22 20:18:12 +03:00
|
|
|
|
2009-05-15 01:35:06 +04:00
|
|
|
static inline DeviceState *sysbus_create_simple(const char *name,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr,
|
2009-05-15 01:35:06 +04:00
|
|
|
qemu_irq irq)
|
|
|
|
{
|
|
|
|
return sysbus_create_varargs(name, addr, irq, NULL);
|
|
|
|
}
|
|
|
|
|
2011-02-05 17:34:56 +03:00
|
|
|
|
2016-06-29 16:29:06 +03:00
|
|
|
#endif /* HW_SYSBUS_H */
|