From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by mx.groups.io with SMTP id smtpd.web12.1596.1635796721822573420 for ; Mon, 01 Nov 2021 12:58:41 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@corthon-com.20210112.gappssmtp.com header.s=20210112 header.b=58SR8Bx0; spf=none, err=permanent DNS error (domain: corthon.com, ip: 209.85.214.172, mailfrom: bret@corthon.com) Received: by mail-pl1-f172.google.com with SMTP id s24so12417211plp.0 for ; Mon, 01 Nov 2021 12:58:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corthon-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aQlK0+Ol3NNwQA9dFWPAvnjOuZOF9dLhentJDG3b7j0=; b=58SR8Bx0BAlXJropZxDz8adSXf1JFZOPM8I7r8UoE3QUAAQfoqbfrfqTTEUzKllIVQ knokQRTCg/Fy5SfZtnCokhqWe2GyAnqFRJ/6e+P7aPakwB6+10UzBGLhkZhtbn7RXPvo 98hpx+VYQXeQxODEagNbfEmz/YKy27lOY3ZZ8Sm68cEzt/wFG7ZbwB1hdZc1wzxPdFls u8dh6oiBSVFnMW+pi5VdA9IXakAlIRUmPkiV95EbunrbitvcE9wTlD4TvDRepEDSHXGL 6T10OnXNbUznmROqjC2LsVZTnlZadDwfaE8+qqcvQ2t/vTsUTvZ00sJ9KCe1bJCKp5lZ qutw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aQlK0+Ol3NNwQA9dFWPAvnjOuZOF9dLhentJDG3b7j0=; b=tFGBYTMzQ84iSmVmzyqSx8V1aaIN91UUQIZDi/r6389tJmTL9MlMQTnXDHZKMCuu8l 0/ebLrc6W9UMxz//+DquNGKa/jqRdeLJDno44RzrrW8KeAv3jw5TBBM3dfS5TQdaw2IN /BkAVv0AcLgsCsbkii1qhZDcgiwbmPtrtIKM/ZvHB5nusXuzkPdAi0AsY0zm68aeiHD6 PyTgzklCZhEN1TbrV2KIZ9Yxt9ibg8tSD8qgUY4BDpiuTbbemdR3+hYQrcMAj+6qKFl6 ScjeEFAcWd2ax4GSEcaGw+BfMDIUtW10yF0KSIAuv1/G2Cv96UfoB3ckIn83w5razBqH BZXA== X-Gm-Message-State: AOAM533KkuyVEHzbrPAh0zKGexY3LyZqm7dplxzIGTmpiwL1EZCkqvdr He4ZsitDPowODYPeHVhtZGyJ7oL9NK2VQ7kw X-Google-Smtp-Source: ABdhPJzedCaMFAlcfYuYJjDh8MbY/vTL+gXI0afpZikhW/fqO3X4qAWmNjlNotuHYLi2HxcJDu7AGQ== X-Received: by 2002:a17:90a:9906:: with SMTP id b6mr1167574pjp.180.1635796721191; Mon, 01 Nov 2021 12:58:41 -0700 (PDT) Return-Path: Received: from localhost.localdomain (174-21-94-94.tukw.qwest.net. [174.21.94.94]) by smtp.gmail.com with ESMTPSA id t2sm13759796pgf.35.2021.11.01.12.58.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 12:58:40 -0700 (PDT) From: "Bret Barkelew" X-Google-Original-From: "brbarkel@microsoft.com" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Sean Brogan Subject: [PATCH v1 08/16] MdePkg: Create the MMU access lib to abstract memory protection settings Date: Mon, 1 Nov 2021 12:56:40 -0700 Message-Id: <20211101195648.6420-9-brbarkel@microsoft.com> X-Mailer: git-send-email 2.31.1.windows.1 In-Reply-To: <20211101195648.6420-1-brbarkel@microsoft.com> References: <20211101195648.6420-1-brbarkel@microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Bret Barkelew There are a number of Arm-specific accesses that are abstracted behind this. It may need to be refactored to work better across architectures. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3651 Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Sean Brogan Signed-off-by: Bret Barkelew --- MdePkg/Library/BaseMmuLibNull/BaseMmuLibNull.c | 86 ++++++++++++++++++++ MdePkg/Include/Library/MmuLib.h | 75 +++++++++++++++++ MdePkg/Library/BaseMmuLibNull/BaseMmuLibNull.inf | 28 +++++++ MdePkg/MdePkg.dec | 5 ++ MdePkg/MdePkg.dsc | 2 + 5 files changed, 196 insertions(+) diff --git a/MdePkg/Library/BaseMmuLibNull/BaseMmuLibNull.c b/MdePkg/Librar= y/BaseMmuLibNull/BaseMmuLibNull.c new file mode 100644 index 000000000000..0398bc03f8f7 --- /dev/null +++ b/MdePkg/Library/BaseMmuLibNull/BaseMmuLibNull.c @@ -0,0 +1,86 @@ +/** @file=0D +This lib abstracts some of the MMU accesses currently hardcoded against=0D +an Arm lib. It's likely that this will need to be refactored at some point= .=0D +=0D +Copyright (c) Microsoft Corporation.=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +#include =0D +=0D +/**=0D + Bitwise sets the memory attributes on a range of memory based on an attr= ibutes mask.=0D +=0D + @param BaseAddress The start of the range for which to set at= tributes.=0D + @param Length The length of the range.=0D + @param Attributes A bitmask of the attributes to set. See "P= hysical memory=0D + protection attributes" in UefiSpec.h=0D +=0D + @return EFI_SUCCESS=0D + @return Others=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +MmuSetAttributes (=0D + IN EFI_PHYSICAL_ADDRESS BaseAddress,=0D + IN UINT64 Length,=0D + IN UINT64 Attributes=0D + )=0D +{=0D + DEBUG ((DEBUG_ERROR, "%a() NULL implementation used!\n", __FUNCTION__));= =0D + ASSERT (FALSE);=0D + return EFI_UNSUPPORTED;=0D +}=0D +=0D +=0D +/**=0D + Bitwise clears the memory attributes on a range of memory based on an at= tributes mask.=0D +=0D + @param BaseAddress The start of the range for which to clear = attributes.=0D + @param Length The length of the range.=0D + @param Attributes A bitmask of the attributes to clear. See = "Physical memory=0D + protection attributes" in UefiSpec.h=0D +=0D + @return EFI_SUCCESS=0D + @return Others=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +MmuClearAttributes (=0D + IN EFI_PHYSICAL_ADDRESS BaseAddress,=0D + IN UINT64 Length,=0D + IN UINT64 Attributes=0D + )=0D +{=0D + DEBUG ((DEBUG_ERROR, "%a() NULL implementation used!\n", __FUNCTION__));= =0D + ASSERT (FALSE);=0D + return EFI_UNSUPPORTED;=0D +}=0D +=0D +=0D +/**=0D + Returns the memory attributes on a range of memory.=0D +=0D + @param BaseAddress The start of the range for which to set at= tributes.=0D + @param Attributes A return pointer for the attributes.=0D +=0D + @return EFI_SUCCESS=0D + @return EFI_INVALID_PARAMETER A return pointer is NULL.=0D + @return Others=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +MmuGetAttributes (=0D + IN EFI_PHYSICAL_ADDRESS BaseAddress,=0D + OUT UINT64 *Attributes=0D + )=0D +{=0D + DEBUG ((DEBUG_ERROR, "%a() NULL implementation used!\n", __FUNCTION__));= =0D + ASSERT (FALSE);=0D + return EFI_UNSUPPORTED;=0D +}=0D diff --git a/MdePkg/Include/Library/MmuLib.h b/MdePkg/Include/Library/MmuLi= b.h new file mode 100644 index 000000000000..170670f7d52a --- /dev/null +++ b/MdePkg/Include/Library/MmuLib.h @@ -0,0 +1,75 @@ +/** @file=0D +This lib abstracts some of the MMU accesses currently hardcoded against=0D +an Arm lib. It's likely that this will need to be refactored at some point= .=0D +=0D +Copyright (c) Microsoft Corporation.=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef _MMU_LIB_H_=0D +#define _MMU_LIB_H_=0D +=0D +#include =0D +=0D +/**=0D + Bitwise sets the memory attributes on a range of memory based on an attr= ibutes mask.=0D +=0D + @param BaseAddress The start of the range for which to set at= tributes.=0D + @param Length The length of the range.=0D + @param Attributes A bitmask of the attributes to set. See "P= hysical memory=0D + protection attributes" in UefiSpec.h=0D +=0D + @return EFI_SUCCESS=0D + @return Others=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +MmuSetAttributes (=0D + IN EFI_PHYSICAL_ADDRESS BaseAddress,=0D + IN UINT64 Length,=0D + IN UINT64 Attributes=0D + );=0D +=0D +=0D +/**=0D + Bitwise clears the memory attributes on a range of memory based on an at= tributes mask.=0D +=0D + @param BaseAddress The start of the range for which to clear = attributes.=0D + @param Length The length of the range.=0D + @param Attributes A bitmask of the attributes to clear. See = "Physical memory=0D + protection attributes" in UefiSpec.h=0D +=0D + @return EFI_SUCCESS=0D + @return Others=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +MmuClearAttributes (=0D + IN EFI_PHYSICAL_ADDRESS BaseAddress,=0D + IN UINT64 Length,=0D + IN UINT64 Attributes=0D + );=0D +=0D +=0D +/**=0D + Returns the memory attributes on a range of memory.=0D +=0D + @param BaseAddress The start of the range for which to set at= tributes.=0D + @param Attributes A return pointer for the attributes.=0D +=0D + @return EFI_SUCCESS=0D + @return EFI_INVALID_PARAMETER A return pointer is NULL.=0D + @return Others=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +MmuGetAttributes (=0D + IN EFI_PHYSICAL_ADDRESS BaseAddress,=0D + OUT UINT64 *Attributes=0D + );=0D +=0D +#endif // _MMU_LIB_H_=0D diff --git a/MdePkg/Library/BaseMmuLibNull/BaseMmuLibNull.inf b/MdePkg/Libr= ary/BaseMmuLibNull/BaseMmuLibNull.inf new file mode 100644 index 000000000000..9f1b4422cc04 --- /dev/null +++ b/MdePkg/Library/BaseMmuLibNull/BaseMmuLibNull.inf @@ -0,0 +1,28 @@ +## @file=0D +# This lib abstracts some of the MMU accesses currently hardcoded against= =0D +# an Arm lib. It's likely that this will need to be refactored at some poi= nt.=0D +#=0D +# Copyright (c) Microsoft Corporation.=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +##=0D +=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010017=0D + BASE_NAME =3D BaseMmuLibNull=0D + FILE_GUID =3D 97196A48-00C0-4487-802A-CC5540583EEB=0D + VERSION_STRING =3D 1.0=0D + MODULE_TYPE =3D BASE=0D + LIBRARY_CLASS =3D MmuLib=0D +=0D +=0D +[Sources]=0D + BaseMmuLibNull.c=0D +=0D +=0D +[LibraryClasses]=0D + DebugLib=0D +=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 8b18415b107a..43ad9726bf7f 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -267,6 +267,11 @@ [LibraryClasses] #=0D RegisterFilterLib|Include/Library/RegisterFilterLib.h=0D =0D + ## @libraryclass This lib abstracts some of the MMU accesses currently = hardcoded against=0D + # an Arm lib. It's likely that this will need to be refa= ctored at some point.=0D + #=0D + MmuLib|Include/Library/MmuLib.h=0D +=0D [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]=0D ## @libraryclass Provides services to generate random number.=0D #=0D diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index cb3907c88b4e..a9c67b72e4e0 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -131,6 +131,8 @@ [Components] =0D MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNull.inf=0D =0D + MdePkg/Library/BaseMmuLibNull/BaseMmuLibNull.inf=0D +=0D [Components.IA32, Components.X64, Components.ARM, Components.AARCH64]=0D #=0D # Add UEFI Target Based Unit Tests=0D --=20 2.31.1.windows.1