chardev: remove many local variables in qemu_chr_parse_socket
[qemu/ar7.git] / include / hw / sysbus.h
blob1aedcf05c92bda109afa69408dea6c9ce52ad2ce
1 #ifndef HW_SYSBUS_H
2 #define HW_SYSBUS_H
4 /* Devices attached directly to the main system bus. */
6 #include "hw/qdev.h"
7 #include "exec/memory.h"
9 #define QDEV_MAX_MMIO 32
10 #define QDEV_MAX_PIO 32
12 #define TYPE_SYSTEM_BUS "System"
13 #define SYSTEM_BUS(obj) OBJECT_CHECK(BusState, (obj), TYPE_SYSTEM_BUS)
15 typedef struct SysBusDevice SysBusDevice;
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)
25 /**
26 * SysBusDeviceClass:
27 * @init: Callback function invoked when the #DeviceState.realized property
28 * is changed to %true. Deprecated, new types inheriting directly from
29 * TYPE_SYS_BUS_DEVICE should use #DeviceClass.realize instead, new leaf
30 * types should consult their respective parent type.
32 * SysBusDeviceClass is not overriding #DeviceClass.realize, so derived
33 * classes overriding it are not required to invoke its implementation.
36 #define SYSBUS_DEVICE_GPIO_IRQ "sysbus-irq"
38 typedef struct SysBusDeviceClass {
39 /*< private >*/
40 DeviceClass parent_class;
43 * Let the sysbus device format its own non-PIO, non-MMIO unit address.
45 * Sometimes a class of SysBusDevices has neither MMIO nor PIO resources,
46 * yet instances of it would like to distinguish themselves, in
47 * OpenFirmware device paths, from other instances of the same class on the
48 * sysbus. For that end we expose this callback.
50 * The implementation is not supposed to change *@dev, or incur other
51 * observable change.
53 * The function returns a dynamically allocated string. On error, NULL
54 * should be returned; the unit address portion of the OFW node will be
55 * omitted then. (This is not considered a fatal error.)
57 char *(*explicit_ofw_unit_address)(const SysBusDevice *dev);
58 void (*connect_irq_notifier)(SysBusDevice *dev, qemu_irq irq);
59 } SysBusDeviceClass;
61 struct SysBusDevice {
62 /*< private >*/
63 DeviceState parent_obj;
64 /*< public >*/
66 int num_mmio;
67 struct {
68 hwaddr addr;
69 MemoryRegion *memory;
70 } mmio[QDEV_MAX_MMIO];
71 int num_pio;
72 uint32_t pio[QDEV_MAX_PIO];
75 typedef void FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque);
77 void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
78 MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
79 void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
80 void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
81 void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size);
84 bool sysbus_has_irq(SysBusDevice *dev, int n);
85 bool sysbus_has_mmio(SysBusDevice *dev, unsigned int n);
86 void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
87 bool sysbus_is_irq_connected(SysBusDevice *dev, int n);
88 qemu_irq sysbus_get_connected_irq(SysBusDevice *dev, int n);
89 void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr);
90 void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
91 int priority);
92 void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
93 MemoryRegion *mem);
94 MemoryRegion *sysbus_address_space(SysBusDevice *dev);
96 /**
97 * sysbus_init_child_obj:
98 * @parent: The parent object
99 * @childname: Used as name of the "child<>" property in the parent
100 * @child: A pointer to the memory to be used for the object.
101 * @childsize: The maximum size available at @child for the object.
102 * @childtype: The name of the type of the object to instantiate.
104 * This function will initialize an object and attach it to the main system
105 * bus. The memory for the object should have already been allocated. The
106 * object will then be added as child to the given parent. The returned object
107 * has a reference count of 1 (for the "child<...>" property from the parent),
108 * so the object will be finalized automatically when the parent gets removed.
110 void sysbus_init_child_obj(Object *parent, const char *childname, void *child,
111 size_t childsize, const char *childtype);
113 /* Call func for every dynamically created sysbus device in the system */
114 void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque);
116 /* Legacy helper function for creating devices. */
117 DeviceState *sysbus_create_varargs(const char *name,
118 hwaddr addr, ...);
119 DeviceState *sysbus_try_create_varargs(const char *name,
120 hwaddr addr, ...);
121 static inline DeviceState *sysbus_create_simple(const char *name,
122 hwaddr addr,
123 qemu_irq irq)
125 return sysbus_create_varargs(name, addr, irq, NULL);
128 static inline DeviceState *sysbus_try_create_simple(const char *name,
129 hwaddr addr,
130 qemu_irq irq)
132 return sysbus_try_create_varargs(name, addr, irq, NULL);
135 #endif /* HW_SYSBUS_H */