[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-ppc] [PATCH for-3.2 v3 12/14] machine: add compat-props interface
From: |
Marc-André Lureau |
Subject: |
[Qemu-ppc] [PATCH for-3.2 v3 12/14] machine: add compat-props interface |
Date: |
Wed, 7 Nov 2018 16:36:50 +0400 |
Let's make compatiblity properties an interface, so that objects other
than QDev can benefit from having machine compatiblity properties.
Signed-off-by: Marc-André Lureau <address@hidden>
---
include/hw/boards.h | 2 ++
hw/core/compat-props.c | 43 ++++++++++++++++++++++++++++++++++++++++++
hw/core/qdev.c | 12 ++++--------
MAINTAINERS | 1 +
hw/core/Makefile.objs | 1 +
tests/Makefile.include | 1 +
6 files changed, 52 insertions(+), 8 deletions(-)
create mode 100644 hw/core/compat-props.c
diff --git a/include/hw/boards.h b/include/hw/boards.h
index c02190fc52..e09cbe70a4 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -9,6 +9,8 @@
#include "qom/object.h"
#include "qom/cpu.h"
+#define TYPE_COMPAT_PROPS "compat-props"
+
/**
* memory_region_allocate_system_memory - Allocate a board's main memory
* @mr: the #MemoryRegion to be initialized
diff --git a/hw/core/compat-props.c b/hw/core/compat-props.c
new file mode 100644
index 0000000000..1edeadb6a3
--- /dev/null
+++ b/hw/core/compat-props.c
@@ -0,0 +1,43 @@
+/*
+ * QEMU Machine compat properties
+ *
+ * Copyright (C) 2018 Red Hat Inc
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/boards.h"
+#include "qapi/error.h"
+
+typedef struct CompatProps CompatProps;
+
+typedef struct CompatPropsClass {
+ InterfaceClass parent_class;
+} CompatPropsClass;
+
+static void compat_props_post_init(Object *obj)
+{
+ if (current_machine) {
+ MachineClass *mc = MACHINE_GET_CLASS(current_machine);
+ AccelClass *ac = ACCEL_GET_CLASS(current_machine->accelerator);
+
+ object_apply_global_props(obj, mc->compat_props, &error_abort);
+ object_apply_global_props(obj, ac->compat_props, &error_abort);
+ }
+}
+
+static void compat_props_register_types(void)
+{
+ static const TypeInfo cp_interface_info = {
+ .name = TYPE_COMPAT_PROPS,
+ .parent = TYPE_INTERFACE,
+ .class_size = sizeof(CompatPropsClass),
+ .instance_post_init = compat_props_post_init,
+ };
+
+ type_register_static(&cp_interface_info);
+}
+
+type_init(compat_props_register_types)
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 30890f2c8d..b0ee05f837 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -972,14 +972,6 @@ static void device_initfn(Object *obj)
static void device_post_init(Object *obj)
{
- if (current_machine) {
- MachineClass *mc = MACHINE_GET_CLASS(current_machine);
- AccelClass *ac = ACCEL_GET_CLASS(current_machine->accelerator);
-
- object_apply_global_props(obj, mc->compat_props, &error_abort);
- object_apply_global_props(obj, ac->compat_props, &error_abort);
- }
-
qdev_prop_set_globals(DEVICE(obj));
}
@@ -1112,6 +1104,10 @@ static const TypeInfo device_type_info = {
.class_init = device_class_init,
.abstract = true,
.class_size = sizeof(DeviceClass),
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_COMPAT_PROPS },
+ { }
+ }
};
static void qdev_register_types(void)
diff --git a/MAINTAINERS b/MAINTAINERS
index 0499e11593..60af287386 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1024,6 +1024,7 @@ Machine core
M: Eduardo Habkost <address@hidden>
M: Marcel Apfelbaum <address@hidden>
S: Supported
+F: hw/core/compat-props.c
F: hw/core/machine.c
F: hw/core/null-machine.c
F: include/hw/boards.h
diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
index a799c83815..f15b3c970a 100644
--- a/hw/core/Makefile.objs
+++ b/hw/core/Makefile.objs
@@ -1,5 +1,6 @@
# core qdev-related obj files, also used by *-user:
common-obj-y += qdev.o qdev-properties.o
+common-obj-y += compat-props.o
common-obj-y += bus.o reset.o
common-obj-$(CONFIG_SOFTMMU) += qdev-fw.o
common-obj-$(CONFIG_SOFTMMU) += fw-path-provider.o
diff --git a/tests/Makefile.include b/tests/Makefile.include
index 074eece558..4bfde2e7b0 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -565,6 +565,7 @@ tests/test-qdev-global-props$(EXESUF):
tests/test-qdev-global-props.o \
hw/core/irq.o \
hw/core/fw-path-provider.o \
hw/core/reset.o \
+ hw/core/compat-props.o \
$(test-qapi-obj-y)
tests/test-vmstate$(EXESUF): tests/test-vmstate.o \
migration/vmstate.o migration/vmstate-types.o migration/qemu-file.o \
--
2.19.1.708.g4ede3d42df