From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by mx.groups.io with SMTP id smtpd.web08.908.1635884458454902462 for ; Tue, 02 Nov 2021 13:20:58 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@corthon-com.20210112.gappssmtp.com header.s=20210112 header.b=jeMNQH59; spf=none, err=permanent DNS error (domain: corthon.com, ip: 209.85.215.170, mailfrom: bret@corthon.com) Received: by mail-pg1-f170.google.com with SMTP id r28so454971pga.0 for ; Tue, 02 Nov 2021 13:20:58 -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=736IEu2JKVxKdjKmBDRX5BxIzKIQ4ijoemtTxK4AMMk=; b=jeMNQH590twDjkaIvW17tW0Q7+sHXmRsuzrbuKv8RSIn7OEgZvSG5WlSvMCCBi1vex r7zU+pjVFIhBtIORUseP3M+CjnnFlo+FvCjW2+nC3aY4Av7YllRWqYPW6kRAiShm6seP ig7yYogOippzVggakR9GtwC6y9jjaJ7D6xv4Y3Vx/8ToGSCcSjC3NkB97UjmYk3DDTew nJ7/OBDFGEdKiTpr0ohibqSTGhaPuUhD/k/r8vMF4Ca8SHt7LB6BDR2+XfkmP1fPwuF0 vyugdYT9/11o/xSQ4tRBAXzCE5f1VX62UEyZJ9KqBnd9/VMiZBPuqq1TbdVkrVxDWnFD /TTQ== 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=736IEu2JKVxKdjKmBDRX5BxIzKIQ4ijoemtTxK4AMMk=; b=cLQm70hBwbax9ysFkHfl4N9FY0ULxWwxnpskBP1PbMxlaJDlFEie4uOq72+3zqwEWI gIA8ErEKE/ZKVsqAGdCppjEWa54gpXaV9iepNpQgr622KHtEsjEWErrVvlVwIJkJKQYY xasVz8I5ewYLNGuseaxLSscnoPw/gTABuuHT9qFFgt4e0eaQjZLv7Dr0ypYWAz2B4xYU h6Tnejqzrw8uXQ+ABCZSCnIbmW1IyacnlRoY4VJ+xvp0/JtfJZ+Sy6ySVjZKf3G/zf4H FKkcqfDHIGpJpd+KFn+NAFOFV3i12r48qEtoH9OrbIt5zqGYOQrvqVEkT6vq2jtwUroR QllQ== X-Gm-Message-State: AOAM533f2eY7gvUuu2VE94lC8cc5Uv2HvvUUyK+6gcwICLv9k6xuUG7V 0IYBExAg+yIh31n3NCnenQHnrvzne13RYKpN X-Google-Smtp-Source: ABdhPJxhl+PB21aPtyEXekF2RMBLbnmLZ8td4sQnHghn+aJtcO+ZsW5SSYQu1XMVyAYnCM0HgNNWcA== X-Received: by 2002:a05:6a00:850:b0:47c:2c90:df44 with SMTP id q16-20020a056a00085000b0047c2c90df44mr38618871pfk.70.1635884457727; Tue, 02 Nov 2021 13:20:57 -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.20.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Nov 2021 13:20:57 -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 v2 11/16] ArmPkg: Add Basic MMU Lib for Arm silicon Date: Tue, 2 Nov 2021 13:17:43 -0700 Message-Id: <20211102201748.1963-12-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: Sean Brogan The previously Arm-specific "ArmMmuLib" has been generalized as "MmuLib". The Arm implementation of this lib can still use the existing library logic to back it. As such, this implementation is currently just a shim to the old library, while enabling higher-level code to be more common. 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..70840c26f489 --- /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