qemu with hax to log dma reads & writes
jcs.org/2018/11/12/vfio
1#ifndef HW_SYSBUS_H
2#define HW_SYSBUS_H
3
4/* Devices attached directly to the main system bus. */
5
6#include "hw/qdev-core.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
25/**
26 * SysBusDeviceClass:
27 *
28 * SysBusDeviceClass is not overriding #DeviceClass.realize, so derived
29 * classes overriding it are not required to invoke its implementation.
30 */
31
32#define SYSBUS_DEVICE_GPIO_IRQ "sysbus-irq"
33
34typedef struct SysBusDeviceClass {
35 /*< private >*/
36 DeviceClass parent_class;
37
38 /*
39 * Let the sysbus device format its own non-PIO, non-MMIO unit address.
40 *
41 * Sometimes a class of SysBusDevices has neither MMIO nor PIO resources,
42 * yet instances of it would like to distinguish themselves, in
43 * OpenFirmware device paths, from other instances of the same class on the
44 * sysbus. For that end we expose this callback.
45 *
46 * The implementation is not supposed to change *@dev, or incur other
47 * observable change.
48 *
49 * The function returns a dynamically allocated string. On error, NULL
50 * should be returned; the unit address portion of the OFW node will be
51 * omitted then. (This is not considered a fatal error.)
52 */
53 char *(*explicit_ofw_unit_address)(const SysBusDevice *dev);
54 void (*connect_irq_notifier)(SysBusDevice *dev, qemu_irq irq);
55} SysBusDeviceClass;
56
57struct SysBusDevice {
58 /*< private >*/
59 DeviceState parent_obj;
60 /*< public >*/
61
62 int num_mmio;
63 struct {
64 hwaddr addr;
65 MemoryRegion *memory;
66 } mmio[QDEV_MAX_MMIO];
67 int num_pio;
68 uint32_t pio[QDEV_MAX_PIO];
69};
70
71typedef void FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque);
72
73void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
74MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
75void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
76void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
77void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size);
78
79
80bool sysbus_has_irq(SysBusDevice *dev, int n);
81bool sysbus_has_mmio(SysBusDevice *dev, unsigned int n);
82void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
83bool sysbus_is_irq_connected(SysBusDevice *dev, int n);
84qemu_irq sysbus_get_connected_irq(SysBusDevice *dev, int n);
85void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr);
86void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
87 int priority);
88void sysbus_mmio_unmap(SysBusDevice *dev, int n);
89void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
90 MemoryRegion *mem);
91MemoryRegion *sysbus_address_space(SysBusDevice *dev);
92
93bool sysbus_realize(SysBusDevice *dev, Error **errp);
94bool sysbus_realize_and_unref(SysBusDevice *dev, Error **errp);
95
96/* Call func for every dynamically created sysbus device in the system */
97void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque);
98
99/* Legacy helper function for creating devices. */
100DeviceState *sysbus_create_varargs(const char *name,
101 hwaddr addr, ...);
102
103static inline DeviceState *sysbus_create_simple(const char *name,
104 hwaddr addr,
105 qemu_irq irq)
106{
107 return sysbus_create_varargs(name, addr, irq, NULL);
108}
109
110#endif /* HW_SYSBUS_H */