From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by mx.groups.io with SMTP id smtpd.web12.843.1635884332573810374 for ; Tue, 02 Nov 2021 13:18:52 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@corthon-com.20210112.gappssmtp.com header.s=20210112 header.b=dzeqOhku; spf=none, err=permanent DNS error (domain: corthon.com, ip: 209.85.214.171, mailfrom: bret@corthon.com) Received: by mail-pl1-f171.google.com with SMTP id s24so708031plp.0 for ; Tue, 02 Nov 2021 13:18:52 -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=dzeqOhku5CdQA/thqp7urFjVPPcAP16T/nU7Pt6zPqMc5L2L0AF/x2mwjuGMFGNwVj rQ2vaS9jo5zcoyORhI7Nz4W5G3piqDz3xsTfZlJ28gK/2eU4nA+pou6n+Osbo459q3ZP EDW6qyjT480FfmodMp1ewyeoudOoGEV/aPrc3rYnsxUxEQZGXtOafxhGq7CgJ5sWJblp OpazWRLlzZbP6FMTVBvfrXKq6+XmBzoN2PpJAEVz6ENEE4Vj3H+byRodLYhHf87RF5M0 TDUV8tf2FEkGKGvKGUPn65sBpkGe3j2Lq3ABwTVewT3d6yy6mjNa+YZItWDmixFNk0sP dFiA== 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=qrXOcdSzS64yDXqTqWqSfXl+35vZ3QgUNjjEj5gwMRgZrjpdKwD8DrNrLdvV5SfAs2 x5M3BDLviOIdondlZ7EkzeNbNXp3AfwYyLsvPHSf3GQNI8G8KfuO+SfKPJG+qQBO1oK/ cM4rocyaBj8rQEnWU3mw0+l2fY9hl6w7qkYj1ezDO3fdw9cNUkhWrOkjLqUMX+vUW6Qr 8epnWNIIyxRZ137fST/9q/FOmxIk2MGgTc7yrkEn7yln0xIpac2lNlA/1cIpvmCWgPuS tljyz2b4MDgl5+pgTrcgZ/w7AUEtKgNRTnxdGZ92HBOh60fsoNaQ1awAYM1Hlzq2febr wfpw== X-Gm-Message-State: AOAM532poiHPvirlenVmywsjmAq38G4oDXsFPJu8a3oxqXqpL5s2PRXb LiwDS6tTb4SlOJEIfHKnH5VlQZPfyYif3Txa X-Google-Smtp-Source: ABdhPJyy1UUaKVXeQT7vH1ZYSQrGzr5FFZv2iEBdIsskb+ACqvfpSY0bEw0wvbBUV0YpZ8UeqRkX5Q== X-Received: by 2002:a17:903:120c:b0:13f:d043:3477 with SMTP id l12-20020a170903120c00b0013fd0433477mr33575021plh.89.1635884331908; Tue, 02 Nov 2021 13:18:51 -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 t24sm17652pfg.118.2021.11.02.13.18.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Nov 2021 13:18:51 -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 v2 08/16] MdePkg: Create the MMU access lib to abstract memory protection settings Date: Tue, 2 Nov 2021 13:17:40 -0700 Message-Id: <20211102201748.1963-9-brbarkel@microsoft.com> X-Mailer: git-send-email 2.31.1.windows.1 In-Reply-To: <20211102201748.1963-1-brbarkel@microsoft.com> References: <20211102201748.1963-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