From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by mx.groups.io with SMTP id smtpd.web10.1400.1688055638948995921 for ; Thu, 29 Jun 2023 09:20:39 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="signature has expired" header.i=@taylorbeebe.com header.s=google header.b=ReY5zikA; spf=pass (domain: taylorbeebe.com, ip: 209.85.210.170, mailfrom: t@taylorbeebe.com) Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-666eec46206so860800b3a.3 for ; Thu, 29 Jun 2023 09:20:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=taylorbeebe.com; s=google; t=1688055638; x=1690647638; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DGr2CH9gsYdCU7jpd+3ACf7a6939yWODEPE2ozRKB/8=; b=ReY5zikAB8rxyNRImWm91vjVOYTSXajAUmmA/OMSmdpOqd1lFYdL9tuGPwW64rOOnz w9dNPuPoqArFnLD5etToiHbgklSPpuM2lIW98ydNxdDVykNhbfSr2XV/Vk/ESef/BftV 7q1tracY80ABFVUFCErpNyi9DVUQEmI6NgJTIlLa/Z40fbT0zNY4YRxv3WAB0icSQL2x BPjZpatGn8Psppz+zyTI98GZoeSZn1Br6PfRCmePuKmYY62p+JQ89I+PUW1Ot+UcjD48 wySjMhBY6x3AKdOD/8qzoPJVwYm0SVILq0Nu2iGs7pAX+tRwcSuQClADEHqybOwk3ksP X/Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688055638; x=1690647638; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DGr2CH9gsYdCU7jpd+3ACf7a6939yWODEPE2ozRKB/8=; b=CJDE+NsN+g9HbQUom/18V7V7VvM+WH0HjqdWMPi6c5eLsp7WXOE6LZXVXB/Y8K2cg8 TuAH21R0yjfRTJM/jbGx0CXmjEgNdzwSMtYWRryMUn0IZ53FWHs8k0qfDXlEZv6NWjtf qNkbU8qerjC/iYc8ccHvhaj18ifjuLtWbGlLBu+OxSV1lP7SjUO6IrfmnbBBB5WgLr1z OGN2LtYS56f69txb2laDPKk96q/OUJnK+NZTpzrib/lHWjZi3gF7OnLJoWHVOP/kYOiX 8SmtRgtyKgJ+qAZ/qX8tm+Zc3eslnQbVDbuOgfoctgbaK7FloX/LhqpasmCUF+Db78SN /9MQ== X-Gm-Message-State: ABy/qLaT6bRbTx8Dmt6pf44wA7b4scoodJ+St/s6TeHTq7ol0qPD2iCn 7+YG3IDpL7HDzusKzk95Rr3xC4V93jCRuaMEXbaPOw== X-Google-Smtp-Source: APBJJlF7GXg64hJUL/LFuFIKemi3YgGHx6er+bl6OrE+SEMGCPMqy8UvwgxS0ln44vdaZhnw1QRGWA== X-Received: by 2002:a05:6a00:1352:b0:67e:45ab:b86b with SMTP id k18-20020a056a00135200b0067e45abb86bmr410488pfu.28.1688055638158; Thu, 29 Jun 2023 09:20:38 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([50.46.230.135]) by smtp.gmail.com with ESMTPSA id b5-20020aa78705000000b0064f7c56d8b7sm6993578pfo.219.2023.06.29.09.20.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 09:20:37 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Taylor Beebe , Leif Lindholm , Ard Biesheuvel , Taylor Beebe Subject: [PATCH 4/4] ArmPkg: Add Function Headers to MMU Logic Date: Thu, 29 Jun 2023 09:17:58 -0700 Message-ID: <389dd0904fc75321dc307834f735874ffe43e9ab.1687989723.git.t@taylorbeebe.com> X-Mailer: git-send-email 2.41.0.windows.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Taylor Beebe =0D Much of the MMU logic was written without function headers. This patch=0D adds function headers where absent and updates function headers which=0D do not match the EDK2 standard.=0D =0D Cc: Leif Lindholm =0D Cc: Ard Biesheuvel =0D =0D Signed-off-by: Taylor Beebe =0D ---=0D ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c | 92 ++++++++++++++++++++++++++++-=0D ArmPkg/Drivers/CpuDxe/Arm/Mmu.c | 86 ++++++++++++++++++++++++---=0D 2 files changed, 169 insertions(+), 9 deletions(-)=0D =0D diff --git a/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c b/ArmPkg/Drivers/CpuDxe/AA= rch64/Mmu.c=0D index d9d386dbed6b..e14eb47ce4c6 100644=0D --- a/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c=0D +++ b/ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c=0D @@ -18,6 +18,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent=0D #define MIN_T0SZ 16=0D #define BITS_PER_LEVEL 9=0D =0D +/**=0D + Parses T0SZ to determine the level and number of entries at the root=0D + of the translation table.=0D +=0D + @param T0SZ The T0SZ value to be parsed.=0D + @param RootTableLevel The level of the root table.=0D + @param RootTableEntryCount The number of entries in the root table.=0D +**/=0D STATIC=0D VOID=0D GetRootTranslationTableInfo (=0D @@ -30,6 +38,13 @@ GetRootTranslationTableInfo (=0D *RootTableEntryCount =3D TT_ENTRY_COUNT >> (T0SZ - MIN_T0SZ) % BITS_PER_= LEVEL;=0D }=0D =0D +/**=0D + Converts ARM translation table attributes to GCD attributes.=0D +=0D + @param PageAttributes The translation table attributes to be converted.= =0D +=0D + @retval The analogous GCD attributes.=0D +**/=0D STATIC=0D UINT64=0D PageAttributeToGcdAttribute (=0D @@ -100,6 +115,14 @@ RegionAttributeToGcdAttribute (=0D return PageAttributeToGcdAttribute (PageAttributes);=0D }=0D =0D +/**=0D + Retrieves the attribute of the first page entry in the translation table= .=0D +=0D + @param[in] FirstLevelTableAddress The base address of the translation = table.=0D + @param[in] TableLevel The current level being traversed.=0D +=0D + @retval The attributes of the first page entry found, or INVALID_ENTRY.= =0D +**/=0D STATIC=0D UINT64=0D GetFirstPageAttribute (=0D @@ -126,6 +149,19 @@ GetFirstPageAttribute (=0D }=0D }=0D =0D +/**=0D + This function recursively traverses the translation table heirarchy to=0D + synchronise the GCD with the translation table.=0D +=0D + @param[in] TableAddress The address of the table being pro= cessed.=0D + @param[in] EntryCount The number of entries in the curre= nt level of the table.=0D + @param[in] TableLevel The current level of the memory ta= ble being processed.=0D + @param[in] BaseAddress The starting address of the region= .=0D + @param[in, out] PrevEntryAttribute The attributes of the previous reg= ion.=0D + @param[in, out] StartGcdRegion The start of the GCD region.=0D +=0D + @retval The address at the end of the last region processed.=0D +**/=0D STATIC=0D UINT64=0D GetNextEntryAttribute (=0D @@ -220,6 +256,15 @@ GetNextEntryAttribute (=0D return BaseAddress + (EntryCount * TT_ADDRESS_AT_LEVEL (TableLevel));=0D }=0D =0D +/**=0D + Sync the GCD memory space attributes with the translation table.=0D +=0D + @param[in] CpuProtocol The CPU architectural protocol instance.=0D +=0D + @retval EFI_SUCCESS The GCD memory space attributes are synced with=0D + the MMU page table.=0D + @retval Others The return value of GetMemorySpaceMap().=0D +**/=0D EFI_STATUS=0D SyncCacheConfig (=0D IN EFI_CPU_ARCH_PROTOCOL *CpuProtocol=0D @@ -298,6 +343,13 @@ SyncCacheConfig (=0D return EFI_SUCCESS;=0D }=0D =0D +/**=0D + Convert EFI memory attributes to ARM translation table attributes.=0D +=0D + @param[in] EfiAttributes EFI memory attributes.=0D +=0D + @retval The analogous translation table attributes.=0D +**/=0D UINT64=0D EfiAttributeToArmAttribute (=0D IN UINT64 EfiAttributes=0D @@ -345,8 +397,25 @@ EfiAttributeToArmAttribute (=0D return ArmAttributes;=0D }=0D =0D -// This function will recursively go down the page table to find the first= block address linked to 'BaseAddress'.=0D -// And then the function will identify the size of the region that has the= same page table attribute.=0D +/**=0D + This function returns the attributes of the memory region containing the= =0D + specified address.=0D +=0D + RegionLength and RegionAttributes are only valid if the result is EFI_SU= CCESS.=0D +=0D + @param[in] TranslationTable The translation table base address.= =0D + @param[in] TableLevel The level of the translation table.= =0D + @param[in] LastBlockEntry The last block address of the table = level.=0D + @param[in, out] BaseAddress The base address of the memory regio= n.=0D + @param[out] RegionLength The length of the memory region.=0D + @param[out] RegionAttributes The attributes of the memory region.= =0D +=0D + @retval EFI_SUCCESS The attributes of the memory region were=0D + returned successfully.=0D + @retval EFI_NOT_FOUND The memory region was not found.=0D + @retval EFI_NO_MAPPING The translation table entry associated with=0D + BaseAddress is invalid.=0D +**/=0D EFI_STATUS=0D GetMemoryRegionRec (=0D IN UINT64 *TranslationTable,=0D @@ -423,6 +492,25 @@ GetMemoryRegionRec (=0D return EFI_NOT_FOUND;=0D }=0D =0D +/**=0D + Retrieves a memory region from a given base address.=0D +=0D + This function retrieves a memory region starting from a given base addre= ss.=0D +=0D + @param[in, out] BaseAddress The base address from which to retriev= e=0D + the memory region. On successful retur= n, this is=0D + updated to the end address of the retr= ieved region.=0D + @param[out] RegionLength The length of the retrieved memory reg= ion.=0D + @param[out] RegionAttributes The attributes of the retrieved memory= region.=0D +=0D + @retval EFI_STATUS Returns EFI_SUCCESS if the memory region= is=0D + retrieved successfully, or the status of= the=0D + recursive call to GetMemoryRegionRec.=0D + @retval EFI_NOT_FOUND The memory region was not found.=0D + @retval EFI_NO_MAPPING The translation table entry associated w= ith=0D + BaseAddress is invalid.=0D + @retval EFI_INVALID_PARAMETER One of the input parameters was NULL.=0D +**/=0D EFI_STATUS=0D GetMemoryRegion (=0D IN OUT UINTN *BaseAddress,=0D diff --git a/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c b/ArmPkg/Drivers/CpuDxe/Arm/Mm= u.c=0D index 5a2f36d06086..8c4de284e160 100644=0D --- a/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c=0D +++ b/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c=0D @@ -17,9 +17,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent=0D Convert a set of ARM short descriptor section attributes into a mask=0D of EFI_MEMORY_xx constants.=0D =0D - @param SectionAttributes The set of page attributes.=0D - @param GcdAttributes Pointer to the return value.=0D + @param[in] SectionAttributes The set of page attributes.=0D + @param[out] GcdAttributes Pointer to the return value.=0D =0D + @retval EFI_SUCCESS The attributes were converted successfully.=0D + @retval EFI_UNSUPPORTED The section attributes did not have a=0D + GCD transation.=0D **/=0D STATIC=0D EFI_STATUS=0D @@ -87,10 +90,11 @@ SectionToGcdAttributes (=0D Convert an arch specific set of page attributes into a mask=0D of EFI_MEMORY_xx constants.=0D =0D - @param PageAttributes The set of page attributes.=0D -=0D - @retval The mask of EFI_MEMORY_xx constants.=0D + @param[in] PageAttributes The set of page attributes.=0D =0D + @retval EFI_SUCCESS The attributes were converted successfully.=0D + @retval EFI_UNSUPPORTED The section attributes did not have a=0D + GCD transation.=0D **/=0D UINT64=0D RegionAttributeToGcdAttribute (=0D @@ -107,9 +111,11 @@ RegionAttributeToGcdAttribute (=0D Convert a set of ARM short descriptor page attributes into a mask=0D of EFI_MEMORY_xx constants.=0D =0D - @param PageAttributes The set of page attributes.=0D - @param GcdAttributes Pointer to the return value.=0D + @param[in] PageAttributes The set of page attributes.=0D + @param[out] GcdAttributes Pointer to the return value.=0D =0D + @retval EFI_SUCCESS The attributes were converted successfully.=0D + @retval EFI_UNSUPPORTED The page attributes did not have a GCD transat= ion.=0D **/=0D STATIC=0D EFI_STATUS=0D @@ -173,6 +179,23 @@ PageToGcdAttributes (=0D return EFI_SUCCESS;=0D }=0D =0D +/**=0D + Synchronizes the GCD with the translation table for a specified page.=0D +=0D + This function synchronizes cache configuration for a given page based on= its section index=0D + and the first level descriptor. It traverses the second level table entr= ies of the page and=0D + updates the GCD attributes accordingly for each entry.=0D +=0D + @param[in] SectionIndex The index of the section where= the page resides.=0D + @param[in] FirstLevelDescriptor The first translation table le= vel of the page.=0D + @param[in] NumberOfDescriptors The number of descriptors in t= he GCD memory space map.=0D + @param[in] MemorySpaceMap The GCD memory space descripto= r.=0D + @param[in, out] NextRegionBase The next region base address.= =0D + @param[in, out] NextRegionLength The next region length.=0D + @param[in, out] NextSectionAttributes The next section attributes.=0D +=0D + @retval EFI_STATUS Always return success=0D +**/=0D EFI_STATUS=0D SyncCacheConfigPage (=0D IN UINT32 SectionIndex,=0D @@ -258,6 +281,14 @@ SyncCacheConfigPage (=0D return EFI_SUCCESS;=0D }=0D =0D +/**=0D + Sync the GCD memory space attributes with the translation table.=0D +=0D + @param[in] CpuProtocol The CPU architectural protocol instance.=0D +=0D + @retval EFI_SUCCESS The GCD memory space attributes are synced with th= e MMU page table.=0D + @retval Others The return value of GetMemorySpaceMap().=0D +**/=0D EFI_STATUS=0D SyncCacheConfig (=0D IN EFI_CPU_ARCH_PROTOCOL *CpuProtocol=0D @@ -395,6 +426,13 @@ SyncCacheConfig (=0D return EFI_SUCCESS;=0D }=0D =0D +/**=0D + Convert EFI memory attributes to ARM translation table attributes.=0D +=0D + @param[in] EfiAttributes EFI memory attributes.=0D +=0D + @retval The analogous translation table attributes.=0D +**/=0D UINT64=0D EfiAttributeToArmAttribute (=0D IN UINT64 EfiAttributes=0D @@ -448,6 +486,22 @@ EfiAttributeToArmAttribute (=0D return ArmAttributes;=0D }=0D =0D +/**=0D + This function finds the end of a memory region in a translation table. A= =0D + memory region is defined as a contiguous set of pages with the same attr= ibutes.=0D +=0D + @param[in] PageTable The translation table to traverse.=0D + @param[in] BaseAddress The address from which to start the sear= ch=0D + @param[in] RegionAttributes The attributes of the start of the regio= n.=0D + @param[out] RegionLength The length of the region found.=0D +=0D + @retval EFI_SUCCESS The region was found.=0D + @retval EFI_NOT_FOUND The end of the region was not found.=0D + @retval EFI_NO_MAPPING The region specified by BaseAddress is not map= ped=0D + in the input translation table.=0D + @retval EFI_UNSUPPORTED Large pages are not supported.=0D +**/=0D +STATIC=0D EFI_STATUS=0D GetMemoryRegionPage (=0D IN UINT32 *PageTable,=0D @@ -496,6 +550,24 @@ GetMemoryRegionPage (=0D return Status;=0D }=0D =0D +/**=0D + Get the memory region that contains the specified address. A memory regi= on is defined=0D + as a contiguous set of pages with the same attributes.=0D +=0D + RegionLength and RegionAttributes are only valid if EFI_SUCCESS is retur= ned.=0D +=0D + @param[in, out] BaseAddress On input, the address to search for.= =0D + On output, the base address of the r= egion found.=0D + @param[out] RegionLength The length of the region found.=0D + @param[out] RegionAttributes The attributes of the region found.= =0D +=0D + @retval EFI_SUCCESS Region found=0D + @retval EFI_NOT_FOUND Region not found=0D + @retval EFI_UNSUPPORTED Large pages are unsupported=0D + @retval EFI_NO_MAPPING The page specified by BaseAddress is u= nmapped=0D + @retval EFI_INVALID_PARAMETER The BaseAddress exceeds the addressabl= e range of=0D + the translation table.=0D +**/=0D EFI_STATUS=0D GetMemoryRegion (=0D IN OUT UINTN *BaseAddress,=0D -- =0D 2.41.0.windows.1=0D =0D