From nobody Tue Feb 10 06:40:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.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 152078138976713.524318823085991; Sun, 11 Mar 2018 08:16:29 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id BF01E2258AF15; Sun, 11 Mar 2018 08:10:07 -0700 (PDT) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (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 3D1312258AF02 for ; Sun, 11 Mar 2018 08:10:05 -0700 (PDT) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Mar 2018 08:16:24 -0700 Received: from lzeng14-mobl2.ccr.corp.intel.com ([10.255.31.175]) by fmsmga006.fm.intel.com with ESMTP; 11 Mar 2018 08:16:23 -0700 X-Original-To: edk2-devel@lists.01.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; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.151; helo=mga17.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,455,1515484800"; d="scan'208";a="210652148" From: Star Zeng To: edk2-devel@lists.01.org Date: Sun, 11 Mar 2018 23:16:17 +0800 Message-Id: <20180311151619.1260-2-star.zeng@intel.com> X-Mailer: git-send-email 2.13.3.windows.1 In-Reply-To: <20180311151619.1260-1-star.zeng@intel.com> References: <20180311151619.1260-1-star.zeng@intel.com> Subject: [edk2] [PATCH 1/3] SourceLevelDebugPkg DebugCommUsb3: Refine some formats X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Hao Wu , Jiewen Yao , Star Zeng 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" Refine some formats and remove some unused prototypes. Cc: Jiewen Yao Cc: Ruiyu Ni Cc: Hao Wu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng Reviewed-by: Hao Wu --- .../DebugCommunicationLibUsb3Common.c | 10 ++--- .../DebugCommunicationLibUsb3Dxe.inf | 6 ++- .../DebugCommunicationLibUsb3Internal.h | 43 ++----------------= ---- .../DebugCommunicationLibUsb3Pei.inf | 2 +- 4 files changed, 13 insertions(+), 48 deletions(-) diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCom= municationLibUsb3Common.c b/SourceLevelDebugPkg/Library/DebugCommunicationL= ibUsb3/DebugCommunicationLibUsb3Common.c index c577df7dea97..e67ff1fe5ca7 100644 --- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Common.c +++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Common.c @@ -87,8 +87,8 @@ XhcClearR32Bit( VOID XhcWriteDebugReg ( IN USB3_DEBUG_PORT_HANDLE *Handle, - IN UINT32 Offset, - IN UINT32 Data + IN UINT32 Offset, + IN UINT32 Data ) { EFI_PHYSICAL_ADDRESS DebugCapabilityBase; @@ -111,7 +111,7 @@ XhcWriteDebugReg ( UINT32 XhcReadDebugReg ( IN USB3_DEBUG_PORT_HANDLE *Handle, - IN UINT32 Offset + IN UINT32 Offset ) { UINT32 Data; @@ -1049,8 +1049,8 @@ DebugPortInitialize ( } =20 if (Function !=3D NULL) { - Function (Context, UsbDebugPortHandle); + Function (Context, (DEBUG_PORT_HANDLE) UsbDebugPortHandle); } =20 - return (DEBUG_PORT_HANDLE)(UINTN)UsbDebugPortHandle; + return (DEBUG_PORT_HANDLE) UsbDebugPortHandle; } diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCom= municationLibUsb3Dxe.inf b/SourceLevelDebugPkg/Library/DebugCommunicationLi= bUsb3/DebugCommunicationLibUsb3Dxe.inf index c4e4282c98b4..3af7e7180d37 100644 --- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Dxe.inf +++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Dxe.inf @@ -59,8 +59,10 @@ [Pcd] gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugPortHandleBufferSize|250 = ## SOMETIMES_CONSUMES =20 [Protocols] - gEfiPciIoProtocolGuid ## CONSUMES - gEdkiiIoMmuProtocolGuid ## CONSUMES + ## NOTIFY + ## SOMETIMES_CONSUMES + gEfiPciIoProtocolGuid + gEdkiiIoMmuProtocolGuid ## SOMETIMES_CONSUMES =20 [LibraryClasses] BaseLib diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCom= municationLibUsb3Internal.h b/SourceLevelDebugPkg/Library/DebugCommunicatio= nLibUsb3/DebugCommunicationLibUsb3Internal.h index 66757dafaebe..961786e2a41f 100644 --- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Internal.h +++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Internal.h @@ -561,7 +561,7 @@ typedef struct _USB3_DEBUG_PORT_INSTANCE { UINT32 XhcReadDebugReg ( IN USB3_DEBUG_PORT_HANDLE *Handle, - IN UINT32 Offset + IN UINT32 Offset ); =20 /** @@ -575,8 +575,8 @@ XhcReadDebugReg ( VOID XhcSetDebugRegBit ( IN USB3_DEBUG_PORT_HANDLE *Handle, - IN UINT32 Offset, - IN UINT32 Bit + IN UINT32 Offset, + IN UINT32 Bit ); =20 /** @@ -595,43 +595,6 @@ XhcWriteDebugReg ( ); =20 /** - Discover the USB3 debug device. - =20 - @param Handle Debug port handle. - =20 - @retval RETURN_SUCCESS The serial device was initialized. - @retval RETURN_DEVICE_ERROR The serial device could not be initialized. - -**/ -RETURN_STATUS -DiscoverUsb3DebugPort( - USB3_DEBUG_PORT_HANDLE *Handle - ); - =20 -/** - Initialize the Serial Device hardware. - =20 - @param Handle Debug port handle. - - @retval RETURN_SUCCESS The serial device was initialized successfully. - @retval !RETURN_SUCCESS Error. - -**/ -RETURN_STATUS -InitializeUsb3DebugPort ( - USB3_DEBUG_PORT_HANDLE *Handle - ); - -/** - Return XHCI MMIO base address. - -**/ -EFI_PHYSICAL_ADDRESS -GetXhciBaseAddress ( - VOID - ); - -/** Verifies if the bit positions specified by a mask are set in a register. =20 @param[in, out] Register UNITN register diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCom= municationLibUsb3Pei.inf b/SourceLevelDebugPkg/Library/DebugCommunicationLi= bUsb3/DebugCommunicationLibUsb3Pei.inf index 33074db49a78..4f367622d826 100644 --- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Pei.inf +++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Pei.inf @@ -41,7 +41,7 @@ [Packages] =20 [Ppis] gEfiPeiMemoryDiscoveredPpiGuid ## CONSUMES - gEdkiiIoMmuPpiGuid ## CONSUMES + gEdkiiIoMmuPpiGuid ## SOMETIMES_CONSUMES =20 [Pcd] # The memory BAR of ehci host controller, in which usb debug feature is = enabled. --=20 2.13.3.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Tue Feb 10 06:40:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.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 152078139228063.70759995763399; Sun, 11 Mar 2018 08:16:32 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3000D22603AEA; Sun, 11 Mar 2018 08:10:10 -0700 (PDT) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (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 791292258AF0A for ; Sun, 11 Mar 2018 08:10:06 -0700 (PDT) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Mar 2018 08:16:26 -0700 Received: from lzeng14-mobl2.ccr.corp.intel.com ([10.255.31.175]) by fmsmga006.fm.intel.com with ESMTP; 11 Mar 2018 08:16:24 -0700 X-Original-To: edk2-devel@lists.01.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; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.151; helo=mga17.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,455,1515484800"; d="scan'208";a="210652160" From: Star Zeng To: edk2-devel@lists.01.org Date: Sun, 11 Mar 2018 23:16:18 +0800 Message-Id: <20180311151619.1260-3-star.zeng@intel.com> X-Mailer: git-send-email 2.13.3.windows.1 In-Reply-To: <20180311151619.1260-1-star.zeng@intel.com> References: <20180311151619.1260-1-star.zeng@intel.com> Subject: [edk2] [PATCH 2/3] SourceLevelDebugPkg DebugCommUsb3: Realloc granted DXE DMA buffer X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Hao Wu , Jiewen Yao , Star Zeng 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" For the case that the USB3 debug port instance and DMA buffers are from PEI HOB with IOMMU enabled, de8373fa07f8 is to reallocate the DMA buffers by AllocateAddress with the memory type accessible by SMM environment. But reallocating the DMA buffers by AllocateAddress may fail. Instead, this patch is to reinitialize USB3 debug port with granted DXE DMA buffer accessible by SMM environment. Cc: Jiewen Yao Cc: Ruiyu Ni Cc: Hao Wu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng Reviewed-by: Hao Wu --- .../DebugCommunicationLibUsb3Dxe.c | 246 +++++++++++++----= ---- .../DebugCommunicationLibUsb3Dxe.inf | 3 + .../DebugCommunicationLibUsb3Pei.c | 2 +- 3 files changed, 155 insertions(+), 96 deletions(-) diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCom= municationLibUsb3Dxe.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibU= sb3/DebugCommunicationLibUsb3Dxe.c index 29cec56f39dc..588c9715bd00 100644 --- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Dxe.c +++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Dxe.c @@ -18,11 +18,13 @@ #include #include #include +#include #include "DebugCommunicationLibUsb3Internal.h" =20 GUID gUsb3DbgGuid =3D USB3_DBG_GUID; =20 USB3_DEBUG_PORT_HANDLE *mUsb3Instance =3D NULL; +EFI_PCI_IO_PROTOCOL *mUsb3PciIo =3D NULL; =20 /** Creates a named event that can be signaled. @@ -85,20 +87,16 @@ Usb3NamedEventListen ( /** USB3 map one DMA buffer. =20 - @param Instance Pointer to USB3 debug port instance. @param PciIo Pointer to PciIo for USB3 debug port. @param Address DMA buffer address to be mapped. @param NumberOfBytes Number of bytes to be mapped. - @param BackupBuffer Backup buffer address. =20 **/ VOID Usb3MapOneDmaBuffer ( - IN USB3_DEBUG_PORT_HANDLE *Instance, IN EFI_PCI_IO_PROTOCOL *PciIo, IN EFI_PHYSICAL_ADDRESS Address, - IN UINTN NumberOfBytes, - IN EFI_PHYSICAL_ADDRESS BackupBuffer + IN UINTN NumberOfBytes ) { EFI_STATUS Status; @@ -117,23 +115,6 @@ Usb3MapOneDmaBuffer ( ); ASSERT_EFI_ERROR (Status); ASSERT (DeviceAddress =3D=3D ((EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress= )); - if (Instance->FromHob) { - // - // Reallocate the DMA buffer by AllocateAddress with - // the memory type accessible by SMM. - // - CopyMem ((VOID *) (UINTN) BackupBuffer, (VOID *) (UINTN) Address, Numb= erOfBytes); - Status =3D gBS->FreePages (Address, EFI_SIZE_TO_PAGES (NumberOfBytes)); - ASSERT_EFI_ERROR (Status); - Status =3D gBS->AllocatePages ( - AllocateAddress, - EfiACPIMemoryNVS, - EFI_SIZE_TO_PAGES (NumberOfBytes), - &Address - ); - ASSERT_EFI_ERROR (Status); - CopyMem ((VOID *) (UINTN) Address, (VOID *) (UINTN) BackupBuffer, Numb= erOfBytes); - } } =20 /** @@ -149,99 +130,111 @@ Usb3MapDmaBuffers ( IN EFI_PCI_IO_PROTOCOL *PciIo ) { - EFI_STATUS Status; - EDKII_IOMMU_PROTOCOL *IoMmu; - EFI_PHYSICAL_ADDRESS BackupBuffer; - UINTN BackupBufferSize; - - IoMmu =3D NULL; - Status =3D gBS->LocateProtocol (&gEdkiiIoMmuProtocolGuid, NULL, (VOID **= ) &IoMmu); - if (EFI_ERROR (Status) || (IoMmu =3D=3D NULL)) { - // - // No need to map the DMA buffers. - // - return; - } - - // - // Allocate backup buffer for the case that the USB3 - // debug port instance and DMA buffers are from PEI HOB. - // For this case, the DMA buffers need to be reallocated - // by AllocateAddress with the memory type accessible by - // SMM. - // - BackupBufferSize =3D MAX (XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE * 2 + USB3_D= EBUG_PORT_WRITE_MAX_PACKET_SIZE, - MAX (sizeof (TRB_TEMPLATE) * TR_RING_TRB_NUMBER, - MAX (sizeof (TRB_TEMPLATE) * EVENT_RING_TRB= _NUMBER, - MAX (sizeof (EVENT_RING_SEG_TABLE_ENTR= Y) * ERST_NUMBER, - MAX (sizeof (XHC_DC_CONTEXT), - STRING0_DESC_LEN + MANU_DESC= _LEN + PRODUCT_DESC_LEN + SERIAL_DESC_LEN))))); - - Status =3D gBS->AllocatePages ( - AllocateAnyPages, - EfiBootServicesData, - EFI_SIZE_TO_PAGES (BackupBufferSize), - &BackupBuffer - ); - ASSERT_EFI_ERROR (Status); - Usb3MapOneDmaBuffer ( - Instance, PciIo, Instance->UrbIn.Data, - XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE * 2 + USB3_DEBUG_PORT_WRITE_MAX_PACK= ET_SIZE, - BackupBuffer + XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE * 2 + USB3_DEBUG_PORT_WRITE_MAX_PACK= ET_SIZE ); =20 Usb3MapOneDmaBuffer ( - Instance, PciIo, Instance->TransferRingIn.RingSeg0, - sizeof (TRB_TEMPLATE) * TR_RING_TRB_NUMBER, - BackupBuffer + sizeof (TRB_TEMPLATE) * TR_RING_TRB_NUMBER ); =20 Usb3MapOneDmaBuffer ( - Instance, PciIo, Instance->TransferRingOut.RingSeg0, - sizeof (TRB_TEMPLATE) * TR_RING_TRB_NUMBER, - BackupBuffer + sizeof (TRB_TEMPLATE) * TR_RING_TRB_NUMBER ); =20 Usb3MapOneDmaBuffer ( - Instance, PciIo, Instance->EventRing.EventRingSeg0, - sizeof (TRB_TEMPLATE) * EVENT_RING_TRB_NUMBER, - BackupBuffer + sizeof (TRB_TEMPLATE) * EVENT_RING_TRB_NUMBER ); =20 Usb3MapOneDmaBuffer ( - Instance, PciIo, Instance->EventRing.ERSTBase, - sizeof (EVENT_RING_SEG_TABLE_ENTRY) * ERST_NUMBER, - BackupBuffer + sizeof (EVENT_RING_SEG_TABLE_ENTRY) * ERST_NUMBER ); =20 Usb3MapOneDmaBuffer ( - Instance, PciIo, Instance->DebugCapabilityContext, - sizeof (XHC_DC_CONTEXT), - BackupBuffer + sizeof (XHC_DC_CONTEXT) ); =20 Usb3MapOneDmaBuffer ( - Instance, PciIo, ((XHC_DC_CONTEXT *) (UINTN) Instance->DebugCapabilityContext)->DbcInfo= Context.String0DescAddress, - STRING0_DESC_LEN + MANU_DESC_LEN + PRODUCT_DESC_LEN + SERIAL_DESC_LEN, - BackupBuffer + STRING0_DESC_LEN + MANU_DESC_LEN + PRODUCT_DESC_LEN + SERIAL_DESC_LEN ); +} + +/** + Invoke a notification event =20 - gBS->FreePages (BackupBuffer, EFI_SIZE_TO_PAGES (BackupBufferSize)); + @param[in] Event Event whose notification function is being= invoked. + @param[in] Context The pointer to the notification function's= context, + which is implementation-dependent. + +**/ +VOID +EFIAPI +Usb3DxeSmmReadyToLockNotify ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + ASSERT (mUsb3Instance !=3D NULL); + + DEBUG ((DEBUG_INFO, "%a()\n", __FUNCTION__)); + mUsb3Instance->InNotify =3D TRUE; + + // + // For the case that the USB3 debug port instance and DMA buffers are + // from PEI HOB with IOMMU enabled. + // Reinitialize USB3 debug port with granted DXE DMA buffer accessible + // by SMM environment. + // + InitializeUsbDebugHardware (mUsb3Instance); + + // + // Wait some time for host to be ready after re-initialization. + // + MicroSecondDelay (1000000); + + mUsb3Instance->InNotify =3D FALSE; + gBS->CloseEvent (Event); +} + +/** + USB3 get IOMMU protocol. + + @return Pointer to IOMMU protocol. + +**/ +EDKII_IOMMU_PROTOCOL * +Usb3GetIoMmu ( + VOID + ) +{ + EFI_STATUS Status; + EDKII_IOMMU_PROTOCOL *IoMmu; + + IoMmu =3D NULL; + Status =3D gBS->LocateProtocol ( + &gEdkiiIoMmuProtocolGuid, + NULL, + (VOID **) &IoMmu + ); + if (!EFI_ERROR (Status) && (IoMmu !=3D NULL)) { + return IoMmu; + } + + return NULL; } =20 /** @@ -270,8 +263,6 @@ Usb3PciIoNotify ( UINTN PciFunctionNumber; UINT32 PciAddress; =20 - ASSERT (mUsb3Instance !=3D NULL); - Status =3D gBS->LocateHandleBuffer ( ByProtocol, &gEfiPciIoProtocolGuid, @@ -296,10 +287,23 @@ Usb3PciIoNotify ( // // Found the PciIo for USB3 debug port. // + ASSERT (mUsb3Instance !=3D NULL); DEBUG ((DEBUG_INFO, "%a()\n", __FUNCTION__)); - mUsb3Instance->InNotify =3D TRUE; - Usb3MapDmaBuffers (mUsb3Instance, PciIo); - mUsb3Instance->InNotify =3D FALSE; + if (Usb3GetIoMmu !=3D NULL) { + mUsb3Instance->InNotify =3D TRUE; + Usb3MapDmaBuffers (mUsb3Instance, PciIo); + mUsb3Instance->InNotify =3D FALSE; + + if (mUsb3Instance->FromHob) { + mUsb3PciIo =3D PciIo; + Usb3NamedEventListen ( + &gEfiDxeSmmReadyToLockProtocolGuid, + TPL_NOTIFY, + Usb3DxeSmmReadyToLockNotify, + &Event + ); + } + } gBS->CloseEvent ((EFI_EVENT) (UINTN) mUsb3Instance->PciIoEvent); break; } @@ -334,13 +338,57 @@ GetUsb3DebugPortInstance ( } =20 Done: - if (Instance !=3D NULL) { + if ((Instance !=3D NULL) && (!Instance->InNotify)) { DiscoverInitializeUsbDebugPort (Instance); } return Instance; } =20 /** + Allocates pages that are suitable for an OperationBusMasterCommonBuffer = or + OperationBusMasterCommonBuffer64 mapping. + + @param PciIo Pointer to PciIo for USB3 debug port. + @param Pages The number of pages to allocate. + @param Address A pointer to store the base system memory = address of the + allocated range. + + @retval EFI_SUCCESS The requested memory pages were allocated. + @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal = attribute bits are + MEMORY_WRITE_COMBINE and MEMORY_CACHED. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated. + +**/ +EFI_STATUS +Usb3AllocateDmaBuffer ( + IN EFI_PCI_IO_PROTOCOL *PciIo, + IN UINTN Pages, + OUT VOID **Address + ) +{ + EFI_STATUS Status; + + *Address =3D NULL; + Status =3D PciIo->AllocateBuffer ( + PciIo, + AllocateAnyPages, + EfiRuntimeServicesData, + Pages, + Address, + 0 + ); + if (!EFI_ERROR (Status)) { + Usb3MapOneDmaBuffer ( + PciIo, + (EFI_PHYSICAL_ADDRESS) (UINTN) *Address, + EFI_PAGES_TO_SIZE (Pages) + ); + } + return Status; +} + +/** Allocate aligned memory for XHC's usage. =20 @param BufferSize The size, in bytes, of the Buffer. @@ -360,15 +408,23 @@ AllocateAlignBuffer ( Buf =3D NULL; =20 if (gBS !=3D NULL) { - TmpAddr =3D 0xFFFFFFFF; - Status =3D gBS->AllocatePages ( - AllocateMaxAddress, - EfiACPIMemoryNVS, - EFI_SIZE_TO_PAGES (BufferSize), - &TmpAddr - ); - if (!EFI_ERROR (Status)) { - Buf =3D (VOID *) (UINTN) TmpAddr; + if (mUsb3PciIo !=3D NULL) { + Usb3AllocateDmaBuffer ( + mUsb3PciIo, + EFI_SIZE_TO_PAGES (BufferSize), + &Buf + ); + } else { + TmpAddr =3D 0xFFFFFFFF; + Status =3D gBS->AllocatePages ( + AllocateMaxAddress, + EfiACPIMemoryNVS, + EFI_SIZE_TO_PAGES (BufferSize), + &TmpAddr + ); + if (!EFI_ERROR (Status)) { + Buf =3D (VOID *) (UINTN) TmpAddr; + } } } =20 diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCom= municationLibUsb3Dxe.inf b/SourceLevelDebugPkg/Library/DebugCommunicationLi= bUsb3/DebugCommunicationLibUsb3Dxe.inf index 3af7e7180d37..9f737b9478a8 100644 --- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Dxe.inf +++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Dxe.inf @@ -63,6 +63,9 @@ [Protocols] ## SOMETIMES_CONSUMES gEfiPciIoProtocolGuid gEdkiiIoMmuProtocolGuid ## SOMETIMES_CONSUMES + ## NOTIFY + ## SOMETIMES_CONSUMES + gEfiDxeSmmReadyToLockProtocolGuid =20 [LibraryClasses] BaseLib diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCom= municationLibUsb3Pei.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibU= sb3/DebugCommunicationLibUsb3Pei.c index 40e9b6406b2e..145113d28dc3 100644 --- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Pei.c +++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Pei.c @@ -106,7 +106,7 @@ IoMmuAllocateBuffer ( =20 Status =3D IoMmu->AllocateBuffer ( IoMmu, - EfiBootServicesData, + EfiRuntimeServicesData, Pages, HostAddress, 0 --=20 2.13.3.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Tue Feb 10 06:40:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.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 1520781394777894.0459778772521; Sun, 11 Mar 2018 08:16:34 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9782322603AF4; Sun, 11 Mar 2018 08:10:10 -0700 (PDT) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (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 C67BE2258AF17 for ; Sun, 11 Mar 2018 08:10:07 -0700 (PDT) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Mar 2018 08:16:27 -0700 Received: from lzeng14-mobl2.ccr.corp.intel.com ([10.255.31.175]) by fmsmga006.fm.intel.com with ESMTP; 11 Mar 2018 08:16:26 -0700 X-Original-To: edk2-devel@lists.01.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; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.151; helo=mga17.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,455,1515484800"; d="scan'208";a="210652171" From: Star Zeng To: edk2-devel@lists.01.org Date: Sun, 11 Mar 2018 23:16:19 +0800 Message-Id: <20180311151619.1260-4-star.zeng@intel.com> X-Mailer: git-send-email 2.13.3.windows.1 In-Reply-To: <20180311151619.1260-1-star.zeng@intel.com> References: <20180311151619.1260-1-star.zeng@intel.com> Subject: [edk2] [PATCH 3/3] SourceLevelDebugPkg DebugCommUsb3: Use the Handle from DebugAgentLib X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Hao Wu , Jiewen Yao , Star Zeng 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" For notifications to get the Instance, de8373fa07f8 was to build HOB/SystemTable in DebugCommunicationLibUsb3 itself, that works well at normal boot, but will fail at S3 resume. At S3 resume, after the code is transferred to PiSmmCpuDxeSmm from S3Resume2Pei, HOB is still needed to be used for DMA operation, but PiSmmCpuDxeSmm has no way to get the HOB at S3 resume. In fact, DebugAgentLib has been managing the instance as Handle in HOB/SystemTable. This patch is to use the Handle from DebugAgentLib for the instance needed in DebugCommunicationLibUsb3. Cc: Jiewen Yao Cc: Ruiyu Ni Cc: Hao Wu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng Reviewed-by: Hao Wu --- .../DebugCommunicationLibUsb3Common.c | 86 +++++++++-- .../DebugCommunicationLibUsb3Dxe.c | 167 ++++++++++-------= ---- .../DebugCommunicationLibUsb3Dxe.inf | 2 +- .../DebugCommunicationLibUsb3Internal.h | 17 +-- .../DebugCommunicationLibUsb3Pei.c | 48 +++--- .../DebugCommunicationLibUsb3Pei.inf | 2 +- 6 files changed, 188 insertions(+), 134 deletions(-) diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCom= municationLibUsb3Common.c b/SourceLevelDebugPkg/Library/DebugCommunicationL= ibUsb3/DebugCommunicationLibUsb3Common.c index e67ff1fe5ca7..740d9f98b41d 100644 --- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Common.c +++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Common.c @@ -811,6 +811,42 @@ DiscoverInitializeUsbDebugPort ( } =20 /** + Set USB3 debug instance address. + +**/ =20 +VOID +SetUsb3DebugPortInstance ( + IN USB3_DEBUG_PORT_HANDLE *Instance + ) +{ + EFI_PHYSICAL_ADDRESS *AddrPtr; + + AddrPtr =3D GetUsb3DebugPortInstanceAddrPtr (); + ASSERT (AddrPtr !=3D NULL); + *AddrPtr =3D (EFI_PHYSICAL_ADDRESS) (UINTN) Instance; +} + +/** + Return USB3 debug instance address. + +**/ =20 +USB3_DEBUG_PORT_HANDLE * +GetUsb3DebugPortInstance ( + VOID + ) +{ + EFI_PHYSICAL_ADDRESS *AddrPtr; + USB3_DEBUG_PORT_HANDLE *Instance; + + AddrPtr =3D GetUsb3DebugPortInstanceAddrPtr (); + ASSERT (AddrPtr !=3D NULL); + + Instance =3D (USB3_DEBUG_PORT_HANDLE *) (UINTN) *AddrPtr; + + return Instance; +} + +/** Read data from debug device and save the data in buffer. =20 Reads NumberOfBytes data bytes from a debug device into the buffer @@ -844,16 +880,23 @@ DebugPortReadBuffer ( return 0; } =20 - UsbDebugPortHandle =3D GetUsb3DebugPortInstance (); + if (Handle !=3D NULL) { + UsbDebugPortHandle =3D (USB3_DEBUG_PORT_HANDLE *) Handle; + SetUsb3DebugPortInstance (UsbDebugPortHandle); + } else { + UsbDebugPortHandle =3D GetUsb3DebugPortInstance (); + } if (UsbDebugPortHandle =3D=3D NULL) { return 0; } =20 - if (UsbDebugPortHandle->Initialized !=3D USB3DBG_ENABLED) { + if (UsbDebugPortHandle->InNotify) { return 0; } =20 - if (UsbDebugPortHandle->InNotify) { + DiscoverInitializeUsbDebugPort (UsbDebugPortHandle); + + if (UsbDebugPortHandle->Initialized !=3D USB3DBG_ENABLED) { return 0; } =20 @@ -914,16 +957,23 @@ DebugPortWriteBuffer ( Sent =3D 0; Total =3D 0; =20 - UsbDebugPortHandle =3D GetUsb3DebugPortInstance (); + if (Handle !=3D NULL) { + UsbDebugPortHandle =3D (USB3_DEBUG_PORT_HANDLE *) Handle; + SetUsb3DebugPortInstance (UsbDebugPortHandle); + } else { + UsbDebugPortHandle =3D GetUsb3DebugPortInstance (); + } if (UsbDebugPortHandle =3D=3D NULL) { return 0; } =20 - if (UsbDebugPortHandle->Initialized !=3D USB3DBG_ENABLED) { + if (UsbDebugPortHandle->InNotify) { return 0; } =20 - if (UsbDebugPortHandle->InNotify) { + DiscoverInitializeUsbDebugPort (UsbDebugPortHandle); + + if (UsbDebugPortHandle->Initialized !=3D USB3DBG_ENABLED) { return 0; } =20 @@ -968,16 +1018,23 @@ DebugPortPollBuffer ( USB3_DEBUG_PORT_HANDLE *UsbDebugPortHandle; UINTN Length; =20 - UsbDebugPortHandle =3D GetUsb3DebugPortInstance (); + if (Handle !=3D NULL) { + UsbDebugPortHandle =3D (USB3_DEBUG_PORT_HANDLE *) Handle; + SetUsb3DebugPortInstance (UsbDebugPortHandle); + } else { + UsbDebugPortHandle =3D GetUsb3DebugPortInstance (); + } if (UsbDebugPortHandle =3D=3D NULL) { return FALSE; } =20 - if (UsbDebugPortHandle->Initialized !=3D USB3DBG_ENABLED) { + if (UsbDebugPortHandle->InNotify) { return FALSE; } =20 - if (UsbDebugPortHandle->InNotify) { + DiscoverInitializeUsbDebugPort (UsbDebugPortHandle); + + if (UsbDebugPortHandle->Initialized !=3D USB3DBG_ENABLED) { return FALSE; } =20 @@ -1043,11 +1100,22 @@ DebugPortInitialize ( { USB3_DEBUG_PORT_HANDLE *UsbDebugPortHandle; =20 + // + // Validate the PCD PcdDebugPortHandleBufferSize value=20 + // + ASSERT (PcdGet16 (PcdDebugPortHandleBufferSize) =3D=3D sizeof (USB3_DEBU= G_PORT_HANDLE)); + + if (Function =3D=3D NULL && Context !=3D NULL) { + SetUsb3DebugPortInstance ((USB3_DEBUG_PORT_HANDLE *) Context); + return (DEBUG_PORT_HANDLE) Context; + } UsbDebugPortHandle =3D GetUsb3DebugPortInstance (); if (UsbDebugPortHandle =3D=3D NULL) { return NULL; } =20 + DiscoverInitializeUsbDebugPort (UsbDebugPortHandle); + if (Function !=3D NULL) { Function (Context, (DEBUG_PORT_HANDLE) UsbDebugPortHandle); } diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCom= municationLibUsb3Dxe.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibU= sb3/DebugCommunicationLibUsb3Dxe.c index 588c9715bd00..d2f3c56704eb 100644 --- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Dxe.c +++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Dxe.c @@ -23,7 +23,9 @@ =20 GUID gUsb3DbgGuid =3D USB3_DBG_GUID; =20 -USB3_DEBUG_PORT_HANDLE *mUsb3Instance =3D NULL; +USB3_DEBUG_PORT_HANDLE mUsb3Instance =3D {USB3DBG_UNINITIALIZED}; +EFI_PHYSICAL_ADDRESS mUsb3InstanceAddr =3D 0; +EFI_PHYSICAL_ADDRESS *mUsb3InstanceAddrPtr =3D NULL; EFI_PCI_IO_PROTOCOL *mUsb3PciIo =3D NULL; =20 /** @@ -184,14 +186,18 @@ Usb3MapDmaBuffers ( VOID EFIAPI Usb3DxeSmmReadyToLockNotify ( - IN EFI_EVENT Event, - IN VOID *Context + IN EFI_EVENT Event, + IN VOID *Context ) { - ASSERT (mUsb3Instance !=3D NULL); + USB3_DEBUG_PORT_HANDLE *Instance; =20 DEBUG ((DEBUG_INFO, "%a()\n", __FUNCTION__)); - mUsb3Instance->InNotify =3D TRUE; + + Instance =3D GetUsb3DebugPortInstance (); + ASSERT (Instance !=3D NULL); + + Instance->InNotify =3D TRUE; =20 // // For the case that the USB3 debug port instance and DMA buffers are @@ -199,14 +205,14 @@ Usb3DxeSmmReadyToLockNotify ( // Reinitialize USB3 debug port with granted DXE DMA buffer accessible // by SMM environment. // - InitializeUsbDebugHardware (mUsb3Instance); + InitializeUsbDebugHardware (Instance); =20 // // Wait some time for host to be ready after re-initialization. // MicroSecondDelay (1000000); =20 - mUsb3Instance->InNotify =3D FALSE; + Instance->InNotify =3D FALSE; gBS->CloseEvent (Event); } =20 @@ -262,6 +268,8 @@ Usb3PciIoNotify ( UINTN PciDeviceNumber; UINTN PciFunctionNumber; UINT32 PciAddress; + USB3_DEBUG_PORT_HANDLE *Instance; + EFI_EVENT SmmReadyToLockEvent; =20 Status =3D gBS->LocateHandleBuffer ( ByProtocol, @@ -287,24 +295,27 @@ Usb3PciIoNotify ( // // Found the PciIo for USB3 debug port. // - ASSERT (mUsb3Instance !=3D NULL); DEBUG ((DEBUG_INFO, "%a()\n", __FUNCTION__)); if (Usb3GetIoMmu !=3D NULL) { - mUsb3Instance->InNotify =3D TRUE; - Usb3MapDmaBuffers (mUsb3Instance, PciIo); - mUsb3Instance->InNotify =3D FALSE; - - if (mUsb3Instance->FromHob) { - mUsb3PciIo =3D PciIo; - Usb3NamedEventListen ( - &gEfiDxeSmmReadyToLockProtocolGuid, - TPL_NOTIFY, - Usb3DxeSmmReadyToLockNotify, - &Event - ); + Instance =3D GetUsb3DebugPortInstance (); + ASSERT (Instance !=3D NULL); + if (Instance->Ready) { + Instance->InNotify =3D TRUE; + Usb3MapDmaBuffers (Instance, PciIo); + Instance->InNotify =3D FALSE; + + if (Instance->FromHob) { + mUsb3PciIo =3D PciIo; + Usb3NamedEventListen ( + &gEfiDxeSmmReadyToLockProtocolGuid, + TPL_NOTIFY, + Usb3DxeSmmReadyToLockNotify, + &SmmReadyToLockEvent + ); + } } } - gBS->CloseEvent ((EFI_EVENT) (UINTN) mUsb3Instance->PciIoEvent); + gBS->CloseEvent (Event); break; } } @@ -314,34 +325,22 @@ Usb3PciIoNotify ( } =20 /** - Return USB3 debug instance address. + Return USB3 debug instance address pointer. =20 **/ =20 -USB3_DEBUG_PORT_HANDLE * -GetUsb3DebugPortInstance ( +EFI_PHYSICAL_ADDRESS * +GetUsb3DebugPortInstanceAddrPtr ( VOID ) { - USB3_DEBUG_PORT_HANDLE *Instance; - EFI_PEI_HOB_POINTERS Hob; - - Instance =3D NULL; - - if (mUsb3Instance !=3D NULL) { - Instance =3D mUsb3Instance; - goto Done; - } - - Hob.Raw =3D GetFirstGuidHob (&gUsb3DbgGuid); - if (Hob.Raw !=3D NULL) { - Instance =3D GET_GUID_HOB_DATA (Hob.Guid); - } - -Done: - if ((Instance !=3D NULL) && (!Instance->InNotify)) { - DiscoverInitializeUsbDebugPort (Instance); + if (mUsb3InstanceAddrPtr =3D=3D NULL) { + // + // Use the local variables temporarily. + // + mUsb3InstanceAddr =3D (EFI_PHYSICAL_ADDRESS) (UINTN) &mUsb3Instance; + mUsb3InstanceAddrPtr =3D &mUsb3InstanceAddr; } - return Instance; + return mUsb3InstanceAddrPtr; } =20 /** @@ -447,59 +446,50 @@ DebugCommunicationUsb3DxeConstructor ( IN EFI_SYSTEM_TABLE *SystemTable ) { - USB3_DEBUG_PORT_HANDLE UsbDbg; + EFI_PHYSICAL_ADDRESS *AddrPtr; USB3_DEBUG_PORT_HANDLE *Instance; EFI_PHYSICAL_ADDRESS Address; EFI_STATUS Status; EFI_EVENT Event; =20 - Instance =3D GetUsb3DebugPortInstance (); - - Status =3D EfiGetSystemConfigurationTable (&gUsb3DbgGuid, (VOID **) &mUs= b3Instance); - if (!EFI_ERROR (Status)) { - goto Done; - } - - if (Instance =3D=3D NULL) { + Status =3D EfiGetSystemConfigurationTable (&gUsb3DbgGuid, (VOID **) &Add= rPtr); + if (EFI_ERROR (Status)) { // - // Initialize USB debug + // Instead of using local variables, install system configuration tabl= e for + // the local instance and the buffer to save instance address pointer. // - ZeroMem (&UsbDbg, sizeof (UsbDbg)); - UsbDbg.Initialized =3D USB3DBG_UNINITIALIZED; + Address =3D SIZE_4GB; + Status =3D gBS->AllocatePages ( + AllocateMaxAddress, + EfiACPIMemoryNVS, + EFI_SIZE_TO_PAGES (sizeof (EFI_PHYSICAL_ADDRESS) + siz= eof (USB3_DEBUG_PORT_HANDLE)), + &Address + ); + if (EFI_ERROR (Status)) { + return Status; + } =20 - DiscoverInitializeUsbDebugPort (&UsbDbg); + AddrPtr =3D (EFI_PHYSICAL_ADDRESS *) (UINTN) Address; + ZeroMem (AddrPtr, sizeof (EFI_PHYSICAL_ADDRESS) + sizeof (USB3_DEBUG_P= ORT_HANDLE)); + Instance =3D (USB3_DEBUG_PORT_HANDLE *) (AddrPtr + 1); + CopyMem (Instance, &mUsb3Instance, sizeof (USB3_DEBUG_PORT_HANDLE)); + *AddrPtr =3D (EFI_PHYSICAL_ADDRESS) (UINTN) Instance; =20 - Instance =3D &UsbDbg; + Status =3D gBS->InstallConfigurationTable (&gUsb3DbgGuid, AddrPtr); + if (EFI_ERROR (Status)) { + return Status; + } } =20 - // - // It is first time to run DXE instance, copy Instance from Hob to ACPIN= vs. - // - Address =3D SIZE_4GB; - Status =3D gBS->AllocatePages ( - AllocateMaxAddress, - EfiACPIMemoryNVS, - EFI_SIZE_TO_PAGES (sizeof (USB3_DEBUG_PORT_HANDLE)), - &Address - ); - if (EFI_ERROR (Status)) { - return Status; + if (mUsb3InstanceAddrPtr !=3D NULL) { + *AddrPtr =3D *mUsb3InstanceAddrPtr; } + mUsb3InstanceAddrPtr =3D AddrPtr; =20 - CopyMem ( - (VOID *)(UINTN)Address, - Instance, - sizeof (USB3_DEBUG_PORT_HANDLE) - ); - mUsb3Instance =3D (USB3_DEBUG_PORT_HANDLE *)(UINTN)Address; - - Status =3D gBS->InstallConfigurationTable (&gUsb3DbgGuid, mUsb3Instance); - if (EFI_ERROR (Status)) { - return Status; - } + Instance =3D GetUsb3DebugPortInstance (); + ASSERT (Instance !=3D NULL); =20 -Done: - if ((mUsb3Instance !=3D NULL) && mUsb3Instance->Ready && (mUsb3Instance-= >PciIoEvent =3D=3D 0)) { + if (Instance->PciIoEvent =3D=3D 0) { Status =3D Usb3NamedEventListen ( &gEfiPciIoProtocolGuid, TPL_NOTIFY, @@ -507,7 +497,7 @@ Done: &Event ); if (!EFI_ERROR (Status)) { - mUsb3Instance->PciIoEvent =3D (EFI_PHYSICAL_ADDRESS) (UINTN) Event; + Instance->PciIoEvent =3D (EFI_PHYSICAL_ADDRESS) (UINTN) Event; } } =20 @@ -530,12 +520,17 @@ DebugCommunicationUsb3DxeDestructor ( IN EFI_SYSTEM_TABLE *SystemTable ) { - if ((mUsb3Instance !=3D NULL) && (mUsb3Instance->PciIoEvent !=3D 0)) { + USB3_DEBUG_PORT_HANDLE *Instance; + + Instance =3D GetUsb3DebugPortInstance (); + ASSERT (Instance !=3D NULL); + + if (Instance->PciIoEvent !=3D 0) { // // Close the event created. // - gBS->CloseEvent ((EFI_EVENT) (UINTN) mUsb3Instance->PciIoEvent); - mUsb3Instance->PciIoEvent =3D 0; + gBS->CloseEvent ((EFI_EVENT) (UINTN) Instance->PciIoEvent); + Instance->PciIoEvent =3D 0; } return EFI_SUCCESS; } diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCom= municationLibUsb3Dxe.inf b/SourceLevelDebugPkg/Library/DebugCommunicationLi= bUsb3/DebugCommunicationLibUsb3Dxe.inf index 9f737b9478a8..683d9572e9f7 100644 --- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Dxe.inf +++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Dxe.inf @@ -56,7 +56,7 @@ [Pcd] =20 # The value of data buffer size used for USB debug port handle. # It should be equal to sizeof (USB3_DEBUG_PORT_HANDLE). - gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugPortHandleBufferSize|250 = ## SOMETIMES_CONSUMES + gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugPortHandleBufferSize|249 = ## SOMETIMES_CONSUMES =20 [Protocols] ## NOTIFY diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCom= municationLibUsb3Internal.h b/SourceLevelDebugPkg/Library/DebugCommunicatio= nLibUsb3/DebugCommunicationLibUsb3Internal.h index 961786e2a41f..8673dad6c55e 100644 --- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Internal.h +++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Internal.h @@ -472,11 +472,6 @@ typedef struct _USB3_DEBUG_PORT_INSTANCE { BOOLEAN FromHob; =20 // - // IOMMU PPI Notify registered - // - BOOLEAN PpiNotifyRegistered; - - // // Prevent notification being interrupted by debug timer // BOOLEAN InNotify; @@ -728,14 +723,12 @@ InitializeUsbDebugHardware ( ); =20 /** - Discover and initialize usb debug port. - - @param Handle Debug port handle. + Return USB3 debug instance address pointer. =20 -**/ -VOID -DiscoverInitializeUsbDebugPort ( - IN USB3_DEBUG_PORT_HANDLE *Handle +**/ =20 +EFI_PHYSICAL_ADDRESS * +GetUsb3DebugPortInstanceAddrPtr ( + VOID ); =20 /** diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCom= municationLibUsb3Pei.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibU= sb3/DebugCommunicationLibUsb3Pei.c index 145113d28dc3..dfdbfb0b7c2e 100644 --- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Pei.c +++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Pei.c @@ -45,6 +45,9 @@ Usb3IoMmuPpiNotify ( =20 Instance =3D GetUsb3DebugPortInstance (); ASSERT (Instance !=3D NULL); + if (!Instance->Ready) { + return EFI_SUCCESS; + } =20 Instance->InNotify =3D TRUE; =20 @@ -174,49 +177,44 @@ Usb3GetIoMmu ( } =20 /** - Return USB3 debug instance address. + Return USB3 debug instance address pointer. =20 **/ =20 -USB3_DEBUG_PORT_HANDLE * -GetUsb3DebugPortInstance ( +EFI_PHYSICAL_ADDRESS * +GetUsb3DebugPortInstanceAddrPtr ( VOID ) { USB3_DEBUG_PORT_HANDLE *Instance; + EFI_PHYSICAL_ADDRESS *AddrPtr; EFI_PEI_HOB_POINTERS Hob; EFI_STATUS Status; =20 Hob.Raw =3D GetFirstGuidHob (&gUsb3DbgGuid); if (Hob.Raw =3D=3D NULL) { // - // Save Instance into HOB + // Build HOB for the local instance and the buffer to save instance ad= dress pointer. + // Use the local instance in HOB temporarily. // - Instance =3D BuildGuidHob ( - &gUsb3DbgGuid, - sizeof (USB3_DEBUG_PORT_HANDLE) - ); - ASSERT (Instance !=3D NULL); - ZeroMem (Instance, sizeof (USB3_DEBUG_PORT_HANDLE)); - + AddrPtr =3D BuildGuidHob ( + &gUsb3DbgGuid, + sizeof (EFI_PHYSICAL_ADDRESS) + sizeof (USB3_DEBUG_PORT_HA= NDLE) + ); + ASSERT (AddrPtr !=3D NULL); + ZeroMem (AddrPtr, sizeof (EFI_PHYSICAL_ADDRESS) + sizeof (USB3_DEBUG_P= ORT_HANDLE)); + Instance =3D (USB3_DEBUG_PORT_HANDLE *) (AddrPtr + 1); + *AddrPtr =3D (EFI_PHYSICAL_ADDRESS) (UINTN) Instance; Instance->FromHob =3D TRUE; Instance->Initialized =3D USB3DBG_UNINITIALIZED; + if (Usb3GetIoMmu () =3D=3D NULL) { + Status =3D PeiServicesNotifyPpi (&mUsb3IoMmuPpiNotifyDesc); + ASSERT_EFI_ERROR (Status); + } } else { - Instance =3D GET_GUID_HOB_DATA (Hob.Guid); - } - - if (!Instance->InNotify) { - DiscoverInitializeUsbDebugPort (Instance); - } - - if (Instance->Ready && - !Instance->PpiNotifyRegistered && - (Usb3GetIoMmu () =3D=3D NULL)) { - Status =3D PeiServicesNotifyPpi (&mUsb3IoMmuPpiNotifyDesc); - ASSERT_EFI_ERROR (Status); - Instance->PpiNotifyRegistered =3D TRUE; + AddrPtr =3D GET_GUID_HOB_DATA (Hob.Guid); } =20 - return Instance; + return AddrPtr; } =20 /** diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCom= municationLibUsb3Pei.inf b/SourceLevelDebugPkg/Library/DebugCommunicationLi= bUsb3/DebugCommunicationLibUsb3Pei.inf index 4f367622d826..12257bce7da7 100644 --- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Pei.inf +++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicat= ionLibUsb3Pei.inf @@ -58,7 +58,7 @@ [Pcd] =20 # The value of data buffer size used for USB debug port handle. # It should be equal to sizeof (USB3_DEBUG_PORT_HANDLE). - gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugPortHandleBufferSize|250 = ## SOMETIMES_CONSUMES + gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugPortHandleBufferSize|249 = ## SOMETIMES_CONSUMES =20 [LibraryClasses] BaseLib --=20 2.13.3.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel