From nobody Wed Nov 5 20:19:49 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 1537174090257147.93388912477212; Mon, 17 Sep 2018 01:48:10 -0700 (PDT) Received: from localhost ([::1]:34458 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1pCT-0002IV-28 for importer@patchew.org; Mon, 17 Sep 2018 04:48:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46509) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1p5y-0006Az-7Y for qemu-devel@nongnu.org; Mon, 17 Sep 2018 04:41:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g1p5w-0005dP-MX for qemu-devel@nongnu.org; Mon, 17 Sep 2018 04:41:26 -0400 Received: from greensocs.com ([193.104.36.180]:51747) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1p5q-0005VO-4u; Mon, 17 Sep 2018 04:41:18 -0400 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id A4503443493; Mon, 17 Sep 2018 10:41:11 +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 OZoln28FHWLZ; Mon, 17 Sep 2018 10:41:10 +0200 (CEST) Received: by greensocs.com (Postfix, from userid 998) id A6006443483; Mon, 17 Sep 2018 10:41:10 +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 2927023878C; Mon, 17 Sep 2018 10:41:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1537173671; bh=33jTLJUAXeCS/V1HY/PDWUYfbAkkSfTM6JFFP2a3zxo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=2Mhim9PThv2C9ns/F7tLC6fsxyqHH0XH3jm3TccQUZEJRipLk/H4XRSVlUy+08zgp 7Lz45cghsjOkwNWEUL3YPCr5MzWzJnGM8Np2Pnu4elCZ6MlfM8+nDW6TzaBYOK8fa5 vX+WUwFUzxC5e1cUro6m1KZTCYxZfHfE/Y5ezpsk= 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=OYvuZG2m; dkim=pass (1024-bit key) header.d=greensocs.com header.b=OYvuZG2m DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1537173670; bh=33jTLJUAXeCS/V1HY/PDWUYfbAkkSfTM6JFFP2a3zxo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OYvuZG2mLKUZdcpiI37yR85PwHMXB0UuUEj7FoJ6Uh2j9ErGeSbmiSr4B/v/rafOC Zy9TnsQjbVx4lJMGpc+YXvF485qZjdQjR4hM7/qZfjmJ/SQ6O42kJVChoM0wvEoD3A espkiMCtYaKiiYPyFMMj/qZ7Z92iItsermcYBM+Y= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1537173670; bh=33jTLJUAXeCS/V1HY/PDWUYfbAkkSfTM6JFFP2a3zxo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OYvuZG2mLKUZdcpiI37yR85PwHMXB0UuUEj7FoJ6Uh2j9ErGeSbmiSr4B/v/rafOC Zy9TnsQjbVx4lJMGpc+YXvF485qZjdQjR4hM7/qZfjmJ/SQ6O42kJVChoM0wvEoD3A espkiMCtYaKiiYPyFMMj/qZ7Z92iItsermcYBM+Y= From: damien.hedde@greensocs.com To: qemu-devel@nongnu.org Date: Mon, 17 Sep 2018 10:40:12 +0200 Message-Id: <20180917084016.12750-7-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180917084016.12750-1-damien.hedde@greensocs.com> References: <20180917084016.12750-1-damien.hedde@greensocs.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 193.104.36.180 Subject: [Qemu-devel] [PATCH v4 06/10] sysbus: add bus_interface_clock feature to sysbus devices 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, fred.konrad@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" From: Damien Hedde Add an optional bus interface clock to sysbus devices. This clock can be added by the subclasses if required using the sysbus_init_bus_interface_clock function given the target name of the clock. The default behavior of the clock is to enable or disable the mmios in function of the clock status (mmios are enabled iff the clock is running and the reset not asserted). This behavior may be changed by overriding the clock callback using sysbus_get_bus_interface_clock and clock_set_callback functions. Signed-off-by: Damien Hedde --- include/hw/sysbus.h | 22 ++++++++++++++++++++++ hw/core/sysbus.c | 25 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/include/hw/sysbus.h b/include/hw/sysbus.h index 0b59a3b8d6..abbeece601 100644 --- a/include/hw/sysbus.h +++ b/include/hw/sysbus.h @@ -73,6 +73,7 @@ struct SysBusDevice { } mmio[QDEV_MAX_MMIO]; int num_pio; uint32_t pio[QDEV_MAX_PIO]; + ClockIn *bus_itf_clk; }; =20 typedef void FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque); @@ -135,4 +136,25 @@ static inline DeviceState *sysbus_try_create_simple(co= nst char *name, return sysbus_try_create_varargs(name, addr, irq, NULL); } =20 +/** + * sysbus_init_bus_interface_clock: + * @dev: the sysbus device + * @name: the name of the clock + * + * Add the bus interface clock to the device. Mmios will be enabled/disabl= ed + * according to the clock status. Must not be called more than once on the= same + * device. + * + * Note: if this clock remains unconnected, the sysbus device will work as= if + * the clock was absent (no side-effect). + */ +void sysbus_init_bus_interface_clock(SysBusDevice *dev, const char *name); + +/** + * sysbus_init_get_interface_clock: + * @dev: the sysbus device + * @retuns: the clock previously added by sysbus_init_bus_interface_clock. + */ +ClockIn *sysbus_get_bus_interface_clock(SysBusDevice *dev); + #endif /* HW_SYSBUS_H */ diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c index 7ac36ad3e7..8d225263fa 100644 --- a/hw/core/sysbus.c +++ b/hw/core/sysbus.c @@ -324,6 +324,31 @@ MemoryRegion *sysbus_address_space(SysBusDevice *dev) return get_system_memory(); } =20 +static void sysbus_device_clock_callback(void *opaque, ClockState *clk) +{ + SysBusDevice *dev =3D opaque; + bool enable =3D clock_state_is_domain_running(clk); + int i; + + /* set/clear mmio visible flag on clock change */ + for (i =3D 0; i < dev->num_mmio && i < QDEV_MAX_MMIO; i++) { + MemoryRegion *mr =3D sysbus_mmio_get_region(dev, i); + memory_region_set_enabled(mr, enable); + } +} + +void sysbus_init_bus_interface_clock(SysBusDevice *dev, const char *name) +{ + assert(dev->bus_itf_clk =3D=3D NULL); + dev->bus_itf_clk =3D qdev_init_clock_in(DEVICE(dev), name, + sysbus_device_clock_callback, dev); +} + +ClockIn *sysbus_get_bus_interface_clock(SysBusDevice *dev) +{ + return dev->bus_itf_clk; +} + static void sysbus_device_class_init(ObjectClass *klass, void *data) { DeviceClass *k =3D DEVICE_CLASS(klass); --=20 2.18.0