From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by mx.groups.io with SMTP id smtpd.web09.7073.1635847040252169367 for ; Tue, 02 Nov 2021 02:57:20 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20210112.gappssmtp.com header.s=20210112 header.b=6Gb0jwM6; spf=pass (domain: nuviainc.com, ip: 209.85.221.41, mailfrom: leif@nuviainc.com) Received: by mail-wr1-f41.google.com with SMTP id u18so32364753wrg.5 for ; Tue, 02 Nov 2021 02:57:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=D4sF0UCetPW/DeLeTZIfjCrniMvRxyqfQU3VSTpeiuc=; b=6Gb0jwM6MoisQ20FF/CaHjlikwDObQYxo6ASTtv1HhRdcqUL8ifo65Cpq/jwEN3rLV +oTPYQ83nW1GKmlHDx94BxltDbRKv3pHdAacs+utYTkxh9IN6fKszo+C2NIEReLDueMg 893+CnPz4nAlMJ6PDaZ7OamAVMJvZ+3jgh1m818GByShXQI6R6fR7IxcIt4WOz/lXvJK CETLiXbOVTE3PcBbKyS3lGElupj8HL+osNzzH8C+ZDUQWgXYi1w0q64HOlT1EGLSCwJA a2jKpYxo20aYWzqxSoTF9hxSSQDsY8v2kkBwsNZ9frDEdJYf3sEksiAJPIjvEDf3pAwl k4og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=D4sF0UCetPW/DeLeTZIfjCrniMvRxyqfQU3VSTpeiuc=; b=lCNhSrk2xUVUsvl+sqxydE6M1NGqDGwTzkh3EmMMHRh31Wf4DbQ9AfE1ZNI5/aNZkd yyAkITvO4X00pNlhA9Ewk6Szfaj6+5L6IsKjbRWTjEUGHDFfjGvJ5QX2MPwaPi08+d6C UwURiBcfr9qgzHJGLXsrXOsHCCQ7nwmbCzMKN+9CFh/3vUW+CDNkwIcyhpi7jnNgw+mi hB7pFr8Ggtr2IpHbGEXOgQT9hApMD+rjiRZTzAs1ptjXmzitChma3lgKV8gVP4ObbL/x qWv6lthYfVBz61MOw9JR4/yyjxIdSOgKJjke+cMpZVHHrr1iBIrUtij9axedK7wYZWUS WOtg== X-Gm-Message-State: AOAM5331wrqyzZUaNHUv9beuDYXNKVpcBGBfusoqbdu3/LJ0PFGS0O72 YE12L3jhLWEEEXo5FAnfMFn4ow== X-Google-Smtp-Source: ABdhPJxXz0FLSsAWiYKVrk6ucmBgLpuIvLpjkY9v8BJK2JhQGO5eYIggou9SW4zjXssBNQX4SmcAqQ== X-Received: by 2002:adf:c40f:: with SMTP id v15mr36265041wrf.302.1635847038715; Tue, 02 Nov 2021 02:57:18 -0700 (PDT) Return-Path: Received: from leviathan (cpc92314-cmbg19-2-0-cust559.5-4.cable.virginm.net. [82.11.186.48]) by smtp.gmail.com with ESMTPSA id t11sm5057423wrz.97.2021.11.02.02.57.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Nov 2021 02:57:18 -0700 (PDT) Date: Tue, 2 Nov 2021 09:57:16 +0000 From: "Leif Lindholm" To: "brbarkel@microsoft.com" Cc: devel@edk2.groups.io, Ard Biesheuvel , Sean Brogan Subject: Re: [PATCH v1 11/16] ArmPkg: Add Basic MMU Lib for Arm silicon Message-ID: <20211102095716.ucmiocmes3fsylge@leviathan> References: <20211101195648.6420-1-brbarkel@microsoft.com> <20211101195648.6420-12-brbarkel@microsoft.com> MIME-Version: 1.0 In-Reply-To: <20211101195648.6420-12-brbarkel@microsoft.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Nov 01, 2021 at 12:56:43 -0700, brbarkel@microsoft.com wrote: > From: Sean Brogan > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3651 Some description please. > 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 > +This library instance implements a very limited MMU Lib instance > +for the ARM/AARCH64 architectures. This library shims a common library > +interface to the ArmPkg defined ArmMmuLib.ib. - ib. ? > + > +Copyright (c) Microsoft Corporation. > +SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include > +#include > +#include Please sort alphabetically. / Leif > + > +/** > + Bitwise sets the memory attributes on a range of memory based on an attributes mask. > + > + @param BaseAddress The start of the range for which to set attributes. > + @param Length The length of the range. > + @param Attributes A bitmask of the attributes to set. See "Physical memory > + protection attributes" in UefiSpec.h > + > + @return EFI_SUCCESS > + @return Others > + > +**/ > +EFI_STATUS > +EFIAPI > +MmuSetAttributes ( > + IN EFI_PHYSICAL_ADDRESS BaseAddress, > + IN UINT64 Length, > + IN UINT64 Attributes > + ) > + { > + EFI_STATUS Status; > + > + Status = EFI_UNSUPPORTED; > + > + if (Attributes & EFI_MEMORY_XP) { > + Status = ArmSetMemoryRegionNoExec (BaseAddress, Length); > + if (EFI_ERROR(Status)) { > + DEBUG((DEBUG_ERROR, "%a - Failed to set NX. Status = %r\n", __FUNCTION__, Status)); > + } > + } > + > + ASSERT_EFI_ERROR(Status); > + return Status; > + } > + > + > +/** > + Bitwise clears the memory attributes on a range of memory based on an attributes mask. > + > + @param BaseAddress The start of the range for which to clear attributes. > + @param Length The length of the range. > + @param Attributes A bitmask of the attributes to clear. See "Physical memory > + protection attributes" in UefiSpec.h > + > + @return EFI_SUCCESS > + @return Others > + > +**/ > +EFI_STATUS > +EFIAPI > +MmuClearAttributes ( > + IN EFI_PHYSICAL_ADDRESS BaseAddress, > + IN UINT64 Length, > + IN UINT64 Attributes > + ) > + { > + EFI_STATUS Status; > + > + Status = EFI_UNSUPPORTED; > + > + if (Attributes & EFI_MEMORY_XP) { > + Status = ArmClearMemoryRegionNoExec (BaseAddress, Length); > + if (EFI_ERROR(Status)) { > + DEBUG((DEBUG_ERROR, "%a - Failed to clear NX. Status = %r\n", __FUNCTION__, Status)); > + } > + } > + > + if (Attributes & EFI_MEMORY_RO) { > + Status = ArmClearMemoryRegionReadOnly(BaseAddress, Length); > + if (EFI_ERROR(Status)) { > + DEBUG((DEBUG_ERROR, "%a - Failed to clear RO. Status = %r\n", __FUNCTION__, Status)); > + } > + } > + > + ASSERT_EFI_ERROR(Status); > + return Status; > + } > + > + > +/** > + Returns the memory attributes on a range of memory. > + > + @param BaseAddress The start of the range for which to set attributes. > + @param Attributes A return pointer for the attributes. > + > + @return EFI_SUCCESS > + @return EFI_INVALID_PARAMETER A return pointer is NULL. > + @return Others > + > +**/ > +EFI_STATUS > +EFIAPI > +MmuGetAttributes ( > + IN EFI_PHYSICAL_ADDRESS BaseAddress, > + OUT UINT64 *Attributes > + ) > + { > + EFI_STATUS Status; > + > + Status = EFI_UNSUPPORTED; > + > + DEBUG ((DEBUG_ERROR, "%a() API not implemented\n", __FUNCTION__)); > + > + ASSERT_EFI_ERROR(Status); > + return Status; > + } > 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] > > [Components.AARCH64, Components.ARM] > ArmPkg/Library/StandaloneMmMmuLib/ArmMmuStandaloneMmLib.inf > + ArmPkg/Library/MmuLib/BaseMmuLib.inf > diff --git a/ArmPkg/Library/MmuLib/BaseMmuLib.inf b/ArmPkg/Library/MmuLib/BaseMmuLib.inf > new file mode 100644 > index 000000000000..15095abee9c3 > --- /dev/null > +++ b/ArmPkg/Library/MmuLib/BaseMmuLib.inf > @@ -0,0 +1,30 @@ > +## @file > +# This library instance implements a very limited MMU Lib instance > +# for the ARM/AARCH64 architectures. This library shims a common library > +# interface to the ArmPkg defined ArmMmuLib. > +# > +# Copyright (c) Microsoft Corporation. > +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +## > + > +[Defines] > + INF_VERSION = 0x00010005 > + BASE_NAME = MmuLib > + FILE_GUID = 6f2ee9a4-79b3-4b77-9a47-e2bd4b917b75 > + MODULE_TYPE = BASE > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = MmuLib > + > +[Sources] > + MmuLib.c > + > +[Packages] > + MdePkg/MdePkg.dec > + MdeModulePkg/MdeModulePkg.dec > + ArmPkg/ArmPkg.dec > + > +[LibraryClasses] > + DebugLib > + ArmMmuLib > -- > 2.31.1.windows.1 >