Statistics
| Branch: | Revision:

root / include / hw / qdev-properties.h @ f487b677

History | View | Annotate | Download (9.8 kB)

1 074a86fc Anthony Liguori
#ifndef QEMU_QDEV_PROPERTIES_H
2 074a86fc Anthony Liguori
#define QEMU_QDEV_PROPERTIES_H
3 074a86fc Anthony Liguori
4 83c9f4ca Paolo Bonzini
#include "hw/qdev-core.h"
5 074a86fc Anthony Liguori
6 074a86fc Anthony Liguori
/*** qdev-properties.c ***/
7 074a86fc Anthony Liguori
8 074a86fc Anthony Liguori
extern PropertyInfo qdev_prop_bit;
9 72cc5137 Igor Mammedov
extern PropertyInfo qdev_prop_bool;
10 074a86fc Anthony Liguori
extern PropertyInfo qdev_prop_uint8;
11 074a86fc Anthony Liguori
extern PropertyInfo qdev_prop_uint16;
12 074a86fc Anthony Liguori
extern PropertyInfo qdev_prop_uint32;
13 074a86fc Anthony Liguori
extern PropertyInfo qdev_prop_int32;
14 074a86fc Anthony Liguori
extern PropertyInfo qdev_prop_uint64;
15 074a86fc Anthony Liguori
extern PropertyInfo qdev_prop_hex8;
16 074a86fc Anthony Liguori
extern PropertyInfo qdev_prop_hex32;
17 074a86fc Anthony Liguori
extern PropertyInfo qdev_prop_hex64;
18 074a86fc Anthony Liguori
extern PropertyInfo qdev_prop_string;
19 074a86fc Anthony Liguori
extern PropertyInfo qdev_prop_chr;
20 074a86fc Anthony Liguori
extern PropertyInfo qdev_prop_ptr;
21 074a86fc Anthony Liguori
extern PropertyInfo qdev_prop_macaddr;
22 074a86fc Anthony Liguori
extern PropertyInfo qdev_prop_losttickpolicy;
23 074a86fc Anthony Liguori
extern PropertyInfo qdev_prop_bios_chs_trans;
24 074a86fc Anthony Liguori
extern PropertyInfo qdev_prop_drive;
25 074a86fc Anthony Liguori
extern PropertyInfo qdev_prop_netdev;
26 074a86fc Anthony Liguori
extern PropertyInfo qdev_prop_vlan;
27 074a86fc Anthony Liguori
extern PropertyInfo qdev_prop_pci_devfn;
28 074a86fc Anthony Liguori
extern PropertyInfo qdev_prop_blocksize;
29 074a86fc Anthony Liguori
extern PropertyInfo qdev_prop_pci_host_devaddr;
30 0be6bfac Peter Maydell
extern PropertyInfo qdev_prop_arraylen;
31 074a86fc Anthony Liguori
32 074a86fc Anthony Liguori
#define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
33 074a86fc Anthony Liguori
        .name      = (_name),                                    \
34 074a86fc Anthony Liguori
        .info      = &(_prop),                                   \
35 074a86fc Anthony Liguori
        .offset    = offsetof(_state, _field)                    \
36 1ceef9f2 Jason Wang
            + type_check(_type, typeof_field(_state, _field)),   \
37 074a86fc Anthony Liguori
        }
38 074a86fc Anthony Liguori
#define DEFINE_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) { \
39 074a86fc Anthony Liguori
        .name      = (_name),                                           \
40 074a86fc Anthony Liguori
        .info      = &(_prop),                                          \
41 074a86fc Anthony Liguori
        .offset    = offsetof(_state, _field)                           \
42 074a86fc Anthony Liguori
            + type_check(_type,typeof_field(_state, _field)),           \
43 074a86fc Anthony Liguori
        .qtype     = QTYPE_QINT,                                        \
44 074a86fc Anthony Liguori
        .defval    = (_type)_defval,                                    \
45 074a86fc Anthony Liguori
        }
