From patchwork Sun Jan 10 12:42:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pragnesh Patel X-Patchwork-Id: 1424242 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=lXF4OOec; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DDGjR4HxDz9sVp for ; Sun, 10 Jan 2021 23:43:29 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EFE05829C5; Sun, 10 Jan 2021 13:43:20 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="lXF4OOec"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8E667829C8; Sun, 10 Jan 2021 13:43:18 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8A33F829BF for ; Sun, 10 Jan 2021 13:43:15 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pragnesh.patel@sifive.com Received: by mail-qv1-xf33.google.com with SMTP id s6so6374601qvn.6 for ; Sun, 10 Jan 2021 04:43:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id; bh=iDOqQA6vTGRnb8U7ajUapdgx4LYHIH4rDdXyygRhKNc=; b=lXF4OOecDybBUqMQmCVhBvVFnXN4K1+zdSxZBYcMJ+lW3p4tP/DVBLGB64qe/ANilT j2xxBqEc40TgHN6EydRr1VbnnAL59kMwxiK+V+R1czaVGvEFIOBWYaHkEUiFSsGfv3sP uCuffMSjL8GPvL9V81xmsWX/GnsWkQ276BwFnUVcndRN6BhT8pesDDFq2b3EQdlaz18n sjdtJyNDWC3wwWmssLt/1Mq8ZaA52EJwHmJm9ZhIzuKNsIOAJAbWkNP5nMLljVhUdvIg ZG/JGrTuBd7JN5tALLT6zOiR8ZcDiCjxbhrwD7lddutqIda0zEymqkNEAQjgmKagTIQ0 n8Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=iDOqQA6vTGRnb8U7ajUapdgx4LYHIH4rDdXyygRhKNc=; b=c+tpQbNDQefJIonj8fIW6ikMA58jp0HXUe3GfjLbmOVHoEDeF0HoEr4SrPeKJMe9gX N7RhaN0iIhCztJH2f942BoDA90OlySnqnzLuT8sBYq23QvBblkLvI23mXst8PC/w1y70 FJASZQs8mePvdhP26M4PhsUzKKx5Gh2rZ8/jRUdwurku8bXkGViJPRoo8C7azAX2U+vh AXZdjn8BjQ5pnHVJqLSnSwNBJU0jzEDokv92pz+IBeZLXYTC0quqVRLgH8jdxwAbjIUG z6M0+X0kwJ+6zGDVvbF1o/aMnI8LNNOIC2JP5GoDnYawxFPpg0mxKe3sizNfCWYML0kv jFtQ== X-Gm-Message-State: AOAM533GGGFwt5EsrUKl1KZ3+38wIyuBpCz/TljXZeq1PBVNOxcD3AkG 8r2HZQ0wFPPjpUPoDVXptRTq0a9kJPucD0GH X-Google-Smtp-Source: ABdhPJy0S5xHGkLmUfiXhdpznQrXi9YbZvo1rAGCaRBa+ht4wz5N1gVxOpazx+4R2Ef7JOEzT1UGAw== X-Received: by 2002:a05:6214:321:: with SMTP id j1mr14997247qvu.32.1610282593994; Sun, 10 Jan 2021 04:43:13 -0800 (PST) Received: from sachinj2-OptiPlex-7010.open-silicon.com ([114.143.65.226]) by smtp.gmail.com with ESMTPSA id m13sm6665077qtu.93.2021.01.10.04.43.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Jan 2021 04:43:13 -0800 (PST) From: Pragnesh Patel To: u-boot@lists.denx.de Cc: atish.patra@wdc.com, palmerdabbelt@google.com, bmeng.cn@gmail.com, paul.walmsley@sifive.com, anup.patel@wdc.com, sagar.kadam@sifive.com, rick@andestech.com, Pragnesh Patel , Simon Glass , Stefan Roese , Joao Marcos Costa , Heinrich Schuchardt , Reuben Dowle , Sean Anderson , Michael Walle , Marek Szyprowski , Keerthy , Marcin Juszkiewicz Subject: [PATCH v3 1/2] trace: select TIMER_EARLY to avoid infinite recursion Date: Sun, 10 Jan 2021 18:12:52 +0530 Message-Id: <20210110124254.16312-1-pragnesh.patel@sifive.com> X-Mailer: git-send-email 2.17.1 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean When tracing functions is enabled this adds calls to __cyg_profile_func_enter() and __cyg_profile_func_exit() to the traced functions. __cyg_profile_func_enter() and __cyg_profile_func_exit() invoke timer_get_us() to record the entry and exit time. initr_dm() will make gd->dm_root = NULL and gd->timer = NULL, so timer_get_us() -> get_ticks() -> dm_timer_init() will lead to an indefinite recursion. So select TIMER_EARLY when tracing got enabled. Signed-off-by: Pragnesh Patel Reviewed-by: Simon Glass Reviewed-by: Rick Chen --- Changes in v3: - no change Changes in v2: - new patch lib/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Kconfig b/lib/Kconfig index 7673d2e4e0..671386963a 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -210,6 +210,7 @@ config BITREVERSE config TRACE bool "Support for tracing of function calls and timing" imply CMD_TRACE + select TIMER_EARLY help Enables function tracing within U-Boot. This allows recording of call traces including timing information. The command can write data to From patchwork Sun Jan 10 12:42:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pragnesh Patel X-Patchwork-Id: 1424243 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=hkCzUOGG; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DDGjY0q33z9sVp for ; Sun, 10 Jan 2021 23:43:44 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 69243829CF; Sun, 10 Jan 2021 13:43:27 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="hkCzUOGG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 79AE1829CC; Sun, 10 Jan 2021 13:43:25 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 85069829C9 for ; Sun, 10 Jan 2021 13:43:21 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pragnesh.patel@sifive.com Received: by mail-qk1-x72b.google.com with SMTP id 143so12464394qke.10 for ; Sun, 10 Jan 2021 04:43:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=efk2CzZJy9yGIFaAR5fTnCbIip0UzmaR2WZ0zpPhcKc=; b=hkCzUOGGuHgkjKLxh0VE0UBB51TT4HLC7ngO6icqs+jgXuoQq/o2VNaAijjh4kL4Aj +pxSP/0yNGuP/2/CAShCTQ875j/d9Li8OAg386ROypazf/WdAOe3u0DJftxE/o56yBYP YYLGqkR36Mxi6K/PMypRu5mRp64lYNrofnZJjR9VJ2R48p4+M0bkpdPdwsuykCAuJim6 xBF1ZYNnkXhQCiPlhe6jRGEG7c42ejo3h5e4bUVmCw5eJrMYNsMy2bu/TkeX4WQfEnYQ DXnug+8ENx8vhJIDJPyqdhrB7Zo/hU499c4zYwD5VvguC8U3SbnwZyoR9tp7XZCXv3g7 lBDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=efk2CzZJy9yGIFaAR5fTnCbIip0UzmaR2WZ0zpPhcKc=; b=aqT0Mz7y5oZNV7wcEsXQLbS2ON0i3e2flXz0xJJlLEby2V3FBOLv2JOjPTsd8+SBHG Pulv98jutHz5qH/olpszcvFminJ0d/WIRyVL2orDv/Nx/Huog6aHLIw388aPQfecKHn4 EUjEjAjY7xDZ4eVKW7R9xRp7BS30I6HRMP/efQiWyyENj5fAWYEtmQzp9b8sEApKfbFY zI+KjeAp5ffUFaG8bqlVA6Bl04/R1a4pIF1ndiWKgHx0TBYeQLXqVmZ42DSo0FrF5yBE tFGdRn6mJmVtbGPn1oB5ygYugsQncOlv/1dNW52ss+vgDW0Wj9u+9azM8hNa2n4BHEd/ caIQ== X-Gm-Message-State: AOAM5333vT50ra0XFtdrr48XJRyBiQW4HT5niLTC1kUOqXuUnodeWdiW Lol7GKpJrJRNhxrErsyuoFMStEvg/3NqVlDc X-Google-Smtp-Source: ABdhPJxUKLc0gHnipc4ZTfyakwemLYLtwUCYt34/IqVmfKQ+d10JI8oEzzp3QMJZwemSpspo3DxJBQ== X-Received: by 2002:a05:620a:12b9:: with SMTP id x25mr12257398qki.421.1610282599956; Sun, 10 Jan 2021 04:43:19 -0800 (PST) Received: from sachinj2-OptiPlex-7010.open-silicon.com ([114.143.65.226]) by smtp.gmail.com with ESMTPSA id m13sm6665077qtu.93.2021.01.10.04.43.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Jan 2021 04:43:19 -0800 (PST) From: Pragnesh Patel To: u-boot@lists.denx.de Cc: atish.patra@wdc.com, palmerdabbelt@google.com, bmeng.cn@gmail.com, paul.walmsley@sifive.com, anup.patel@wdc.com, sagar.kadam@sifive.com, rick@andestech.com, Pragnesh Patel , Palmer Dabbelt , Sean Anderson , Simon Glass Subject: [PATCH v3 2/2] riscv: timer: Add support for an early timer Date: Sun, 10 Jan 2021 18:12:53 +0530 Message-Id: <20210110124254.16312-2-pragnesh.patel@sifive.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210110124254.16312-1-pragnesh.patel@sifive.com> References: <20210110124254.16312-1-pragnesh.patel@sifive.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Added support for timer_early_get_count() and timer_early_get_rate() This is mostly useful in tracing. Signed-off-by: Pragnesh Patel Reviewed-by: Rick Chen --- Changes in v3: - Add IS_ENABLED(CONFIG_TIMER_EARLY) for timer_early_get_rate() and timer_early_get_count() functions. Changes in v2: - make u-boot compile for qemu (include/configs/qemu-riscv.h) drivers/timer/andes_plmt_timer.c | 21 ++++++++++++++++++++- drivers/timer/riscv_timer.c | 21 ++++++++++++++++++++- drivers/timer/sifive_clint_timer.c | 21 ++++++++++++++++++++- include/configs/ax25-ae350.h | 5 +++++ include/configs/qemu-riscv.h | 5 +++++ include/configs/sifive-fu540.h | 5 +++++ 6 files changed, 75 insertions(+), 3 deletions(-) diff --git a/drivers/timer/andes_plmt_timer.c b/drivers/timer/andes_plmt_timer.c index cec86718c7..ce4040d76d 100644 --- a/drivers/timer/andes_plmt_timer.c +++ b/drivers/timer/andes_plmt_timer.c @@ -17,11 +17,30 @@ /* mtime register */ #define MTIME_REG(base) ((ulong)(base)) -static u64 andes_plmt_get_count(struct udevice *dev) +static u64 notrace andes_plmt_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } +#if CONFIG_IS_ENABLED(RISCV_MMODE) && IS_ENABLED(CONFIG_TIMER_EARLY) +/** + * timer_early_get_rate() - Get the timer rate before driver model + */ +unsigned long notrace timer_early_get_rate(void) +{ + return RISCV_MMODE_TIMER_FREQ; +} + +/** + * timer_early_get_count() - Get the timer count before driver model + * + */ +u64 notrace timer_early_get_count(void) +{ + return readq((void __iomem *)MTIME_REG(RISCV_MMODE_TIMERBASE)); +} +#endif + static const struct timer_ops andes_plmt_ops = { .get_count = andes_plmt_get_count, }; diff --git a/drivers/timer/riscv_timer.c b/drivers/timer/riscv_timer.c index 21ae184057..3627ed79b8 100644 --- a/drivers/timer/riscv_timer.c +++ b/drivers/timer/riscv_timer.c @@ -16,7 +16,7 @@ #include #include -static u64 riscv_timer_get_count(struct udevice *dev) +static u64 notrace riscv_timer_get_count(struct udevice *dev) { __maybe_unused u32 hi, lo; @@ -31,6 +31,25 @@ static u64 riscv_timer_get_count(struct udevice *dev) return ((u64)hi << 32) | lo; } +#if CONFIG_IS_ENABLED(RISCV_SMODE) && IS_ENABLED(CONFIG_TIMER_EARLY) +/** + * timer_early_get_rate() - Get the timer rate before driver model + */ +unsigned long notrace timer_early_get_rate(void) +{ + return RISCV_SMODE_TIMER_FREQ; +} + +/** + * timer_early_get_count() - Get the timer count before driver model + * + */ +u64 notrace timer_early_get_count(void) +{ + return riscv_timer_get_count(NULL); +} +#endif + static int riscv_timer_probe(struct udevice *dev) { struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev); diff --git a/drivers/timer/sifive_clint_timer.c b/drivers/timer/sifive_clint_timer.c index 00ce0f08d6..2e902feb61 100644 --- a/drivers/timer/sifive_clint_timer.c +++ b/drivers/timer/sifive_clint_timer.c @@ -14,11 +14,30 @@ /* mtime register */ #define MTIME_REG(base) ((ulong)(base) + 0xbff8) -static u64 sifive_clint_get_count(struct udevice *dev) +static u64 notrace sifive_clint_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } +#if CONFIG_IS_ENABLED(RISCV_MMODE) && IS_ENABLED(CONFIG_TIMER_EARLY) +/** + * timer_early_get_rate() - Get the timer rate before driver model + */ +unsigned long notrace timer_early_get_rate(void) +{ + return RISCV_MMODE_TIMER_FREQ; +} + +/** + * timer_early_get_count() - Get the timer count before driver model + * + */ +u64 notrace timer_early_get_count(void) +{ + return readq((void __iomem *)MTIME_REG(RISCV_MMODE_TIMERBASE)); +} +#endif + static const struct timer_ops sifive_clint_ops = { .get_count = sifive_clint_get_count, }; diff --git a/include/configs/ax25-ae350.h b/include/configs/ax25-ae350.h index b2606e794d..bd9c371f83 100644 --- a/include/configs/ax25-ae350.h +++ b/include/configs/ax25-ae350.h @@ -17,6 +17,11 @@ #endif #endif +#define RISCV_MMODE_TIMERBASE 0xe6000000 +#define RISCV_MMODE_TIMER_FREQ 60000000 + +#define RISCV_SMODE_TIMER_FREQ 60000000 + /* * CPU and Board Configuration Options */ diff --git a/include/configs/qemu-riscv.h b/include/configs/qemu-riscv.h index a2f33587c2..5291de83f8 100644 --- a/include/configs/qemu-riscv.h +++ b/include/configs/qemu-riscv.h @@ -29,6 +29,11 @@ #define CONFIG_STANDALONE_LOAD_ADDR 0x80200000 +#define RISCV_MMODE_TIMERBASE 0x2000000 +#define RISCV_MMODE_TIMER_FREQ 1000000 + +#define RISCV_SMODE_TIMER_FREQ 1000000 + /* Environment options */ #ifndef CONFIG_SPL_BUILD diff --git a/include/configs/sifive-fu540.h b/include/configs/sifive-fu540.h index c1c79db147..0d69d1c548 100644 --- a/include/configs/sifive-fu540.h +++ b/include/configs/sifive-fu540.h @@ -36,6 +36,11 @@ #define CONFIG_STANDALONE_LOAD_ADDR 0x80200000 +#define RISCV_MMODE_TIMERBASE 0x2000000 +#define RISCV_MMODE_TIMER_FREQ 1000000 + +#define RISCV_SMODE_TIMER_FREQ 1000000 + /* Environment options */ #ifndef CONFIG_SPL_BUILD