Statistics
| Branch: | Revision:

root / hw / qdev.h @ 90d37239

History | View | Annotate | Download (2.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 aae9460e Paul Brook
6 aae9460e Paul Brook
typedef struct DeviceType DeviceType;
7 aae9460e Paul Brook
8 aae9460e Paul Brook
typedef struct DeviceProperty DeviceProperty;
9 aae9460e Paul Brook
10 4d6ae674 Paul Brook
typedef struct ChildBusList ChildBusList;
11 4d6ae674 Paul Brook
12 aae9460e Paul Brook
/* This structure should not be accessed directly.  We declare it here
13 aae9460e Paul Brook
   so that it can be embedded in individual device state structures.  */
14 aae9460e Paul Brook
struct DeviceState
15 aae9460e Paul Brook
{
16 aae9460e Paul Brook
    const char *name;
17 aae9460e Paul Brook
    DeviceType *type;
18 aae9460e Paul Brook
    void *bus;
19 aae9460e Paul Brook
    DeviceProperty *props;
20 aae9460e Paul Brook
    int num_irq_sink;
21 aae9460e Paul Brook
    qemu_irq *irq_sink;
22 aae9460e Paul Brook
    int num_gpio_out;
23 aae9460e Paul Brook
    qemu_irq *gpio_out;
24 aae9460e Paul Brook
    int num_gpio_in;
25 aae9460e Paul Brook
    qemu_irq *gpio_in;
26 4d6ae674 Paul Brook
    ChildBusList *child_bus;
27 9d07d757 Paul Brook
    NICInfo *nd;
28 aae9460e Paul Brook
};
29 aae9460e Paul Brook
30 aae9460e Paul Brook
/*** Board API.  This should go away once we have a machine config file.  ***/
31 aae9460e Paul Brook
32 aae9460e Paul Brook
DeviceState *qdev_create(void *bus, const char *name);
33 aae9460e Paul Brook
void qdev_init(DeviceState *dev);
34 aae9460e Paul Brook
35 aae9460e Paul Brook
/* Set properties between creation and init.  */
36 aae9460e Paul Brook
void qdev_set_prop_int(DeviceState *dev, const char *name, int value);
37 aae9460e Paul Brook
void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value);
38 9d07d757 Paul Brook
void qdev_set_netdev(DeviceState *dev, NICInfo *nd);
39 aae9460e Paul Brook
40 aae9460e Paul Brook
qemu_irq qdev_get_irq_sink(DeviceState *dev, int n);
41 aae9460e Paul Brook
qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
42 aae9460e Paul Brook
void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
43 aae9460e Paul Brook
44 4d6ae674 Paul Brook
void *qdev_get_child_bus(DeviceState *dev, const char *name);
45 4d6ae674 Paul Brook
46 aae9460e Paul Brook
/*** Device API.  ***/
47 aae9460e Paul Brook
48 aae9460e Paul Brook
typedef void (*qdev_initfn)(DeviceState *dev, void *opaque);
49 6f68ecb2 Paul Brook
typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
50 6f68ecb2 Paul Brook
              int unit);
51 aae9460e Paul Brook
52 aae9460e Paul Brook
DeviceType *qdev_register(const char *name, int size, qdev_initfn init,
53 aae9460e Paul Brook
                          void *opaque);
54 aae9460e Paul Brook
55 aae9460e Paul Brook
/* Register device properties.  */
56 aae9460e Paul Brook
void qdev_init_irq_sink(DeviceState *dev, qemu_irq_handler handler, int nirq);
57 aae9460e Paul Brook
void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
58 aae9460e Paul Brook
void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
59 4d6ae674 Paul Brook
void qdev_attach_child_bus(DeviceState *dev, const char *name, void *bus);
60 aae9460e Paul Brook
61 6f68ecb2 Paul Brook
void scsi_bus_new(DeviceState *host, SCSIAttachFn attach);
62 6f68ecb2 Paul Brook
63 aae9460e Paul Brook
CharDriverState *qdev_init_chardev(DeviceState *dev);
64 aae9460e Paul Brook
65 aae9460e Paul Brook
void *qdev_get_bus(DeviceState *dev);
66 aae9460e Paul Brook
uint64_t qdev_get_prop_int(DeviceState *dev, const char *name, uint64_t def);
67 aae9460e Paul Brook
void *qdev_get_prop_ptr(DeviceState *dev, const char *name);
68 aae9460e Paul Brook
69 aae9460e Paul Brook
/* Convery from a base type to a parent type, with compile time checking.  */
70 aae9460e Paul Brook
#ifdef __GNUC__
71 aae9460e Paul Brook
#define DO_UPCAST(type, field, dev) ( __extension__ ( { \
72 aae9460e Paul Brook
    char __attribute__((unused)) offset_must_be_zero[ \
73 aae9460e Paul Brook
        -offsetof(type, field)]; \
74 aae9460e Paul Brook
    container_of(dev, type, field);}))
75 aae9460e Paul Brook
#else
76 aae9460e Paul Brook
#define DO_UPCAST(type, field, dev) container_of(dev, type, field)
77 aae9460e Paul Brook
#endif
78 aae9460e Paul Brook
79 aae9460e Paul Brook
#endif