From patchwork Thu Jan 26 09:47:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?S09OUkFEIEZyw6lkw6lyaWM=?= X-Patchwork-Id: 9538711 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E82BA604A9 for ; Thu, 26 Jan 2017 09:48:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBB762811E for ; Thu, 26 Jan 2017 09:48:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D013F281C3; Thu, 26 Jan 2017 09:48:40 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, 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 7AE3C2811E for ; Thu, 26 Jan 2017 09:48:40 +0000 (UTC) Received: from localhost ([::1]:37102 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cWgfX-0005Cn-IB for patchwork-qemu-devel@patchwork.kernel.org; Thu, 26 Jan 2017 04:48:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39097) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cWges-00053y-UC for qemu-devel@nongnu.org; Thu, 26 Jan 2017 04:47:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cWgep-0000my-6l for qemu-devel@nongnu.org; Thu, 26 Jan 2017 04:47:59 -0500 Received: from greensocs.com ([193.104.36.180]:33071) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cWgeo-0000mj-Pd for qemu-devel@nongnu.org; Thu, 26 Jan 2017 04:47:55 -0500 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 0FD94389843; Thu, 26 Jan 2017 10:47:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1485424074; bh=0BXQmGf/n1LduLtQI4E/BSZFiGYTFPimU333+2yUp0M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MJYzCMSimWakMbkFds0MBV//mhYVdSCmKpzZjn0esHQUZQqokPbib725BE1Xdq3qg WRHBqBwwWURvwuzzmP2RKr1cm03HfGaL9J7575LvLuzzzkrmTBZ4rKDSMt0gbZ4QXw 5G44pJj5WhT+TIaHv7jIwNgmA2iCmIA2tFvK63i0= 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=De9WA0ch; dkim=pass (1024-bit key) header.d=greensocs.com header.b=bB/uBYE0 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 MYmbIHi1_dv5; Thu, 26 Jan 2017 10:47:52 +0100 (CET) Received: by greensocs.com (Postfix, from userid 998) id 2AB91389857; Thu, 26 Jan 2017 10:47:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1485424072; bh=0BXQmGf/n1LduLtQI4E/BSZFiGYTFPimU333+2yUp0M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=De9WA0chXa/9M4QrPzVBmyEXKLb6owYuvk7kiZQn1orZX1ait5CspOGQskRsItBSp JQMv5gvsB4jdfgz6VsDPjzR2QuNYVNEeIQ6BMA6rBh+J1NhzkgAdKbCOmSwLAgsVDN GI5/mELx2bzRBglsdY5pc5/iHWPMorjRo5iL3Hi0= Received: from corsair.home (bd231-7-88-127-3-24.fbx.proxad.net [88.127.3.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: fred.konrad@greensocs.com) by greensocs.com (Postfix) with ESMTPSA id 77951389843; Thu, 26 Jan 2017 10:47:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1485424071; bh=0BXQmGf/n1LduLtQI4E/BSZFiGYTFPimU333+2yUp0M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bB/uBYE0IeI7lyo8gJBwOgN0W7fJmCp30YAEd7HGSERz47UVCZRbcozHzAHDqUTUM bSbjZdxf7SSYNst8B9x1Uiu3XcyJIEraOMOEaJMAGBeCcg1Xl7nxZm2TnV+ECMLdUF tm5dAJb1kfHZz2WdztCJncqLibyQeGeHEds8jR18= From: fred.konrad@greensocs.com To: qemu-devel@nongnu.org Date: Thu, 26 Jan 2017 10:47:34 +0100 Message-Id: <1485424060-12217-5-git-send-email-fred.konrad@greensocs.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1485424060-12217-1-git-send-email-fred.konrad@greensocs.com> References: <1485424060-12217-1-git-send-email-fred.konrad@greensocs.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 193.104.36.180 Subject: [Qemu-devel] [PATCH V2 04/10] qemu-clk: introduce an init array to help the device construction 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, fred.konrad@greensocs.com, mark.burton@greensocs.com, alistair.francis@xilinx.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: KONRAD Frederic This introduces a clock init array to ease the clock tree construction. Signed-off-by: KONRAD Frederic --- include/qemu/qemu-clock.h | 23 +++++++++++++++++++++++ qemu-clock.c | 17 +++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/qemu/qemu-clock.h b/include/qemu/qemu-clock.h index 6d30299..45f8766 100644 --- a/include/qemu/qemu-clock.h +++ b/include/qemu/qemu-clock.h @@ -49,6 +49,29 @@ struct ClkList { QLIST_ENTRY(ClkList) node; }; +typedef struct ClockInitElement { + const char *name; /* Name to give to the clock. */ + size_t offset; /* Offset of the qemu_clk field in the object. */ + QEMUClkRateUpdateCallback *cb; +} ClockInitElement; + +#define DEVICE_CLOCK(_state, _field, _cb) { \ + .name = #_field, \ + .offset = offsetof(_state, _field), \ + .cb = _cb \ +} + +#define DEVICE_CLOCK_END() { \ + .name = NULL \ +} + +/** + * qemu_clk_init_device: + * @obj: the Object which need to be initialized. + * @array: the array of ClockInitElement to be used. + */ +void qemu_clk_init_device(Object *obj, ClockInitElement *array); + /** * qemu_clk_device_add_clock: * @dev: the device on which the clock needs to be added. diff --git a/qemu-clock.c b/qemu-clock.c index 8c12368..300e38f 100644 --- a/qemu-clock.c +++ b/qemu-clock.c @@ -26,6 +26,7 @@ #include "hw/hw.h" #include "qemu/log.h" #include "qapi/error.h" +#include "hw/qdev-core.h" #ifndef DEBUG_QEMU_CLOCK #define DEBUG_QEMU_CLOCK 0 @@ -37,6 +38,22 @@ } \ } while (0); +void qemu_clk_init_device(Object *obj, ClockInitElement *array) +{ + qemu_clk *cur = NULL; + + while (array->name != NULL) { + DPRINTF("init clock named %s\n", array->name); + cur = (((void *)obj) + array->offset); + *cur = QEMU_CLOCK(object_new(TYPE_CLOCK)); + qemu_clk_device_add_clock(DEVICE(obj), *cur, array->name); + if (array->cb) { + qemu_clk_set_callback(*cur, array->cb, obj); + } + array++; + } +} + void qemu_clk_refresh(qemu_clk clk) { qemu_clk_update_rate(clk, clk->in_rate);