public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v1 0/9] MdePkg changes for RISC-V edk2 port
@ 2020-04-10  7:21 Abner Chang
  2020-04-10  7:21 ` [PATCH v1 1/9] MdePkg: RISC-V RV64 binding in MdePkg Abner Chang
                   ` (8 more replies)
  0 siblings, 9 replies; 20+ messages in thread
From: Abner Chang @ 2020-04-10  7:21 UTC (permalink / raw)
  To: devel; +Cc: abner.chang

MdePkg modules and definitionsfor RISC-V architecture on edk2.

BZ for entire RISC-V edk2 port,
https://bugzilla.tianocore.org/show_bug.cgi?id=2672

These commits are verified by below PR,
https://github.com/tianocore/edk2/pull/512

Abner Chang (9):
  MdePkg: RISC-V RV64 binding in MdePkg
  MdePkg/Include: RISC-V definitions.
  MdePkg/BaseLib: BaseLib for RISC-V RV64 Processor.
  MdePkg/BaseCacheMaintenanceLib: RISC-V cache maintenance
    implementation.
  MdePkg/BaseIoLibIntrinsic: Rename IoLibArm.c=>IoLibNoIo.c
  MdePkg/BasePeCoff: Add RISC-V PE/Coff related code.
  MdePkg/BaseCpuLib: RISC-V Base CPU library implementation.
  MdePkg/BaseSynchronizationLib: RISC-V cache related code.
  MdePkg/BaseSafeIntLib: Add RISCV64 arch for BaseSafeIntLib.

 MdePkg/MdePkg.dec                             |   5 +-
 MdePkg/MdePkg.dsc                             |   3 +-
 .../BaseCacheMaintenanceLib.inf               |   4 +
 MdePkg/Library/BaseCpuLib/BaseCpuLib.inf      |   6 +-
 .../BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf |  12 +-
 MdePkg/Library/BaseLib/BaseLib.inf            |  18 +-
 .../Library/BasePeCoffLib/BasePeCoffLib.inf   |   5 +
 .../Library/BaseSafeIntLib/BaseSafeIntLib.inf |   6 +-
 .../BaseSynchronizationLib.inf                |   5 +
 MdePkg/Include/IndustryStandard/PeImage.h     |  12 +
 MdePkg/Include/Library/BaseLib.h              |  26 ++
 MdePkg/Include/Protocol/DebugSupport.h        |  55 ++++
 MdePkg/Include/Protocol/PxeBaseCode.h         |   4 +
 MdePkg/Include/RiscV64/ProcessorBind.h        | 173 ++++++++++++
 MdePkg/Include/Uefi/UefiBaseType.h            |  13 +
 MdePkg/Include/Uefi/UefiSpec.h                |   5 +
 .../BasePeCoffLib/BasePeCoffLibInternals.h    |   9 +
 .../BaseCacheMaintenanceLib/RiscVCache.c      | 250 ++++++++++++++++++
 .../{IoLibArm.c => IoLibNoIo.c}               |   4 +-
 .../Library/BaseLib/RiscV64/CpuBreakpoint.c   |  27 ++
 MdePkg/Library/BaseLib/RiscV64/CpuPause.c     |  29 ++
 .../BaseLib/RiscV64/DisableInterrupts.c       |  24 ++
 .../BaseLib/RiscV64/EnableInterrupts.c        |  25 ++
 .../BaseLib/RiscV64/GetInterruptState.c       |  35 +++
 .../BaseLib/RiscV64/InternalSwitchStack.c     |  55 ++++
 MdePkg/Library/BaseLib/RiscV64/LongJump.c     |  32 +++
 MdePkg/Library/BasePeCoffLib/BasePeCoff.c     |   3 +-
 .../BasePeCoffLib/RiscV/PeCoffLoaderEx.c      | 133 ++++++++++
 MdePkg/Library/BaseCpuLib/BaseCpuLib.uni      |   5 +-
 MdePkg/Library/BaseCpuLib/RiscV/Cpu.S         |  19 ++
 MdePkg/Library/BaseLib/RiscV64/FlushCache.S   |  21 ++
 .../BaseLib/RiscV64/RiscVCpuBreakpoint.S      |  14 +
 .../Library/BaseLib/RiscV64/RiscVCpuPause.S   |  14 +
 .../Library/BaseLib/RiscV64/RiscVInterrupt.S  |  32 +++
 .../BaseLib/RiscV64/RiscVSetJumpLongJump.S    |  55 ++++
 .../Library/BasePeCoffLib/BasePeCoffLib.uni   |   2 +
 .../RiscV64/SynchronizationAsm.S              |  78 ++++++
 37 files changed, 1204 insertions(+), 14 deletions(-)
 create mode 100644 MdePkg/Include/RiscV64/ProcessorBind.h
 create mode 100644 MdePkg/Library/BaseCacheMaintenanceLib/RiscVCache.c
 rename MdePkg/Library/BaseIoLibIntrinsic/{IoLibArm.c => IoLibNoIo.c} (94%)
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/CpuBreakpoint.c
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/CpuPause.c
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/DisableInterrupts.c
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/EnableInterrupts.c
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/GetInterruptState.c
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/LongJump.c
 create mode 100644 MdePkg/Library/BasePeCoffLib/RiscV/PeCoffLoaderEx.c
 create mode 100644 MdePkg/Library/BaseCpuLib/RiscV/Cpu.S
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/FlushCache.S
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/RiscVCpuBreakpoint.S
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/RiscVCpuPause.S
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/RiscVSetJumpLongJump.S
 create mode 100644 MdePkg/Library/BaseSynchronizationLib/RiscV64/SynchronizationAsm.S

-- 
2.25.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v1 1/9] MdePkg: RISC-V RV64 binding in MdePkg
  2020-04-10  7:21 [PATCH v1 0/9] MdePkg changes for RISC-V edk2 port Abner Chang
@ 2020-04-10  7:21 ` Abner Chang
  2020-04-21  6:30   ` [edk2-devel] " Zhiguang Liu
  2020-04-10  7:21 ` [PATCH v1 2/9] MdePkg/Include: RISC-V definitions Abner Chang
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Abner Chang @ 2020-04-10  7:21 UTC (permalink / raw)
  To: devel
  Cc: abner.chang, Gilbert Chen, Leif Lindholm, Michael D Kinney,
	Liming Gao

Add RISCV64 sections in MdePkg.dec and RISCV64 ProcessorBind.h

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Co-authored-by: Gilbert Chen <gilbert.chen@hpe.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
---
 MdePkg/MdePkg.dec                      |   5 +-
 MdePkg/MdePkg.dsc                      |   3 +-
 MdePkg/Include/RiscV64/ProcessorBind.h | 173 +++++++++++++++++++++++++
 3 files changed, 179 insertions(+), 2 deletions(-)
 create mode 100644 MdePkg/Include/RiscV64/ProcessorBind.h

diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index 6c37c2181c..0b9c4bc40a 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -6,7 +6,7 @@
 #
 # Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>
 # Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-# (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
+# (C) Copyright 2016 - 2020 Hewlett Packard Enterprise Development LP<BR>
 #
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -39,6 +39,9 @@
 [Includes.AARCH64]
   Include/AArch64
 
+[Includes.RISCV64]
+  Include/RiscV64
+
 [LibraryClasses]
   ##  @libraryclass  Provides most usb APIs to support the Hid requests defined in Usb Hid 1.1 spec
   #                  and the standard requests defined in Usb 1.1 spec.
diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc
index 2b2d5981e8..6cd38e7ec3 100644
--- a/MdePkg/MdePkg.dsc
+++ b/MdePkg/MdePkg.dsc
@@ -3,6 +3,7 @@
 #
 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
 # Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
+# (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
 #
 #    SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -14,7 +15,7 @@
   PLATFORM_VERSION               = 1.08
   DSC_SPECIFICATION              = 0x00010005
   OUTPUT_DIRECTORY               = Build/Mde
-  SUPPORTED_ARCHITECTURES        = IA32|X64|EBC|ARM|AARCH64
+  SUPPORTED_ARCHITECTURES        = IA32|X64|EBC|ARM|AARCH64|RISCV64
   BUILD_TARGETS                  = DEBUG|RELEASE|NOOPT
   SKUID_IDENTIFIER               = DEFAULT
 
diff --git a/MdePkg/Include/RiscV64/ProcessorBind.h b/MdePkg/Include/RiscV64/ProcessorBind.h
new file mode 100644
index 0000000000..2b11f041ea
--- /dev/null
+++ b/MdePkg/Include/RiscV64/ProcessorBind.h
@@ -0,0 +1,173 @@
+/** @file
+  Processor or Compiler specific defines and types for RISC-V
+
+  Copyright (c) 2016 - 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef PROCESSOR_BIND_H__
+#define PROCESSOR_BIND_H__
+
+///
+/// Define the processor type so other code can make processor based choices
+///
+#define MDE_CPU_RISCV64
+
+//
+// Make sure we are using the correct packing rules per EFI specification
+//
+#if !defined(__GNUC__)
+#pragma pack()
+#endif
+
+///
+/// 8-byte unsigned value
+///
+typedef unsigned long long  UINT64  __attribute__ ((aligned (8)));
+///
+/// 8-byte signed value
+///
+typedef long long           INT64  __attribute__ ((aligned (8)));
+///
+/// 4-byte unsigned value
+///
+typedef unsigned int        UINT32 __attribute__ ((aligned (4)));
+///
+/// 4-byte signed value
+///
+typedef int                 INT32  __attribute__ ((aligned (4)));
+///
+/// 2-byte unsigned value
+///
+typedef unsigned short      UINT16  __attribute__ ((aligned (2)));
+///
+/// 2-byte Character.  Unless otherwise specified all strings are stored in the
+/// UTF-16 encoding format as defined by Unicode 2.1 and ISO/IEC 10646 standards.
+///
+typedef unsigned short      CHAR16  __attribute__ ((aligned (2)));
+///
+/// 2-byte signed value
+///
+typedef short               INT16  __attribute__ ((aligned (2)));
+///
+/// Logical Boolean.  1-byte value containing 0 for FALSE or a 1 for TRUE.  Other
+/// values are undefined.
+///
+typedef unsigned char       BOOLEAN;
+///
+/// 1-byte unsigned value
+///
+typedef unsigned char       UINT8;
+///
+/// 1-byte Character
+///
+typedef char                CHAR8;
+///
+/// 1-byte signed value
+///
+typedef signed char         INT8;
+///
+/// Unsigned value of native width.  (4 bytes on supported 32-bit processor instructions,
+/// 8 bytes on supported 64-bit processor instructions)
+///
+typedef UINT64  UINTN __attribute__ ((aligned (8)));
+///
+/// Signed value of native width.  (4 bytes on supported 32-bit processor instructions,
+/// 8 bytes on supported 64-bit processor instructions)
+///
+typedef INT64   INTN __attribute__ ((aligned (8)));
+
+//
+// Processor specific defines
+//
+
+///
+/// A value of native width with the highest bit set.
+///
+#define MAX_BIT     0x8000000000000000ULL
+///
+/// A value of native width with the two highest bits set.
+///
+#define MAX_2_BITS  0xC000000000000000ULL
+
+///
+/// Maximum legal RV64 address
+///
+#define MAX_ADDRESS   0xFFFFFFFFFFFFFFFFULL
+
+///
+/// Maximum usable address at boot time (48 bits using 4 KB pages in Supervisor mode)
+///
+#define MAX_ALLOC_ADDRESS   0xFFFFFFFFFFFFULL
+
+///
+/// Maximum legal RISC-V INTN and UINTN values.
+///
+#define MAX_INTN   ((INTN)0x7FFFFFFFFFFFFFFFULL)
+#define MAX_UINTN  ((UINTN)0xFFFFFFFFFFFFFFFFULL)
+
+///
+/// The stack alignment required for RISC-V
+///
+#define CPU_STACK_ALIGNMENT   16
+
+///
+/// Page allocation granularity for RISC-V
+///
+#define DEFAULT_PAGE_ALLOCATION_GRANULARITY   (0x1000)
+#define RUNTIME_PAGE_ALLOCATION_GRANULARITY   (0x1000)
+
+//
+// Modifier to ensure that all protocol member functions and EFI intrinsics
+// use the correct C calling convention. All protocol member functions and
+// EFI intrinsics are required to modify their member functions with EFIAPI.
+//
+#ifdef EFIAPI
+  ///
+  /// If EFIAPI is already defined, then we use that definition.
+  ///
+#elif defined(__GNUC__)
+  ///
+  /// Define the standard calling convention regardless of optimization level
+  /// The GCC support assumes a GCC compiler that supports the EFI ABI. The EFI
+  /// ABI is much closer to the x64 Microsoft* ABI than standard x64 (x86-64)
+  /// GCC ABI. Thus a standard x64 (x86-64) GCC compiler can not be used for
+  /// x64. Warning the assembly code in the MDE x64 does not follow the correct
+  /// ABI for the standard x64 (x86-64) GCC.
+  ///
+  #define EFIAPI
+#else
+  ///
+  /// The default for a non Microsoft* or GCC compiler is to assume the EFI ABI
+  /// is the standard.
+  ///
+  #define EFIAPI
+#endif
+
+#if defined(__GNUC__)
+  ///
+  /// For GNU assembly code, .global or .globl can declare global symbols.
+  /// Define this macro to unify the usage.
+  ///
+  #define ASM_GLOBAL .globl
+#endif
+
+/**
+  Return the pointer to the first instruction of a function given a function pointer.
+  On x64 CPU architectures, these two pointer values are the same,
+  so the implementation of this macro is very simple.
+
+  @param  FunctionPointer   A pointer to a function.
+
+  @return The pointer to the first instruction of a function given a function pointer.
+
+**/
+#define FUNCTION_ENTRY_POINT(FunctionPointer) (VOID *)(UINTN)(FunctionPointer)
+
+#ifndef __USER_LABEL_PREFIX__
+#define __USER_LABEL_PREFIX__
+#endif
+
+#endif
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v1 2/9] MdePkg/Include: RISC-V definitions.
  2020-04-10  7:21 [PATCH v1 0/9] MdePkg changes for RISC-V edk2 port Abner Chang
  2020-04-10  7:21 ` [PATCH v1 1/9] MdePkg: RISC-V RV64 binding in MdePkg Abner Chang
