Statistics
| Branch: | Revision:

root / hw / qdev.h @ 067a3ddc

History | View | Annotate | Download (2.9 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
/* This structure should not be accessed directly.  We declare it here
14
   so that it can be embedded in individual device state structures.  */
15
struct DeviceState {
16
    const char *name;
17
    DeviceType *type;
18
    BusState *parent_bus;
19
    DeviceProperty *props;
20
    int num_gpio_out;
21
    qemu_irq *gpio_out;
22
    int num_gpio_in;
23
    qemu_irq *gpio_in;
24
    LIST_HEAD(, BusState) child_bus;
25
    NICInfo *nd;
26
    LIST_ENTRY(DeviceState) sibling;
27
};
28

    
29
typedef enum {
30
    BUS_TYPE_SYSTEM,
31
    BUS_TYPE_PCI,
32
    BUS_TYPE_SCSI,
33
    BUS_TYPE_I2C,
34
    BUS_TYPE_SSI
35
} BusType;
36

    
37
struct BusState {
38
    DeviceState *parent;
39
    const char *name;
40
    BusType type;
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_ptr(DeviceState *dev, const char *name, void *value);
54
void qdev_set_netdev(DeviceState *dev, NICInfo *nd);
55

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

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

    
61
/*** Device API.  ***/
62

    
63
typedef struct DeviceInfo DeviceInfo;
64

    
65
typedef void (*qdev_initfn)(DeviceState *dev, DeviceInfo *info);
66
typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
67
              int unit);
68

    
69
struct DeviceInfo {
70
    qdev_initfn init;
71
    BusType bus_type;
72
};
73

    
74
void qdev_register(const char *name, int size, DeviceInfo *info);
75

    
76
/* Register device properties.  */
77
/* GPIO inputs also double as IRQ sinks.  */
78
void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
79
void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
80

    
81
void scsi_bus_new(DeviceState *host, SCSIAttachFn attach);
82

    
83
CharDriverState *qdev_init_chardev(DeviceState *dev);
84

    
85
BusState *qdev_get_parent_bus(DeviceState *dev);
86
uint64_t qdev_get_prop_int(DeviceState *dev, const char *name, uint64_t def);
87
void *qdev_get_prop_ptr(DeviceState *dev, const char *name);
88

    
89
/* Convery from a base type to a parent type, with compile time checking.  */
90
#ifdef __GNUC__
91
#define DO_UPCAST(type, field, dev) ( __extension__ ( { \
92
    char __attribute__((unused)) offset_must_be_zero[ \
93
        -offsetof(type, field)]; \
94
    container_of(dev, type, field);}))
95
#else
96
#define DO_UPCAST(type, field, dev) container_of(dev, type, field)
97
#endif
98

    
99
/*** BUS API. ***/
100

    
101
BusState *qbus_create(BusType type, size_t size,
102
                      DeviceState *parent, const char *name);
103

    
104
#define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
105

    
106
#endif