2014-10-07 10:00:05 +02:00
|
|
|
/*
|
|
|
|
* QEMU Boot Device Implement
|
|
|
|
*
|
2015-03-26 13:57:43 +01:00
|
|
|
* Copyright (c) 2014 HUAWEI TECHNOLOGIES CO., LTD.
|
2014-10-07 10:00:05 +02:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2016-01-29 18:50:05 +01:00
|
|
|
#include "qemu/osdep.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2014-10-07 10:00:05 +02:00
|
|
|
#include "sysemu/sysemu.h"
|
2014-10-07 10:00:11 +02:00
|
|
|
#include "qapi/visitor.h"
|
2014-10-07 10:00:38 +02:00
|
|
|
#include "qemu/error-report.h"
|
2017-06-26 07:22:57 +02:00
|
|
|
#include "sysemu/reset.h"
|
2015-12-04 11:10:27 +01:00
|
|
|
#include "hw/qdev-core.h"
|
2018-08-10 14:40:27 +02:00
|
|
|
#include "hw/boards.h"
|
2014-10-07 10:00:05 +02:00
|
|
|
|
|
|
|
typedef struct FWBootEntry FWBootEntry;
|
|
|
|
|
|
|
|
struct FWBootEntry {
|
|
|
|
QTAILQ_ENTRY(FWBootEntry) link;
|
|
|
|
int32_t bootindex;
|
|
|
|
DeviceState *dev;
|
|
|
|
char *suffix;
|
|
|
|
};
|
|
|
|
|
|
|
|
static QTAILQ_HEAD(, FWBootEntry) fw_boot_order =
|
|
|
|
QTAILQ_HEAD_INITIALIZER(fw_boot_order);
|
2014-12-03 17:49:46 +01:00
|
|
|
static QEMUBootSetHandler *boot_set_handler;
|
|
|
|
static void *boot_set_opaque;
|
|
|
|
|
|
|
|
void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
|
|
|
|
{
|
|
|
|
boot_set_handler = func;
|
|
|
|
boot_set_opaque = opaque;
|
|
|
|
}
|
|
|
|
|
2014-12-03 19:20:58 +01:00
|
|
|
void qemu_boot_set(const char *boot_order, Error **errp)
|
2014-12-03 17:49:46 +01:00
|
|
|
{
|
2014-12-03 19:25:46 +01:00
|
|
|
Error *local_err = NULL;
|
|
|
|
|
2014-12-03 17:49:46 +01:00
|
|
|
if (!boot_set_handler) {
|
2014-12-03 19:20:58 +01:00
|
|
|
error_setg(errp, "no function defined to set boot device list for"
|
|
|
|
" this architecture");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-03 19:25:46 +01:00
|
|
|
validate_bootdevices(boot_order, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-03 20:04:02 +01:00
|
|
|
boot_set_handler(boot_set_opaque, boot_order, errp);
|
2014-12-03 17:49:46 +01:00
|
|
|
}
|
|
|
|
|
2014-12-03 18:11:39 +01:00
|
|
|
void validate_bootdevices(const char *devices, Error **errp)
|
2014-12-03 17:49:46 +01:00
|
|
|
{
|
|
|
|
/* We just do some generic consistency checks */
|
|
|
|
const char *p;
|
|
|
|
int bitmap = 0;
|
|
|
|
|
|
|
|
for (p = devices; *p != '\0'; p++) {
|
|
|
|
/* Allowed boot devices are:
|
|
|
|
* a-b: floppy disk drives
|
|
|
|
* c-f: IDE disk drives
|
|
|
|
* g-m: machine implementation dependent drives
|
|
|
|
* n-p: network devices
|
|
|
|
* It's up to each machine implementation to check if the given boot
|
|
|
|
* devices match the actual hardware implementation and firmware
|
|
|
|
* features.
|
|
|
|
*/
|
|
|
|
if (*p < 'a' || *p > 'p') {
|
2014-12-03 18:11:39 +01:00
|
|
|
error_setg(errp, "Invalid boot device '%c'", *p);
|
|
|
|
return;
|
2014-12-03 17:49:46 +01:00
|
|
|
}
|
|
|
|
if (bitmap & (1 << (*p - 'a'))) {
|
2014-12-03 18:11:39 +01:00
|
|
|
error_setg(errp, "Boot device '%c' was given twice", *p);
|
|
|
|
return;
|
2014-12-03 17:49:46 +01:00
|
|
|
}
|
|
|
|
bitmap |= 1 << (*p - 'a');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void restore_boot_order(void *opaque)
|
|
|
|
{
|
|
|
|
char *normal_boot_order = opaque;
|
|
|
|
static int first = 1;
|
|
|
|
|
|
|
|
/* Restore boot order and remove ourselves after the first boot */
|
|
|
|
if (first) {
|
|
|
|
first = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-29 14:13:47 +01:00
|
|
|
if (boot_set_handler) {
|
|
|
|
qemu_boot_set(normal_boot_order, &error_abort);
|
|
|
|
}
|
2014-12-03 17:49:46 +01:00
|
|
|
|
|
|
|
qemu_unregister_reset(restore_boot_order, normal_boot_order);
|
|
|
|
g_free(normal_boot_order);
|
|
|
|
}
|
2014-10-07 10:00:05 +02:00
|
|
|
|
2014-10-07 10:00:06 +02:00
|
|
|
void check_boot_index(int32_t bootindex, Error **errp)
|
|
|
|
{
|
|
|
|
FWBootEntry *i;
|
|
|
|
|
|
|
|
if (bootindex >= 0) {
|
|
|
|
QTAILQ_FOREACH(i, &fw_boot_order, link) {
|
|
|
|
if (i->bootindex == bootindex) {
|
|
|
|
error_setg(errp, "The bootindex %d has already been used",
|
|
|
|
bootindex);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-07 10:00:07 +02:00
|
|
|
void del_boot_device_path(DeviceState *dev, const char *suffix)
|
|
|
|
{
|
|
|
|
FWBootEntry *i;
|
|
|
|
|
|
|
|
if (dev == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(i, &fw_boot_order, link) {
|
|
|
|
if ((!suffix || !g_strcmp0(i->suffix, suffix)) &&
|
|
|
|
i->dev == dev) {
|
|
|
|
QTAILQ_REMOVE(&fw_boot_order, i, link);
|
|
|
|
g_free(i->suffix);
|
|
|
|
g_free(i);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-07 10:00:05 +02:00
|
|
|
void add_boot_device_path(int32_t bootindex, DeviceState *dev,
|
|
|
|
const char *suffix)
|
|
|
|
{
|
|
|
|
FWBootEntry *node, *i;
|
|
|
|
|
|
|
|
if (bootindex < 0) {
|
2014-10-07 10:00:10 +02:00
|
|
|
del_boot_device_path(dev, suffix);
|
2014-10-07 10:00:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(dev != NULL || suffix != NULL);
|
|
|
|
|
2014-10-07 10:00:09 +02:00
|
|
|
del_boot_device_path(dev, suffix);
|
|
|
|
|
2014-10-07 10:00:05 +02:00
|
|
|
node = g_malloc0(sizeof(FWBootEntry));
|
|
|
|
node->bootindex = bootindex;
|
|
|
|
node->suffix = g_strdup(suffix);
|
|
|
|
node->dev = dev;
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(i, &fw_boot_order, link) {
|
|
|
|
if (i->bootindex == bootindex) {
|
2014-10-07 10:00:38 +02:00
|
|
|
error_report("Two devices with same boot index %d", bootindex);
|
2014-10-07 10:00:05 +02:00
|
|
|
exit(1);
|
|
|
|
} else if (i->bootindex < bootindex) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
QTAILQ_INSERT_BEFORE(i, node, link);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceState *get_boot_device(uint32_t position)
|
|
|
|
{
|
|
|
|
uint32_t counter = 0;
|
|
|
|
FWBootEntry *i = NULL;
|
|
|
|
DeviceState *res = NULL;
|
|
|
|
|
|
|
|
if (!QTAILQ_EMPTY(&fw_boot_order)) {
|
|
|
|
QTAILQ_FOREACH(i, &fw_boot_order, link) {
|
|
|
|
if (counter == position) {
|
|
|
|
res = i->dev;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
counter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-10-16 18:41:43 +02:00
|
|
|
static char *get_boot_device_path(DeviceState *dev, bool ignore_suffixes,
|
|
|
|
const char *suffix)
|
|
|
|
{
|
|
|
|
char *devpath = NULL, *s = NULL, *d, *bootpath;
|
|
|
|
|
|
|
|
if (dev) {
|
|
|
|
devpath = qdev_get_fw_dev_path(dev);
|
|
|
|
assert(devpath);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ignore_suffixes) {
|
|
|
|
if (dev) {
|
|
|
|
d = qdev_get_own_fw_dev_path_from_handler(dev->parent_bus, dev);
|
|
|
|
if (d) {
|
|
|
|
assert(!suffix);
|
|
|
|
s = d;
|
|
|
|
} else {
|
|
|
|
s = g_strdup(suffix);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
s = g_strdup(suffix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bootpath = g_strdup_printf("%s%s",
|
|
|
|
devpath ? devpath : "",
|
|
|
|
s ? s : "");
|
|
|
|
g_free(devpath);
|
|
|
|
g_free(s);
|
|
|
|
|
|
|
|
return bootpath;
|
|
|
|
}
|
|
|
|
|
2014-10-07 10:00:05 +02:00
|
|
|
/*
|
|
|
|
* This function returns null terminated string that consist of new line
|
|
|
|
* separated device paths.
|
|
|
|
*
|
|
|
|
* memory pointed by "size" is assigned total length of the array in bytes
|
|
|
|
*
|
|
|
|
*/
|
2018-08-10 14:40:27 +02:00
|
|
|
char *get_boot_devices_list(size_t *size)
|
2014-10-07 10:00:05 +02:00
|
|
|
{
|
|
|
|
FWBootEntry *i;
|
|
|
|
size_t total = 0;
|
|
|
|
char *list = NULL;
|
2018-08-10 14:40:27 +02:00
|
|
|
MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine());
|
|
|
|
bool ignore_suffixes = mc->ignore_boot_device_suffixes;
|
2014-10-07 10:00:05 +02:00
|
|
|
|
|
|
|
QTAILQ_FOREACH(i, &fw_boot_order, link) {
|
2015-01-29 08:08:51 +01:00
|
|
|
char *bootpath;
|
2014-10-07 10:00:05 +02:00
|
|
|
size_t len;
|
|
|
|
|
2019-10-16 18:41:43 +02:00
|
|
|
bootpath = get_boot_device_path(i->dev, ignore_suffixes, i->suffix);
|
2015-01-29 08:08:51 +01:00
|
|
|
|
2014-10-07 10:00:05 +02:00
|
|
|
if (total) {
|
|
|
|
list[total-1] = '\n';
|
|
|
|
}
|
|
|
|
len = strlen(bootpath) + 1;
|
|
|
|
list = g_realloc(list, total + len);
|
|
|
|
memcpy(&list[total], bootpath, len);
|
|
|
|
total += len;
|
|
|
|
g_free(bootpath);
|
|
|
|
}
|
|
|
|
|
|
|
|
*size = total;
|
|
|
|
|
|
|
|
if (boot_strict && *size > 0) {
|
|
|
|
list[total-1] = '\n';
|
|
|
|
list = g_realloc(list, total + 5);
|
|
|
|
memcpy(&list[total], "HALT", 5);
|
|
|
|
*size = total + 5;
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
2014-10-07 10:00:11 +02:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int32_t *bootindex;
|
|
|
|
const char *suffix;
|
|
|
|
DeviceState *dev;
|
|
|
|
} BootIndexProperty;
|
|
|
|
|
qom: Swap 'name' next to visitor in ObjectPropertyAccessor
Similar to the previous patch, it's nice to have all functions
in the tree that involve a visitor and a name for conversion to
or from QAPI to consistently stick the 'name' parameter next
to the Visitor parameter.
Done by manually changing include/qom/object.h and qom/object.c,
then running this Coccinelle script and touching up the fallout
(Coccinelle insisted on adding some trailing whitespace).
@ rule1 @
identifier fn;
typedef Object, Visitor, Error;
identifier obj, v, opaque, name, errp;
@@
void fn
- (Object *obj, Visitor *v, void *opaque, const char *name,
+ (Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp) { ... }
@@
identifier rule1.fn;
expression obj, v, opaque, name, errp;
@@
fn(obj, v,
- opaque, name,
+ name, opaque,
errp)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-20-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:55 +01:00
|
|
|
static void device_get_bootindex(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
2014-10-07 10:00:11 +02:00
|
|
|
{
|
|
|
|
BootIndexProperty *prop = opaque;
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:54 +01:00
|
|
|
visit_type_int32(v, name, prop->bootindex, errp);
|
2014-10-07 10:00:11 +02:00
|
|
|
}
|
|
|
|
|
qom: Swap 'name' next to visitor in ObjectPropertyAccessor
Similar to the previous patch, it's nice to have all functions
in the tree that involve a visitor and a name for conversion to
or from QAPI to consistently stick the 'name' parameter next
to the Visitor parameter.
Done by manually changing include/qom/object.h and qom/object.c,
then running this Coccinelle script and touching up the fallout
(Coccinelle insisted on adding some trailing whitespace).
@ rule1 @
identifier fn;
typedef Object, Visitor, Error;
identifier obj, v, opaque, name, errp;
@@
void fn
- (Object *obj, Visitor *v, void *opaque, const char *name,
+ (Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp) { ... }
@@
identifier rule1.fn;
expression obj, v, opaque, name, errp;
@@
fn(obj, v,
- opaque, name,
+ name, opaque,
errp)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-20-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:55 +01:00
|
|
|
static void device_set_bootindex(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
2014-10-07 10:00:11 +02:00
|
|
|
{
|
|
|
|
BootIndexProperty *prop = opaque;
|
|
|
|
int32_t boot_index;
|
|
|
|
Error *local_err = NULL;
|
|
|
|
|
2020-07-07 18:05:47 +02:00
|
|
|
if (!visit_type_int32(v, name, &boot_index, errp)) {
|
|
|
|
return;
|
2014-10-07 10:00:11 +02:00
|
|
|
}
|
|
|
|
/* check whether bootindex is present in fw_boot_order list */
|
|
|
|
check_boot_index(boot_index, &local_err);
|
|
|
|
if (local_err) {
|
2020-07-07 18:06:04 +02:00
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
2014-10-07 10:00:11 +02:00
|
|
|
}
|
|
|
|
/* change bootindex to a new one */
|
|
|
|
*prop->bootindex = boot_index;
|
|
|
|
|
2014-10-07 10:00:36 +02:00
|
|
|
add_boot_device_path(*prop->bootindex, prop->dev, prop->suffix);
|
2014-10-07 10:00:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void property_release_bootindex(Object *obj, const char *name,
|
|
|
|
void *opaque)
|
|
|
|
|
|
|
|
{
|
|
|
|
BootIndexProperty *prop = opaque;
|
2014-10-07 10:00:37 +02:00
|
|
|
|
|
|
|
del_boot_device_path(prop->dev, prop->suffix);
|
2014-10-07 10:00:11 +02:00
|
|
|
g_free(prop);
|
|
|
|
}
|
|
|
|
|
|
|
|
void device_add_bootindex_property(Object *obj, int32_t *bootindex,
|
|
|
|
const char *name, const char *suffix,
|
2020-05-05 17:29:23 +02:00
|
|
|
DeviceState *dev)
|
2014-10-07 10:00:11 +02:00
|
|
|
{
|
|
|
|
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,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 17:29:22 +02:00
|
|
|
prop);
|
2014-10-07 10:00:11 +02:00
|
|
|
|
|
|
|
/* initialize devices' bootindex property to -1 */
|
qom: Put name parameter before value / visitor parameter
The object_property_set_FOO() setters take property name and value in
an unusual order:
void object_property_set_FOO(Object *obj, FOO_TYPE value,
const char *name, Error **errp)
Having to pass value before name feels grating. Swap them.
Same for object_property_set(), object_property_get(), and
object_property_parse().
Convert callers with this Coccinelle script:
@@
identifier fun = {
object_property_get, object_property_parse, object_property_set_str,
object_property_set_link, object_property_set_bool,
object_property_set_int, object_property_set_uint, object_property_set,
object_property_set_qobject
};
expression obj, v, name, errp;
@@
- fun(obj, v, name, errp)
+ fun(obj, name, v, errp)
Chokes on hw/arm/musicpal.c's lcd_refresh() with the unhelpful error
message "no position information". Convert that one manually.
Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
ARMSSE being used both as typedef and function-like macro there.
Convert manually.
Fails to convert hw/rx/rx-gdbsim.c, because Coccinelle gets confused
by RXCPU being used both as typedef and function-like macro there.
Convert manually. The other files using RXCPU that way don't need
conversion.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200707160613.848843-27-armbru@redhat.com>
[Straightforwad conflict with commit 2336172d9b "audio: set default
value for pcspk.iobase property" resolved]
2020-07-07 18:05:54 +02:00
|
|
|
object_property_set_int(obj, name, -1, NULL);
|
2014-10-07 10:00:11 +02:00
|
|
|
}
|
2019-10-16 18:41:40 +02:00
|
|
|
|
|
|
|
typedef struct FWLCHSEntry FWLCHSEntry;
|
|
|
|
|
|
|
|
struct FWLCHSEntry {
|
|
|
|
QTAILQ_ENTRY(FWLCHSEntry) link;
|
|
|
|
DeviceState *dev;
|
|
|
|
char *suffix;
|
|
|
|
uint32_t lcyls;
|
|
|
|
uint32_t lheads;
|
|
|
|
uint32_t lsecs;
|
|
|
|
};
|
|
|
|
|
|
|
|
static QTAILQ_HEAD(, FWLCHSEntry) fw_lchs =
|
|
|
|
QTAILQ_HEAD_INITIALIZER(fw_lchs);
|
|
|
|
|
|
|
|
void add_boot_device_lchs(DeviceState *dev, const char *suffix,
|
|
|
|
uint32_t lcyls, uint32_t lheads, uint32_t lsecs)
|
|
|
|
{
|
|
|
|
FWLCHSEntry *node;
|
|
|
|
|
|
|
|
if (!lcyls && !lheads && !lsecs) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(dev != NULL || suffix != NULL);
|
|
|
|
|
|
|
|
node = g_malloc0(sizeof(FWLCHSEntry));
|
|
|
|
node->suffix = g_strdup(suffix);
|
|
|
|
node->dev = dev;
|
|
|
|
node->lcyls = lcyls;
|
|
|
|
node->lheads = lheads;
|
|
|
|
node->lsecs = lsecs;
|
|
|
|
|
|
|
|
QTAILQ_INSERT_TAIL(&fw_lchs, node, link);
|
|
|
|
}
|
|
|
|
|
|
|
|
void del_boot_device_lchs(DeviceState *dev, const char *suffix)
|
|
|
|
{
|
|
|
|
FWLCHSEntry *i;
|
|
|
|
|
|
|
|
if (dev == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(i, &fw_lchs, link) {
|
|
|
|
if ((!suffix || !g_strcmp0(i->suffix, suffix)) &&
|
|
|
|
i->dev == dev) {
|
|
|
|
QTAILQ_REMOVE(&fw_lchs, i, link);
|
|
|
|
g_free(i->suffix);
|
|
|
|
g_free(i);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-16 18:41:44 +02:00
|
|
|
|
|
|
|
char *get_boot_devices_lchs_list(size_t *size)
|
|
|
|
{
|
|
|
|
FWLCHSEntry *i;
|
|
|
|
size_t total = 0;
|
|
|
|
char *list = NULL;
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(i, &fw_lchs, link) {
|
|
|
|
char *bootpath;
|
|
|
|
char *chs_string;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
bootpath = get_boot_device_path(i->dev, false, i->suffix);
|
|
|
|
chs_string = g_strdup_printf("%s %" PRIu32 " %" PRIu32 " %" PRIu32,
|
|
|
|
bootpath, i->lcyls, i->lheads, i->lsecs);
|
|
|
|
|
|
|
|
if (total) {
|
|
|
|
list[total - 1] = '\n';
|
|
|
|
}
|
|
|
|
len = strlen(chs_string) + 1;
|
|
|
|
list = g_realloc(list, total + len);
|
|
|
|
memcpy(&list[total], chs_string, len);
|
|
|
|
total += len;
|
|
|
|
g_free(chs_string);
|
|
|
|
g_free(bootpath);
|
|
|
|
}
|
|
|
|
|
|
|
|
*size = total;
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|