@ 2020-04-10  7:21 ` Abner Chang
  2020-04-21  6:32   ` [edk2-devel] " Zhiguang Liu
  2020-04-10  7:21 ` [PATCH v1 3/9] MdePkg/BaseLib: BaseLib for RISC-V RV64 Processor Abner Chang
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Abner Chang @ 2020-04-10  7:21 UTC (permalink / raw)
  To: devel
  Cc: abner.chang, Gilbert Chen, Leif Lindholm, Michael D Kinney,
	Liming Gao

Add RISC-V processor related definitions.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Co-authored-by: Gilbert Chen <gilbert.chen@hpe.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
---
 MdePkg/Include/IndustryStandard/PeImage.h | 12 +++++
 MdePkg/Include/Protocol/DebugSupport.h    | 55 +++++++++++++++++++++++
 MdePkg/Include/Protocol/PxeBaseCode.h     |  4 ++
 MdePkg/Include/Uefi/UefiBaseType.h        | 13 ++++++
 MdePkg/Include/Uefi/UefiSpec.h            |  5 +++
 5 files changed, 89 insertions(+)

diff --git a/MdePkg/Include/IndustryStandard/PeImage.h b/MdePkg/Include/IndustryStandard/PeImage.h
index a3d9bbed75..9b267002a1 100644
--- a/MdePkg/Include/IndustryStandard/PeImage.h
+++ b/MdePkg/Include/IndustryStandard/PeImage.h
@@ -9,6 +9,8 @@
 
 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
+Portions Copyright (c) 2016 - 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -34,6 +36,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #define IMAGE_FILE_MACHINE_X64             0x8664
 #define IMAGE_FILE_MACHINE_ARMTHUMB_MIXED  0x01c2
 #define IMAGE_FILE_MACHINE_ARM64           0xAA64
+#define IMAGE_FILE_MACHINE_RISCV32         0x5032
+#define IMAGE_FILE_MACHINE_RISCV64         0x5064
+#define IMAGE_FILE_MACHINE_RISCV128        0x5128
 
 //
 // EXE file formats
@@ -493,6 +498,13 @@ typedef struct {
 #define EFI_IMAGE_REL_BASED_MIPS_JMPADDR16  9
 #define EFI_IMAGE_REL_BASED_DIR64           10
 
+///
+/// Relocation types of RISC-V processor.
+///
+#define EFI_IMAGE_REL_BASED_RISCV_HI20      5
+#define EFI_IMAGE_REL_BASED_RISCV_LOW12I    7
+#define EFI_IMAGE_REL_BASED_RISCV_LOW12S    8
+
 ///
 /// Line number format.
 ///
diff --git a/MdePkg/Include/Protocol/DebugSupport.h b/MdePkg/Include/Protocol/DebugSupport.h
index 800e7710e6..7fb1d3b3e4 100644
--- a/MdePkg/Include/Protocol/DebugSupport.h
+++ b/MdePkg/Include/Protocol/DebugSupport.h
@@ -7,6 +7,7 @@
 
 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
 Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>
+Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
 
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -603,6 +604,59 @@ typedef struct {
   UINT64  FAR;  // Fault Address Register
 } EFI_SYSTEM_CONTEXT_AARCH64;
 
+///
+/// RISC-V processor exception types.
+///
+#define EXCEPT_RISCV_INST_MISALIGNED              0
+#define EXCEPT_RISCV_INST_ACCESS_FAULT            1
+#define EXCEPT_RISCV_ILLEGAL_INST                 2
+#define EXCEPT_RISCV_BREAKPOINT                   3
+#define EXCEPT_RISCV_LOAD_ADDRESS_MISALIGNED      4
+#define EXCEPT_RISCV_LOAD_ACCESS_FAULT            5
+#define EXCEPT_RISCV_STORE_AMO_ADDRESS_MISALIGNED 6
+#define EXCEPT_RISCV_STORE_AMO_ACCESS_FAULT       7
+#define EXCEPT_RISCV_ENV_CALL_FROM_UMODE          8
+#define EXCEPT_RISCV_ENV_CALL_FROM_SMODE          9
+#define EXCEPT_RISCV_ENV_CALL_FROM_HMODE          10
+#define EXCEPT_RISCV_ENV_CALL_FROM_MMODE          11
+
+#define EXCEPT_RISCV_SOFTWARE_INT       0x0
+#define EXCEPT_RISCV_TIMER_INT          0x1
+
+typedef struct {
+  UINT64  X0;
+  UINT64  X1;
+  UINT64  X2;
+  UINT64  X3;
+  UINT64  X4;
+  UINT64  X5;
+  UINT64  X6;
+  UINT64  X7;
+  UINT64  X8;
+  UINT64  X9;
+  UINT64  X10;
+  UINT64  X11;
+  UINT64  X12;
+  UINT64  X13;
+  UINT64  X14;
+  UINT64  X15;
+  UINT64  X16;
+  UINT64  X17;
+  UINT64  X18;
+  UINT64  X19;
+  UINT64  X20;
+  UINT64  X21;
+  UINT64  X22;
+  UINT64  X23;
+  UINT64  X24;
+  UINT64  X25;
+  UINT64  X26;
+  UINT64  X27;
+  UINT64  X28;
+  UINT64  X29;
+  UINT64  X30;
+  UINT64  X31;
+} EFI_SYSTEM_CONTEXT_RISCV64;
 
 ///
 /// Universal EFI_SYSTEM_CONTEXT definition.
@@ -614,6 +668,7 @@ typedef union {
   EFI_SYSTEM_CONTEXT_IPF  *SystemContextIpf;
   EFI_SYSTEM_CONTEXT_ARM  *SystemContextArm;
   EFI_SYSTEM_CONTEXT_AARCH64  *SystemContextAArch64;
+  EFI_SYSTEM_CONTEXT_RISCV64  *SystemContextRiscV64;
 } EFI_SYSTEM_CONTEXT;
 
 //
diff --git a/MdePkg/Include/Protocol/PxeBaseCode.h b/MdePkg/Include/Protocol/PxeBaseCode.h
index b02d270134..c666d312b5 100644
--- a/MdePkg/Include/Protocol/PxeBaseCode.h
+++ b/MdePkg/Include/Protocol/PxeBaseCode.h
@@ -3,6 +3,8 @@
   devices for network access and network booting.
 
 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Revision Reference:
@@ -153,6 +155,8 @@ typedef UINT16  EFI_PXE_BASE_CODE_UDP_PORT;
 #define EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE    0x000A
 #elif defined (MDE_CPU_AARCH64)
 #define EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE    0x000B
+#elif defined (MDE_CPU_RISCV64)
+#define EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE    0x001B
 #endif
 
 
diff --git a/MdePkg/Include/Uefi/UefiBaseType.h b/MdePkg/Include/Uefi/UefiBaseType.h
index a62f13dd06..934fc07285 100644
--- a/MdePkg/Include/Uefi/UefiBaseType.h
+++ b/MdePkg/Include/Uefi/UefiBaseType.h
@@ -3,6 +3,7 @@
 
 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
 Portions copyright (c) 2011 - 2016, ARM Ltd. All rights reserved.<BR>
+Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
 
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -240,6 +241,12 @@ typedef union {
 ///
 #define EFI_IMAGE_MACHINE_AARCH64  0xAA64
 
+///
+/// PE32+ Machine type for RISC-V 32/64/128
+///
+#define EFI_IMAGE_MACHINE_RISCV32   0x5032
+#define EFI_IMAGE_MACHINE_RISCV64   0x5064
+#define EFI_IMAGE_MACHINE_RISCV128  0x5128
 
 #if   defined (MDE_CPU_IA32)
 
@@ -268,6 +275,12 @@ typedef union {
 
 #define EFI_IMAGE_MACHINE_CROSS_TYPE_SUPPORTED(Machine) (FALSE)
 
+#elif defined (MDE_CPU_RISCV64)
+#define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) \
+  ((Machine) == EFI_IMAGE_MACHINE_RISCV64)
+
+#define EFI_IMAGE_MACHINE_CROSS_TYPE_SUPPORTED(Machine) (FALSE)
+
 #elif defined (MDE_CPU_EBC)
 
 ///
diff --git a/MdePkg/Include/Uefi/UefiSpec.h b/MdePkg/Include/Uefi/UefiSpec.h
index 444aa35eca..8ffaf97515 100644
--- a/MdePkg/Include/Uefi/UefiSpec.h
+++ b/MdePkg/Include/Uefi/UefiSpec.h
@@ -6,6 +6,8 @@
   by this include file.
 
 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
+Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -2198,6 +2200,7 @@ typedef struct {
 #define EFI_REMOVABLE_MEDIA_FILE_NAME_X64     L"\\EFI\\BOOT\\BOOTX64.EFI"
 #define EFI_REMOVABLE_MEDIA_FILE_NAME_ARM     L"\\EFI\\BOOT\\BOOTARM.EFI"
 #define EFI_REMOVABLE_MEDIA_FILE_NAME_AARCH64 L"\\EFI\\BOOT\\BOOTAA64.EFI"
+#define EFI_REMOVABLE_MEDIA_FILE_NAME_RISCV64 L"\\EFI\\BOOT\\BOOTRISCV64.EFI"
 
 #if   defined (MDE_CPU_IA32)
   #define EFI_REMOVABLE_MEDIA_FILE_NAME   EFI_REMOVABLE_MEDIA_FILE_NAME_IA32
@@ -2208,6 +2211,8 @@ typedef struct {
   #define EFI_REMOVABLE_MEDIA_FILE_NAME   EFI_REMOVABLE_MEDIA_FILE_NAME_ARM
 #elif defined (MDE_CPU_AARCH64)
   #define EFI_REMOVABLE_MEDIA_FILE_NAME   EFI_REMOVABLE_MEDIA_FILE_NAME_AARCH64
+#elif defined (MDE_CPU_RISCV64)
+  #define EFI_REMOVABLE_MEDIA_FILE_NAME   EFI_REMOVABLE_MEDIA_FILE_NAME_RISCV64
 #else
   #error Unknown Processor Type
 #endif
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v1 3/9] MdePkg/BaseLib: BaseLib for RISC-V RV64 Processor.
  2020-04-10  7:21 [PATCH v1 0/9] MdePkg changes for RISC-V edk2 port Abner Chang
  2020-04-10  7:21 ` [PATCH v1 1/9] MdePkg: RISC-V RV64 binding in MdePkg Abner Chang
  2020-04-10  7:21 ` [PATCH v1 2/9] MdePkg/Include: RISC-V definitions Abner Chang
@ 2020-04-10  7:21 ` Abner Chang
  2020-04-21  6:32   ` [edk2-devel] " Zhiguang Liu
  2020-04-10  7:21 ` [PATCH v1 4/9] MdePkg/BaseCacheMaintenanceLib: RISC-V cache maintenance implementation Abner Chang
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Abner Chang @ 2020-04-10  7:21 UTC (permalink / raw)
  To: devel
  Cc: abner.chang, Gilbert Chen, Leif Lindholm, Michael D Kinney,
	Liming Gao

Add RISC-V RV64 BaseLib functions.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Co-authored-by: Gilbert Chen <gilbert.chen@hpe.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
---
 MdePkg/Library/BaseLib/BaseLib.inf            | 18 +++++-
 MdePkg/Include/Library/BaseLib.h              | 26 +++++++++
 .../Library/BaseLib/RiscV64/CpuBreakpoint.c   | 27 +++++++++
 MdePkg/Library/BaseLib/RiscV64/CpuPause.c     | 29 ++++++++++
 .../BaseLib/RiscV64/DisableInterrupts.c       | 24 ++++++++
 .../BaseLib/RiscV64/EnableInterrupts.c        | 25 +++++++++
 .../BaseLib/RiscV64/GetInterruptState.c       | 35 ++++++++++++
 .../BaseLib/RiscV64/InternalSwitchStack.c     | 55 +++++++++++++++++++
 MdePkg/Library/BaseLib/RiscV64/LongJump.c     | 32 +++++++++++
 MdePkg/Library/BaseLib/RiscV64/FlushCache.S   | 21 +++++++
 .../BaseLib/RiscV64/RiscVCpuBreakpoint.S      | 14 +++++
 .../Library/BaseLib/RiscV64/RiscVCpuPause.S   | 14 +++++
 .../Library/BaseLib/RiscV64/RiscVInterrupt.S  | 32 +++++++++++
 .../BaseLib/RiscV64/RiscVSetJumpLongJump.S    | 55 +++++++++++++++++++
 14 files changed, 406 insertions(+), 1 deletion(-)
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/CpuBreakpoint.c
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/CpuPause.c
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/DisableInterrupts.c
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/EnableInterrupts.c
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/GetInterruptState.c
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/LongJump.c
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/FlushCache.S
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/RiscVCpuBreakpoint.S
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/RiscVCpuPause.S
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/RiscVSetJumpLongJump.S

diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/BaseLib.inf
index 3586beb0ab..a57ae2da31 100644
--- a/MdePkg/Library/BaseLib/BaseLib.inf
+++ b/MdePkg/Library/BaseLib/BaseLib.inf
@@ -4,6 +4,7 @@
 #  Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>
 #  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
 #  Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>
+#  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -20,7 +21,7 @@
   LIBRARY_CLASS                  = BaseLib
 
 #
-#  VALID_ARCHITECTURES           = IA32 X64 EBC ARM AARCH64
+#  VALID_ARCHITECTURES           = IA32 X64 EBC ARM AARCH64 RISCV64
 #
 
 [Sources]
@@ -381,6 +382,21 @@
   AArch64/CpuBreakpoint.asm         | MSFT
   AArch64/SpeculationBarrier.asm    | MSFT
 
+[Sources.RISCV64]
+  Math64.c
+  Unaligned.c
+  RiscV64/InternalSwitchStack.c
+  RiscV64/CpuBreakpoint.c
+  RiscV64/GetInterruptState.c
+  RiscV64/DisableInterrupts.c
+  RiscV64/EnableInterrupts.c
+  RiscV64/CpuPause.c
+  RiscV64/RiscVSetJumpLongJump.S    | GCC
+  RiscV64/RiscVCpuBreakpoint.S      | GCC
+  RiscV64/RiscVCpuPause.S           | GCC
+  RiscV64/RiscVInterrupt.S          | GCC
+  RiscV64/FlushCache.S              | GCC
+
 [Packages]
   MdePkg/MdePkg.dec
 
diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h
index ecadff8b23..41862e4285 100644
--- a/MdePkg/Include/Library/BaseLib.h
+++ b/MdePkg/Include/Library/BaseLib.h
@@ -4,6 +4,8 @@
 
 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
+Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -124,6 +126,30 @@ typedef struct {
 
 #endif  // defined (MDE_CPU_AARCH64)
 
+#if defined (MDE_CPU_RISCV64)
+///
+/// The RISC-V architecture context buffer used by SetJump() and LongJump().
+///
+typedef struct {
+  UINT64                            RA;
+  UINT64                            S0;
+  UINT64                            S1;
+  UINT64                            S2;
+  UINT64                            S3;
+  UINT64                            S4;
+  UINT64                            S5;
+  UINT64                            S6;
+  UINT64                            S7;
+  UINT64                            S8;
+  UINT64                            S9;
+  UINT64                            S10;
+  UINT64                            S11;
+  UINT64                            SP;
+} BASE_LIBRARY_JUMP_BUFFER;
+
+#define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
+
+#endif // defined (MDE_CPU_RISCV64)
 
 //
 // String Services
diff --git a/MdePkg/Library/BaseLib/RiscV64/CpuBreakpoint.c b/MdePkg/Library/BaseLib/RiscV64/CpuBreakpoint.c
new file mode 100644
index 0000000000..88d0877a2f
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/CpuBreakpoint.c
@@ -0,0 +1,27 @@
+/** @file
+  CPU breakpoint for RISC-V
+
+  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include "BaseLibInternals.h"
+
+extern VOID RiscVCpuBreakpoint (VOID);
+
+/**
+  Generates a breakpoint on the CPU.
+
+  Generates a breakpoint on the CPU. The breakpoint must be implemented such
+  that code can resume normal execution after the breakpoint.
+
+**/
+VOID
+EFIAPI
+CpuBreakpoint (
+  VOID
+  )
+{
+  RiscVCpuBreakpoint ();
+}
diff --git a/MdePkg/Library/BaseLib/RiscV64/CpuPause.c b/MdePkg/Library/BaseLib/RiscV64/CpuPause.c
new file mode 100644
index 0000000000..9931bad294
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/CpuPause.c
@@ -0,0 +1,29 @@
+/** @file
+  CPU pause for RISC-V
+
+  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include "BaseLibInternals.h"
+
+extern VOID RiscVCpuPause (VOID);
+
+
+/**
+  Requests CPU to pause for a short period of time.
+
+  Requests CPU to pause for a short period of time. Typically used in MP
+  systems to prevent memory starvation while waiting for a spin lock.
+
+**/
+VOID
+EFIAPI
+CpuPause (
+  VOID
+  )
+{
+  RiscVCpuPause ();
+}
+
diff --git a/MdePkg/Library/BaseLib/RiscV64/DisableInterrupts.c b/MdePkg/Library/BaseLib/RiscV64/DisableInterrupts.c
new file mode 100644
index 0000000000..867086c09c
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/DisableInterrupts.c
@@ -0,0 +1,24 @@
+/** @file
+  CPU disable interrupt function for RISC-V
+
+  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+#include "BaseLibInternals.h"
+
+extern VOID RiscVDisableSupervisorModeInterrupts (VOID);
+
+/**
+  Disables CPU interrupts.
+
+**/
+VOID
+EFIAPI
+DisableInterrupts (
+  VOID
+  )
+{
+  RiscVDisableSupervisorModeInterrupts ();
+}
+
diff --git a/MdePkg/Library/BaseLib/RiscV64/EnableInterrupts.c b/MdePkg/Library/BaseLib/RiscV64/EnableInterrupts.c
new file mode 100644
index 0000000000..22ef73067e
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/EnableInterrupts.c
@@ -0,0 +1,25 @@
+/** @file
+  CPU enable interrupt function for RISC-V
+
+  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include "BaseLibInternals.h"
+
+extern VOID RiscVEnableSupervisorModeInterrupt (VOID);
+
+/**
+  Enables CPU interrupts.
+
+**/
+VOID
+EFIAPI
+EnableInterrupts (
+  VOID
+  )
+{
+  RiscVEnableSupervisorModeInterrupt ();
+}
+
diff --git a/MdePkg/Library/BaseLib/RiscV64/GetInterruptState.c b/MdePkg/Library/BaseLib/RiscV64/GetInterruptState.c
new file mode 100644
index 0000000000..292f1ec441
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/GetInterruptState.c
@@ -0,0 +1,35 @@
+/** @file
+  CPU get interrupt state function for RISC-V
+
+  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include "BaseLibInternals.h"
+
+extern UINT32 RiscVGetSupervisorModeInterrupts (VOID);
+
+/**
+  Retrieves the current CPU interrupt state.
+
+  Returns TRUE is interrupts are currently enabled. Otherwise
+  returns FALSE.
+
+  @retval TRUE  CPU interrupts are enabled.
+  @retval FALSE CPU interrupts are disabled.
+
+**/
+BOOLEAN
+EFIAPI
+GetInterruptState (
+  VOID
+  )
+{
+  unsigned long RetValue;
+
+  RetValue = RiscVGetSupervisorModeInterrupts ();
+  return RetValue? TRUE: FALSE;
+}
+
+
diff --git a/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c b/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c
new file mode 100644
index 0000000000..0bb292141d
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c
@@ -0,0 +1,55 @@
+/** @file
+  Switch stack function for RISC-V
+
+  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include "BaseLibInternals.h"
+
+/**
+  Transfers control to a function starting with a new stack.
+
+  Transfers control to the function specified by EntryPoint using the
+  new stack specified by NewStack and passing in the parameters specified
+  by Context1 and Context2.  Context1 and Context2 are optional and may
+  be NULL.  The function EntryPoint must never return.
+  Marker will be ignored on IA-32, x64, and EBC.
+  IPF CPUs expect one additional parameter of type VOID * that specifies
+  the new backing store pointer.
+
+  If EntryPoint is NULL, then ASSERT().
+  If NewStack is NULL, then ASSERT().
+
+  @param  EntryPoint  A pointer to function to call with the new stack.
+  @param  Context1    A pointer to the context to pass into the EntryPoint
+                      function.
+  @param  Context2    A pointer to the context to pass into the EntryPoint
+                      function.
+  @param  NewStack    A pointer to the new stack to use for the EntryPoint
+                      function.
+  @param  Marker      VA_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+InternalSwitchStack (
+  IN      SWITCH_STACK_ENTRY_POINT  EntryPoint,
+  IN      VOID                      *Context1,   OPTIONAL
+  IN      VOID                      *Context2,   OPTIONAL
+  IN      VOID                      *NewStack,
+  IN      VA_LIST                   Marker
+  )
+{
+  BASE_LIBRARY_JUMP_BUFFER  JumpBuffer;
+
+  DEBUG ((DEBUG_INFO, "RISC-V InternalSwitchStack Entry:%x Context1:%x Context2:%x NewStack%x\n", \
+          EntryPoint, Context1, Context2, NewStack));
+  JumpBuffer.RA = (UINTN)EntryPoint;
+  JumpBuffer.SP = (UINTN)NewStack - sizeof (VOID *);
+  JumpBuffer.S0 = (UINT64)(UINTN)Context1;
+  JumpBuffer.S1 = (UINT64)(UINTN)Context2;
+  LongJump (&JumpBuffer, (UINTN)-1);
+  ASSERT(FALSE);
+}
diff --git a/MdePkg/Library/BaseLib/RiscV64/LongJump.c b/MdePkg/Library/BaseLib/RiscV64/LongJump.c
new file mode 100644
index 0000000000..fb2ed3fa2d
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/LongJump.c
@@ -0,0 +1,32 @@
+/** @file
+  Long jump implementation of RISC-V
+
+  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include "BaseLibInternals.h"
+
+
+/**
+  Restores the CPU context that was saved with SetJump().
+
+  Restores the CPU context from the buffer specified by JumpBuffer.
+  This function never returns to the caller.
+  Instead is resumes execution based on the state of JumpBuffer.
+
+  @param  JumpBuffer    A pointer to CPU context buffer.
+  @param  Value         The value to return when the SetJump() context is restored.
+
+**/
+VOID
+EFIAPI
+InternalLongJump (
+  IN      BASE_LIBRARY_JUMP_BUFFER  *JumpBuffer,
+  IN      UINTN                     Value
+  )
+{
+    ASSERT (FALSE);
+}
+
diff --git a/MdePkg/Library/BaseLib/RiscV64/FlushCache.S b/MdePkg/Library/BaseLib/RiscV64/FlushCache.S
new file mode 100644
index 0000000000..7c10fdd268
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/FlushCache.S
@@ -0,0 +1,21 @@
+//------------------------------------------------------------------------------
+//
+// RISC-V cache operation.
+//
+// Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+//------------------------------------------------------------------------------
+
+.align 3
+ASM_GLOBAL ASM_PFX(RiscVInvalidateInstCacheAsm)
+ASM_GLOBAL ASM_PFX(RiscVInvalidateDataCacheAsm)
+
+ASM_PFX(RiscVInvalidateInstCacheAsm):
+    fence.i
+    ret
+
+ASM_PFX(RiscVInvalidateDataCacheAsm):
+    fence
+    ret
diff --git a/MdePkg/Library/BaseLib/RiscV64/RiscVCpuBreakpoint.S b/MdePkg/Library/BaseLib/RiscV64/RiscVCpuBreakpoint.S
new file mode 100644
index 0000000000..ccf91df816
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/RiscVCpuBreakpoint.S
@@ -0,0 +1,14 @@
+//------------------------------------------------------------------------------
+//
+// CpuBreakpoint for RISC-V
+//
+// Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+//------------------------------------------------------------------------------
+
+ASM_GLOBAL ASM_PFX(RiscVCpuBreakpoint)
+ASM_PFX(RiscVCpuBreakpoint):
+  ebreak
+  ret
diff --git a/MdePkg/Library/BaseLib/RiscV64/RiscVCpuPause.S b/MdePkg/Library/BaseLib/RiscV64/RiscVCpuPause.S
new file mode 100644
index 0000000000..6660c2fcb3
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/RiscVCpuPause.S
@@ -0,0 +1,14 @@
+//------------------------------------------------------------------------------
+//
+// CpuPause for RISC-V
+//
+// Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+//------------------------------------------------------------------------------
+
+ASM_GLOBAL ASM_PFX(RiscVCpuPause)
+ASM_PFX(RiscVCpuPause):
+  nop
+  ret
diff --git a/MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S b/MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S
new file mode 100644
index 0000000000..766fcfb9cb
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S
@@ -0,0 +1,32 @@
+//------------------------------------------------------------------------------
+//
+// RISC-V Supervisor Mode interrupt enable/disable
+//
+// Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+//------------------------------------------------------------------------------
+
+ASM_GLOBAL ASM_PFX(RiscVDisableSupervisorModeInterrupts)
+ASM_GLOBAL ASM_PFX(RiscVEnableSupervisorModeInterrupt)
+ASM_GLOBAL ASM_PFX(RiscVGetSupervisorModeInterrupts)
+
+# define  MSTATUS_SIE    0x00000002
+# define  CSR_SSTATUS    0x100
+
+ASM_PFX(RiscVDisableSupervisorModeInterrupts):
+  li   a1, MSTATUS_SIE
+  csrc CSR_SSTATUS, a1
+  ret
+
+ASM_PFX(RiscVEnableSupervisorModeInterrupt):
+  li   a1, MSTATUS_SIE
+  csrs CSR_SSTATUS, a1
+  ret
+
+ASM_PFX(RiscVGetSupervisorModeInterrupts):
+  csrr a0, CSR_SSTATUS
+  andi a0, a0, MSTATUS_SIE
+  ret
+
diff --git a/MdePkg/Library/BaseLib/RiscV64/RiscVSetJumpLongJump.S b/MdePkg/Library/BaseLib/RiscV64/RiscVSetJumpLongJump.S
new file mode 100644
index 0000000000..34486eabba
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/RiscVSetJumpLongJump.S
@@ -0,0 +1,55 @@
+//------------------------------------------------------------------------------
+//
+// Set/Long jump for RISC-V
+//
+// Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+//------------------------------------------------------------------------------
+# define REG_S  sd
+# define REG_L  ld
+# define SZREG  8
+.align 3
+    .globl  SetJump
+
+SetJump:
+    REG_S ra,  0*SZREG(a0)
+    REG_S s0,  1*SZREG(a0)
+    REG_S s1,  2*SZREG(a0)
+    REG_S s2,  3*SZREG(a0)
+    REG_S s3,  4*SZREG(a0)
+    REG_S s4,  5*SZREG(a0)
+    REG_S s5,  6*SZREG(a0)
+    REG_S s6,  7*SZREG(a0)
+    REG_S s7,  8*SZREG(a0)
+    REG_S s8,  9*SZREG(a0)
+    REG_S s9,  10*SZREG(a0)
+    REG_S s10, 11*SZREG(a0)
+    REG_S s11, 12*SZREG(a0)
+    REG_S sp,  13*SZREG(a0)
+    li    a0,  0
+    ret
+
+    .globl  InternalLongJump
+InternalLongJump:
+    REG_L ra,  0*SZREG(a0)
+    REG_L s0,  1*SZREG(a0)
+    REG_L s1,  2*SZREG(a0)
+    REG_L s2,  3*SZREG(a0)
+    REG_L s3,  4*SZREG(a0)
+    REG_L s4,  5*SZREG(a0)
+    REG_L s5,  6*SZREG(a0)
+    REG_L s6,  7*SZREG(a0)
+    REG_L s7,  8*SZREG(a0)
+    REG_L s8,  9*SZREG(a0)
+    REG_L s9,  10*SZREG(a0)
+    REG_L s10, 11*SZREG(a0)
+    REG_L s11, 12*SZREG(a0)
+    REG_L sp,  13*SZREG(a0)
+
+    add   a0, s0, 0
+    add   a1, s1, 0
+    add   a2, s2, 0
+    add   a3, s3, 0
+    ret
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v1 4/9] MdePkg/BaseCacheMaintenanceLib: RISC-V cache maintenance implementation.
  2020-04-10  7:21 [PATCH v1 0/9] MdePkg changes for RISC-V edk2 port Abner Chang
                   ` (2 preceding siblings ...)
  2020-04-10  7:21 ` [PATCH v1 3/9] MdePkg/BaseLib: BaseLib for RISC-V RV64 Processor Abner Chang
