Revision 02e2da45 hw/qdev.h

b/hw/qdev.h
2 2
#define QDEV_H
3 3

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

  
6 7
typedef struct DeviceType DeviceType;
7 8

  
8 9
typedef struct DeviceProperty DeviceProperty;
9 10

  
10
typedef struct ChildBusList ChildBusList;
11
typedef struct BusState BusState;
11 12

  
12 13
/* This structure should not be accessed directly.  We declare it here
13 14
   so that it can be embedded in individual device state structures.  */
14
struct DeviceState
15
{
15
struct DeviceState {
16 16
    const char *name;
17 17
    DeviceType *type;
18
    void *bus;
18
    BusState *parent_bus;
19 19
    DeviceProperty *props;
20 20
    int num_irq_sink;
21 21
    qemu_irq *irq_sink;
......
23 23
    qemu_irq *gpio_out;
24 24
    int num_gpio_in;
25 25
    qemu_irq *gpio_in;
26
    ChildBusList *child_bus;
26
    LIST_HEAD(, BusState) child_bus;
27 27
    NICInfo *nd;
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;
28 45
};
29 46

  
30 47
/*** Board API.  This should go away once we have a machine config file.  ***/
31 48

  
32
DeviceState *qdev_create(void *bus, const char *name);
49
DeviceState *qdev_create(BusState *bus, const char *name);
33 50
void qdev_init(DeviceState *dev);
51
void qdev_free(DeviceState *dev);
34 52

  
35 53
/* Set properties between creation and init.  */
36 54
void qdev_set_prop_int(DeviceState *dev, const char *name, uint64_t value);
......
41 59
qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
42 60
void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
43 61

  
44
void *qdev_get_child_bus(DeviceState *dev, const char *name);
62
BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
45 63

  
46 64
/*** Device API.  ***/
47 65

  
48
typedef void (*qdev_initfn)(DeviceState *dev, void *opaque);
66
typedef struct DeviceInfo DeviceInfo;
67

  
68
typedef void (*qdev_initfn)(DeviceState *dev, DeviceInfo *info);
49 69
typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
50 70
              int unit);
51 71

  
52
DeviceType *qdev_register(const char *name, int size, qdev_initfn init,
53
                          void *opaque);
72
struct DeviceInfo {
73
    qdev_initfn init;
74
    BusType bus_type;
75
};
76

  
77
void qdev_register(const char *name, int size, DeviceInfo *info);
54 78

  
55 79
/* Register device properties.  */
56 80
void qdev_init_irq_sink(DeviceState *dev, qemu_irq_handler handler, int nirq);
57 81
void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
58 82
void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
59
void qdev_attach_child_bus(DeviceState *dev, const char *name, void *bus);
60 83

  
61 84
void scsi_bus_new(DeviceState *host, SCSIAttachFn attach);
62 85

  
63 86
CharDriverState *qdev_init_chardev(DeviceState *dev);
64 87

  
65
void *qdev_get_bus(DeviceState *dev);
88
BusState *qdev_get_parent_bus(DeviceState *dev);
66 89
uint64_t qdev_get_prop_int(DeviceState *dev, const char *name, uint64_t def);
67 90
void *qdev_get_prop_ptr(DeviceState *dev, const char *name);
68 91

  
......
76 99
#define DO_UPCAST(type, field, dev) container_of(dev, type, field)
77 100
#endif
78 101

  
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

  
79 109
#endif

Also available in: Unified diff