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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 761CAC4338F for ; Tue, 17 Aug 2021 09:09:34 +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 BC28D6023B for ; Tue, 17 Aug 2021 09:09:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BC28D6023B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.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 AD69182C28; Tue, 17 Aug 2021 11:09:17 +0200 (CEST) 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="Mu7I3FUw"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EA32A82C24; Tue, 17 Aug 2021 11:09:10 +0200 (CEST) Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) (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 C2DF582959 for ; Tue, 17 Aug 2021 11:09:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=zong.li@sifive.com Received: by mail-pj1-x1036.google.com with SMTP id mq2-20020a17090b3802b0290178911d298bso5316927pjb.1 for ; Tue, 17 Aug 2021 02:09:03 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=S5pTsyRsgjM6b7MUvg7ktjT8E6W1h2gCBYyFPsM4dvE=; b=Mu7I3FUwGrv9G5dBBlL5mmn7x+Twh+dMdp8h8KOPQSgdc3unl0CaS7HqKIXHE1vftS B3QLrqvxTTRojQAvUcnT/25TlV8VZeZl2cHO+na6RXZSo5xS3CoTbeHeDWhdBosZZ86L sr0Bk+SdIP398G1/yNrRUTmpOyR14jImmFHVb3zjD8HW20PVaENgpDj0AgADyljrs9Kh DGUrVUogcosmfa6saSYyYcFtMcCI3zDclvEmhlB/7yj8ye5RC6yyICiwkBMOBbNE4HB6 nfOKXq6Aw5BzLPo7N6l8dJCPeRxySXX9j4ZMhWPiXH30ErBmBWj1xKrnAVpTkTehBE0+ TTDA== 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:mime-version:content-transfer-encoding; bh=S5pTsyRsgjM6b7MUvg7ktjT8E6W1h2gCBYyFPsM4dvE=; b=JRIsX6Era87QYzfu9ZaDKKBIn1oHEFWO5k5dP4GOpawLDPVO/p6xcnvomz94Xoyhqx /3w+6WXYqvxZheVAZWKDEE4hAX1vhgSfmx2z2FIIK7mSLDFEmsp6FhnAOtXDe9hgqkS9 JQB+pcJW8ZHvA1mkkUVxoCvpTQAVFS99d10Y7qC13GiMyQyFTohUbWDwmIn6lyueXz64 EwwBBaSNvOd6L3Q0xQr+JgmTvxO3IIbUz5cOrYN5RUeZJq9j+WEUR/tRcgEp/rE0++wa bNdxSqH5ADyfdc+7Ojwisvh39I4SEDJgAp3iYpRaS/ncilOh3lgUSxAIHH9/1uMa05EE ky/g== X-Gm-Message-State: AOAM5320++gWeTlt/thrFUuMcP0StKuaUFKx8CZRk6poSnPco5htLYT5 1wT+5ug+AT19WWjQOG9Rm1jrfPv6tFL0Xg== X-Google-Smtp-Source: ABdhPJyaHlrFIPQ+5cVgoBc8rhZ22EJRUj7CKA3oS5tlg45+ZA5ZfJ2qAcvA6hBdcgCjD5kO8A4DEw== X-Received: by 2002:aa7:8bdd:0:b0:3e2:13fc:dd2f with SMTP id s29-20020aa78bdd000000b003e213fcdd2fmr2716866pfd.53.1629191342139; Tue, 17 Aug 2021 02:09:02 -0700 (PDT) Received: from hsinchu15.internal.sifive.com (59-124-168-89.HINET-IP.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id y2sm1813318pfe.146.2021.08.17.02.09.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 02:09:01 -0700 (PDT) From: Zong Li To: rick@andestech.com, ycliang@andestech.com, bmeng.cn@gmail.com, seanga2@gmail.com, green.wan@sifive.com, paul.walmsley@sifive.com, sjg@chromium.org, u-boot@lists.denx.de Cc: Zong Li Subject: [PATCH v3 2/4] riscv: lib: introduce a cache_init interface Date: Tue, 17 Aug 2021 17:08:50 +0800 Message-Id: <20210817090852.17022-3-zong.li@sifive.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210817090852.17022-1-zong.li@sifive.com> References: <20210817090852.17022-1-zong.li@sifive.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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; +} 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; +} -- 2.32.0