Hi Anderi, There are indeed typos and I will fix them in V4. Thank you! Thanks, Chao On 2023/11/18 04:18, Andrei Warkentin wrote: > +Tuan as a heads-up. > > This seems reasonable to me. What does the "Uint" mean in ConfigureMemoryManagementUint? > > Did you intend to say "Unit"? > > Reviewed-by: Andrei Warkentin > >> -----Original Message----- >> From: Chao Li >> Sent: Friday, November 17, 2023 4:00 AM >> To:devel@edk2.groups.io >> Cc: Dong, Eric; Ni, Ray; Kumar, >> Rahul R; Gerd Hoffmann; >> Leif Lindholm; Ard Biesheuvel >> ; Sami Mujawar; >> Sunil V L; Warkentin, Andrei >> >> Subject: [PATCH v3 13/39] UefiCpuPkg: Add CpuMmuLib.h to UefiCpuPkg >> >> Add a new header file CpuMmuLib.h, whitch is referenced from >> ArmPkg/Include/Library/ArmMmuLib.h. Currently, only support for >> LoongArch64 is added, and more architectures can be accommodated in the >> future. >> >> BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=4584 >> >> Cc: Eric Dong >> Cc: Ray Ni >> Cc: Rahul Kumar >> Cc: Gerd Hoffmann >> Cc: Leif Lindholm >> Cc: Ard Biesheuvel >> Cc: Sami Mujawar >> Cc: Sunil V L >> Cc: Andrei Warkentin >> Signed-off-by: Chao Li >> --- >> UefiCpuPkg/Include/Library/CpuMmuLib.h | 155 >> +++++++++++++++++++++++++ >> UefiCpuPkg/UefiCpuPkg.dec | 4 + >> 2 files changed, 159 insertions(+) >> create mode 100644 UefiCpuPkg/Include/Library/CpuMmuLib.h >> >> diff --git a/UefiCpuPkg/Include/Library/CpuMmuLib.h >> b/UefiCpuPkg/Include/Library/CpuMmuLib.h >> new file mode 100644 >> index 0000000000..23b2fe34ac >> --- /dev/null >> +++ b/UefiCpuPkg/Include/Library/CpuMmuLib.h >> @@ -0,0 +1,155 @@ >> +/** @file >> + >> + Copyright (c) 2023 Loongson Technology Corporation Limited. All >> + rights reserved.
>> + >> + SPDX-License-Identifier: BSD-2-Clause-Patent >> + >> +**/ >> + >> +#ifndef CPU_MMU_LIB_H_ >> +#define CPU_MMU_LIB_H_ >> + >> +#include >> + >> +#define EFI_MEMORY_CACHETYPE_MASK (EFI_MEMORY_UC | \ >> + EFI_MEMORY_WC | \ >> + EFI_MEMORY_WT | \ >> + EFI_MEMORY_WB | \ >> + EFI_MEMORY_UCE \ >> + ) >> + >> +typedef struct { >> + EFI_PHYSICAL_ADDRESS PhysicalBase; >> + EFI_VIRTUAL_ADDRESS VirtualBase; >> + UINTN Length; >> + UINTN Attributes; >> +} MEMORY_REGION_DESCRIPTOR; >> + >> +/** >> + Converts EFI Attributes to corresponding architecture Attributes. >> + >> + @param[in] EfiAttributes Efi Attributes. >> + >> + @retval Corresponding architecture attributes. >> +**/ >> +UINTN >> +EfiAttributeConverse ( >> + IN UINTN EfiAttributes >> + ); >> + >> +/** >> + Finds the length and memory properties of the memory region >> corresponding to the specified base address. >> + >> + @param[in] BaseAddress To find the base address of the memory >> region. >> + @param[in] EndAddress To find the end address of the memory region. >> + @param[out] RegionLength The length of the memory region found. >> + @param[out] RegionAttributes Properties of the memory region found. >> + >> + @retval EFI_SUCCESS The corresponding memory area was successfully >> found >> + EFI_NOT_FOUND No memory area found >> +**/ >> +EFI_STATUS >> +GetMemoryRegionAttribute ( >> + IN UINTN BaseAddress, >> + IN UINTN EndAddress, >> + OUT UINTN *RegionLength, >> + OUT UINTN *RegionAttributes >> + ); >> + >> +/** >> + Sets the Attributes of the specified memory region >> + >> + @param[in] BaseAddress The base address of the memory region to set >> the Attributes. >> + @param[in] Length The length of the memory region to set the >> Attributes. >> + @param[in] Attributes The Attributes to be set. >> + @param[in] AttributeMask Mask of memory attributes to take into >> account. >> + >> + @retval EFI_SUCCESS The Attributes was set successfully >> +**/ >> +EFI_STATUS >> +SetMemoryRegionAttributes ( >> + IN EFI_PHYSICAL_ADDRESS BaseAddress, >> + IN UINTN Length, >> + IN UINTN Attributes, >> + IN UINT64 AttributeMask >> + ); >> + >> +/** >> + Sets the non-executable Attributes for the specified memory region >> + >> + @param[in] BaseAddress The base address of the memory region to set >> the Attributes. >> + @param[in] Length The length of the memory region to set the >> Attributes. >> + >> + @retval EFI_SUCCESS The Attributes was set successfully >> +**/ >> +EFI_STATUS >> +SetMemoryRegionNoExec ( >> + IN EFI_PHYSICAL_ADDRESS BaseAddress, >> + IN UINTN Length >> + ); >> + >> +/** >> + Clears the non-executable Attributes for the specified memory region >> + >> + @param[in] BaseAddress The base address of the memory region to clear >> the Attributes. >> + @param[in] Length The length of the memory region to clear the >> Attributes. >> + >> + @retval EFI_SUCCESS The Attributes was clear successfully >> +**/ >> +EFI_STATUS >> +EFIAPI >> +ClearMemoryRegionNoExec ( >> + IN EFI_PHYSICAL_ADDRESS BaseAddress, >> + IN UINT64 Length >> + ); >> + >> +/** >> + Sets the read-only Attributes for the specified memory region >> + >> + @param[in] BaseAddress The base address of the memory region to set >> the Attributes. >> + @param[in] Length The length of the memory region to set the >> Attributes. >> + >> + @retval EFI_SUCCESS The Attributes was set successfully >> +**/ >> +EFI_STATUS >> +EFIAPI >> +SetMemoryRegionReadOnly ( >> + IN EFI_PHYSICAL_ADDRESS BaseAddress, >> + IN UINT64 Length >> + ); >> + >> +/** >> + Clears the read-only Attributes for the specified memory region >> + >> + @param[in] BaseAddress The base address of the memory region to clear >> the Attributes. >> + @param[in] Length The length of the memory region to clear the >> Attributes. >> + >> + @retval EFI_SUCCESS The Attributes was clear successfully >> +**/ >> +EFI_STATUS >> +EFIAPI >> +ClearMemoryRegionReadOnly ( >> + IN EFI_PHYSICAL_ADDRESS BaseAddress, >> + IN UINT64 Length >> + ); >> + >> +/** >> + Create a page table and initialize the memory management unit(MMU). >> + >> + @param[in] MemoryTable A pointer to a memory ragion table. >> + @param[out] TranslationTableBase A pointer to a translation table base >> address. >> + @param[out] TranslationTableSize A pointer to a translation table base >> size. >> + >> + @retval EFI_SUCCESS Configure MMU successfully. >> + EFI_INVALID_PARAMETER MemoryTable is NULL. >> + EFI_UNSUPPORTED Out of memory space or size not aligned. >> +**/ >> +EFI_STATUS >> +EFIAPI >> +ConfigureMemoryManagementUint ( >> + IN MEMORY_REGION_DESCRIPTOR *MemoryTable, >> + OUT VOID **TranslationTableBase OPTIONAL, >> + OUT UINTN *TranslationTableSize OPTIONAL >> + ); >> + >> +#endif // CPU_MMU_LIB_H_ >> diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index >> 154b1d06fe..150beae981 100644 >> --- a/UefiCpuPkg/UefiCpuPkg.dec >> +++ b/UefiCpuPkg/UefiCpuPkg.dec >> @@ -62,6 +62,10 @@ >> ## @libraryclass Provides function for manipulating x86 paging structures. >> CpuPageTableLib|Include/Library/CpuPageTableLib.h >> >> +[LibraryClasses.LoongArch64] >> + ## @libraryclass Provides macros and functions for the memory >> management unit. >> + CpuMmuLib|Include/Library/CpuMmuLib.h >> + >> ## @libraryclass Provides functions for manipulating smram savestate >> registers. >> MmSaveStateLib|Include/Library/MmSaveStateLib.h >> >> -- >> 2.27.0 > > > > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111442): https://edk2.groups.io/g/devel/message/111442 Mute This Topic: https://groups.io/mt/102644768/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-