From nobody Wed Nov 5 05:17:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532702571017608.2316584686127; Fri, 27 Jul 2018 07:42:51 -0700 (PDT) Received: from localhost ([::1]:41620 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fj3xB-0006qK-W8 for importer@patchew.org; Fri, 27 Jul 2018 10:42:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34372) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fj3sH-0003FE-SQ for qemu-devel@nongnu.org; Fri, 27 Jul 2018 10:37:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fj3sG-0008Ib-IY for qemu-devel@nongnu.org; Fri, 27 Jul 2018 10:37:45 -0400 Received: from greensocs.com ([193.104.36.180]:50605) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fj3sB-0008Ac-FY; Fri, 27 Jul 2018 10:37:39 -0400 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id D5D2642899A; Fri, 27 Jul 2018 16:37:30 +0200 (CEST) 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 KgjokB7tLjZZ; Fri, 27 Jul 2018 16:37:30 +0200 (CEST) Received: by greensocs.com (Postfix, from userid 998) id ECCE9443482; Fri, 27 Jul 2018 16:37:29 +0200 (CEST) Received: from kouign-amann.hive.antfield.fr (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 8C1D3400DC8; Fri, 27 Jul 2018 16:37:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1532702250; bh=TBvJXPPgCFdfbLN9eDsNvJN9V0c/E9DoiD6BK2AxeaA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=oDk74velvNhby1mpSLcDpIMB+YUEtflCOlVW/a1yguBNsoSjzep3YaBLOrvsrdhMr A2XnwqVRmexaOAEaMNSNSDfvtNuTTrTWhtlnDo1NleEKoE3p+lw/twv2Hnquuhz2SJ gPTRrIAgGyi1yveHv35LgxEAAOTygZKsWH1MZtes= 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=U8Jd9xDc; dkim=pass (1024-bit key) header.d=greensocs.com header.b=U8Jd9xDc DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1532702249; bh=TBvJXPPgCFdfbLN9eDsNvJN9V0c/E9DoiD6BK2AxeaA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=U8Jd9xDcAKoH2UmbN7e+dfA/4zBqKdoNHPGwVuSRiCiK05JVZz4Lr4plmU7ladfRe 06ccZ0Gn/USTy2Yg3Ar5/e6DabZNrNDTKcJBt/n8ic8vpJnUYeFzwZ9eNe7jxeWyrw t7aBbT2LukrH+8VrnltWApsWDcW3nU0F+YGmTkec= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1532702249; bh=TBvJXPPgCFdfbLN9eDsNvJN9V0c/E9DoiD6BK2AxeaA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=U8Jd9xDcAKoH2UmbN7e+dfA/4zBqKdoNHPGwVuSRiCiK05JVZz4Lr4plmU7ladfRe 06ccZ0Gn/USTy2Yg3Ar5/e6DabZNrNDTKcJBt/n8ic8vpJnUYeFzwZ9eNe7jxeWyrw t7aBbT2LukrH+8VrnltWApsWDcW3nU0F+YGmTkec= From: Damien Hedde To: qemu-devel@nongnu.org Date: Fri, 27 Jul 2018 16:37:20 +0200 Message-Id: <0379e54aecc5534d68e1ac3bdf61fda79916396e.1532701430.git.damien.hedde@greensocs.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 193.104.36.180 Subject: [Qemu-devel] [RFC PATCH 1/6] qdev: add a power and clock gating support 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, alistair@alistair23.me, mark.burton@greensocs.com, saipava@xilinx.com, qemu-arm@nongnu.org, Damien Hedde , pbonzini@redhat.com, luc.michel@greensocs.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (found 2 invalid signatures) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add two boolean new fields _powered_ and _clocked_ to hold the gating state. Also add methods to act on each gating change. The power/clock gating is controlled by 2 functions *device_set_power* and *device_set_clock*. Add a default behavior to do a device_reset at power-up. Signed-off-by: Damien Hedde --- include/hw/qdev-core.h | 30 ++++++++++++++++++++++++ hw/core/qdev.c | 52 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index f1fd0f8736..659287e185 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -34,6 +34,7 @@ typedef void (*DeviceUnrealize)(DeviceState *dev, Error *= *errp); typedef void (*DeviceReset)(DeviceState *dev); typedef void (*BusRealize)(BusState *bus, Error **errp); typedef void (*BusUnrealize)(BusState *bus, Error **errp); +typedef void (*DeviceGatingUpdate)(DeviceState *dev); =20 struct VMStateDescription; =20 @@ -109,6 +110,8 @@ typedef struct DeviceClass { DeviceReset reset; DeviceRealize realize; DeviceUnrealize unrealize; + DeviceGatingUpdate power_update; + DeviceGatingUpdate clock_update; =20 /* device state */ const struct VMStateDescription *vmsd; @@ -151,6 +154,9 @@ struct DeviceState { int num_child_bus; int instance_id_alias; int alias_required_for_version; + + bool powered; + bool clocked; }; =20 struct DeviceListener { @@ -404,6 +410,12 @@ void device_class_set_parent_realize(DeviceClass *dc, void device_class_set_parent_unrealize(DeviceClass *dc, DeviceUnrealize dev_unrealize, DeviceUnrealize *parent_unrealize); +void device_class_set_parent_power_update(DeviceClass *dc, + DeviceGatingUpdate dev_power_upd= ate, + DeviceGatingUpdate *parent_power= _update); +void device_class_set_parent_clock_update(DeviceClass *dc, + DeviceGatingUpdate dev_clock_upd= ate, + DeviceGatingUpdate *parent_clock= _update); =20 const struct VMStateDescription *qdev_get_vmsd(DeviceState *dev); =20 @@ -434,4 +446,22 @@ static inline bool qbus_is_hotpluggable(BusState *bus) void device_listener_register(DeviceListener *listener); void device_listener_unregister(DeviceListener *listener); =20 +/** + * device_set_power: + * Enable/Disable the power of a device + * + * @dev: device to update + * @en: true to enable, false to disable + */ +void device_set_power(DeviceState *dev, bool en); + +/** + * device_set_clock: + * Enable/Disable the clock of a device + * + * @dev: device to update + * @en: true to enable, false to disable + */ +void device_set_clock(DeviceState *dev, bool en); + #endif diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 529b82de18..bb6d36eab9 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -950,6 +950,8 @@ static void device_initfn(Object *obj) =20 dev->instance_id_alias =3D -1; dev->realized =3D false; + dev->powered =3D true; + dev->clocked =3D true; =20 object_property_add_bool(obj, "realized", device_get_realized, device_set_realized, NUL= L); @@ -1038,6 +1040,13 @@ static void device_unparent(Object *obj) } } =20 +static void device_power_update(DeviceState *dev) +{ + if (dev->powered) { + device_reset(dev); + } +} + static void device_class_init(ObjectClass *class, void *data) { DeviceClass *dc =3D DEVICE_CLASS(class); @@ -1052,6 +1061,8 @@ static void device_class_init(ObjectClass *class, voi= d *data) */ dc->hotpluggable =3D true; dc->user_creatable =3D true; + + dc->power_update =3D device_power_update; } =20 void device_class_set_parent_reset(DeviceClass *dc, @@ -1078,6 +1089,22 @@ void device_class_set_parent_unrealize(DeviceClass *= dc, dc->unrealize =3D dev_unrealize; } =20 +void device_class_set_parent_power_update(DeviceClass *dc, + DeviceGatingUpdate dev_power_update, + DeviceGatingUpdate *parent_power_up= date) +{ + *parent_power_update =3D dc->power_update; + dc->power_update =3D dev_power_update; +} + +void device_class_set_parent_clock_update(DeviceClass *dc, + DeviceGatingUpdate dev_clock_update, + DeviceGatingUpdate *parent_clock_up= date) +{ + *parent_clock_update =3D dc->clock_update; + dc->clock_update =3D dev_clock_update; +} + void device_reset(DeviceState *dev) { DeviceClass *klass =3D DEVICE_GET_CLASS(dev); @@ -1087,6 +1114,31 @@ void device_reset(DeviceState *dev) } } =20 +void device_set_power(DeviceState *dev, bool en) +{ + DeviceClass *klass =3D DEVICE_GET_CLASS(dev); + + if (en !=3D dev->powered) { + dev->powered =3D en; + if (klass->power_update) { + klass->power_update(dev); + } + } +} + +void device_set_clock(DeviceState *dev, bool en) +{ + DeviceClass *klass =3D DEVICE_GET_CLASS(dev); + + if (en !=3D dev->clocked) { + dev->clocked =3D en; + if (klass->clock_update) { + klass->clock_update(dev); + } + } +} + + Object *qdev_get_machine(void) { static Object *dev; --=20 2.18.0