X-Git-Url: https://repo.jachan.dev/qemu.git/blobdiff_plain/a598f2ffc2df59afcea5454fb353b849911da90b..f3e69beb942103ccd5248273e4d95e76b64ab64c:/bootdevice.c diff --git a/bootdevice.c b/bootdevice.c index a38479a72a..b29970c7a3 100644 --- a/bootdevice.c +++ b/bootdevice.c @@ -23,6 +23,8 @@ */ #include "sysemu/sysemu.h" +#include "qapi/visitor.h" +#include "qemu/error-report.h" typedef struct FWBootEntry FWBootEntry; @@ -92,7 +94,7 @@ void add_boot_device_path(int32_t bootindex, DeviceState *dev, QTAILQ_FOREACH(i, &fw_boot_order, link) { if (i->bootindex == bootindex) { - fprintf(stderr, "Two devices with same boot index %d\n", bootindex); + error_report("Two devices with same boot index %d", bootindex); exit(1); } else if (i->bootindex < bootindex) { continue; @@ -178,3 +180,79 @@ char *get_boot_devices_list(size_t *size, bool ignore_suffixes) } return list; } + +typedef struct { + int32_t *bootindex; + const char *suffix; + DeviceState *dev; +} BootIndexProperty; + +static void device_get_bootindex(Object *obj, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + BootIndexProperty *prop = opaque; + visit_type_int32(v, prop->bootindex, name, errp); +} + +static void device_set_bootindex(Object *obj, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + BootIndexProperty *prop = opaque; + int32_t boot_index; + Error *local_err = NULL; + + visit_type_int32(v, &boot_index, name, &local_err); + if (local_err) { + goto out; + } + /* check whether bootindex is present in fw_boot_order list */ + check_boot_index(boot_index, &local_err); + if (local_err) { + goto out; + } + /* change bootindex to a new one */ + *prop->bootindex = boot_index; + + add_boot_device_path(*prop->bootindex, prop->dev, prop->suffix); + +out: + if (local_err) { + error_propagate(errp, local_err); + } +} + +static void property_release_bootindex(Object *obj, const char *name, + void *opaque) + +{ + BootIndexProperty *prop = opaque; + + del_boot_device_path(prop->dev, prop->suffix); + g_free(prop); +} + +void device_add_bootindex_property(Object *obj, int32_t *bootindex, + const char *name, const char *suffix, + DeviceState *dev, Error **errp) +{ + Error *local_err = NULL; + BootIndexProperty *prop = g_malloc0(sizeof(*prop)); + + prop->bootindex = bootindex; + prop->suffix = suffix; + prop->dev = dev; + + object_property_add(obj, name, "int32", + device_get_bootindex, + device_set_bootindex, + property_release_bootindex, + prop, &local_err); + + if (local_err) { + error_propagate(errp, local_err); + g_free(prop); + return; + } + /* initialize devices' bootindex property to -1 */ + object_property_set_int(obj, -1, name, NULL); +}