Skip to content

Commit

Permalink
Create the MMU access lib to abstract memory protection settings
Browse files Browse the repository at this point in the history
There are a number of Arm-specific accesses that are abstracted
behind this. It may need to be refactored to work better across
architectures.
  • Loading branch information
Bret Barkelew authored and kenlautner committed May 4, 2023
1 parent dac80fe commit ec4bdf7
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 2 deletions.
73 changes: 73 additions & 0 deletions MdePkg/Include/Library/MmuLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/** @file
This lib abstracts some of the MMU accesses currently hardcoded against
an Arm lib. It's likely that this will need to be refactored at some point.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef _MMU_LIB_H_
#define _MMU_LIB_H_

#include <Uefi.h>

/**
Bitwise sets the memory attributes on a range of memory based on an attributes mask.
@param BaseAddress The start of the range for which to set attributes.
@param Length The length of the range.
@param Attributes A bitmask of the attributes to set. See "Physical memory
protection attributes" in UefiSpec.h
@return EFI_SUCCESS
@return Others
**/
EFI_STATUS
EFIAPI
MmuSetAttributes (
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length,
IN UINT64 Attributes
);

/**
Bitwise clears the memory attributes on a range of memory based on an attributes mask.
@param BaseAddress The start of the range for which to clear attributes.
@param Length The length of the range.
@param Attributes A bitmask of the attributes to clear. See "Physical memory
protection attributes" in UefiSpec.h
@return EFI_SUCCESS
@return Others
**/
EFI_STATUS
EFIAPI
MmuClearAttributes (
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length,
IN UINT64 Attributes
);

/**
Returns the memory attributes on a range of memory.
@param BaseAddress The start of the range for which to set attributes.
@param Attributes A return pointer for the attributes.
@return EFI_SUCCESS
@return EFI_INVALID_PARAMETER A return pointer is NULL.
@return Others
**/
EFI_STATUS
EFIAPI
MmuGetAttributes (
IN EFI_PHYSICAL_ADDRESS BaseAddress,
OUT UINT64 *Attributes
);

#endif // _MMU_LIB_H_
84 changes: 84 additions & 0 deletions MdePkg/Library/BaseMmuLibNull/BaseMmuLibNull.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/** @file
This lib abstracts some of the MMU accesses currently hardcoded against
an Arm lib. It's likely that this will need to be refactored at some point.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <Uefi.h>
#include <Library/DebugLib.h>

/**
Bitwise sets the memory attributes on a range of memory based on an attributes mask.
@param BaseAddress The start of the range for which to set attributes.
@param Length The length of the range.
@param Attributes A bitmask of the attributes to set. See "Physical memory
protection attributes" in UefiSpec.h
@return EFI_SUCCESS
@return Others
**/
EFI_STATUS
EFIAPI
MmuSetAttributes (
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length,
IN UINT64 Attributes
)
{
DEBUG ((DEBUG_ERROR, "%a() NULL implementation used!\n", __FUNCTION__));
ASSERT (FALSE);
return EFI_UNSUPPORTED;
}

/**
Bitwise clears the memory attributes on a range of memory based on an attributes mask.
@param BaseAddress The start of the range for which to clear attributes.
@param Length The length of the range.
@param Attributes A bitmask of the attributes to clear. See "Physical memory
protection attributes" in UefiSpec.h
@return EFI_SUCCESS
@return Others
**/
EFI_STATUS
EFIAPI
MmuClearAttributes (
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length,
IN UINT64 Attributes
)
{
DEBUG ((DEBUG_ERROR, "%a() NULL implementation used!\n", __FUNCTION__));
ASSERT (FALSE);
return EFI_UNSUPPORTED;
}

/**
Returns the memory attributes on a range of memory.
@param BaseAddress The start of the range for which to set attributes.
@param Attributes A return pointer for the attributes.
@return EFI_SUCCESS
@return EFI_INVALID_PARAMETER A return pointer is NULL.
@return Others
**/
EFI_STATUS
EFIAPI
MmuGetAttributes (
IN EFI_PHYSICAL_ADDRESS BaseAddress,
OUT UINT64 *Attributes
)
{
DEBUG ((DEBUG_ERROR, "%a() NULL implementation used!\n", __FUNCTION__));
ASSERT (FALSE);
return EFI_UNSUPPORTED;
}
29 changes: 29 additions & 0 deletions MdePkg/Library/BaseMmuLibNull/BaseMmuLibNull.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## @file
# This lib abstracts some of the MMU accesses currently hardcoded against
# an Arm lib. It's likely that this will need to be refactored at some point.
#
##
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##


[Defines]
INF_VERSION = 0x00010017
BASE_NAME = BaseMmuLibNull
FILE_GUID = 97196A48-00C0-4487-802A-CC5540583EEB
VERSION_STRING = 1.0
MODULE_TYPE = BASE
LIBRARY_CLASS = MmuLib


[Sources]
BaseMmuLibNull.c


[LibraryClasses]
DebugLib


[Packages]
MdePkg/MdePkg.dec
8 changes: 6 additions & 2 deletions MdePkg/MdePkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,19 @@
#
#
RegisterFilterLib|Include/Library/RegisterFilterLib.h

## @libraryclass This library provides interfances to probe ConfidentialComputing guest type.
#
#
CcProbeLib|Include/Library/CcProbeLib.h

## @libraryclass Provides function for SMM CPU Rendezvous Library.
SmmCpuRendezvousLib|Include/Library/SmmCpuRendezvousLib.h
# MU_CHANGE [BEGIN]
## @libraryclass This lib abstracts some of the MMU accesses currently hardcoded against
# an Arm lib. It's likely that this will need to be refactored at some point.
#
MmuLib|Include/Library/MmuLib.h
# MU_CHANGE [END]

## @libraryclass Provides services to generate Entropy using a TRNG.
#
Expand Down Expand Up @@ -315,7 +320,6 @@

## @libraryclass Provides services to log the SMI handler registration.
SmiHandlerProfileLib|Include/Library/SmiHandlerProfileLib.h

## @libraryclass Provides function to support TDX processing.
TdxLib|Include/Library/TdxLib.h

Expand Down
2 changes: 2 additions & 0 deletions MdePkg/MdePkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@
MdePkg/Library/CcProbeLibNull/CcProbeLibNull.inf
MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf

MdePkg/Library/BaseMmuLibNull/BaseMmuLibNull.inf ## MU_CHANGE

[Components.IA32, Components.X64, Components.ARM, Components.AARCH64]
#
# Add UEFI Target Based Unit Tests
Expand Down

0 comments on commit ec4bdf7

Please sign in to comment.