From nobody Mon Apr 29 09:11:19 2024 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 1566406186874443.6167875077075; Wed, 21 Aug 2019 09:49:46 -0700 (PDT) Received: from localhost ([::1]:50534 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0Tnq-0004tO-Bt for importer@patchew.org; Wed, 21 Aug 2019 12:49:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59593) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0TZx-0007Z4-3f for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0TZv-00062I-8P for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:21 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:36338) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i0TZS-0005Rt-TT; Wed, 21 Aug 2019 12:34:51 -0400 Received: from kouign-amann.bar.greensocs.com (unknown [172.16.11.117]) by beetle.greensocs.com (Postfix) with ESMTPS id 151EC96F51; Wed, 21 Aug 2019 16:34:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1566405289; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P6SapPxRej/FiM0qOsHgMc57cnM2e6ZeN4HLykX3sVw=; b=3GvDSfLC1YLBBbQNnwPEUmKTQv4vYxTZMhqnLq8bvey06rH0PfhS+Z1WVi7P/RHVqVXsJ/ EJHc+GQk5rPkA3FSrAHJwaOOHUbiYnRGQc+cZVNlExt9ex5YQt9IL3VaHkggHm5Lieu8xU MZHcUAR4NjPEytEjdSCMEGGUJ6Lb+RU= From: Damien Hedde To: qemu-devel@nongnu.org Date: Wed, 21 Aug 2019 18:33:32 +0200 Message-Id: <20190821163341.16309-2-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190821163341.16309-1-damien.hedde@greensocs.com> References: <20190821163341.16309-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=1566405290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P6SapPxRej/FiM0qOsHgMc57cnM2e6ZeN4HLykX3sVw=; b=IKLG2Qo8sANJdbwrZF8lxq9eD5gCvoaIblyl5mp1uSMx/SrD0JBerQOSfjUPDyrAFAEuEw 8iHF9rqvrJssFuwq6246mxWTvaNogKeYRZ98P68a2VrWTqjkjdm4k6uCokC4t1HwrPTCwl 3ih87QvUL5wnvor67uEMM7dvHewq15w= ARC-Seal: i=1; s=mail; d=greensocs.com; t=1566405290; a=rsa-sha256; cv=none; b=LEELEocpSDKmNkGPmpN2oIksSSExTMkAoQb3Qm2gaGWarJq9nRMRpOVZOv1I7v0js2PaLA iHmTiOvU2ZMuzB/eltqGpceB+6oLubs/KLz4CD8jV1Clw9QTnk8dbSYZNswlvy8aRhfjDr dmLIr4vPQE6apbSXahtWsL5vYk4x8mg= ARC-Authentication-Results: i=1; beetle.greensocs.com; none 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 v4 01/10] add device_legacy_reset function to prepare for reset api change 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 Zheng , peter.maydell@linaro.org, Collin Walling , Dmitry Fleytman , "Michael S. Tsirkin" , Gerd Hoffmann , edgar.iglesias@xilinx.com, qemu-block@nongnu.org, David Hildenbrand , Halil Pasic , Christian Borntraeger , david@gibson.dropbear.id.au, philmd@redhat.com, ehabkost@redhat.com, qemu-s390x@nongnu.org, qemu-arm@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , John Snow , Richard Henderson , Damien Hedde , berrange@redhat.com, Cornelia Huck , 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 (identity @greensocs.com: invalid key for signature: Missing mandatory tag: p) Content-Type: text/plain; charset="utf-8" Provide a temporary device_legacy_reset function doing what device_reset does to prepare for the transition with Resettable API. All occurrence of device_reset in the code tree are also replaced by device_legacy_reset. The new resettable API has different prototype and semantics (resetting child buses as well as the specified device). Subsequent commits will make the changeover for each call site individually; once that is complete device_legacy_reset() will be removed. Signed-off-by: Damien Hedde Reviewed-by: Peter Maydell Acked-by: David Gibson --- Cc: Gerd Hoffmann Cc: Paolo Bonzini Cc: "Daniel P. Berrang=C3=A9" Cc: Eduardo Habkost Cc: Richard Henderson Cc: "Michael S. Tsirkin" Cc: Marcel Apfelbaum Cc: John Snow Cc: "C=C3=A9dric Le Goater" Cc: Collin Walling Cc: Cornelia Huck Cc: David Hildenbrand Cc: Halil Pasic Cc: Christian Borntraeger Cc: Dmitry Fleytman Cc: Fam Zheng Cc: qemu-block@nongnu.org Cc: qemu-ppc@nongnu.org Cc: qemu-s390x@nongnu.org Cc: qemu-arm@nongnu.org --- hw/audio/intel-hda.c | 2 +- hw/core/qdev.c | 6 +++--- hw/hyperv/hyperv.c | 2 +- hw/i386/pc.c | 2 +- hw/ide/microdrive.c | 8 ++++---- hw/intc/spapr_xive.c | 2 +- hw/ppc/pnv_psi.c | 2 +- hw/ppc/spapr_pci.c | 2 +- hw/ppc/spapr_vio.c | 2 +- hw/s390x/s390-pci-inst.c | 2 +- hw/scsi/vmw_pvscsi.c | 2 +- hw/sd/omap_mmc.c | 2 +- hw/sd/pl181.c | 2 +- include/hw/qdev-core.h | 4 ++-- 14 files changed, 20 insertions(+), 20 deletions(-) diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c index 6ecd383540..27b71c57cf 100644 --- a/hw/audio/intel-hda.c +++ b/hw/audio/intel-hda.c @@ -1087,7 +1087,7 @@ static void intel_hda_reset(DeviceState *dev) QTAILQ_FOREACH(kid, &d->codecs.qbus.children, sibling) { DeviceState *qdev =3D kid->child; cdev =3D HDA_CODEC_DEVICE(qdev); - device_reset(DEVICE(cdev)); + device_legacy_reset(DEVICE(cdev)); d->state_sts |=3D (1 << cdev->cad); } intel_hda_update_irq(d); diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 60d66c2f39..a95d4fa87d 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -257,7 +257,7 @@ HotplugHandler *qdev_get_hotplug_handler(DeviceState *d= ev) =20 static int qdev_reset_one(DeviceState *dev, void *opaque) { - device_reset(dev); + device_legacy_reset(dev); =20 return 0; } @@ -865,7 +865,7 @@ static void device_set_realized(Object *obj, bool value= , Error **errp) } } if (dev->hotplugged) { - device_reset(dev); + device_legacy_reset(dev); } dev->pending_deleted_event =3D false; =20 @@ -1087,7 +1087,7 @@ void device_class_set_parent_unrealize(DeviceClass *d= c, dc->unrealize =3D dev_unrealize; } =20 -void device_reset(DeviceState *dev) +void device_legacy_reset(DeviceState *dev) { DeviceClass *klass =3D DEVICE_GET_CLASS(dev); =20 diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c index 6ebf31c310..cd9db3cb5c 100644 --- a/hw/hyperv/hyperv.c +++ b/hw/hyperv/hyperv.c @@ -140,7 +140,7 @@ void hyperv_synic_reset(CPUState *cs) SynICState *synic =3D get_synic(cs); =20 if (synic) { - device_reset(DEVICE(synic)); + device_legacy_reset(DEVICE(synic)); } } =20 diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 3ab4bcb3ca..f33a8de42f 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -2826,7 +2826,7 @@ static void pc_machine_reset(MachineState *machine) cpu =3D X86_CPU(cs); =20 if (cpu->apic_state) { - device_reset(cpu->apic_state); + device_legacy_reset(cpu->apic_state); } } } diff --git a/hw/ide/microdrive.c b/hw/ide/microdrive.c index b0272ea14b..6b30e36ed8 100644 --- a/hw/ide/microdrive.c +++ b/hw/ide/microdrive.c @@ -173,7 +173,7 @@ static void md_attr_write(PCMCIACardState *card, uint32= _t at, uint8_t value) case 0x00: /* Configuration Option Register */ s->opt =3D value & 0xcf; if (value & OPT_SRESET) { - device_reset(DEVICE(s)); + device_legacy_reset(DEVICE(s)); } md_interrupt_update(s); break; @@ -316,7 +316,7 @@ static void md_common_write(PCMCIACardState *card, uint= 32_t at, uint16_t value) case 0xe: /* Device Control */ s->ctrl =3D value; if (value & CTRL_SRST) { - device_reset(DEVICE(s)); + device_legacy_reset(DEVICE(s)); } md_interrupt_update(s); break; @@ -541,7 +541,7 @@ static int dscm1xxxx_attach(PCMCIACardState *card) md->attr_base =3D pcc->cis[0x74] | (pcc->cis[0x76] << 8); md->io_base =3D 0x0; =20 - device_reset(DEVICE(md)); + device_legacy_reset(DEVICE(md)); md_interrupt_update(md); =20 return 0; @@ -551,7 +551,7 @@ static int dscm1xxxx_detach(PCMCIACardState *card) { MicroDriveState *md =3D MICRODRIVE(card); =20 - device_reset(DEVICE(md)); + device_legacy_reset(DEVICE(md)); return 0; } =20 diff --git a/hw/intc/spapr_xive.c b/hw/intc/spapr_xive.c index aad981cb78..a0f1787ee0 100644 --- a/hw/intc/spapr_xive.c +++ b/hw/intc/spapr_xive.c @@ -1514,7 +1514,7 @@ static target_ulong h_int_reset(PowerPCCPU *cpu, return H_PARAMETER; } =20 - device_reset(DEVICE(xive)); + device_legacy_reset(DEVICE(xive)); =20 if (kvm_irqchip_in_kernel()) { Error *local_err =3D NULL; diff --git a/hw/ppc/pnv_psi.c b/hw/ppc/pnv_psi.c index 88ba8e7b9b..bfdc30d4e1 100644 --- a/hw/ppc/pnv_psi.c +++ b/hw/ppc/pnv_psi.c @@ -705,7 +705,7 @@ static void pnv_psi_p9_mmio_write(void *opaque, hwaddr = addr, break; case PSIHB9_INTERRUPT_CONTROL: if (val & PSIHB9_IRQ_RESET) { - device_reset(DEVICE(&psi9->source)); + device_legacy_reset(DEVICE(&psi9->source)); } psi->regs[reg] =3D val; break; diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index bf31fd854c..f4c918be8b 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -2031,7 +2031,7 @@ static int spapr_phb_children_reset(Object *child, vo= id *opaque) DeviceState *dev =3D (DeviceState *) object_dynamic_cast(child, TYPE_D= EVICE); =20 if (dev) { - device_reset(dev); + device_legacy_reset(dev); } =20 return 0; diff --git a/hw/ppc/spapr_vio.c b/hw/ppc/spapr_vio.c index 0803649658..ff7ee4d822 100644 --- a/hw/ppc/spapr_vio.c +++ b/hw/ppc/spapr_vio.c @@ -305,7 +305,7 @@ int spapr_vio_send_crq(SpaprVioDevice *dev, uint8_t *cr= q) static void spapr_vio_quiesce_one(SpaprVioDevice *dev) { if (dev->tcet) { - device_reset(DEVICE(dev->tcet)); + device_legacy_reset(DEVICE(dev->tcet)); } free_crq(dev); } diff --git a/hw/s390x/s390-pci-inst.c b/hw/s390x/s390-pci-inst.c index 00235148be..93cda37c27 100644 --- a/hw/s390x/s390-pci-inst.c +++ b/hw/s390x/s390-pci-inst.c @@ -242,7 +242,7 @@ int clp_service_call(S390CPU *cpu, uint8_t r2, uintptr_= t ra) stw_p(&ressetpci->hdr.rsp, CLP_RC_SETPCIFN_FHOP); goto out; } - device_reset(DEVICE(pbdev)); + device_legacy_reset(DEVICE(pbdev)); pbdev->fh &=3D ~FH_MASK_ENABLE; pbdev->state =3D ZPCI_FS_DISABLED; stl_p(&ressetpci->fh, pbdev->fh); diff --git a/hw/scsi/vmw_pvscsi.c b/hw/scsi/vmw_pvscsi.c index 452a3b63b2..7baab1532f 100644 --- a/hw/scsi/vmw_pvscsi.c +++ b/hw/scsi/vmw_pvscsi.c @@ -838,7 +838,7 @@ pvscsi_on_cmd_reset_device(PVSCSIState *s) =20 if (sdev !=3D NULL) { s->resetting++; - device_reset(&sdev->qdev); + device_legacy_reset(&sdev->qdev); s->resetting--; return PVSCSI_COMMAND_PROCESSING_SUCCEEDED; } diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c index c6e516b611..4088a8a80b 100644 --- a/hw/sd/omap_mmc.c +++ b/hw/sd/omap_mmc.c @@ -318,7 +318,7 @@ void omap_mmc_reset(struct omap_mmc_s *host) * into any bus, and we must reset it manually. When omap_mmc is * QOMified this must move into the QOM reset function. */ - device_reset(DEVICE(host->card)); + device_legacy_reset(DEVICE(host->card)); } =20 static uint64_t omap_mmc_read(void *opaque, hwaddr offset, diff --git a/hw/sd/pl181.c b/hw/sd/pl181.c index 8033fe455d..2b3776a6a0 100644 --- a/hw/sd/pl181.c +++ b/hw/sd/pl181.c @@ -482,7 +482,7 @@ static void pl181_reset(DeviceState *d) /* Since we're still using the legacy SD API the card is not plugged * into any bus, and we must reset it manually. */ - device_reset(DEVICE(s->card)); + device_legacy_reset(DEVICE(s->card)); } =20 static void pl181_init(Object *obj) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index de70b7a19a..09e6dfd664 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -406,11 +406,11 @@ char *qdev_get_own_fw_dev_path_from_handler(BusState = *bus, DeviceState *dev); void qdev_machine_init(void); =20 /** - * @device_reset + * device_legacy_reset: * * Reset a single device (by calling the reset method). */ -void device_reset(DeviceState *dev); +void device_legacy_reset(DeviceState *dev); =20 void device_class_set_parent_reset(DeviceClass *dc, DeviceReset dev_reset, --=20 2.22.0 From nobody Mon Apr 29 09:11:19 2024 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 1566405553589986.8472428000318; Wed, 21 Aug 2019 09:39:13 -0700 (PDT) Received: from localhost ([::1]:50438 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0Tdg-0004BI-Aq for importer@patchew.org; Wed, 21 Aug 2019 12:39:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59232) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0TZb-0006pH-H9 for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0TZY-0005a0-KO for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:34:59 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:36358) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i0TZY-0005Xo-BM for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:34:56 -0400 Received: from kouign-amann.bar.greensocs.com (unknown [172.16.11.117]) by beetle.greensocs.com (Postfix) with ESMTPS id 0950C96F50; Wed, 21 Aug 2019 16:34:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1566405295; 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=zzGv99HuMKd0JutBn8eGlSOlX0+Kjm8cGkvMfkb8hpo=; b=LSpB6TLUyAKTyj3HdSdQVllFr4CGpuFLWVXmmPeCDsQ26NK4GKEIH4zJ6EWQ+1Ysb9PORy VUCBszJi7EcdKDAbSk9Jkb/eTMlU3ti2MhCM1Ju3TtIeeAeEMf2oXz077ABdfsptk+5+v4 XgEcaJi19CUgJoiGrncNPMqPE/6kQc4= From: Damien Hedde To: qemu-devel@nongnu.org Date: Wed, 21 Aug 2019 18:33:33 +0200 Message-Id: <20190821163341.16309-3-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190821163341.16309-1-damien.hedde@greensocs.com> References: <20190821163341.16309-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=1566405295; 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=zzGv99HuMKd0JutBn8eGlSOlX0+Kjm8cGkvMfkb8hpo=; b=eOC2wF9EHLh1FD9piBzHj2rkyyJPsHy5h2Nq6XtHuHmKOJ+LWqPaI//u5jVweqpeilxc83 ekOeaHj3mS6sB181wKRZ0t9dbfVa2qqab2P+LdLkKMD8Q7cK/j5x3m3gyKiRvE2DdQV4mw efvah1BzMFKNgyVyjBobxzdOXxKZNtU= ARC-Seal: i=1; s=mail; d=greensocs.com; t=1566405295; a=rsa-sha256; cv=none; b=D7DDt+vB3ymPrDR9O81jnUzSpf7V4TEF2WFdKKulF6nj3c5+0yDrO3XDZZYGx+e8dqxbyL i7MFQjNmK6idLCqTEYQaS2KWJYXauPT2ndUFHrepxFRDbJVwYOdGisEie18ErFfGBNNx7W hD/174dqMoPjoksSkH0A7YUhFw+gz58= ARC-Authentication-Results: i=1; beetle.greensocs.com; none 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 v4 02/10] hw/core: create Resettable QOM interface 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: Damien Hedde , peter.maydell@linaro.org, edgar.iglesias@xilinx.com, berrange@redhat.com, ehabkost@redhat.com, mark.burton@greensocs.com, pbonzini@redhat.com, philmd@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (identity @greensocs.com: invalid key for signature: Missing mandatory tag: p) Content-Type: text/plain; charset="utf-8" This commit defines an interface allowing multi-phase reset. This aims to solve a problem of the actual single-phase reset (built in DeviceClass and BusClass): reset behavior is dependent on the order in which reset handlers are called. In particular doing external side-effect (like setting an qemu_irq) is problematic because receiving object may not be reset yet. The Resettable interface divides the reset in 3 well defined phases. To reset an object tree, all 1st phases are executed then all 2nd then all 3rd. See the comments in include/hw/resettable.h for a more complete description. There is 3 phases to allow a device to be held in reset state; the ability to control this state will be added in a following commits. The qdev/qbus reset in DeviceClass and BusClass will be modified in following commits to use this interface. No change of behavior is expected because the init phase execution order follows the children-then-parent order inside a tree. Since this is the actual order of qdev/qbus reset, we will be able to map current reset handlers on init phase for example. In this patch only cold reset is introduced, which is pretty much the actual semantics of the current reset handlers. The interface can be extended to support more reset types. Documentation will be added in a following commit. Signed-off-by: Damien Hedde --- I kept the non-recursive count approach (a given object counts reset initiated on it as well as reset initiated on its parents in reset hierarchy). I implemented the other approach, it is possible but is more complex (an object has to know its direct parent(s) and we need to scan the reset hierarchy to know if we are in reset) so I prefer not to introduce it here. Moreover I think it has drawbacks if we want to handle complex reset use cases with more reset type. Anyway, as long as we don't migrate the reset-related state, there is no problem to switch between approaches. --- Makefile.objs | 1 + hw/core/Makefile.objs | 1 + hw/core/resettable.c | 186 ++++++++++++++++++++++++++++++++++++++++ hw/core/trace-events | 36 ++++++++ include/hw/resettable.h | 159 ++++++++++++++++++++++++++++++++++ 5 files changed, 383 insertions(+) create mode 100644 hw/core/resettable.c create mode 100644 hw/core/trace-events create mode 100644 include/hw/resettable.h diff --git a/Makefile.objs b/Makefile.objs index 6a143dcd57..a723a47e14 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -191,6 +191,7 @@ trace-events-subdirs +=3D migration trace-events-subdirs +=3D net trace-events-subdirs +=3D ui endif +trace-events-subdirs +=3D hw/core trace-events-subdirs +=3D hw/display trace-events-subdirs +=3D qapi trace-events-subdirs +=3D qom diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs index b49f880a0c..69b408ad1c 100644 --- a/hw/core/Makefile.objs +++ b/hw/core/Makefile.objs @@ -1,6 +1,7 @@ # core qdev-related obj files, also used by *-user: common-obj-y +=3D qdev.o qdev-properties.o common-obj-y +=3D bus.o reset.o +common-obj-y +=3D resettable.o common-obj-$(CONFIG_SOFTMMU) +=3D qdev-fw.o common-obj-$(CONFIG_SOFTMMU) +=3D fw-path-provider.o # irq.o needed for qdev GPIO handling: diff --git a/hw/core/resettable.c b/hw/core/resettable.c new file mode 100644 index 0000000000..b534c2c7a4 --- /dev/null +++ b/hw/core/resettable.c @@ -0,0 +1,186 @@ +/* + * Resettable interface. + * + * Copyright (c) 2019 GreenSocs SAS + * + * Authors: + * Damien Hedde + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/module.h" +#include "hw/resettable.h" +#include "trace.h" + +#define RESETTABLE_GET_CLASS(obj) \ + OBJECT_GET_CLASS(ResettableClass, (obj), TYPE_RESETTABLE_INTERFACE) + +static void resettable_foreach_child(ResettableClass *rc, + Object *obj, + void (*func)(Object *, ResetType type= ), + ResetType type) +{ + if (rc->foreach_child) { + rc->foreach_child(obj, func, type); + } +} + +static void resettable_init_reset(Object *obj, ResetType type) +{ + ResettableClass *rc =3D RESETTABLE_GET_CLASS(obj); + ResetState *s =3D rc->get_state(obj); + bool action_needed =3D false; + + /* Only take action if we really enter reset for the 1st time. */ + /* + * TODO: if adding more ResetType support, some additional checks + * are probably needed here. + */ + if (s->count =3D=3D 0) { + action_needed =3D true; + } + s->count +=3D 1; + /* + * We limit the count to an arbitrary "big" value. The value is big + * enough not to be triggered nominally. + * The assert will stop an infinite loop if there is a cycle in the + * reset tree. The loop goes through resettable_foreach_child below + * which at some point will call us again. + */ + assert(s->count <=3D 50); + trace_resettable_phase_init(obj, object_get_typename(obj), type, + s->count, action_needed); + + /* + * handle the children even if action_needed is at false so that + * children counts are incremented too + */ + resettable_foreach_child(rc, obj, resettable_init_reset, type); + + /* exec init phase */ + if (action_needed) { + s->hold_phase_needed =3D true; + if (rc->phases.init) { + rc->phases.init(obj, type); + } + } + trace_resettable_phase_init_end(obj); +} + +static void resettable_hold_reset_child(Object *obj, ResetType type) +{ + ResettableClass *rc =3D RESETTABLE_GET_CLASS(obj); + ResetState *s =3D rc->get_state(obj); + + trace_resettable_phase_hold(obj, object_get_typename(obj)); + + /* handle children first */ + resettable_foreach_child(rc, obj, resettable_hold_reset_child, 0); + + /* exec hold phase */ + if (s->hold_phase_needed) { + s->hold_phase_needed =3D false; + if (rc->phases.hold) { + rc->phases.hold(obj); + } + } + trace_resettable_phase_hold_end(obj, s->hold_phase_needed); +} + +static void resettable_hold_reset(Object *obj) +{ + /* we don't care of 2nd argument here */ + resettable_hold_reset_child(obj, 0); +} + +static void resettable_exit_reset_child(Object *obj, ResetType type) +{ + ResettableClass *rc =3D RESETTABLE_GET_CLASS(obj); + ResetState *s =3D rc->get_state(obj); + + trace_resettable_phase_exit(obj, object_get_typename(obj)); + + resettable_foreach_child(rc, obj, resettable_exit_reset_child, 0); + + /* + * we could assert that count > 0 but there are some corner cases + * where we prefer to let it go as it is probably harmless. + * For example: if there is reset support addition between + * hosts when doing a migration. We may do such things as + * deassert a non-existing reset. + */ + if (s->count > 0) { + s->count -=3D 1; + } else { + trace_resettable_count_underflow(obj); + } + if (s->count =3D=3D 0) { + if (rc->phases.exit) { + rc->phases.exit(obj); + } + } + trace_resettable_phase_exit_end(obj, s->count); +} + +static void resettable_exit_reset(Object *obj) +{ + /* we don't care of 2nd argument here */ + resettable_exit_reset_child(obj, 0); +} + +void resettable_reset(Object *obj, ResetType type) +{ + /* TODO: change that when adding support for other reset types */ + assert(type =3D=3D RESET_TYPE_COLD); + trace_resettable_reset(obj, type); + resettable_init_reset(obj, type); + resettable_hold_reset(obj); + resettable_exit_reset(obj); +} + +void resettable_cold_reset_fn(void *opaque) +{ + resettable_reset((Object *) opaque, RESET_TYPE_COLD); +} + +bool resettable_is_resetting(Object *obj) +{ + ResettableClass *rc =3D RESETTABLE_GET_CLASS(obj); + ResetState *s =3D rc->get_state(obj); + + return (s->count > 0); +} + +void resettable_class_set_parent_phases(ResettableClass *rc, + ResettableInitPhase init, + ResettableHoldPhase hold, + ResettableExitPhase exit, + ResettablePhases *parent_phases) +{ + *parent_phases =3D rc->phases; + if (init) { + rc->phases.init =3D init; + } + if (hold) { + rc->phases.hold =3D hold; + } + if (exit) { + rc->phases.exit =3D exit; + } +} + +static const TypeInfo resettable_interface_info =3D { + .name =3D TYPE_RESETTABLE_INTERFACE, + .parent =3D TYPE_INTERFACE, + .class_size =3D sizeof(ResettableClass), +}; + +static void reset_register_types(void) +{ + type_register_static(&resettable_interface_info); +} + +type_init(reset_register_types) diff --git a/hw/core/trace-events b/hw/core/trace-events new file mode 100644 index 0000000000..ecf966c314 --- /dev/null +++ b/hw/core/trace-events @@ -0,0 +1,36 @@ +# See docs/devel/tracing.txt for syntax documentation. +# +# This file is processed by the tracetool script during the build. +# +# To add a new trace event: +# +# 1. Choose a name for the trace event. Declare its arguments and format +# string. +# +# 2. Call the trace event from code using trace_##name, e.g. multiwrite_cb= () -> +# trace_multiwrite_cb(). The source file must #include "trace.h". +# +# Format of a trace event: +# +# [disable] ( [, ] ...) "" +# +# Example: g_malloc(size_t size) "size %zu" +# +# The "disable" keyword will build without the trace event. +# +# The must be a valid as a C function name. +# +# Types should be standard C types. Use void * for pointers because the t= race +# system may not have the necessary headers included. +# +# The should be a sprintf()-compatible format string. + +# resettable.c +resettable_reset(void *obj, int cold) "obj=3D%p cold=3D%d" +resettable_phase_init(void *obj, const char *type, int cold, uint32_t coun= t, int needed) "obj=3D%p(%s) cold=3D%d count=3D%" PRIu32 " needed=3D%d" +resettable_phase_init_end(void *obj) "obj=3D%p" +resettable_phase_hold(void *obj, const char *type) "obj=3D%p(%s)" +resettable_phase_hold_end(void *obj, int needed) "obj=3D%p needed=3D%d" +resettable_phase_exit(void *obj, const char *type) "obj=3D%p(%s)" +resettable_phase_exit_end(void *obj, uint32_t count) "obj=3D%p count=3D%" = PRIu32 +resettable_count_underflow(void *obj) "obj=3D%p" diff --git a/include/hw/resettable.h b/include/hw/resettable.h new file mode 100644 index 0000000000..5808c3c187 --- /dev/null +++ b/include/hw/resettable.h @@ -0,0 +1,159 @@ +#ifndef HW_RESETTABLE_H +#define HW_RESETTABLE_H + +#include "qom/object.h" + +#define TYPE_RESETTABLE_INTERFACE "resettable" + +#define RESETTABLE_CLASS(class) \ + OBJECT_CLASS_CHECK(ResettableClass, (class), TYPE_RESETTABLE_INTERFACE) + +typedef struct ResetState ResetState; + +/** + * ResetType: + * Types of reset. + * + * + Cold: reset resulting from a power cycle of the object. + * + * TODO: Support has to be added to handle more types. In particular, + * ResetState structure needs to be expanded. + */ +typedef enum ResetType { + RESET_TYPE_COLD, +} ResetType; + +/* + * ResettableClass: + * Interface for resettable objects. + * + * See docs/devel/reset.rst for more detailed information about + * how QEMU models reset. + * + * All objects which can be reset must implement this interface; + * it is usually provided by a base class such as DeviceClass or BusClass. + * Every Resettable object must maintain some state tracking the + * progress of a reset operation by providing a ResetState structure. + * The functions defined in this module take care of updating the + * state of the reset. + * The base class implementation of the interface provides this + * state and implements the associated method: get_state. + * + * Concrete object implementations (typically specific devices + * such as a UART model) should provide the functions + * for the phases.init, phases.hold and phases.exit methods, which + * they can set in their class init function, either directly or + * by calling resettable_class_set_parent_phases(). + * The phase methods are guaranteed to only only ever be called once + * for any reset event, in the order 'init', 'hold', 'exit'. + * An object will always move quickly from 'init' to 'hold' + * but might remain in 'hold' for an arbitrary period of time + * before eventually reset is deasserted and the 'exit' phase is called. + * Object implementations should be prepared for functions handling + * inbound connections from other devices (such as qemu_irq handler + * functions) to be called at any point during reset after their + * 'init' method has been called. + * + * Users of a resettable object should not call these methods + * directly, but instead use the function resettable_reset(). + * + * @phases.init: This phase is called when the object enters reset. It + * should reset local state of the object, but it must not do anything that + * has a side-effect on other objects, such as raising or lowering a qemu_= irq + * line or reading or writing guest memory. It takes the reset's type as + * argument. + * + * @phases.hold: This phase is called for entry into reset, once every obj= ect + * in the system which is being reset has had its @phases.init method call= ed. + * At this point devices can do actions that affect other objects. + * + * @phases.exit: This phase is called when the object leaves the reset sta= te. + * Actions affecting other objects are permitted. + * + * @get_state: Mandatory method which must return a pointer to a ResetStat= e. + * + * @foreach_child: Executes a given function on every Resettable child. Ch= ild + * in this context means a child in the qbus tree, so the children of a qb= us + * are the devices on it, and the children of a device are all the buses it + * owns. This is not the same as the QOM object hierarchy. The function ta= kes + * an additional ResetType argument which is passed to foreach_child. + */ +typedef void (*ResettableInitPhase)(Object *obj, ResetType type); +typedef void (*ResettableHoldPhase)(Object *obj); +typedef void (*ResettableExitPhase)(Object *obj); +typedef ResetState * (*ResettableGetState)(Object *obj); +typedef void (*ResettableForeachChild)(Object *obj, + void (*func)(Object *, ResetType ty= pe), + ResetType type); +typedef struct ResettableClass { + InterfaceClass parent_class; + + struct ResettablePhases { + ResettableInitPhase init; + ResettableHoldPhase hold; + ResettableExitPhase exit; + } phases; + + ResettableGetState get_state; + ResettableForeachChild foreach_child; +} ResettableClass; +typedef struct ResettablePhases ResettablePhases; + +/** + * ResetState: + * Structure holding reset related state. The fields should not be accessed + * directly, the definition is here to allow further inclusion into other + * objects. + * + * @count: Number of reset level the object is into. It is incremented when + * the reset operation starts and decremented when it finishes. + * @hold_phase_needed: flag which indicates that we need to invoke the 'ho= ld' + * phase handler for this object. + */ +struct ResetState { + uint32_t count; + bool hold_phase_needed; +}; + +/** + * resettable_is_resetting: + * Return true if @obj is under reset. + * + * @obj must implement Resettable interface. + */ +bool resettable_is_resetting(Object *obj); + +/** + * resettable_reset: + * Trigger a reset on a object @obj of type @type. @obj must implement + * Resettable interface. + * + * Calling this function is equivalent to calling @resettable_assert_reset= then + * @resettable_deassert_reset. + */ +void resettable_reset(Object *obj, ResetType type); + +/** + * resettable_cold_reset_fn: + * Helper to call resettable_reset((Object *) opaque, RESET_TYPE_COLD). + * + * This function is typically useful to register a reset handler with + * qemu_register_reset. + */ +void resettable_cold_reset_fn(void *opaque); + +/** + * resettable_class_set_parent_phases: + * + * Save @rc current reset phases into @parent_phases and override @rc phas= es + * by the given new methods (@init, @hold and @exit). + * Each phase is overridden only if the new one is not NULL allowing to + * override a subset of phases. + */ +void resettable_class_set_parent_phases(ResettableClass *rc, + ResettableInitPhase init, + ResettableHoldPhase hold, + ResettableExitPhase exit, + ResettablePhases *parent_phases); + +#endif --=20 2.22.0 From nobody Mon Apr 29 09:11:19 2024 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 1566405867698820.7666147052847; Wed, 21 Aug 2019 09:44:27 -0700 (PDT) Received: from localhost ([::1]:50484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0Tik-0000bo-DZ for importer@patchew.org; Wed, 21 Aug 2019 12:44:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59244) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0TZc-0006qZ-5w for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0TZa-0005bN-6r for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:00 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:36374) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i0TZZ-0005ad-UU for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:34:58 -0400 Received: from kouign-amann.bar.greensocs.com (unknown [172.16.11.117]) by beetle.greensocs.com (Postfix) with ESMTPS id A570896F52; Wed, 21 Aug 2019 16:34:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1566405297; 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=vatH2bbSlFKH2lP1p0Ci9l3PXtnnf6vO2BL1O07qJEM=; b=DDEdHK2bPBiENDjLdXzKzpjfMgvuF2S971d1oS8Tfgh7cl+oc/kwwV53Ti1gyKOS8L5CA0 ouPFrx0MFPBC5Z5ebn4qyLOvFD/iWmbl79ieIReRDVLXPMeke0LN6ycjdEfdlxestEaTp4 UGV8yFyIBPYs9tZEnspDuTLBz9llf/U= From: Damien Hedde To: qemu-devel@nongnu.org Date: Wed, 21 Aug 2019 18:33:34 +0200 Message-Id: <20190821163341.16309-4-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190821163341.16309-1-damien.hedde@greensocs.com> References: <20190821163341.16309-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=1566405297; 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=vatH2bbSlFKH2lP1p0Ci9l3PXtnnf6vO2BL1O07qJEM=; b=tr8AGmZDEiaPXnqE8kngAX2P0gI3srY6beq03kZ38NxlkHx+Ay6M8qmtEnczuHBDzxAtEC 3jAqwiuFgYfP43PhmMqnJeCjgxkwB8HRDQqSi6ulOJ/Deow6AO5xxMymYSn9MMtXGyfPli WqkD0qCMAijL7FeI4vrVgsIxDjfo8+I= ARC-Seal: i=1; s=mail; d=greensocs.com; t=1566405297; a=rsa-sha256; cv=none; b=jAqnOuuVCQINpupP2UA6Ps2v71+THWc3D1AEYetunAwCtaiB+OgyXA6MGMCDva3FAYKJCI ct7ixoftm9D2OyC3VdB89B0fUyemjP6xK2eYL6Pr2pLnxVkMvlXgQ+ZKRORbTdda6lqNEZ Mg/lJ0iVZG7D+epmCvt9jmkobU69Saw= ARC-Authentication-Results: i=1; beetle.greensocs.com; none 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 v4 03/10] hw/core: add Resettable interface in Bus and Device classes 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: Damien Hedde , peter.maydell@linaro.org, edgar.iglesias@xilinx.com, berrange@redhat.com, ehabkost@redhat.com, mark.burton@greensocs.com, pbonzini@redhat.com, philmd@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (identity @greensocs.com: invalid key for signature: Missing mandatory tag: p) Content-Type: text/plain; charset="utf-8" Implement Resettable interface in BusClass and DeviceClass; it adds the ResetState structure into BusState and DeviceState and the required methods in the classes. Helpers device_cold_reset and bus_cold_reset are defined to call to use the new interface. Also add a [device|bus]_is_resetting telling if the device/bus is currently under reset. Compatibility with existing code base is ensured; The legacy bus or device reset method is called in the new init phase. Since this phase is called for children before for parent in qbus hierarchy, the new reset behavior will be the same as qdev/qbus_reset_all functions; qdev/qbus_reset_all are now wrappers around device/bus_cold_reset functions. Deprecate old reset apis (device_legacy_reset and qdev/qbus_reset_all). These functions will be removed when transition to the new api is complete. At this point no migration support is required since there is no way to held an object into reset. This will be added later on. Signed-off-by: Damien Hedde --- I've kept the device/bus_cold_reset name; I think that even if we don't introduce other reset types (like warm), it has to advantage to clarify that current reset is "cold" (it put back what is the initial state when qemu starts). --- hw/core/bus.c | 53 +++++++++++++++++++++++++++++++ hw/core/qdev.c | 71 +++++++++++++++++++++++++++++++----------- include/hw/qdev-core.h | 62 +++++++++++++++++++++++++++++++++--- tests/Makefile.include | 1 + 4 files changed, 164 insertions(+), 23 deletions(-) diff --git a/hw/core/bus.c b/hw/core/bus.c index 7f3d2a3dbd..3be65ad041 100644 --- a/hw/core/bus.c +++ b/hw/core/bus.c @@ -22,6 +22,7 @@ #include "qemu/ctype.h" #include "qemu/module.h" #include "qapi/error.h" +#include "hw/resettable.h" =20 void qbus_set_hotplug_handler(BusState *bus, Object *handler, Error **errp) { @@ -68,6 +69,34 @@ int qbus_walk_children(BusState *bus, return 0; } =20 +void bus_cold_reset(BusState *bus) +{ + resettable_reset(OBJECT(bus), RESET_TYPE_COLD); +} + +bool bus_is_resetting(BusState *bus) +{ + return resettable_is_resetting(OBJECT(bus)); +} + +static ResetState *bus_get_reset_state(Object *obj) +{ + BusState *bus =3D BUS(obj); + return &bus->reset; +} + +static void bus_reset_foreach_child(Object *obj, + void (*func)(Object *, ResetType), + ResetType type) +{ + BusState *bus =3D BUS(obj); + BusChild *kid; + + QTAILQ_FOREACH(kid, &bus->children, sibling) { + func(OBJECT(kid->child), type); + } +} + static void qbus_realize(BusState *bus, DeviceState *parent, const char *n= ame) { const char *typename =3D object_get_typename(OBJECT(bus)); @@ -199,12 +228,32 @@ static char *default_bus_get_fw_dev_path(DeviceState = *dev) return g_strdup(object_get_typename(OBJECT(dev))); } =20 +/** + * bus_legacy_reset_wrapper: + * Compatibility wrapper during the transition to multi-phase reset. + * This function should be deleted when all buses are converted. + */ +static void bus_legacy_reset_wrapper(Object *obj, ResetType type) +{ + BusState *bus =3D BUS(obj); + BusClass *bc =3D BUS_GET_CLASS(obj); + + if (bc->reset) { + bc->reset(bus); + } +} + static void bus_class_init(ObjectClass *class, void *data) { BusClass *bc =3D BUS_CLASS(class); + ResettableClass *rc =3D RESETTABLE_CLASS(class); =20 class->unparent =3D bus_unparent; bc->get_fw_dev_path =3D default_bus_get_fw_dev_path; + + rc->phases.init =3D bus_legacy_reset_wrapper; + rc->get_state =3D bus_get_reset_state; + rc->foreach_child =3D bus_reset_foreach_child; } =20 static void qbus_finalize(Object *obj) @@ -223,6 +272,10 @@ static const TypeInfo bus_info =3D { .instance_init =3D qbus_initfn, .instance_finalize =3D qbus_finalize, .class_init =3D bus_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_RESETTABLE_INTERFACE }, + { } + }, }; =20 static void bus_register_types(void) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index a95d4fa87d..85c85822fd 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -255,25 +255,9 @@ HotplugHandler *qdev_get_hotplug_handler(DeviceState *= dev) return hotplug_ctrl; } =20 -static int qdev_reset_one(DeviceState *dev, void *opaque) -{ - device_legacy_reset(dev); - - return 0; -} - -static int qbus_reset_one(BusState *bus, void *opaque) -{ - BusClass *bc =3D BUS_GET_CLASS(bus); - if (bc->reset) { - bc->reset(bus); - } - return 0; -} - void qdev_reset_all(DeviceState *dev) { - qdev_walk_children(dev, NULL, NULL, qdev_reset_one, qbus_reset_one, NU= LL); + device_cold_reset(dev); } =20 void qdev_reset_all_fn(void *opaque) @@ -283,7 +267,7 @@ void qdev_reset_all_fn(void *opaque) =20 void qbus_reset_all(BusState *bus) { - qbus_walk_children(bus, NULL, NULL, qdev_reset_one, qbus_reset_one, NU= LL); + bus_cold_reset(bus); } =20 void qbus_reset_all_fn(void *opaque) @@ -292,6 +276,33 @@ void qbus_reset_all_fn(void *opaque) qbus_reset_all(bus); } =20 +void device_cold_reset(DeviceState *dev) +{ + resettable_reset(OBJECT(dev), RESET_TYPE_COLD); +} + +bool device_is_resetting(DeviceState *dev) +{ + return resettable_is_resetting(OBJECT(dev)); +} + +static ResetState *device_get_reset_state(Object *obj) +{ + DeviceState *dev =3D DEVICE(obj); + return &dev->reset; +} + +static void device_reset_foreach_child(Object *obj, + void (*func)(Object *, ResetType), + ResetType type) +{ + DeviceState *dev =3D DEVICE(obj); + BusState *bus; + QLIST_FOREACH(bus, &dev->child_bus, sibling) { + func(OBJECT(bus), type); + } +} + /* can be used as ->unplug() callback for the simple cases */ void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) @@ -1047,9 +1058,25 @@ static void device_unparent(Object *obj) } } =20 +/** + * device_legacy_reset_wrapper: + * Compatibility wrapper during the transition to multi-phase reset. + * This function should be deleted when all devices are converted. + */ +static void device_legacy_reset_wrapper(Object *obj, ResetType type) +{ + DeviceState *dev =3D DEVICE(obj); + DeviceClass *dc =3D DEVICE_GET_CLASS(dev); + + if (dc->reset) { + dc->reset(dev); + } +} + static void device_class_init(ObjectClass *class, void *data) { DeviceClass *dc =3D DEVICE_CLASS(class); + ResettableClass *rc =3D RESETTABLE_CLASS(class); =20 class->unparent =3D device_unparent; =20 @@ -1061,6 +1088,10 @@ static void device_class_init(ObjectClass *class, vo= id *data) */ dc->hotpluggable =3D true; dc->user_creatable =3D true; + + rc->phases.init =3D device_legacy_reset_wrapper; + rc->get_state =3D device_get_reset_state; + rc->foreach_child =3D device_reset_foreach_child; } =20 void device_class_set_parent_reset(DeviceClass *dc, @@ -1118,6 +1149,10 @@ static const TypeInfo device_type_info =3D { .class_init =3D device_class_init, .abstract =3D true, .class_size =3D sizeof(DeviceClass), + .interfaces =3D (InterfaceInfo[]) { + { TYPE_RESETTABLE_INTERFACE }, + { } + }, }; =20 static void qdev_register_types(void) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 09e6dfd664..2976121fbc 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -5,6 +5,7 @@ #include "qemu/bitmap.h" #include "qom/object.h" #include "hw/hotplug.h" +#include "hw/resettable.h" =20 enum { DEV_NVECTORS_UNSPECIFIED =3D -1, @@ -104,6 +105,11 @@ typedef struct DeviceClass { bool hotpluggable; =20 /* callbacks */ + /* + * Reset method here is deprecated and replaced by methods in the + * resettable class interface to implement a multi-phase reset. + * TODO: remove once every reset callback is unused + */ DeviceReset reset; DeviceRealize realize; DeviceUnrealize unrealize; @@ -128,6 +134,7 @@ struct NamedGPIOList { /** * DeviceState: * @realized: Indicates whether the device has been fully constructed. + * @reset: ResetState for the device; handled by Resettable interface. * * This structure should not be accessed directly. We declare it here * so that it can be embedded in individual device state structures. @@ -149,6 +156,7 @@ struct DeviceState { int num_child_bus; int instance_id_alias; int alias_required_for_version; + ResetState reset; }; =20 struct DeviceListener { @@ -195,6 +203,7 @@ typedef struct BusChild { /** * BusState: * @hotplug_handler: link to a hotplug handler associated with bus. + * @reset: ResetState for the bus; handled by Resettable interface. */ struct BusState { Object obj; @@ -206,6 +215,7 @@ struct BusState { int num_children; QTAILQ_HEAD(, BusChild) children; QLIST_ENTRY(BusState) sibling; + ResetState reset; }; =20 /** @@ -375,22 +385,55 @@ int qdev_walk_children(DeviceState *dev, qdev_walkerfn *post_devfn, qbus_walkerfn *post_busf= n, void *opaque); =20 -void qdev_reset_all(DeviceState *dev); -void qdev_reset_all_fn(void *opaque); - /** - * @qbus_reset_all: - * @bus: Bus to be reset. + * qbus/qdev_reset_all: + * @bus (resp. @dev): Bus (resp. Device) to be reset. * * Reset @bus and perform a bus-level ("hard") reset of all devices connec= ted * to it, including recursive processing of all buses below @bus itself. A * hard reset means that qbus_reset_all will reset all state of the device. * For PCI devices, for example, this will include the base address regist= ers * or configuration space. + * + * These functions are deprecated and are wrappers around device_cold_rese= t and + * bus_cold_reset. Please use these instead. + * TODO: remove them when all occurrences are removed */ +void qdev_reset_all(DeviceState *dev); +void qdev_reset_all_fn(void *opaque); void qbus_reset_all(BusState *bus); void qbus_reset_all_fn(void *opaque); =20 +/** + * device_cold_reset: + * Trigger a cold reset of the device @dev. + * + * Use the Resettable interface (see hw/interface.h); it also reset the + * device's qdev/qbus subtree. + */ +void device_cold_reset(DeviceState *dev); + +/** + * bus_cold_reset: + * Trigger a cold reset of the bus @bus. + * + * Use the Resettable interface (see hw/interface.h); it also reset the + * bus's qdev/qbus subtree. + */ +void bus_cold_reset(BusState *bus); + +/** + * device_is_resetting: + * Return true if the device @dev is currently being reset. + */ +bool device_is_resetting(DeviceState *dev); + +/** + * bus_is_resetting: + * Return true if the bus @bus is currently being reset. + */ +bool bus_is_resetting(BusState *bus); + /* This should go away once we get rid of the NULL bus hack */ BusState *sysbus_get_default(void); =20 @@ -409,9 +452,18 @@ void qdev_machine_init(void); * device_legacy_reset: * * Reset a single device (by calling the reset method). + * + * This function is deprecated, please use Resettable api instead (eg: + * device_cold_reset()) + * TODO: remove the function when all occurrences are removed. */ void device_legacy_reset(DeviceState *dev); =20 +/** + * device_class_set_parent_reset: + * TODO: remove the function when DeviceClass's reset method + * is not used anymore. + */ void device_class_set_parent_reset(DeviceClass *dc, DeviceReset dev_reset, DeviceReset *parent_reset); diff --git a/tests/Makefile.include b/tests/Makefile.include index 6f02dfcc01..f0b4628cc6 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -561,6 +561,7 @@ tests/fp/%: =20 tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \ hw/core/qdev.o hw/core/qdev-properties.o hw/core/hotplug.o\ + hw/core/resettable.o \ hw/core/bus.o \ hw/core/irq.o \ hw/core/fw-path-provider.o \ --=20 2.22.0 From nobody Mon Apr 29 09:11:19 2024 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 1566406160265715.0362465058624; Wed, 21 Aug 2019 09:49:20 -0700 (PDT) Received: from localhost ([::1]:50530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0TnP-000443-Ht for importer@patchew.org; Wed, 21 Aug 2019 12:49:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59279) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0TZe-0006sy-70 for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0TZc-0005dE-2W for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:02 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:36390) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i0TZb-0005cG-QP for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:00 -0400 Received: from kouign-amann.bar.greensocs.com (unknown [172.16.11.117]) by beetle.greensocs.com (Postfix) with ESMTPS id 81F2D96F53; Wed, 21 Aug 2019 16:34:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1566405298; 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=5s3g+eOtJnwndxxC6fRoKzELDl+Nr+QvbKDkRFoK0lY=; b=KA34+g8+D/lNpDybKrqki0WeQbTgsEc785IbxS4FjTxSty6pPi47bamytRWGQnEouhZ9k/ y1hNN3wmcSTLrShIUDOvmlpMm1jfnyx6TFqxlv5jugsio4ypMNyJD184YuIwowskIeALxH uoKc/gG+KqclQ/YkTQh3xP5NU2KjRZU= From: Damien Hedde To: qemu-devel@nongnu.org Date: Wed, 21 Aug 2019 18:33:35 +0200 Message-Id: <20190821163341.16309-5-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190821163341.16309-1-damien.hedde@greensocs.com> References: <20190821163341.16309-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=1566405298; 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=5s3g+eOtJnwndxxC6fRoKzELDl+Nr+QvbKDkRFoK0lY=; b=cHMrXL3oSWGuYmRkZrUWJ7rOVUguSLrNJrAYvPUjWNIpet4oOX4EQdEe7jd7GuxjVLMiuF YCgwurv0LllmyECsuh+LRGcpiNHlkxEMRM3RhhqQ42EgbDCu54AJacgLt3ddmz2LMcKuwr hmxufvyvzubTjd53NSevZtF+30Fzh6Q= ARC-Seal: i=1; s=mail; d=greensocs.com; t=1566405299; a=rsa-sha256; cv=none; b=2Ar5XziUDI9kXbdIS3NcX6aKYGudLi+ShHtLpoyT79VYH+AACYUj/5kCd4ssmAAzRSLNXY XjZO2hOnElN8kTSflSFVwPhNlZIRHTciFCOSQIftsiy3Hv9f/GiIfR5Zt7nBO6hNtVL8CQ faaiS8XejOadW+wJ4S+ziGSlU+RXrz8= ARC-Authentication-Results: i=1; beetle.greensocs.com; none 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 v4 04/10] docs/devel/reset.txt: create doc about Resettable interface 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: Damien Hedde , peter.maydell@linaro.org, edgar.iglesias@xilinx.com, berrange@redhat.com, ehabkost@redhat.com, mark.burton@greensocs.com, pbonzini@redhat.com, philmd@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (identity @greensocs.com: invalid key for signature: Missing mandatory tag: p) Content-Type: text/plain; charset="utf-8" It documents only the multi-phase mechanism with one reset possible type (cold). Other features will be documented by further commits. Signed-off-by: Damien Hedde --- docs/devel/reset.txt | 237 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 237 insertions(+) create mode 100644 docs/devel/reset.txt diff --git a/docs/devel/reset.txt b/docs/devel/reset.txt new file mode 100644 index 0000000000..77ff29b3d7 --- /dev/null +++ b/docs/devel/reset.txt @@ -0,0 +1,237 @@ + +=3D=3D=3D=3D=3D +Reset +=3D=3D=3D=3D=3D + +The reset of qemu objects is handled using the Resettable interface declar= ed +in *include/hw/resettable.h*. + +This interface allows to group objects (on a tree basis) and to reset the +whole group consistently. Each individual member object does not have to c= are +about others; in particular problems of order (which object is reset first) +are addressed. + +As of now DeviceClass and BusClass implement this interface. + + +Reset types +----------- + +There are several kinds of reset. The most obvious one is the "cold" reset= : a +"cold" reset is the operation resulting of a power cycle (when we apply the +power). + +By opposition, we call a "warm" reset, a reset operation not resulting of a +power cycle; it can be triggered by a gpio or a software operation. + +Some buses also define specific kinds of reset. + +What does a reset is device-dependent. For most devices, cold or warm reset +makes no difference. But there can be some; some configuration may be kept= when +applying a warm reset for example. + +The Resettable interface handles reset kinds with an enum. For now only co= ld +reset is defined, others may be added later. +``` +typedef enum ResetType { + RESET_TYPE_COLD, +} ResetType; +``` + +In qemu, RESET_TYPE_COLD means we reset to the initial state corresponding= to +the start of qemu; this might differs from what is a read hardware cold re= set. + + +Triggering reset +---------------- + +This section documents the APIs which "users" of a resettable object shoul= d use +to control it. All resettable control functions must be called while holdi= ng +the iothread lock. + +You can trigger a reset event on a resettable object with resettable_reset= (). +The object will be instantly reset. + +```void resettable_reset(Object *obj, ResetType type);``` +The parameter "obj" is an object implementing the Resettable interface. +The parameter "type" gives the type of reset you want to trigger. + +It is possible to interleave multiple calls to + - resettable_reset(). + +There may be several reset sources/controllers of a given object. The inte= rface +handles everything and the different reset controllers do not need to know +anything about each others. The object will leave reset state only when ea= ch +other controllers end their reset operation. This point is handled by +maintaining a count of reset. + +Note that it is a programming error to call a resettable function on a +non-Resettable object and it will trigger a run time assert error. Since m= ost +call to Resettable interface are done through base class functions, such an +error is not likely to happen. + +For Devices and Buses, the following helper functions exists: +``` +void device_cold_reset(Device *dev); +void bus_cold_reset(Bus *bus); +``` + +These are simple wrappers around resettable_reset() function; they only ca= st the +Device or Bus into an Object and add the corresponding reset type. + +Device and bus functions co-exist because there can be semantic differences +between resetting a bus and resetting the controller bridge which owns it. +For example, considering a SCSI controller. Resetting the controller puts = all +its registers back to what reset state was as well as reset everything on = the +SCSI bus. Whereas resetting just the SCSI bus only resets everything that'= s on +it but not the controller. + + +How it works: multi-phase reset +------------------------------- + +This section documents the internals of the resettable interface. + +The resettable interface uses a multi-phase system to relieve objects and +machines from reset ordering problems. To address this, the reset operation +of an object is split into 3 well defined phases. + +When resetting a several objects (for example the whole machine at simulat= ion +startup), all 1st phases of all objects are executed, then all 2nd phases = and +then all 3rd phases. + +The 3 phases are: + + 1. INIT: This phase is executed when the object enters reset. It should = reset + local state of the object, but it must not do anything that has a side-e= ffect + on other objects, such as raising or lowering a qemu_irq line or reading= or + writing guest memory. + + 2. HOLD: This phase is executed for entry into reset, once every object = in the + system which is being reset has had its init phase executed. At this poi= nt + devices can do actions that affect other objects. + + 3. EXIT: This phase is executed when the object leaves the reset state. + Actions affecting other objects are permitted. + +As said in previous section, the interface maintains a count of reset. This +count is used to ensure phases are executed only when required. +init and hold phases are executed only when entering reset for the first t= ime +(if an object is already in reset state when calling resettable_assert_res= et() +or resettable_reset(), they are not executed). +The exit phase is executed only when the last reset operation ends. Theref= ore +the object has not to care how many reset controllers it has and how many = of +them have started a reset. + + +Handling reset in a new resettable object +----------------------------------------- + +This section documents the APIs that an implementation of a resettable obj= ect +must provide and what functions it has access to. + +There are three methods in the interface that must be implemented in an +resettable object. +The methods correspond to the three phases described in the previous secti= on: +``` +typedef void (*ResettableInitPhase)(Object *obj, ResetType type); +typedef void (*ResettableHoldPhase)(Object *obj); +typedef void (*ResettableExitPhase)(Object *obj); +typedef struct ResettableClass { + InterfaceClass parent_class; + + struct ResettablePhases { + ResettableInitPhase init; + ResettableHoldPhase hold; + ResettableExitPhase exit; + } phases; + [...] +} ResettableClass; +``` + +All phases takes a pointer to the object as first argument. The init phase= also +takes the reset type. + +These methods should be updated when specializing an object. For this the +helper function resettable_class_set_parent_phases() can be used to "backu= p" +parent methods while changing the specialized ones: + + +``` +void resettable_class_set_parent_reset_phases(ResettableClass *rc, + ResettableInitPhase init, + ResettableHoldPhase hold, + ResettableExitPhase exit, + ResettablePhases *parent_pha= ses); +``` +"rc" argument is the interface class structure; "init", "hold" and "exit" = are +the specialized phase methods for the object; and "parent_phases" is an +allocated space (typically in the specialized object class) to backup the +parent phases. This function only do the backup and update operation for p= hase +arguments that are non-NULL; you can use it to specialize only the init me= thod +for example. When you specialize a method, it's on you to call or not the = parent +method inside the specialized one. + +If for some operation in the object, you need to know the reset state, the= re is +a function to access that: +``` +bool resettable_is_resetting(Object *obj); +``` + +resettable_is_resetting() tells if the resettable object is currently under +reset. + +Helpers are defined for devices and buses that wrap resettable_is_resettin= g(): +``` +bool device_is_resetting(DeviceState *dev); +bool bus_is_resetting(BusState *bus); +``` + + +Base class handling of reset +---------------------------- + +This section documents parts of the reset mechanism that you only need to = know +about if you are extending it to work with a new base class other than +DeviceClass or BusClass, or maintaining the existing code in those classes= . Most +people can ignore it. + +There are two other methods that need to exist in a class implementing the +interface. + +``` +typedef struct ResetState { + uint32_t count; + bool hold_phase_needed; +} ResetState; + +typedef ResetState *(*ResettableGetState)(Object *obj); +typedef void (*ResettableForeachChild)(Object *obj, + void (*visitor)(Object *, ResetType= ), + ResetType type); +typedef struct ResettableClass { + InterfaceClass parent_class; + + [...] + + ResettableGetState get_state; + ResettableForeachChild foreach_child; +} ResettableClass; +``` + +get_state() must return a pointer to an allocated ResetState structure. +This structure is used by the interface to store the information required +to handle reset properly. This structure must not be modified by the object +directly. The object must handle eventual allocation/deallocation of this +structure during its creation and deletion. Typically it is located in the +object state structure. + +The reset hierarchy is handled by means of the foreach_child() method. This +method executes a given function on all reset children. An additional type +argument is given to foreach_child() and must be passed to the function. + +In DeviceClass and BusClass the ResetState structure is located +DeviceState/BusState structure. foreach_child() is implemented to follow t= he bus +hierarchy; for a bus, it calls the function on every child device; for a d= evice, +it calls the function on every bus child. So when we reset the main system= bus, +we reset the whole machine bus tree. --=20 2.22.0 From nobody Mon Apr 29 09:11:19 2024 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 1566405559739586.4619830048681; Wed, 21 Aug 2019 09:39:19 -0700 (PDT) Received: from localhost ([::1]:50440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0Tdm-0004HB-Ib for importer@patchew.org; Wed, 21 Aug 2019 12:39:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59444) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0TZm-0007BT-KN for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0TZl-0005po-FI for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:10 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:36410) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i0TZl-0005nS-6l for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:09 -0400 Received: from kouign-amann.bar.greensocs.com (unknown [172.16.11.117]) by beetle.greensocs.com (Postfix) with ESMTPS id D839B96F50; Wed, 21 Aug 2019 16:35:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1566405308; 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=r4V2TkfQMmqe9F4xpIDy/kbJA4b4WXcmEZS3sT7nAis=; b=yIFHJOCES4jzCfh1jZBX6xkQ0Y9wANyHYJdMFN2wzxuAENfr2VnrystfCFYks4vonyLkVo mwF/8DpQ8WCsaDimrLi8yNA/E4VxcDz1Vt99fkyND1muDlSIL1/RJU7kDLB5A1bgJs1l71 fJVdPZsxZkwFAzk1aojgeaYHsT/XVK4= From: Damien Hedde To: qemu-devel@nongnu.org Date: Wed, 21 Aug 2019 18:33:36 +0200 Message-Id: <20190821163341.16309-6-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190821163341.16309-1-damien.hedde@greensocs.com> References: <20190821163341.16309-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=1566405308; 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=r4V2TkfQMmqe9F4xpIDy/kbJA4b4WXcmEZS3sT7nAis=; b=GEXU8aorDGiWJuJf50Um0oS+dynX4AvyqbN9D6uPhw3HDxdNKcdIRFsrZ66vtYDVtCXoOY VBQEalDqar+G9SUVxGrxsbAfFJQs8TYO+hzN7bkVNFTArkdmNZGKLwkhLJiPn6eBWSrJbe M2Bt49zj7epPDBjrDxAHPrvLOUIh6aY= ARC-Seal: i=1; s=mail; d=greensocs.com; t=1566405308; a=rsa-sha256; cv=none; b=sKc1fC0XgQy1JxuXhFGeD3fiNOdgToHbqQbW27D8ohZKb7SBfsG2Tga3pU8WtwLUUq69sg T8yhJkGBZeBBYzJet2mnNzSuPFb55tY1C9V18bYyb4e1Cng8y6IiB6kSUq023SO+J24scx a50gg3EOzo0WK6X3Vipl8g/pkl1gbLc= ARC-Authentication-Results: i=1; beetle.greensocs.com; none 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 v4 05/10] vl.c: replace deprecated qbus_reset_all registration 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: Damien Hedde , peter.maydell@linaro.org, edgar.iglesias@xilinx.com, berrange@redhat.com, ehabkost@redhat.com, mark.burton@greensocs.com, pbonzini@redhat.com, philmd@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (identity @greensocs.com: invalid key for signature: Missing mandatory tag: p) Content-Type: text/plain; charset="utf-8" Replace deprecated qbus_reset_all by resettable_cold_reset_fn for the sysbus reset registration. This does not impact the behavior: qbus_reset_all is already a wrapper for the cold reset function. Signed-off-by: Damien Hedde Reviewed-by: Peter Maydell --- vl.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/vl.c b/vl.c index edd5390110..8df686b333 100644 --- a/vl.c +++ b/vl.c @@ -4422,7 +4422,15 @@ int main(int argc, char **argv, char **envp) =20 /* TODO: once all bus devices are qdevified, this should be done * when bus is created by qdev.c */ - qemu_register_reset(qbus_reset_all_fn, sysbus_get_default()); + /* + * TODO: If we had a main 'reset container' that the whole system + * lived in, we could reset that using the multi-phase reset + * APIs. For the moment, we just reset the sysbus, which will cause + * all devices hanging off it (and all their child buses, recursively) + * to be reset. Note that this will *not* reset any Device objects + * which are not attached to some part of the qbus tree! + */ + qemu_register_reset(resettable_cold_reset_fn, sysbus_get_default()); qemu_run_machine_init_done_notifiers(); =20 if (rom_check_and_register_reset() !=3D 0) { --=20 2.22.0 From nobody Mon Apr 29 09:11:19 2024 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 1566405894802872.4806668668793; Wed, 21 Aug 2019 09:44:54 -0700 (PDT) Received: from localhost ([::1]:50498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0TjB-0001E8-Ku for importer@patchew.org; Wed, 21 Aug 2019 12:44:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59591) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0TZw-0007Yr-VY for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0TZv-00062w-Tc for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:20 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:36434) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i0TZv-000621-OI; Wed, 21 Aug 2019 12:35:19 -0400 Received: from kouign-amann.bar.greensocs.com (unknown [172.16.11.117]) by beetle.greensocs.com (Postfix) with ESMTPS id 4BAC196F51; Wed, 21 Aug 2019 16:35:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1566405318; 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=7oVn6Ej5gpQqBhvpdEgVYAbVkVIuJr7fow3pu2NUpL8=; b=SL1t5YPNrtnpMOBRx4jIX566EM2G4MkaqeZs/BwFELIVo1+df7GjO4f+2VznMKNUVUIYIi 6CbioF1q3EGHHMmXYqdFW57hqInZmGNLAH/CbpLTSEXOnal88V8WftKAjpbEOOR5g0UUPM XTNIENg6hieLzdU12sReut9jGjEP2Ug= From: Damien Hedde To: qemu-devel@nongnu.org Date: Wed, 21 Aug 2019 18:33:37 +0200 Message-Id: <20190821163341.16309-7-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190821163341.16309-1-damien.hedde@greensocs.com> References: <20190821163341.16309-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=1566405318; 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=7oVn6Ej5gpQqBhvpdEgVYAbVkVIuJr7fow3pu2NUpL8=; b=ZDHnk7SDL6W49lJAL2hG4S8loJlnLLNCSOjdZV2/Go36CSg32uof4qNCTlCFtXMMyas1W6 fBjlVxG8QADpAdvxYdX7w+aeBUguatB7DkFyP/DoufkqY1k3SAOrF9b+xrK+ZJw06REsEH J5sQE3Rdm6xPlRY05XG9J9/x0Ey2KrU= ARC-Seal: i=1; s=mail; d=greensocs.com; t=1566405318; a=rsa-sha256; cv=none; b=Gk7oRRFSzsRxJGan7x47CiHQg2wxlUrHDLLhgMRQIYEW6Hlv0lUUT8K0pu8z4VfTXd8V35 Gag+BkQ1lLudshxDyVql/nvW6NswlvpalgtDtuXep7rEg5g/YWD8f5Qm9rjAyZVAITaUgu 2I5qBNeqzPWnb0P3uEwSE0rj3bb44Yk= ARC-Authentication-Results: i=1; beetle.greensocs.com; none 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 v4 06/10] hw/s390x/ipl.c: replace deprecated qbus_reset_all registration 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: Damien Hedde , peter.maydell@linaro.org, Thomas Huth , edgar.iglesias@xilinx.com, berrange@redhat.com, ehabkost@redhat.com, Cornelia Huck , mark.burton@greensocs.com, Christian Borntraeger , qemu-s390x@nongnu.org, pbonzini@redhat.com, philmd@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (identity @greensocs.com: invalid key for signature: Missing mandatory tag: p) Content-Type: text/plain; charset="utf-8" Replace deprecated qbus_reset_all by resettable_cold_reset_fn for the ipl registration in the main reset handlers. This does not impact the behavior: qbus_reset_all is already a wrapper for the cold reset function. Signed-off-by: Damien Hedde --- Cc: Cornelia Huck Cc: qemu-s390x@nongnu.org Cc: Christian Borntraeger Cc: Thomas Huth --- hw/s390x/ipl.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c index ca544d64c5..2689f7a017 100644 --- a/hw/s390x/ipl.c +++ b/hw/s390x/ipl.c @@ -237,7 +237,15 @@ static void s390_ipl_realize(DeviceState *dev, Error *= *errp) */ ipl->compat_start_addr =3D ipl->start_addr; ipl->compat_bios_start_addr =3D ipl->bios_start_addr; - qemu_register_reset(qdev_reset_all_fn, dev); + /* + * Because this Device is not on any bus in the qbus tree (it is + * not a sysbus device and it's not on some other bus like a PCI + * bus) it will not be automatically reset by the 'reset the + * sysbus' hook registered by vl.c like most devices. So we must + * manually register a reset hook for it. + * TODO: there should be a better way to do this. + */ + qemu_register_reset(resettable_cold_reset_fn, dev); error: error_propagate(errp, err); } --=20 2.22.0 From nobody Mon Apr 29 09:11:19 2024 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 1566405700783450.5738011211812; Wed, 21 Aug 2019 09:41:40 -0700 (PDT) Received: from localhost ([::1]:50454 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0Tg3-0006Xh-Dr for importer@patchew.org; Wed, 21 Aug 2019 12:41:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59651) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0Ta2-0007hu-Jb for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0Ta1-00067q-KI for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:26 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:36454) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i0Ta1-000670-EQ for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:25 -0400 Received: from kouign-amann.bar.greensocs.com (unknown [172.16.11.117]) by beetle.greensocs.com (Postfix) with ESMTPS id 266C196F52; Wed, 21 Aug 2019 16:35:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1566405324; 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=JJqzrWUesMM9moVvWlYjWIG14La+JA2uQqLkOjCIyVA=; b=H2w4W3G9ZieSuyLnZQxAd72oBZSjWwOBUYN6mdvj+mEKj8JyV6pOlLTpZAffuhoshRCIhZ 6lNn7mboUEYqL+WJ3bK4tOrdRZHcYkQohghqAJvJjegT/yi1PvqPcG5fZomBcUdIz8urNB 84x7scbOPi9UBx6FEMcFkNBp6tztZPk= From: Damien Hedde To: qemu-devel@nongnu.org Date: Wed, 21 Aug 2019 18:33:38 +0200 Message-Id: <20190821163341.16309-8-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190821163341.16309-1-damien.hedde@greensocs.com> References: <20190821163341.16309-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=1566405324; 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=JJqzrWUesMM9moVvWlYjWIG14La+JA2uQqLkOjCIyVA=; b=7wzMrZNzszHcPDuv9AtKGGuU53RzItbuHLWBLkHXqODErecQ3nEpRouB3eBxbLGZByC1s2 Sl9QwZ3NCB3q38hrA2RmqViYbw+meoVhLHDA7xCqZPY80f2lqwl+VetgX/PIgZrAA6gn7i Z4LhA8mNJiz38GtqG8LOQFLwFUYzMjg= ARC-Seal: i=1; s=mail; d=greensocs.com; t=1566405324; a=rsa-sha256; cv=none; b=BOufbBvxcdk5EA7O+BvNKUUTL0zxdT/246WtEKDTItcZUI1KFrJApE2KqhBmR/xTk/o5Mr oAH1wpN8Pqjs0ENwyglkhSCHvQ2z9NMMBIYAup3aa1ar3ezatGY2pScWKufH+bBsuUnR4q +5ua+d2mYTaFAl4jLxwTAZmG/TIPzX0= ARC-Authentication-Results: i=1; beetle.greensocs.com; none 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 v4 07/10] hw/core/qdev: replace deprecated device_legacy_reset when hotplugging device 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: Damien Hedde , peter.maydell@linaro.org, edgar.iglesias@xilinx.com, berrange@redhat.com, ehabkost@redhat.com, mark.burton@greensocs.com, pbonzini@redhat.com, philmd@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (identity @greensocs.com: invalid key for signature: Missing mandatory tag: p) Content-Type: text/plain; charset="utf-8" Replace the hotplugged device_legacy_reset by device_cold_reset. Since we're talking hotplug, cold reset seems the proper reset type. This does change the behavior since the new function propagates also the reset to eventual child buses. But it should be a bug if resetting eventual child buses fail. Signed-off-by: Damien Hedde --- hw/core/qdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 85c85822fd..1638bc9f3b 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -876,7 +876,7 @@ static void device_set_realized(Object *obj, bool value= , Error **errp) } } if (dev->hotplugged) { - device_legacy_reset(dev); + device_cold_reset(dev); } dev->pending_deleted_event =3D false; =20 --=20 2.22.0 From nobody Mon Apr 29 09:11:19 2024 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 1566406387206460.8781839709003; Wed, 21 Aug 2019 09:53:07 -0700 (PDT) Received: from localhost ([::1]:50584 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0Tr7-0007pN-Td for importer@patchew.org; Wed, 21 Aug 2019 12:53:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59685) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0Ta5-0007n8-Br for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0Ta4-0006AF-26 for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:29 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:36476) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i0Ta3-00069Q-Pv for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:28 -0400 Received: from kouign-amann.bar.greensocs.com (unknown [172.16.11.117]) by beetle.greensocs.com (Postfix) with ESMTPS id 72AF396F53; Wed, 21 Aug 2019 16:35:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1566405326; 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=4T0tdRysLQN0/hyNXEL3bhUMmWy8v0Titbmq3w/t+44=; b=fMpN/mteEmPFjIusu2nrD5fpFOwsUBu4FTzCwoiYZiBE9EAFdAB/OGYyjEcmvBt1UdRaU8 FE9WHpmPKD/YKi1l8y+6Va5yfJmWivYUpFnOAa7q488tKVfx6k6jXjnPBw1nwSTTPtvxdY jebIa0vPNNBdiETKGNMeaeqp6bBWCNY= From: Damien Hedde To: qemu-devel@nongnu.org Date: Wed, 21 Aug 2019 18:33:39 +0200 Message-Id: <20190821163341.16309-9-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190821163341.16309-1-damien.hedde@greensocs.com> References: <20190821163341.16309-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=1566405326; 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=4T0tdRysLQN0/hyNXEL3bhUMmWy8v0Titbmq3w/t+44=; b=mJEIsJfKIHztppP3z7aj0IcbaDA4BX4MDI1H1BF3nVXDA/8CVzUHv4iRq0BtYW4bd/B5Xa FCEtJ12f38syUmB2pPmMh0aQzE3lPQJVjQpoS5qIYpXfMbrzoVd9d4Rw2NL9pal3yNmXbU slb6mzjjJ2Yvcx1vIQh/q4Rdnu4PM9o= ARC-Seal: i=1; s=mail; d=greensocs.com; t=1566405326; a=rsa-sha256; cv=none; b=faWP2sO/fWFFCBIxuHjkfDog4OdVgP7Eukg1C08m7KQrbMPDmtwAI7ihjm9f3aRKl7MlnC UJBKcWsRasLGqoYBmLYa66szysuuYREFFsKBWuBTorjUY+8u1SYfwTWjewQw4pXd0MLztQ PNn5h7aU03rDKdtMg43NWL/AvSqVlwk= ARC-Authentication-Results: i=1; beetle.greensocs.com; none 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 v4 08/10] hw/core/resettable: add support for warm reset 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: Damien Hedde , peter.maydell@linaro.org, edgar.iglesias@xilinx.com, berrange@redhat.com, ehabkost@redhat.com, mark.burton@greensocs.com, pbonzini@redhat.com, philmd@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (identity @greensocs.com: invalid key for signature: Missing mandatory tag: p) Content-Type: text/plain; charset="utf-8" Add the RESET_TYPE_WARM reset type. Expand the actual implementation to support several types. I used values which can be or'ed together. This way we can what reset has been triggered. Documentation is added in a following patch. Signed-off-by: Damien Hedde --- hw/core/resettable.c | 25 +++++++++++++++++++------ include/hw/resettable.h | 22 +++++++++++++++++----- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/hw/core/resettable.c b/hw/core/resettable.c index b534c2c7a4..80674292b3 100644 --- a/hw/core/resettable.c +++ b/hw/core/resettable.c @@ -34,12 +34,17 @@ static void resettable_init_reset(Object *obj, ResetTyp= e type) ResetState *s =3D rc->get_state(obj); bool action_needed =3D false; =20 - /* Only take action if we really enter reset for the 1st time. */ + /* ensure type is empty if no reset is in progress */ + if (s->count =3D=3D 0) { + s->type =3D 0; + } + /* - * TODO: if adding more ResetType support, some additional checks - * are probably needed here. + * Only take action if: + * + we are not already in cold reset, + * + and we enter a new type of reset. */ - if (s->count =3D=3D 0) { + if ((s->type & RESET_TYPE_COLD) =3D=3D 0 && (s->type & type) =3D=3D 0)= { action_needed =3D true; } s->count +=3D 1; @@ -62,6 +67,7 @@ static void resettable_init_reset(Object *obj, ResetType = type) =20 /* exec init phase */ if (action_needed) { + s->type |=3D type; s->hold_phase_needed =3D true; if (rc->phases.init) { rc->phases.init(obj, type); @@ -133,8 +139,7 @@ static void resettable_exit_reset(Object *obj) =20 void resettable_reset(Object *obj, ResetType type) { - /* TODO: change that when adding support for other reset types */ - assert(type =3D=3D RESET_TYPE_COLD); + assert(type =3D=3D RESET_TYPE_COLD || type =3D=3D RESET_TYPE_WARM); trace_resettable_reset(obj, type); resettable_init_reset(obj, type); resettable_hold_reset(obj); @@ -154,6 +159,14 @@ bool resettable_is_resetting(Object *obj) return (s->count > 0); } =20 +ResetType resettable_get_type(Object *obj) +{ + ResettableClass *rc =3D RESETTABLE_GET_CLASS(obj); + ResetState *s =3D rc->get_state(obj); + + return s->type; +} + void resettable_class_set_parent_phases(ResettableClass *rc, ResettableInitPhase init, ResettableHoldPhase hold, diff --git a/include/hw/resettable.h b/include/hw/resettable.h index 5808c3c187..1e77cbd75b 100644 --- a/include/hw/resettable.h +++ b/include/hw/resettable.h @@ -12,15 +12,14 @@ typedef struct ResetState ResetState; =20 /** * ResetType: - * Types of reset. + * Types of reset, values can be OR'ed together. * * + Cold: reset resulting from a power cycle of the object. - * - * TODO: Support has to be added to handle more types. In particular, - * ResetState structure needs to be expanded. + * + Warm: reset without power cycling. */ typedef enum ResetType { - RESET_TYPE_COLD, + RESET_TYPE_COLD =3D 0x1, + RESET_TYPE_WARM =3D 0x2, } ResetType; =20 /* @@ -107,11 +106,13 @@ typedef struct ResettablePhases ResettablePhases; * * @count: Number of reset level the object is into. It is incremented when * the reset operation starts and decremented when it finishes. + * @type: Type of the in-progress reset. Valid only when count is non-zero. * @hold_phase_needed: flag which indicates that we need to invoke the 'ho= ld' * phase handler for this object. */ struct ResetState { uint32_t count; + ResetType type; bool hold_phase_needed; }; =20 @@ -123,6 +124,17 @@ struct ResetState { */ bool resettable_is_resetting(Object *obj); =20 +/** + * resettable_get_type: + * Return the current type of reset @obj is under. + * + * @obj must implement Resettable interface. Result is only valid if + * @resettable_is_resetting is true. + * + * Note: this return an OR'ed value of type if several reset were triggered + */ +ResetType resettable_get_type(Object *obj); + /** * resettable_reset: * Trigger a reset on a object @obj of type @type. @obj must implement --=20 2.22.0 From nobody Mon Apr 29 09:11:19 2024 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 1566406457898845.5794577287108; Wed, 21 Aug 2019 09:54:17 -0700 (PDT) Received: from localhost ([::1]:50596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0TsA-0001We-Il for importer@patchew.org; Wed, 21 Aug 2019 12:54:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59701) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0Ta6-0007rD-LL for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0Ta5-0006Bc-Dl for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:30 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:36492) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i0Ta5-0006Ae-5c for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:29 -0400 Received: from kouign-amann.bar.greensocs.com (unknown [172.16.11.117]) by beetle.greensocs.com (Postfix) with ESMTPS id DC66D96F54; Wed, 21 Aug 2019 16:35:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1566405328; 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=IoXWqtvBGWyNCiBvyV0lKqkzc+865svTakM6A2Tn4Wk=; b=G/MeHLaH4aAjNQudwW3sXabdf2FzcsahvfF33SALhn2jSgXXDnFsgr5W4Zxmw5vZfZ7+l1 wKumm0o2gYn2vBUw2zGlrUIq8EjX95fho8iBq1nkPaXKPn/H+FxDQCh8RG4ew4eRiaoFJO XW7EqGwzpS2/dWTwzPZFDoCCJHNtVRk= From: Damien Hedde To: qemu-devel@nongnu.org Date: Wed, 21 Aug 2019 18:33:40 +0200 Message-Id: <20190821163341.16309-10-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190821163341.16309-1-damien.hedde@greensocs.com> References: <20190821163341.16309-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=1566405328; 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=IoXWqtvBGWyNCiBvyV0lKqkzc+865svTakM6A2Tn4Wk=; b=OLi8yLSbTEHnvGY6grGbLGGgzTuR4VU0EJxNEhluRs6/WFlqje4iQcdy8ye2tTgkeBMN6x ltIj5ttoqJhPtHVKAfYxthFz6GSypZR9MlZ8V+C9lREJH4RETEoQlmmF2q7WoTpFx7GWT3 R9ogOklrt4xhn9D+fJ+I+Fd8eBcSZPw= ARC-Seal: i=1; s=mail; d=greensocs.com; t=1566405328; a=rsa-sha256; cv=none; b=597dorltUPx5uesqcLQCv6daraqUYiPE46pTVlnjKi0Gb6RmAwl4fJkJMGm4a0R7ePNpHf +nPHru8zyO3aR2nuT1ozHx7H0FoXpup7TR1Ye3IIdt7s6173dNsDesCUOsxDWw9avRGs8z YWRHRDSy9RUxHLu5Gkerr0uRX7ASnJI= ARC-Authentication-Results: i=1; beetle.greensocs.com; none 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 v4 09/10] hw/core/: add warm reset helpers for devices and buses 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: Damien Hedde , peter.maydell@linaro.org, edgar.iglesias@xilinx.com, berrange@redhat.com, ehabkost@redhat.com, mark.burton@greensocs.com, pbonzini@redhat.com, philmd@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (identity @greensocs.com: invalid key for signature: Missing mandatory tag: p) Content-Type: text/plain; charset="utf-8" This add helpers to trigger warm reset and to retrieve the reset current reset type. Signed-off-by: Damien Hedde --- hw/core/bus.c | 11 +++++++++++ hw/core/qdev.c | 11 +++++++++++ include/hw/qdev-core.h | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/hw/core/bus.c b/hw/core/bus.c index 3be65ad041..b245fd6937 100644 --- a/hw/core/bus.c +++ b/hw/core/bus.c @@ -74,11 +74,22 @@ void bus_cold_reset(BusState *bus) resettable_reset(OBJECT(bus), RESET_TYPE_COLD); } =20 +void bus_warm_reset(BusState *bus) +{ + resettable_reset(OBJECT(bus), RESET_TYPE_WARM); +} + bool bus_is_resetting(BusState *bus) { return resettable_is_resetting(OBJECT(bus)); } =20 +bool bus_test_reset_type(BusState *bus, ResetType type) +{ + ResetType cur_type =3D resettable_get_type(OBJECT(bus)); + return (cur_type & type); +} + static ResetState *bus_get_reset_state(Object *obj) { BusState *bus =3D BUS(obj); diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 1638bc9f3b..9095f2b9c1 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -281,11 +281,22 @@ void device_cold_reset(DeviceState *dev) resettable_reset(OBJECT(dev), RESET_TYPE_COLD); } =20 +void device_warm_reset(DeviceState *dev) +{ + resettable_reset(OBJECT(dev), RESET_TYPE_WARM); +} + bool device_is_resetting(DeviceState *dev) { return resettable_is_resetting(OBJECT(dev)); } =20 +bool device_test_reset_type(DeviceState *dev, ResetType type) +{ + ResetType cur_type =3D resettable_get_type(OBJECT(dev)); + return (cur_type & type); +} + static ResetState *device_get_reset_state(Object *obj) { DeviceState *dev =3D DEVICE(obj); diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 2976121fbc..eb11f0f801 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -422,18 +422,52 @@ void device_cold_reset(DeviceState *dev); */ void bus_cold_reset(BusState *bus); =20 +/** + * device_warm_reset: + * Trigger a warm reset of the device @dev. + * + * Use the Resettable interface (see hw/interface.h); it also reset the + * device's qdev/qbus subtree. + */ +void device_warm_reset(DeviceState *dev); + +/** + * bus_warm_reset: + * Trigger a warm reset of the bus @bus. + * + * Use the Resettable interface (see hw/interface.h); it also reset the + * bus's qdev/qbus subtree. + */ +void bus_warm_reset(BusState *bus); + /** * device_is_resetting: * Return true if the device @dev is currently being reset. */ bool device_is_resetting(DeviceState *dev); =20 +/** + * device_test_reset_type: + * Return true if the device @dev is currently under reset type + * @type. + * Only valid if device_is_resetting() is true + */ +bool device_test_reset_type(DeviceState *dev, ResetType type); + /** * bus_is_resetting: * Return true if the bus @bus is currently being reset. */ bool bus_is_resetting(BusState *bus); =20 +/** + * bus_test_reset_type: + * Return true if the bus @bus is currently under reset type + * @type. + * Only valid if device_is_resetting() is true + */ +bool bus_test_reset_type(BusState *bus, ResetType type); + /* This should go away once we get rid of the NULL bus hack */ BusState *sysbus_get_default(void); =20 --=20 2.22.0 From nobody Mon Apr 29 09:11:19 2024 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 1566406621225943.1298014583306; Wed, 21 Aug 2019 09:57:01 -0700 (PDT) Received: from localhost ([::1]:50622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0Tut-00049b-Px for importer@patchew.org; Wed, 21 Aug 2019 12:56:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59714) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0Ta8-0007tg-5g for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0Ta6-0006Cd-PU for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:32 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:36506) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i0Ta6-0006Bt-Fl for qemu-devel@nongnu.org; Wed, 21 Aug 2019 12:35:30 -0400 Received: from kouign-amann.bar.greensocs.com (unknown [172.16.11.117]) by beetle.greensocs.com (Postfix) with ESMTPS id 37FC296F56; Wed, 21 Aug 2019 16:35:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1566405329; 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=0BR3eridDeouQ+ZfE9j4HBjTSNzRxIpuXQwC0lZSXRw=; b=2hh4BAez+k2D75Mso0k7eea36N1cRG5Vw0XGPBO+50R4TDtQskzOXCnnrea3c4swsdard+ 6RNuD7BKc1cKf7QpFL49CM2H6lL0QzhUB43a82fI0DX19hzDm++cxl6XWAGSPmbEnr9N/4 EHxtvwT67qyvOb4nmo9w9TGtPiWbnL4= From: Damien Hedde To: qemu-devel@nongnu.org Date: Wed, 21 Aug 2019 18:33:41 +0200 Message-Id: <20190821163341.16309-11-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190821163341.16309-1-damien.hedde@greensocs.com> References: <20190821163341.16309-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=1566405329; 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=0BR3eridDeouQ+ZfE9j4HBjTSNzRxIpuXQwC0lZSXRw=; b=C6cas6EmaSKbb/7RvHLBDI+LBytvNe17O7DS2ja5KD+tjb+L0qrF4Mf/qnoyBRmWSLXYtN xxwYEZiNDw7NeBRqSf1uyrN6GidMbDnzEJzQ4dl5Y1tmzRJVBkREZwPQ/uvSY+8xcmMhuH ViDinnU+kKmcyFyCsI+fxnlsZpBswA8= ARC-Seal: i=1; s=mail; d=greensocs.com; t=1566405329; a=rsa-sha256; cv=none; b=auUOw8C4R+1wmvrmoFFW3MpmAuPceMMtoj5n3r2Qf9nYuf3cnzNeyvjiyU/0leAteZIA/C OF2gp3K7rNZVSshUIs8RSdDVQqDJVG13wdlwnYumr3Uqi7N3SwzPly5b63DoAKjD+83NYo oeuPxqVrcm2El/9mNQJ3HUuib5tLMog= ARC-Authentication-Results: i=1; beetle.greensocs.com; none 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 v4 10/10] docs/devel/reset.txt: add documentation about warm reset 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: Damien Hedde , peter.maydell@linaro.org, edgar.iglesias@xilinx.com, berrange@redhat.com, ehabkost@redhat.com, mark.burton@greensocs.com, pbonzini@redhat.com, philmd@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (identity @greensocs.com: invalid key for signature: Missing mandatory tag: p) Content-Type: text/plain; charset="utf-8" Complete the documentation with the handling of several reset types (cold and warm). Signed-off-by: Damien Hedde --- docs/devel/reset.txt | 55 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/docs/devel/reset.txt b/docs/devel/reset.txt index 77ff29b3d7..ed1a72566d 100644 --- a/docs/devel/reset.txt +++ b/docs/devel/reset.txt @@ -31,16 +31,21 @@ makes no difference. But there can be some; some config= uration may be kept when applying a warm reset for example. =20 The Resettable interface handles reset kinds with an enum. For now only co= ld -reset is defined, others may be added later. +and warm reset are defined, others may be added later. ``` typedef enum ResetType { RESET_TYPE_COLD, + RESET_TYPE_WARM, } ResetType; ``` =20 In qemu, RESET_TYPE_COLD means we reset to the initial state corresponding= to the start of qemu; this might differs from what is a read hardware cold re= set. =20 +Although the interface can handle several kind of resets, these are not to= tally +independant and disjoint. There are some constraints; these are explained = below +in the "multi-phase" section. + =20 Triggering reset ---------------- @@ -49,21 +54,41 @@ This section documents the APIs which "users" of a rese= ttable object should use to control it. All resettable control functions must be called while holdi= ng the iothread lock. =20 -You can trigger a reset event on a resettable object with resettable_reset= (). -The object will be instantly reset. +A resettable object can be put into its "in reset" state and held there +indefinitely. + +You must call resettable_assert_reset() to put an object in reset. It will= stay +in this state until you eventually call resettable_deassert_reset(). Care = must +be taken to call resettable_deassert_reset() once and only once per call of +resettable_assert_reset(). + +```resettable_assert_reset(Object *obj, ResetType type);``` +The parameter "obj" is an object implementing the Resettable interface. +The parameter "type" gives the type of reset you want to trigger. + +```resettable_deassert_reset(Object *obj);``` +The parameter "obj" is an object implementing the Resettable interface. + +If you want to just trigger a reset event but not leave the object in rese= t for +any period of time, you can use resettable_reset(), which is a convenience +function identical in behaviour to calling resettable_assert() and then +immediately calling resettable_deassert(). =20 ```void resettable_reset(Object *obj, ResetType type);``` The parameter "obj" is an object implementing the Resettable interface. The parameter "type" gives the type of reset you want to trigger. =20 It is possible to interleave multiple calls to + - resettable_assert_reset(), + - resettable_deassert_reset(), - resettable_reset(). =20 There may be several reset sources/controllers of a given object. The inte= rface handles everything and the different reset controllers do not need to know anything about each others. The object will leave reset state only when ea= ch other controllers end their reset operation. This point is handled by -maintaining a count of reset. +maintaining a count of reset; this is why resettable_deassert_reset() must= be +called once and only once per resettable_assert_reset(). =20 Note that it is a programming error to call a resettable function on a non-Resettable object and it will trigger a run time assert error. Since m= ost @@ -74,6 +99,8 @@ For Devices and Buses, the following helper functions exi= sts: ``` void device_cold_reset(Device *dev); void bus_cold_reset(Bus *bus); +void device_warm_reset(Device *dev); +void bus_warm_reset(Bus *bus); ``` =20 These are simple wrappers around resettable_reset() function; they only ca= st the @@ -123,6 +150,25 @@ The exit phase is executed only when the last reset op= eration ends. Therefore the object has not to care how many reset controllers it has and how many = of them have started a reset. =20 +An exception to that is when entering a new reset type AND if there was no +previous cold reset; in that case, init and hold methods are executed again +because the different reset type may reset more things than the previous o= ne +has done. + +For example if some controller has started a RESET_TYPE_WARM with +resettable_assert_reset() on a device and another controller does a +device_cold_reset() on the same object, then the init phase is executed wi= th +RESET_TYPE_COLD as an argument and then the hold phase. +If the first reset was a cold reset, then the warm reset would have trigge= red +nothing because the cold reset is "stronger". + +Note also that the exit phase will never be executed twice; it will only be +executed when all reset operation are closed, independently of the number = of +reset types that were issued. This is a limitation of the interface, there= is +only a global count of reset (not a count per reset type). The consequence= is +that the different reset types must be close enough in behavior to not req= uire +different exit phases. + =20 Handling reset in a new resettable object ----------------------------------------- @@ -203,6 +249,7 @@ interface. typedef struct ResetState { uint32_t count; bool hold_phase_needed; + ResetType type; } ResetState; =20 typedef ResetState *(*ResettableGetState)(Object *obj); --=20 2.22.0