| 1 | /* |
| 2 | * QEMU Object Model |
| 3 | * |
| 4 | * Copyright IBM, Corp. 2011 |
| 5 | * |
| 6 | * Authors: |
| 7 | * Anthony Liguori <aliguori@us.ibm.com> |
| 8 | * |
| 9 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 10 | */ |
| 11 | |
| 12 | #include "qemu/osdep.h" |
| 13 | #include "qapi/error.h" |
| 14 | #include "qom/compat-properties.h" |
| 15 | #include "qom/qom-qobject.h" |
| 16 | #include "hw/core/qdev.h" |
| 17 | |
| 18 | /* |
| 19 | * Global property defaults |
| 20 | * Slot 0: accelerator's global property defaults |
| 21 | * Slot 1: machine's global property defaults |
| 22 | * Slot 2: global properties from legacy command line option |
| 23 | * Each is a GPtrArray of GlobalProperty. |
| 24 | * Applied in order, later entries override earlier ones. |
| 25 | */ |
| 26 | static GPtrArray *object_compat_props[3]; |
| 27 | |
| 28 | /* |
| 29 | * Retrieve @GPtrArray for global property defined with options |
| 30 | * other than "-global". These are generally used for syntactic |
| 31 | * sugar and legacy command line options. |
| 32 | */ |
| 33 | void object_register_sugar_prop(const char *driver, const char *prop, |
| 34 | const char *value, bool optional) |
| 35 | { |
| 36 | GlobalProperty *g; |
| 37 | if (!object_compat_props[2]) { |
| 38 | object_compat_props[2] = g_ptr_array_new(); |
| 39 | } |
| 40 | g = g_new0(GlobalProperty, 1); |
| 41 | g->driver = g_strdup(driver); |
| 42 | g->property = g_strdup(prop); |
| 43 | g->value = g_strdup(value); |
| 44 | g->optional = optional; |
| 45 | g_ptr_array_add(object_compat_props[2], g); |
| 46 | } |
| 47 | |
| 48 | /* |
| 49 | * Set machine's global property defaults to @compat_props. |
| 50 | * May be called at most once. |
| 51 | */ |
| 52 | void object_set_machine_compat_props(GPtrArray *compat_props) |
| 53 | { |
| 54 | assert(!object_compat_props[1]); |
| 55 | object_compat_props[1] = compat_props; |
| 56 | } |
| 57 | |
| 58 | /* |
| 59 | * Set accelerator's global property defaults to @compat_props. |
| 60 | * May be called at most once. |
| 61 | */ |
| 62 | void object_set_accelerator_compat_props(GPtrArray *compat_props) |
| 63 | { |
| 64 | assert(!object_compat_props[0]); |
| 65 | object_compat_props[0] = compat_props; |
| 66 | } |
| 67 | |
| 68 | void object_apply_compat_props(Object *obj) |
| 69 | { |
| 70 | int i; |
| 71 | |
| 72 | for (i = 0; i < ARRAY_SIZE(object_compat_props); i++) { |
| 73 | object_apply_global_props(obj, object_compat_props[i], |
| 74 | i == 2 ? &error_fatal : &error_abort); |
| 75 | } |
| 76 | } |