From patchwork Wed Oct 5 22:10:58 2016 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: 9363519 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 3F374607D6 for ; Wed, 5 Oct 2016 22:11:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39CA628CC6 for ; Wed, 5 Oct 2016 22:11:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E95728D10; Wed, 5 Oct 2016 22:11:48 +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 A9D0928CC6 for ; Wed, 5 Oct 2016 22:11:47 +0000 (UTC) Received: from localhost ([::1]:51590 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bruPi-0002I2-Ld for patchwork-qemu-devel@patchwork.kernel.org; Wed, 05 Oct 2016 18:11:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47118) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bruOD-0001U1-NK for qemu-devel@nongnu.org; Wed, 05 Oct 2016 18:10:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bruOB-0007QE-My for qemu-devel@nongnu.org; Wed, 05 Oct 2016 18:10:12 -0400 Received: from greensocs.com ([193.104.36.180]:60360) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bruOB-0007Q0-D3 for qemu-devel@nongnu.org; Wed, 05 Oct 2016 18:10:11 -0400 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id DEAA42E8DD0; Thu, 6 Oct 2016 00:10:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1475705410; bh=+VBvKxishKEHj2iCe9kZXJ9g0IbIts7M/XooTrqRksU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=oB2YTf4dkI5kJpz7qJF7uo0eBLOlRKZYSjQrnSqUpkY173Knsvr7DDVT3SqfWepoL u9pObSFFoJ1oIJSFPMF7/lqTnwypOlvinaIGyhWQOTkZ3Vv1PbefvabFkq+UuILPjX NPllMlWp1cB4508Zy7GbIqA36b7tna+8/UtW5b24= 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=1mepYldR; dkim=pass (1024-bit key) header.d=greensocs.com header.b=1mepYldR 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 lbPkQnLwbdfc; Thu, 6 Oct 2016 00:10:10 +0200 (CEST) Received: by greensocs.com (Postfix, from userid 998) id ECAC92E8DCE; Thu, 6 Oct 2016 00:10:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1475705409; bh=+VBvKxishKEHj2iCe9kZXJ9g0IbIts7M/XooTrqRksU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1mepYldRDAfCpVYXZQrzQHOwBAWsC8mYMYEtvkEUYkIAtWL/hOQ4+uYA3ZoVtTICt QUFpG2JOsIQKZAmfaOVkNXHCam3g1uQjAsn+fWoARUpLRhc9Mf1McRhdscyrOgPVgU LKeoIvDAR0G4Kq6787MlKc+augVXJlRoeuJVfJ28= Received: from asus.localdomain (localhost [IPv6:::1]) (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 3481A2E8DC6; Thu, 6 Oct 2016 00:10:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1475705409; bh=+VBvKxishKEHj2iCe9kZXJ9g0IbIts7M/XooTrqRksU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1mepYldRDAfCpVYXZQrzQHOwBAWsC8mYMYEtvkEUYkIAtWL/hOQ4+uYA3ZoVtTICt QUFpG2JOsIQKZAmfaOVkNXHCam3g1uQjAsn+fWoARUpLRhc9Mf1McRhdscyrOgPVgU LKeoIvDAR0G4Kq6787MlKc+augVXJlRoeuJVfJ28= From: fred.konrad@greensocs.com To: qemu-devel@nongnu.org Date: Thu, 6 Oct 2016 00:10:58 +0200 Message-Id: <1475705464-27130-5-git-send-email-fred.konrad@greensocs.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1475705464-27130-1-git-send-email-fred.konrad@greensocs.com> References: <1475705464-27130-1-git-send-email-fred.konrad@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 V1 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 d575566..72062de 100644 --- a/include/qemu/qemu-clock.h +++ b/include/qemu/qemu-clock.h @@ -50,6 +50,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. */ + qemu_clk_on_rate_update_cb 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_attach_to_device: * @dev: the device on which the clock need to be attached. diff --git a/qemu-clock.c b/qemu-clock.c index 541f615..5c799bc 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_attach_to_device(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);