From nobody Mon Feb 9 18:45:09 2026 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 155351215568989.81647757666803; Mon, 25 Mar 2019 04:09:15 -0700 (PDT) Received: from localhost ([127.0.0.1]:40571 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h8NTe-0001fE-E6 for importer@patchew.org; Mon, 25 Mar 2019 07:09:14 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58674) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h8NNH-0005De-Ts for qemu-devel@nongnu.org; Mon, 25 Mar 2019 07:02:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h8NNC-0007rw-8R for qemu-devel@nongnu.org; Mon, 25 Mar 2019 07:02:39 -0400 Received: from greensocs.com ([193.104.36.180]:38247) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h8NN7-0007kW-Lj; Mon, 25 Mar 2019 07:02:30 -0400 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 235427D78AE; Mon, 25 Mar 2019 12:02:22 +0100 (CET) Received: from greensocs.com ([127.0.0.1]) by localhost (gs-01.greensocs.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rDy1deads57w; Mon, 25 Mar 2019 12:02:21 +0100 (CET) Received: by greensocs.com (Postfix, from userid 998) id 089097D78A0; Mon, 25 Mar 2019 12:02:20 +0100 (CET) Received: from kouign-amann.bar.greensocs.com (antfield.tima.u-ga.fr [147.171.129.253]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: damien.hedde@greensocs.com) by greensocs.com (Postfix) with ESMTPSA id 641E57D788E; Mon, 25 Mar 2019 12:02:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1553511742; bh=fim3p4zmaf3aFDPE3gcaY2aoXqpm/15izlSUkLSkHAQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1E9Jsi+1+PYA0IsIz4dITUBE0AkjYVXKmDH/yUdePOy96F/o0ZZwbrOCQbTx/e6rW v0MBGZFRA0I5tX7UuXcTpOtSqmHC7Kqul9tT+859hTKN23DbueBJV6QN+R0mCzII2+ qTrh0xQdmuIs3JCW3sbeZ2gmIqO62hyN6X+DZnVQ= X-Virus-Scanned: amavisd-new at greensocs.com Authentication-Results: gs-01.greensocs.com (amavisd-new); dkim=pass (1024-bit key) header.d=greensocs.com header.b=7em/qB7v; dkim=pass (1024-bit key) header.d=greensocs.com header.b=kOO+0ut1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1553511741; bh=fim3p4zmaf3aFDPE3gcaY2aoXqpm/15izlSUkLSkHAQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=7em/qB7v5iU6nlx8AL2232qhb76gPZ+1KmPjxNlXigSXke2TCMbXlvRpaxIq5YQg+ 9tya1o0AbSJWFcYmt4bXluvjjFpcNEtvvVNBYBIdaaia7I8j2JJccqlykLMTBsvQuG kk9Lh8r0PfpErsVVxUn8ClEEt0ElyPJuDEEhr09E= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1553511740; bh=fim3p4zmaf3aFDPE3gcaY2aoXqpm/15izlSUkLSkHAQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kOO+0ut1cFqycEDJ6vqpimJmGfOG3IYNfzvxVd/Q/82GrLI2Jy+fEzLgt77O8h5Qw nLyhAwhgffBFLMCoatU1s7OwjZP7X2+VaaDsYufpk/o7tEuqBqxyaUnW5iBwltni+t 2cr4y7TbAhNJ4s+mTdAyd150N1Kr40h53OIXZv2U= From: Damien Hedde To: qemu-devel@nongnu.org Date: Mon, 25 Mar 2019 12:01:44 +0100 Message-Id: <19e6624397deb68db77526a8d25be42aafb3373e.1553510737.git.damien.hedde@greensocs.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 193.104.36.180 Subject: [Qemu-devel] [RFC PATCH 01/17] Create Resettable QOM interface X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: edgar.iglesias@xilinx.com, peter.maydell@linaro.org, mark.burton@greensocs.com, Damien Hedde , qemu-arm@nongnu.org, alistair.francis@wdc.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, philmd@redhat.com, luc.michel@greensocs.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (found 3 invalid signatures) Content-Type: text/plain; charset="utf-8" This commit defines an interface allowing multi-phase reset. The phases are INIT, HOLD and EXIT. The reset of a Resettable is controlled with 2 functions: - resettable_assert_reset which starts the reset operation. - resettable_deassert_reset which ends the reset operation. There is also a `resettable_reset` helper function which does assert then deassert allowing to do a proper reset in one call. The interface only contains 3 methods, one per phase. Each method should handle reset of the object and its sub-elements. Signed-off-by: Damien Hedde --- hw/core/Makefile.objs | 1 + hw/core/resettable.c | 69 ++++++++++++++++++++++++++++++++++ include/hw/resettable.h | 83 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 hw/core/resettable.c create mode 100644 include/hw/resettable.h diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs index a799c83815..97007454a8 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..6ea1e5b54a --- /dev/null +++ b/hw/core/resettable.c @@ -0,0 +1,69 @@ +/* + * 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" + +#define RESETTABLE_GET_CLASS(obj) \ + OBJECT_GET_CLASS(ResettableClass, (obj), TYPE_RESETTABLE) + +void resettable_init_phase(Object *obj, bool cold) +{ + ResettableClass *rc =3D RESETTABLE_GET_CLASS(obj); + + if (rc->phases.init) { + rc->phases.init(obj, cold); + } +} + +void resettable_hold_phase(Object *obj) +{ + ResettableClass *rc =3D RESETTABLE_GET_CLASS(obj); + + if (rc->phases.hold) { + rc->phases.hold(obj); + } +} + +void resettable_exit_phase(Object *obj) +{ + ResettableClass *rc =3D RESETTABLE_GET_CLASS(obj); + + if (rc->phases.exit) { + rc->phases.exit(obj); + } +} + +void resettable_assert_reset(Object *obj, bool cold) +{ + resettable_init_phase(obj, cold); + resettable_hold_phase(obj); +} + +void resettable_deassert_reset(Object *obj) +{ + resettable_exit_phase(obj); +} + +static const TypeInfo resettable_interface_info =3D { + .name =3D TYPE_RESETTABLE, + .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/include/hw/resettable.h b/include/hw/resettable.h new file mode 100644 index 0000000000..15d5bd878d --- /dev/null +++ b/include/hw/resettable.h @@ -0,0 +1,83 @@ +#ifndef HW_RESETTABLE_H +#define HW_RESETTABLE_H + +#include "qom/object.h" + +#define TYPE_RESETTABLE "resettable" + +#define RESETTABLE_CLASS(class) \ + OBJECT_CLASS_CHECK(ResettableClass, (class), TYPE_RESETTABLE) + +/* + * ResettableClass: + * Interface for resettable objects. + * + * The reset operation is divided in several phases each represented by a + * method. + * + * @phases.init: should reset local state only. Takes a bool @cold argument + * specifying whether the reset is cold or warm. It must not do side-effect + * on others objects. + * + * @phases.hold: side-effects action on others objects due to staying in a + * resetting state. + * + * @phases.exit: leave the reset state, may do side-effects action on othe= rs + * objects. + * + * "Entering the reset state" corresponds to the init and hold phases. + * "Leaving the reset state" corresponds to the exit phase. + */ +typedef void (*ResettableInitPhase)(Object *obj, bool cold); +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; +typedef struct ResettablePhases ResettablePhases; + +/* + * Helpers to do a single phase of a Resettable. + * Call the corresponding ResettableClass method if it is not NULL. + */ +void resettable_init_phase(Object *obj, bool cold); +void resettable_hold_phase(Object *obj); +void resettable_exit_phase(Object *obj); + +/** + * resettable_assert_reset: + * Put an object in reset state. + * Each time resettable_assert_reset is called, resettable_deassert_reset + * must be eventually called once and only once. + * + * @obj object to reset, must implement Resettable interface. + * @cold boolean indicating the type of reset (cold or warm) + */ +void resettable_assert_reset(Object *obj, bool cold); + +/** + * resettable_deassert_reset: + * End the reset state if an object. + * + * @obj object to reset, must implement Resettable interface. + */ +void resettable_deassert_reset(Object *obj); + +/** + * resettable_reset: + * Calling this function is equivalent to call @assert_reset then + * @deassert_reset. + */ +static inline void resettable_reset(Object *obj, bool cold) +{ + resettable_assert_reset(obj, cold); + resettable_deassert_reset(obj); +} + +#endif --=20 2.21.0