MdePkg/BaseLib: Add SpeculationBarrier implementation for RiscV64

Implement the SpeculationBarrier with implementations consisting of
fence instruction which provides finer-grain memory orderings.
Perform Data Barrier in RiscV: fence rw,rw
Perform Instruction Barrier in RiscV: fence.i; fence r,r
More detail is in Appendix A: RVWMO Explanatory Material in
https://github.com/riscv/riscv-isa-manual

This API is first introduced in the below commits for IA32 and x64
d9f1cac51b
e83d841fdc
and below the commit for ARM and AArch64 implementation
c0959b4426

This commit is to add the RiscV64 implementation which will be used by
variable service under Variable/RuntimeDxe

Cc: Andrei Warkentin <andrei.warkentin@intel.com>
Cc: Evan Chai <evan.chai@intel.com>
Cc: Sunil V L <sunilvl@ventanamicro.com>
Cc: Tuan Phan <tphan@ventanamicro.com>
Signed-off-by: Yong Li <yong.li@intel.com>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
This commit is contained in:
Yong Li 2023-04-20 12:36:40 +08:00 committed by mergify[bot]
parent d189de3b0a
commit ded0b489af
2 changed files with 35 additions and 0 deletions

View File

@ -404,6 +404,7 @@
RiscV64/CpuScratch.S | GCC
RiscV64/ReadTimer.S | GCC
RiscV64/RiscVMmu.S | GCC
RiscV64/SpeculationBarrier.S | GCC
[Sources.LOONGARCH64]
Math64.c

View File

@ -0,0 +1,34 @@
##------------------------------------------------------------------------------
#
# SpeculationBarrier() for RISCV64
#
# Copyright (c) 2023, Intel Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##------------------------------------------------------------------------------
.text
.p2align 2
ASM_GLOBAL ASM_PFX(SpeculationBarrier)
#/**
# Uses as a barrier to stop speculative execution.
#
# Ensures that no later instruction will execute speculatively, until all prior
# instructions have completed.
#
#**/
#VOID
#EFIAPI
#SpeculationBarrier (
# VOID
# );
#
ASM_PFX(SpeculationBarrier):
fence rw,rw
fence.i
fence r,r
ret