Statistics
| Branch: | Revision:

root / hw / qdev.h @ 10c4c98a

History | View | Annotate | Download (3.5 kB)

1
#ifndef QDEV_H
2
#define QDEV_H
3

    
4
#include "hw.h"
5
#include "sys-queue.h"
6

    
7
typedef struct DeviceType DeviceType;
8

    
9
typedef struct DeviceProperty DeviceProperty;
10

    
11
typedef struct BusState BusState;
12

    
13
typedef struct BusInfo BusInfo;
14

    
15
/* This structure should not be accessed directly.  We declare it here
16
   so that it can be embedded in individual device state structures.  */
17
struct DeviceState {
18
    DeviceType *type;
19
    BusState *parent_bus;
20
    DeviceProperty *props;
21
    int num_gpio_out;
22
    qemu_irq *gpio_out;
23
    int num_gpio_in;
24
    qemu_irq *gpio_in;
25
    LIST_HEAD(, BusState) child_bus;
26
    NICInfo *nd;
27
    LIST_ENTRY(DeviceState) sibling;
28
};
29

    
30
typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
31
struct BusInfo {
32
    const char *name;
33
    size_t size;
34
    bus_dev_printfn print_dev;
35
};
36

    
37
struct BusState {
38
    DeviceState *parent;
39
    BusInfo *info;
40
    const char *name;
41
    LIST_HEAD(, DeviceState) children;
42
    LIST_ENTRY(BusState) sibling;
43
};
44

    
45
/*** Board API.  This should go away once we have a machine config file.  ***/
46

    
47
DeviceState *qdev_create(BusState *bus, const char *name);
48
void qdev_init(DeviceState *dev);
49
void qdev_free(DeviceState *dev);
50

    
51
/* Set properties between creation and init.  */
52
void qdev_set_prop_int(DeviceState *dev, const char *name, uint64_t value);
53
void qdev_set_prop_dev(DeviceState *dev, const char *name, DeviceState *value);
54
void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value);
55
void qdev_set_netdev(DeviceState *dev, NICInfo *nd);
56

    
57
qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
58
void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
59

    
60
BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
61

    
62
/*** Device API.  ***/
63

    
64
typedef enum {
65
    PROP_TYPE_INT,
66
    PROP_TYPE_PTR,
67
    PROP_TYPE_DEV
68
} DevicePropType;
69

    
70
typedef struct {
71
    const char *name;
72
    DevicePropType type;
73
} DevicePropList;
74

    
75
typedef struct DeviceInfo DeviceInfo;
76

    
77
typedef void (*qdev_initfn)(DeviceState *dev, DeviceInfo *info);
78
typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
79
              int unit);
80

    
81
struct DeviceInfo {
82
    const char *name;
83
    size_t size;
84
    DevicePropList *props;
85

    
86
    /* Private to qdev / bus.  */
87
    qdev_initfn init;
88
    BusInfo *bus_info;
89
};
90

    
91
void qdev_register(DeviceInfo *info);
92

    
93
/* Register device properties.  */
94
/* GPIO inputs also double as IRQ sinks.  */
95
void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
96
void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
97

    
98
void scsi_bus_new(DeviceState *host, SCSIAttachFn attach);
99

    
100
CharDriverState *qdev_init_chardev(DeviceState *dev);
101

    
102
BusState *qdev_get_parent_bus(DeviceState *dev);
103
uint64_t qdev_get_prop_int(DeviceState *dev, const char *name, uint64_t def);
104
DeviceState *qdev_get_prop_dev(DeviceState *dev, const char *name);
105
/* FIXME: Remove opaque pointer properties.  */
106
void *qdev_get_prop_ptr(DeviceState *dev, const char *name);
107

    
108
/* Convery from a base type to a parent type, with compile time checking.  */
109
#ifdef __GNUC__
110
#define DO_UPCAST(type, field, dev) ( __extension__ ( { \
111
    char __attribute__((unused)) offset_must_be_zero[ \
112
        -offsetof(type, field)]; \
113
    container_of(dev, type, field);}))
114
#else
115
#define DO_UPCAST(type, field, dev) container_of(dev, type, field)
116
#endif
117

    
118
/*** BUS API. ***/
119

    
120
BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name);
121

    
122
#define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
123

    
124
/*** monitor commands ***/
125

    
126
void do_info_qtree(Monitor *mon);
127

    
128
#endif