Statistics
| Branch: | Revision:

root / hw / qdev-properties.h @ d5aea6f3

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