From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by mx.groups.io with SMTP id smtpd.web09.3958.1636590330511516611 for ; Wed, 10 Nov 2021 16:25:30 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@corthon-com.20210112.gappssmtp.com header.s=20210112 header.b=uwpls9of; spf=none, err=permanent DNS error (domain: corthon.com, ip: 209.85.214.175, mailfrom: bret@corthon.com) Received: by mail-pl1-f175.google.com with SMTP id u17so4342919plg.9 for ; Wed, 10 Nov 2021 16:25:30 -0800 (PST) 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=HJQDdL3mAQnNHkNTj7xqG9uD17w9gInHuyDs4JSxPJw=; b=uwpls9ofAjsUDe6JcVibHQvxE4yjudx9CoP+gTmlzjHjm/dTss8KOsVXh3F7izwSv/ msloFujHx1MXIoabrQthLpQ0QKt5s1fvVs9KuCNQ0F8tpipbbenBkmnhahEV9PSb3lMr fXYohSa+EfSfvBARwl1J7u/Q0fTb4AdbXI8Xxh/Ux3/iqHUqHUFcH4uSmuSg1LGz0PIU Zv2vbb6dZVzb1KqH9E121jgIBRTOzNh4HTiO4i3X63UbVMGV5d0lq1Yizog7g8HyWAWg BUCmI9wwZpHDfXJtD8X0StYtBg8rZ1sbcxicN/YfnyKcak9BsSctfOQAtBzQlyWPxq+r lezw== 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=HJQDdL3mAQnNHkNTj7xqG9uD17w9gInHuyDs4JSxPJw=; b=5jNCZpesXV/J8S6hbCcQCC5M70cR4tUT61wW+b0RyJ/WWetFAm0OIIVOLjp2BKlSQm ws38caZI6xmhlJGnGqGdtJNjqma8gEp2Kp2KLX6fosF1H9VUIyZ7f2HoQR1R/OkDIai2 KLZtSvu9M7/iqftlxN53swVUPud1B0Qc4+DjPzPJKWIxhkwg1xyO6xJa90mRQqOkmagm NRZCrCF37GYOfIoJdmR99HzbSLh3Cacy9JynfjdsgWcGOUqmJdfsWptqmg8N1hPV82Q2 4ZNxiROykjE8KjYXGZJdyz9lt1G5iJqGDxDF/dXbIctFJrP99Hb4Usq8uU1P5TkIDQtM OLZA== X-Gm-Message-State: AOAM5309Bb57sptZoN0Fuj1psi6wplNDJaixDAnYRMDrhcKR1ralwYA5 bfE6/w7HAKji9WD1HzuDBlLYB4HnJ6aZfjsZ X-Google-Smtp-Source: ABdhPJzqzuXm3tNBGBhIAdYf0Jb8hl+haW86QpnnjEygwZDE/QjvaGh267DYfYdgNGZplgXlzWB3fQ== X-Received: by 2002:a17:90a:f002:: with SMTP id bt2mr3424010pjb.221.1636590329822; Wed, 10 Nov 2021 16:25:29 -0800 (PST) Return-Path: Received: from localhost.localdomain (174-21-94-94.tukw.qwest.net. [174.21.94.94]) by smtp.gmail.com with ESMTPSA id e14sm838890pfv.18.2021.11.10.16.25.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Nov 2021 16:25:29 -0800 (PST) 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 v3 08/14] MdePkg: Create the MMU access lib to abstract memory protection settings Date: Wed, 10 Nov 2021 16:24:10 -0800 Message-Id: <20211111002416.1770-9-brbarkel@microsoft.com> X-Mailer: git-send-email 2.31.1.windows.1 In-Reply-To: <20211111002416.1770-1-brbarkel@microsoft.com> References: <20211111002416.1770-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..34b363bf712f --- /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=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 a04f0aec8c20..c0f9bac787f2 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