]>
Commit | Line | Data |
---|---|---|
aae9460e PB |
1 | #ifndef QDEV_H |
2 | #define QDEV_H | |
3 | ||
4 | #include "hw.h" | |
02e2da45 | 5 | #include "sys-queue.h" |
aae9460e PB |
6 | |
7 | typedef struct DeviceType DeviceType; | |
8 | ||
9 | typedef struct DeviceProperty DeviceProperty; | |
10 | ||
02e2da45 | 11 | typedef struct BusState BusState; |
4d6ae674 | 12 | |
aae9460e PB |
13 | /* This structure should not be accessed directly. We declare it here |
14 | so that it can be embedded in individual device state structures. */ | |
02e2da45 | 15 | struct DeviceState { |
aae9460e | 16 | DeviceType *type; |
02e2da45 | 17 | BusState *parent_bus; |
aae9460e | 18 | DeviceProperty *props; |
aae9460e PB |
19 | int num_gpio_out; |
20 | qemu_irq *gpio_out; | |
21 | int num_gpio_in; | |
22 | qemu_irq *gpio_in; | |
02e2da45 | 23 | LIST_HEAD(, BusState) child_bus; |
9d07d757 | 24 | NICInfo *nd; |
02e2da45 PB |
25 | LIST_ENTRY(DeviceState) sibling; |
26 | }; | |
27 | ||
28 | typedef enum { | |
29 | BUS_TYPE_SYSTEM, | |
30 | BUS_TYPE_PCI, | |
31 | BUS_TYPE_SCSI, | |
32 | BUS_TYPE_I2C, | |
33 | BUS_TYPE_SSI | |
34 | } BusType; | |
35 | ||
36 | struct BusState { | |
37 | DeviceState *parent; | |
38 | const char *name; | |
39 | BusType type; | |
40 | LIST_HEAD(, DeviceState) children; | |
41 | LIST_ENTRY(BusState) sibling; | |
aae9460e PB |
42 | }; |
43 | ||
44 | /*** Board API. This should go away once we have a machine config file. ***/ | |
45 | ||
02e2da45 | 46 | DeviceState *qdev_create(BusState *bus, const char *name); |
aae9460e | 47 | void qdev_init(DeviceState *dev); |
02e2da45 | 48 | void qdev_free(DeviceState *dev); |
aae9460e PB |
49 | |
50 | /* Set properties between creation and init. */ | |
89a740e1 | 51 | void qdev_set_prop_int(DeviceState *dev, const char *name, uint64_t value); |
aae9460e | 52 | void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value); |
9d07d757 | 53 | void qdev_set_netdev(DeviceState *dev, NICInfo *nd); |
aae9460e | 54 | |
aae9460e PB |
55 | qemu_irq qdev_get_gpio_in(DeviceState *dev, int n); |
56 | void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin); | |
57 | ||
02e2da45 | 58 | BusState *qdev_get_child_bus(DeviceState *dev, const char *name); |
4d6ae674 | 59 | |
aae9460e PB |
60 | /*** Device API. ***/ |
61 | ||
02e2da45 PB |
62 | typedef struct DeviceInfo DeviceInfo; |
63 | ||
64 | typedef void (*qdev_initfn)(DeviceState *dev, DeviceInfo *info); | |
6f68ecb2 PB |
65 | typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv, |
66 | int unit); | |
aae9460e | 67 | |
02e2da45 PB |
68 | struct DeviceInfo { |
69 | qdev_initfn init; | |
70 | BusType bus_type; | |
71 | }; | |
72 | ||
73 | void qdev_register(const char *name, int size, DeviceInfo *info); | |
aae9460e PB |
74 | |
75 | /* Register device properties. */ | |
067a3ddc | 76 | /* GPIO inputs also double as IRQ sinks. */ |
aae9460e PB |
77 | void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n); |
78 | void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n); | |
79 | ||
6f68ecb2 PB |
80 | void scsi_bus_new(DeviceState *host, SCSIAttachFn attach); |
81 | ||
aae9460e PB |
82 | CharDriverState *qdev_init_chardev(DeviceState *dev); |
83 | ||
02e2da45 | 84 | BusState *qdev_get_parent_bus(DeviceState *dev); |
aae9460e PB |
85 | uint64_t qdev_get_prop_int(DeviceState *dev, const char *name, uint64_t def); |
86 | void *qdev_get_prop_ptr(DeviceState *dev, const char *name); | |
87 | ||
88 | /* Convery from a base type to a parent type, with compile time checking. */ | |
89 | #ifdef __GNUC__ | |
90 | #define DO_UPCAST(type, field, dev) ( __extension__ ( { \ | |
91 | char __attribute__((unused)) offset_must_be_zero[ \ | |
92 | -offsetof(type, field)]; \ | |
93 | container_of(dev, type, field);})) | |
94 | #else | |
95 | #define DO_UPCAST(type, field, dev) container_of(dev, type, field) | |
96 | #endif | |
97 | ||
02e2da45 PB |
98 | /*** BUS API. ***/ |
99 | ||
100 | BusState *qbus_create(BusType type, size_t size, | |
101 | DeviceState *parent, const char *name); | |
102 | ||
103 | #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev) | |
104 | ||
aae9460e | 105 | #endif |