[edk2-platforms][PATCH v1 1/1] KabylakeOpenBoardPkg/PeiSerialPortLibSpiFlash: Remove PPI from HOB


Michael Kubacki
 

From: Michael Kubacki <michael.kubacki@microsoft.com>

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3486

The PPI pointer should not be cached in a HOB as it could get out
of sync with the current pointers in the PPI list.

Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Benjamin Doron <benjamin.doron00@gmail.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
---
Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFlash/Pei=
SerialPortLibSpiFlash.c | 114 +++++++++-----------
1 file changed, 48 insertions(+), 66 deletions(-)

diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLib=
SpiFlash/PeiSerialPortLibSpiFlash.c b/Platform/Intel/KabylakeOpenBoardPkg=
/Library/PeiSerialPortLibSpiFlash/PeiSerialPortLibSpiFlash.c
index 0230149a38c4..fc48bdc6fccb 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFlas=
h/PeiSerialPortLibSpiFlash.c
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFlas=
h/PeiSerialPortLibSpiFlash.c
@@ -2,6 +2,7 @@
Serial I/O Port library implementation for output to SPI flash
=20
Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (c) Microsoft Corporation.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
=20
**/
@@ -17,40 +18,23 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/SpiLib.h>
=20
typedef struct {
- PCH_SPI_PPI *PchSpiPpi;
UINT32 CurrentWriteOffset;
} SPI_FLASH_DEBUG_CONTEXT;
=20
/**
- Update reference to the most recent PCH SPI PPI installed
+ Returns a pointer to the PCH SPI PPI.
=20
- @param PeiServices An indirect pointer to the EFI_PEI_SERVICES t=
able published by the PEI Foundation
- @param NotifyDescriptor Address of the notification descriptor data s=
tructure.
- @param Ppi Address of the PPI that was installed.
-
- @retval EFI_SUCCESS Successfully update the PCH SPI PPI reference
- @retval EFI_NOT_FOUND An error occurred locating a required interfa=
ce
- @retval EFI_NOT_SUPPORTED
+ @return Pointer to PCH_SPI_PPI If an instance of the PCH SPI PPI is=
found
+ @return NULL If an instance of the PCH SPI PPI is=
not found
=20
**/
-EFI_STATUS
-EFIAPI
-SpiPpiNotifyCallback (
- IN EFI_PEI_SERVICES **PeiServices,
- IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
- IN VOID *Ppi
+PCH_SPI_PPI *
+GetSpiPpi (
+ VOID
)
{
- EFI_STATUS Status;
- EFI_HOB_GUID_TYPE *GuidHob;
- PCH_SPI_PPI *PchSpiPpi;
- SPI_FLASH_DEBUG_CONTEXT *Context;
-
- GuidHob =3D GetFirstGuidHob (&gSpiFlashDebugHobGuid);
- if (GuidHob =3D=3D NULL) {
- return EFI_NOT_FOUND;
- }
- Context =3D GET_GUID_HOB_DATA (GuidHob);
+ EFI_STATUS Status;
+ PCH_SPI_PPI *PchSpiPpi;
=20
Status =3D PeiServicesLocatePpi (
&gPchSpiPpiGuid,
@@ -59,27 +43,17 @@ SpiPpiNotifyCallback (
(VOID **) &PchSpiPpi
);
if (EFI_ERROR (Status)) {
- return EFI_NOT_FOUND;
+ return NULL;
}
=20
- Context->PchSpiPpi =3D PchSpiPpi;
-
- return EFI_SUCCESS;
+ return PchSpiPpi;
}
=20
-EFI_PEI_NOTIFY_DESCRIPTOR mSpiPpiNotifyList[] =3D {
- {
- (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TER=
MINATE_LIST),
- &gPchSpiPpiGuid,
- SpiPpiNotifyCallback
- }
-};
-
/**
Common function to write trace data to a chosen debug interface like
UART Serial device, USB Serial device or Trace Hub device
=20
- @param Buffer Point of data buffer which need to be writed.
+ @param Buffer Point of data buffer which needs to be writte=
n.
@param NumberOfBytes Number of output bytes which are cached in Bu=
ffer.
=20
**/
@@ -93,6 +67,7 @@ SerialPortWrite (
EFI_STATUS Status;
EFI_HOB_GUID_TYPE *GuidHob;
SPI_FLASH_DEBUG_CONTEXT *Context;
+ PCH_SPI_PPI *PchSpiPpi;
UINT32 BytesWritten;
UINT32 SourceBufferOffset;
UINT32 NvMessageAreaSize;
@@ -111,18 +86,22 @@ SerialPortWrite (
return 0;
}
Context =3D GET_GUID_HOB_DATA (GuidHob);
- if (Context =3D=3D NULL || Context->PchSpiPpi =3D=3D NULL || Context->=
CurrentWriteOffset >=3D NvMessageAreaSize) {
+ if (Context =3D=3D NULL || Context->CurrentWriteOffset >=3D NvMessageA=
reaSize) {
+ return 0;
+ }
+ PchSpiPpi =3D GetSpiPpi ();
+ if (PchSpiPpi =3D=3D NULL) {
return 0;
}
=20
if ((Context->CurrentWriteOffset + NumberOfBytes) / NvMessageAreaSize =
0) {
LinearOffset =3D (UINT32) (FixedPcdGet32 (PcdFlashNvDebugMessageBase=
) - FixedPcdGet32 (PcdFlashAreaBaseAddress));
- Status =3D Context->PchSpiPpi->FlashErase (
- Context->PchSpiPpi,
- FlashRegionBios,
- LinearOffset,
- NvMessageAreaSize
- );
+ Status =3D PchSpiPpi->FlashErase (
+ PchSpiPpi,
+ FlashRegionBios,
+ LinearOffset,
+ NvMessageAreaSize
+ );
if (!EFI_ERROR (Status)) {
Context->CurrentWriteOffset =3D 0;
} else {
@@ -137,13 +116,13 @@ SerialPortWrite (
=20
LinearOffset =3D (FixedPcdGet32 (PcdFlashNvDebugMessageBase) + Context=
->CurrentWriteOffset) - FixedPcdGet32 (PcdFlashAreaBaseAddress);
=20
- Status =3D Context->PchSpiPpi->FlashWrite (
- Context->PchSpiPpi,
- FlashRegionBios,
- LinearOffset,
- BytesWritten,
- (UINT8 *) &Buffer[SourceBufferOffset]
- );
+ Status =3D PchSpiPpi->FlashWrite (
+ PchSpiPpi,
+ FlashRegionBios,
+ LinearOffset,
+ BytesWritten,
+ (UINT8 *) &Buffer[SourceBufferOffset]
+ );
if (!EFI_ERROR (Status)) {
Context->CurrentWriteOffset +=3D BytesWritten;
return BytesWritten;
@@ -295,26 +274,29 @@ SerialPortInitialize (
)
{
EFI_STATUS Status;
+ EFI_HOB_GUID_TYPE *GuidHob;
SPI_FLASH_DEBUG_CONTEXT *Context;
=20
+ GuidHob =3D GetFirstGuidHob (&gSpiFlashDebugHobGuid);
+ if (GuidHob !=3D NULL) {
+ // Initialization only needs to occur once
+ return EFI_SUCCESS;
+ }
+
+ //
+ // Perform silicon specific initialization required to enable write to=
SPI flash.
+ //
+ Status =3D SpiServiceInit ();
+ if (EFI_ERROR (Status)) {
+ return EFI_DEVICE_ERROR;
+ }
+
Context =3D (SPI_FLASH_DEBUG_CONTEXT *) BuildGuidHob (&gSpiFlashDebugH=
obGuid, sizeof (SPI_FLASH_DEBUG_CONTEXT));
if (Context =3D=3D NULL) {
return EFI_DEVICE_ERROR;
}
+
ZeroMem ((VOID *) Context, sizeof (SPI_FLASH_DEBUG_CONTEXT));
=20
- Status =3D PeiServicesNotifyPpi (&mSpiPpiNotifyList[0]);
- if (EFI_ERROR (Status)) {
- return EFI_DEVICE_ERROR;
- }
-
- //
- // Perform silicon specific initialization required to enable write to=
SPI flash.
- //
- Status =3D SpiServiceInit ();
- if (EFI_ERROR (Status)) {
- Status =3D EFI_DEVICE_ERROR;
- }
-
- return Status;
+ return EFI_SUCCESS;
}
--=20
2.28.0.windows.1

Join devel@edk2.groups.io to automatically receive all group messages.