From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by mx.groups.io with SMTP id smtpd.web12.1599.1635796725670660431 for ; Mon, 01 Nov 2021 12:58:45 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@corthon-com.20210112.gappssmtp.com header.s=20210112 header.b=pof+cZuD; spf=none, err=permanent DNS error (domain: corthon.com, ip: 209.85.210.172, mailfrom: bret@corthon.com) Received: by mail-pf1-f172.google.com with SMTP id u33so5360645pfg.8 for ; Mon, 01 Nov 2021 12:58:45 -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=RoF8Sr2KIIykdaCf8n9uuo0hO9y7uGesdJhx4PdIhfw=; b=pof+cZuDARSfsQduVn/YOh9tsc8QSQMwJu38SdaR1Ho6bWEOux/dJCB/oJcfmu46wK t1Eo/9mKPg1FEPIAUCmRQ+VRRdfbRutYNi1oWEJVeEI/lhx7ly1zsPtzsQC+KEQYS+4q H52YIKRNCgKKhgrtdrBMBeEFqhZ2qvdasQhP3ALaj/Dm9/lIOLAoR1Mwaqce8QodgwwQ MyjkrQcYZMx8/4Bi+w3h62NzufgFkGA8cOqz9E1GODLmopCTfJQYvbwozunLbTvNJsUl 0fwLY3vq9lnlp38QIlAlziCGNPGpRGYcW8OuvD9fFxu0vf9P3NgdAtnsI9g6aIaokZsO ObhA== 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=RoF8Sr2KIIykdaCf8n9uuo0hO9y7uGesdJhx4PdIhfw=; b=r0DnLbBXSSf8BMpZZOyLx+5OecYMqm4qxth7SjwGxdF0zj1/ikzmzg38kzZ1mo2cc/ OGmpGpTCJAaVLKsCMlrOAKj/h3YUul8W8WUTNRY2bbtuW69dl6OqXy/R2r1yCx2rIOP1 WUgQrVghuNXY/aqTC6Q20P++/9lKgawL36GPtzQLo/lBTJn1NNlKWLVrJYzHgMmwUj43 huWnI8wUNenl60UPwzkFfsfuFHzu4dYpLMtBEPEqofnl543v5aMmQ+MtX4Q6NPS4ucVQ 2K3O0AJtQoyJ8GHFIAAcs+d1TeCZoigJYzoduS03t2tqBEv0DD5p6x5R9ftFUgs7kz/i xDTg== X-Gm-Message-State: AOAM530HRBl/xQkeEXWVJ5CKWW/xbgCP7lZ+aAAXGoa74bDO8htK2HF+ Wu8BSUeaK50dOv3pdzNK/2Qc04lM706Udzp3 X-Google-Smtp-Source: ABdhPJxF1/KDD3qLjAeLQyKQHMAxKK3+35vyXB3kC3e4o09WGMEsZHsKcKtNrCK45/zxUVodLdFYOg== X-Received: by 2002:a63:788d:: with SMTP id t135mr23436334pgc.2.1635796724962; Mon, 01 Nov 2021 12:58:44 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 12:58:44 -0700 (PDT) From: "Bret Barkelew" X-Google-Original-From: "brbarkel@microsoft.com" To: devel@edk2.groups.io Cc: Leif Lindholm , Ard Biesheuvel , Sean Brogan Subject: [PATCH v1 11/16] ArmPkg: Add Basic MMU Lib for Arm silicon Date: Mon, 1 Nov 2021 12:56:43 -0700 Message-Id: <20211101195648.6420-12-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: Sean Brogan REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3651 Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Sean Brogan Signed-off-by: Bret Barkelew --- ArmPkg/Library/MmuLib/MmuLib.c | 120 ++++++++++++++++++++ ArmPkg/ArmPkg.dsc | 1 + ArmPkg/Library/MmuLib/BaseMmuLib.inf | 30 +++++ 3 files changed, 151 insertions(+) diff --git a/ArmPkg/Library/MmuLib/MmuLib.c b/ArmPkg/Library/MmuLib/MmuLib.c new file mode 100644 index 000000000000..7a6ba1f81819 --- /dev/null +++ b/ArmPkg/Library/MmuLib/MmuLib.c @@ -0,0 +1,120 @@ +/** @file=0D +This library instance implements a very limited MMU Lib instance=0D +for the ARM/AARCH64 architectures. This library shims a common library=0D +interface to the ArmPkg defined ArmMmuLib.ib.=0D +=0D +Copyright (c) Microsoft Corporation.=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =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 + EFI_STATUS Status;=0D +=0D + Status =3D EFI_UNSUPPORTED;=0D +=0D + if (Attributes & EFI_MEMORY_XP) {=0D + Status =3D ArmSetMemoryRegionNoExec (BaseAddress, Length);=0D + if (EFI_ERROR(Status)) {=0D + DEBUG((DEBUG_ERROR, "%a - Failed to set NX. Status =3D %r\n", __F= UNCTION__, Status));=0D + }=0D + }=0D +=0D + ASSERT_EFI_ERROR(Status);=0D + return Status;=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 + EFI_STATUS Status;=0D +=0D + Status =3D EFI_UNSUPPORTED;=0D +=0D + if (Attributes & EFI_MEMORY_XP) {=0D + Status =3D ArmClearMemoryRegionNoExec (BaseAddress, Length);=0D + if (EFI_ERROR(Status)) {=0D + DEBUG((DEBUG_ERROR, "%a - Failed to clear NX. Status =3D %r\n", _= _FUNCTION__, Status));=0D + }=0D + }=0D +=0D + if (Attributes & EFI_MEMORY_RO) {=0D + Status =3D ArmClearMemoryRegionReadOnly(BaseAddress, Length);=0D + if (EFI_ERROR(Status)) {=0D + DEBUG((DEBUG_ERROR, "%a - Failed to clear RO. Status =3D %r\n", _= _FUNCTION__, Status));=0D + }=0D + }=0D +=0D + ASSERT_EFI_ERROR(Status);=0D + return Status;=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 + EFI_STATUS Status;=0D +=0D + Status =3D EFI_UNSUPPORTED;=0D +=0D + DEBUG ((DEBUG_ERROR, "%a() API not implemented\n", __FUNCTION__));=0D +=0D + ASSERT_EFI_ERROR(Status);=0D + return Status;=0D + }=0D diff --git a/ArmPkg/ArmPkg.dsc b/ArmPkg/ArmPkg.dsc index 06ede068f99d..cbc67daa7696 100644 --- a/ArmPkg/ArmPkg.dsc +++ b/ArmPkg/ArmPkg.dsc @@ -165,3 +165,4 @@ [Components.AARCH64] =0D [Components.AARCH64, Components.ARM]=0D ArmPkg/Library/StandaloneMmMmuLib/ArmMmuStandaloneMmLib.inf=0D + ArmPkg/Library/MmuLib/BaseMmuLib.inf=0D diff --git a/ArmPkg/Library/MmuLib/BaseMmuLib.inf b/ArmPkg/Library/MmuLib/B= aseMmuLib.inf new file mode 100644 index 000000000000..15095abee9c3 --- /dev/null +++ b/ArmPkg/Library/MmuLib/BaseMmuLib.inf @@ -0,0 +1,30 @@ +## @file=0D +# This library instance implements a very limited MMU Lib instance=0D +# for the ARM/AARCH64 architectures. This library shims a common library= =0D +# interface to the ArmPkg defined ArmMmuLib.=0D +#=0D +# Copyright (c) Microsoft Corporation.=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D MmuLib=0D + FILE_GUID =3D 6f2ee9a4-79b3-4b77-9a47-e2bd4b917b75= =0D + MODULE_TYPE =3D BASE=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D MmuLib=0D +=0D +[Sources]=0D + MmuLib.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D + ArmPkg/ArmPkg.dec=0D +=0D +[LibraryClasses]=0D + DebugLib=0D + ArmMmuLib=0D --=20 2.31.1.windows.1