* [edk2-platforms][PATCH v1 1/1] KabylakeOpenBoardPkg/PeiSerialPortLibSpiFlash: Remove PPI from HOB
@ 2021-07-09 16:08 Michael Kubacki
2021-07-29 1:41 ` Nate DeSimone
2021-07-29 1:47 ` Nate DeSimone
0 siblings, 2 replies; 3+ messages in thread
From: Michael Kubacki @ 2021-07-09 16:08 UTC (permalink / raw)
To: devel; +Cc: Chasel Chiu, Nate DeSimone, Benjamin Doron
From: Michael Kubacki <michael.kubacki@microsoft.com>
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3486
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/PeiSerialPortLibSpiFlash.c | 114 +++++++++-----------
1 file changed, 48 insertions(+), 66 deletions(-)
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFlash/PeiSerialPortLibSpiFlash.c b/Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFlash/PeiSerialPortLibSpiFlash.c
index 0230149a38c4..fc48bdc6fccb 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFlash/PeiSerialPortLibSpiFlash.c
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFlash/PeiSerialPortLibSpiFlash.c
@@ -2,6 +2,7 @@
Serial I/O Port library implementation for output to SPI flash
Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (c) Microsoft Corporation.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -17,40 +18,23 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/SpiLib.h>
typedef struct {
- PCH_SPI_PPI *PchSpiPpi;
UINT32 CurrentWriteOffset;
} SPI_FLASH_DEBUG_CONTEXT;
/**
- Update reference to the most recent PCH SPI PPI installed
+ Returns a pointer to the PCH SPI PPI.
- @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation
- @param NotifyDescriptor Address of the notification descriptor data structure.
- @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 interface
- @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
**/
-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 = GetFirstGuidHob (&gSpiFlashDebugHobGuid);
- if (GuidHob == NULL) {
- return EFI_NOT_FOUND;
- }
- Context = GET_GUID_HOB_DATA (GuidHob);
+ EFI_STATUS Status;
+ PCH_SPI_PPI *PchSpiPpi;
Status = PeiServicesLocatePpi (
&gPchSpiPpiGuid,
@@ -59,27 +43,17 @@ SpiPpiNotifyCallback (
(VOID **) &PchSpiPpi
);
if (EFI_ERROR (Status)) {
- return EFI_NOT_FOUND;
+ return NULL;
}
- Context->PchSpiPpi = PchSpiPpi;
-
- return EFI_SUCCESS;
+ return PchSpiPpi;
}
-EFI_PEI_NOTIFY_DESCRIPTOR mSpiPpiNotifyList[] = {
- {
- (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_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
- @param Buffer Point of data buffer which need to be writed.
+ @param Buffer Point of data buffer which needs to be written.
@param NumberOfBytes Number of output bytes which are cached in Buffer.
**/
@@ -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 = GET_GUID_HOB_DATA (GuidHob);
- if (Context == NULL || Context->PchSpiPpi == NULL || Context->CurrentWriteOffset >= NvMessageAreaSize) {
+ if (Context == NULL || Context->CurrentWriteOffset >= NvMessageAreaSize) {
+ return 0;
+ }
+ PchSpiPpi = GetSpiPpi ();
+ if (PchSpiPpi == NULL) {
return 0;
}
if ((Context->CurrentWriteOffset + NumberOfBytes) / NvMessageAreaSize > 0) {
LinearOffset = (UINT32) (FixedPcdGet32 (PcdFlashNvDebugMessageBase) - FixedPcdGet32 (PcdFlashAreaBaseAddress));
- Status = Context->PchSpiPpi->FlashErase (
- Context->PchSpiPpi,
- FlashRegionBios,
- LinearOffset,
- NvMessageAreaSize
- );
+ Status = PchSpiPpi->FlashErase (
+ PchSpiPpi,
+ FlashRegionBios,
+ LinearOffset,
+ NvMessageAreaSize
+ );
if (!EFI_ERROR (Status)) {
Context->CurrentWriteOffset = 0;
} else {
@@ -137,13 +116,13 @@ SerialPortWrite (
LinearOffset = (FixedPcdGet32 (PcdFlashNvDebugMessageBase) + Context->CurrentWriteOffset) - FixedPcdGet32 (PcdFlashAreaBaseAddress);
- Status = Context->PchSpiPpi->FlashWrite (
- Context->PchSpiPpi,
- FlashRegionBios,
- LinearOffset,
- BytesWritten,
- (UINT8 *) &Buffer[SourceBufferOffset]
- );
+ Status = PchSpiPpi->FlashWrite (
+ PchSpiPpi,
+ FlashRegionBios,
+ LinearOffset,
+ BytesWritten,
+ (UINT8 *) &Buffer[SourceBufferOffset]
+ );
if (!EFI_ERROR (Status)) {
Context->CurrentWriteOffset += BytesWritten;
return BytesWritten;
@@ -295,26 +274,29 @@ SerialPortInitialize (
)
{
EFI_STATUS Status;
+ EFI_HOB_GUID_TYPE *GuidHob;
SPI_FLASH_DEBUG_CONTEXT *Context;
+ GuidHob = GetFirstGuidHob (&gSpiFlashDebugHobGuid);
+ if (GuidHob != NULL) {
+ // Initialization only needs to occur once
+ return EFI_SUCCESS;
+ }
+
+ //
+ // Perform silicon specific initialization required to enable write to SPI flash.
+ //
+ Status = SpiServiceInit ();
+ if (EFI_ERROR (Status)) {
+ return EFI_DEVICE_ERROR;
+ }
+
Context = (SPI_FLASH_DEBUG_CONTEXT *) BuildGuidHob (&gSpiFlashDebugHobGuid, sizeof (SPI_FLASH_DEBUG_CONTEXT));
if (Context == NULL) {
return EFI_DEVICE_ERROR;
}
+
ZeroMem ((VOID *) Context, sizeof (SPI_FLASH_DEBUG_CONTEXT));
- Status = PeiServicesNotifyPpi (&mSpiPpiNotifyList[0]);
- if (EFI_ERROR (Status)) {
- return EFI_DEVICE_ERROR;
- }
-
- //
- // Perform silicon specific initialization required to enable write to SPI flash.
- //
- Status = SpiServiceInit ();
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- }
-
- return Status;
+ return EFI_SUCCESS;
}
--
2.28.0.windows.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [edk2-platforms][PATCH v1 1/1] KabylakeOpenBoardPkg/PeiSerialPortLibSpiFlash: Remove PPI from HOB
2021-07-09 16:08 [edk2-platforms][PATCH v1 1/1] KabylakeOpenBoardPkg/PeiSerialPortLibSpiFlash: Remove PPI from HOB Michael Kubacki
@ 2021-07-29 1:41 ` Nate DeSimone
2021-07-29 1:47 ` Nate DeSimone
1 sibling, 0 replies; 3+ messages in thread
From: Nate DeSimone @ 2021-07-29 1:41 UTC (permalink / raw)
To: mikuback@linux.microsoft.com, devel@edk2.groups.io
Cc: Chiu, Chasel, Benjamin Doron
Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
> -----Original Message-----
> From: mikuback@linux.microsoft.com <mikuback@linux.microsoft.com>
> Sent: Friday, July 9, 2021 9:08 AM
> To: devel@edk2.groups.io
> Cc: Chiu, Chasel <chasel.chiu@intel.com>; Desimone, Nathaniel L
> <nathaniel.l.desimone@intel.com>; Benjamin Doron
> <benjamin.doron00@gmail.com>
> Subject: [edk2-platforms][PATCH v1 1/1]
> KabylakeOpenBoardPkg/PeiSerialPortLibSpiFlash: Remove PPI from HOB
>
> From: Michael Kubacki <michael.kubacki@microsoft.com>
>
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3486
>
> 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/PeiS
> erialPortLibSpiFlash.c | 114 +++++++++-----------
> 1 file changed, 48 insertions(+), 66 deletions(-)
>
> diff --git
> a/Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFlash/P
> eiSerialPortLibSpiFlash.c
> b/Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFlash/P
> eiSerialPortLibSpiFlash.c
> index 0230149a38c4..fc48bdc6fccb 100644
> ---
> a/Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFlash/P
> eiSerialPortLibSpiFlash.c
> +++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFla
> +++ sh/PeiSerialPortLibSpiFlash.c
> @@ -2,6 +2,7 @@
> Serial I/O Port library implementation for output to SPI flash
>
> Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) Microsoft Corporation.<BR>
> SPDX-License-Identifier: BSD-2-Clause-Patent
>
> **/
> @@ -17,40 +18,23 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
> #include <Library/SpiLib.h>
>
> typedef struct {
> - PCH_SPI_PPI *PchSpiPpi;
> UINT32 CurrentWriteOffset;
> } SPI_FLASH_DEBUG_CONTEXT;
>
> /**
> - Update reference to the most recent PCH SPI PPI installed
> + Returns a pointer to the PCH SPI PPI.
>
> - @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table
> published by the PEI Foundation
> - @param NotifyDescriptor Address of the notification descriptor data
> structure.
> - @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 interface
> - @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
>
> **/
> -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 = GetFirstGuidHob (&gSpiFlashDebugHobGuid);
> - if (GuidHob == NULL) {
> - return EFI_NOT_FOUND;
> - }
> - Context = GET_GUID_HOB_DATA (GuidHob);
> + EFI_STATUS Status;
> + PCH_SPI_PPI *PchSpiPpi;
>
> Status = PeiServicesLocatePpi (
> &gPchSpiPpiGuid,
> @@ -59,27 +43,17 @@ SpiPpiNotifyCallback (
> (VOID **) &PchSpiPpi
> );
> if (EFI_ERROR (Status)) {
> - return EFI_NOT_FOUND;
> + return NULL;
> }
>
> - Context->PchSpiPpi = PchSpiPpi;
> -
> - return EFI_SUCCESS;
> + return PchSpiPpi;
> }
>
> -EFI_PEI_NOTIFY_DESCRIPTOR mSpiPpiNotifyList[] = {
> - {
> - (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK |
> EFI_PEI_PPI_DESCRIPTOR_TERMINATE_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
>
> - @param Buffer Point of data buffer which need to be writed.
> + @param Buffer Point of data buffer which needs to be written.
> @param NumberOfBytes Number of output bytes which are cached in
> Buffer.
>
> **/
> @@ -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 = GET_GUID_HOB_DATA (GuidHob);
> - if (Context == NULL || Context->PchSpiPpi == NULL || Context-
> >CurrentWriteOffset >= NvMessageAreaSize) {
> + if (Context == NULL || Context->CurrentWriteOffset >=
> NvMessageAreaSize) {
> + return 0;
> + }
> + PchSpiPpi = GetSpiPpi ();
> + if (PchSpiPpi == NULL) {
> return 0;
> }
>
> if ((Context->CurrentWriteOffset + NumberOfBytes) / NvMessageAreaSize
> > 0) {
> LinearOffset = (UINT32) (FixedPcdGet32 (PcdFlashNvDebugMessageBase)
> - FixedPcdGet32 (PcdFlashAreaBaseAddress));
> - Status = Context->PchSpiPpi->FlashErase (
> - Context->PchSpiPpi,
> - FlashRegionBios,
> - LinearOffset,
> - NvMessageAreaSize
> - );
> + Status = PchSpiPpi->FlashErase (
> + PchSpiPpi,
> + FlashRegionBios,
> + LinearOffset,
> + NvMessageAreaSize
> + );
> if (!EFI_ERROR (Status)) {
> Context->CurrentWriteOffset = 0;
> } else {
> @@ -137,13 +116,13 @@ SerialPortWrite (
>
> LinearOffset = (FixedPcdGet32 (PcdFlashNvDebugMessageBase) +
> Context->CurrentWriteOffset) - FixedPcdGet32 (PcdFlashAreaBaseAddress);
>
> - Status = Context->PchSpiPpi->FlashWrite (
> - Context->PchSpiPpi,
> - FlashRegionBios,
> - LinearOffset,
> - BytesWritten,
> - (UINT8 *) &Buffer[SourceBufferOffset]
> - );
> + Status = PchSpiPpi->FlashWrite (
> + PchSpiPpi,
> + FlashRegionBios,
> + LinearOffset,
> + BytesWritten,
> + (UINT8 *) &Buffer[SourceBufferOffset]
> + );
> if (!EFI_ERROR (Status)) {
> Context->CurrentWriteOffset += BytesWritten;
> return BytesWritten;
> @@ -295,26 +274,29 @@ SerialPortInitialize (
> )
> {
> EFI_STATUS Status;
> + EFI_HOB_GUID_TYPE *GuidHob;
> SPI_FLASH_DEBUG_CONTEXT *Context;
>
> + GuidHob = GetFirstGuidHob (&gSpiFlashDebugHobGuid); if (GuidHob !=
> + NULL) {
> + // Initialization only needs to occur once
> + return EFI_SUCCESS;
> + }
> +
> + //
> + // Perform silicon specific initialization required to enable write to SPI flash.
> + //
> + Status = SpiServiceInit ();
> + if (EFI_ERROR (Status)) {
> + return EFI_DEVICE_ERROR;
> + }
> +
> Context = (SPI_FLASH_DEBUG_CONTEXT *) BuildGuidHob
> (&gSpiFlashDebugHobGuid, sizeof (SPI_FLASH_DEBUG_CONTEXT));
> if (Context == NULL) {
> return EFI_DEVICE_ERROR;
> }
> +
> ZeroMem ((VOID *) Context, sizeof (SPI_FLASH_DEBUG_CONTEXT));
>
> - Status = PeiServicesNotifyPpi (&mSpiPpiNotifyList[0]);
> - if (EFI_ERROR (Status)) {
> - return EFI_DEVICE_ERROR;
> - }
> -
> - //
> - // Perform silicon specific initialization required to enable write to SPI flash.
> - //
> - Status = SpiServiceInit ();
> - if (EFI_ERROR (Status)) {
> - Status = EFI_DEVICE_ERROR;
> - }
> -
> - return Status;
> + return EFI_SUCCESS;
> }
> --
> 2.28.0.windows.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [edk2-platforms][PATCH v1 1/1] KabylakeOpenBoardPkg/PeiSerialPortLibSpiFlash: Remove PPI from HOB
2021-07-09 16:08 [edk2-platforms][PATCH v1 1/1] KabylakeOpenBoardPkg/PeiSerialPortLibSpiFlash: Remove PPI from HOB Michael Kubacki
2021-07-29 1:41 ` Nate DeSimone
@ 2021-07-29 1:47 ` Nate DeSimone
1 sibling, 0 replies; 3+ messages in thread
From: Nate DeSimone @ 2021-07-29 1:47 UTC (permalink / raw)
To: mikuback@linux.microsoft.com, devel@edk2.groups.io
Cc: Chiu, Chasel, Benjamin Doron
Pushed: https://github.com/tianocore/edk2-platforms/commit/8c9335e
> -----Original Message-----
> From: mikuback@linux.microsoft.com <mikuback@linux.microsoft.com>
> Sent: Friday, July 9, 2021 9:08 AM
> To: devel@edk2.groups.io
> Cc: Chiu, Chasel <chasel.chiu@intel.com>; Desimone, Nathaniel L
> <nathaniel.l.desimone@intel.com>; Benjamin Doron
> <benjamin.doron00@gmail.com>
> Subject: [edk2-platforms][PATCH v1 1/1]
> KabylakeOpenBoardPkg/PeiSerialPortLibSpiFlash: Remove PPI from HOB
>
> From: Michael Kubacki <michael.kubacki@microsoft.com>
>
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3486
>
> 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/PeiS
> erialPortLibSpiFlash.c | 114 +++++++++-----------
> 1 file changed, 48 insertions(+), 66 deletions(-)
>
> diff --git
> a/Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFlash/P
> eiSerialPortLibSpiFlash.c
> b/Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFlash/P
> eiSerialPortLibSpiFlash.c
> index 0230149a38c4..fc48bdc6fccb 100644
> ---
> a/Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFlash/P
> eiSerialPortLibSpiFlash.c
> +++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFla
> +++ sh/PeiSerialPortLibSpiFlash.c
> @@ -2,6 +2,7 @@
> Serial I/O Port library implementation for output to SPI flash
>
> Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) Microsoft Corporation.<BR>
> SPDX-License-Identifier: BSD-2-Clause-Patent
>
> **/
> @@ -17,40 +18,23 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
> #include <Library/SpiLib.h>
>
> typedef struct {
> - PCH_SPI_PPI *PchSpiPpi;
> UINT32 CurrentWriteOffset;
> } SPI_FLASH_DEBUG_CONTEXT;
>
> /**
> - Update reference to the most recent PCH SPI PPI installed
> + Returns a pointer to the PCH SPI PPI.
>
> - @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table
> published by the PEI Foundation
> - @param NotifyDescriptor Address of the notification descriptor data
> structure.
> - @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 interface
> - @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
>
> **/
> -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 = GetFirstGuidHob (&gSpiFlashDebugHobGuid);
> - if (GuidHob == NULL) {
> - return EFI_NOT_FOUND;
> - }
> - Context = GET_GUID_HOB_DATA (GuidHob);
> + EFI_STATUS Status;
> + PCH_SPI_PPI *PchSpiPpi;
>
> Status = PeiServicesLocatePpi (
> &gPchSpiPpiGuid,
> @@ -59,27 +43,17 @@ SpiPpiNotifyCallback (
> (VOID **) &PchSpiPpi
> );
> if (EFI_ERROR (Status)) {
> - return EFI_NOT_FOUND;
> + return NULL;
> }
>
> - Context->PchSpiPpi = PchSpiPpi;
> -
> - return EFI_SUCCESS;
> + return PchSpiPpi;
> }
>
> -EFI_PEI_NOTIFY_DESCRIPTOR mSpiPpiNotifyList[] = {
> - {
> - (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK |
> EFI_PEI_PPI_DESCRIPTOR_TERMINATE_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
>
> - @param Buffer Point of data buffer which need to be writed.
> + @param Buffer Point of data buffer which needs to be written.
> @param NumberOfBytes Number of output bytes which are cached in
> Buffer.
>
> **/
> @@ -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 = GET_GUID_HOB_DATA (GuidHob);
> - if (Context == NULL || Context->PchSpiPpi == NULL || Context-
> >CurrentWriteOffset >= NvMessageAreaSize) {
> + if (Context == NULL || Context->CurrentWriteOffset >=
> NvMessageAreaSize) {
> + return 0;
> + }
> + PchSpiPpi = GetSpiPpi ();
> + if (PchSpiPpi == NULL) {
> return 0;
> }
>
> if ((Context->CurrentWriteOffset + NumberOfBytes) / NvMessageAreaSize
> > 0) {
> LinearOffset = (UINT32) (FixedPcdGet32 (PcdFlashNvDebugMessageBase)
> - FixedPcdGet32 (PcdFlashAreaBaseAddress));
> - Status = Context->PchSpiPpi->FlashErase (
> - Context->PchSpiPpi,
> - FlashRegionBios,
> - LinearOffset,
> - NvMessageAreaSize
> - );
> + Status = PchSpiPpi->FlashErase (
> + PchSpiPpi,
> + FlashRegionBios,
> + LinearOffset,
> + NvMessageAreaSize
> + );
> if (!EFI_ERROR (Status)) {
> Context->CurrentWriteOffset = 0;
> } else {
> @@ -137,13 +116,13 @@ SerialPortWrite (
>
> LinearOffset = (FixedPcdGet32 (PcdFlashNvDebugMessageBase) +
> Context->CurrentWriteOffset) - FixedPcdGet32 (PcdFlashAreaBaseAddress);
>
> - Status = Context->PchSpiPpi->FlashWrite (
> - Context->PchSpiPpi,
> - FlashRegionBios,
> - LinearOffset,
> - BytesWritten,
> - (UINT8 *) &Buffer[SourceBufferOffset]
> - );
> + Status = PchSpiPpi->FlashWrite (
> + PchSpiPpi,
> + FlashRegionBios,
> + LinearOffset,
> + BytesWritten,
> + (UINT8 *) &Buffer[SourceBufferOffset]
> + );
> if (!EFI_ERROR (Status)) {
> Context->CurrentWriteOffset += BytesWritten;
> return BytesWritten;
> @@ -295,26 +274,29 @@ SerialPortInitialize (
> )
> {
> EFI_STATUS Status;
> + EFI_HOB_GUID_TYPE *GuidHob;
> SPI_FLASH_DEBUG_CONTEXT *Context;
>
> + GuidHob = GetFirstGuidHob (&gSpiFlashDebugHobGuid); if (GuidHob !=
> + NULL) {
> + // Initialization only needs to occur once
> + return EFI_SUCCESS;
> + }
> +
> + //
> + // Perform silicon specific initialization required to enable write to SPI flash.
> + //
> + Status = SpiServiceInit ();
> + if (EFI_ERROR (Status)) {
> + return EFI_DEVICE_ERROR;
> + }
> +
> Context = (SPI_FLASH_DEBUG_CONTEXT *) BuildGuidHob
> (&gSpiFlashDebugHobGuid, sizeof (SPI_FLASH_DEBUG_CONTEXT));
> if (Context == NULL) {
> return EFI_DEVICE_ERROR;
> }
> +
> ZeroMem ((VOID *) Context, sizeof (SPI_FLASH_DEBUG_CONTEXT));
>
> - Status = PeiServicesNotifyPpi (&mSpiPpiNotifyList[0]);
> - if (EFI_ERROR (Status)) {
> - return EFI_DEVICE_ERROR;
> - }
> -
> - //
> - // Perform silicon specific initialization required to enable write to SPI flash.
> - //
> - Status = SpiServiceInit ();
> - if (EFI_ERROR (Status)) {
> - Status = EFI_DEVICE_ERROR;
> - }
> -
> - return Status;
> + return EFI_SUCCESS;
> }
> --
> 2.28.0.windows.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-07-29 1:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-09 16:08 [edk2-platforms][PATCH v1 1/1] KabylakeOpenBoardPkg/PeiSerialPortLibSpiFlash: Remove PPI from HOB Michael Kubacki
2021-07-29 1:41 ` Nate DeSimone
2021-07-29 1:47 ` Nate DeSimone
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox