public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Star Zeng <star.zeng@intel.com>
To: edk2-devel@lists.01.org
Cc: Star Zeng <star.zeng@intel.com>,
	Jiewen Yao <jiewen.yao@intel.com>, Ruiyu Ni <ruiyu.ni@intel.com>,
	Hao Wu <hao.a.wu@intel.com>
Subject: [PATCH 3/3] SourceLevelDebugPkg DebugCommUsb3: Use the Handle from DebugAgentLib
Date: Sun, 11 Mar 2018 23:16:19 +0800	[thread overview]
Message-ID: <20180311151619.1260-4-star.zeng@intel.com> (raw)
In-Reply-To: <20180311151619.1260-1-star.zeng@intel.com>

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 <jiewen.yao@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
---
 .../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/DebugCommunicationLibUsb3Common.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c
index e67ff1fe5ca7..740d9f98b41d 100644
--- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c
+++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c
@@ -811,6 +811,42 @@ DiscoverInitializeUsbDebugPort (
 }
 
 /**
+  Set USB3 debug instance address.
+
+**/  
+VOID
+SetUsb3DebugPortInstance (
+  IN USB3_DEBUG_PORT_HANDLE     *Instance
+  )
+{
+  EFI_PHYSICAL_ADDRESS          *AddrPtr;
+
+  AddrPtr = GetUsb3DebugPortInstanceAddrPtr ();
+  ASSERT (AddrPtr != NULL);
+  *AddrPtr = (EFI_PHYSICAL_ADDRESS) (UINTN) Instance;
+}
+
+/**
+  Return USB3 debug instance address.
+
+**/  
+USB3_DEBUG_PORT_HANDLE *
+GetUsb3DebugPortInstance (
+  VOID
+  )
+{
+  EFI_PHYSICAL_ADDRESS          *AddrPtr;
+  USB3_DEBUG_PORT_HANDLE        *Instance;
+
+  AddrPtr = GetUsb3DebugPortInstanceAddrPtr ();
+  ASSERT (AddrPtr != NULL);
+
+  Instance = (USB3_DEBUG_PORT_HANDLE *) (UINTN) *AddrPtr;
+
+  return Instance;
+}
+
+/**
   Read data from debug device and save the data in buffer.
 
   Reads NumberOfBytes data bytes from a debug device into the buffer
@@ -844,16 +880,23 @@ DebugPortReadBuffer (
     return 0;
   }
 
-  UsbDebugPortHandle = GetUsb3DebugPortInstance ();
+  if (Handle != NULL) {
+    UsbDebugPortHandle = (USB3_DEBUG_PORT_HANDLE *) Handle;
+    SetUsb3DebugPortInstance (UsbDebugPortHandle);
+  } else {
+    UsbDebugPortHandle = GetUsb3DebugPortInstance ();
+  }
   if (UsbDebugPortHandle == NULL) {
     return 0;
   }
 
-  if (UsbDebugPortHandle->Initialized != USB3DBG_ENABLED) {
+  if (UsbDebugPortHandle->InNotify) {
     return 0;
   }
 
-  if (UsbDebugPortHandle->InNotify) {
+  DiscoverInitializeUsbDebugPort (UsbDebugPortHandle);
+
+  if (UsbDebugPortHandle->Initialized != USB3DBG_ENABLED) {
     return 0;
   }
 
@@ -914,16 +957,23 @@ DebugPortWriteBuffer (
   Sent  = 0;
   Total = 0;
 
-  UsbDebugPortHandle = GetUsb3DebugPortInstance ();
+  if (Handle != NULL) {
+    UsbDebugPortHandle = (USB3_DEBUG_PORT_HANDLE *) Handle;
+    SetUsb3DebugPortInstance (UsbDebugPortHandle);
+  } else {
+    UsbDebugPortHandle = GetUsb3DebugPortInstance ();
+  }
   if (UsbDebugPortHandle == NULL) {
     return 0;
   }
 
-  if (UsbDebugPortHandle->Initialized != USB3DBG_ENABLED) {
+  if (UsbDebugPortHandle->InNotify) {
     return 0;
   }
 
-  if (UsbDebugPortHandle->InNotify) {
+  DiscoverInitializeUsbDebugPort (UsbDebugPortHandle);
+
+  if (UsbDebugPortHandle->Initialized != USB3DBG_ENABLED) {
     return 0;
   }
 
@@ -968,16 +1018,23 @@ DebugPortPollBuffer (
   USB3_DEBUG_PORT_HANDLE     *UsbDebugPortHandle;
   UINTN                     Length;
 
-  UsbDebugPortHandle = GetUsb3DebugPortInstance ();
+  if (Handle != NULL) {
+    UsbDebugPortHandle = (USB3_DEBUG_PORT_HANDLE *) Handle;
+    SetUsb3DebugPortInstance (UsbDebugPortHandle);
+  } else {
+    UsbDebugPortHandle = GetUsb3DebugPortInstance ();
+  }
   if (UsbDebugPortHandle == NULL) {
     return FALSE;
   }
 
-  if (UsbDebugPortHandle->Initialized != USB3DBG_ENABLED) {
+  if (UsbDebugPortHandle->InNotify) {
     return FALSE;
   }
 
-  if (UsbDebugPortHandle->InNotify) {
+  DiscoverInitializeUsbDebugPort (UsbDebugPortHandle);
+
+  if (UsbDebugPortHandle->Initialized != USB3DBG_ENABLED) {
     return FALSE;
   }
 
@@ -1043,11 +1100,22 @@ DebugPortInitialize (
 {
   USB3_DEBUG_PORT_HANDLE    *UsbDebugPortHandle;
 
+  //
+  // Validate the PCD PcdDebugPortHandleBufferSize value 
+  //
+  ASSERT (PcdGet16 (PcdDebugPortHandleBufferSize) == sizeof (USB3_DEBUG_PORT_HANDLE));
+
+  if (Function == NULL && Context != NULL) {
+    SetUsb3DebugPortInstance ((USB3_DEBUG_PORT_HANDLE *) Context);
+    return (DEBUG_PORT_HANDLE) Context;
+  }
   UsbDebugPortHandle = GetUsb3DebugPortInstance ();
   if (UsbDebugPortHandle == NULL) {
     return NULL;
   }
 
+  DiscoverInitializeUsbDebugPort (UsbDebugPortHandle);
+
   if (Function != NULL) {
     Function (Context, (DEBUG_PORT_HANDLE) UsbDebugPortHandle);
   }
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Dxe.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Dxe.c
index 588c9715bd00..d2f3c56704eb 100644
--- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Dxe.c
+++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Dxe.c
@@ -23,7 +23,9 @@
 
 GUID                        gUsb3DbgGuid =  USB3_DBG_GUID;
 
-USB3_DEBUG_PORT_HANDLE      *mUsb3Instance = NULL;
+USB3_DEBUG_PORT_HANDLE      mUsb3Instance = {USB3DBG_UNINITIALIZED};
+EFI_PHYSICAL_ADDRESS        mUsb3InstanceAddr = 0;
+EFI_PHYSICAL_ADDRESS        *mUsb3InstanceAddrPtr = NULL;
 EFI_PCI_IO_PROTOCOL         *mUsb3PciIo = NULL;
 
 /**
@@ -184,14 +186,18 @@ Usb3MapDmaBuffers (
 VOID
 EFIAPI
 Usb3DxeSmmReadyToLockNotify (
-  IN  EFI_EVENT                 Event,
-  IN  VOID                      *Context
+  IN EFI_EVENT                  Event,
+  IN VOID                       *Context
   )
 {
-  ASSERT (mUsb3Instance != NULL);
+  USB3_DEBUG_PORT_HANDLE        *Instance;
 
   DEBUG ((DEBUG_INFO, "%a()\n", __FUNCTION__));
-  mUsb3Instance->InNotify = TRUE;
+
+  Instance = GetUsb3DebugPortInstance ();
+  ASSERT (Instance != NULL);
+
+  Instance->InNotify = TRUE;
 
   //
   // 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);
 
   //
   // Wait some time for host to be ready after re-initialization.
   //
   MicroSecondDelay (1000000);
 
-  mUsb3Instance->InNotify = FALSE;
+  Instance->InNotify = FALSE;
   gBS->CloseEvent (Event);
 }
 
@@ -262,6 +268,8 @@ Usb3PciIoNotify (
   UINTN                         PciDeviceNumber;
   UINTN                         PciFunctionNumber;
   UINT32                        PciAddress;
+  USB3_DEBUG_PORT_HANDLE        *Instance;
+  EFI_EVENT                     SmmReadyToLockEvent;
 
   Status = gBS->LocateHandleBuffer (
                   ByProtocol,
@@ -287,24 +295,27 @@ Usb3PciIoNotify (
         //
         // Found the PciIo for USB3 debug port.
         //
-        ASSERT (mUsb3Instance != NULL);
         DEBUG ((DEBUG_INFO, "%a()\n", __FUNCTION__));
         if (Usb3GetIoMmu != NULL) {
-          mUsb3Instance->InNotify = TRUE;
-          Usb3MapDmaBuffers (mUsb3Instance, PciIo);
-          mUsb3Instance->InNotify = FALSE;
-
-          if (mUsb3Instance->FromHob) {
-            mUsb3PciIo = PciIo;
-            Usb3NamedEventListen (
-              &gEfiDxeSmmReadyToLockProtocolGuid,
-              TPL_NOTIFY,
-              Usb3DxeSmmReadyToLockNotify,
-              &Event
-              );
+          Instance = GetUsb3DebugPortInstance ();
+          ASSERT (Instance != NULL);
+          if (Instance->Ready) {
+            Instance->InNotify = TRUE;
+            Usb3MapDmaBuffers (Instance, PciIo);
+            Instance->InNotify = FALSE;
+
+            if (Instance->FromHob) {
+              mUsb3PciIo = PciIo;
+              Usb3NamedEventListen (
+                &gEfiDxeSmmReadyToLockProtocolGuid,
+                TPL_NOTIFY,
+                Usb3DxeSmmReadyToLockNotify,
+                &SmmReadyToLockEvent
+                );
+            }
           }
         }
-        gBS->CloseEvent ((EFI_EVENT) (UINTN) mUsb3Instance->PciIoEvent);
+        gBS->CloseEvent (Event);
         break;
       }
     }
@@ -314,34 +325,22 @@ Usb3PciIoNotify (
 }
 
 /**
-  Return USB3 debug instance address.
+  Return USB3 debug instance address pointer.
 
 **/  