46 074a86fc Anthony Liguori
#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) {  \
47 074a86fc Anthony Liguori
        .name      = (_name),                                    \
48 074a86fc Anthony Liguori
        .info      = &(qdev_prop_bit),                           \
49 074a86fc Anthony Liguori
        .bitnr    = (_bit),                                      \
50 074a86fc Anthony Liguori
        .offset    = offsetof(_state, _field)                    \
51 074a86fc Anthony Liguori
            + type_check(uint32_t,typeof_field(_state, _field)), \
52 074a86fc Anthony Liguori
        .qtype     = QTYPE_QBOOL,                                \
53 074a86fc Anthony Liguori
        .defval    = (bool)_defval,                              \
54 074a86fc Anthony Liguori
        }
55 074a86fc Anthony Liguori
56 72cc5137 Igor Mammedov
#define DEFINE_PROP_BOOL(_name, _state, _field, _defval) {       \
57 72cc5137 Igor Mammedov
        .name      = (_name),                                    \
58 72cc5137 Igor Mammedov
        .info      = &(qdev_prop_bool),                          \
59 72cc5137 Igor Mammedov
        .offset    = offsetof(_state, _field)                    \
60 72cc5137 Igor Mammedov
            + type_check(bool, typeof_field(_state, _field)),    \
61 72cc5137 Igor Mammedov
        .qtype     = QTYPE_QBOOL,                                \
62 72cc5137 Igor Mammedov
        .defval    = (bool)_defval,                              \
63 72cc5137 Igor Mammedov
        }
64 72cc5137 Igor Mammedov
65 0be6bfac Peter Maydell
#define PROP_ARRAY_LEN_PREFIX "len-"
66 0be6bfac Peter Maydell
67 0be6bfac Peter Maydell
/**
68 0be6bfac Peter Maydell
 * DEFINE_PROP_ARRAY:
69 0be6bfac Peter Maydell
 * @_name: name of the array
70 0be6bfac Peter Maydell
 * @_state: name of the device state structure type
71 0be6bfac Peter Maydell
 * @_field: uint32_t field in @_state to hold the array length
72 0be6bfac Peter Maydell
 * @_arrayfield: field in @_state (of type '@_arraytype *') which
73 0be6bfac Peter Maydell
 *               will point to the array
74 0be6bfac Peter Maydell
 * @_arrayprop: PropertyInfo defining what property the array elements have
75 0be6bfac Peter Maydell
 * @_arraytype: C type of the array elements
76 0be6bfac Peter Maydell
 *
77 0be6bfac Peter Maydell
 * Define device properties for a variable-length array _name.  A
78 0be6bfac Peter Maydell
 * static property "len-arrayname" is defined. When the device creator
79 0be6bfac Peter Maydell
 * sets this property to the desired length of array, further dynamic
80 0be6bfac Peter Maydell
 * properties "arrayname[0]", "arrayname[1]", ...  are defined so the
81 0be6bfac Peter Maydell
 * device creator can set the array element values. Setting the
82 0be6bfac Peter Maydell
 * "len-arrayname" property more than once is an error.
83 0be6bfac Peter Maydell
 *
84 0be6bfac Peter Maydell
 * When the array length is set, the @_field member of the device
85 0be6bfac Peter Maydell
 * struct is set to the array length, and @_arrayfield is set to point
86 0be6bfac Peter Maydell
 * to (zero-initialised) memory allocated for the array.  For a zero
87 0be6bfac Peter Maydell
 * length array, @_field will be set to 0 and @_arrayfield to NULL.
88 0be6bfac Peter Maydell
 * It is the responsibility of the device deinit code to free the
89 0be6bfac Peter Maydell
 * @_arrayfield memory.
90 0be6bfac Peter Maydell
 */
