Statistics
| Branch: | Revision:

root / hw / qdev.h @ aae9460e

History | View | Annotate | Download (2.1 kB)

1
#ifndef QDEV_H
2
#define QDEV_H
3

    
4
#include "hw.h"
5

    
6
typedef struct DeviceType DeviceType;
7

    
8
typedef struct DeviceProperty DeviceProperty;
9

    
10
/* This structure should not be accessed directly.  We declare it here
11
   so that it can be embedded in individual device state structures.  */
12
struct DeviceState
13
{
14
    const char *name;
15
    DeviceType *type;
16
    void *bus;
17
    DeviceProperty *props;
18
    int num_irq_sink;
19
    qemu_irq *irq_sink;
20
    int num_gpio_out;
21
    qemu_irq *gpio_out;
22
    int num_gpio_in;
23
    qemu_irq *gpio_in;
24
};
25

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

    
28
DeviceState *qdev_create(void *bus, const char *name);
29
void qdev_init(DeviceState *dev);
30

    
31
/* Set properties between creation and init.  */
32
void qdev_set_prop_int(DeviceState *dev, const char *name, int value);
33
void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value);
34

    
35
qemu_irq qdev_get_irq_sink(DeviceState *dev, int n);
36
qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
37
void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
38

    
39
/*** Device API.  ***/
40

    
41
typedef void (*qdev_initfn)(DeviceState *dev, void *opaque);
42

    
43
DeviceType *qdev_register(const char *name, int size, qdev_initfn init,
44
                          void *opaque);
45

    
46
/* Register device properties.  */
47
void qdev_init_irq_sink(DeviceState *dev, qemu_irq_handler handler, int nirq);
48
void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
49
void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
50

    
51
CharDriverState *qdev_init_chardev(DeviceState *dev);
52

    
53
void *qdev_get_bus(DeviceState *dev);
54
uint64_t qdev_get_prop_int(DeviceState *dev, const char *name, uint64_t def);
55
void *qdev_get_prop_ptr(DeviceState *dev, const char *name);
56

    
57
/* Convery from a base type to a parent type, with compile time checking.  */
58
#ifdef __GNUC__
59
#define DO_UPCAST(type, field, dev) ( __extension__ ( { \
60
    char __attribute__((unused)) offset_must_be_zero[ \
61
        -offsetof(type, field)]; \
62
    container_of(dev, type, field);}))
63
#else
64
#define DO_UPCAST(type, field, dev) container_of(dev, type, field)
65
#endif
66

    
67
#endif