]> Git Repo - qemu.git/blame - hw/qdev.h
Sparc32: use hex for version numbers
[qemu.git] / hw / qdev.h
CommitLineData
aae9460e
PB
1#ifndef QDEV_H
2#define QDEV_H
3
4#include "hw.h"
02e2da45 5#include "sys-queue.h"
aae9460e 6
ee6847d1
GH
7typedef struct Property Property;
8
9typedef struct PropertyInfo PropertyInfo;
aae9460e 10
b6b61144
GH
11typedef struct CompatProperty CompatProperty;
12
ee6847d1 13typedef struct DeviceInfo DeviceInfo;
aae9460e 14
02e2da45 15typedef struct BusState BusState;
4d6ae674 16
10c4c98a
GH
17typedef struct BusInfo BusInfo;
18
aae9460e
PB
19/* This structure should not be accessed directly. We declare it here
20 so that it can be embedded in individual device state structures. */
02e2da45 21struct DeviceState {
ccb63de3 22 char *id;
042f84d0 23 DeviceInfo *info;
02e2da45 24 BusState *parent_bus;
aae9460e
PB
25 int num_gpio_out;
26 qemu_irq *gpio_out;
27 int num_gpio_in;
28 qemu_irq *gpio_in;
02e2da45 29 LIST_HEAD(, BusState) child_bus;
9d07d757 30 NICInfo *nd;
02e2da45
PB
31 LIST_ENTRY(DeviceState) sibling;
32};
33
10c4c98a
GH
34typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
35struct BusInfo {
36 const char *name;
37 size_t size;
38 bus_dev_printfn print_dev;
ee6847d1 39 Property *props;
10c4c98a 40};
02e2da45
PB
41
42struct BusState {
43 DeviceState *parent;
10c4c98a 44 BusInfo *info;
02e2da45 45 const char *name;
02e2da45
PB
46 LIST_HEAD(, DeviceState) children;
47 LIST_ENTRY(BusState) sibling;
aae9460e
PB
48};
49
ee6847d1
GH
50struct Property {
51 const char *name;
52 PropertyInfo *info;
53 int offset;
54 void *defval;
55};
56
57enum PropertyType {
58 PROP_TYPE_UNSPEC = 0,
59 PROP_TYPE_UINT16,
60 PROP_TYPE_UINT32,
61 PROP_TYPE_TADDR,
62 PROP_TYPE_MACADDR,
63 PROP_TYPE_PTR,
64};
65
66struct PropertyInfo {
67 const char *name;
68 size_t size;
69 enum PropertyType type;
70 int (*parse)(DeviceState *dev, Property *prop, const char *str);
71 int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
72};
73
b6b61144
GH
74struct CompatProperty {
75 const char *driver;
76 const char *property;
77 const char *value;
78};
79
aae9460e
PB
80/*** Board API. This should go away once we have a machine config file. ***/
81
02e2da45 82DeviceState *qdev_create(BusState *bus, const char *name);
aae9460e 83void qdev_init(DeviceState *dev);
02e2da45 84void qdev_free(DeviceState *dev);
aae9460e 85
aae9460e
PB
86qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
87void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
88
02e2da45 89BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
4d6ae674 90
aae9460e
PB
91/*** Device API. ***/
92
02e2da45 93typedef void (*qdev_initfn)(DeviceState *dev, DeviceInfo *info);
6f68ecb2
PB
94typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
95 int unit);
aae9460e 96
02e2da45 97struct DeviceInfo {
074f2fff 98 const char *name;
3320e56e
GH
99 const char *alias;
100 const char *desc;
074f2fff 101 size_t size;
ee6847d1 102 Property *props;
3320e56e 103 int no_user;
074f2fff
GH
104
105 /* Private to qdev / bus. */
02e2da45 106 qdev_initfn init;
10c4c98a 107 BusInfo *bus_info;
042f84d0 108 struct DeviceInfo *next;
02e2da45
PB
109};
110
074f2fff 111void qdev_register(DeviceInfo *info);
aae9460e
PB
112
113/* Register device properties. */
067a3ddc 114/* GPIO inputs also double as IRQ sinks. */
aae9460e
PB
115void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
116void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
117
6f68ecb2
PB
118void scsi_bus_new(DeviceState *host, SCSIAttachFn attach);
119
aae9460e
PB
120CharDriverState *qdev_init_chardev(DeviceState *dev);
121
02e2da45 122BusState *qdev_get_parent_bus(DeviceState *dev);
aae9460e
PB
123
124/* Convery from a base type to a parent type, with compile time checking. */
125#ifdef __GNUC__
126#define DO_UPCAST(type, field, dev) ( __extension__ ( { \
127 char __attribute__((unused)) offset_must_be_zero[ \
128 -offsetof(type, field)]; \
129 container_of(dev, type, field);}))
130#else
131#define DO_UPCAST(type, field, dev) container_of(dev, type, field)
132#endif
133
02e2da45
PB
134/*** BUS API. ***/
135
10c4c98a 136BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name);
02e2da45
PB
137
138#define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
139
cae4956e
GH
140/*** monitor commands ***/
141
142void do_info_qtree(Monitor *mon);
cae4956e 143
ee6847d1
GH
144/*** qdev-properties.c ***/
145
146extern PropertyInfo qdev_prop_uint16;
147extern PropertyInfo qdev_prop_uint32;
148extern PropertyInfo qdev_prop_hex32;
149extern PropertyInfo qdev_prop_ptr;
150extern PropertyInfo qdev_prop_macaddr;
151
152/* Set properties between creation and init. */
153void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
154int qdev_prop_parse(DeviceState *dev, const char *name, const char *value);
155void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type);
156void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
157void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
158/* FIXME: Remove opaque pointer properties. */
159void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
160void qdev_prop_set_defaults(DeviceState *dev, Property *props);
161
b6b61144
GH
162void qdev_prop_register_compat(CompatProperty *props);
163void qdev_prop_set_compat(DeviceState *dev);
164
aae9460e 165#endif
This page took 0.109827 seconds and 4 git commands to generate.