Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BDB2C432BE for ; Tue, 31 Aug 2021 04:49:00 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1AE876103A for ; Tue, 31 Aug 2021 04:48:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1AE876103A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 79D26833DA; Tue, 31 Aug 2021 06:48:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.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=gmail.com header.i=@gmail.com header.b="E/+YSMCH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3B759833F4; Tue, 31 Aug 2021 06:48:54 +0200 (CEST) Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) (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 04914833B3 for ; Tue, 31 Aug 2021 06:48:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qv1-xf2d.google.com with SMTP id e18so9716253qvo.1 for ; Mon, 30 Aug 2021 21:48:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=CJ6c1ebmKVy21OdmJwrY350YVQlvALYhh2JPGDH7WOQ=; b=E/+YSMCHlqviHVLhUoKXfCPgYns7SlBmwFgWZa+9t26oA/zSXTrDyeqFTY6vX2kcrC jFBZmFlFJBN4kKdlJWeOe/E9xPtRqgh8Ns0PQyAml94XAHN4taJiWa56GK6GH059+hF8 JCjaV8sNOKnJxCuzRGYOoHSJ7bNq70XP6hm8wZ8/xxwzkmqOQfGZfbGNv93MloXItmrt Q4GgPwKz/sIOJmFQK7EQQwv9sjnM82iGPNF8dddzzaaqTmCQTYiB+pboell/Wjo8oJbB YUWpuAZ9nkp9ZZKIr0rCzrzhQMnX9vyB0QdwY7R3D6Bhxypb3xiDzuw1lj0/mqJ68X22 T8qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=CJ6c1ebmKVy21OdmJwrY350YVQlvALYhh2JPGDH7WOQ=; b=q+USufpRpk4u8dgEbNbc3mbMcrB55jNY5TZKACfs9b3jfkNKJEwYENZmaAqim2bmeF 8PSlZ7O9HMfeg9ty2tCB7qHZOD7t2piRBnC+4hbP0CpC2BCiD3Pw318AKjR4hoeBJ6qn XppQFUWv1TJuruGGE/c41GnXD/5w7MFF1mTvGPunNz7FoshSBUT4xVa4+glCvs/vScUr s3Tn2DYkfq3shOOvUd5zf2AYX51gZaDzqCdQGBjdyaE6JLtx9HQjE1WYR+z2EF9jJ7Zs 7Ui5ym5eehKZMmr4BALcTvO57o0XdmqHPhDuRyNUImKxP0t1q5Ava+JboAXZmMRFSiiB SqDA== X-Gm-Message-State: AOAM5301vhfFxgR/AilHdyy+2qBSOGWZt8Pd8iaj+wDg80/Xh/ZKawtz mp6IaI3iq41TJ9CYCWLyyq41PZ7IPCI= X-Google-Smtp-Source: ABdhPJzfERUMpbDV02mqidyd+G/1fOLEsMujo2d3aGLN9dOmulqoFtiyuAGidJBUkWQAuto8fYNnCw== X-Received: by 2002:a0c:d804:: with SMTP id h4mr27374473qvj.37.1630385328132; Mon, 30 Aug 2021 21:48:48 -0700 (PDT) Received: from [192.168.1.201] (pool-108-45-127-224.washdc.fios.verizon.net. [108.45.127.224]) by smtp.googlemail.com with ESMTPSA id q11sm12654701qkm.56.2021.08.30.21.48.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Aug 2021 21:48:47 -0700 (PDT) Subject: Re: [PATCH v3 2/4] riscv: lib: introduce a cache_init interface To: Zong Li , rick@andestech.com, ycliang@andestech.com, bmeng.cn@gmail.com, green.wan@sifive.com, paul.walmsley@sifive.com, sjg@chromium.org, u-boot@lists.denx.de References: <20210817090852.17022-1-zong.li@sifive.com> <20210817090852.17022-3-zong.li@sifive.com> From: Sean Anderson Message-ID: <3a7fa068-412f-4311-9c89-06deb899391f@gmail.com> Date: Tue, 31 Aug 2021 00:48:46 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20210817090852.17022-3-zong.li@sifive.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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.103.2 at phobos.denx.de X-Virus-Status: Clean On 8/17/21 5:08 AM, Zong Li wrote: > Add an interface for cache initialization. Each platform can overwrite > this weak function by their own implementation, such as sifive_cache in > this patch. > > In sifive_cache, it invokes the generic cache_enable interface of cache > uclass to execute the relative implementation in SiFive ccache driver. > > Signed-off-by: Zong Li > --- > arch/riscv/Kconfig | 5 +++++ > arch/riscv/include/asm/cache.h | 1 + > arch/riscv/lib/Makefile | 1 + > arch/riscv/lib/cache.c | 5 +++++ > arch/riscv/lib/sifive_cache.c | 27 +++++++++++++++++++++++++++ > 5 files changed, 39 insertions(+) > create mode 100644 arch/riscv/lib/sifive_cache.c > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > index 4b0c3dffa6..ec651fe0a4 100644 > --- a/arch/riscv/Kconfig > +++ b/arch/riscv/Kconfig > @@ -179,6 +179,11 @@ config SPL_SIFIVE_CLINT > The SiFive CLINT block holds memory-mapped control and status registers > associated with software and timer interrupts. > > +config SIFIVE_CACHE > + bool > + help > + This enables the operations to configure SiFive cache > + > config ANDES_PLIC > bool > depends on RISCV_MMODE || SPL_RISCV_MMODE > diff --git a/arch/riscv/include/asm/cache.h b/arch/riscv/include/asm/cache.h > index ec8fe201d3..6ebb2b4329 100644 > --- a/arch/riscv/include/asm/cache.h > +++ b/arch/riscv/include/asm/cache.h > @@ -9,6 +9,7 @@ > > /* cache */ > void cache_flush(void); > +int cache_init(void); > > /* > * The current upper bound for RISCV L1 data cache line sizes is 32 bytes. > diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile > index c4cc41434b..06020fcc2a 100644 > --- a/arch/riscv/lib/Makefile > +++ b/arch/riscv/lib/Makefile > @@ -10,6 +10,7 @@ obj-$(CONFIG_CMD_BOOTM) += bootm.o > obj-$(CONFIG_CMD_BOOTI) += bootm.o image.o > obj-$(CONFIG_CMD_GO) += boot.o > obj-y += cache.o > +obj-$(CONFIG_SIFIVE_CACHE) += sifive_cache.o > ifeq ($(CONFIG_$(SPL_)RISCV_MMODE),y) > obj-$(CONFIG_$(SPL_)SIFIVE_CLINT) += sifive_clint.o > obj-$(CONFIG_ANDES_PLIC) += andes_plic.o > diff --git a/arch/riscv/lib/cache.c b/arch/riscv/lib/cache.c > index b1d42bcc2b..2cd66504c6 100644 > --- a/arch/riscv/lib/cache.c > +++ b/arch/riscv/lib/cache.c > @@ -70,3 +70,8 @@ __weak int dcache_status(void) > { > return 0; > } > + > +__weak int cache_init(void) > +{ > + return 0; > +} Don't make this generic. Just call a `sifive_cache_init` or whatever. IMO this pattern shouldn't be duplicated by other platforms, but it is OK to do for now until we have a more generic method. --Sean > diff --git a/arch/riscv/lib/sifive_cache.c b/arch/riscv/lib/sifive_cache.c > new file mode 100644 > index 0000000000..94e84e024e > --- /dev/null > +++ b/arch/riscv/lib/sifive_cache.c > @@ -0,0 +1,27 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Copyright (C) 2021 SiFive, Inc > + */ > + > +#include > +#include > +#include > + > +int cache_init(void) > +{ > + struct udevice *dev; > + int ret; > + > + /* Enable ways of ccache */ > + ret = uclass_get_device_by_driver(UCLASS_CACHE, > + DM_DRIVER_GET(sifive_ccache), > + &dev); > + if (ret) > + return log_msg_ret("Cannot enable cache ways", ret); > + > + ret = cache_enable(dev); > + if (ret) > + return log_msg_ret("ccache enable failed", ret); > + > + return 0; > +} >