]> Git Repo - qemu.git/blame - hw/qdev.h
qdev: remove DeviceType
[qemu.git] / hw / qdev.h
CommitLineData
aae9460e
PB
1#ifndef QDEV_H
2#define QDEV_H
3
4#include "hw.h"
02e2da45 5#include "sys-queue.h"
aae9460e 6
042f84d0 7typedef struct DeviceInfo DeviceInfo;
aae9460e
PB
8
9typedef struct DeviceProperty DeviceProperty;
10
02e2da45 11typedef struct BusState BusState;
4d6ae674 12
10c4c98a
GH
13typedef struct BusInfo BusInfo;
14
aae9460e
PB
15/* This structure should not be accessed directly. We declare it here
16 so that it can be embedded in individual device state structures. */
02e2da45 17struct DeviceState {
042f84d0 18 DeviceInfo *info;
02e2da45 19 BusState *parent_bus;
aae9460e 20 DeviceProperty *props;
aae9460e
PB
21 int num_gpio_out;
22 qemu_irq *gpio_out;
23 int num_gpio_in;
24 qemu_irq *gpio_in;
02e2da45 25 LIST_HEAD(, BusState) child_bus;
9d07d757 26 NICInfo *nd;
02e2da45
PB
27 LIST_ENTRY(DeviceState) sibling;
28};
29
10c4c98a
GH
30typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
31struct BusInfo {
32 const char *name;
33 size_t size;
34 bus_dev_printfn print_dev;
35};
02e2da45
PB
36
37struct BusState {
38 DeviceState *parent;
10c4c98a 39 BusInfo *info;
02e2da45 40 const char *name;
02e2da45
PB
41 LIST_HEAD(, DeviceState) children;
42 LIST_ENTRY(BusState) sibling;
aae9460e
PB
43};
44
45/*** Board API. This should go away once we have a machine config file. ***/
46
02e2da45 47DeviceState *qdev_create(BusState *bus, const char *name);
aae9460e 48void qdev_init(DeviceState *dev);
02e2da45 49void qdev_free(DeviceState *dev);
aae9460e
PB
50
51/* Set properties between creation and init. */
89a740e1 52void qdev_set_prop_int(DeviceState *dev, const char *name, uint64_t value);
1431b6a1 53void qdev_set_prop_dev(DeviceState *dev, const char *name, DeviceState *value);
aae9460e 54void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value);
9d07d757 55void qdev_set_netdev(DeviceState *dev, NICInfo *nd);
aae9460e 56
aae9460e
PB
57qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
58void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
59
02e2da45 60BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
4d6ae674 61
aae9460e
PB
62/*** Device API. ***/
63
1431b6a1
PB
64typedef enum {
65 PROP_TYPE_INT,
66 PROP_TYPE_PTR,
67 PROP_TYPE_DEV
68} DevicePropType;
69
70typedef struct {
71 const char *name;
72 DevicePropType type;
73} DevicePropList;
74
02e2da45 75typedef void (*qdev_initfn)(DeviceState *dev, DeviceInfo *info);
6f68ecb2
PB
76typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
77 int unit);
aae9460e 78
02e2da45 79struct DeviceInfo {
074f2fff
GH
80 const char *name;
81 size_t size;
82 DevicePropList *props;
83
84 /* Private to qdev / bus. */
02e2da45 85 qdev_initfn init;
10c4c98a 86 BusInfo *bus_info;
042f84d0 87 struct DeviceInfo *next;
02e2da45
PB
88};
89
074f2fff 90void qdev_register(DeviceInfo *info);
aae9460e
PB
91
92/* Register device properties. */
067a3ddc 93/* GPIO inputs also double as IRQ sinks. */
aae9460e
PB
94void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
95void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
96
6f68ecb2
PB
97void scsi_bus_new(DeviceState *host, SCSIAttachFn attach);
98
aae9460e
PB
99CharDriverState *qdev_init_chardev(DeviceState *dev);
100
02e2da45 101BusState *qdev_get_parent_bus(DeviceState *dev);
aae9460e 102uint64_t qdev_get_prop_int(DeviceState *dev, const char *name, uint64_t def);
1431b6a1
PB
103DeviceState *qdev_get_prop_dev(DeviceState *dev, const char *name);
104/* FIXME: Remove opaque pointer properties. */
aae9460e
PB
105void *qdev_get_prop_ptr(DeviceState *dev, const char *name);
106
107/* Convery from a base type to a parent type, with compile time checking. */
108#ifdef __GNUC__
109#define DO_UPCAST(type, field, dev) ( __extension__ ( { \
110 char __attribute__((unused)) offset_must_be_zero[ \
111 -offsetof(type, field)]; \
112 container_of(dev, type, field);}))
113#else
114#define DO_UPCAST(type, field, dev) container_of(dev, type, field)
115#endif
116
02e2da45
PB
117/*** BUS API. ***/
118
10c4c98a 119BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name);
02e2da45
PB
120
121#define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
122
cae4956e
GH
123/*** monitor commands ***/
124
125void do_info_qtree(Monitor *mon);
cae4956e 126
aae9460e 127#endif
This page took 0.094281 seconds and 4 git commands to generate.