@ 2020-04-10  7:21 ` Abner Chang
  2020-04-21  6:32   ` [edk2-devel] " Zhiguang Liu
  2020-04-10  7:21 ` [PATCH v1 5/9] MdePkg/BaseIoLibIntrinsic: Rename IoLibArm.c=>IoLibNoIo.c Abner Chang
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Abner Chang @ 2020-04-10  7:21 UTC (permalink / raw)
  To: devel
  Cc: abner.chang, Gilbert Chen, Leif Lindholm, Michael D Kinney,
	Liming Gao

Implement RISC-V cache maintenance functions in
BaseCacheMaintenanceLib.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Co-authored-by: Gilbert Chen <gilbert.chen@hpe.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
---
 .../BaseCacheMaintenanceLib.inf               |   4 +
 .../BaseCacheMaintenanceLib/RiscVCache.c      | 250 ++++++++++++++++++
 2 files changed, 254 insertions(+)
 create mode 100644 MdePkg/Library/BaseCacheMaintenanceLib/RiscVCache.c

diff --git a/MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf b/MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf
index ec7feecf9c..33114243d5 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.<BR>
 #  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
+#  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
 #
 #  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 0000000000..21a695c843
--- /dev/null
+++ b/MdePkg/Library/BaseCacheMaintenanceLib/RiscVCache.c
@@ -0,0 +1,250 @@
+/** @file
+  RISC-V specific functionality for cache.
+
+  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Base.h>
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+
+/**
+  RISC-V invalidate instruction cache.
+
+**/
+VOID
+EFIAPI
+RiscVInvalidateInstCacheAsm (
+  VOID
+  );
+
+/**
+  RISC-V invalidate data cache.
+
+**/
+VOID
+EFIAPI
+RiscVInvalidateDataCacheAsm (
+  VOID
+  );
+
+/**
+  Invalidates the entire instruction cache in cache coherency domain of the
+  calling CPU.
+
+**/
+VOID
+EFIAPI
+InvalidateInstructionCache (
+  VOID
+  )
+{
+  RiscVInvalidateInstCacheAsm ();
+}
+
+/**
+  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__));
+  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__));
+}
+
+/**
+  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 unsupported function.\n", __FUNCTION__));
+  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 unsupported function.\n", __FUNCTION__));
+}
+
+/**
+  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 unsupported function.\n", __FUNCTION__));
+  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
+  )
+{
+  RiscVInvalidateDataCacheAsm ();
+}
+
+/**
+  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 unsupported function.\n", __FUNCTION__));
+  return Address;
+}
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v1 5/9] MdePkg/BaseIoLibIntrinsic: Rename IoLibArm.c=>IoLibNoIo.c
  2020-04-10  7:21 [PATCH v1 0/9] MdePkg changes for RISC-V edk2 port Abner Chang
                   ` (3 preceding siblings ...)
  2020-04-10  7:21 ` [PATCH v1 4/9] MdePkg/BaseCacheMaintenanceLib: RISC-V cache maintenance implementation Abner Chang
@ 2020-04-10  7:21 ` Abner Chang
  2020-04-21  6:36   ` [edk2-devel] " Zhiguang Liu
  2020-04-10  7:21 ` [PATCH v1 6/9] MdePkg/BasePeCoff: Add RISC-V PE/Coff related code Abner Chang
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Abner Chang @ 2020-04-10  7:21 UTC (permalink / raw)
  To: devel
  Cc: abner.chang, Gilbert Chen, Leif Lindholm, Michael D Kinney,
	Liming Gao

RISC-V MMIO library instance.
IoLibArm.c in fact implements a generic Mmio-only (and ANSI
C compliant), so rename it to better reflect this.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Co-authored-by: Gilbert Chen <gilbert.chen@hpe.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
---
 .../BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf        | 12 ++++++++----
 .../BaseIoLibIntrinsic/{IoLibArm.c => IoLibNoIo.c}   |  4 +++-
 2 files changed, 11 insertions(+), 5 deletions(-)
 rename MdePkg/Library/BaseIoLibIntrinsic/{IoLibArm.c => IoLibNoIo.c} (94%)

diff --git a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
index 457cce9378..cc23b6b227 100644
--- a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
+++ b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
@@ -4,11 +4,12 @@
 #  I/O Library that uses compiler intrinsics to perform IN and OUT instructions
 #  for IA-32 and x64.  On IPF, I/O port requests are translated into MMIO requests.
 #  MMIO requests are forwarded directly to memory.  For EBC, I/O port requests
-#  ASSERT().
+#  ASSERT(). This I/O library only provides non I/O read and write.
 #
 #  Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
 #  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
 #  Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
+#  Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -25,7 +26,7 @@
 
 
 #
-#  VALID_ARCHITECTURES           = IA32 X64 EBC ARM AARCH64
+#  VALID_ARCHITECTURES           = IA32 X64 EBC ARM AARCH64 RISCV64
 #
 
 [Sources]
@@ -50,10 +51,13 @@
   IoLib.c
 
 [Sources.ARM]
-  IoLibArm.c
+  IoLibNoIo.c
 
 [Sources.AARCH64]
-  IoLibArm.c
+  IoLibNoIo.c
+
+[Sources.RISCV64]
+  IoLibNoIo.c
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git a/MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c b/MdePkg/Library/BaseIoLibIntrinsic/IoLibNoIo.c
similarity index 94%
rename from MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c
rename to MdePkg/Library/BaseIoLibIntrinsic/IoLibNoIo.c
index c6b822461d..a107136a74 100644
--- a/MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c
+++ b/MdePkg/Library/BaseIoLibIntrinsic/IoLibNoIo.c
@@ -1,9 +1,11 @@
 /** @file
-  I/O Library for ARM.
+  I/O library for non I/O read and write access (memory map I/O read and
+  write only) architecture, such as ARM and RISC-V processor.
 
   Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
   Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
   Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
+  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v1 6/9] MdePkg/BasePeCoff: Add RISC-V PE/Coff related code.
  2020-04-10  7:21 [PATCH v1 0/9] MdePkg changes for RISC-V edk2 port Abner Chang
                   ` (4 preceding siblings ...)
  2020-04-10  7:21 ` [PATCH v1 5/9] MdePkg/BaseIoLibIntrinsic: Rename IoLibArm.c=>IoLibNoIo.c Abner Chang
@ 2020-04-10  7:21 ` Abner Chang
  2020-04-21  6:36   ` [edk2-devel] " Zhiguang Liu
  2020-04-10  7:21 ` [PATCH v1 7/9] MdePkg/BaseCpuLib: RISC-V Base CPU library implementation Abner Chang
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Abner Chang @ 2020-04-10  7:21 UTC (permalink / raw)
  To: devel
  Cc: abner.chang, Gilbert Chen, Leif Lindholm, Michael D Kinney,
	Liming Gao

Support RISC-V image relocation.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Co-authored-by: Gilbert Chen <gilbert.chen@hpe.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
---
 .../Library/BasePeCoffLib/BasePeCoffLib.inf   |   5 +
 .../BasePeCoffLib/BasePeCoffLibInternals.h    |   9 ++
 MdePkg/Library/BasePeCoffLib/BasePeCoff.c     |   3 +-
 .../BasePeCoffLib/RiscV/PeCoffLoaderEx.c      | 133 ++++++++++++++++++
 .../Library/BasePeCoffLib/BasePeCoffLib.uni   |   2 +
 5 files changed, 151 insertions(+), 1 deletion(-)
 create mode 100644 MdePkg/Library/BasePeCoffLib/RiscV/PeCoffLoaderEx.c

diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf b/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
index 395c1403c0..110b6d5a09 100644
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
+++ b/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
@@ -3,6 +3,7 @@
 #  The IPF version library supports loading IPF and EBC PE/COFF image.
 #  The IA32 version library support loading IA32, X64 and EBC PE/COFF images.
 #  The X64 version library support loading IA32, X64 and EBC PE/COFF images.
+#  The RISC-V version library support loading RISC-V images.
 #
 #  Caution: This module requires additional review when modified.
 #  This library will have external input - PE/COFF image.
@@ -11,6 +12,7 @@
 #
 #  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
 #  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
+#  Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -41,6 +43,9 @@
 [Sources.ARM]
   Arm/PeCoffLoaderEx.c
 
+[Sources.RISCV64]
+  RiscV/PeCoffLoaderEx.c
+
 [Packages]
   MdePkg/MdePkg.dec
 
diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoffLibInternals.h b/MdePkg/Library/BasePeCoffLib/BasePeCoffLibInternals.h
index b74277f3e8..3ee56e0e5f 100644
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoffLibInternals.h
+++ b/MdePkg/Library/BasePeCoffLib/BasePeCoffLibInternals.h
@@ -2,6 +2,7 @@
   Declaration of internal functions in PE/COFF Lib.
 
   Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+  Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -16,6 +17,14 @@
 #include <Library/PeCoffExtraActionLib.h>
 #include <IndustryStandard/PeImage.h>
 
+//
+// Macro definitions for RISC-V architecture.
+//
+#define RV_X(x, s, n) (((x) >> (s)) & ((1<<(n))-1))
+#define RISCV_IMM_BITS 12
+#define RISCV_IMM_REACH (1LL<<RISCV_IMM_BITS)
+#define RISCV_CONST_HIGH_PART(VALUE) \
+  (((VALUE) + (RISCV_IMM_REACH/2)) & ~(RISCV_IMM_REACH-1))
 
 
 /**
diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
index 07bb62f860..1102833b94 100644
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
+++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
@@ -1,6 +1,6 @@
 /** @file
   Base PE/COFF loader supports loading any PE32/PE32+ or TE image, but
-  only supports relocating IA32, x64, IPF, and EBC images.
+  only supports relocating IA32, x64, IPF, ARM, RISC-V and EBC images.
 
   Caution: This file requires additional review when modified.
   This library will have external input - PE/COFF image.
@@ -17,6 +17,7 @@
 
   Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
   Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
+  Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
diff --git a/MdePkg/Library/BasePeCoffLib/RiscV/PeCoffLoaderEx.c b/MdePkg/Library/BasePeCoffLib/RiscV/PeCoffLoaderEx.c
new file mode 100644
index 0000000000..23170a6603
--- /dev/null
+++ b/MdePkg/Library/BasePeCoffLib/RiscV/PeCoffLoaderEx.c
@@ -0,0 +1,133 @@
+/** @file
+  PE/Coff loader for RISC-V PE image
+
+  Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+#include "BasePeCoffLibInternals.h"
+#include <Library/BaseLib.h>
+
+/**
+  Performs an RISC-V specific relocation fixup and is a no-op on
+  other instruction sets.
+  RISC-V splits 32-bit fixup into 20bit and 12-bit with two relocation
+  types. We have to know the lower 12-bit fixup first then we can deal
+  carry over on high 20-bit fixup. So we log the high 20-bit in
+  FixupData.
+
+  @param  Reloc       The pointer to the relocation record.
+  @param  Fixup       The pointer to the address to fix up.
+  @param  FixupData   The pointer to a buffer to log the fixups.
+  @param  Adjust      The offset to adjust the fixup.
+
+  @return Status code.
+
+**/
+RETURN_STATUS
+PeCoffLoaderRelocateImageEx (
+  IN UINT16      *Reloc,
+  IN OUT CHAR8   *Fixup,
+  IN OUT CHAR8   **FixupData,
+  IN UINT64      Adjust
+  )
+{
+  UINT32 Value;
+  UINT32 Value2;
+  UINT32 *RiscVHi20Fixup;
+
+  switch ((*Reloc) >> 12) {
+  case EFI_IMAGE_REL_BASED_RISCV_HI20:
+      *(UINT64 *)(*FixupData) = (UINT64)(UINTN)Fixup;
+      break;
+
+  case EFI_IMAGE_REL_BASED_RISCV_LOW12I:
+      RiscVHi20Fixup =  (UINT32 *)(*(UINT64 *)(*FixupData));
+      if (RiscVHi20Fixup != NULL) {
+
+        Value = (UINT32)(RV_X(*RiscVHi20Fixup, 12, 20) << 12);
+        Value2 = (UINT32)(RV_X(*(UINT32 *)Fixup, 20, 12));
+        if (Value2 & (RISCV_IMM_REACH/2)) {
+          Value2 |= ~(RISCV_IMM_REACH-1);
+        }
+        Value += Value2;
+        Value += (UINT32)Adjust;
+        Value2 = RISCV_CONST_HIGH_PART (Value);
+        *(UINT32 *)RiscVHi20Fixup = (RV_X (Value2, 12, 20) << 12) |\
+                                           (RV_X (*(UINT32 *)RiscVHi20Fixup, 0, 12));
+        *(UINT32 *)Fixup = (RV_X (Value, 0, 12) << 20) |\
+                           (RV_X (*(UINT32 *)Fixup, 0, 20));
+      }
+      break;
+
+  case EFI_IMAGE_REL_BASED_RISCV_LOW12S:
+      RiscVHi20Fixup =  (UINT32 *)(*(UINT64 *)(*FixupData));
+      if (RiscVHi20Fixup != NULL) {
+        Value = (UINT32)(RV_X(*RiscVHi20Fixup, 12, 20) << 12);
+        Value2 = (UINT32)(RV_X(*(UINT32 *)Fixup, 7, 5) | (RV_X(*(UINT32 *)Fixup, 25, 7) << 5));
+        if (Value2 & (RISCV_IMM_REACH/2)) {
+          Value2 |= ~(RISCV_IMM_REACH-1);
+        }
+        Value += Value2;
+        Value += (UINT32)Adjust;
+        Value2 = RISCV_CONST_HIGH_PART (Value);
+        *(UINT32 *)RiscVHi20Fixup = (RV_X (Value2, 12, 20) << 12) | \
+                                           (RV_X (*(UINT32 *)RiscVHi20Fixup, 0, 12));
+        Value2 = *(UINT32 *)Fixup & 0x01fff07f;
+        Value &= RISCV_IMM_REACH - 1;
+        *(UINT32 *)Fixup = Value2 | (UINT32)(((RV_X(Value, 0, 5) << 7) | (RV_X(Value, 5, 7) << 25)));
+      }
+      break;
+
+  default:
+      return RETURN_UNSUPPORTED;
+
+  }
+  return RETURN_SUCCESS;
+}
+
+/**
+  Returns TRUE if the machine type of PE/COFF image is supported. Supported
+  does not mean the image can be executed it means the PE/COFF loader supports
+  loading and relocating of the image type. It's up to the caller to support
+  the entry point.
+
+  @param  Machine   Machine type from the PE Header.
+
+  @return TRUE if this PE/COFF loader can load the image
+
+**/
+BOOLEAN
+PeCoffLoaderImageFormatSupported (
+  IN  UINT16  Machine
+  )
+{
+  if (Machine ==  IMAGE_FILE_MACHINE_RISCV64) {
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
+/**
+  Performs an Itanium-based specific re-relocation fixup and is a no-op on other
+  instruction sets. This is used to re-relocated the image into the EFI virtual
+  space for runtime calls.
+
+  @param  Reloc       The pointer to the relocation record.
+  @param  Fixup       The pointer to the address to fix up.
+  @param  FixupData   The pointer to a buffer to log the fixups.
+  @param  Adjust      The offset to adjust the fixup.
+
+  @return Status code.
+
+**/
+RETURN_STATUS
+PeHotRelocateImageEx (
+  IN UINT16      *Reloc,
+  IN OUT CHAR8   *Fixup,
+  IN OUT CHAR8   **FixupData,
+  IN UINT64      Adjust
+  )
+{
+  return RETURN_UNSUPPORTED;
+}
diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.uni b/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.uni
index b0ea702f76..55417029f2 100644
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.uni
+++ b/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.uni
@@ -4,6 +4,7 @@
 // The IPF version library supports loading IPF and EBC PE/COFF image.
 // The IA32 version library support loading IA32, X64 and EBC PE/COFF images.
 // The X64 version library support loading IA32, X64 and EBC PE/COFF images.
+// The RISC-V version library support loading RISC-V32 and RISC-V64 PE/COFF images.
 //
 // Caution: This module requires additional review when modified.
 // This library will have external input - PE/COFF image.
@@ -12,6 +13,7 @@
 //
 // Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
 // Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
+// Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
 //
 // SPDX-License-Identifier: BSD-2-Clause-Patent
 //
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v1 7/9] MdePkg/BaseCpuLib: RISC-V Base CPU library implementation.
  2020-04-10  7:21 [PATCH v1 0/9] MdePkg changes for RISC-V edk2 port Abner Chang
                   ` (5 preceding siblings ...)
  2020-04-10  7:21 ` [PATCH v1 6/9] MdePkg/BasePeCoff: Add RISC-V PE/Coff related code Abner Chang
@ 2020-04-10  7:21 ` Abner Chang
  2020-04-21  6:36   ` [edk2-devel] " Zhiguang Liu
  2020-04-10  7:21 ` [PATCH v1 8/9] MdePkg/BaseSynchronizationLib: RISC-V cache related code Abner Chang
  2020-04-10  7:21 ` [PATCH v1 9/9] MdePkg/BaseSafeIntLib: Add RISCV64 arch for BaseSafeIntLib Abner Chang
  8 siblings, 1 reply; 20+ messages in thread
From: Abner Chang @ 2020-04-10  7:21 UTC (permalink / raw)
  To: devel
  Cc: abner.chang, Gilbert Chen, Leif Lindholm, Michael D Kinney,
	Liming Gao

Implement RISC-V CPU related functions in BaseCpuLib.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Co-authored-by: Gilbert Chen <gilbert.chen@hpe.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
---
 MdePkg/Library/BaseCpuLib/BaseCpuLib.inf |  6 +++++-
 MdePkg/Library/BaseCpuLib/BaseCpuLib.uni |  5 +++--
 MdePkg/Library/BaseCpuLib/RiscV/Cpu.S    | 19 +++++++++++++++++++
 3 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 MdePkg/Library/BaseCpuLib/RiscV/Cpu.S

diff --git a/MdePkg/Library/BaseCpuLib/BaseCpuLib.inf b/MdePkg/Library/BaseCpuLib/BaseCpuLib.inf
index a7cb381a85..950f5229b2 100644
--- a/MdePkg/Library/BaseCpuLib/BaseCpuLib.inf
+++ b/MdePkg/Library/BaseCpuLib/BaseCpuLib.inf
@@ -7,6 +7,7 @@
 #  Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
 #  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
 #  Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>
+#  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -24,7 +25,7 @@
 
 
 #
-#  VALID_ARCHITECTURES           = IA32 X64 EBC ARM AARCH64
+#  VALID_ARCHITECTURES           = IA32 X64 EBC ARM AARCH64 RISCV64
 #
 
 [Sources.IA32]
@@ -59,6 +60,9 @@
   AArch64/CpuFlushTlb.asm | MSFT
   AArch64/CpuSleep.asm    | MSFT
 
+[Sources.RISCV64]
+  RiscV/Cpu.S
+
 [Packages]
   MdePkg/MdePkg.dec
 
diff --git a/MdePkg/Library/BaseCpuLib/BaseCpuLib.uni b/MdePkg/Library/BaseCpuLib/BaseCpuLib.uni
index fc95cda9fc..80dc495786 100644
--- a/MdePkg/Library/BaseCpuLib/BaseCpuLib.uni
+++ b/MdePkg/Library/BaseCpuLib/BaseCpuLib.uni
@@ -1,12 +1,13 @@
 // /** @file
 // Instance of CPU Library for various architecture.
 //
-// CPU Library implemented using ASM functions for IA-32 and X64,
+// CPU Library implemented using ASM functions for IA-32, X64 and RISCV64,
 // PAL CALLs for IPF, and empty functions for EBC.
 //
 // Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
 // Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
 // Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>
+// Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
 //
 // SPDX-License-Identifier: BSD-2-Clause-Patent
 //
@@ -15,5 +16,5 @@
 
 #string STR_MODULE_ABSTRACT             #language en-US "Instance of CPU Library for various architectures"
 
-#string STR_MODULE_DESCRIPTION          #language en-US "CPU Library implemented using ASM functions for IA-32 and X64, PAL CALLs for IPF, and empty functions for EBC."
+#string STR_MODULE_DESCRIPTION          #language en-US "CPU Library implemented using ASM functions for IA-32, X64 and RISCV64, PAL CALLs for IPF, and empty functions for EBC."
 
diff --git a/MdePkg/Library/BaseCpuLib/RiscV/Cpu.S b/MdePkg/Library/BaseCpuLib/RiscV/Cpu.S
new file mode 100644
index 0000000000..375b91d314
--- /dev/null
+++ b/MdePkg/Library/BaseCpuLib/RiscV/Cpu.S
@@ -0,0 +1,19 @@
+//------------------------------------------------------------------------------
+//
+// CpuSleep for RISC-V
+//
+// Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+//------------------------------------------------------------------------------
+.data
+.align 3
+.section .text
+
+.global ASM_PFX(_CpuSleep)
+
+ASM_PFX(_CpuSleep):
+    wfi
+    ret
+
+
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v1 8/9] MdePkg/BaseSynchronizationLib: RISC-V cache related code.
  2020-04-10  7:21 [PATCH v1 0/9] MdePkg changes for RISC-V edk2 port Abner Chang
                   ` (6 preceding siblings ...)
  2020-04-10  7:21 ` [PATCH v1 7/9] MdePkg/BaseCpuLib: RISC-V Base CPU library implementation Abner Chang
