From patchwork Mon Sep 17 08:40:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Hedde X-Patchwork-Id: 10602229 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 813F917E1 for ; Mon, 17 Sep 2018 08:47:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7201A29647 for ; Mon, 17 Sep 2018 08:47:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 661622965F; Mon, 17 Sep 2018 08:47:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EB80D29651 for ; Mon, 17 Sep 2018 08:47:38 +0000 (UTC) Received: from localhost ([::1]:34458 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1pBx-0002IV-UU for patchwork-qemu-devel@patchwork.kernel.org; Mon, 17 Sep 2018 04:47:37 -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) 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 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) 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= 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=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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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; }; typedef void FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque); @@ -135,4 +136,25 @@ static inline DeviceState *sysbus_try_create_simple(const char *name, return sysbus_try_create_varargs(name, addr, irq, NULL); } +/** + * 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/disabled + * 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(); } +static void sysbus_device_clock_callback(void *opaque, ClockState *clk) +{ + SysBusDevice *dev = opaque; + bool enable = clock_state_is_domain_running(clk); + int i; + + /* set/clear mmio visible flag on clock change */ + for (i = 0; i < dev->num_mmio && i < QDEV_MAX_MMIO; i++) { + MemoryRegion *mr = 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 == NULL); + dev->bus_itf_clk = 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 = DEVICE_CLASS(klass);