From mboxrd@z Thu Jan 1 00:00:00 1970 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=-14.7 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,URIBL_BLOCKED, 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 D2ADAC4338F for ; Wed, 28 Jul 2021 04:24:07 +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 2EE9F60E9B for ; Wed, 28 Jul 2021 04:24:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2EE9F60E9B 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 6BCDD829E4; Wed, 28 Jul 2021 06:24:04 +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="mTJ/Z/t9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BE025829F8; Wed, 28 Jul 2021 06:24:01 +0200 (CEST) Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) (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 ABF5682986 for ; Wed, 28 Jul 2021 06:23:57 +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-qk1-x72f.google.com with SMTP id t66so1090206qkb.0 for ; Tue, 27 Jul 2021 21:23:57 -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=4Bx6+QlXObHQdkgY95CVxYlUx9AQrZTY+BWXDsDQTYg=; b=mTJ/Z/t9KyQPyXShu+0V+/9tEXozW1Fdw4yZnt+iK7p72A0qez9V06dMxuXhMBrncY sA7VEWrOxaSBKjm+51rDWu1hn9j7NAtSlsAWe5qDGXcHvViuiIsmlKRMu5wfjDjgP008 OQKnYoDtVcuNpkjuE8Ehp966tKajnKAgHtpfJY/ClCKPVez6riQGMD911Kcyz7XZxOSR z2lBsy2L0PmcK+RvlzqnRQY3tD8pqU5P39LjZou5WICV8ppk8bqRLQO/LxpIcqxlQK6W dxRo2jZwDTieZd0TDpSJmbq2opJczLPUExjjVJWo1uzBPsSz5sQxN5F+CL1QUJtBXl30 nkXg== 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=4Bx6+QlXObHQdkgY95CVxYlUx9AQrZTY+BWXDsDQTYg=; b=EskXQRYYJJqmbgC9zqwrc3cRSRmxJkoT7UwM8WiIk9UkwowOK1b/OmnMjuD/ACGgQn m6dpyjJdd2gI8i6czIMToaDtZcmgCYdlbhq5ehQmkVJgyRkn2F91J0a5HZBnIMUBbfFn 547msvhrYz+2SBd2axDD5/ASzeBNiNwMYCgzg/8XnKArIYC4TDJnEe5GPgJIjVM629gb QuWxtRfaoyxpfe31BpW37kf3Jduc4ZVzzC1HjxaaBHK3YtX1WK16nM7TBYNrte0AQyK7 bon0k5JYOnUmydMpXQaSXqItEvTO52AjmQ2d9JokJLeKsX/pYte50hBR/eT32jbRnSD8 XssA== X-Gm-Message-State: AOAM533n4yIYoKOx3cJmLM3veLD2U7Ar3dNzimkVVHcrOA7vXaMrCXL7 eC9S1egfTcURgTZdrY/x9C1W+jRNXus= X-Google-Smtp-Source: ABdhPJw4aMvaJ/02G7tUDnABY250EOuofkFrSicCNS0kdY52wsKBU56byQHHlz6u908l7lV3uE19GQ== X-Received: by 2002:ae9:f805:: with SMTP id x5mr25385487qkh.373.1627446236210; Tue, 27 Jul 2021 21:23:56 -0700 (PDT) Received: from [192.168.1.201] (pool-74-96-87-9.washdc.fios.verizon.net. [74.96.87.9]) by smtp.googlemail.com with ESMTPSA id i4sm2648945qka.130.2021.07.27.21.23.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 27 Jul 2021 21:23:55 -0700 (PDT) Subject: Re: [PATCH 1/2] cache: add sifive composable cache driver To: Zong Li , rick@andestech.com, ycliang@andestech.com, bmeng.cn@gmail.com, sjg@chromium.org, green.wan@sifive.com, paul.walmsley@sifive.com, u-boot@lists.denx.de References: <20210727085452.25708-1-zong.li@sifive.com> From: Sean Anderson Message-ID: Date: Wed, 28 Jul 2021 00:23:55 -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: <20210727085452.25708-1-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 7/27/21 4:54 AM, Zong Li wrote: > This driver is currently responsible for enabling all ccache ways. Can you expand on this a little? Perhaps describe the hardware a little. For example, you could describe what a way/bank is, and that they can't be disabled by the hardware. > > Signed-off-by: Zong Li > --- > drivers/cache/Kconfig | 7 +++ > drivers/cache/Makefile | 1 + > drivers/cache/cache-sifive-ccache.c | 69 +++++++++++++++++++++++++++++ > 3 files changed, 77 insertions(+) > create mode 100644 drivers/cache/cache-sifive-ccache.c > > diff --git a/drivers/cache/Kconfig b/drivers/cache/Kconfig > index 1e452ad6d9..b903e3e935 100644 > --- a/drivers/cache/Kconfig > +++ b/drivers/cache/Kconfig > @@ -39,4 +39,11 @@ config NCORE_CACHE > controller. The driver initializes cache directories and coherent > agent interfaces. > > +config SIFIVE_CACHE_CCACHE Just SIFIVE_CCACHE (or SIFIVE_CACHE) please. > + bool "SiFive composable cache" > + select CACHE > + help > + This driver is for SiFive Composable L2/L3 cache. It enables cache > + ways of composable cache. > + > endmenu > diff --git a/drivers/cache/Makefile b/drivers/cache/Makefile > index fed50be3f9..92c6c5a83f 100644 > --- a/drivers/cache/Makefile > +++ b/drivers/cache/Makefile > @@ -4,3 +4,4 @@ obj-$(CONFIG_SANDBOX) += sandbox_cache.o > obj-$(CONFIG_L2X0_CACHE) += cache-l2x0.o > obj-$(CONFIG_NCORE_CACHE) += cache-ncore.o > obj-$(CONFIG_V5L2_CACHE) += cache-v5l2.o > +obj-$(CONFIG_SIFIVE_CACHE_CCACHE) += cache-sifive-ccache.o > diff --git a/drivers/cache/cache-sifive-ccache.c b/drivers/cache/cache-sifive-ccache.c > new file mode 100644 > index 0000000000..9ea064912f > --- /dev/null > +++ b/drivers/cache/cache-sifive-ccache.c > @@ -0,0 +1,69 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (C) 2021 SiFive > + */ > + > +#include > +#include > +#include > +#include > +#include > + > +#define SIFIVE_CCACHE_CONFIG 0x000 > +#define SIFIVE_CCACHE_ENABLE 0x008 WAY_ENABLE? > + > +#define SIFIVE_CCACHE_NUM_WAY_MASK GENMASK(15, 8) > +#define SIFIVE_CCACHE_NUM_WAY_SHIFT 8 > + > +struct sifive_ccache { > + void __iomem *base; > +}; > + > +static int sifive_ccache_enable_all_ways(struct udevice *dev) > +{ > + struct sifive_ccache *priv = dev_get_priv(dev); > + u32 config; > + u32 ways; > + > + config = readl(priv->base + SIFIVE_CCACHE_CONFIG); > + ways = (config & SIFIVE_CCACHE_NUM_WAY_MASK) >> SIFIVE_CCACHE_NUM_WAY_SHIFT; ways = FIELD_GET(SIFIVE_CCACHE_NUM_WAY_MASK, config); and perhaps this should be named SIFIVE_CCACHE_CONFIG_WAYS to better match the datasheet? > + > + writel(ways - 1, priv->base + SIFIVE_CCACHE_ENABLE); > + > + return 0; > +} > + > +static int sifive_ccache_enable(struct udevice *dev) > +{ > + return sifive_ccache_enable_all_ways(dev); Any reason to have this in a separate function? > +} > + > +static const struct cache_ops sifive_ccache_ops = { > + .enable = sifive_ccache_enable, Please implement get_info as well. It should effectively just be get_info() { struct sifive_ccache *priv = dev_get_priv(dev); info->base = priv->base; return 0; } > +}; > + > +static int sifive_ccache_probe(struct udevice *dev) > +{ > + struct sifive_ccache *priv = dev_get_priv(dev); > + > + priv->base = dev_read_addr_ptr(dev); > + if (!priv->base) > + return -ENODEV; Please return -EINVAL instead [1]. --Sean [1] https://u-boot.readthedocs.io/en/latest/develop/driver-model/design.html#error-codes > + > + return 0; > +} > + > +static const struct udevice_id sifive_ccache_ids[] = { > + { .compatible = "sifive,fu540-c000-ccache" }, > + { .compatible = "sifive,fu740-c000-ccache" }, > + {} > +}; > + > +U_BOOT_DRIVER(sifive_ccache) = { > + .name = "sifive_ccache", > + .id = UCLASS_CACHE, > + .of_match = sifive_ccache_ids, > + .probe = sifive_ccache_probe, > + .priv_auto = sizeof(struct sifive_ccache), > + .ops = &sifive_ccache_ops, > +}; >