@ 2020-04-10  7:21 ` Abner Chang
  2020-04-21  6:36   ` [edk2-devel] " Zhiguang Liu
  2020-04-10  7:21 ` [PATCH v1 9/9] MdePkg/BaseSafeIntLib: Add RISCV64 arch for BaseSafeIntLib Abner Chang
  8 siblings, 1 reply; 20+ messages in thread
From: Abner Chang @ 2020-04-10  7:21 UTC (permalink / raw)
  To: devel
  Cc: abner.chang, Gilbert Chen, Leif Lindholm, Michael D Kinney,
	Liming Gao

Support RISC-V cache related functions.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Co-authored-by: Gilbert Chen <gilbert.chen@hpe.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
---
 .../BaseSynchronizationLib.inf                |  5 ++
 .../RiscV64/SynchronizationAsm.S              | 78 +++++++++++++++++++
 2 files changed, 83 insertions(+)
 create mode 100644 MdePkg/Library/BaseSynchronizationLib/RiscV64/SynchronizationAsm.S

diff --git a/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf b/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
index 446bc19b63..9309d2e1d5 100755
--- a/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
+++ b/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
@@ -3,6 +3,7 @@
 #
 #  Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
 #  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
+#  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -78,6 +79,10 @@
   AArch64/Synchronization.S     | GCC
   AArch64/Synchronization.asm   | MSFT
 
+[Sources.RISCV64]
+  Synchronization.c
+  RiscV64/SynchronizationAsm.S
+
 [Packages]
   MdePkg/MdePkg.dec
 
diff --git a/MdePkg/Library/BaseSynchronizationLib/RiscV64/SynchronizationAsm.S b/MdePkg/Library/BaseSynchronizationLib/RiscV64/SynchronizationAsm.S
new file mode 100644
index 0000000000..bac80d6871
--- /dev/null
+++ b/MdePkg/Library/BaseSynchronizationLib/RiscV64/SynchronizationAsm.S
@@ -0,0 +1,78 @@
+//------------------------------------------------------------------------------
+//
+// RISC-V synchronization functions.
+//
+// Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+//------------------------------------------------------------------------------
+#include <Base.h>
+
+.data
+
+.text
+.align 3
+
+.global ASM_PFX(InternalSyncCompareExchange32)
+.global ASM_PFX(InternalSyncCompareExchange64)
+.global ASM_PFX(InternalSyncIncrement)
+.global ASM_PFX(InternalSyncDecrement)
+
+//
+// ompare and xchange a 32-bit value.
+//
+// @param a0 : Pointer to 32-bit value.
+// @param a1 : Compare value.
+// @param a2 : Exchange value.
+//
+ASM_PFX (InternalSyncCompareExchange32):
+    lr.w  a3, (a0)        // Load the value from a0 and make
+                          // the reservation of address.
+    bne   a3, a1, exit
+    sc.w  a3, a2, (a0)    // Write the value back to the address.
+    mv    a3, a1
+exit:
+    mv    a0, a3
+    ret
+
+.global ASM_PFX(InternalSyncCompareExchange64)
+
+//
+// Compare and xchange a 64-bit value.
+//
+// @param a0 : Pointer to 64-bit value.
+// @param a1 : Compare value.
+// @param a2 : Exchange value.
+//
+ASM_PFX (SyncCompareExchange64):
+    lr.d  a3, (a0)       // Load the value from a0 and make
+                         // the reservation of address.
+    bne   a3, a1, exit
+    sc.d  a3, a2, (a0)   // Write the value back to the address.
+    mv    a3, a1
+exit2:
+    mv    a0, a3
+    ret
+
+//
+// Performs an atomic increment of an 32-bit unsigned integer.
+//
+// @param a0 : Pointer to 32-bit value.
+//
+ASM_PFX (InternalSyncIncrement):
+    li  a1, 1
+    amoadd.w  a2, a1, (a0)
+    mv  a0, a2
+    ret
+
+//
+// Performs an atomic decrement of an 32-bit unsigned integer.
+//
+// @param a0 : Pointer to 32-bit value.
+//
+ASM_PFX (InternalSyncDecrement):
+    li  a1, -1
+    amoadd.w  a2, a1, (a0)
+    mv  a0, a2
+    ret
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v1 9/9] MdePkg/BaseSafeIntLib: Add RISCV64 arch for BaseSafeIntLib.
  2020-04-10  7:21 [PATCH v1 0/9] MdePkg changes for RISC-V edk2 port Abner Chang
                   ` (7 preceding siblings ...)
  2020-04-10  7:21 ` [PATCH v1 8/9] MdePkg/BaseSynchronizationLib: RISC-V cache related code Abner Chang
@ 2020-04-10  7:21 ` Abner Chang
  2020-04-21  6:36   ` [edk2-devel] " Zhiguang Liu
  8 siblings, 1 reply; 20+ messages in thread
From: Abner Chang @ 2020-04-10  7:21 UTC (permalink / raw)
  To: devel
  Cc: abner.chang, Leif Lindholm, Michael D Kinney, Liming Gao,
	Leif Lindholm, Gilbert Chen, Daniel Helmut Schaefer

Add RISCV64 arch for BaseSafeIntLib library.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Reviewed-by: Leif Lindholm <leif@nuviainc.com>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
Cc: Daniel Helmut Schaefer <daniel.schaefer@hpe.com>
---
 MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf b/MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
index 68ade962d6..40017ec88b 100644
--- a/MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
+++ b/MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
@@ -6,6 +6,8 @@
 #
 #  Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
 # Copyright (c) 2017, Microsoft Corporation
+#  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+
 #
 # All rights reserved.
 # SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -23,7 +25,7 @@
 #
 # The following information is for reference only and not required by the build tools.
 #
-#  VALID_ARCHITECTURES           = IA32 X64
+#  VALID_ARCHITECTURES           = IA32 X64 ARM AARCH64 RISCV64
 #
 
 [Sources]
@@ -32,7 +34,7 @@
 [Sources.Ia32, Sources.ARM]
   SafeIntLib32.c
 
-[Sources.X64, Sources.AARCH64]
+[Sources.X64, Sources.AARCH64, Sources.RISCV64]
   SafeIntLib64.c
 
 [Sources.EBC]
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [edk2-devel] [PATCH v1 1/9] MdePkg: RISC-V RV64 binding in MdePkg
  2020-04-10  7:21 ` [PATCH v1 1/9] MdePkg: RISC-V RV64 binding in MdePkg Abner Chang
@ 2020-04-21  6:30   ` Zhiguang Liu
  0 siblings, 0 replies; 20+ messages in thread
From: Zhiguang Liu @ 2020-04-21  6:30 UTC (permalink / raw)
  To: devel@edk2.groups.io, abner.chang@hpe.com
  Cc: Gilbert Chen, Leif Lindholm, Kinney, Michael D, Gao, Liming

Reviewed-by: Zhiguang Liu <zhiguang.liu@intel.com>

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Abner Chang
Sent: Friday, April 10, 2020 3:21 PM
To: devel@edk2.groups.io
Cc: abner.chang@hpe.com; Gilbert Chen <gilbert.chen@hpe.com>; Leif Lindholm <leif.lindholm@linaro.org>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [edk2-devel] [PATCH v1 1/9] MdePkg: RISC-V RV64 binding in MdePkg

Add RISCV64 sections in MdePkg.dec and RISCV64 ProcessorBind.h

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Co-authored-by: Gilbert Chen <gilbert.chen@hpe.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
---
 MdePkg/MdePkg.dec                      |   5 +-
 MdePkg/MdePkg.dsc                      |   3 +-
 MdePkg/Include/RiscV64/ProcessorBind.h | 173 +++++++++++++++++++++++++
 3 files changed, 179 insertions(+), 2 deletions(-)
 create mode 100644 MdePkg/Include/RiscV64/ProcessorBind.h

diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index 6c37c2181c..0b9c4bc40a 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -6,7 +6,7 @@
 #

 # Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>

 # Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

-# (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>

+# (C) Copyright 2016 - 2020 Hewlett Packard Enterprise Development LP<BR>

 #

 # SPDX-License-Identifier: BSD-2-Clause-Patent

 #

@@ -39,6 +39,9 @@
 [Includes.AARCH64]

   Include/AArch64

 

+[Includes.RISCV64]

+  Include/RiscV64

+

 [LibraryClasses]

   ##  @libraryclass  Provides most usb APIs to support the Hid requests defined in Usb Hid 1.1 spec

   #                  and the standard requests defined in Usb 1.1 spec.

diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc
index 2b2d5981e8..6cd38e7ec3 100644
--- a/MdePkg/MdePkg.dsc
+++ b/MdePkg/MdePkg.dsc
@@ -3,6 +3,7 @@
 #

 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>

 # Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

+# (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>

 #

 #    SPDX-License-Identifier: BSD-2-Clause-Patent

 #

@@ -14,7 +15,7 @@
   PLATFORM_VERSION               = 1.08

   DSC_SPECIFICATION              = 0x00010005

   OUTPUT_DIRECTORY               = Build/Mde

-  SUPPORTED_ARCHITECTURES        = IA32|X64|EBC|ARM|AARCH64

+  SUPPORTED_ARCHITECTURES        = IA32|X64|EBC|ARM|AARCH64|RISCV64

   BUILD_TARGETS                  = DEBUG|RELEASE|NOOPT

   SKUID_IDENTIFIER               = DEFAULT

 

diff --git a/MdePkg/Include/RiscV64/ProcessorBind.h b/MdePkg/Include/RiscV64/ProcessorBind.h
new file mode 100644
index 0000000000..2b11f041ea
--- /dev/null
+++ b/MdePkg/Include/RiscV64/ProcessorBind.h
@@ -0,0 +1,173 @@
+/** @file

+  Processor or Compiler specific defines and types for RISC-V

+

+  Copyright (c) 2016 - 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

+

+  SPDX-License-Identifier: BSD-2-Clause-Patent

+

+**/

+

+#ifndef PROCESSOR_BIND_H__

+#define PROCESSOR_BIND_H__

+

+///

+/// Define the processor type so other code can make processor based choices

+///

+#define MDE_CPU_RISCV64

+

+//

+// Make sure we are using the correct packing rules per EFI specification

+//

+#if !defined(__GNUC__)

+#pragma pack()

+#endif

+

+///

+/// 8-byte unsigned value

+///

+typedef unsigned long long  UINT64  __attribute__ ((aligned (8)));

+///

+/// 8-byte signed value

+///

+typedef long long           INT64  __attribute__ ((aligned (8)));

+///

+/// 4-byte unsigned value

+///

+typedef unsigned int        UINT32 __attribute__ ((aligned (4)));

+///

+/// 4-byte signed value

+///

+typedef int                 INT32  __attribute__ ((aligned (4)));

+///

+/// 2-byte unsigned value

+///

+typedef unsigned short      UINT16  __attribute__ ((aligned (2)));

+///

+/// 2-byte Character.  Unless otherwise specified all strings are stored in the

+/// UTF-16 encoding format as defined by Unicode 2.1 and ISO/IEC 10646 standards.

+///

+typedef unsigned short      CHAR16  __attribute__ ((aligned (2)));

+///

+/// 2-byte signed value

+///

+typedef short               INT16  __attribute__ ((aligned (2)));

+///

+/// Logical Boolean.  1-byte value containing 0 for FALSE or a 1 for TRUE.  Other

+/// values are undefined.

+///

+typedef unsigned char       BOOLEAN;

+///

+/// 1-byte unsigned value

+///

+typedef unsigned char       UINT8;

+///

+/// 1-byte Character

+///

+typedef char                CHAR8;

+///

+/// 1-byte signed value

+///

+typedef signed char         INT8;

+///

+/// Unsigned value of native width.  (4 bytes on supported 32-bit processor instructions,

+/// 8 bytes on supported 64-bit processor instructions)

+///

+typedef UINT64  UINTN __attribute__ ((aligned (8)));

+///

+/// Signed value of native width.  (4 bytes on supported 32-bit processor instructions,

+/// 8 bytes on supported 64-bit processor instructions)

+///

+typedef INT64   INTN __attribute__ ((aligned (8)));

+

+//

+// Processor specific defines

+//

+

+///

+/// A value of native width with the highest bit set.

+///

+#define MAX_BIT     0x8000000000000000ULL

+///

+/// A value of native width with the two highest bits set.

+///

+#define MAX_2_BITS  0xC000000000000000ULL

+

+///

+/// Maximum legal RV64 address

+///

+#define MAX_ADDRESS   0xFFFFFFFFFFFFFFFFULL

+

+///

+/// Maximum usable address at boot time (48 bits using 4 KB pages in Supervisor mode)

+///

+#define MAX_ALLOC_ADDRESS   0xFFFFFFFFFFFFULL

+

+///

+/// Maximum legal RISC-V INTN and UINTN values.

+///

+#define MAX_INTN   ((INTN)0x7FFFFFFFFFFFFFFFULL)

+#define MAX_UINTN  ((UINTN)0xFFFFFFFFFFFFFFFFULL)

+

+///

+/// The stack alignment required for RISC-V

+///

+#define CPU_STACK_ALIGNMENT   16

+

+///

+/// Page allocation granularity for RISC-V

+///

+#define DEFAULT_PAGE_ALLOCATION_GRANULARITY   (0x1000)

+#define RUNTIME_PAGE_ALLOCATION_GRANULARITY   (0x1000)

+

+//

+// Modifier to ensure that all protocol member functions and EFI intrinsics

+// use the correct C calling convention. All protocol member functions and

+// EFI intrinsics are required to modify their member functions with EFIAPI.

+//

+#ifdef EFIAPI

+  ///

+  /// If EFIAPI is already defined, then we use that definition.

+  ///

+#elif defined(__GNUC__)

+  ///

+  /// Define the standard calling convention regardless of optimization level

+  /// The GCC support assumes a GCC compiler that supports the EFI ABI. The EFI

+  /// ABI is much closer to the x64 Microsoft* ABI than standard x64 (x86-64)

+  /// GCC ABI. Thus a standard x64 (x86-64) GCC compiler can not be used for

+  /// x64. Warning the assembly code in the MDE x64 does not follow the correct

+  /// ABI for the standard x64 (x86-64) GCC.

+  ///

+  #define EFIAPI

+#else

+  ///

+  /// The default for a non Microsoft* or GCC compiler is to assume the EFI ABI

+  /// is the standard.

+  ///

+  #define EFIAPI

+#endif

+

+#if defined(__GNUC__)

+  ///

+  /// For GNU assembly code, .global or .globl can declare global symbols.

+  /// Define this macro to unify the usage.

+  ///

+  #define ASM_GLOBAL .globl

+#endif

+

+/**

+  Return the pointer to the first instruction of a function given a function pointer.

+  On x64 CPU architectures, these two pointer values are the same,

+  so the implementation of this macro is very simple.

+

+  @param  FunctionPointer   A pointer to a function.

+

+  @return The pointer to the first instruction of a function given a function pointer.

+

+**/

+#define FUNCTION_ENTRY_POINT(FunctionPointer) (VOID *)(UINTN)(FunctionPointer)

+

+#ifndef __USER_LABEL_PREFIX__

+#define __USER_LABEL_PREFIX__

+#endif

+

+#endif

-- 
2.25.0


-=-=-=-=-=-=
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#57192): https://edk2.groups.io/g/devel/message/57192
Mute This Topic: https://groups.io/mt/72916359/1779286
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [zhiguang.liu@intel.com]
-=-=-=-=-=-=


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [edk2-devel] [PATCH v1 2/9] MdePkg/Include: RISC-V definitions.
  2020-04-10  7:21 ` [PATCH v1 2/9] MdePkg/Include: RISC-V definitions Abner Chang
@ 2020-04-21  6:32   ` Zhiguang Liu
  0 siblings, 0 replies; 20+ messages in thread
From: Zhiguang Liu @ 2020-04-21  6:32 UTC (permalink / raw)
  To: devel@edk2.groups.io, abner.chang@hpe.com
  Cc: Gilbert Chen, Leif Lindholm, Kinney, Michael D, Gao, Liming

Reviewed-by: Zhiguang Liu <zhiguang.liu@intel.com>

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Abner Chang
Sent: Friday, April 10, 2020 3:21 PM
To: devel@edk2.groups.io
Cc: abner.chang@hpe.com; Gilbert Chen <gilbert.chen@hpe.com>; Leif Lindholm <leif.lindholm@linaro.org>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [edk2-devel] [PATCH v1 2/9] MdePkg/Include: RISC-V definitions.

Add RISC-V processor related definitions.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Co-authored-by: Gilbert Chen <gilbert.chen@hpe.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
---
 MdePkg/Include/IndustryStandard/PeImage.h | 12 +++++
 MdePkg/Include/Protocol/DebugSupport.h    | 55 +++++++++++++++++++++++
 MdePkg/Include/Protocol/PxeBaseCode.h     |  4 ++
 MdePkg/Include/Uefi/UefiBaseType.h        | 13 ++++++
 MdePkg/Include/Uefi/UefiSpec.h            |  5 +++
 5 files changed, 89 insertions(+)

diff --git a/MdePkg/Include/IndustryStandard/PeImage.h b/MdePkg/Include/IndustryStandard/PeImage.h
index a3d9bbed75..9b267002a1 100644
--- a/MdePkg/Include/IndustryStandard/PeImage.h
+++ b/MdePkg/Include/IndustryStandard/PeImage.h
@@ -9,6 +9,8 @@
 

 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>

 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

+Portions Copyright (c) 2016 - 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

+

 SPDX-License-Identifier: BSD-2-Clause-Patent

 

 **/

@@ -34,6 +36,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #define IMAGE_FILE_MACHINE_X64             0x8664

 #define IMAGE_FILE_MACHINE_ARMTHUMB_MIXED  0x01c2

 #define IMAGE_FILE_MACHINE_ARM64           0xAA64

+#define IMAGE_FILE_MACHINE_RISCV32         0x5032

+#define IMAGE_FILE_MACHINE_RISCV64         0x5064

+#define IMAGE_FILE_MACHINE_RISCV128        0x5128

 

 //

 // EXE file formats

@@ -493,6 +498,13 @@ typedef struct {
 #define EFI_IMAGE_REL_BASED_MIPS_JMPADDR16  9

 #define EFI_IMAGE_REL_BASED_DIR64           10

 

+///

+/// Relocation types of RISC-V processor.

+///

+#define EFI_IMAGE_REL_BASED_RISCV_HI20      5

+#define EFI_IMAGE_REL_BASED_RISCV_LOW12I    7

+#define EFI_IMAGE_REL_BASED_RISCV_LOW12S    8

+

 ///

 /// Line number format.

 ///

diff --git a/MdePkg/Include/Protocol/DebugSupport.h b/MdePkg/Include/Protocol/DebugSupport.h
index 800e7710e6..7fb1d3b3e4 100644
--- a/MdePkg/Include/Protocol/DebugSupport.h
+++ b/MdePkg/Include/Protocol/DebugSupport.h
@@ -7,6 +7,7 @@
 

 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>

 Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>

+Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

 

 SPDX-License-Identifier: BSD-2-Clause-Patent

 

@@ -603,6 +604,59 @@ typedef struct {
   UINT64  FAR;  // Fault Address Register

 } EFI_SYSTEM_CONTEXT_AARCH64;

 

+///

+/// RISC-V processor exception types.

+///

+#define EXCEPT_RISCV_INST_MISALIGNED              0

+#define EXCEPT_RISCV_INST_ACCESS_FAULT            1

+#define EXCEPT_RISCV_ILLEGAL_INST                 2

+#define EXCEPT_RISCV_BREAKPOINT                   3

+#define EXCEPT_RISCV_LOAD_ADDRESS_MISALIGNED      4

+#define EXCEPT_RISCV_LOAD_ACCESS_FAULT            5

+#define EXCEPT_RISCV_STORE_AMO_ADDRESS_MISALIGNED 6

+#define EXCEPT_RISCV_STORE_AMO_ACCESS_FAULT       7

+#define EXCEPT_RISCV_ENV_CALL_FROM_UMODE          8

+#define EXCEPT_RISCV_ENV_CALL_FROM_SMODE          9

+#define EXCEPT_RISCV_ENV_CALL_FROM_HMODE          10

+#define EXCEPT_RISCV_ENV_CALL_FROM_MMODE          11

+

+#define EXCEPT_RISCV_SOFTWARE_INT       0x0

+#define EXCEPT_RISCV_TIMER_INT          0x1

+

+typedef struct {

+  UINT64  X0;

+  UINT64  X1;

+  UINT64  X2;

+  UINT64  X3;

+  UINT64  X4;

+  UINT64  X5;

+  UINT64  X6;

+  UINT64  X7;

+  UINT64  X8;

+  UINT64  X9;

+  UINT64  X10;

+  UINT64  X11;

+  UINT64  X12;

+  UINT64  X13;

+  UINT64  X14;

+  UINT64  X15;

+  UINT64  X16;

+  UINT64  X17;

+  UINT64  X18;

+  UINT64  X19;

+  UINT64  X20;

+  UINT64  X21;

+  UINT64  X22;

+  UINT64  X23;

+  UINT64  X24;

+  UINT64  X25;

+  UINT64  X26;

+  UINT64  X27;

+  UINT64  X28;

+  UINT64  X29;

+  UINT64  X30;

+  UINT64  X31;

+} EFI_SYSTEM_CONTEXT_RISCV64;

 

 ///

 /// Universal EFI_SYSTEM_CONTEXT definition.

@@ -614,6 +668,7 @@ typedef union {
   EFI_SYSTEM_CONTEXT_IPF  *SystemContextIpf;

   EFI_SYSTEM_CONTEXT_ARM  *SystemContextArm;

   EFI_SYSTEM_CONTEXT_AARCH64  *SystemContextAArch64;

+  EFI_SYSTEM_CONTEXT_RISCV64  *SystemContextRiscV64;

 } EFI_SYSTEM_CONTEXT;

 

 //

diff --git a/MdePkg/Include/Protocol/PxeBaseCode.h b/MdePkg/Include/Protocol/PxeBaseCode.h
index b02d270134..c666d312b5 100644
--- a/MdePkg/Include/Protocol/PxeBaseCode.h
+++ b/MdePkg/Include/Protocol/PxeBaseCode.h
@@ -3,6 +3,8 @@
   devices for network access and network booting.

 

 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>

+Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

+

 SPDX-License-Identifier: BSD-2-Clause-Patent

 

   @par Revision Reference:

@@ -153,6 +155,8 @@ typedef UINT16  EFI_PXE_BASE_CODE_UDP_PORT;
 #define EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE    0x000A

 #elif defined (MDE_CPU_AARCH64)

 #define EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE    0x000B

+#elif defined (MDE_CPU_RISCV64)

+#define EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE    0x001B

 #endif

 

 

diff --git a/MdePkg/Include/Uefi/UefiBaseType.h b/MdePkg/Include/Uefi/UefiBaseType.h
index a62f13dd06..934fc07285 100644
--- a/MdePkg/Include/Uefi/UefiBaseType.h
+++ b/MdePkg/Include/Uefi/UefiBaseType.h
@@ -3,6 +3,7 @@
 

 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>

 Portions copyright (c) 2011 - 2016, ARM Ltd. All rights reserved.<BR>

+Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

 

 SPDX-License-Identifier: BSD-2-Clause-Patent

 

@@ -240,6 +241,12 @@ typedef union {
 ///

 #define EFI_IMAGE_MACHINE_AARCH64  0xAA64

 

+///

+/// PE32+ Machine type for RISC-V 32/64/128

+///

+#define EFI_IMAGE_MACHINE_RISCV32   0x5032

+#define EFI_IMAGE_MACHINE_RISCV64   0x5064

+#define EFI_IMAGE_MACHINE_RISCV128  0x5128

 

 #if   defined (MDE_CPU_IA32)

 

@@ -268,6 +275,12 @@ typedef union {
 

 #define EFI_IMAGE_MACHINE_CROSS_TYPE_SUPPORTED(Machine) (FALSE)

 

+#elif defined (MDE_CPU_RISCV64)

+#define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) \

+  ((Machine) == EFI_IMAGE_MACHINE_RISCV64)

+

+#define EFI_IMAGE_MACHINE_CROSS_TYPE_SUPPORTED(Machine) (FALSE)

+

 #elif defined (MDE_CPU_EBC)

 

 ///

diff --git a/MdePkg/Include/Uefi/UefiSpec.h b/MdePkg/Include/Uefi/UefiSpec.h
index 444aa35eca..8ffaf97515 100644
--- a/MdePkg/Include/Uefi/UefiSpec.h
+++ b/MdePkg/Include/Uefi/UefiSpec.h
@@ -6,6 +6,8 @@
   by this include file.

 

 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>

+Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

+

 SPDX-License-Identifier: BSD-2-Clause-Patent

 

 **/

@@ -2198,6 +2200,7 @@ typedef struct {
 #define EFI_REMOVABLE_MEDIA_FILE_NAME_X64     L"\\EFI\\BOOT\\BOOTX64.EFI"

 #define EFI_REMOVABLE_MEDIA_FILE_NAME_ARM     L"\\EFI\\BOOT\\BOOTARM.EFI"

 #define EFI_REMOVABLE_MEDIA_FILE_NAME_AARCH64 L"\\EFI\\BOOT\\BOOTAA64.EFI"

+#define EFI_REMOVABLE_MEDIA_FILE_NAME_RISCV64 L"\\EFI\\BOOT\\BOOTRISCV64.EFI"

 

 #if   defined (MDE_CPU_IA32)

   #define EFI_REMOVABLE_MEDIA_FILE_NAME   EFI_REMOVABLE_MEDIA_FILE_NAME_IA32

@@ -2208,6 +2211,8 @@ typedef struct {
   #define EFI_REMOVABLE_MEDIA_FILE_NAME   EFI_REMOVABLE_MEDIA_FILE_NAME_ARM

 #elif defined (MDE_CPU_AARCH64)

   #define EFI_REMOVABLE_MEDIA_FILE_NAME   EFI_REMOVABLE_MEDIA_FILE_NAME_AARCH64

+#elif defined (MDE_CPU_RISCV64)

+  #define EFI_REMOVABLE_MEDIA_FILE_NAME   EFI_REMOVABLE_MEDIA_FILE_NAME_RISCV64

 #else

   #error Unknown Processor Type

 #endif

-- 
2.25.0


-=-=-=-=-=-=
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#57193): https://edk2.groups.io/g/devel/message/57193
Mute This Topic: https://groups.io/mt/72916360/1779286
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [zhiguang.liu@intel.com]
-=-=-=-=-=-=


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [edk2-devel] [PATCH v1 3/9] MdePkg/BaseLib: BaseLib for RISC-V RV64 Processor.
  2020-04-10  7:21 ` [PATCH v1 3/9] MdePkg/BaseLib: BaseLib for RISC-V RV64 Processor Abner Chang