-USB3_DEBUG_PORT_HANDLE *
-GetUsb3DebugPortInstance (
+EFI_PHYSICAL_ADDRESS *
+GetUsb3DebugPortInstanceAddrPtr (
   VOID
   )
 {
-  USB3_DEBUG_PORT_HANDLE          *Instance;
-  EFI_PEI_HOB_POINTERS            Hob;
-
-  Instance = NULL;
-
-  if (mUsb3Instance != NULL) {
-    Instance = mUsb3Instance;
-    goto Done;
-  }
-
-  Hob.Raw = GetFirstGuidHob (&gUsb3DbgGuid);
-  if (Hob.Raw != NULL) {
-    Instance = GET_GUID_HOB_DATA (Hob.Guid);
-  }
-
-Done:
-  if ((Instance != NULL) && (!Instance->InNotify)) {
-    DiscoverInitializeUsbDebugPort (Instance);
+  if (mUsb3InstanceAddrPtr == NULL) {
+    //
+    // Use the local variables temporarily.
+    //
+    mUsb3InstanceAddr = (EFI_PHYSICAL_ADDRESS) (UINTN) &mUsb3Instance;
+    mUsb3InstanceAddrPtr = &mUsb3InstanceAddr;
   }
-  return Instance;
+  return mUsb3InstanceAddrPtr;
 }
 
 /**
@@ -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;
 
-  Instance = GetUsb3DebugPortInstance ();
-
-  Status = EfiGetSystemConfigurationTable (&gUsb3DbgGuid, (VOID **) &mUsb3Instance);
-  if (!EFI_ERROR (Status)) {
-    goto Done;
-  }
-
-  if (Instance == NULL) {
+  Status = EfiGetSystemConfigurationTable (&gUsb3DbgGuid, (VOID **) &AddrPtr);
+  if (EFI_ERROR (Status)) {
     //
-    // Initialize USB debug
+    // Instead of using local variables, install system configuration table for
+    // the local instance and the buffer to save instance address pointer.
     //
-    ZeroMem (&UsbDbg, sizeof (UsbDbg));
-    UsbDbg.Initialized = USB3DBG_UNINITIALIZED;
+    Address = SIZE_4GB;
+    Status = gBS->AllocatePages (
+                    AllocateMaxAddress,
+                    EfiACPIMemoryNVS,
+                    EFI_SIZE_TO_PAGES (sizeof (EFI_PHYSICAL_ADDRESS) + sizeof (USB3_DEBUG_PORT_HANDLE)),
+                    &Address
+                    );
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
 
-    DiscoverInitializeUsbDebugPort (&UsbDbg);
+    AddrPtr = (EFI_PHYSICAL_ADDRESS *) (UINTN) Address;
+    ZeroMem (AddrPtr, sizeof (EFI_PHYSICAL_ADDRESS) + sizeof (USB3_DEBUG_PORT_HANDLE));
+    Instance = (USB3_DEBUG_PORT_HANDLE *) (AddrPtr + 1);
+    CopyMem (Instance, &mUsb3Instance, sizeof (USB3_DEBUG_PORT_HANDLE));
+    *AddrPtr = (EFI_PHYSICAL_ADDRESS) (UINTN) Instance;
 
-    Instance = &UsbDbg;
+    Status = gBS->InstallConfigurationTable (&gUsb3DbgGuid, AddrPtr);
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
   }
 
-  //
-  // It is first time to run DXE instance, copy Instance from Hob to ACPINvs.
-  //
-  Address = SIZE_4GB;
-  Status = gBS->AllocatePages (
-                  AllocateMaxAddress,
-                  EfiACPIMemoryNVS,
-                  EFI_SIZE_TO_PAGES (sizeof (USB3_DEBUG_PORT_HANDLE)),
-                  &Address
-                  );
-  if (EFI_ERROR (Status)) {
-    return Status;
+  if (mUsb3InstanceAddrPtr != NULL) {
+    *AddrPtr = *mUsb3InstanceAddrPtr;
   }
+  mUsb3InstanceAddrPtr = AddrPtr;
 
-  CopyMem (
-    (VOID *)(UINTN)Address,
-    Instance,
-    sizeof (USB3_DEBUG_PORT_HANDLE)
-    );
-  mUsb3Instance = (USB3_DEBUG_PORT_HANDLE *)(UINTN)Address;
-
-  Status = gBS->InstallConfigurationTable (&gUsb3DbgGuid, mUsb3Instance);
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
+  Instance = GetUsb3DebugPortInstance ();
+  ASSERT (Instance != NULL);
 
-Done:
-  if ((mUsb3Instance != NULL) && mUsb3Instance->Ready && (mUsb3Instance->PciIoEvent == 0)) {
+  if (Instance->PciIoEvent == 0) {
     Status = Usb3NamedEventListen (
                &gEfiPciIoProtocolGuid,
                TPL_NOTIFY,
@@ -507,7 +497,7 @@ Done:
                &Event
                );
     if (!EFI_ERROR (Status)) {
-      mUsb3Instance->PciIoEvent = (EFI_PHYSICAL_ADDRESS) (UINTN) Event;
+      Instance->PciIoEvent = (EFI_PHYSICAL_ADDRESS) (UINTN) Event;
     }
   }
 
@@ -530,12 +520,17 @@ DebugCommunicationUsb3DxeDestructor (
   IN EFI_SYSTEM_TABLE  *SystemTable
   )
 {
-  if ((mUsb3Instance != NULL) && (mUsb3Instance->PciIoEvent != 0)) {
+  USB3_DEBUG_PORT_HANDLE        *Instance;
+
+  Instance = GetUsb3DebugPortInstance ();
+  ASSERT (Instance != NULL);
+
+  if (Instance->PciIoEvent != 0) {
     //
     // Close the event created.
     //
-    gBS->CloseEvent ((EFI_EVENT) (UINTN) mUsb3Instance->PciIoEvent);
-    mUsb3Instance->PciIoEvent = 0;
+    gBS->CloseEvent ((EFI_EVENT) (UINTN) Instance->PciIoEvent);
+    Instance->PciIoEvent = 0;
   }
   return EFI_SUCCESS;
 }
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Dxe.inf b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Dxe.inf
index 9f737b9478a8..683d9572e9f7 100644
--- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Dxe.inf
+++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Dxe.inf
@@ -56,7 +56,7 @@ [Pcd]
 
   # 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
 
 [Protocols]
    ## NOTIFY
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Internal.h b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Internal.h
index 961786e2a41f..8673dad6c55e 100644
--- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Internal.h
+++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Internal.h
@@ -472,11 +472,6 @@ typedef struct _USB3_DEBUG_PORT_INSTANCE {
   BOOLEAN                                 FromHob;
 
   //
-  // IOMMU PPI Notify registered
-  //
-  BOOLEAN                                 PpiNotifyRegistered;
-
-  //
   // Prevent notification being interrupted by debug timer
   //
   BOOLEAN                                 InNotify;
@@ -728,14 +723,12 @@ InitializeUsbDebugHardware (
   );
 
 /**
-  Discover and initialize usb debug port.
-
-  @param Handle                  Debug port handle.
+  Return USB3 debug instance address pointer.
 
-**/
-VOID
-DiscoverInitializeUsbDebugPort (
-  IN USB3_DEBUG_PORT_HANDLE     *Handle
+**/  
+EFI_PHYSICAL_ADDRESS *
+GetUsb3DebugPortInstanceAddrPtr (
+  VOID
   );
 
 /**
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.c
index 145113d28dc3..dfdbfb0b7c2e 100644
--- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.c
+++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.c
@@ -45,6 +45,9 @@ Usb3IoMmuPpiNotify (
 
   Instance = GetUsb3DebugPortInstance ();
   ASSERT (Instance != NULL);
+  if (!Instance->Ready) {
+    return EFI_SUCCESS;
+  }
 
   Instance->InNotify = TRUE;
 
@@ -174,49 +177,44 @@ Usb3GetIoMmu (
 }
 
 /**
-  Return USB3 debug instance address.
+  Return USB3 debug instance address pointer.
 
 **/  
-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;
 
   Hob.Raw = GetFirstGuidHob (&gUsb3DbgGuid);
   if (Hob.Raw == NULL) {
     //
-    // Save Instance into HOB
+    // Build HOB for the local instance and the buffer to save instance address pointer.
+    // Use the local instance in HOB temporarily.
     //
-    Instance = BuildGuidHob (
-                 &gUsb3DbgGuid,
-                 sizeof (USB3_DEBUG_PORT_HANDLE)
-                 );
-    ASSERT (Instance != NULL);
-    ZeroMem (Instance, sizeof (USB3_DEBUG_PORT_HANDLE));
-
+    AddrPtr = BuildGuidHob (
+                &gUsb3DbgGuid,
+                sizeof (EFI_PHYSICAL_ADDRESS) + sizeof (USB3_DEBUG_PORT_HANDLE)
+                );
+    ASSERT (AddrPtr != NULL);
+    ZeroMem (AddrPtr, sizeof (EFI_PHYSICAL_ADDRESS) + sizeof (USB3_DEBUG_PORT_HANDLE));
+    Instance = (USB3_DEBUG_PORT_HANDLE *) (AddrPtr + 1);
+    *AddrPtr = (EFI_PHYSICAL_ADDRESS) (UINTN) Instance;
     Instance->FromHob = TRUE;
     Instance->Initialized = USB3DBG_UNINITIALIZED;
+    if (Usb3GetIoMmu () == NULL) {
+      Status = PeiServicesNotifyPpi (&mUsb3IoMmuPpiNotifyDesc);
+      ASSERT_EFI_ERROR (Status);
+    }
   } else {
-    Instance = GET_GUID_HOB_DATA (Hob.Guid);
-  }
-
-  if (!Instance->InNotify) {
-    DiscoverInitializeUsbDebugPort (Instance);
-  }
-
-  if (Instance->Ready &&
-      !Instance->PpiNotifyRegistered &&
-      (Usb3GetIoMmu () == NULL)) {
-    Status = PeiServicesNotifyPpi (&mUsb3IoMmuPpiNotifyDesc);
-    ASSERT_EFI_ERROR (Status);
-    Instance->PpiNotifyRegistered = TRUE;
+    AddrPtr = GET_GUID_HOB_DATA (Hob.Guid);
   }
 
-  return Instance;
+  return AddrPtr;
 }
 
 /**
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.inf b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.inf
index 4f367622d826..12257bce7da7 100644
--- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.inf
+++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.inf
@@ -58,7 +58,7 @@ [Pcd]
 
   # 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
 
 [LibraryClasses]
   BaseLib
-- 
2.13.3.windows.1



  parent reply	other threads:[~2018-03-11 15:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-11 15:16 [PATCH 0/3] SouceLevelDebugPkg DebugCommUsb3: Enhancements after supporting IOMMU Star Zeng
2018-03-11 15:16 ` [PATCH 1/3] SourceLevelDebugPkg DebugCommUsb3: Refine some formats Star Zeng
2018-03-11 15:16 ` [PATCH 2/3] SourceLevelDebugPkg DebugCommUsb3: Realloc granted DXE DMA buffer Star Zeng
2018-03-11 15:16 ` Star Zeng [this message]
2018-03-12  2:09 ` [PATCH 0/3] SouceLevelDebugPkg DebugCommUsb3: Enhancements after supporting IOMMU Wu, Hao A
2018-03-12  2:28   ` Zeng, Star
2018-03-12  3:37     ` Zeng, Star
2018-03-13 12:56       ` Wu, Hao A
2018-03-13 12:58         ` Zeng, Star

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180311151619.1260-4-star.zeng@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox