From nobody Tue Nov 11 17:32:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=fail Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564412967275851.3358253863469; Mon, 29 Jul 2019 08:09:27 -0700 (PDT) Received: from localhost ([::1]:53144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hs7HA-0005B2-7C for importer@patchew.org; Mon, 29 Jul 2019 11:09:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37960) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hs77J-0004C2-VH for qemu-devel@nongnu.org; Mon, 29 Jul 2019 10:59:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hs77H-0004fM-Dl for qemu-devel@nongnu.org; Mon, 29 Jul 2019 10:59:13 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:48070) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hs777-0004TL-1w; Mon, 29 Jul 2019 10:59:01 -0400 Received: from kouign-amann.bar.greensocs.com (unknown [172.16.11.117]) by beetle.greensocs.com (Postfix) with ESMTPS id D39C596F5E; Mon, 29 Jul 2019 14:58:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1564412340; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NnkkIoHVwWj6c273Ch/WUhHvEUJl8xs34edh8vQqVyY=; b=CroHY+IlItvjMM4Iw8/7AYkxH5q8EiTBp1PKOIK+M0rdPIHctZYv9o1GokUeUF5uTySRNj fO8u47ZuIG+TSBno3xcVOgBS4os+0iLJ/5bfKNCLRprHTocNKBxKxID9LM2xqptAiIHor/ V3gQvO/Jxh+CZ27PTXuYGxw613ku4OU= From: Damien Hedde To: qemu-devel@nongnu.org Date: Mon, 29 Jul 2019 16:56:28 +0200 Message-Id: <20190729145654.14644-8-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729145654.14644-1-damien.hedde@greensocs.com> References: <20190729145654.14644-1-damien.hedde@greensocs.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1564412340; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NnkkIoHVwWj6c273Ch/WUhHvEUJl8xs34edh8vQqVyY=; b=NFJL4PD3UgBLR7FmwdToZdyfJh+nCcCVNXArVa4OtIbRuz0PoSUGZ+bl5HZSd1I7C5Stvy 351xcD331HNpGgIFDA/gRnLDcGopGY2Bc3QmEoacdjQpD5TpifOfi01xTDzTIaZI3mRWMg zE701oZWUEyMYk/qp/oqfdW8u+TgCI0= ARC-Seal: i=1; s=mail; d=greensocs.com; t=1564412340; a=rsa-sha256; cv=none; b=XwPuZipvWSknFivXe90DlrcOw0OtcyvyzoGCBs9TYAJuwybn3igXaReNWrg991UMTMRDs4 AiT3xcKfHAdH2kOJ8xNEQxxsXTQuxzX1h/t+ckopXNAAzKR0fkPOUfAk1iGO1/erfhMoJT 7b7TOiaXU/Z/cN7GGLWb61OvUTXGgQ4= ARC-Authentication-Results: i=1; beetle.greensocs.com; none X-Spam: Yes Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 5.135.226.135 Subject: [Qemu-devel] [PATCH v3 07/33] automatically add vmstate for reset support in devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, peter.maydell@linaro.org, walling@linux.ibm.com, dmitry.fleytman@gmail.com, mst@redhat.com, mark.cave-ayland@ilande.co.uk, kraxel@redhat.com, edgar.iglesias@xilinx.com, hare@suse.com, qemu-block@nongnu.org, david@redhat.com, pasic@linux.ibm.com, borntraeger@de.ibm.com, marcandre.lureau@redhat.com, rth@twiddle.net, thuth@redhat.com, ehabkost@redhat.com, alistair@alistair23.me, qemu-s390x@nongnu.org, qemu-arm@nongnu.org, clg@kaod.org, jsnow@redhat.com, david@gibson.dropbear.id.au, Damien Hedde , berrange@redhat.com, cohuck@redhat.com, mark.burton@greensocs.com, qemu-ppc@nongnu.org, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This add the reset related sections for every QOM device. Signed-off-by: Damien Hedde --- hw/core/qdev-vmstate.c | 41 +++++++++++++++++++++++++++++++++++++++++ hw/core/qdev.c | 12 +++++++++++- include/hw/qdev-core.h | 3 +++ stubs/Makefile.objs | 1 + stubs/device.c | 7 +++++++ 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 stubs/device.c diff --git a/hw/core/qdev-vmstate.c b/hw/core/qdev-vmstate.c index 07b010811f..24f8465c61 100644 --- a/hw/core/qdev-vmstate.c +++ b/hw/core/qdev-vmstate.c @@ -43,3 +43,44 @@ const struct VMStateDescription device_vmstate_reset =3D= { VMSTATE_END_OF_LIST() }, }; + +static VMStateDescription *vmsd_duplicate_and_append( + const VMStateDescription *old_vmsd, + const VMStateDescription *new_subsection) +{ + VMStateDescription *vmsd; + int n =3D 0; + + assert(old_vmsd && new_subsection); + + vmsd =3D (VMStateDescription *) g_memdup(old_vmsd, sizeof(*vmsd)); + + if (old_vmsd->subsections) { + while (old_vmsd->subsections[n]) { + n +=3D 1; + } + } + vmsd->subsections =3D g_new(const VMStateDescription *, n + 2); + + if (old_vmsd->subsections) { + memcpy(vmsd->subsections, old_vmsd->subsections, + sizeof(VMStateDescription *) * n); + } + vmsd->subsections[n] =3D new_subsection; + vmsd->subsections[n + 1] =3D NULL; + + return vmsd; +} + +void device_class_build_extended_vmsd(DeviceClass *dc) +{ + assert(dc->vmsd); + assert(!dc->vmsd_ext); + + /* forge a subsection with proper name */ + VMStateDescription *reset; + reset =3D g_memdup(&device_vmstate_reset, sizeof(*reset)); + reset->name =3D g_strdup_printf("%s/device_reset", dc->vmsd->name); + + dc->vmsd_ext =3D vmsd_duplicate_and_append(dc->vmsd, reset); +} diff --git a/hw/core/qdev.c b/hw/core/qdev.c index e9e5f2d5f9..88387d3743 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -45,7 +45,17 @@ bool qdev_hot_removed =3D false; const VMStateDescription *qdev_get_vmsd(DeviceState *dev) { DeviceClass *dc =3D DEVICE_GET_CLASS(dev); - return dc->vmsd; + + if (!dc->vmsd) { + return NULL; + } + + if (!dc->vmsd_ext) { + /* build it first time we need it */ + device_class_build_extended_vmsd(dc); + } + + return dc->vmsd_ext; } =20 static void bus_remove_child(BusState *bus, DeviceState *child) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 1670ae41bb..926d4bbcb1 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -120,6 +120,7 @@ typedef struct DeviceClass { =20 /* device state */ const struct VMStateDescription *vmsd; + const struct VMStateDescription *vmsd_ext; =20 /* Private to qdev / bus. */ const char *bus_type; @@ -520,6 +521,8 @@ void device_class_set_parent_unrealize(DeviceClass *dc, =20 const struct VMStateDescription *qdev_get_vmsd(DeviceState *dev); =20 +void device_class_build_extended_vmsd(DeviceClass *dc); + const char *qdev_fw_name(DeviceState *dev); =20 Object *qdev_get_machine(void); diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 9c7393b08c..432b56f290 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -40,4 +40,5 @@ stub-obj-y +=3D pci-host-piix.o stub-obj-y +=3D ram-block.o stub-obj-y +=3D ramfb.o stub-obj-y +=3D fw_cfg.o +stub-obj-y +=3D device.o stub-obj-$(CONFIG_SOFTMMU) +=3D semihost.o diff --git a/stubs/device.c b/stubs/device.c new file mode 100644 index 0000000000..e9b4f57e5f --- /dev/null +++ b/stubs/device.c @@ -0,0 +1,7 @@ +#include "qemu/osdep.h" +#include "hw/qdev-core.h" + +void device_class_build_extended_vmsd(DeviceClass *dc) +{ + return; +} --=20 2.22.0