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 125DD7803E7 for ; Tue, 24 Oct 2023 12:39:32 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=1rfG18th9RtRS/u8QvNYKwj/3ztLhg5k/gDm7cWR1Is=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1698151171; v=1; b=esy+aB/3+XHM5Z1K4qQnQNtabENBWbB1vpngoLkVCQdbbWGsZW+7VFE/o5Nr6Uk/DpB9x1nV HqbMyHAh4XspxeY1O1BfWsVr2l7mZMW9iIDyb5UWlHTvxQVtKz4RE0nUAwrYqw5swWVtLIYwi95 D5sc1/GHE9RueWYka3Yv19a8= X-Received: by 127.0.0.2 with SMTP id 5XxhYY7687511xo8yWPAH4rm; Tue, 24 Oct 2023 05:39:31 -0700 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web10.146582.1698151171090481221 for ; Tue, 24 Oct 2023 05:39:31 -0700 X-Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-391-_qzYKWs1Ma2vJKaewTAfOw-1; Tue, 24 Oct 2023 08:39:20 -0400 X-MC-Unique: _qzYKWs1Ma2vJKaewTAfOw-1 X-Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9358B2824775; Tue, 24 Oct 2023 12:39:19 +0000 (UTC) X-Received: from [10.39.195.39] (unknown [10.39.195.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 19A372026D4C; Tue, 24 Oct 2023 12:39:17 +0000 (UTC) Message-ID: <76d2c541-0c59-eae7-3efb-bc450f806b29@redhat.com> Date: Tue, 24 Oct 2023 14:39:16 +0200 MIME-Version: 1.0 Subject: Re: [edk2-devel] [PATCH v6 3/5] MdePkg: Implement RISC-V Cache Management Operations To: devel@edk2.groups.io, dhaval@rivosinc.com Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Sunil V L , Daniel Schaefer References: <20231021173314.19363-1-dhaval@rivosinc.com> <20231021173314.19363-4-dhaval@rivosinc.com> From: "Laszlo Ersek" In-Reply-To: <20231021173314.19363-4-dhaval@rivosinc.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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,lersek@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: ovzqKsLVIn0GGGDbBi5uXQV5x7686176AA= Content-Language: en-US Content-Type: text/plain; charset=UTF-8 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="esy+aB/3"; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.com (policy=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 On 10/21/23 19:33, Dhaval Sharma wrote: > Implement Cache Management Operations (CMO) defined by > RISC-V spec https://github.com/riscv/riscv-CMOs. >=20 > 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. >=20 > 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. >=20 > Cc: Michael D Kinney > Cc: Liming Gao > Cc: Zhiguang Liu > Cc: Sunil V L > Cc: Daniel Schaefer > Cc: Laszlo Ersek >=20 > Signed-off-by: Dhaval Sharma > --- >=20 > Notes: > V1: > - Implement Cache management instructions in Baselib >=20 > 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(-) >=20 > diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/= BaseLib.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 > RiscV64/RiscVCpuPause.S | GCC > RiscV64/RiscVInterrupt.S | GCC > - RiscV64/FlushCache.S | GCC > + RiscV64/RiscVCacheMgmt.S | GCC > RiscV64/CpuScratch.S | GCC > RiscV64/ReadTimer.S | GCC > RiscV64/RiscVMmu.S | GCC > diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Ba= seLib.h > index d4b56a9601da..60d60602b876 100644 > --- a/MdePkg/Include/Library/BaseLib.h > +++ b/MdePkg/Include/Library/BaseLib.h > @@ -226,6 +226,39 @@ RiscVInvalidateDataCacheAsmFence ( > VOID > ); > =20 > +/** > + RISC-V flush cache block. Atomically perform a clean operation > + followed by an invalidate operation > + > +**/ > +VOID > +EFIAPI > +RiscVCpuCacheFlushAsmCbo ( > + IN UINTN > + ); > + > +/** > +Perform a write transfer to another cache or to memory if the > +data in the copy of the cache block have been modified by a store > +operation > + > +**/ > +VOID > +EFIAPI > +RiscVCpuCacheCleanAsmCbo ( > + IN UINTN > + ); > + > +/** > +Deallocate the copy of the cache block > + > +**/ > +VOID > +EFIAPI > +RiscVCpuCacheInvalAsmCbo ( > + IN UINTN > + ); > + > #endif // defined (MDE_CPU_RISCV64) > =20 > #if defined (MDE_CPU_LOONGARCH64) > diff --git a/MdePkg/Include/RiscV64/RiscVasm.inc b/MdePkg/Include/RiscV64= /RiscVasm.inc > new file mode 100644 > index 000000000000..6f418232d507 > --- /dev/null > +++ b/MdePkg/Include/RiscV64/RiscVasm.inc > @@ -0,0 +1,19 @@ > +/* > + * > + * RISC-V cache operation encoding. > + * Copyright (c) 2023, Rivos Inc. All rights reserved.
> + * SPDX-License-Identifier: BSD-2-Clause-Patent > + * > + */ > + > +.macro RISCVCBOFLSH > + .word 0x25200f > +.endm > + > +.macro RISCVCBOINVD > + .word 0x05200f > +.endm > + > +.macro RISCVCBOCLEN > + .word 0x15200f > +.endm > diff --git a/MdePkg/Library/BaseLib/RiscV64/FlushCache.S b/MdePkg/Library= /BaseLib/RiscV64/RiscVCacheMgmt.S > similarity index 57% > rename from MdePkg/Library/BaseLib/RiscV64/FlushCache.S > rename to MdePkg/Library/BaseLib/RiscV64/RiscVCacheMgmt.S > index e0eea0b5fb25..fe3943ae3f7c 100644 > --- a/MdePkg/Library/BaseLib/RiscV64/FlushCache.S > +++ b/MdePkg/Library/BaseLib/RiscV64/RiscVCacheMgmt.S > @@ -3,10 +3,12 @@ > // RISC-V cache operation. > // > // Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All ri= ghts reserved.
> +// Copyright (c) 2023, Rivos Inc. All rights reserved.
> // > // SPDX-License-Identifier: BSD-2-Clause-Patent > // > //----------------------------------------------------------------------= -------- > +.include "RiscVasm.inc" > =20 > .align 3 > ASM_GLOBAL ASM_PFX(RiscVInvalidateInstCacheAsmFence) > @@ -19,3 +21,18 @@ ASM_PFX(RiscVInvalidateInstCacheAsmFence): > ASM_PFX(RiscVInvalidateDataCacheAsmFence): > fence > ret > + > +ASM_GLOBAL ASM_PFX (RiscVCpuCacheFlushAsmCbo) > +ASM_PFX (RiscVCpuCacheFlushAsmCbo): > + RISCVCBOFLSH > + ret > + > +ASM_GLOBAL ASM_PFX (RiscVCpuCacheCleanAsmCbo) > +ASM_PFX (RiscVCpuCacheCleanAsmCbo): > + RISCVCBOCLEN > + ret > + > +ASM_GLOBAL ASM_PFX (RiscVCpuCacheInvalAsmCbo) > +ASM_PFX (RiscVCpuCacheInvalAsmCbo): > + RISCVCBOINVD > + ret I've not validated the assembly insn encodings. I also think that *FLSH, *CLEN, and *INVD could just as well be FLUSH, CLEAN, and INVALIDATE. But those are really minor IMO. Reviewed-by: Laszlo Ersek -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#110003): https://edk2.groups.io/g/devel/message/110003 Mute This Topic: https://groups.io/mt/102103780/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/19134562= 12/xyzzy [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-