1#ifndef QEMU_QDEV_PROPERTIES_H
2#define QEMU_QDEV_PROPERTIES_H
3
4#include "hw/qdev-core.h"
5
6
7
8extern PropertyInfo qdev_prop_bit;
9extern PropertyInfo qdev_prop_bool;
10extern PropertyInfo qdev_prop_uint8;
11extern PropertyInfo qdev_prop_uint16;
12extern PropertyInfo qdev_prop_uint32;
13extern PropertyInfo qdev_prop_int32;
14extern PropertyInfo qdev_prop_uint64;
15extern PropertyInfo qdev_prop_hex8;
16extern PropertyInfo qdev_prop_hex32;
17extern PropertyInfo qdev_prop_hex64;
18extern PropertyInfo qdev_prop_size;
19extern PropertyInfo qdev_prop_string;
20extern PropertyInfo qdev_prop_chr;
21extern PropertyInfo qdev_prop_ptr;
22extern PropertyInfo qdev_prop_macaddr;
23extern PropertyInfo qdev_prop_losttickpolicy;
24extern PropertyInfo qdev_prop_bios_chs_trans;
25extern PropertyInfo qdev_prop_drive;
26extern PropertyInfo qdev_prop_netdev;
27extern PropertyInfo qdev_prop_vlan;
28extern PropertyInfo qdev_prop_pci_devfn;
29extern PropertyInfo qdev_prop_blocksize;
30extern PropertyInfo qdev_prop_pci_host_devaddr;
31extern PropertyInfo qdev_prop_arraylen;
32
33#define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
34 .name = (_name), \
35 .info = &(_prop), \
36 .offset = offsetof(_state, _field) \
37 + type_check(_type, typeof_field(_state, _field)), \
38 }
39#define DEFINE_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) { \
40 .name = (_name), \
41 .info = &(_prop), \
42 .offset = offsetof(_state, _field) \
43 + type_check(_type,typeof_field(_state, _field)), \
44 .qtype = QTYPE_QINT, \
45 .defval = (_type)_defval, \
46 }
47#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \
48 .name = (_name), \
49 .info = &(qdev_prop_bit), \
50 .bitnr = (_bit), \
51 .offset = offsetof(_state, _field) \
52 + type_check(uint32_t,typeof_field(_state, _field)), \
53 .qtype = QTYPE_QBOOL, \
54 .defval = (bool)_defval, \
55 }
56
57#define DEFINE_PROP_BOOL(_name, _state, _field, _defval) { \
58 .name = (_name), \
59 .info = &(qdev_prop_bool), \
60 .offset = offsetof(_state, _field) \
61 + type_check(bool, typeof_field(_state, _field)), \
62 .qtype = QTYPE_QBOOL, \
63 .defval = (bool)_defval, \
64 }
65
66#define PROP_ARRAY_LEN_PREFIX "len-"
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92#define DEFINE_PROP_ARRAY(_name, _state, _field, \
93 _arrayfield, _arrayprop, _arraytype) { \
94 .name = (PROP_ARRAY_LEN_PREFIX _name), \
95 .info = &(qdev_prop_arraylen), \
96 .offset = offsetof(_state, _field) \
97 + type_check(uint32_t, typeof_field(_state, _field)), \
98 .qtype = QTYPE_QINT, \
99 .arrayinfo = &(_arrayprop), \
100 .arrayfieldsize = sizeof(_arraytype), \
101 .arrayoffset = offsetof(_state, _arrayfield), \
102 }
103
104#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
105 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
106#define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
107 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
108#define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
109 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
110#define DEFINE_PROP_INT32(_n, _s, _f, _d) \
111 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_int32, int32_t)
112#define DEFINE_PROP_UINT64(_n, _s, _f, _d) \
113 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
114#define DEFINE_PROP_HEX8(_n, _s, _f, _d) \
115 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex8, uint8_t)
116#define DEFINE_PROP_HEX32(_n, _s, _f, _d) \
117 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex32, uint32_t)
118#define DEFINE_PROP_HEX64(_n, _s, _f, _d) \
119 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_t)
120#define DEFINE_PROP_SIZE(_n, _s, _f, _d) \
121 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_size, uint64_t)
122#define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \
123 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t)
124
125#define DEFINE_PROP_PTR(_n, _s, _f) \
126 DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
127#define DEFINE_PROP_CHR(_n, _s, _f) \
128 DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
129#define DEFINE_PROP_STRING(_n, _s, _f) \
130 DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
131#define DEFINE_PROP_NETDEV(_n, _s, _f) \
132 DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, NICPeers)
133#define DEFINE_PROP_VLAN(_n, _s, _f) \
134 DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, NICPeers)
135#define DEFINE_PROP_DRIVE(_n, _s, _f) \
136 DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockDriverState *)
137#define DEFINE_PROP_MACADDR(_n, _s, _f) \
138 DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
139#define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \
140 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_losttickpolicy, \
141 LostTickPolicy)
142#define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \
143 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int)
144#define DEFINE_PROP_BLOCKSIZE(_n, _s, _f, _d) \
145 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_blocksize, uint16_t)
146#define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \
147 DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
148
149#define DEFINE_PROP_END_OF_LIST() \
150 {}
151
152
153void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
154void qdev_prop_parse(DeviceState *dev, const char *name, const char *value,
155 Error **errp);
156void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value);
157void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
158void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
159void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
160void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
161void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
162void qdev_prop_set_string(DeviceState *dev, const char *name, const char *value);
163void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value);
164void qdev_prop_set_netdev(DeviceState *dev, const char *name, NetClientState *value);
165int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value) QEMU_WARN_UNUSED_RESULT;
166void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverState *value);
167void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value);
168void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
169
170void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
171
172void qdev_prop_register_global(GlobalProperty *prop);
173void qdev_prop_register_global_list(GlobalProperty *props);
174void qdev_prop_set_globals(DeviceState *dev, Error **errp);
175void qdev_prop_set_globals_for_type(DeviceState *dev, const char *typename,
176 Error **errp);
177void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
178 Property *prop, const char *value);
179
180
181
182
183
184void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp);
185
186
187
188
189
190
191
192
193
194
195
196void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
197 Error **errp);
198#endif
199