root / hw / qdev-properties.c @ bfdb3629
History | View | Annotate | Download (8.8 kB)
1 | ee6847d1 | Gerd Hoffmann | #include "qdev.h" |
---|---|---|---|
2 | ee6847d1 | Gerd Hoffmann | |
3 | ee6847d1 | Gerd Hoffmann | void *qdev_get_prop_ptr(DeviceState *dev, Property *prop)
|
4 | ee6847d1 | Gerd Hoffmann | { |
5 | ee6847d1 | Gerd Hoffmann | void *ptr = dev;
|
6 | ee6847d1 | Gerd Hoffmann | ptr += prop->offset; |
7 | ee6847d1 | Gerd Hoffmann | return ptr;
|
8 | ee6847d1 | Gerd Hoffmann | } |
9 | ee6847d1 | Gerd Hoffmann | |
10 | ee6847d1 | Gerd Hoffmann | /* --- 16bit integer --- */
|
11 | ee6847d1 | Gerd Hoffmann | |
12 | ee6847d1 | Gerd Hoffmann | static int parse_uint16(DeviceState *dev, Property *prop, const char *str) |
13 | ee6847d1 | Gerd Hoffmann | { |
14 | ee6847d1 | Gerd Hoffmann | uint16_t *ptr = qdev_get_prop_ptr(dev, prop); |
15 | ee6847d1 | Gerd Hoffmann | const char *fmt; |
16 | ee6847d1 | Gerd Hoffmann | |
17 | ee6847d1 | Gerd Hoffmann | /* accept both hex and decimal */
|
18 | ee6847d1 | Gerd Hoffmann | fmt = strncasecmp(str, "0x",2) == 0 ? "%" PRIx16 : "%" PRIu16; |
19 | ee6847d1 | Gerd Hoffmann | if (sscanf(str, fmt, ptr) != 1) |
20 | ee6847d1 | Gerd Hoffmann | return -1; |
21 | ee6847d1 | Gerd Hoffmann | return 0; |
22 | ee6847d1 | Gerd Hoffmann | } |
23 | ee6847d1 | Gerd Hoffmann | |
24 | ee6847d1 | Gerd Hoffmann | static int print_uint16(DeviceState *dev, Property *prop, char *dest, size_t len) |
25 | ee6847d1 | Gerd Hoffmann | { |
26 | ee6847d1 | Gerd Hoffmann | uint16_t *ptr = qdev_get_prop_ptr(dev, prop); |
27 | ee6847d1 | Gerd Hoffmann | return snprintf(dest, len, "%" PRIu16, *ptr); |
28 | ee6847d1 | Gerd Hoffmann | } |
29 | ee6847d1 | Gerd Hoffmann | |
30 | ee6847d1 | Gerd Hoffmann | PropertyInfo qdev_prop_uint16 = { |
31 | ee6847d1 | Gerd Hoffmann | .name = "uint16",
|
32 | ee6847d1 | Gerd Hoffmann | .type = PROP_TYPE_UINT16, |
33 | ee6847d1 | Gerd Hoffmann | .size = sizeof(uint16_t),
|
34 | ee6847d1 | Gerd Hoffmann | .parse = parse_uint16, |
35 | ee6847d1 | Gerd Hoffmann | .print = print_uint16, |
36 | ee6847d1 | Gerd Hoffmann | }; |
37 | ee6847d1 | Gerd Hoffmann | |
38 | ee6847d1 | Gerd Hoffmann | /* --- 32bit integer --- */
|
39 | ee6847d1 | Gerd Hoffmann | |
40 | ee6847d1 | Gerd Hoffmann | static int parse_uint32(DeviceState *dev, Property *prop, const char *str) |
41 | ee6847d1 | Gerd Hoffmann | { |
42 | ee6847d1 | Gerd Hoffmann | uint32_t *ptr = qdev_get_prop_ptr(dev, prop); |
43 | ee6847d1 | Gerd Hoffmann | const char *fmt; |
44 | ee6847d1 | Gerd Hoffmann | |
45 | ee6847d1 | Gerd Hoffmann | /* accept both hex and decimal */
|
46 | ee6847d1 | Gerd Hoffmann | fmt = strncasecmp(str, "0x",2) == 0 ? "%" PRIx32 : "%" PRIu32; |
47 | ee6847d1 | Gerd Hoffmann | if (sscanf(str, fmt, ptr) != 1) |
48 | ee6847d1 | Gerd Hoffmann | return -1; |
49 | ee6847d1 | Gerd Hoffmann | return 0; |
50 | ee6847d1 | Gerd Hoffmann | } |
51 | ee6847d1 | Gerd Hoffmann | |
52 | ee6847d1 | Gerd Hoffmann | static int print_uint32(DeviceState *dev, Property *prop, char *dest, size_t len) |
53 | ee6847d1 | Gerd Hoffmann | { |
54 | ee6847d1 | Gerd Hoffmann | uint32_t *ptr = qdev_get_prop_ptr(dev, prop); |
55 | ee6847d1 | Gerd Hoffmann | return snprintf(dest, len, "%" PRIu32, *ptr); |
56 | ee6847d1 | Gerd Hoffmann | } |
57 | ee6847d1 | Gerd Hoffmann | |
58 | ee6847d1 | Gerd Hoffmann | PropertyInfo qdev_prop_uint32 = { |
59 | ee6847d1 | Gerd Hoffmann | .name = "uint32",
|
60 | ee6847d1 | Gerd Hoffmann | .type = PROP_TYPE_UINT32, |
61 | ee6847d1 | Gerd Hoffmann | .size = sizeof(uint32_t),
|
62 | ee6847d1 | Gerd Hoffmann | .parse = parse_uint32, |
63 | ee6847d1 | Gerd Hoffmann | .print = print_uint32, |
64 | ee6847d1 | Gerd Hoffmann | }; |
65 | ee6847d1 | Gerd Hoffmann | |
66 | ee6847d1 | Gerd Hoffmann | /* --- 32bit hex value --- */
|
67 | ee6847d1 | Gerd Hoffmann | |
68 | ee6847d1 | Gerd Hoffmann | static int parse_hex32(DeviceState *dev, Property *prop, const char *str) |
69 | ee6847d1 | Gerd Hoffmann | { |
70 | ee6847d1 | Gerd Hoffmann | uint32_t *ptr = qdev_get_prop_ptr(dev, prop); |
71 | ee6847d1 | Gerd Hoffmann | |
72 | ee6847d1 | Gerd Hoffmann | if (sscanf(str, "%" PRIx32, ptr) != 1) |
73 | ee6847d1 | Gerd Hoffmann | return -1; |
74 | ee6847d1 | Gerd Hoffmann | return 0; |
75 | ee6847d1 | Gerd Hoffmann | } |
76 | ee6847d1 | Gerd Hoffmann | |
77 | ee6847d1 | Gerd Hoffmann | static int print_hex32(DeviceState *dev, Property *prop, char *dest, size_t len) |
78 | ee6847d1 | Gerd Hoffmann | { |
79 | ee6847d1 | Gerd Hoffmann | uint32_t *ptr = qdev_get_prop_ptr(dev, prop); |
80 | ee6847d1 | Gerd Hoffmann | return snprintf(dest, len, "0x%" PRIx32, *ptr); |
81 | ee6847d1 | Gerd Hoffmann | } |
82 | ee6847d1 | Gerd Hoffmann | |
83 | ee6847d1 | Gerd Hoffmann | PropertyInfo qdev_prop_hex32 = { |
84 | ee6847d1 | Gerd Hoffmann | .name = "hex32",
|
85 | ee6847d1 | Gerd Hoffmann | .type = PROP_TYPE_UINT32, |
86 | ee6847d1 | Gerd Hoffmann | .size = sizeof(uint32_t),
|
87 | ee6847d1 | Gerd Hoffmann | .parse = parse_hex32, |
88 | ee6847d1 | Gerd Hoffmann | .print = print_hex32, |
89 | ee6847d1 | Gerd Hoffmann | }; |
90 | ee6847d1 | Gerd Hoffmann | |
91 | 5a053d1f | Blue Swirl | /* --- 64bit integer --- */
|
92 | 5a053d1f | Blue Swirl | |
93 | 5a053d1f | Blue Swirl | static int parse_uint64(DeviceState *dev, Property *prop, const char *str) |
94 | 5a053d1f | Blue Swirl | { |
95 | 5a053d1f | Blue Swirl | uint64_t *ptr = qdev_get_prop_ptr(dev, prop); |
96 | 5a053d1f | Blue Swirl | const char *fmt; |
97 | 5a053d1f | Blue Swirl | |
98 | 5a053d1f | Blue Swirl | /* accept both hex and decimal */
|
99 | 5a053d1f | Blue Swirl | fmt = strncasecmp(str, "0x",2) == 0 ? "%" PRIx64 : "%" PRIu64; |
100 | 5a053d1f | Blue Swirl | if (sscanf(str, fmt, ptr) != 1) |
101 | 5a053d1f | Blue Swirl | return -1; |
102 | 5a053d1f | Blue Swirl | return 0; |
103 | 5a053d1f | Blue Swirl | } |
104 | 5a053d1f | Blue Swirl | |
105 | 5a053d1f | Blue Swirl | static int print_uint64(DeviceState *dev, Property *prop, char *dest, size_t len) |
106 | 5a053d1f | Blue Swirl | { |
107 | 5a053d1f | Blue Swirl | uint64_t *ptr = qdev_get_prop_ptr(dev, prop); |
108 | 5a053d1f | Blue Swirl | return snprintf(dest, len, "%" PRIu64, *ptr); |
109 | 5a053d1f | Blue Swirl | } |
110 | 5a053d1f | Blue Swirl | |
111 | 5a053d1f | Blue Swirl | PropertyInfo qdev_prop_uint64 = { |
112 | 5a053d1f | Blue Swirl | .name = "uint64",
|
113 | 5a053d1f | Blue Swirl | .type = PROP_TYPE_UINT64, |
114 | 5a053d1f | Blue Swirl | .size = sizeof(uint64_t),
|
115 | 5a053d1f | Blue Swirl | .parse = parse_uint64, |
116 | 5a053d1f | Blue Swirl | .print = print_uint64, |
117 | 5a053d1f | Blue Swirl | }; |
118 | 5a053d1f | Blue Swirl | |
119 | 5a053d1f | Blue Swirl | /* --- 64bit hex value --- */
|
120 | 5a053d1f | Blue Swirl | |
121 | 5a053d1f | Blue Swirl | static int parse_hex64(DeviceState *dev, Property *prop, const char *str) |
122 | 5a053d1f | Blue Swirl | { |
123 | 5a053d1f | Blue Swirl | uint64_t *ptr = qdev_get_prop_ptr(dev, prop); |
124 | 5a053d1f | Blue Swirl | |
125 | 5a053d1f | Blue Swirl | if (sscanf(str, "%" PRIx64, ptr) != 1) |
126 | 5a053d1f | Blue Swirl | return -1; |
127 | 5a053d1f | Blue Swirl | return 0; |
128 | 5a053d1f | Blue Swirl | } |
129 | 5a053d1f | Blue Swirl | |
130 | 5a053d1f | Blue Swirl | static int print_hex64(DeviceState *dev, Property *prop, char *dest, size_t len) |
131 | 5a053d1f | Blue Swirl | { |
132 | 5a053d1f | Blue Swirl | uint64_t *ptr = qdev_get_prop_ptr(dev, prop); |
133 | 5a053d1f | Blue Swirl | return snprintf(dest, len, "0x%" PRIx64, *ptr); |
134 | 5a053d1f | Blue Swirl | } |
135 | 5a053d1f | Blue Swirl | |
136 | 5a053d1f | Blue Swirl | PropertyInfo qdev_prop_hex64 = { |
137 | 5a053d1f | Blue Swirl | .name = "hex64",
|
138 | 5a053d1f | Blue Swirl | .type = PROP_TYPE_UINT64, |
139 | 5a053d1f | Blue Swirl | .size = sizeof(uint64_t),
|
140 | 5a053d1f | Blue Swirl | .parse = parse_hex64, |
141 | 5a053d1f | Blue Swirl | .print = print_hex64, |
142 | 5a053d1f | Blue Swirl | }; |
143 | 5a053d1f | Blue Swirl | |
144 | ee6847d1 | Gerd Hoffmann | /* --- pointer --- */
|
145 | ee6847d1 | Gerd Hoffmann | |
146 | ee6847d1 | Gerd Hoffmann | static int print_ptr(DeviceState *dev, Property *prop, char *dest, size_t len) |
147 | ee6847d1 | Gerd Hoffmann | { |
148 | ee6847d1 | Gerd Hoffmann | void **ptr = qdev_get_prop_ptr(dev, prop);
|
149 | ee6847d1 | Gerd Hoffmann | return snprintf(dest, len, "<%p>", *ptr); |
150 | ee6847d1 | Gerd Hoffmann | } |
151 | ee6847d1 | Gerd Hoffmann | |
152 | ee6847d1 | Gerd Hoffmann | PropertyInfo qdev_prop_ptr = { |
153 | ee6847d1 | Gerd Hoffmann | .name = "ptr",
|
154 | ee6847d1 | Gerd Hoffmann | .type = PROP_TYPE_PTR, |
155 | ee6847d1 | Gerd Hoffmann | .size = sizeof(void*), |
156 | ee6847d1 | Gerd Hoffmann | .print = print_ptr, |
157 | ee6847d1 | Gerd Hoffmann | }; |
158 | ee6847d1 | Gerd Hoffmann | |
159 | ee6847d1 | Gerd Hoffmann | /* --- mac address --- */
|
160 | ee6847d1 | Gerd Hoffmann | |
161 | ee6847d1 | Gerd Hoffmann | /*
|
162 | ee6847d1 | Gerd Hoffmann | * accepted syntax versions:
|
163 | ee6847d1 | Gerd Hoffmann | * 01:02:03:04:05:06
|
164 | ee6847d1 | Gerd Hoffmann | * 01-02-03-04-05-06
|
165 | ee6847d1 | Gerd Hoffmann | */
|
166 | ee6847d1 | Gerd Hoffmann | static int parse_mac(DeviceState *dev, Property *prop, const char *str) |
167 | ee6847d1 | Gerd Hoffmann | { |
168 | ee6847d1 | Gerd Hoffmann | uint8_t *mac = qdev_get_prop_ptr(dev, prop); |
169 | ee6847d1 | Gerd Hoffmann | int i, pos;
|
170 | ee6847d1 | Gerd Hoffmann | char *p;
|
171 | ee6847d1 | Gerd Hoffmann | |
172 | ee6847d1 | Gerd Hoffmann | for (i = 0, pos = 0; i < 6; i++, pos += 3) { |
173 | 88e150a5 | Christoph Egger | if (!qemu_isxdigit(str[pos]))
|
174 | ee6847d1 | Gerd Hoffmann | return -1; |
175 | 88e150a5 | Christoph Egger | if (!qemu_isxdigit(str[pos+1])) |
176 | ee6847d1 | Gerd Hoffmann | return -1; |
177 | ee6847d1 | Gerd Hoffmann | if (i == 5 && str[pos+2] != '\0') |
178 | ee6847d1 | Gerd Hoffmann | return -1; |
179 | ee6847d1 | Gerd Hoffmann | if (str[pos+2] != ':' && str[pos+2] != '-') |
180 | ee6847d1 | Gerd Hoffmann | return -1; |
181 | ee6847d1 | Gerd Hoffmann | mac[i] = strtol(str+pos, &p, 16);
|
182 | ee6847d1 | Gerd Hoffmann | } |
183 | ee6847d1 | Gerd Hoffmann | return 0; |
184 | ee6847d1 | Gerd Hoffmann | } |
185 | ee6847d1 | Gerd Hoffmann | |
186 | ee6847d1 | Gerd Hoffmann | static int print_mac(DeviceState *dev, Property *prop, char *dest, size_t len) |
187 | ee6847d1 | Gerd Hoffmann | { |
188 | ee6847d1 | Gerd Hoffmann | uint8_t *mac = qdev_get_prop_ptr(dev, prop); |
189 | ee6847d1 | Gerd Hoffmann | return snprintf(dest, len, "%02x:%02x:%02x:%02x:%02x:%02x", |
190 | ee6847d1 | Gerd Hoffmann | mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); |
191 | ee6847d1 | Gerd Hoffmann | } |
192 | ee6847d1 | Gerd Hoffmann | |
193 | ee6847d1 | Gerd Hoffmann | PropertyInfo qdev_prop_macaddr = { |
194 | ee6847d1 | Gerd Hoffmann | .name = "mac-addr",
|
195 | ee6847d1 | Gerd Hoffmann | .type = PROP_TYPE_MACADDR, |
196 | ee6847d1 | Gerd Hoffmann | .size = 6,
|
197 | ee6847d1 | Gerd Hoffmann | .parse = parse_mac, |
198 | ee6847d1 | Gerd Hoffmann | .print = print_mac, |
199 | ee6847d1 | Gerd Hoffmann | }; |
200 | ee6847d1 | Gerd Hoffmann | |
201 | 05cb5fe4 | Gerd Hoffmann | /* --- pci address --- */
|
202 | 05cb5fe4 | Gerd Hoffmann | |
203 | 05cb5fe4 | Gerd Hoffmann | /*
|
204 | 05cb5fe4 | Gerd Hoffmann | * bus-local address, i.e. "$slot" or "$slot.$fn"
|
205 | 05cb5fe4 | Gerd Hoffmann | */
|
206 | 05cb5fe4 | Gerd Hoffmann | static int parse_pci_devfn(DeviceState *dev, Property *prop, const char *str) |
207 | 05cb5fe4 | Gerd Hoffmann | { |
208 | 05cb5fe4 | Gerd Hoffmann | uint32_t *ptr = qdev_get_prop_ptr(dev, prop); |
209 | 05cb5fe4 | Gerd Hoffmann | unsigned int slot, fn, n; |
210 | 05cb5fe4 | Gerd Hoffmann | |
211 | 05cb5fe4 | Gerd Hoffmann | if (sscanf(str, "%x.%x%n", &slot, &fn, &n) != 2) { |
212 | 05cb5fe4 | Gerd Hoffmann | fn = 0;
|
213 | 05cb5fe4 | Gerd Hoffmann | if (sscanf(str, "%x%n", &slot, &n) != 1) { |
214 | 05cb5fe4 | Gerd Hoffmann | return -1; |
215 | 05cb5fe4 | Gerd Hoffmann | } |
216 | 05cb5fe4 | Gerd Hoffmann | } |
217 | 05cb5fe4 | Gerd Hoffmann | if (str[n] != '\0') |
218 | 05cb5fe4 | Gerd Hoffmann | return -1; |
219 | 05cb5fe4 | Gerd Hoffmann | if (fn > 7) |
220 | 05cb5fe4 | Gerd Hoffmann | return -1; |
221 | 05cb5fe4 | Gerd Hoffmann | *ptr = slot << 3 | fn;
|
222 | 05cb5fe4 | Gerd Hoffmann | return 0; |
223 | 05cb5fe4 | Gerd Hoffmann | } |
224 | 05cb5fe4 | Gerd Hoffmann | |
225 | 05cb5fe4 | Gerd Hoffmann | static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest, size_t len) |
226 | 05cb5fe4 | Gerd Hoffmann | { |
227 | 05cb5fe4 | Gerd Hoffmann | uint32_t *ptr = qdev_get_prop_ptr(dev, prop); |
228 | 05cb5fe4 | Gerd Hoffmann | |
229 | 05cb5fe4 | Gerd Hoffmann | if (-1 == *ptr) { |
230 | 05cb5fe4 | Gerd Hoffmann | return snprintf(dest, len, "<unset>"); |
231 | 05cb5fe4 | Gerd Hoffmann | } else {
|
232 | 05cb5fe4 | Gerd Hoffmann | return snprintf(dest, len, "%02x.%x", *ptr >> 3, *ptr & 7); |
233 | 05cb5fe4 | Gerd Hoffmann | } |
234 | 05cb5fe4 | Gerd Hoffmann | } |
235 | 05cb5fe4 | Gerd Hoffmann | |
236 | 05cb5fe4 | Gerd Hoffmann | PropertyInfo qdev_prop_pci_devfn = { |
237 | 05cb5fe4 | Gerd Hoffmann | .name = "pci-devfn",
|
238 | 05cb5fe4 | Gerd Hoffmann | .type = PROP_TYPE_UINT32, |
239 | 05cb5fe4 | Gerd Hoffmann | .size = sizeof(uint32_t),
|
240 | 05cb5fe4 | Gerd Hoffmann | .parse = parse_pci_devfn, |
241 | 05cb5fe4 | Gerd Hoffmann | .print = print_pci_devfn, |
242 | 05cb5fe4 | Gerd Hoffmann | }; |
243 | 05cb5fe4 | Gerd Hoffmann | |
244 | ee6847d1 | Gerd Hoffmann | /* --- public helpers --- */
|
245 | ee6847d1 | Gerd Hoffmann | |
246 | ee6847d1 | Gerd Hoffmann | static Property *qdev_prop_walk(Property *props, const char *name) |
247 | ee6847d1 | Gerd Hoffmann | { |
248 | ee6847d1 | Gerd Hoffmann | if (!props)
|
249 | ee6847d1 | Gerd Hoffmann | return NULL; |
250 | ee6847d1 | Gerd Hoffmann | while (props->name) {
|
251 | ee6847d1 | Gerd Hoffmann | if (strcmp(props->name, name) == 0) |
252 | ee6847d1 | Gerd Hoffmann | return props;
|
253 | ee6847d1 | Gerd Hoffmann | props++; |
254 | ee6847d1 | Gerd Hoffmann | } |
255 | ee6847d1 | Gerd Hoffmann | return NULL; |
256 | ee6847d1 | Gerd Hoffmann | } |
257 | ee6847d1 | Gerd Hoffmann | |
258 | ee6847d1 | Gerd Hoffmann | static Property *qdev_prop_find(DeviceState *dev, const char *name) |
259 | ee6847d1 | Gerd Hoffmann | { |
260 | ee6847d1 | Gerd Hoffmann | Property *prop; |
261 | ee6847d1 | Gerd Hoffmann | |
262 | ee6847d1 | Gerd Hoffmann | /* device properties */
|
263 | ee6847d1 | Gerd Hoffmann | prop = qdev_prop_walk(dev->info->props, name); |
264 | ee6847d1 | Gerd Hoffmann | if (prop)
|
265 | ee6847d1 | Gerd Hoffmann | return prop;
|
266 | ee6847d1 | Gerd Hoffmann | |
267 | ee6847d1 | Gerd Hoffmann | /* bus properties */
|
268 | ee6847d1 | Gerd Hoffmann | prop = qdev_prop_walk(dev->parent_bus->info->props, name); |
269 | ee6847d1 | Gerd Hoffmann | if (prop)
|
270 | ee6847d1 | Gerd Hoffmann | return prop;
|
271 | ee6847d1 | Gerd Hoffmann | |
272 | ee6847d1 | Gerd Hoffmann | return NULL; |
273 | ee6847d1 | Gerd Hoffmann | } |
274 | ee6847d1 | Gerd Hoffmann | |
275 | ee6847d1 | Gerd Hoffmann | int qdev_prop_parse(DeviceState *dev, const char *name, const char *value) |
276 | ee6847d1 | Gerd Hoffmann | { |
277 | ee6847d1 | Gerd Hoffmann | Property *prop; |
278 | ee6847d1 | Gerd Hoffmann | |
279 | ee6847d1 | Gerd Hoffmann | prop = qdev_prop_find(dev, name); |
280 | ee6847d1 | Gerd Hoffmann | if (!prop) {
|
281 | ee6847d1 | Gerd Hoffmann | fprintf(stderr, "property \"%s.%s\" not found\n",
|
282 | ee6847d1 | Gerd Hoffmann | dev->info->name, name); |
283 | ee6847d1 | Gerd Hoffmann | return -1; |
284 | ee6847d1 | Gerd Hoffmann | } |
285 | ee6847d1 | Gerd Hoffmann | if (!prop->info->parse) {
|
286 | ee6847d1 | Gerd Hoffmann | fprintf(stderr, "property \"%s.%s\" has no parser\n",
|
287 | ee6847d1 | Gerd Hoffmann | dev->info->name, name); |
288 | ee6847d1 | Gerd Hoffmann | return -1; |
289 | ee6847d1 | Gerd Hoffmann | } |
290 | ee6847d1 | Gerd Hoffmann | return prop->info->parse(dev, prop, value);
|
291 | ee6847d1 | Gerd Hoffmann | } |
292 | ee6847d1 | Gerd Hoffmann | |
293 | ee6847d1 | Gerd Hoffmann | void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type) |
294 | ee6847d1 | Gerd Hoffmann | { |
295 | ee6847d1 | Gerd Hoffmann | Property *prop; |
296 | ee6847d1 | Gerd Hoffmann | void *dst;
|
297 | ee6847d1 | Gerd Hoffmann | |
298 | ee6847d1 | Gerd Hoffmann | prop = qdev_prop_find(dev, name); |
299 | ee6847d1 | Gerd Hoffmann | if (!prop) {
|
300 | ee6847d1 | Gerd Hoffmann | fprintf(stderr, "%s: property \"%s.%s\" not found\n",
|
301 | ee6847d1 | Gerd Hoffmann | __FUNCTION__, dev->info->name, name); |
302 | ee6847d1 | Gerd Hoffmann | abort(); |
303 | ee6847d1 | Gerd Hoffmann | } |
304 | ee6847d1 | Gerd Hoffmann | if (prop->info->type != type) {
|
305 | ee6847d1 | Gerd Hoffmann | fprintf(stderr, "%s: property \"%s.%s\" type mismatch\n",
|
306 | ee6847d1 | Gerd Hoffmann | __FUNCTION__, dev->info->name, name); |
307 | ee6847d1 | Gerd Hoffmann | abort(); |
308 | ee6847d1 | Gerd Hoffmann | } |
309 | ee6847d1 | Gerd Hoffmann | dst = qdev_get_prop_ptr(dev, prop); |
310 | ee6847d1 | Gerd Hoffmann | memcpy(dst, src, prop->info->size); |
311 | ee6847d1 | Gerd Hoffmann | } |
312 | ee6847d1 | Gerd Hoffmann | |
313 | ee6847d1 | Gerd Hoffmann | void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value) |
314 | ee6847d1 | Gerd Hoffmann | { |
315 | ee6847d1 | Gerd Hoffmann | qdev_prop_set(dev, name, &value, PROP_TYPE_UINT16); |
316 | ee6847d1 | Gerd Hoffmann | } |
317 | ee6847d1 | Gerd Hoffmann | |
318 | ee6847d1 | Gerd Hoffmann | void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value) |
319 | ee6847d1 | Gerd Hoffmann | { |
320 | ee6847d1 | Gerd Hoffmann | qdev_prop_set(dev, name, &value, PROP_TYPE_UINT32); |
321 | ee6847d1 | Gerd Hoffmann | } |
322 | ee6847d1 | Gerd Hoffmann | |
323 | 5a053d1f | Blue Swirl | void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value) |
324 | 5a053d1f | Blue Swirl | { |
325 | 5a053d1f | Blue Swirl | qdev_prop_set(dev, name, &value, PROP_TYPE_UINT64); |
326 | 5a053d1f | Blue Swirl | } |
327 | 5a053d1f | Blue Swirl | |
328 | ee6847d1 | Gerd Hoffmann | void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value) |
329 | ee6847d1 | Gerd Hoffmann | { |
330 | ee6847d1 | Gerd Hoffmann | qdev_prop_set(dev, name, &value, PROP_TYPE_PTR); |
331 | ee6847d1 | Gerd Hoffmann | } |
332 | ee6847d1 | Gerd Hoffmann | |
333 | ee6847d1 | Gerd Hoffmann | void qdev_prop_set_defaults(DeviceState *dev, Property *props)
|
334 | ee6847d1 | Gerd Hoffmann | { |
335 | ee6847d1 | Gerd Hoffmann | char *dst;
|
336 | ee6847d1 | Gerd Hoffmann | |
337 | ee6847d1 | Gerd Hoffmann | if (!props)
|
338 | ee6847d1 | Gerd Hoffmann | return;
|
339 | ee6847d1 | Gerd Hoffmann | while (props->name) {
|
340 | ee6847d1 | Gerd Hoffmann | if (props->defval) {
|
341 | ee6847d1 | Gerd Hoffmann | dst = qdev_get_prop_ptr(dev, props); |
342 | ee6847d1 | Gerd Hoffmann | memcpy(dst, props->defval, props->info->size); |
343 | ee6847d1 | Gerd Hoffmann | } |
344 | ee6847d1 | Gerd Hoffmann | props++; |
345 | ee6847d1 | Gerd Hoffmann | } |
346 | ee6847d1 | Gerd Hoffmann | } |
347 | ee6847d1 | Gerd Hoffmann | |
348 | b6b61144 | Gerd Hoffmann | static CompatProperty *compat_props;
|
349 | b6b61144 | Gerd Hoffmann | |
350 | b6b61144 | Gerd Hoffmann | void qdev_prop_register_compat(CompatProperty *props)
|
351 | b6b61144 | Gerd Hoffmann | { |
352 | b6b61144 | Gerd Hoffmann | compat_props = props; |
353 | b6b61144 | Gerd Hoffmann | } |
354 | b6b61144 | Gerd Hoffmann | |
355 | b6b61144 | Gerd Hoffmann | void qdev_prop_set_compat(DeviceState *dev)
|
356 | b6b61144 | Gerd Hoffmann | { |
357 | b6b61144 | Gerd Hoffmann | CompatProperty *prop; |
358 | b6b61144 | Gerd Hoffmann | |
359 | b6b61144 | Gerd Hoffmann | if (!compat_props) {
|
360 | b6b61144 | Gerd Hoffmann | return;
|
361 | b6b61144 | Gerd Hoffmann | } |
362 | b6b61144 | Gerd Hoffmann | for (prop = compat_props; prop->driver != NULL; prop++) { |
363 | b6b61144 | Gerd Hoffmann | if (strcmp(dev->info->name, prop->driver) != 0) { |
364 | b6b61144 | Gerd Hoffmann | continue;
|
365 | b6b61144 | Gerd Hoffmann | } |
366 | b6b61144 | Gerd Hoffmann | if (qdev_prop_parse(dev, prop->property, prop->value) != 0) { |
367 | b6b61144 | Gerd Hoffmann | abort(); |
368 | b6b61144 | Gerd Hoffmann | } |
369 | b6b61144 | Gerd Hoffmann | } |
370 | b6b61144 | Gerd Hoffmann | } |