]> git.proxmox.com Git - qemu.git/blame - hw/qdev.h
PCI network qdev conversion
[qemu.git] / hw / qdev.h
CommitLineData
aae9460e
PB
1#ifndef QDEV_H
2#define QDEV_H
3
4#include "hw.h"
5
6typedef struct DeviceType DeviceType;
7
8typedef struct DeviceProperty DeviceProperty;
9
4d6ae674
PB
10typedef struct ChildBusList ChildBusList;
11
aae9460e
PB
12/* This structure should not be accessed directly. We declare it here
13 so that it can be embedded in individual device state structures. */
14struct DeviceState
15{
16 const char *name;
17 DeviceType *type;
18 void *bus;
19 DeviceProperty *props;
20 int num_irq_sink;
21 qemu_irq *irq_sink;
22 int num_gpio_out;
23 qemu_irq *gpio_out;
24 int num_gpio_in;
25 qemu_irq *gpio_in;
4d6ae674 26 ChildBusList *child_bus;
9d07d757 27 NICInfo *nd;
aae9460e
PB
28};
29
30/*** Board API. This should go away once we have a machine config file. ***/
31
32DeviceState *qdev_create(void *bus, const char *name);
33void qdev_init(DeviceState *dev);
34
35/* Set properties between creation and init. */
36void qdev_set_prop_int(DeviceState *dev, const char *name, int value);
37void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value);
9d07d757 38void qdev_set_netdev(DeviceState *dev, NICInfo *nd);
aae9460e
PB
39
40qemu_irq qdev_get_irq_sink(DeviceState *dev, int n);
41qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
42void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
43
4d6ae674
PB
44void *qdev_get_child_bus(DeviceState *dev, const char *name);
45
aae9460e
PB
46/*** Device API. ***/
47
48typedef void (*qdev_initfn)(DeviceState *dev, void *opaque);
6f68ecb2
PB
49typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
50 int unit);
aae9460e
PB
51
52DeviceType *qdev_register(const char *name, int size, qdev_initfn init,
53 void *opaque);
54
55/* Register device properties. */
56void qdev_init_irq_sink(DeviceState *dev, qemu_irq_handler handler, int nirq);
57void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
58void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
4d6ae674 59void qdev_attach_child_bus(DeviceState *dev, const char *name, void *bus);
aae9460e 60
6f68ecb2
PB
61void scsi_bus_new(DeviceState *host, SCSIAttachFn attach);
62
aae9460e
PB
63CharDriverState *qdev_init_chardev(DeviceState *dev);
64
65void *qdev_get_bus(DeviceState *dev);
66uint64_t qdev_get_prop_int(DeviceState *dev, const char *name, uint64_t def);
67void *qdev_get_prop_ptr(DeviceState *dev, const char *name);
68
69/* Convery from a base type to a parent type, with compile time checking. */
70#ifdef __GNUC__
71#define DO_UPCAST(type, field, dev) ( __extension__ ( { \
72 char __attribute__((unused)) offset_must_be_zero[ \
73 -offsetof(type, field)]; \
74 container_of(dev, type, field);}))
75#else
76#define DO_UPCAST(type, field, dev) container_of(dev, type, field)
77#endif
78
79#endif