@ 2020-04-21  6:32   ` Zhiguang Liu
  0 siblings, 0 replies; 20+ messages in thread
From: Zhiguang Liu @ 2020-04-21  6:32 UTC (permalink / raw)
  To: devel@edk2.groups.io, abner.chang@hpe.com
  Cc: Gilbert Chen, Leif Lindholm, Kinney, Michael D, Gao, Liming

Reviewed-by: Zhiguang Liu <zhiguang.liu@intel.com>

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Abner Chang
Sent: Friday, April 10, 2020 3:21 PM
To: devel@edk2.groups.io
Cc: abner.chang@hpe.com; Gilbert Chen <gilbert.chen@hpe.com>; Leif Lindholm <leif.lindholm@linaro.org>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [edk2-devel] [PATCH v1 3/9] MdePkg/BaseLib: BaseLib for RISC-V RV64 Processor.

Add RISC-V RV64 BaseLib functions.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Co-authored-by: Gilbert Chen <gilbert.chen@hpe.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
---
 MdePkg/Library/BaseLib/BaseLib.inf            | 18 +++++-
 MdePkg/Include/Library/BaseLib.h              | 26 +++++++++
 .../Library/BaseLib/RiscV64/CpuBreakpoint.c   | 27 +++++++++
 MdePkg/Library/BaseLib/RiscV64/CpuPause.c     | 29 ++++++++++
 .../BaseLib/RiscV64/DisableInterrupts.c       | 24 ++++++++
 .../BaseLib/RiscV64/EnableInterrupts.c        | 25 +++++++++
 .../BaseLib/RiscV64/GetInterruptState.c       | 35 ++++++++++++
 .../BaseLib/RiscV64/InternalSwitchStack.c     | 55 +++++++++++++++++++
 MdePkg/Library/BaseLib/RiscV64/LongJump.c     | 32 +++++++++++
 MdePkg/Library/BaseLib/RiscV64/FlushCache.S   | 21 +++++++
 .../BaseLib/RiscV64/RiscVCpuBreakpoint.S      | 14 +++++
 .../Library/BaseLib/RiscV64/RiscVCpuPause.S   | 14 +++++
 .../Library/BaseLib/RiscV64/RiscVInterrupt.S  | 32 +++++++++++
 .../BaseLib/RiscV64/RiscVSetJumpLongJump.S    | 55 +++++++++++++++++++
 14 files changed, 406 insertions(+), 1 deletion(-)
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/CpuBreakpoint.c
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/CpuPause.c
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/DisableInterrupts.c
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/EnableInterrupts.c
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/GetInterruptState.c
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/LongJump.c
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/FlushCache.S
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/RiscVCpuBreakpoint.S
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/RiscVCpuPause.S
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S
 create mode 100644 MdePkg/Library/BaseLib/RiscV64/RiscVSetJumpLongJump.S

diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/BaseLib.inf
index 3586beb0ab..a57ae2da31 100644
--- a/MdePkg/Library/BaseLib/BaseLib.inf
+++ b/MdePkg/Library/BaseLib/BaseLib.inf
@@ -4,6 +4,7 @@
 #  Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>

 #  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

 #  Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>

+#  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

 #

 #  SPDX-License-Identifier: BSD-2-Clause-Patent

 #

@@ -20,7 +21,7 @@
   LIBRARY_CLASS                  = BaseLib

 

 #

-#  VALID_ARCHITECTURES           = IA32 X64 EBC ARM AARCH64

+#  VALID_ARCHITECTURES           = IA32 X64 EBC ARM AARCH64 RISCV64

 #

 

 [Sources]

@@ -381,6 +382,21 @@
   AArch64/CpuBreakpoint.asm         | MSFT

   AArch64/SpeculationBarrier.asm    | MSFT

 

+[Sources.RISCV64]

+  Math64.c

+  Unaligned.c

+  RiscV64/InternalSwitchStack.c

+  RiscV64/CpuBreakpoint.c

+  RiscV64/GetInterruptState.c

+  RiscV64/DisableInterrupts.c

+  RiscV64/EnableInterrupts.c

+  RiscV64/CpuPause.c

+  RiscV64/RiscVSetJumpLongJump.S    | GCC

+  RiscV64/RiscVCpuBreakpoint.S      | GCC

+  RiscV64/RiscVCpuPause.S           | GCC

+  RiscV64/RiscVInterrupt.S          | GCC

+  RiscV64/FlushCache.S              | GCC

+

 [Packages]

   MdePkg/MdePkg.dec

 

diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h
index ecadff8b23..41862e4285 100644
--- a/MdePkg/Include/Library/BaseLib.h
+++ b/MdePkg/Include/Library/BaseLib.h
@@ -4,6 +4,8 @@
 

 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>

 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

+Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

+

 SPDX-License-Identifier: BSD-2-Clause-Patent

 

 **/

@@ -124,6 +126,30 @@ typedef struct {
 

 #endif  // defined (MDE_CPU_AARCH64)

 

+#if defined (MDE_CPU_RISCV64)

+///

+/// The RISC-V architecture context buffer used by SetJump() and LongJump().

+///

+typedef struct {

+  UINT64                            RA;

+  UINT64                            S0;

+  UINT64                            S1;

+  UINT64                            S2;

+  UINT64                            S3;

+  UINT64                            S4;

+  UINT64                            S5;

+  UINT64                            S6;

+  UINT64                            S7;

+  UINT64                            S8;

+  UINT64                            S9;

+  UINT64                            S10;

+  UINT64                            S11;

+  UINT64                            SP;

+} BASE_LIBRARY_JUMP_BUFFER;

+

+#define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8

+

+#endif // defined (MDE_CPU_RISCV64)

 

 //

 // String Services

diff --git a/MdePkg/Library/BaseLib/RiscV64/CpuBreakpoint.c b/MdePkg/Library/BaseLib/RiscV64/CpuBreakpoint.c
new file mode 100644
index 0000000000..88d0877a2f
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/CpuBreakpoint.c
@@ -0,0 +1,27 @@
+/** @file

+  CPU breakpoint for RISC-V

+

+  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

+

+  SPDX-License-Identifier: BSD-2-Clause-Patent

+**/

+

+#include "BaseLibInternals.h"

+

+extern VOID RiscVCpuBreakpoint (VOID);

+

+/**

+  Generates a breakpoint on the CPU.

+

+  Generates a breakpoint on the CPU. The breakpoint must be implemented such

+  that code can resume normal execution after the breakpoint.

+

+**/

+VOID

+EFIAPI

+CpuBreakpoint (

+  VOID

+  )

+{

+  RiscVCpuBreakpoint ();

+}

diff --git a/MdePkg/Library/BaseLib/RiscV64/CpuPause.c b/MdePkg/Library/BaseLib/RiscV64/CpuPause.c
new file mode 100644
index 0000000000..9931bad294
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/CpuPause.c
@@ -0,0 +1,29 @@
+/** @file

+  CPU pause for RISC-V

+

+  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

+

+  SPDX-License-Identifier: BSD-2-Clause-Patent

+**/

+

+#include "BaseLibInternals.h"

+

+extern VOID RiscVCpuPause (VOID);

+

+

+/**

+  Requests CPU to pause for a short period of time.

+

+  Requests CPU to pause for a short period of time. Typically used in MP

+  systems to prevent memory starvation while waiting for a spin lock.

+

+**/

+VOID

+EFIAPI

+CpuPause (

+  VOID

+  )

+{

+  RiscVCpuPause ();

+}

+

diff --git a/MdePkg/Library/BaseLib/RiscV64/DisableInterrupts.c b/MdePkg/Library/BaseLib/RiscV64/DisableInterrupts.c
new file mode 100644
index 0000000000..867086c09c
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/DisableInterrupts.c
@@ -0,0 +1,24 @@
+/** @file

+  CPU disable interrupt function for RISC-V

+

+  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

+

+  SPDX-License-Identifier: BSD-2-Clause-Patent

+**/

+#include "BaseLibInternals.h"

+

+extern VOID RiscVDisableSupervisorModeInterrupts (VOID);

+

+/**

+  Disables CPU interrupts.

+

+**/

+VOID

+EFIAPI

+DisableInterrupts (

+  VOID

+  )

+{

+  RiscVDisableSupervisorModeInterrupts ();

+}

+

diff --git a/MdePkg/Library/BaseLib/RiscV64/EnableInterrupts.c b/MdePkg/Library/BaseLib/RiscV64/EnableInterrupts.c
new file mode 100644
index 0000000000..22ef73067e
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/EnableInterrupts.c
@@ -0,0 +1,25 @@
+/** @file

+  CPU enable interrupt function for RISC-V

+

+  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

+

+  SPDX-License-Identifier: BSD-2-Clause-Patent

+**/

+

+#include "BaseLibInternals.h"

+

+extern VOID RiscVEnableSupervisorModeInterrupt (VOID);

+

+/**

+  Enables CPU interrupts.

+

+**/

+VOID

+EFIAPI

+EnableInterrupts (

+  VOID

+  )

+{

+  RiscVEnableSupervisorModeInterrupt ();

+}

+

diff --git a/MdePkg/Library/BaseLib/RiscV64/GetInterruptState.c b/MdePkg/Library/BaseLib/RiscV64/GetInterruptState.c
new file mode 100644
index 0000000000..292f1ec441
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/GetInterruptState.c
@@ -0,0 +1,35 @@
+/** @file

+  CPU get interrupt state function for RISC-V

+

+  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

+

+  SPDX-License-Identifier: BSD-2-Clause-Patent

+**/

+

+#include "BaseLibInternals.h"

+

+extern UINT32 RiscVGetSupervisorModeInterrupts (VOID);

+

+/**

+  Retrieves the current CPU interrupt state.

+

+  Returns TRUE is interrupts are currently enabled. Otherwise

+  returns FALSE.

+

+  @retval TRUE  CPU interrupts are enabled.

+  @retval FALSE CPU interrupts are disabled.

+

+**/

+BOOLEAN

+EFIAPI

+GetInterruptState (

+  VOID

+  )

+{

+  unsigned long RetValue;

+

+  RetValue = RiscVGetSupervisorModeInterrupts ();

+  return RetValue? TRUE: FALSE;

+}

+

+

diff --git a/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c b/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c
new file mode 100644
index 0000000000..0bb292141d
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c
@@ -0,0 +1,55 @@
+/** @file

+  Switch stack function for RISC-V

+

+  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

+

+  SPDX-License-Identifier: BSD-2-Clause-Patent

+**/

+

+#include "BaseLibInternals.h"

+

+/**

+  Transfers control to a function starting with a new stack.

+

+  Transfers control to the function specified by EntryPoint using the

+  new stack specified by NewStack and passing in the parameters specified

+  by Context1 and Context2.  Context1 and Context2 are optional and may

+  be NULL.  The function EntryPoint must never return.

+  Marker will be ignored on IA-32, x64, and EBC.

+  IPF CPUs expect one additional parameter of type VOID * that specifies

+  the new backing store pointer.

+

+  If EntryPoint is NULL, then ASSERT().

+  If NewStack is NULL, then ASSERT().

+

+  @param  EntryPoint  A pointer to function to call with the new stack.

+  @param  Context1    A pointer to the context to pass into the EntryPoint

+                      function.

+  @param  Context2    A pointer to the context to pass into the EntryPoint

+                      function.

+  @param  NewStack    A pointer to the new stack to use for the EntryPoint

+                      function.

+  @param  Marker      VA_LIST marker for the variable argument list.

+

+**/

+VOID

+EFIAPI

+InternalSwitchStack (

+  IN      SWITCH_STACK_ENTRY_POINT  EntryPoint,

+  IN      VOID                      *Context1,   OPTIONAL

+  IN      VOID                      *Context2,   OPTIONAL

+  IN      VOID                      *NewStack,

+  IN      VA_LIST                   Marker

+  )

+{

+  BASE_LIBRARY_JUMP_BUFFER  JumpBuffer;

+

+  DEBUG ((DEBUG_INFO, "RISC-V InternalSwitchStack Entry:%x Context1:%x Context2:%x NewStack%x\n", \

+          EntryPoint, Context1, Context2, NewStack));

+  JumpBuffer.RA = (UINTN)EntryPoint;

+  JumpBuffer.SP = (UINTN)NewStack - sizeof (VOID *);

+  JumpBuffer.S0 = (UINT64)(UINTN)Context1;

+  JumpBuffer.S1 = (UINT64)(UINTN)Context2;

+  LongJump (&JumpBuffer, (UINTN)-1);

+  ASSERT(FALSE);

+}

diff --git a/MdePkg/Library/BaseLib/RiscV64/LongJump.c b/MdePkg/Library/BaseLib/RiscV64/LongJump.c
new file mode 100644
index 0000000000..fb2ed3fa2d
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/LongJump.c
@@ -0,0 +1,32 @@
+/** @file

+  Long jump implementation of RISC-V

+

+  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

+

+  SPDX-License-Identifier: BSD-2-Clause-Patent

+**/

+

+#include "BaseLibInternals.h"

+

+

+/**

+  Restores the CPU context that was saved with SetJump().

+

+  Restores the CPU context from the buffer specified by JumpBuffer.

+  This function never returns to the caller.

+  Instead is resumes execution based on the state of JumpBuffer.

+

+  @param  JumpBuffer    A pointer to CPU context buffer.

+  @param  Value         The value to return when the SetJump() context is restored.

+

+**/

+VOID

+EFIAPI

+InternalLongJump (

+  IN      BASE_LIBRARY_JUMP_BUFFER  *JumpBuffer,

+  IN      UINTN                     Value

+  )

+{

+    ASSERT (FALSE);

+}

+

diff --git a/MdePkg/Library/BaseLib/RiscV64/FlushCache.S b/MdePkg/Library/BaseLib/RiscV64/FlushCache.S
new file mode 100644
index 0000000000..7c10fdd268
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/FlushCache.S
@@ -0,0 +1,21 @@
+//------------------------------------------------------------------------------

+//

+// RISC-V cache operation.

+//

+// Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

+//

+// SPDX-License-Identifier: BSD-2-Clause-Patent

+//

+//------------------------------------------------------------------------------

+

+.align 3

+ASM_GLOBAL ASM_PFX(RiscVInvalidateInstCacheAsm)

+ASM_GLOBAL ASM_PFX(RiscVInvalidateDataCacheAsm)

+

+ASM_PFX(RiscVInvalidateInstCacheAsm):

+    fence.i

+    ret

+

+ASM_PFX(RiscVInvalidateDataCacheAsm):

+    fence

+    ret

diff --git a/MdePkg/Library/BaseLib/RiscV64/RiscVCpuBreakpoint.S b/MdePkg/Library/BaseLib/RiscV64/RiscVCpuBreakpoint.S
new file mode 100644
index 0000000000..ccf91df816
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/RiscVCpuBreakpoint.S
@@ -0,0 +1,14 @@
+//------------------------------------------------------------------------------

+//

+// CpuBreakpoint for RISC-V

+//

+// Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

+//

+// SPDX-License-Identifier: BSD-2-Clause-Patent

+//

+//------------------------------------------------------------------------------

+

+ASM_GLOBAL ASM_PFX(RiscVCpuBreakpoint)

+ASM_PFX(RiscVCpuBreakpoint):

+  ebreak

+  ret

diff --git a/MdePkg/Library/BaseLib/RiscV64/RiscVCpuPause.S b/MdePkg/Library/BaseLib/RiscV64/RiscVCpuPause.S
new file mode 100644
index 0000000000..6660c2fcb3
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/RiscVCpuPause.S
@@ -0,0 +1,14 @@
+//------------------------------------------------------------------------------

+//

+// CpuPause for RISC-V

+//

+// Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

+//

+// SPDX-License-Identifier: BSD-2-Clause-Patent

+//

+//------------------------------------------------------------------------------

+

+ASM_GLOBAL ASM_PFX(RiscVCpuPause)

+ASM_PFX(RiscVCpuPause):

+  nop

+  ret

diff --git a/MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S b/MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S
new file mode 100644
index 0000000000..766fcfb9cb
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S
@@ -0,0 +1,32 @@
+//------------------------------------------------------------------------------

+//

+// RISC-V Supervisor Mode interrupt enable/disable

+//

+// Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

+//

+// SPDX-License-Identifier: BSD-2-Clause-Patent

+//

+//------------------------------------------------------------------------------

+

+ASM_GLOBAL ASM_PFX(RiscVDisableSupervisorModeInterrupts)

+ASM_GLOBAL ASM_PFX(RiscVEnableSupervisorModeInterrupt)

+ASM_GLOBAL ASM_PFX(RiscVGetSupervisorModeInterrupts)

+

+# define  MSTATUS_SIE    0x00000002

+# define  CSR_SSTATUS    0x100

+

+ASM_PFX(RiscVDisableSupervisorModeInterrupts):

+  li   a1, MSTATUS_SIE

+  csrc CSR_SSTATUS, a1

+  ret

+

+ASM_PFX(RiscVEnableSupervisorModeInterrupt):

+  li   a1, MSTATUS_SIE

+  csrs CSR_SSTATUS, a1

+  ret

+

+ASM_PFX(RiscVGetSupervisorModeInterrupts):

+  csrr a0, CSR_SSTATUS

+  andi a0, a0, MSTATUS_SIE

+  ret

+

diff --git a/MdePkg/Library/BaseLib/RiscV64/RiscVSetJumpLongJump.S b/MdePkg/Library/BaseLib/RiscV64/RiscVSetJumpLongJump.S
new file mode 100644
index 0000000000..34486eabba
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/RiscVSetJumpLongJump.S
@@ -0,0 +1,55 @@
+//------------------------------------------------------------------------------

+//

+// Set/Long jump for RISC-V

+//

+// Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

+//

+// SPDX-License-Identifier: BSD-2-Clause-Patent

+//

+//------------------------------------------------------------------------------

+# define REG_S  sd

+# define REG_L  ld

+# define SZREG  8

+.align 3

+    .globl  SetJump

+

+SetJump:

+    REG_S ra,  0*SZREG(a0)

+    REG_S s0,  1*SZREG(a0)

+    REG_S s1,  2*SZREG(a0)

+    REG_S s2,  3*SZREG(a0)

+    REG_S s3,  4*SZREG(a0)

+    REG_S s4,  5*SZREG(a0)

+    REG_S s5,  6*SZREG(a0)

+    REG_S s6,  7*SZREG(a0)

+    REG_S s7,  8*SZREG(a0)

+    REG_S s8,  9*SZREG(a0)

+    REG_S s9,  10*SZREG(a0)

+    REG_S s10, 11*SZREG(a0)

+    REG_S s11, 12*SZREG(a0)

+    REG_S sp,  13*SZREG(a0)

+    li    a0,  0

+    ret

+

+    .globl  InternalLongJump

+InternalLongJump:

+    REG_L ra,  0*SZREG(a0)

+    REG_L s0,  1*SZREG(a0)

+    REG_L s1,  2*SZREG(a0)

+    REG_L s2,  3*SZREG(a0)

+    REG_L s3,  4*SZREG(a0)

+    REG_L s4,  5*SZREG(a0)

+    REG_L s5,  6*SZREG(a0)

+    REG_L s6,  7*SZREG(a0)

+    REG_L s7,  8*SZREG(a0)

+    REG_L s8,  9*SZREG(a0)

+    REG_L s9,  10*SZREG(a0)

+    REG_L s10, 11*SZREG(a0)

+    REG_L s11, 12*SZREG(a0)

+    REG_L sp,  13*SZREG(a0)

+

+    add   a0, s0, 0

+    add   a1, s1, 0

+    add   a2, s2, 0

+    add   a3, s3, 0

+    ret

-- 
2.25.0


-=-=-=-=-=-=
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#57194): https://edk2.groups.io/g/devel/message/57194
Mute This Topic: https://groups.io/mt/72916361/1779286
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [zhiguang.liu@intel.com]
-=-=-=-=-=-=


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [edk2-devel] [PATCH v1 4/9] MdePkg/BaseCacheMaintenanceLib: RISC-V cache maintenance implementation.
  2020-04-10  7:21 ` [PATCH v1 4/9] MdePkg/BaseCacheMaintenanceLib: RISC-V cache maintenance implementation Abner Chang
@ 2020-04-21  6:32   ` Zhiguang Liu
  0 siblings, 0 replies; 20+ messages in thread
From: Zhiguang Liu @ 2020-04-21  6:32 UTC (permalink / raw)
  To: devel@edk2.groups.io, abner.chang@hpe.com
  Cc: Gilbert Chen, Leif Lindholm, Kinney, Michael D, Gao, Liming

Reviewed-by: Zhiguang Liu <zhiguang.liu@intel.com>

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Abner Chang
Sent: Friday, April 10, 2020 3:21 PM
To: devel@edk2.groups.io
Cc: abner.chang@hpe.com; Gilbert Chen <gilbert.chen@hpe.com>; Leif Lindholm <leif.lindholm@linaro.org>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [edk2-devel] [PATCH v1 4/9] MdePkg/BaseCacheMaintenanceLib: RISC-V cache maintenance implementation.

Implement RISC-V cache maintenance functions in
BaseCacheMaintenanceLib.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Co-authored-by: Gilbert Chen <gilbert.chen@hpe.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
---
 .../BaseCacheMaintenanceLib.inf               |   4 +
 .../BaseCacheMaintenanceLib/RiscVCache.c      | 250 ++++++++++++++++++
 2 files changed, 254 insertions(+)
 create mode 100644 MdePkg/Library/BaseCacheMaintenanceLib/RiscVCache.c

diff --git a/MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf b/MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf
index ec7feecf9c..33114243d5 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.<BR>

 #  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

+#  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

 #

 #  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 0000000000..21a695c843
--- /dev/null
+++ b/MdePkg/Library/BaseCacheMaintenanceLib/RiscVCache.c
@@ -0,0 +1,250 @@
+/** @file

+  RISC-V specific functionality for cache.

+

+  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

+

+  SPDX-License-Identifier: BSD-2-Clause-Patent

+**/

+

+#include <Base.h>

+#include <Library/BaseLib.h>

+#include <Library/DebugLib.h>

+

+/**

+  RISC-V invalidate instruction cache.

+

+**/

+VOID

+EFIAPI

+RiscVInvalidateInstCacheAsm (

+  VOID

+  );

+

+/**

+  RISC-V invalidate data cache.

+

+**/

+VOID

+EFIAPI

+RiscVInvalidateDataCacheAsm (

+  VOID

+  );

+

+/**

+  Invalidates the entire instruction cache in cache coherency domain of the

+  calling CPU.

+

+**/

+VOID

+EFIAPI

+InvalidateInstructionCache (

+  VOID

+  )

+{

+  RiscVInvalidateInstCacheAsm ();

+}

+

+/**

+  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__));

+  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__));

+}

+

+/**

+  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 unsupported function.\n", __FUNCTION__));

+  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 unsupported function.\n", __FUNCTION__));

+}

+

+/**

+  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 unsupported function.\n", __FUNCTION__));

+  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

+  )

+{

+  RiscVInvalidateDataCacheAsm ();

+}

+

+/**

+  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 unsupported function.\n", __FUNCTION__));

+  return Address;

+}

-- 
2.25.0


-=-=-=-=-=-=
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#57195): https://edk2.groups.io/g/devel/message/57195
Mute This Topic: https://groups.io/mt/72916362/1779286
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [zhiguang.liu@intel.com]
-=-=-=-=-=-=


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [edk2-devel] [PATCH v1 5/9] MdePkg/BaseIoLibIntrinsic: Rename IoLibArm.c=>IoLibNoIo.c
  2020-04-10  7:21 ` [PATCH v1 5/9] MdePkg/BaseIoLibIntrinsic: Rename IoLibArm.c=>IoLibNoIo.c Abner Chang
