]>
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 PB |
16 | const char *name; |
17 | DeviceType *type; | |
02e2da45 | 18 | BusState *parent_bus; |
aae9460e PB |
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; | |
02e2da45 | 26 | LIST_HEAD(, BusState) child_bus; |
9d07d757 | 27 | NICInfo *nd; |
02e2da45 PB |
28 | LIST_ENTRY(DeviceState) sibling; |
29 | }; | |
30 | ||
31 | typedef enum { | |
32 | BUS_TYPE_SYSTEM, | |
33 | BUS_TYPE_PCI, | |
34 | BUS_TYPE_SCSI, | |
35 | BUS_TYPE_I2C, | |
36 | BUS_TYPE_SSI | |
37 | } BusType; | |
38 | ||
39 | struct BusState { | |
40 | DeviceState *parent; | |
41 | const char *name; | |
42 | BusType type; | |
43 | LIST_HEAD(, DeviceState) children; | |
44 | LIST_ENTRY(BusState) sibling; | |
aae9460e PB |
45 | }; |
46 | ||
47 | /*** Board API. This should go away once we have a machine config file. ***/ | |
48 | ||
02e2da45 | 49 | DeviceState *qdev_create(BusState *bus, const char *name); |
aae9460e | 50 | void qdev_init(DeviceState *dev); |
02e2da45 | 51 | void qdev_free(DeviceState *dev); |
aae9460e PB |
52 | |
53 | /* Set properties between creation and init. */ | |
89a740e1 | 54 | void qdev_set_prop_int(DeviceState *dev, const char *name, uint64_t value); |
aae9460e | 55 | void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value); |
9d07d757 | 56 | void qdev_set_netdev(DeviceState *dev, NICInfo *nd); |
aae9460e PB |
57 | |
58 | qemu_irq qdev_get_irq_sink(DeviceState *dev, int n); | |
59 | qemu_irq qdev_get_gpio_in(DeviceState *dev, int n); | |
60 | void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin); | |
61 | ||
02e2da45 | 62 | BusState *qdev_get_child_bus(DeviceState *dev, const char *name); |
4d6ae674 | 63 | |
aae9460e PB |
64 | /*** Device API. ***/ |
65 | ||
02e2da45 PB |
66 | typedef struct DeviceInfo DeviceInfo; |
67 | ||
68 | typedef void (*qdev_initfn)(DeviceState *dev, DeviceInfo *info); | |
6f68ecb2 PB |
69 | typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv, |
70 | int unit); | |
aae9460e | 71 | |
02e2da45 PB |
72 | struct DeviceInfo { |
73 | qdev_initfn init; | |
74 | BusType bus_type; | |
75 | }; | |
76 | ||
77 | void qdev_register(const char *name, int size, DeviceInfo *info); | |
aae9460e PB |
78 | |
79 | /* Register device properties. */ | |
80 | void qdev_init_irq_sink(DeviceState *dev, qemu_irq_handler handler, int nirq); | |
81 | void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n); | |
82 | void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n); | |
83 | ||
6f68ecb2 PB |
84 | void scsi_bus_new(DeviceState *host, SCSIAttachFn attach); |
85 | ||
aae9460e PB |
86 | CharDriverState *qdev_init_chardev(DeviceState *dev); |
87 | ||
02e2da45 | 88 | BusState *qdev_get_parent_bus(DeviceState *dev); |
aae9460e PB |
89 | uint64_t qdev_get_prop_int(DeviceState *dev, const char *name, uint64_t def); |
90 | void *qdev_get_prop_ptr(DeviceState *dev, const char *name); | |
91 | ||
92 | /* Convery from a base type to a parent type, with compile time checking. */ | |
93 | #ifdef __GNUC__ | |
94 | #define DO_UPCAST(type, field, dev) ( __extension__ ( { \ | |
95 | char __attribute__((unused)) offset_must_be_zero[ \ | |
96 | -offsetof(type, field)]; \ | |
97 | container_of(dev, type, field);})) | |
98 | #else | |
99 | #define DO_UPCAST(type, field, dev) container_of(dev, type, field) | |
100 | #endif | |
101 | ||
02e2da45 PB |
102 | /*** BUS API. ***/ |
103 | ||
104 | BusState *qbus_create(BusType type, size_t size, | |
105 | DeviceState *parent, const char *name); | |
106 | ||
107 | #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev) | |
108 | ||
aae9460e | 109 | #endif |