Statistics
| Branch: | Revision:

root / hw / qdev.h @ 02eb84d0

History | View | Annotate | Download (3.5 kB)

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