From patchwork Wed Nov 7 12:36:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 994238 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qmXs3gW7z9sBZ for ; Wed, 7 Nov 2018 23:52:45 +1100 (AEDT) Received: from localhost ([::1]:47716 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNK7-0005X0-6c for incoming@patchwork.ozlabs.org; Wed, 07 Nov 2018 07:52:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37968) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKN7S-0008N7-Nj for qemu-devel@nongnu.org; Wed, 07 Nov 2018 07:39:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKN7F-0007WV-0C for qemu-devel@nongnu.org; Wed, 07 Nov 2018 07:39:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43254) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gKN70-00075y-6j; Wed, 07 Nov 2018 07:39:10 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9182D30084CB; Wed, 7 Nov 2018 12:38:51 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 375C060F89; Wed, 7 Nov 2018 12:38:43 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Wed, 7 Nov 2018 16:36:50 +0400 Message-Id: <20181107123652.23417-13-marcandre.lureau@redhat.com> In-Reply-To: <20181107123652.23417-1-marcandre.lureau@redhat.com> References: <20181107123652.23417-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 07 Nov 2018 12:38:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-3.2 v3 12/14] machine: add compat-props interface X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stefano Stabellini , xen-devel@lists.xenproject.org, Corey Minyard , Amit Shah , =?utf-8?q?Herv=C3=A9_Poussineau?= , "Michael S. Tsirkin" , Mark Cave-Ayland , dgilbert@redhat.com, Eduardo Habkost , =?utf-8?q?Marc-Andr=C3=A9_Lure?= =?utf-8?q?au?= , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Igor Mammedov , Anthony Perard , Paolo Bonzini , Stefan Berger , =?utf-8?q?Andreas_F=C3=A4rber?= , Artyom Tarasenko , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 M: Marcel Apfelbaum 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 \