6 void *qdev_get_prop_ptr(DeviceState *dev, Property *prop)
13 static uint32_t qdev_get_prop_mask(Property *prop)
15 assert(prop->info == &qdev_prop_bit);
16 return 0x1 << prop->bitnr;
19 static void bit_prop_set(DeviceState *dev, Property *props, bool val)
21 uint32_t *p = qdev_get_prop_ptr(dev, props);
22 uint32_t mask = qdev_get_prop_mask(props);
31 static int print_bit(DeviceState *dev, Property *prop, char *dest, size_t len)
33 uint32_t *p = qdev_get_prop_ptr(dev, prop);
34 return snprintf(dest, len, (*p & qdev_get_prop_mask(prop)) ? "on" : "off");
37 static void get_bit(Object *obj, Visitor *v, void *opaque,
38 const char *name, Error **errp)
40 DeviceState *dev = DEVICE(obj);
41 Property *prop = opaque;
42 uint32_t *p = qdev_get_prop_ptr(dev, prop);
43 bool value = (*p & qdev_get_prop_mask(prop)) != 0;
45 visit_type_bool(v, &value, name, errp);
48 static void set_bit(Object *obj, Visitor *v, void *opaque,
49 const char *name, Error **errp)
51 DeviceState *dev = DEVICE(obj);
52 Property *prop = opaque;
53 Error *local_err = NULL;
56 if (dev->state != DEV_STATE_CREATED) {
57 error_set(errp, QERR_PERMISSION_DENIED);
61 visit_type_bool(v, &value, name, &local_err);
63 error_propagate(errp, local_err);
66 bit_prop_set(dev, prop, value);
69 PropertyInfo qdev_prop_bit = {
71 .legacy_name = "on/off",
77 /* --- 8bit integer --- */
79 static void get_int8(Object *obj, Visitor *v, void *opaque,
80 const char *name, Error **errp)
82 DeviceState *dev = DEVICE(obj);
83 Property *prop = opaque;
84 int8_t *ptr = qdev_get_prop_ptr(dev, prop);
88 visit_type_int(v, &value, name, errp);
91 static void set_int8(Object *obj, Visitor *v, void *opaque,
92 const char *name, Error **errp)
94 DeviceState *dev = DEVICE(obj);
95 Property *prop = opaque;
96 int8_t *ptr = qdev_get_prop_ptr(dev, prop);
97 Error *local_err = NULL;
100 if (dev->state != DEV_STATE_CREATED) {
101 error_set(errp, QERR_PERMISSION_DENIED);
105 visit_type_int(v, &value, name, &local_err);
107 error_propagate(errp, local_err);
110 if (value >= prop->info->min && value <= prop->info->max) {
113 error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
114 dev->id?:"", name, value, prop->info->min,
119 PropertyInfo qdev_prop_uint8 = {
127 /* --- 8bit hex value --- */
129 static int parse_hex8(DeviceState *dev, Property *prop, const char *str)
131 uint8_t *ptr = qdev_get_prop_ptr(dev, prop);
134 if (str[0] != '0' || str[1] != 'x') {
138 *ptr = strtoul(str, &end, 16);
139 if ((*end != '\0') || (end == str)) {
146 static int print_hex8(DeviceState *dev, Property *prop, char *dest, size_t len)
148 uint8_t *ptr = qdev_get_prop_ptr(dev, prop);
149 return snprintf(dest, len, "0x%" PRIx8, *ptr);
152 PropertyInfo qdev_prop_hex8 = {
154 .legacy_name = "hex8",
163 /* --- 16bit integer --- */
165 static void get_int16(Object *obj, Visitor *v, void *opaque,
166 const char *name, Error **errp)
168 DeviceState *dev = DEVICE(obj);
169 Property *prop = opaque;
170 int16_t *ptr = qdev_get_prop_ptr(dev, prop);
174 visit_type_int(v, &value, name, errp);
177 static void set_int16(Object *obj, Visitor *v, void *opaque,
178 const char *name, Error **errp)
180 DeviceState *dev = DEVICE(obj);
181 Property *prop = opaque;
182 int16_t *ptr = qdev_get_prop_ptr(dev, prop);
183 Error *local_err = NULL;
186 if (dev->state != DEV_STATE_CREATED) {
187 error_set(errp, QERR_PERMISSION_DENIED);
191 visit_type_int(v, &value, name, &local_err);
193 error_propagate(errp, local_err);
196 if (value >= prop->info->min && value <= prop->info->max) {
199 error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
200 dev->id?:"", name, value, prop->info->min,
205 PropertyInfo qdev_prop_uint16 = {
213 /* --- 32bit integer --- */
215 static void get_int32(Object *obj, Visitor *v, void *opaque,
216 const char *name, Error **errp)
218 DeviceState *dev = DEVICE(obj);
219 Property *prop = opaque;
220 int32_t *ptr = qdev_get_prop_ptr(dev, prop);
224 visit_type_int(v, &value, name, errp);
227 static void set_int32(Object *obj, Visitor *v, void *opaque,
228 const char *name, Error **errp)
230 DeviceState *dev = DEVICE(obj);
231 Property *prop = opaque;
232 int32_t *ptr = qdev_get_prop_ptr(dev, prop);
233 Error *local_err = NULL;
236 if (dev->state != DEV_STATE_CREATED) {
237 error_set(errp, QERR_PERMISSION_DENIED);
241 visit_type_int(v, &value, name, &local_err);
243 error_propagate(errp, local_err);
246 if (value >= prop->info->min && value <= prop->info->max) {
249 error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
250 dev->id?:"", name, value, prop->info->min,
255 PropertyInfo qdev_prop_uint32 = {
260 .max = 0xFFFFFFFFULL,
263 PropertyInfo qdev_prop_int32 = {
267 .min = -0x80000000LL,
271 /* --- 32bit hex value --- */
273 static int parse_hex32(DeviceState *dev, Property *prop, const char *str)
275 uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
278 if (str[0] != '0' || str[1] != 'x') {
282 *ptr = strtoul(str, &end, 16);
283 if ((*end != '\0') || (end == str)) {
290 static int print_hex32(DeviceState *dev, Property *prop, char *dest, size_t len)
292 uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
293 return snprintf(dest, len, "0x%" PRIx32, *ptr);
296 PropertyInfo qdev_prop_hex32 = {
298 .legacy_name = "hex32",
299 .parse = parse_hex32,
300 .print = print_hex32,
304 .max = 0xFFFFFFFFULL,
307 /* --- 64bit integer --- */
309 static void get_int64(Object *obj, Visitor *v, void *opaque,
310 const char *name, Error **errp)
312 DeviceState *dev = DEVICE(obj);
313 Property *prop = opaque;
314 int64_t *ptr = qdev_get_prop_ptr(dev, prop);
316 visit_type_int(v, ptr, name, errp);
319 static void set_int64(Object *obj, Visitor *v, void *opaque,
320 const char *name, Error **errp)
322 DeviceState *dev = DEVICE(obj);
323 Property *prop = opaque;
324 int64_t *ptr = qdev_get_prop_ptr(dev, prop);
326 if (dev->state != DEV_STATE_CREATED) {
327 error_set(errp, QERR_PERMISSION_DENIED);
331 visit_type_int(v, ptr, name, errp);
334 PropertyInfo qdev_prop_uint64 = {
340 /* --- 64bit hex value --- */
342 static int parse_hex64(DeviceState *dev, Property *prop, const char *str)
344 uint64_t *ptr = qdev_get_prop_ptr(dev, prop);
347 if (str[0] != '0' || str[1] != 'x') {
351 *ptr = strtoull(str, &end, 16);
352 if ((*end != '\0') || (end == str)) {
359 static int print_hex64(DeviceState *dev, Property *prop, char *dest, size_t len)
361 uint64_t *ptr = qdev_get_prop_ptr(dev, prop);
362 return snprintf(dest, len, "0x%" PRIx64, *ptr);
365 PropertyInfo qdev_prop_hex64 = {
367 .legacy_name = "hex64",
368 .parse = parse_hex64,
369 .print = print_hex64,
376 static void release_string(Object *obj, const char *name, void *opaque)
378 Property *prop = opaque;
379 g_free(*(char **)qdev_get_prop_ptr(DEVICE(obj), prop));
382 static int print_string(DeviceState *dev, Property *prop, char *dest, size_t len)
384 char **ptr = qdev_get_prop_ptr(dev, prop);
386 return snprintf(dest, len, "<null>");
387 return snprintf(dest, len, "\"%s\"", *ptr);
390 static void get_string(Object *obj, Visitor *v, void *opaque,
391 const char *name, Error **errp)
393 DeviceState *dev = DEVICE(obj);
394 Property *prop = opaque;
395 char **ptr = qdev_get_prop_ptr(dev, prop);
398 char *str = (char *)"";
399 visit_type_str(v, &str, name, errp);
401 visit_type_str(v, ptr, name, errp);
405 static void set_string(Object *obj, Visitor *v, void *opaque,
406 const char *name, Error **errp)
408 DeviceState *dev = DEVICE(obj);
409 Property *prop = opaque;
410 char **ptr = qdev_get_prop_ptr(dev, prop);
411 Error *local_err = NULL;
414 if (dev->state != DEV_STATE_CREATED) {
415 error_set(errp, QERR_PERMISSION_DENIED);
419 visit_type_str(v, &str, name, &local_err);
421 error_propagate(errp, local_err);
430 PropertyInfo qdev_prop_string = {
432 .print = print_string,
433 .release = release_string,
440 static int parse_drive(DeviceState *dev, const char *str, void **ptr)
442 BlockDriverState *bs;
447 if (bdrv_attach_dev(bs, dev) < 0)
453 static void release_drive(Object *obj, const char *name, void *opaque)
455 DeviceState *dev = DEVICE(obj);
456 Property *prop = opaque;
457 BlockDriverState **ptr = qdev_get_prop_ptr(dev, prop);
460 bdrv_detach_dev(*ptr, dev);
461 blockdev_auto_del(*ptr);
465 static const char *print_drive(void *ptr)
467 return bdrv_get_device_name(ptr);
470 static void get_pointer(Object *obj, Visitor *v, Property *prop,
471 const char *(*print)(void *ptr),
472 const char *name, Error **errp)
474 DeviceState *dev = DEVICE(obj);
475 void **ptr = qdev_get_prop_ptr(dev, prop);
478 p = (char *) (*ptr ? print(*ptr) : "");
479 visit_type_str(v, &p, name, errp);
482 static void set_pointer(Object *obj, Visitor *v, Property *prop,
483 int (*parse)(DeviceState *dev, const char *str, void **ptr),
484 const char *name, Error **errp)
486 DeviceState *dev = DEVICE(obj);
487 Error *local_err = NULL;
488 void **ptr = qdev_get_prop_ptr(dev, prop);
492 if (dev->state != DEV_STATE_CREATED) {
493 error_set(errp, QERR_PERMISSION_DENIED);
497 visit_type_str(v, &str, name, &local_err);
499 error_propagate(errp, local_err);
507 ret = parse(dev, str, ptr);
508 error_set_from_qdev_prop_error(errp, ret, dev, prop, str);
512 static void get_drive(Object *obj, Visitor *v, void *opaque,
513 const char *name, Error **errp)
515 get_pointer(obj, v, opaque, print_drive, name, errp);
518 static void set_drive(Object *obj, Visitor *v, void *opaque,
519 const char *name, Error **errp)
521 set_pointer(obj, v, opaque, parse_drive, name, errp);
524 PropertyInfo qdev_prop_drive = {
528 .release = release_drive,
531 /* --- character device --- */
533 static int parse_chr(DeviceState *dev, const char *str, void **ptr)
535 CharDriverState *chr = qemu_chr_find(str);
539 if (chr->avail_connections < 1) {
543 --chr->avail_connections;
547 static void release_chr(Object *obj, const char *name, void *opaque)
549 DeviceState *dev = DEVICE(obj);
550 Property *prop = opaque;
551 CharDriverState **ptr = qdev_get_prop_ptr(dev, prop);
554 qemu_chr_add_handlers(*ptr, NULL, NULL, NULL, NULL);
559 static const char *print_chr(void *ptr)
561 CharDriverState *chr = ptr;
563 return chr->label ? chr->label : "";
566 static void get_chr(Object *obj, Visitor *v, void *opaque,
567 const char *name, Error **errp)
569 get_pointer(obj, v, opaque, print_chr, name, errp);
572 static void set_chr(Object *obj, Visitor *v, void *opaque,
573 const char *name, Error **errp)
575 set_pointer(obj, v, opaque, parse_chr, name, errp);
578 PropertyInfo qdev_prop_chr = {
582 .release = release_chr,
585 /* --- netdev device --- */
587 static int parse_netdev(DeviceState *dev, const char *str, void **ptr)
589 VLANClientState *netdev = qemu_find_netdev(str);
591 if (netdev == NULL) {
601 static const char *print_netdev(void *ptr)
603 VLANClientState *netdev = ptr;
605 return netdev->name ? netdev->name : "";
608 static void get_netdev(Object *obj, Visitor *v, void *opaque,
609 const char *name, Error **errp)
611 get_pointer(obj, v, opaque, print_netdev, name, errp);
614 static void set_netdev(Object *obj, Visitor *v, void *opaque,
615 const char *name, Error **errp)
617 set_pointer(obj, v, opaque, parse_netdev, name, errp);
620 PropertyInfo qdev_prop_netdev = {
628 static int print_vlan(DeviceState *dev, Property *prop, char *dest, size_t len)
630 VLANState **ptr = qdev_get_prop_ptr(dev, prop);
633 return snprintf(dest, len, "%d", (*ptr)->id);
635 return snprintf(dest, len, "<null>");
639 static void get_vlan(Object *obj, Visitor *v, void *opaque,
640 const char *name, Error **errp)
642 DeviceState *dev = DEVICE(obj);
643 Property *prop = opaque;
644 VLANState **ptr = qdev_get_prop_ptr(dev, prop);
647 id = *ptr ? (*ptr)->id : -1;
648 visit_type_int(v, &id, name, errp);
651 static void set_vlan(Object *obj, Visitor *v, void *opaque,
652 const char *name, Error **errp)
654 DeviceState *dev = DEVICE(obj);
655 Property *prop = opaque;
656 VLANState **ptr = qdev_get_prop_ptr(dev, prop);
657 Error *local_err = NULL;
661 if (dev->state != DEV_STATE_CREATED) {
662 error_set(errp, QERR_PERMISSION_DENIED);
666 visit_type_int(v, &id, name, &local_err);
668 error_propagate(errp, local_err);
675 vlan = qemu_find_vlan(id, 1);
677 error_set(errp, QERR_INVALID_PARAMETER_VALUE,
678 name, prop->info->name);
684 PropertyInfo qdev_prop_vlan = {
691 /* --- pointer --- */
693 /* Not a proper property, just for dirty hacks. TODO Remove it! */
694 PropertyInfo qdev_prop_ptr = {
698 /* --- mac address --- */
701 * accepted syntax versions:
705 static void get_mac(Object *obj, Visitor *v, void *opaque,
706 const char *name, Error **errp)
708 DeviceState *dev = DEVICE(obj);
709 Property *prop = opaque;
710 MACAddr *mac = qdev_get_prop_ptr(dev, prop);
711 char buffer[2 * 6 + 5 + 1];
714 snprintf(buffer, sizeof(buffer), "%02x:%02x:%02x:%02x:%02x:%02x",
715 mac->a[0], mac->a[1], mac->a[2],
716 mac->a[3], mac->a[4], mac->a[5]);
718 visit_type_str(v, &p, name, errp);
721 static void set_mac(Object *obj, Visitor *v, void *opaque,
722 const char *name, Error **errp)
724 DeviceState *dev = DEVICE(obj);
725 Property *prop = opaque;
726 MACAddr *mac = qdev_get_prop_ptr(dev, prop);
727 Error *local_err = NULL;
731 if (dev->state != DEV_STATE_CREATED) {
732 error_set(errp, QERR_PERMISSION_DENIED);
736 visit_type_str(v, &str, name, &local_err);
738 error_propagate(errp, local_err);
742 for (i = 0, pos = 0; i < 6; i++, pos += 3) {
743 if (!qemu_isxdigit(str[pos]))
745 if (!qemu_isxdigit(str[pos+1]))
748 if (str[pos+2] != '\0')
751 if (str[pos+2] != ':' && str[pos+2] != '-')
754 mac->a[i] = strtol(str+pos, &p, 16);
760 error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
764 PropertyInfo qdev_prop_macaddr = {
771 /* --- lost tick policy --- */
773 static const char *lost_tick_policy_table[LOST_TICK_MAX+1] = {
774 [LOST_TICK_DISCARD] = "discard",
775 [LOST_TICK_DELAY] = "delay",
776 [LOST_TICK_MERGE] = "merge",
777 [LOST_TICK_SLEW] = "slew",
778 [LOST_TICK_MAX] = NULL,
781 QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy) != sizeof(int));
783 static void get_enum(Object *obj, Visitor *v, void *opaque,
784 const char *name, Error **errp)
786 DeviceState *dev = DEVICE(obj);
787 Property *prop = opaque;
788 int *ptr = qdev_get_prop_ptr(dev, prop);
790 visit_type_enum(v, ptr, prop->info->enum_table,
791 prop->info->name, prop->name, errp);
794 static void set_enum(Object *obj, Visitor *v, void *opaque,
795 const char *name, Error **errp)
797 DeviceState *dev = DEVICE(obj);
798 Property *prop = opaque;
799 int *ptr = qdev_get_prop_ptr(dev, prop);
801 if (dev->state != DEV_STATE_CREATED) {
802 error_set(errp, QERR_PERMISSION_DENIED);
806 visit_type_enum(v, ptr, prop->info->enum_table,
807 prop->info->name, prop->name, errp);
810 PropertyInfo qdev_prop_losttickpolicy = {
811 .name = "LostTickPolicy",
812 .enum_table = lost_tick_policy_table,
817 /* --- pci address --- */
820 * bus-local address, i.e. "$slot" or "$slot.$fn"
822 static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
823 const char *name, Error **errp)
825 DeviceState *dev = DEVICE(obj);
826 Property *prop = opaque;
827 uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
828 unsigned int slot, fn, n;
829 Error *local_err = NULL;
832 if (dev->state != DEV_STATE_CREATED) {
833 error_set(errp, QERR_PERMISSION_DENIED);
837 visit_type_str(v, &str, name, &local_err);
839 error_free(local_err);
840 return set_int32(obj, v, opaque, name, errp);
843 if (sscanf(str, "%x.%x%n", &slot, &fn, &n) != 2) {
845 if (sscanf(str, "%x%n", &slot, &n) != 1) {
849 if (str[n] != '\0' || fn > 7 || slot > 31) {
852 *ptr = slot << 3 | fn;
857 error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
861 static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest, size_t len)
863 uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
866 return snprintf(dest, len, "<unset>");
868 return snprintf(dest, len, "%02x.%x", *ptr >> 3, *ptr & 7);
872 PropertyInfo qdev_prop_pci_devfn = {
874 .legacy_name = "pci-devfn",
875 .print = print_pci_devfn,
877 .set = set_pci_devfn,
878 /* FIXME: this should be -1...255, but the address is stored
879 * into an uint32_t rather than int32_t.
882 .max = 0xFFFFFFFFULL,
885 /* --- blocksize --- */
887 static void set_blocksize(Object *obj, Visitor *v, void *opaque,
888 const char *name, Error **errp)
890 DeviceState *dev = DEVICE(obj);
891 Property *prop = opaque;
892 int16_t *ptr = qdev_get_prop_ptr(dev, prop);
893 Error *local_err = NULL;
896 if (dev->state != DEV_STATE_CREATED) {
897 error_set(errp, QERR_PERMISSION_DENIED);
901 visit_type_int(v, &value, name, &local_err);
903 error_propagate(errp, local_err);
906 if (value < prop->info->min || value > prop->info->max) {
907 error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
908 dev->id?:"", name, value, prop->info->min,
913 /* We rely on power-of-2 blocksizes for bitmasks */
914 if ((value & (value - 1)) != 0) {
915 error_set(errp, QERR_PROPERTY_VALUE_NOT_POWER_OF_2,
916 dev->id?:"", name, value);
923 PropertyInfo qdev_prop_blocksize = {
926 .set = set_blocksize,
931 /* --- public helpers --- */
933 static Property *qdev_prop_walk(Property *props, const char *name)
937 while (props->name) {
938 if (strcmp(props->name, name) == 0)
945 static Property *qdev_prop_find(DeviceState *dev, const char *name)
949 /* device properties */
950 prop = qdev_prop_walk(qdev_get_props(dev), name);
955 prop = qdev_prop_walk(dev->parent_bus->info->props, name);
962 int qdev_prop_exists(DeviceState *dev, const char *name)
964 return qdev_prop_find(dev, name) ? true : false;
967 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
968 Property *prop, const char *value)
972 error_set(errp, QERR_PROPERTY_VALUE_IN_USE,
973 object_get_typename(OBJECT(dev)), prop->name, value);
977 error_set(errp, QERR_PROPERTY_VALUE_BAD,
978 object_get_typename(OBJECT(dev)), prop->name, value);
981 error_set(errp, QERR_PROPERTY_VALUE_NOT_FOUND,
982 object_get_typename(OBJECT(dev)), prop->name, value);
989 int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
994 legacy_name = g_strdup_printf("legacy-%s", name);
995 if (object_property_get_type(OBJECT(dev), legacy_name, NULL)) {
996 object_property_parse(OBJECT(dev), value, legacy_name, &err);
998 object_property_parse(OBJECT(dev), value, name, &err);
1000 g_free(legacy_name);
1003 qerror_report_err(err);
1010 void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value)
1013 object_property_set_bool(OBJECT(dev), value, name, &errp);
1014 assert_no_error(errp);
1017 void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value)
1020 object_property_set_int(OBJECT(dev), value, name, &errp);
1021 assert_no_error(errp);
1024 void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value)
1027 object_property_set_int(OBJECT(dev), value, name, &errp);
1028 assert_no_error(errp);
1031 void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value)
1034 object_property_set_int(OBJECT(dev), value, name, &errp);
1035 assert_no_error(errp);
1038 void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value)
1041 object_property_set_int(OBJECT(dev), value, name, &errp);
1042 assert_no_error(errp);
1045 void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value)
1048 object_property_set_int(OBJECT(dev), value, name, &errp);
1049 assert_no_error(errp);
1052 void qdev_prop_set_string(DeviceState *dev, const char *name, char *value)
1055 object_property_set_str(OBJECT(dev), value, name, &errp);
1056 assert_no_error(errp);
1059 int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value)
1062 const char *bdrv_name = value ? bdrv_get_device_name(value) : "";
1063 object_property_set_str(OBJECT(dev), bdrv_name,
1066 qerror_report_err(errp);
1073 void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverState *value)
1075 if (qdev_prop_set_drive(dev, name, value) < 0) {
1079 void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value)
1082 assert(!value || value->label);
1083 object_property_set_str(OBJECT(dev),
1084 value ? value->label : "", name, &errp);
1085 assert_no_error(errp);
1088 void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value)
1091 assert(!value || value->name);
1092 object_property_set_str(OBJECT(dev),
1093 value ? value->name : "", name, &errp);
1094 assert_no_error(errp);
1097 void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value)
1100 object_property_set_int(OBJECT(dev), value ? value->id : -1, name, &errp);
1101 assert_no_error(errp);
1104 void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value)
1107 char str[2 * 6 + 5 + 1];
1108 snprintf(str, sizeof(str), "%02x:%02x:%02x:%02x:%02x:%02x",
1109 value[0], value[1], value[2], value[3], value[4], value[5]);
1111 object_property_set_str(OBJECT(dev), str, name, &errp);
1112 assert_no_error(errp);
1115 void qdev_prop_set_enum(DeviceState *dev, const char *name, int value)
1120 prop = qdev_prop_find(dev, name);
1121 object_property_set_str(OBJECT(dev), prop->info->enum_table[value],
1123 assert_no_error(errp);
1126 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
1131 prop = qdev_prop_find(dev, name);
1132 assert(prop && prop->info == &qdev_prop_ptr);
1133 ptr = qdev_get_prop_ptr(dev, prop);
1137 void qdev_prop_set_defaults(DeviceState *dev, Property *props)
1139 Object *obj = OBJECT(dev);
1142 for (; props->name; props++) {
1144 if (props->qtype == QTYPE_NONE) {
1147 if (props->qtype == QTYPE_QBOOL) {
1148 object_property_set_bool(obj, props->defval, props->name, &errp);
1149 } else if (props->info->enum_table) {
1150 object_property_set_str(obj, props->info->enum_table[props->defval],
1151 props->name, &errp);
1152 } else if (props->qtype == QTYPE_QINT) {
1153 object_property_set_int(obj, props->defval, props->name, &errp);
1155 assert_no_error(errp);
1159 static QTAILQ_HEAD(, GlobalProperty) global_props = QTAILQ_HEAD_INITIALIZER(global_props);
1161 static void qdev_prop_register_global(GlobalProperty *prop)
1163 QTAILQ_INSERT_TAIL(&global_props, prop, next);
1166 void qdev_prop_register_global_list(GlobalProperty *props)
1170 for (i = 0; props[i].driver != NULL; i++) {
1171 qdev_prop_register_global(props+i);
1175 void qdev_prop_set_globals(DeviceState *dev)
1177 GlobalProperty *prop;
1179 QTAILQ_FOREACH(prop, &global_props, next) {
1180 if (strcmp(object_get_typename(OBJECT(dev)), prop->driver) != 0 &&
1181 strcmp(qdev_get_bus_info(dev)->name, prop->driver) != 0) {
1184 if (qdev_prop_parse(dev, prop->property, prop->value) != 0) {
1190 static int qdev_add_one_global(QemuOpts *opts, void *opaque)
1194 g = g_malloc0(sizeof(*g));
1195 g->driver = qemu_opt_get(opts, "driver");
1196 g->property = qemu_opt_get(opts, "property");
1197 g->value = qemu_opt_get(opts, "value");
1198 qdev_prop_register_global(g);
1202 void qemu_add_globals(void)
1204 qemu_opts_foreach(qemu_find_opts("global"), qdev_add_one_global, NULL, 0);