From nobody Sat Nov 2 14:37:59 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487646532771966.6815641050794; Mon, 20 Feb 2017 19:08:52 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8751B82213; Mon, 20 Feb 2017 19:08:51 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 97E5782212 for ; Mon, 20 Feb 2017 19:08:50 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Feb 2017 19:08:50 -0800 Received: from jfan12-desk.ccr.corp.intel.com ([10.239.9.5]) by fmsmga006.fm.intel.com with ESMTP; 20 Feb 2017 19:08:49 -0800 X-Original-To: edk2-devel@ml01.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,187,1484035200"; d="scan'208";a="68193571" From: Jeff Fan To: edk2-devel@ml01.01.org Date: Tue, 21 Feb 2017 11:08:21 +0800 Message-Id: <20170221030822.19548-2-jeff.fan@intel.com> X-Mailer: git-send-email 2.9.3.windows.2 In-Reply-To: <20170221030822.19548-1-jeff.fan@intel.com> References: <20170221030822.19548-1-jeff.fan@intel.com> Subject: [edk2] [PATCH v2 1/2] UefiCpuPkg/CpuDxe: Copy two functions from PciHostBridge X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael D Kinney , Jiewen Yao , Feng Tian , Laszlo Ersek MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Copy AddMemoryMappedIoSpace() and AddMemoryMappedIoSpace() from MdeModulePkg\Bus\Pci\PciHostBridgeDxe\PciHostBridge.c. https://bugzilla.tianocore.org/show_bug.cgi?id=3D390 Cc: Laszlo Ersek Cc: Jiewen Yao Cc: Feng Tian Cc: Michael D Kinney Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan Reviewed-by: Laszlo Ersek --- UefiCpuPkg/CpuDxe/CpuDxe.c | 148 +++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 148 insertions(+) diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.c b/UefiCpuPkg/CpuDxe/CpuDxe.c index 9fb6d76..925c50f 100644 --- a/UefiCpuPkg/CpuDxe/CpuDxe.c +++ b/UefiCpuPkg/CpuDxe/CpuDxe.c @@ -887,6 +887,154 @@ IdleLoopEventCallback ( CpuSleep (); } =20 +/** + Ensure the compatibility of a memory space descriptor with the MMIO aper= ture. + + The memory space descriptor can come from the GCD memory space map, or i= t can + represent a gap between two neighboring memory space descriptors. In the + latter case, the GcdMemoryType field is expected to be + EfiGcdMemoryTypeNonExistent. + + If the memory space descriptor already has type + EfiGcdMemoryTypeMemoryMappedIo, and its capabilities are a superset of t= he + required capabilities, then no action is taken -- it is by definition + compatible with the aperture. + + Otherwise, the intersection of the memory space descriptor is calculated= with + the aperture. If the intersection is the empty set (no overlap), no acti= on is + taken; the memory space descriptor is compatible with the aperture. + + Otherwise, the type of the descriptor is investigated again. If the type= is + EfiGcdMemoryTypeNonExistent (representing a gap, or a genuine descriptor= with + such a type), then an attempt is made to add the intersection as MMIO sp= ace + to the GCD memory space map, with the specified capabilities. This ensur= es + continuity for the aperture, and the descriptor is deemed compatible wit= h the + aperture. + + Otherwise, the memory space descriptor is incompatible with the MMIO + aperture. + + @param[in] Base Base address of the aperture. + @param[in] Length Length of the aperture. + @param[in] Capabilities Capabilities required by the aperture. + @param[in] Descriptor The descriptor to ensure compatibility with the + aperture for. + + @retval EFI_SUCCESS The descriptor is compatible. The GCD mem= ory + space map may have been updated, for + continuity within the aperture. + @retval EFI_INVALID_PARAMETER The descriptor is incompatible. + @return Error codes from gDS->AddMemorySpace(). +**/ +EFI_STATUS +IntersectMemoryDescriptor ( + IN UINT64 Base, + IN UINT64 Length, + IN UINT64 Capabilities, + IN CONST EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Descriptor + ) +{ + UINT64 IntersectionBase; + UINT64 IntersectionEnd; + EFI_STATUS Status; + + if (Descriptor->GcdMemoryType =3D=3D EfiGcdMemoryTypeMemoryMappedIo && + (Descriptor->Capabilities & Capabilities) =3D=3D Capabilities) { + return EFI_SUCCESS; + } + + IntersectionBase =3D MAX (Base, Descriptor->BaseAddress); + IntersectionEnd =3D MIN (Base + Length, + Descriptor->BaseAddress + Descriptor->Length); + if (IntersectionBase >=3D IntersectionEnd) { + // + // The descriptor and the aperture don't overlap. + // + return EFI_SUCCESS; + } + + if (Descriptor->GcdMemoryType =3D=3D EfiGcdMemoryTypeNonExistent) { + Status =3D gDS->AddMemorySpace (EfiGcdMemoryTypeMemoryMappedIo, + IntersectionBase, IntersectionEnd - IntersectionBase, + Capabilities); + + DEBUG ((EFI_ERROR (Status) ? EFI_D_ERROR : EFI_D_VERBOSE, + "%a: %a: add [%Lx, %Lx): %r\n", gEfiCallerBaseName, __FUNCTION__, + IntersectionBase, IntersectionEnd, Status)); + return Status; + } + + DEBUG ((EFI_D_ERROR, "%a: %a: desc [%Lx, %Lx) type %u cap %Lx conflicts " + "with aperture [%Lx, %Lx) cap %Lx\n", gEfiCallerBaseName, __FUNCTION__, + Descriptor->BaseAddress, Descriptor->BaseAddress + Descriptor->Length, + (UINT32)Descriptor->GcdMemoryType, Descriptor->Capabilities, + Base, Base + Length, Capabilities)); + return EFI_INVALID_PARAMETER; +} + +/** + Add MMIO space to GCD. + The routine checks the GCD database and only adds those which are + not added in the specified range to GCD. + + @param Base Base address of the MMIO space. + @param Length Length of the MMIO space. + @param Capabilities Capabilities of the MMIO space. + + @retval EFI_SUCCES The MMIO space was added successfully. +**/ +EFI_STATUS +AddMemoryMappedIoSpace ( + IN UINT64 Base, + IN UINT64 Length, + IN UINT64 Capabilities + ) +{ + EFI_STATUS Status; + UINTN Index; + UINTN NumberOfDescriptors; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap; + + Status =3D gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap= ); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "%a: %a: GetMemorySpaceMap(): %r\n", + gEfiCallerBaseName, __FUNCTION__, Status)); + return Status; + } + + for (Index =3D 0; Index < NumberOfDescriptors; Index++) { + Status =3D IntersectMemoryDescriptor (Base, Length, Capabilities, + &MemorySpaceMap[Index]); + if (EFI_ERROR (Status)) { + goto FreeMemorySpaceMap; + } + } + + DEBUG_CODE ( + // + // Make sure there are adjacent descriptors covering [Base, Base + Len= gth). + // It is possible that they have not been merged; merging can be preve= nted + // by allocation and different capabilities. + // + UINT64 CheckBase; + EFI_STATUS CheckStatus; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor; + + for (CheckBase =3D Base; + CheckBase < Base + Length; + CheckBase =3D Descriptor.BaseAddress + Descriptor.Length) { + CheckStatus =3D gDS->GetMemorySpaceDescriptor (CheckBase, &Descripto= r); + ASSERT_EFI_ERROR (CheckStatus); + ASSERT (Descriptor.GcdMemoryType =3D=3D EfiGcdMemoryTypeMemoryMapped= Io); + ASSERT ((Descriptor.Capabilities & Capabilities) =3D=3D Capabilities= ); + } + ); + +FreeMemorySpaceMap: + FreePool (MemorySpaceMap); + + return Status; +} =20 /** Initialize the state information for the CPU Architectural Protocol. --=20 2.9.3.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 14:37:59 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487646535238112.1487947364767; Mon, 20 Feb 2017 19:08:55 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id BC49D82212; Mon, 20 Feb 2017 19:08:53 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id EF21082216 for ; Mon, 20 Feb 2017 19:08:51 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Feb 2017 19:08:51 -0800 Received: from jfan12-desk.ccr.corp.intel.com ([10.239.9.5]) by fmsmga006.fm.intel.com with ESMTP; 20 Feb 2017 19:08:50 -0800 X-Original-To: edk2-devel@ml01.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,187,1484035200"; d="scan'208";a="68193574" From: Jeff Fan To: edk2-devel@ml01.01.org Date: Tue, 21 Feb 2017 11:08:22 +0800 Message-Id: <20170221030822.19548-3-jeff.fan@intel.com> X-Mailer: git-send-email 2.9.3.windows.2 In-Reply-To: <20170221030822.19548-1-jeff.fan@intel.com> References: <20170221030822.19548-1-jeff.fan@intel.com> Subject: [edk2] [PATCH v2 2/2] UefiCpuPkg/CpuDxe: Add Local APIC memory mapped space in GCD X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael D Kinney , Jiewen Yao , Feng Tian , Laszlo Ersek MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Local APIC memory mapped space should be added into GCD and be allocated. Otherwise, UEFI firmware cannot get correct memory map for it. For example, SMM profile feature needs to get the completed MMIO map to protect them. v2: Consume AddMemoryMappedIoSpace() to handle the case that Local APIC memory space has already been added before. https://bugzilla.tianocore.org/show_bug.cgi?id=3D390 Cc: Laszlo Ersek Cc: Jiewen Yao Cc: Feng Tian Cc: Michael D Kinney Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan --- UefiCpuPkg/CpuDxe/CpuDxe.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.c b/UefiCpuPkg/CpuDxe/CpuDxe.c index 925c50f..84d5f78 100644 --- a/UefiCpuPkg/CpuDxe/CpuDxe.c +++ b/UefiCpuPkg/CpuDxe/CpuDxe.c @@ -1037,6 +1037,36 @@ FreeMemorySpaceMap: } =20 /** + Add and allocate CPU local APIC memory mapped space.=20 + + @param[in]ImageHandle Image handle this driver. + +**/ +VOID +AddLocalApicMemorySpace ( + IN EFI_HANDLE ImageHandle + ) +{ + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS BaseAddress; + + BaseAddress =3D (EFI_PHYSICAL_ADDRESS) GetLocalApicBaseAddress(); + Status =3D AddMemoryMappedIoSpace (BaseAddress, SIZE_4KB, EFI_MEMORY_UC); + ASSERT_EFI_ERROR (Status); + + Status =3D gDS->AllocateMemorySpace ( + EfiGcdAllocateAddress, + EfiGcdMemoryTypeMemoryMappedIo, + 0, + SIZE_4KB, + &BaseAddress, + ImageHandle, + NULL + ); + ASSERT_EFI_ERROR (Status); +} + +/** Initialize the state information for the CPU Architectural Protocol. =20 @param ImageHandle Image handle this driver. @@ -1095,6 +1125,11 @@ InitializeCpu ( RefreshGcdMemoryAttributes (); =20 // + // Add and allocate local APIC memory mapped space + // + AddLocalApicMemorySpace (ImageHandle); + + // // Setup a callback for idle events // Status =3D gBS->CreateEventEx ( --=20 2.9.3.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel