From patchwork Tue Feb 28 10:02:59 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: 9595095 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 2EBC6601D7 for ; Tue, 28 Feb 2017 10:19:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FEA728504 for ; Tue, 28 Feb 2017 10:19:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13E202851F; Tue, 28 Feb 2017 10:19:17 +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 7C26428504 for ; Tue, 28 Feb 2017 10:19:16 +0000 (UTC) Received: from localhost ([::1]:59937 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciesE-0002ar-65 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 28 Feb 2017 05:19:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58920) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cied5-0006oG-Uk for qemu-devel@nongnu.org; Tue, 28 Feb 2017 05:03:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cied3-000489-GN for qemu-devel@nongnu.org; Tue, 28 Feb 2017 05:03:35 -0500 Received: from greensocs.com ([193.104.36.180]:38399) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cied3-00047r-3c for qemu-devel@nongnu.org; Tue, 28 Feb 2017 05:03:33 -0500 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 65C9E425190; Tue, 28 Feb 2017 11:03:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1488276212; bh=vCeMpNL6qIdRX8LdY43hmqeiaPANGiirgnKy7nsT2O0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RxCrrCfHNGtbMDczZWEg6I09mczkUQpHfg37z9aNNZoyK5aH/MFS3/P2niux4zrWg 7p0Uflxafp+wLS0+D1PPrk/Z7+SHM2uEp2iO4iBxadw7GYHvVfuL11sOuXg85AUedn dPPS5sWNWvRVxIs3yG2gmuPiuwQI9eSkki8wPseo= 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 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 Mh43EWpE6Rwc; Tue, 28 Feb 2017 11:03:31 +0100 (CET) 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 0481840D438; Tue, 28 Feb 2017 11:03:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1488276211; bh=vCeMpNL6qIdRX8LdY43hmqeiaPANGiirgnKy7nsT2O0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=uqQAlTQcxFCcHfncsTYgHodDQS+uwCKcMufe4p6szzgs2xhv8Tvd8dlZytTsX7zvd 0hkM6PxAbFenULBe11AFqLsbfqCyCXm1SqIsc9d9dIVagNj9mKaShmk8I+Q5ckbpYi AC420BGeGQUrGotQ5WMZE/gbgfLCDVu0Ud0JBiQs= From: fred.konrad@greensocs.com To: qemu-devel@nongnu.org Date: Tue, 28 Feb 2017 11:02:59 +0100 Message-Id: <1488276185-31168-5-git-send-email-fred.konrad@greensocs.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1488276185-31168-1-git-send-email-fred.konrad@greensocs.com> References: <1488276185-31168-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 v3 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, mark.burton@greensocs.com, alistair.francis@xilinx.com, clg@kaod.org, 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: KONRAD Frederic This introduces a clock init array to ease the clock tree construction. Signed-off-by: KONRAD Frederic V2 -> V3: * s/QEMUClock/qemu_clk/g --- 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 f80de56..1c57df4 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 24719e2..8f342f6 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) +{ + QEMUClock **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(QEMUClock *clk) { qemu_clk_update_rate(clk, clk->ref_rate);