@ 2020-04-21  6:36   ` Zhiguang Liu
  2020-04-21  8:21     ` Abner Chang
  0 siblings, 1 reply; 20+ messages in thread
From: Zhiguang Liu @ 2020-04-21  6:36 UTC (permalink / raw)
  To: devel@edk2.groups.io, abner.chang@hpe.com
  Cc: Gilbert Chen, Leif Lindholm, Kinney, Michael D, Gao, Liming

Hi Abner,

In BaseIoLibIntrinsic.inf, you add the line "This I/O library only provides non I/O read and write."
I supposed this is a description for ARM and RISC-V but not for other arch. If so, please specify it because this is an inf files all arch are using.

Thanks
Zhiguang

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Abner Chang
Sent: Friday, April 10, 2020 3:21 PM
To: devel@edk2.groups.io
Cc: abner.chang@hpe.com; Gilbert Chen <gilbert.chen@hpe.com>; Leif Lindholm <leif.lindholm@linaro.org>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [edk2-devel] [PATCH v1 5/9] MdePkg/BaseIoLibIntrinsic: Rename IoLibArm.c=>IoLibNoIo.c

RISC-V MMIO library instance.
IoLibArm.c in fact implements a generic Mmio-only (and ANSI
C compliant), so rename it to better reflect this.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Co-authored-by: Gilbert Chen <gilbert.chen@hpe.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
---
 .../BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf        | 12 ++++++++----
 .../BaseIoLibIntrinsic/{IoLibArm.c => IoLibNoIo.c}   |  4 +++-
 2 files changed, 11 insertions(+), 5 deletions(-)
 rename MdePkg/Library/BaseIoLibIntrinsic/{IoLibArm.c => IoLibNoIo.c} (94%)

diff --git a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
index 457cce9378..cc23b6b227 100644
--- a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
+++ b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
@@ -4,11 +4,12 @@
 #  I/O Library that uses compiler intrinsics to perform IN and OUT instructions

 #  for IA-32 and x64.  On IPF, I/O port requests are translated into MMIO requests.

 #  MMIO requests are forwarded directly to memory.  For EBC, I/O port requests

-#  ASSERT().

+#  ASSERT(). This I/O library only provides non I/O read and write.

 #

 #  Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>

 #  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

 #  Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>

+#  Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

 #

 #  SPDX-License-Identifier: BSD-2-Clause-Patent

 #

@@ -25,7 +26,7 @@
 

 

 #

-#  VALID_ARCHITECTURES           = IA32 X64 EBC ARM AARCH64

+#  VALID_ARCHITECTURES           = IA32 X64 EBC ARM AARCH64 RISCV64

 #

 

 [Sources]

@@ -50,10 +51,13 @@
   IoLib.c

 

 [Sources.ARM]

-  IoLibArm.c

+  IoLibNoIo.c

 

 [Sources.AARCH64]

-  IoLibArm.c

+  IoLibNoIo.c

+

+[Sources.RISCV64]

+  IoLibNoIo.c

 

 [Packages]

   MdePkg/MdePkg.dec

diff --git a/MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c b/MdePkg/Library/BaseIoLibIntrinsic/IoLibNoIo.c
similarity index 94%
rename from MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c
rename to MdePkg/Library/BaseIoLibIntrinsic/IoLibNoIo.c
index c6b822461d..a107136a74 100644
--- a/MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c
+++ b/MdePkg/Library/BaseIoLibIntrinsic/IoLibNoIo.c
@@ -1,9 +1,11 @@
 /** @file

-  I/O Library for ARM.

+  I/O library for non I/O read and write access (memory map I/O read and

+  write only) architecture, such as ARM and RISC-V processor.

 

   Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>

   Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

   Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>

+  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>

 

   SPDX-License-Identifier: BSD-2-Clause-Patent

 

-- 
2.25.0


-=-=-=-=-=-=
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#57196): https://edk2.groups.io/g/devel/message/57196
Mute This Topic: https://groups.io/mt/72916363/1779286
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [zhiguang.liu@intel.com]
-=-=-=-=-=-=


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [edk2-devel] [PATCH v1 6/9] MdePkg/BasePeCoff: Add RISC-V PE/Coff related code.
  2020-04-10  7:21 ` [PATCH v1 6/9] MdePkg/BasePeCoff: Add RISC-V PE/Coff related code Abner Chang
@ 2020-04-21  6:36   ` Zhiguang Liu
  0 siblings, 0 replies; 20+ messages in thread
From: Zhiguang Liu @ 2020-04-21  6:36 UTC (permalink / raw)
  To: devel@edk2.groups.io, abner.chang@hpe.com
  Cc: Gilbert Chen, Leif Lindholm, Kinney, Michael D, Gao, Liming

Reviewed-by: Zhiguang Liu <zhiguang.liu@intel.com>

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Abner Chang
Sent: Friday, April 10, 2020 3:21 PM
To: devel@edk2.groups.io
Cc: abner.chang@hpe.com; Gilbert Chen <gilbert.chen@hpe.com>; Leif Lindholm <leif.lindholm@linaro.org>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [edk2-devel] [PATCH v1 6/9] MdePkg/BasePeCoff: Add RISC-V PE/Coff related code.

Support RISC-V image relocation.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Co-authored-by: Gilbert Chen <gilbert.chen@hpe.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
---
 .../Library/BasePeCoffLib/BasePeCoffLib.inf   |   5 +
 .../BasePeCoffLib/BasePeCoffLibInternals.h    |   9 ++
 MdePkg/Library/BasePeCoffLib/BasePeCoff.c     |   3 +-
 .../BasePeCoffLib/RiscV/PeCoffLoaderEx.c      | 133 ++++++++++++++++++
 .../Library/BasePeCoffLib/BasePeCoffLib.uni   |   2 +
 5 files changed, 151 insertions(+), 1 deletion(-)  create mode 100644 MdePkg/Library/BasePeCoffLib/RiscV/PeCoffLoaderEx.c

diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf b/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
index 395c1403c0..110b6d5a09 100644
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
+++ b/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
@@ -3,6 +3,7 @@
 #  The IPF version library supports loading IPF and EBC PE/COFF image. #  The IA32 version library support loading IA32, X64 and EBC PE/COFF images. #  The X64 version library support loading IA32, X64 and EBC PE/COFF images.+#  The RISC-V version library support loading RISC-V images. # #  Caution: This module requires additional review when modified. #  This library will have external input - PE/COFF image.@@ -11,6 +12,7 @@  # #  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> #  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>+#  Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR> # #  SPDX-License-Identifier: BSD-2-Clause-Patent #@@ -41,6 +43,9 @@
 [Sources.ARM]   Arm/PeCoffLoaderEx.c +[Sources.RISCV64]+  RiscV/PeCoffLoaderEx.c+ [Packages]   MdePkg/MdePkg.dec diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoffLibInternals.h b/MdePkg/Library/BasePeCoffLib/BasePeCoffLibInternals.h
index b74277f3e8..3ee56e0e5f 100644
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoffLibInternals.h
+++ b/MdePkg/Library/BasePeCoffLib/BasePeCoffLibInternals.h
@@ -2,6 +2,7 @@
   Declaration of internal functions in PE/COFF Lib.    Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>+  Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>   SPDX-License-Identifier: BSD-2-Clause-Patent  **/@@ -16,6 +17,14 @@
 #include <Library/PeCoffExtraActionLib.h> #include <IndustryStandard/PeImage.h> +//+// Macro definitions for RISC-V architecture.+//+#define RV_X(x, s, n) (((x) >> (s)) & ((1<<(n))-1))+#define RISCV_IMM_BITS 12+#define RISCV_IMM_REACH (1LL<<RISCV_IMM_BITS)+#define RISCV_CONST_HIGH_PART(VALUE) \+  (((VALUE) + (RISCV_IMM_REACH/2)) & ~(RISCV_IMM_REACH-1))   /**diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
index 07bb62f860..1102833b94 100644
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
+++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
@@ -1,6 +1,6 @@
 /** @file   Base PE/COFF loader supports loading any PE32/PE32+ or TE image, but-  only supports relocating IA32, x64, IPF, and EBC images.+  only supports relocating IA32, x64, IPF, ARM, RISC-V and EBC images.    Caution: This file requires additional review when modified.   This library will have external input - PE/COFF image.@@ -17,6 +17,7 @@
    Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>   Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>+  Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>   SPDX-License-Identifier: BSD-2-Clause-Patent  **/diff --git a/MdePkg/Library/BasePeCoffLib/RiscV/PeCoffLoaderEx.c b/MdePkg/Library/BasePeCoffLib/RiscV/PeCoffLoaderEx.c
new file mode 100644
index 0000000000..23170a6603
--- /dev/null
+++ b/MdePkg/Library/BasePeCoffLib/RiscV/PeCoffLoaderEx.c
@@ -0,0 +1,133 @@
+/** @file+  PE/Coff loader for RISC-V PE image++  Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>+  SPDX-License-Identifier: BSD-2-Clause-Patent+**/+#include "BasePeCoffLibInternals.h"+#include <Library/BaseLib.h>++/**+  Performs an RISC-V specific relocation fixup and is a no-op on+  other instruction sets.+  RISC-V splits 32-bit fixup into 20bit and 12-bit with two relocation+  types. We have to know the lower 12-bit fixup first then we can deal+  carry over on high 20-bit fixup. So we log the high 20-bit in+  FixupData.++  @param  Reloc       The pointer to the relocation record.+  @param  Fixup       The pointer to the address to fix up.+  @param  FixupData   The pointer to a buffer to log the fixups.+  @param  Adjust      The offset to adjust the fixup.++  @return Status code.++**/+RETURN_STATUS+PeCoffLoaderRelocateImageEx (+  IN UINT16      *Reloc,+  IN OUT CHAR8   *Fixup,+  IN OUT CHAR8   **FixupData,+  IN UINT64      Adjust+  )+{+  UINT32 Value;+  UINT32 Value2;+  UINT32 *RiscVHi20Fixup;++  switch ((*Reloc) >> 12) {+  case EFI_IMAGE_REL_BASED_RISCV_HI20:+      *(UINT64 *)(*FixupData) = (UINT64)(UINTN)Fixup;+      break;++  case EFI_IMAGE_REL_BASED_RISCV_LOW12I:+      RiscVHi20Fixup =  (UINT32 *)(*(UINT64 *)(*FixupData));+      if (RiscVHi20Fixup != NULL) {++        Value = (UINT32)(RV_X(*RiscVHi20Fixup, 12, 20) << 12);+        Value2 = (UINT32)(RV_X(*(UINT32 *)Fixup, 20, 12));+        if (Value2 & (RISCV_IMM_REACH/2)) {+          Value2 |= ~(RISCV_IMM_REACH-1);+        }+        Value += Value2;+        Value += (UINT32)Adjust;+        Value2 = RISCV_CONST_HIGH_PART (Value);+        *(UINT32 *)RiscVHi20Fixup = (RV_X (Value2, 12, 20) << 12) |\+                                           (RV_X (*(UINT32 *)RiscVHi20Fixup, 0, 12));+        *(UINT32 *)Fixup = (RV_X (Value, 0, 12) << 20) |\+                           (RV_X (*(UINT32 *)Fixup, 0, 20));+      }+      break;++  case EFI_IMAGE_REL_BASED_RISCV_LOW12S:+      RiscVHi20Fixup =  (UINT32 *)(*(UINT64 *)(*FixupData));+      if (RiscVHi20Fixup != NULL) {+        Value = (UINT32)(RV_X(*RiscVHi20Fixup, 12, 20) << 12);+        Value2 = (UINT32)(RV_X(*(UINT32 *)Fixup, 7, 5) | (RV_X(*(UINT32 *)Fixup, 25, 7) << 5));+        if (Value2 & (RISCV_IMM_REACH/2)) {+          Value2 |= ~(RISCV_IMM_REACH-1);+        }+        Value += Value2;+        Value += (UINT32)Adjust;+        Value2 = RISCV_CONST_HIGH_PART (Value);+        *(UINT32 *)RiscVHi20Fixup = (RV_X (Value2, 12, 20) << 12) | \+                                           (RV_X (*(UINT32 *)RiscVHi20Fixup, 0, 12));+        Value2 = *(UINT32 *)Fixup & 0x01fff07f;+        Value &= RISCV_IMM_REACH - 1;+        *(UINT32 *)Fixup = Value2 | (UINT32)(((RV_X(Value, 0, 5) << 7) | (RV_X(Value, 5, 7) << 25)));+      }+      break;++  default:+      return RETURN_UNSUPPORTED;++  }+  return RETURN_SUCCESS;+}++/**+  Returns TRUE if the machine type of PE/COFF image is supported. Supported+  does not mean the image can be executed it means the PE/COFF loader supports+  loading and relocating of the image type. It's up to the caller to support+  the entry point.++  @param  Machine   Machine type from the PE Header.++  @return TRUE if this PE/COFF loader can load the image++**/+BOOLEAN+PeCoffLoaderImageFormatSupported (+  IN  UINT16  Machine+  )+{+  if (Machine ==  IMAGE_FILE_MACHINE_RISCV64) {+    return TRUE;+  }++  return FALSE;+}++/**+  Performs an Itanium-based specific re-relocation fixup and is a no-op on other+  instruction sets. This is used to re-relocated the image into the EFI virtual+  space for runtime calls.++  @param  Reloc       The pointer to the relocation record.+  @param  Fixup       The pointer to the address to fix up.+  @param  FixupData   The pointer to a buffer to log the fixups.+  @param  Adjust      The offset to adjust the fixup.++  @return Status code.++**/+RETURN_STATUS+PeHotRelocateImageEx (+  IN UINT16      *Reloc,+  IN OUT CHAR8   *Fixup,+  IN OUT CHAR8   **FixupData,+  IN UINT64      Adjust+  )+{+  return RETURN_UNSUPPORTED;+}diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.uni b/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.uni
index b0ea702f76..55417029f2 100644
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.uni
+++ b/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.uni
@@ -4,6 +4,7 @@
 // The IPF version library supports loading IPF and EBC PE/COFF image. // The IA32 version library support loading IA32, X64 and EBC PE/COFF images. // The X64 version library support loading IA32, X64 and EBC PE/COFF images.+// The RISC-V version library support loading RISC-V32 and RISC-V64 PE/COFF images. // // Caution: This module requires additional review when modified. // This library will have external input - PE/COFF image.@@ -12,6 +13,7 @@  // // Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> // Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>+// Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR> // // SPDX-License-Identifier: BSD-2-Clause-Patent //--
2.25.0


-=-=-=-=-=-=
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#57197): https://edk2.groups.io/g/devel/message/57197
Mute This Topic: https://groups.io/mt/72916364/1779286
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [zhiguang.liu@intel.com]
-=-=-=-=-=-=


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [edk2-devel] [PATCH v1 9/9] MdePkg/BaseSafeIntLib: Add RISCV64 arch for BaseSafeIntLib.
  2020-04-10  7:21 ` [PATCH v1 9/9] MdePkg/BaseSafeIntLib: Add RISCV64 arch for BaseSafeIntLib Abner Chang
@ 2020-04-21  6:36   ` Zhiguang Liu
  0 siblings, 0 replies; 20+ messages in thread
From: Zhiguang Liu @ 2020-04-21  6:36 UTC (permalink / raw)
  To: devel@edk2.groups.io, abner.chang@hpe.com
  Cc: Leif Lindholm, Kinney, Michael D, Gao, Liming, Leif Lindholm,
	Gilbert Chen, Daniel Helmut Schaefer

Reviewed-by: Zhiguang Liu <zhiguang.liu@intel.com>

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Abner Chang
Sent: Friday, April 10, 2020 3:21 PM
To: devel@edk2.groups.io
Cc: abner.chang@hpe.com; Leif Lindholm <leif@nuviainc.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>; Leif Lindholm <leif.lindholm@linaro.org>; Gilbert Chen <gilbert.chen@hpe.com>; Daniel Helmut Schaefer <daniel.schaefer@hpe.com>
Subject: [edk2-devel] [PATCH v1 9/9] MdePkg/BaseSafeIntLib: Add RISCV64 arch for BaseSafeIntLib.

Add RISCV64 arch for BaseSafeIntLib library.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Reviewed-by: Leif Lindholm <leif@nuviainc.com>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
Cc: Daniel Helmut Schaefer <daniel.schaefer@hpe.com>
---
 MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf b/MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
index 68ade962d6..40017ec88b 100644
--- a/MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
+++ b/MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
@@ -6,6 +6,8 @@
 # #  Copyright (c) 2018, Intel Corporation. All rights reserved.<BR> # Copyright (c) 2017, Microsoft Corporation+#  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>+ # # All rights reserved. # SPDX-License-Identifier: BSD-2-Clause-Patent@@ -23,7 +25,7 @@
 # # The following information is for reference only and not required by the build tools. #-#  VALID_ARCHITECTURES           = IA32 X64+#  VALID_ARCHITECTURES           = IA32 X64 ARM AARCH64 RISCV64 #  [Sources]@@ -32,7 +34,7 @@
 [Sources.Ia32, Sources.ARM]   SafeIntLib32.c -[Sources.X64, Sources.AARCH64]+[Sources.X64, Sources.AARCH64, Sources.RISCV64]   SafeIntLib64.c  [Sources.EBC]-- 
2.25.0


-=-=-=-=-=-=
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#57199): https://edk2.groups.io/g/devel/message/57199
Mute This Topic: https://groups.io/mt/72916366/1779286
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [zhiguang.liu@intel.com] -=-=-=-=-=-=


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [edk2-devel] [PATCH v1 8/9] MdePkg/BaseSynchronizationLib: RISC-V cache related code.
  2020-04-10  7:21 ` [PATCH v1 8/9] MdePkg/BaseSynchronizationLib: RISC-V cache related code Abner Chang
@ 2020-04-21  6:36   ` Zhiguang Liu
  0 siblings, 0 replies; 20+ messages in thread
