From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id A8158941AB6 for ; Sun, 29 Oct 2023 14:46:32 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=SoRU3sqTTH7efT5/VQucpSxhl/j9l2AB1MoIvwsfzNU=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1698590791; v=1; b=EqITu6DFzy1BvF5Ek2PlsEnqr9Q2nLTwuDfwyhlt6/khqH5BvEbln2ZuzY75WFEvaTw3MkPO VQF0q7rT3IJM1Hg1mqK0n+EwWDcHFqU863PloOUg/be0KIhxluZIkYyO3OU3DLJ69EdsU/5WT3o 8M8urTlZDK6CBDDcS3G4H72M= X-Received: by 127.0.0.2 with SMTP id 98TEYY7687511xptC4oRaH4b; Sun, 29 Oct 2023 07:46:31 -0700 X-Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by mx.groups.io with SMTP id smtpd.web10.73332.1698590790685511867 for ; Sun, 29 Oct 2023 07:46:30 -0700 X-Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-28016496133so1578703a91.0 for ; Sun, 29 Oct 2023 07:46:30 -0700 (PDT) X-Gm-Message-State: DfhvICxVtQ6YIA6Gw6IbXqmxx7686176AA= X-Google-Smtp-Source: AGHT+IEa1bRtNHb/p4mryexd+alIfW9gzYzIsIN3qnSAqgERt8AVrq7LSQvourqbDxYCNbx5yqFHvQ== X-Received: by 2002:a17:90b:fd4:b0:27d:6d9c:6964 with SMTP id gd20-20020a17090b0fd400b0027d6d9c6964mr6871850pjb.26.1698590790018; Sun, 29 Oct 2023 07:46:30 -0700 (PDT) X-Received: from dhaval.. ([171.76.85.25]) by smtp.gmail.com with ESMTPSA id pt11-20020a17090b3d0b00b0027d15bd9fa2sm3783336pjb.35.2023.10.29.07.46.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Oct 2023 07:46:29 -0700 (PDT) From: "Dhaval Sharma" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Sunil V L , Daniel Schaefer , Laszlo Ersek Subject: [edk2-devel] [PATCH v7 3/5] MdePkg: Implement RISC-V Cache Management Operations Date: Sun, 29 Oct 2023 20:16:11 +0530 Message-Id: <20231029144613.150580-4-dhaval@rivosinc.com> In-Reply-To: <20231029144613.150580-1-dhaval@rivosinc.com> References: <20231029144613.150580-1-dhaval@rivosinc.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,dhaval@rivosinc.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=EqITu6DF; dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io Implement Cache Management Operations (CMO) defined by RISC-V spec https://github.com/riscv/riscv-CMOs. Notes: 1. CMO only supports block based Operations. Meaning cache flush/invd/clean Operations are not available for the entire range. In that case we fallback on fence.i instructions. 2. Operations are implemented using Opcodes to make them compiler independent. binutils 2.39+ compilers support CMO instructions. Test: 1. Ensured correct instructions are refelecting in asm 2. Not able to verify actual instruction in HW as Qemu ignores any actual cache operations. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Sunil V L Cc: Daniel Schaefer Cc: Laszlo Ersek Signed-off-by: Dhaval Sharma Reviewed-by: Laszlo Ersek --- Notes: V7: - Modify instruction names as per feedback from V6 - Added RB V6: - Implement Cache management instructions in Baselib MdePkg/Library/BaseLib/BaseLib.inf | 2 +- MdePkg/Include/Library/BaseLib.h | 33 +++= +++++++++++++++++ MdePkg/Include/RiscV64/RiscVasm.inc | 19 +++= ++++++++ MdePkg/Library/BaseLib/RiscV64/{FlushCache.S =3D> RiscVCacheMgmt.S} | 17 += +++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/Ba= seLib.inf index 03c7b02e828b..53389389448c 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -400,7 +400,7 @@ [Sources.RISCV64] RiscV64/RiscVCpuBreakpoint.S | GCC=0D RiscV64/RiscVCpuPause.S | GCC=0D RiscV64/RiscVInterrupt.S | GCC=0D - RiscV64/FlushCache.S | GCC=0D + RiscV64/RiscVCacheMgmt.S | GCC=0D RiscV64/CpuScratch.S | GCC=0D RiscV64/ReadTimer.S | GCC=0D RiscV64/RiscVMmu.S | GCC=0D diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index d4b56a9601da..c42cc165dc82 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -226,6 +226,39 @@ RiscVInvalidateDataCacheAsmFence ( VOID=0D );=0D =0D +/**=0D + RISC-V flush cache block. Atomically perform a clean operation=0D + followed by an invalidate operation=0D +=0D +**/=0D +VOID=0D +EFIAPI=0D +RiscVCpuCacheFlushAsmCmo (=0D + IN UINTN=0D + );=0D +=0D +/**=0D +Perform a write transfer to another cache or to memory if the=0D +data in the copy of the cache block have been modified by a store=0D +operation=0D +=0D +**/=0D +VOID=0D +EFIAPI=0D +RiscVCpuCacheCleanAsmCmo (=0D + IN UINTN=0D + );=0D +=0D +/**=0D +Deallocate the copy of the cache block=0D +=0D +**/=0D +VOID=0D +EFIAPI=0D +RiscVCpuCacheInvalAsmCmo (=0D + IN UINTN=0D + );=0D +=0D #endif // defined (MDE_CPU_RISCV64)=0D =0D #if defined (MDE_CPU_LOONGARCH64)=0D diff --git a/MdePkg/Include/RiscV64/RiscVasm.inc b/MdePkg/Include/RiscV64/R= iscVasm.inc new file mode 100644 index 000000000000..29de7358855c --- /dev/null +++ b/MdePkg/Include/RiscV64/RiscVasm.inc @@ -0,0 +1,19 @@ +/*=0D + *=0D + * RISC-V cache operation encoding.=0D + * Copyright (c) 2023, Rivos Inc. All rights reserved.
=0D + * SPDX-License-Identifier: BSD-2-Clause-Patent=0D + *=0D + */=0D +=0D +.macro RISCVCMOFLUSH=0D + .word 0x25200f=0D +.endm=0D +=0D +.macro RISCVCMOINVALIDATE=0D + .word 0x05200f=0D +.endm=0D +=0D +.macro RISCVCMOCLEAN=0D + .word 0x15200f=0D +.endm=0D diff --git a/MdePkg/Library/BaseLib/RiscV64/FlushCache.S b/MdePkg/Library/B= aseLib/RiscV64/RiscVCacheMgmt.S similarity index 56% rename from MdePkg/Library/BaseLib/RiscV64/FlushCache.S rename to MdePkg/Library/BaseLib/RiscV64/RiscVCacheMgmt.S index e0eea0b5fb25..3c7be3229e3b 100644 --- a/MdePkg/Library/BaseLib/RiscV64/FlushCache.S +++ b/MdePkg/Library/BaseLib/RiscV64/RiscVCacheMgmt.S @@ -3,10 +3,12 @@ // RISC-V cache operation.=0D //=0D // Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
=0D +// Copyright (c) 2023, Rivos Inc. All rights reserved.
=0D //=0D // SPDX-License-Identifier: BSD-2-Clause-Patent=0D //=0D //------------------------------------------------------------------------= ------=0D +.include "RiscVasm.inc"=0D =0D .align 3=0D ASM_GLOBAL ASM_PFX(RiscVInvalidateInstCacheAsmFence)=0D @@ -19,3 +21,18 @@ ASM_PFX(RiscVInvalidateInstCacheAsmFence): ASM_PFX(RiscVInvalidateDataCacheAsmFence):=0D fence=0D ret=0D +=0D +ASM_GLOBAL ASM_PFX (RiscVCpuCacheFlushAsmCmo)=0D +ASM_PFX (RiscVCpuCacheFlushAsmCmo):=0D + RISCVCMOFLUSH=0D + ret=0D +=0D +ASM_GLOBAL ASM_PFX (RiscVCpuCacheCleanAsmCmo)=0D +ASM_PFX (RiscVCpuCacheCleanAsmCmo):=0D + RISCVCMOCLEAN=0D + ret=0D +=0D +ASM_GLOBAL ASM_PFX (RiscVCpuCacheInvalAsmCmo)=0D +ASM_PFX (RiscVCpuCacheInvalAsmCmo):=0D + RISCVCMOINVALIDATE=0D + ret=0D --=20 2.39.2 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#110265): https://edk2.groups.io/g/devel/message/110265 Mute This Topic: https://groups.io/mt/102256466/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-