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 EA788AC0CB0 for ; Mon, 4 Dec 2023 08:30:54 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=Qp/uohINZhpf3VRSGgpt5Fe3FSp7tXsi7RkbdMcpU1Y=; 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=1701678653; v=1; b=feM3+QtjSssxX3MmhRKLZwEccLe1HDpa24v09TUC8HG2sBXxTSLwpa+OYVUsKMzYbLNSAjYj 5xn5KMyB7mMQMkjPcI80Bv0l3qjk49CkMAovkfZ5MlGvy1oJ3emi3uu9mDKhiyCAbNwx/gWg9/o egn6E7BNgNbpTBdVi7iYqv9U= X-Received: by 127.0.0.2 with SMTP id A6ELYY7687511xfoTD6QUq0j; Mon, 04 Dec 2023 00:30:53 -0800 X-Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by mx.groups.io with SMTP id smtpd.web11.64452.1701678653088409768 for ; Mon, 04 Dec 2023 00:30:53 -0800 X-Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1d0b2752dc6so2494525ad.3 for ; Mon, 04 Dec 2023 00:30:53 -0800 (PST) X-Gm-Message-State: xHwStRLpGq9VKYpxcAdzR7kfx7686176AA= X-Google-Smtp-Source: AGHT+IHzVsth0AgiX9iL7gDI2rXHLB2jJPXmjk1ZsUAjGmoJTXiNgVh0lq6+JzaogrNc14uGFep2BQ== X-Received: by 2002:a17:903:264a:b0:1d0:6ffd:9e20 with SMTP id je10-20020a170903264a00b001d06ffd9e20mr2960484plb.114.1701678652241; Mon, 04 Dec 2023 00:30:52 -0800 (PST) X-Received: from dhaval.blr.rivosinc.com ([49.249.129.34]) by smtp.gmail.com with ESMTPSA id h21-20020a170902f7d500b001d058ad8770sm5754211plw.306.2023.12.04.00.30.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 00:30:51 -0800 (PST) From: "Dhaval Sharma" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Sunil V L , Daniel Schaefer , Laszlo Ersek , jingyulee98@gmail.com Subject: [edk2-devel] [PATCH v9 3/5] MdePkg: Implement RISC-V Cache Management Operations Date: Mon, 4 Dec 2023 13:59:48 +0530 Message-Id: <20231204082950.96914-4-dhaval@rivosinc.com> In-Reply-To: <20231204082950.96914-1-dhaval@rivosinc.com> References: <20231204082950.96914-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=feM3+Qtj; 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. Qemu implements basic support for CMO operations in that it allwos instructions without exceptions. Verified it works properly in that sense. 3. SG2042Pkg implements CMO-like instructions. It was verified that CpuFlushCpuDataCache works fine. This more of less confirms that framework is alright. 4. TODO: Once Silicon is available with exact instructions, we will further verify this. 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 Reviewed-by: Sunil V L Reviewed-by: Jingyu Li --- Notes: v8: - Add *asm* postfix to cmo functions - Add reviewed by tags 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 d80e27285424..47424709cd72 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -226,6 +226,39 @@ RiscVInvalidateDataCacheFenceAsm ( 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 +RiscVCpuCacheFlushCmoAsm (=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 +RiscVCpuCacheCleanCmoAsm (=0D + IN UINTN=0D + );=0D +=0D +/**=0D +Deallocate the copy of the cache block=0D +=0D +**/=0D +VOID=0D +EFIAPI=0D +RiscVCpuCacheInvalCmoAsm (=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 8cfb85097996..4752aa72d95e 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(RiscVInvalidateInstCacheFenceAsm)=0D @@ -19,3 +21,18 @@ ASM_PFX(RiscVInvalidateInstCacheFenceAsm): ASM_PFX(RiscVInvalidateDataCacheFenceAsm):=0D fence=0D ret=0D +=0D +ASM_GLOBAL ASM_PFX (RiscVCpuCacheFlushCmoAsm)=0D +ASM_PFX (RiscVCpuCacheFlushCmoAsm):=0D + RISCVCMOFLUSH=0D + ret=0D +=0D +ASM_GLOBAL ASM_PFX (RiscVCpuCacheCleanCmoAsm)=0D +ASM_PFX (RiscVCpuCacheCleanCmoAsm):=0D + RISCVCMOCLEAN=0D + ret=0D +=0D +ASM_GLOBAL ASM_PFX (RiscVCpuCacheInvalCmoAsm)=0D +ASM_PFX (RiscVCpuCacheInvalCmoAsm):=0D + RISCVCMOINVALIDATE=0D + ret=0D --=20 2.39.2 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#112021): https://edk2.groups.io/g/devel/message/112021 Mute This Topic: https://groups.io/mt/102967057/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-