From patchwork Mon Jul 29 14:56:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Hedde X-Patchwork-Id: 1138453 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=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=greensocs.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=greensocs.com header.i=@greensocs.com header.b="CroHY+Il"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45y33Z4th8z9s3l for ; Tue, 30 Jul 2019 01:08:26 +1000 (AEST) Received: from localhost ([::1]:53118 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hs7GC-0003Fh-OA for incoming@patchwork.ozlabs.org; Mon, 29 Jul 2019 11:08: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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 = { VMSTATE_END_OF_LIST() }, }; + +static VMStateDescription *vmsd_duplicate_and_append( + const VMStateDescription *old_vmsd, + const VMStateDescription *new_subsection) +{ + VMStateDescription *vmsd; + int n = 0; + + assert(old_vmsd && new_subsection); + + vmsd = (VMStateDescription *) g_memdup(old_vmsd, sizeof(*vmsd)); + + if (old_vmsd->subsections) { + while (old_vmsd->subsections[n]) { + n += 1; + } + } + vmsd->subsections = g_new(const VMStateDescription *, n + 2); + + if (old_vmsd->subsections) { + memcpy(vmsd->subsections, old_vmsd->subsections, + sizeof(VMStateDescription *) * n); + } + vmsd->subsections[n] = new_subsection; + vmsd->subsections[n + 1] = 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 = g_memdup(&device_vmstate_reset, sizeof(*reset)); + reset->name = g_strdup_printf("%s/device_reset", dc->vmsd->name); + + dc->vmsd_ext = 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 = false; const VMStateDescription *qdev_get_vmsd(DeviceState *dev) { DeviceClass *dc = 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; } 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 { /* device state */ const struct VMStateDescription *vmsd; + const struct VMStateDescription *vmsd_ext; /* Private to qdev / bus. */ const char *bus_type; @@ -520,6 +521,8 @@ void device_class_set_parent_unrealize(DeviceClass *dc, const struct VMStateDescription *qdev_get_vmsd(DeviceState *dev); +void device_class_build_extended_vmsd(DeviceClass *dc); + const char *qdev_fw_name(DeviceState *dev); 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 += pci-host-piix.o stub-obj-y += ram-block.o stub-obj-y += ramfb.o stub-obj-y += fw_cfg.o +stub-obj-y += device.o stub-obj-$(CONFIG_SOFTMMU) += 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; +}