From: Zhiguang Liu @ 2020-04-21  6:36 UTC (permalink / raw)
  To: devel@edk2.groups.io, abner.chang@hpe.com
  Cc: Gilbert Chen, Leif Lindholm, Kinney, Michael D, Gao, Liming

Reviewed-by: Zhiguang Liu <zhiguang.liu@intel.com>

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Abner Chang
Sent: Friday, April 10, 2020 3:21 PM
To: devel@edk2.groups.io
Cc: abner.chang@hpe.com; Gilbert Chen <gilbert.chen@hpe.com>; Leif Lindholm <leif.lindholm@linaro.org>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [edk2-devel] [PATCH v1 8/9] MdePkg/BaseSynchronizationLib: RISC-V cache related code.

Support RISC-V cache related functions.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Co-authored-by: Gilbert Chen <gilbert.chen@hpe.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
---
 .../BaseSynchronizationLib.inf                |  5 ++
 .../RiscV64/SynchronizationAsm.S              | 78 +++++++++++++++++++
 2 files changed, 83 insertions(+)
 create mode 100644 MdePkg/Library/BaseSynchronizationLib/RiscV64/SynchronizationAsm.S

diff --git a/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf b/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
index 446bc19b63..9309d2e1d5 100755
--- a/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
+++ b/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
@@ -3,6 +3,7 @@
 # #  Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR> #  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>+#  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR> # #  SPDX-License-Identifier: BSD-2-Clause-Patent #@@ -78,6 +79,10 @@
   AArch64/Synchronization.S     | GCC   AArch64/Synchronization.asm   | MSFT +[Sources.RISCV64]+  Synchronization.c+  RiscV64/SynchronizationAsm.S+ [Packages]   MdePkg/MdePkg.dec diff --git a/MdePkg/Library/BaseSynchronizationLib/RiscV64/SynchronizationAsm.S b/MdePkg/Library/BaseSynchronizationLib/RiscV64/SynchronizationAsm.S
new file mode 100644
index 0000000000..bac80d6871
--- /dev/null
+++ b/MdePkg/Library/BaseSynchronizationLib/RiscV64/SynchronizationAsm.S
@@ -0,0 +1,78 @@
+//------------------------------------------------------------------------------+//+// RISC-V synchronization functions.+//+// Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>+//+// SPDX-License-Identifier: BSD-2-Clause-Patent+//+//------------------------------------------------------------------------------+#include <Base.h>++.data++.text+.align 3++.global ASM_PFX(InternalSyncCompareExchange32)+.global ASM_PFX(InternalSyncCompareExchange64)+.global ASM_PFX(InternalSyncIncrement)+.global ASM_PFX(InternalSyncDecrement)++//+// ompare and xchange a 32-bit value.+//+// @param a0 : Pointer to 32-bit value.+// @param a1 : Compare value.+// @param a2 : Exchange value.+//+ASM_PFX (InternalSyncCompareExchange32):+    lr.w  a3, (a0)        // Load the value from a0 and make+                          // the reservation of address.+    bne   a3, a1, exit+    sc.w  a3, a2, (a0)    // Write the value back to the address.+    mv    a3, a1+exit:+    mv    a0, a3+    ret++.global ASM_PFX(InternalSyncCompareExchange64)++//+// Compare and xchange a 64-bit value.+//+// @param a0 : Pointer to 64-bit value.+// @param a1 : Compare value.+// @param a2 : Exchange value.+//+ASM_PFX (SyncCompareExchange64):+    lr.d  a3, (a0)       // Load the value from a0 and make+                         // the reservation of address.+    bne   a3, a1, exit+    sc.d  a3, a2, (a0)   // Write the value back to the address.+    mv    a3, a1+exit2:+    mv    a0, a3+    ret++//+// Performs an atomic increment of an 32-bit unsigned integer.+//+// @param a0 : Pointer to 32-bit value.+//+ASM_PFX (InternalSyncIncrement):+    li  a1, 1+    amoadd.w  a2, a1, (a0)+    mv  a0, a2+    ret++//+// Performs an atomic decrement of an 32-bit unsigned integer.+//+// @param a0 : Pointer to 32-bit value.+//+ASM_PFX (InternalSyncDecrement):+    li  a1, -1+    amoadd.w  a2, a1, (a0)+    mv  a0, a2+    ret-- 
2.25.0


-=-=-=-=-=-=
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#57198): https://edk2.groups.io/g/devel/message/57198
Mute This Topic: https://groups.io/mt/72916365/1779286
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [zhiguang.liu@intel.com] -=-=-=-=-=-=


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [edk2-devel] [PATCH v1 7/9] MdePkg/BaseCpuLib: RISC-V Base CPU library implementation.
  2020-04-10  7:21 ` [PATCH v1 7/9] MdePkg/BaseCpuLib: RISC-V Base CPU library implementation Abner Chang
@ 2020-04-21  6:36   ` Zhiguang Liu
  0 siblings, 0 replies; 20+ messages in thread
From: Zhiguang Liu @ 2020-04-21  6:36 UTC (permalink / raw)
  To: devel@edk2.groups.io, abner.chang@hpe.com
  Cc: Gilbert Chen, Leif Lindholm, Kinney, Michael D, Gao, Liming

Reviewed-by: Zhiguang Liu <zhiguang.liu@intel.com>

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Abner Chang
Sent: Friday, April 10, 2020 3:21 PM
To: devel@edk2.groups.io
Cc: abner.chang@hpe.com; Gilbert Chen <gilbert.chen@hpe.com>; Leif Lindholm <leif.lindholm@linaro.org>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [edk2-devel] [PATCH v1 7/9] MdePkg/BaseCpuLib: RISC-V Base CPU library implementation.

Implement RISC-V CPU related functions in BaseCpuLib.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Co-authored-by: Gilbert Chen <gilbert.chen@hpe.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
---
 MdePkg/Library/BaseCpuLib/BaseCpuLib.inf |  6 +++++-  MdePkg/Library/BaseCpuLib/BaseCpuLib.uni |  5 +++--
 MdePkg/Library/BaseCpuLib/RiscV/Cpu.S    | 19 +++++++++++++++++++
 3 files changed, 27 insertions(+), 3 deletions(-)  create mode 100644 MdePkg/Library/BaseCpuLib/RiscV/Cpu.S

diff --git a/MdePkg/Library/BaseCpuLib/BaseCpuLib.inf b/MdePkg/Library/BaseCpuLib/BaseCpuLib.inf
index a7cb381a85..950f5229b2 100644
--- a/MdePkg/Library/BaseCpuLib/BaseCpuLib.inf
+++ b/MdePkg/Library/BaseCpuLib/BaseCpuLib.inf
@@ -7,6 +7,7 @@
 #  Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR> #  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> #  Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>+#  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR> # #  SPDX-License-Identifier: BSD-2-Clause-Patent #@@ -24,7 +25,7 @@
   #-#  VALID_ARCHITECTURES           = IA32 X64 EBC ARM AARCH64+#  VALID_ARCHITECTURES           = IA32 X64 EBC ARM AARCH64 RISCV64 #  [Sources.IA32]@@ -59,6 +60,9 @@
   AArch64/CpuFlushTlb.asm | MSFT   AArch64/CpuSleep.asm    | MSFT +[Sources.RISCV64]+  RiscV/Cpu.S+ [Packages]   MdePkg/MdePkg.dec diff --git a/MdePkg/Library/BaseCpuLib/BaseCpuLib.uni b/MdePkg/Library/BaseCpuLib/BaseCpuLib.uni
index fc95cda9fc..80dc495786 100644
--- a/MdePkg/Library/BaseCpuLib/BaseCpuLib.uni
+++ b/MdePkg/Library/BaseCpuLib/BaseCpuLib.uni
@@ -1,12 +1,13 @@
 // /** @file // Instance of CPU Library for various architecture. //-// CPU Library implemented using ASM functions for IA-32 and X64,+// CPU Library implemented using ASM functions for IA-32, X64 and RISCV64, // PAL CALLs for IPF, and empty functions for EBC. // // Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR> // Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> // Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>+// Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR> // // SPDX-License-Identifier: BSD-2-Clause-Patent //@@ -15,5 +16,5 @@
  #string STR_MODULE_ABSTRACT             #language en-US "Instance of CPU Library for various architectures" -#string STR_MODULE_DESCRIPTION          #language en-US "CPU Library implemented using ASM functions for IA-32 and X64, PAL CALLs for IPF, and empty functions for EBC."+#string STR_MODULE_DESCRIPTION          #language en-US "CPU Library implemented using ASM functions for IA-32, X64 and RISCV64, PAL CALLs for IPF, and empty functions for EBC." diff --git a/MdePkg/Library/BaseCpuLib/RiscV/Cpu.S b/MdePkg/Library/BaseCpuLib/RiscV/Cpu.S
new file mode 100644
index 0000000000..375b91d314
--- /dev/null
+++ b/MdePkg/Library/BaseCpuLib/RiscV/Cpu.S
@@ -0,0 +1,19 @@
+//------------------------------------------------------------------------------+//+// CpuSleep for RISC-V+//+// Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>+// SPDX-License-Identifier: BSD-2-Clause-Patent+//+//------------------------------------------------------------------------------+.data+.align 3+.section .text++.global ASM_PFX(_CpuSleep)++ASM_PFX(_CpuSleep):+    wfi+    ret++-- 
2.25.0


-=-=-=-=-=-=
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#57200): https://edk2.groups.io/g/devel/message/57200
Mute This Topic: https://groups.io/mt/72916367/1779286
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [zhiguang.liu@intel.com] -=-=-=-=-=-=


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [edk2-devel] [PATCH v1 5/9] MdePkg/BaseIoLibIntrinsic: Rename IoLibArm.c=>IoLibNoIo.c
  2020-04-21  6:36   ` [edk2-devel] " Zhiguang Liu
@ 2020-04-21  8:21     ` Abner Chang
  0 siblings, 0 replies; 20+ messages in thread
From: Abner Chang @ 2020-04-21  8:21 UTC (permalink / raw)
  To: Liu, Zhiguang, devel@edk2.groups.io
  Cc: Chen, Gilbert, Leif Lindholm, Kinney, Michael D, Gao, Liming

Sure, the patch sent.

> -----Original Message-----
> From: Liu, Zhiguang [mailto:zhiguang.liu@intel.com]
> Sent: Tuesday, April 21, 2020 2:36 PM
> To: devel@edk2.groups.io; Chang, Abner (HPS SW/FW Technologist)
> <abner.chang@hpe.com>
> Cc: Chen, Gilbert <gilbert.chen@hpe.com>; Leif Lindholm
> <leif.lindholm@linaro.org>; Kinney, Michael D
> <michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>
> Subject: RE: [edk2-devel] [PATCH v1 5/9] MdePkg/BaseIoLibIntrinsic:
> Rename IoLibArm.c=>IoLibNoIo.c
> 
> Hi Abner,
> 
> In BaseIoLibIntrinsic.inf, you add the line "This I/O library only provides non
> I/O read and write."
> I supposed this is a description for ARM and RISC-V but not for other arch. If
> so, please specify it because this is an inf files all arch are using.
> 
> Thanks
> Zhiguang
> 
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Abner
> Chang
> Sent: Friday, April 10, 2020 3:21 PM
> To: devel@edk2.groups.io
> Cc: abner.chang@hpe.com; Gilbert Chen <gilbert.chen@hpe.com>; Leif
> Lindholm <leif.lindholm@linaro.org>; Kinney, Michael D
> <michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>
> Subject: [edk2-devel] [PATCH v1 5/9] MdePkg/BaseIoLibIntrinsic: Rename
> IoLibArm.c=>IoLibNoIo.c
> 
> RISC-V MMIO library instance.
> IoLibArm.c in fact implements a generic Mmio-only (and ANSI C compliant),
> so rename it to better reflect this.
> 
> Signed-off-by: Abner Chang <abner.chang@hpe.com>
> Co-authored-by: Gilbert Chen <gilbert.chen@hpe.com>
> Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
> 
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Cc: Leif Lindholm <leif.lindholm@linaro.org>
> Cc: Gilbert Chen <gilbert.chen@hpe.com>
> ---
>  .../BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf        | 12 ++++++++----
>  .../BaseIoLibIntrinsic/{IoLibArm.c => IoLibNoIo.c}   |  4 +++-
>  2 files changed, 11 insertions(+), 5 deletions(-)  rename
> MdePkg/Library/BaseIoLibIntrinsic/{IoLibArm.c => IoLibNoIo.c} (94%)
> 
> diff --git a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
> b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
> index 457cce9378..cc23b6b227 100644
> --- a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
> +++ b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
> @@ -4,11 +4,12 @@
>  #  I/O Library that uses compiler intrinsics to perform IN and OUT instructions
> 
>  #  for IA-32 and x64.  On IPF, I/O port requests are translated into MMIO
> requests.
> 
>  #  MMIO requests are forwarded directly to memory.  For EBC, I/O port
> requests
> 
> -#  ASSERT().
> 
> +#  ASSERT(). This I/O library only provides non I/O read and write.
> 
>  #
> 
>  #  Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
> 
>  #  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
> 
>  #  Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
> 
> +#  Portions Copyright (c) 2020, Hewlett Packard Enterprise Development
> +LP. All rights reserved.<BR>
> 
>  #
> 
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  #
> 
> @@ -25,7 +26,7 @@
> 
> 
> 
> 
>  #
> 
> -#  VALID_ARCHITECTURES           = IA32 X64 EBC ARM AARCH64
> 
> +#  VALID_ARCHITECTURES           = IA32 X64 EBC ARM AARCH64 RISCV64
> 
>  #
> 
> 
> 
>  [Sources]
> 
> @@ -50,10 +51,13 @@
>    IoLib.c
> 
> 
> 
>  [Sources.ARM]
> 
> -  IoLibArm.c
> 
> +  IoLibNoIo.c
> 
> 
> 
>  [Sources.AARCH64]
> 
> -  IoLibArm.c
> 
> +  IoLibNoIo.c
> 
> +
> 
> +[Sources.RISCV64]
> 
> +  IoLibNoIo.c
> 
> 
> 
>  [Packages]
> 
>    MdePkg/MdePkg.dec
> 
> diff --git a/MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c
> b/MdePkg/Library/BaseIoLibIntrinsic/IoLibNoIo.c
> similarity index 94%
> rename from MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c
> rename to MdePkg/Library/BaseIoLibIntrinsic/IoLibNoIo.c
> index c6b822461d..a107136a74 100644
> --- a/MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c
> +++ b/MdePkg/Library/BaseIoLibIntrinsic/IoLibNoIo.c
> @@ -1,9 +1,11 @@
>  /** @file
> 
> -  I/O Library for ARM.
> 
> +  I/O library for non I/O read and write access (memory map I/O read
> + and
> 
> +  write only) architecture, such as ARM and RISC-V processor.
> 
> 
> 
>    Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
> 
>    Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
> 
>    Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
> 
> +  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All
> + rights reserved.<BR>
> 
> 
> 
>    SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> 
> 
> --
> 2.25.0
> 
> 
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> 
> View/Reply Online (#57196):
> INVALID URI REMOVED
> 3A__edk2.groups.io_g_devel_message_57196&d=DwIFAg&c=C5b8zRQO1mi
> GmBeVZ2LFWg&r=_SN6FZBN4Vgi4Ulkskz6qU3NYRO03nHp9P7Z5q59A3E&m=
> rVdRjG1eBpmch18toKBbAIlRU4fAwHIsbtEYLYFhwUE&s=pXz-
> X2DE2r73AHeQBAwm_1RBEn4M1sUO2xEdist-lPc&e=
> Mute This Topic: INVALID URI REMOVED
> 3A__groups.io_mt_72916363_1779286&d=DwIFAg&c=C5b8zRQO1miGmBeV
> Z2LFWg&r=_SN6FZBN4Vgi4Ulkskz6qU3NYRO03nHp9P7Z5q59A3E&m=rVdRjG
> 1eBpmch18toKBbAIlRU4fAwHIsbtEYLYFhwUE&s=FkqJ3_oaBXUSqJnn0oSAlYn
> JyzfWrjAtjcTikwfmdF8&e=
> Group Owner: devel+owner@edk2.groups.io
> Unsubscribe: INVALID URI REMOVED
> 3A__edk2.groups.io_g_devel_unsub&d=DwIFAg&c=C5b8zRQO1miGmBeVZ2
> LFWg&r=_SN6FZBN4Vgi4Ulkskz6qU3NYRO03nHp9P7Z5q59A3E&m=rVdRjG1e
> Bpmch18toKBbAIlRU4fAwHIsbtEYLYFhwUE&s=edTt4syYvJQgTughhd_lU6FCY
> a1INKJvH-5llF4LAg0&e=   [zhiguang.liu@intel.com]
> -=-=-=-=-=-=


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2020-04-21  8:22 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-10  7:21 [PATCH v1 0/9] MdePkg changes for RISC-V edk2 port Abner Chang
2020-04-10  7:21 ` [PATCH v1 1/9] MdePkg: RISC-V RV64 binding in MdePkg Abner Chang
2020-04-21  6:30   ` [edk2-devel] " Zhiguang Liu
2020-04-10  7:21 ` [PATCH v1 2/9] MdePkg/Include: RISC-V definitions Abner Chang
2020-04-21  6:32   ` [edk2-devel] " Zhiguang Liu
2020-04-10  7:21 ` [PATCH v1 3/9] MdePkg/BaseLib: BaseLib for RISC-V RV64 Processor Abner Chang
2020-04-21  6:32   ` [edk2-devel] " Zhiguang Liu
2020-04-10  7:21 ` [PATCH v1 4/9] MdePkg/BaseCacheMaintenanceLib: RISC-V cache maintenance implementation Abner Chang
2020-04-21  6:32   ` [edk2-devel] " Zhiguang Liu
2020-04-10  7:21 ` [PATCH v1 5/9] MdePkg/BaseIoLibIntrinsic: Rename IoLibArm.c=>IoLibNoIo.c Abner Chang
2020-04-21  6:36   ` [edk2-devel] " Zhiguang Liu
2020-04-21  8:21     ` Abner Chang
2020-04-10  7:21 ` [PATCH v1 6/9] MdePkg/BasePeCoff: Add RISC-V PE/Coff related code Abner Chang
2020-04-21  6:36   ` [edk2-devel] " Zhiguang Liu
2020-04-10  7:21 ` [PATCH v1 7/9] MdePkg/BaseCpuLib: RISC-V Base CPU library implementation Abner Chang
2020-04-21  6:36   ` [edk2-devel] " Zhiguang Liu
2020-04-10  7:21 ` [PATCH v1 8/9] MdePkg/BaseSynchronizationLib: RISC-V cache related code Abner Chang
2020-04-21  6:36   ` [edk2-devel] " Zhiguang Liu
2020-04-10  7:21 ` [PATCH v1 9/9] MdePkg/BaseSafeIntLib: Add RISCV64 arch for BaseSafeIntLib Abner Chang
2020-04-21  6:36   ` [edk2-devel] " Zhiguang Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox