From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=rSbH0cNf; spf=pass (domain: linaro.org, ip: 209.85.221.68, mailfrom: leif.lindholm@linaro.org) Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by groups.io with SMTP; Wed, 04 Sep 2019 13:49:40 -0700 Received: by mail-wr1-f68.google.com with SMTP id s18so253838wrn.1 for ; Wed, 04 Sep 2019 13:49:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=t/OUfgollmukZJovtZ6Lw3el25S3Xc4qcOFaAwR3JuQ=; b=rSbH0cNfG+x4Nj1SiqLBYM9y4gEZYJhoDAy52CfSEJS1MY79j9zNkMgFjwODLdxnZ/ vEdnUHYblrY7NiokrtQFVWL4QYlZRujJHXBFUGxYxX+OvFkvOn6kwunldF2lPM2fgg/v Z117uZijlIfphAIzFzN1DG2BR7M2SwKeC0eMXQUnEuVH1oJ+H6UlYWyszKGCu5/Get2K tyqpzrqijxuF4w8cAEonu4U1ARrMmIc3rOSV3sNJKcXdWk+SZWRK6Zoa2Je2V2Q/s8tC yCZNmY5kSgsKSl4iNDHf3Prqwz2ERqnWi1B7RVWq6uisbZHOjWA1d05Aa7mKRTJE7upq 1q5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=t/OUfgollmukZJovtZ6Lw3el25S3Xc4qcOFaAwR3JuQ=; b=kQyr39cjMoq+/iWn48UcamZdnFhkSroqtU+k1F4W6FyW0oSy3lfKVknDrGu+KydHs+ PeYnopuyswiCEHbkX2SMgU0CkR1zpLfAEW4aSglmBTyHIIUI806Dd3G3yyY5RK/vpIna RVM5XjV0QaQ6HTUapagZJ8ZzJvjP6LkVSNnh+GAO8n4+GkZTgQ4CK8r75cQR6AMQ45FR Cx2nUAZTGkXuzkBrCbOiVBZMKerdmDpWF+Ir17W8/M04r6NVBoCzmxqLIqCu+yw+k41f /CK5tJUC1r8WCLf8g0qGrNAjxSt5RZ/jD6UtfhP3aiQ8buDRDmb7IzryRKUtrGQbOeE2 sJUw== X-Gm-Message-State: APjAAAVnMhWizsca7ODI8NH6vIUpzwVnmX5WcyhVfLN7kGVoRHBmFD+3 wxHWUDGJirRRkRUtRx02wPzNFzpO1v8= X-Google-Smtp-Source: APXvYqzdLhtqCuQ0jJfZSqXWwQL+SVkWmzW0BuQmwJymTOCditrXowAiLJT9D7o4mjHJ+ZqaNtTyow== X-Received: by 2002:a5d:6a81:: with SMTP id s1mr29639505wru.278.1567630178131; Wed, 04 Sep 2019 13:49:38 -0700 (PDT) Return-Path: Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id w15sm16116518wru.53.2019.09.04.13.49.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2019 13:49:37 -0700 (PDT) Date: Wed, 4 Sep 2019 21:49:36 +0100 From: "Leif Lindholm" To: devel@edk2.groups.io, abner.chang@hpe.com Subject: Re: [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v1 6/22]: MdePkg/BaseCacheMaintenanceLib: RISC-V cache maintenance implementation. Message-ID: <20190904204936.GS29255@bivouac.eciton.net> References: <1567593797-26216-1-git-send-email-abner.chang@hpe.com> <1567593797-26216-7-git-send-email-abner.chang@hpe.com> MIME-Version: 1.0 In-Reply-To: <1567593797-26216-7-git-send-email-abner.chang@hpe.com> User-Agent: Mutt/1.10.1 (2018-07-13) Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Sep 04, 2019 at 06:43:01PM +0800, Abner Chang wrote: > Implement RISC-V cache maintenance functions in BaseCacheMaintenanceLib. > > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Abner Chang > --- > .../BaseCacheMaintenanceLib.inf | 4 + > .../Library/BaseCacheMaintenanceLib/RiscVCache.c | 242 +++++++++++++++++++++ I would really prefer to see the header added wit this patch rather than BaseLib. > 2 files changed, 246 insertions(+) > create mode 100644 MdePkg/Library/BaseCacheMaintenanceLib/RiscVCache.c > > diff --git a/MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf b/MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf > index ec7feec..d9bfa04 100644 > --- a/MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf > +++ b/MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf > @@ -6,6 +6,7 @@ > # > # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
> # Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
> +# Copyright (c) 2016, Hewlett Packard Enterprise Development LP. All rights reserved.
> # > # SPDX-License-Identifier: BSD-2-Clause-Patent > # > @@ -41,6 +42,9 @@ > [Sources.AARCH64] > ArmCache.c > > +[Sources.RISCV64] > + RiscVCache.c > + > [Packages] > MdePkg/MdePkg.dec > > diff --git a/MdePkg/Library/BaseCacheMaintenanceLib/RiscVCache.c b/MdePkg/Library/BaseCacheMaintenanceLib/RiscVCache.c > new file mode 100644 > index 0000000..2d376a4 > --- /dev/null > +++ b/MdePkg/Library/BaseCacheMaintenanceLib/RiscVCache.c > @@ -0,0 +1,242 @@ > +/** @file > + RISC-V specific functionality for cache. > + > + Copyright (c) 2016, Hewlett Packard Enterprise Development LP. All rights reserved.
> + > + This program and the accompanying materials > + are licensed and made available under the terms and conditions of the BSD License > + which accompanies this distribution. The full text of the license may be found at > + http://opensource.org/licenses/bsd-license.php > + > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. > +**/ > + > +#include > +#include > +#include > + > +/** > + Invalidates the entire instruction cache in cache coherency domain of the > + calling CPU. > + > +**/ > +VOID > +EFIAPI > +InvalidateInstructionCache ( > + VOID > + ) > +{ > + RiscVInvdInstCacheAsm (); > +} > + > +/** > + Invalidates a range of instruction cache lines in the cache coherency domain > + of the calling CPU. > + > + Invalidates the instruction cache lines specified by Address and Length. If > + Address is not aligned on a cache line boundary, then entire instruction > + cache line containing Address is invalidated. If Address + Length is not > + aligned on a cache line boundary, then the entire instruction cache line > + containing Address + Length -1 is invalidated. This function may choose to > + invalidate the entire instruction cache if that is more efficient than > + invalidating the specified range. If Length is 0, then no instruction cache > + lines are invalidated. Address is returned. > + > + If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT(). > + > + @param Address The base address of the instruction cache lines to > + invalidate. If the CPU is in a physical addressing mode, then > + Address is a physical address. If the CPU is in a virtual > + addressing mode, then Address is a virtual address. > + > + @param Length The number of bytes to invalidate from the instruction cache. > + > + @return Address. > + > +**/ > +VOID * > +EFIAPI > +InvalidateInstructionCacheRange ( > + IN VOID *Address, > + IN UINTN Length > + ) > +{ > + DEBUG((DEBUG_ERROR, "%a:RISC-V unsupported function.\n", __FUNCTION__)); > + //ASSERT(FALSE); I'm OK with all of the unimplemented functions asserting false, but not with them all having a commented out ASSERT in them. Please either uncomment all of them or delete all of them. / Leif > + return Address; > +} > + > +/** > + Writes back and invalidates the entire data cache in cache coherency domain > + of the calling CPU. > + > + Writes back and invalidates the entire data cache in cache coherency domain > + of the calling CPU. This function guarantees that all dirty cache lines are > + written back to system memory, and also invalidates all the data cache lines > + in the cache coherency domain of the calling CPU. > + > +**/ > +VOID > +EFIAPI > +WriteBackInvalidateDataCache ( > + VOID > + ) > +{ > + DEBUG((DEBUG_ERROR, "%a:RISC-V unsupported function.\n", __FUNCTION__)); > + //ASSERT(FALSE); > +} > + > +/** > + Writes back and invalidates a range of data cache lines in the cache > + coherency domain of the calling CPU. > + > + Writes back and invalidates the data cache lines specified by Address and > + Length. If Address is not aligned on a cache line boundary, then entire data > + cache line containing Address is written back and invalidated. If Address + > + Length is not aligned on a cache line boundary, then the entire data cache > + line containing Address + Length -1 is written back and invalidated. This > + function may choose to write back and invalidate the entire data cache if > + that is more efficient than writing back and invalidating the specified > + range. If Length is 0, then no data cache lines are written back and > + invalidated. Address is returned. > + > + If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT(). > + > + @param Address The base address of the data cache lines to write back and > + invalidate. If the CPU is in a physical addressing mode, then > + Address is a physical address. If the CPU is in a virtual > + addressing mode, then Address is a virtual address. > + @param Length The number of bytes to write back and invalidate from the > + data cache. > + > + @return Address of cache invalidation. > + > +**/ > +VOID * > +EFIAPI > +WriteBackInvalidateDataCacheRange ( > + IN VOID *Address, > + IN UINTN Length > + ) > +{ > + DEBUG((DEBUG_ERROR, "%a:RISC-V unsupportted function.\n", __FUNCTION__)); > + //ASSERT(FALSE); > + return Address; > +} > + > +/** > + Writes back the entire data cache in cache coherency domain of the calling > + CPU. > + > + Writes back the entire data cache in cache coherency domain of the calling > + CPU. This function guarantees that all dirty cache lines are written back to > + system memory. This function may also invalidate all the data cache lines in > + the cache coherency domain of the calling CPU. > + > +**/ > +VOID > +EFIAPI > +WriteBackDataCache ( > + VOID > + ) > +{ > + DEBUG((DEBUG_ERROR, "%a:RISC-V unsupportted function.\n", __FUNCTION__)); > + //ASSERT(FALSE); > +} > + > +/** > + Writes back a range of data cache lines in the cache coherency domain of the > + calling CPU. > + > + Writes back the data cache lines specified by Address and Length. If Address > + is not aligned on a cache line boundary, then entire data cache line > + containing Address is written back. If Address + Length is not aligned on a > + cache line boundary, then the entire data cache line containing Address + > + Length -1 is written back. This function may choose to write back the entire > + data cache if that is more efficient than writing back the specified range. > + If Length is 0, then no data cache lines are written back. This function may > + also invalidate all the data cache lines in the specified range of the cache > + coherency domain of the calling CPU. Address is returned. > + > + If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT(). > + > + @param Address The base address of the data cache lines to write back. If > + the CPU is in a physical addressing mode, then Address is a > + physical address. If the CPU is in a virtual addressing > + mode, then Address is a virtual address. > + @param Length The number of bytes to write back from the data cache. > + > + @return Address of cache written in main memory. > + > +**/ > +VOID * > +EFIAPI > +WriteBackDataCacheRange ( > + IN VOID *Address, > + IN UINTN Length > + ) > +{ > + DEBUG((DEBUG_ERROR, "%a:RISC-V unsupportted function.\n", __FUNCTION__)); > + //ASSERT(FALSE); > + return Address; > +} > + > +/** > + Invalidates the entire data cache in cache coherency domain of the calling > + CPU. > + > + Invalidates the entire data cache in cache coherency domain of the calling > + CPU. This function must be used with care because dirty cache lines are not > + written back to system memory. It is typically used for cache diagnostics. If > + the CPU does not support invalidation of the entire data cache, then a write > + back and invalidate operation should be performed on the entire data cache. > + > +**/ > +VOID > +EFIAPI > +InvalidateDataCache ( > + VOID > + ) > +{ > + RiscVInvdDataCacheAsm (); > +} > + > +/** > + Invalidates a range of data cache lines in the cache coherency domain of the > + calling CPU. > + > + Invalidates the data cache lines specified by Address and Length. If Address > + is not aligned on a cache line boundary, then entire data cache line > + containing Address is invalidated. If Address + Length is not aligned on a > + cache line boundary, then the entire data cache line containing Address + > + Length -1 is invalidated. This function must never invalidate any cache lines > + outside the specified range. If Length is 0, then no data cache lines are > + invalidated. Address is returned. This function must be used with care > + because dirty cache lines are not written back to system memory. It is > + typically used for cache diagnostics. If the CPU does not support > + invalidation of a data cache range, then a write back and invalidate > + operation should be performed on the data cache range. > + > + If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT(). > + > + @param Address The base address of the data cache lines to invalidate. If > + the CPU is in a physical addressing mode, then Address is a > + physical address. If the CPU is in a virtual addressing mode, > + then Address is a virtual address. > + @param Length The number of bytes to invalidate from the data cache. > + > + @return Address. > + > +**/ > +VOID * > +EFIAPI > +InvalidateDataCacheRange ( > + IN VOID *Address, > + IN UINTN Length > + ) > +{ > + DEBUG((DEBUG_ERROR, "%a:RISC-V unsupportted function.\n", __FUNCTION__)); > + //ASSERT(FALSE); > + return Address; > +} > -- > 2.7.4 > > > >