]> git.proxmox.com Git - qemu.git/blame - hw/qdev.h
Add common BusState
[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
PB
6
7typedef struct DeviceType DeviceType;
8
9typedef struct DeviceProperty DeviceProperty;
10
02e2da45 11typedef 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 15struct 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
31typedef enum {
32 BUS_TYPE_SYSTEM,
33 BUS_TYPE_PCI,
34 BUS_TYPE_SCSI,
35 BUS_TYPE_I2C,
36 BUS_TYPE_SSI
37} BusType;
38
39struct 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 49DeviceState *qdev_create(BusState *bus, const char *name);
aae9460e 50void qdev_init(DeviceState *dev);
02e2da45 51void qdev_free(DeviceState *dev);
aae9460e
PB
52
53/* Set properties between creation and init. */
89a740e1 54void qdev_set_prop_int(DeviceState *dev, const char *name, uint64_t value);
aae9460e 55void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value);
9d07d757 56void qdev_set_netdev(DeviceState *dev, NICInfo *nd);
aae9460e
PB
57
58qemu_irq qdev_get_irq_sink(DeviceState *dev, int n);
59qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
60void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
61
02e2da45 62BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
4d6ae674 63
aae9460e
PB
64/*** Device API. ***/
65
02e2da45
PB
66typedef struct DeviceInfo DeviceInfo;
67
68typedef void (*qdev_initfn)(DeviceState *dev, DeviceInfo *info);
6f68ecb2
PB
69typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
70 int unit);
aae9460e 71
02e2da45
PB
72struct DeviceInfo {
73 qdev_initfn init;
74 BusType bus_type;
75};
76
77void qdev_register(const char *name, int size, DeviceInfo *info);
aae9460e
PB
78
79/* Register device properties. */
80void qdev_init_irq_sink(DeviceState *dev, qemu_irq_handler handler, int nirq);
81void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
82void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
83
6f68ecb2
PB
84void scsi_bus_new(DeviceState *host, SCSIAttachFn attach);
85
aae9460e
PB
86CharDriverState *qdev_init_chardev(DeviceState *dev);
87
02e2da45 88BusState *qdev_get_parent_bus(DeviceState *dev);
aae9460e
PB
89uint64_t qdev_get_prop_int(DeviceState *dev, const char *name, uint64_t def);
90void *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
104BusState *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