91 0be6bfac Peter Maydell
#define DEFINE_PROP_ARRAY(_name, _state, _field,                        \
92 0be6bfac Peter Maydell
                          _arrayfield, _arrayprop, _arraytype) {        \
93 0be6bfac Peter Maydell
        .name = (PROP_ARRAY_LEN_PREFIX _name),                          \
94 0be6bfac Peter Maydell
        .info = &(qdev_prop_arraylen),                                  \
95 0be6bfac Peter Maydell
        .offset = offsetof(_state, _field)                              \
96 0be6bfac Peter Maydell
            + type_check(uint32_t, typeof_field(_state, _field)),       \
97 0be6bfac Peter Maydell
        .qtype = QTYPE_QINT,                                            \
98 0be6bfac Peter Maydell
        .arrayinfo = &(_arrayprop),                                     \
99 0be6bfac Peter Maydell
        .arrayfieldsize = sizeof(_arraytype),                           \
100 0be6bfac Peter Maydell
        .arrayoffset = offsetof(_state, _arrayfield),                   \
101 0be6bfac Peter Maydell
        }
102 0be6bfac Peter Maydell
103 074a86fc Anthony Liguori
#define DEFINE_PROP_UINT8(_n, _s, _f, _d)                       \
104 074a86fc Anthony Liguori
    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
105 074a86fc Anthony Liguori
#define DEFINE_PROP_UINT16(_n, _s, _f, _d)                      \
106 074a86fc Anthony Liguori
    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
107 074a86fc Anthony Liguori
#define DEFINE_PROP_UINT32(_n, _s, _f, _d)                      \
108 074a86fc Anthony Liguori
    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
109 074a86fc Anthony Liguori
#define DEFINE_PROP_INT32(_n, _s, _f, _d)                      \
110 074a86fc Anthony Liguori
    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_int32, int32_t)
111 074a86fc Anthony Liguori
#define DEFINE_PROP_UINT64(_n, _s, _f, _d)                      \
112 074a86fc Anthony Liguori
    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
113 074a86fc Anthony Liguori
#define DEFINE_PROP_HEX8(_n, _s, _f, _d)                       \
114 074a86fc Anthony Liguori
    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex8, uint8_t)
115 074a86fc Anthony Liguori
#define DEFINE_PROP_HEX32(_n, _s, _f, _d)                       \
116 074a86fc Anthony Liguori
    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex32, uint32_t)
117 074a86fc Anthony Liguori
#define DEFINE_PROP_HEX64(_n, _s, _f, _d)                       \
118 074a86fc Anthony Liguori
    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_t)
119 074a86fc Anthony Liguori
#define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d)                   \
120 074a86fc Anthony Liguori
    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t)
121 074a86fc Anthony Liguori
122 074a86fc Anthony Liguori
#define DEFINE_PROP_PTR(_n, _s, _f)             \
123 074a86fc Anthony Liguori
    DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
124 074a86fc Anthony Liguori
#define DEFINE_PROP_CHR(_n, _s, _f)             \
125 074a86fc Anthony Liguori
    DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
126 074a86fc Anthony Liguori
#define DEFINE_PROP_STRING(_n, _s, _f)             \
127 074a86fc Anthony Liguori
    DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
128 074a86fc Anthony Liguori
#define DEFINE_PROP_NETDEV(_n, _s, _f)             \
129 1ceef9f2 Jason Wang
    DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, NICPeers)
130 074a86fc Anthony Liguori
#define DEFINE_PROP_VLAN(_n, _s, _f)             \
131 1ceef9f2 Jason Wang
    DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, NICPeers)
132 074a86fc Anthony Liguori
#define DEFINE_PROP_DRIVE(_n, _s, _f) \
133 074a86fc Anthony Liguori
    DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockDriverState *)
134 074a86fc Anthony Liguori
#define DEFINE_PROP_MACADDR(_n, _s, _f)         \
135 074a86fc Anthony Liguori
    DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
136 074a86fc Anthony Liguori
#define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \
137 074a86fc Anthony Liguori
    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_losttickpolicy, \
138 074a86fc Anthony Liguori
                        LostTickPolicy)
139 074a86fc Anthony Liguori
#define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \
140 074a86fc Anthony Liguori
    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int)
141 074a86fc Anthony Liguori
#define DEFINE_PROP_BLOCKSIZE(_n, _s, _f, _d) \
142 074a86fc Anthony Liguori
    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_blocksize, uint16_t)
143 074a86fc Anthony Liguori
#define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \
144 074a86fc Anthony Liguori
    DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
145 074a86fc Anthony Liguori
146 074a86fc Anthony Liguori
#define DEFINE_PROP_END_OF_LIST()               \
147 074a86fc Anthony Liguori
    {}
148 074a86fc Anthony Liguori
149 074a86fc Anthony Liguori
/* Set properties between creation and init.  */
150 074a86fc Anthony Liguori
void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
151 b1fe9bcb Andreas Färber
void qdev_prop_parse(DeviceState *dev, const char *name, const char *value,
152 b1fe9bcb Andreas Färber
                     Error **errp);
153 074a86fc Anthony Liguori
void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value);
154 074a86fc Anthony Liguori
void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
155 074a86fc Anthony Liguori
void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
156 074a86fc Anthony Liguori
void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
157 074a86fc Anthony Liguori
void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
158 074a86fc Anthony Liguori
void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
159 074a86fc Anthony Liguori
void qdev_prop_set_string(DeviceState *dev, const char *name, const char *value);
160 074a86fc Anthony Liguori
void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value);
161 074a86fc Anthony Liguori
void qdev_prop_set_netdev(DeviceState *dev, const char *name, NetClientState *value);
162 074a86fc Anthony Liguori
int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value) QEMU_WARN_UNUSED_RESULT;
163 074a86fc Anthony Liguori
void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverState *value);
164 074a86fc Anthony Liguori
void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value);
165 074a86fc Anthony Liguori
void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
166 074a86fc Anthony Liguori
/* FIXME: Remove opaque pointer properties.  */
167 074a86fc Anthony Liguori
void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
168 074a86fc Anthony Liguori
169 a404b612 Eduardo Habkost
void qdev_prop_register_global(GlobalProperty *prop);
170 074a86fc Anthony Liguori
void qdev_prop_register_global_list(GlobalProperty *props);
171 b1fe9bcb Andreas Färber
void qdev_prop_set_globals(DeviceState *dev, Error **errp);
172 868d378b Andreas Färber
void qdev_prop_set_globals_for_type(DeviceState *dev, const char *typename,
173 868d378b Andreas Färber
                                    Error **errp);
174 074a86fc Anthony Liguori
void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
175 074a86fc Anthony Liguori
                                    Property *prop, const char *value);
176 074a86fc Anthony Liguori
177 074a86fc Anthony Liguori
/**
178 074a86fc Anthony Liguori
 * @qdev_property_add_static - add a @Property to a device referencing a
179 074a86fc Anthony Liguori
 * field in a struct.
180 074a86fc Anthony Liguori
 */
181 074a86fc Anthony Liguori
void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp);
182 074a86fc Anthony Liguori
183 b000dfbd Peter Maydell
/**
184 b000dfbd Peter Maydell
 * @qdev_prop_set_after_realize:
185 b000dfbd Peter Maydell
 * @dev: device
186 b000dfbd Peter Maydell
 * @name: name of property
187 b000dfbd Peter Maydell
 * @errp: indirect pointer to Error to be set
188 b000dfbd Peter Maydell
 * Set the Error object to report that an attempt was made to set a property
189 b000dfbd Peter Maydell
 * on a device after it has already been realized. This is a utility function
190 b000dfbd Peter Maydell
 * which allows property-setter functions to easily report the error in
191 b000dfbd Peter Maydell
 * a friendly format identifying both the device and the property.
192 b000dfbd Peter Maydell
 */
193 b000dfbd Peter Maydell
void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
194 b000dfbd Peter Maydell
                                 Error **errp);
195 074a86fc Anthony Liguori
#endif