From: "Kubacki, Michael A" <michael.a.kubacki@intel.com>
To: devel@edk2.groups.io
Cc: Chasel Chiu <chasel.chiu@intel.com>,
Nate DeSimone <nathaniel.l.desimone@intel.com>,
Ankit Sinha <ankit.sinha@intel.com>,
Jeremy Soller <jeremy@system76.com>
Subject: [edk2-platforms][PATCH V1 07/12] KabylakeOpenBoardPkg: Add PeiSerialPortLibSpiFlash
Date: Fri, 20 Sep 2019 11:40:25 -0700 [thread overview]
Message-ID: <20190920184030.6148-8-michael.a.kubacki@intel.com> (raw)
In-Reply-To: <20190920184030.6148-1-michael.a.kubacki@intel.com>
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2207
PeiSerialPortLibSpiFlash is currently used for early boot closed
chassis debug on production systems such as the System 76 Galago Pro
laptop. This change moves the library to KabylakeOpenBoardPkg from
ClevoOpenBoardPkg since the Clevo package is being removes for
code consolidation.
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Ankit Sinha <ankit.sinha@intel.com>
Cc: Jeremy Soller <jeremy@system76.com>
Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com>
---
Platform/Intel/KabylakeOpenBoardPkg/OpenBoardPkg.dec | 6 +
Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFlash/PeiSerialPortLibSpiFlash.inf | 50 +++
Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFlash/PeiSerialPortLibSpiFlash.c | 320 ++++++++++++++++++++
3 files changed, 376 insertions(+)
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/OpenBoardPkg.dec b/Platform/Intel/KabylakeOpenBoardPkg/OpenBoardPkg.dec
index 68977d081e..383c34537d 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/OpenBoardPkg.dec
+++ b/Platform/Intel/KabylakeOpenBoardPkg/OpenBoardPkg.dec
@@ -29,6 +29,8 @@ gBoardModuleTokenSpaceGuid = {0x72d1fff7, 0xa42a, 0x4219, {0xb9, 0x9
gTianoLogoGuid = {0x7BB28B99, 0x61BB, 0x11D5, {0x9A, 0x5D, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D}}
+gSpiFlashDebugHobGuid = {0xcaaaf418, 0x38a5, 0x4d49, {0xbe, 0x74, 0xe6, 0x06, 0xe4, 0x02, 0x6d, 0x25}}
+
gTbtInfoHobGuid = {0x74a81eaa, 0x033c, 0x4783, {0xbe, 0x2b, 0x84, 0x85, 0x74, 0xa6, 0x97, 0xb7}}
gPlatformModuleTokenSpaceGuid = {0x69d13bf0, 0xaf91, 0x4d96, {0xaa, 0x9f, 0x21, 0x84, 0xc5, 0xce, 0x3b, 0xc0}}
@@ -65,6 +67,10 @@ gBoardModuleTokenSpaceGuid.PcdSwSmiDTbtEnumerate|0xF7|UINT8|0x000000110
gBoardModuleTokenSpaceGuid.PcdSmcExtSmiBitPosition|0x01|UINT8|0x90000015
+gBoardModuleTokenSpaceGuid.PcdFlashNvDebugMessageBase|0x00000000|UINT32|0x90000030
+gBoardModuleTokenSpaceGuid.PcdFlashNvDebugMessageSize|0x00000000|UINT32|0x90000031
+gBoardModuleTokenSpaceGuid.PcdFlashNvDebugMessageOffset|0x00000000|UINT32|0x90000032
+
[PcdsDynamic]
# Board GPIO Table
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFlash/PeiSerialPortLibSpiFlash.inf b/Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFlash/PeiSerialPortLibSpiFlash.inf
new file mode 100644
index 0000000000..ed93d0785f
--- /dev/null
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFlash/PeiSerialPortLibSpiFlash.inf
@@ -0,0 +1,50 @@
+### @file
+# Component description file for Serial I/O Port library to write to SPI flash.
+#
+# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = PeiSerialPortLibFlash
+ FILE_GUID = 35A3BA89-04BE-409C-A3CA-DEF6B510F80F
+ VERSION_STRING = 1.1
+ MODULE_TYPE = PEIM
+ LIBRARY_CLASS = SerialPortLib|PEIM PEI_CORE
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ HobLib
+ PcdLib
+ PeiServicesLib
+ SpiLib
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ MinPlatformPkg/MinPlatformPkg.dec
+ KabylakeSiliconPkg/SiPkg.dec
+ KabylakeOpenBoardPkg/OpenBoardPkg.dec
+
+[Sources]
+ PeiSerialPortLibSpiFlash.c
+
+[Ppis]
+ gPchSpiPpiGuid
+
+[Guids]
+ gSpiFlashDebugHobGuid
+
+[Pcd]
+ gMinPlatformPkgTokenSpaceGuid.PcdFlashAreaBaseAddress ## CONSUMES
+ gBoardModuleTokenSpaceGuid.PcdFlashNvDebugMessageBase ## CONSUMES
+ gBoardModuleTokenSpaceGuid.PcdFlashNvDebugMessageSize ## CONSUMES
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFlash/PeiSerialPortLibSpiFlash.c b/Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFlash/PeiSerialPortLibSpiFlash.c
new file mode 100644
index 0000000000..0230149a38
--- /dev/null
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/PeiSerialPortLibSpiFlash/PeiSerialPortLibSpiFlash.c
@@ -0,0 +1,320 @@
+/** @file
+ Serial I/O Port library implementation for output to SPI flash
+
+Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+#include <Ppi/Spi.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/HobLib.h>
+#include <Library/PcdLib.h>
+#include <Library/PeiServicesLib.h>
+#include <Library/SerialPortLib.h>
+#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
+
+ @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
+
+**/
+EFI_STATUS
+EFIAPI
+SpiPpiNotifyCallback (
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
+ IN VOID *Ppi
+ )
+{
+ 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);
+
+ Status = PeiServicesLocatePpi (
+ &gPchSpiPpiGuid,
+ 0,
+ NULL,
+ (VOID **) &PchSpiPpi
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_NOT_FOUND;
+ }
+
+ Context->PchSpiPpi = PchSpiPpi;
+
+ return EFI_SUCCESS;
+}
+
+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 NumberOfBytes Number of output bytes which are cached in Buffer.
+
+**/
+UINTN
+EFIAPI
+SerialPortWrite (
+ IN UINT8 *Buffer,
+ IN UINTN NumberOfBytes
+ )
+{
+ EFI_STATUS Status;
+ EFI_HOB_GUID_TYPE *GuidHob;
+ SPI_FLASH_DEBUG_CONTEXT *Context;
+ UINT32 BytesWritten;
+ UINT32 SourceBufferOffset;
+ UINT32 NvMessageAreaSize;
+ UINT32 LinearOffset;
+
+ BytesWritten = NumberOfBytes;
+ SourceBufferOffset = 0;
+
+ NvMessageAreaSize = (UINT32) FixedPcdGet32 (PcdFlashNvDebugMessageSize);
+
+ if (NumberOfBytes == 0 || NvMessageAreaSize == 0) {
+ return 0;
+ }
+ GuidHob = GetFirstGuidHob (&gSpiFlashDebugHobGuid);
+ if (GuidHob == NULL) {
+ return 0;
+ }
+ Context = GET_GUID_HOB_DATA (GuidHob);
+ if (Context == NULL || Context->PchSpiPpi == NULL || Context->CurrentWriteOffset >= NvMessageAreaSize) {
+ return 0;
+ }
+
+ if ((Context->CurrentWriteOffset + NumberOfBytes) / NvMessageAreaSize > 0) {
+ LinearOffset = (UINT32) (FixedPcdGet32 (PcdFlashNvDebugMessageBase) - FixedPcdGet32 (PcdFlashAreaBaseAddress));
+ Status = Context->PchSpiPpi->FlashErase (
+ Context->PchSpiPpi,
+ FlashRegionBios,
+ LinearOffset,
+ NvMessageAreaSize
+ );
+ if (!EFI_ERROR (Status)) {
+ Context->CurrentWriteOffset = 0;
+ } else {
+ return 0;
+ }
+ }
+
+ if (NumberOfBytes > NvMessageAreaSize) {
+ BytesWritten = NvMessageAreaSize;
+ SourceBufferOffset = NumberOfBytes - NvMessageAreaSize;
+ }
+
+ LinearOffset = (FixedPcdGet32 (PcdFlashNvDebugMessageBase) + Context->CurrentWriteOffset) - FixedPcdGet32 (PcdFlashAreaBaseAddress);
+
+ Status = Context->PchSpiPpi->FlashWrite (
+ Context->PchSpiPpi,
+ FlashRegionBios,
+ LinearOffset,
+ BytesWritten,
+ (UINT8 *) &Buffer[SourceBufferOffset]
+ );
+ if (!EFI_ERROR (Status)) {
+ Context->CurrentWriteOffset += BytesWritten;
+ return BytesWritten;
+ }
+
+ return 0;
+}
+
+/**
+ Common function to Read data from UART serial device, USB serial device and save the datas in buffer.
+
+ @param Buffer Point of data buffer which need to be writed.
+ @param NumberOfBytes Number of output bytes which are cached in Buffer.
+
+ @retval 0 Read data failed, no data is to be read.
+ @retval >0 Actual number of bytes read from debug device.
+
+**/
+UINTN
+EFIAPI
+SerialPortRead (
+ OUT UINT8 *Buffer,
+ IN UINTN NumberOfBytes
+)
+{
+ return 0;
+}
+
+/**
+ Polls a serial device to see if there is any data waiting to be read.
+
+ Polls a serial device to see if there is any data waiting to be read.
+ If there is data waiting to be read from the serial device, then TRUE is returned.
+ If there is no data waiting to be read from the serial device, then FALSE is returned.
+
+ @retval TRUE Data is waiting to be read from the serial device.
+ @retval FALSE There is no data waiting to be read from the serial device.
+
+**/
+BOOLEAN
+EFIAPI
+SerialPortPoll (
+ VOID
+ )
+{
+ return FALSE;
+}
+
+/**
+ Sets the control bits on a serial device.
+
+ @param Control Sets the bits of Control that are settable.
+
+ @retval RETURN_SUCCESS The new control bits were set on the serial device.
+ @retval RETURN_UNSUPPORTED The serial device does not support this operation.
+ @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
+
+**/
+RETURN_STATUS
+EFIAPI
+SerialPortSetControl (
+ IN UINT32 Control
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+/**
+ Retrieve the status of the control bits on a serial device.
+
+ @param Control A pointer to return the current control signals from the serial device.
+
+ @retval RETURN_SUCCESS The control bits were read from the serial device.
+ @retval RETURN_UNSUPPORTED The serial device does not support this operation.
+ @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
+
+**/
+RETURN_STATUS
+EFIAPI
+SerialPortGetControl (
+ OUT UINT32 *Control
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+/**
+ Sets the baud rate, receive FIFO depth, transmit/receice time out, parity,
+ data bits, and stop bits on a serial device.
+
+ @param BaudRate The requested baud rate. A BaudRate value of 0 will use the
+ device's default interface speed.
+ On output, the value actually set.
+ @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the
+ serial interface. A ReceiveFifoDepth value of 0 will use
+ the device's default FIFO depth.
+ On output, the value actually set.
+ @param Timeout The requested time out for a single character in microseconds.
+ This timeout applies to both the transmit and receive side of the
+ interface. A Timeout value of 0 will use the device's default time
+ out value.
+ On output, the value actually set.
+ @param Parity The type of parity to use on this serial device. A Parity value of
+ DefaultParity will use the device's default parity value.
+ On output, the value actually set.
+ @param DataBits The number of data bits to use on the serial device. A DataBits
+ vaule of 0 will use the device's default data bit setting.
+ On output, the value actually set.
+ @param StopBits The number of stop bits to use on this serial device. A StopBits
+ value of DefaultStopBits will use the device's default number of
+ stop bits.
+ On output, the value actually set.
+
+ @retval RETURN_SUCCESS The new attributes were set on the serial device.
+ @retval RETURN_UNSUPPORTED The serial device does not support this operation.
+ @retval RETURN_INVALID_PARAMETER One or more of the attributes has an unsupported value.
+ @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
+
+**/
+RETURN_STATUS
+EFIAPI
+SerialPortSetAttributes (
+ IN OUT UINT64 *BaudRate,
+ IN OUT UINT32 *ReceiveFifoDepth,
+ IN OUT UINT32 *Timeout,
+ IN OUT EFI_PARITY_TYPE *Parity,
+ IN OUT UINT8 *DataBits,
+ IN OUT EFI_STOP_BITS_TYPE *StopBits
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+/**
+ Initialize the serial device hardware.
+
+ If no initialization is required, then return RETURN_SUCCESS.
+ If the serial device was successfully initialized, then return RETURN_SUCCESS.
+ If the serial device could not be initialized, then return RETURN_DEVICE_ERROR.
+
+ @retval RETURN_SUCCESS The serial device was initialized.
+ @retval RETURN_DEVICE_ERROR The serial device could not be initialized.
+
+**/
+RETURN_STATUS
+EFIAPI
+SerialPortInitialize (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ SPI_FLASH_DEBUG_CONTEXT *Context;
+
+ 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;
+}
--
2.16.2.windows.1
next prev parent reply other threads:[~2019-09-20 18:40 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-20 18:40 [edk2-platforms][PATCH V1 00/12] Move ClevoOpenBoardPkg/N1xxWU Contents to KabylakeOpenBoardPkg Kubacki, Michael A
2019-09-20 18:40 ` [edk2-platforms][PATCH V1 01/12] Platform/Intel: Remove N1xxWU board build option Kubacki, Michael A
2019-09-23 7:45 ` [edk2-devel] " Nate DeSimone
2019-09-23 8:51 ` Chiu, Chasel
2019-09-23 20:28 ` Sinha, Ankit
2019-09-23 22:28 ` jeremy
2019-09-20 18:40 ` [edk2-platforms][PATCH V1 02/12] ClevoOpenBoardPkg: Remove package contents Kubacki, Michael A
2019-09-23 8:04 ` Nate DeSimone
2019-09-23 8:23 ` [edk2-devel] " Chiu, Chasel
2019-09-23 22:37 ` Jeremy Soller
2019-09-20 18:40 ` [edk2-platforms][PATCH V1 03/12] ClevoOpenBoardPkg: Remove global files and references Kubacki, Michael A
2019-09-23 0:49 ` [edk2-devel] " Chiu, Chasel
2019-09-23 8:05 ` Nate DeSimone
2019-09-23 22:39 ` Jeremy Soller
2019-09-20 18:40 ` [edk2-platforms][PATCH V1 04/12] KabylakeOpenBoardPkg: Move policy update libs to KabylakeRvp3 board Kubacki, Michael A
2019-09-23 8:07 ` [edk2-devel] " Nate DeSimone
2019-09-23 8:19 ` Chiu, Chasel
2019-09-23 22:38 ` Jeremy Soller
2019-09-20 18:40 ` [edk2-platforms][PATCH V1 05/12] KabylakeOpenBoardPkg: Move EcCommands.h " Kubacki, Michael A
2019-09-23 8:08 ` [edk2-devel] " Nate DeSimone
2019-09-23 8:25 ` Chiu, Chasel
2019-09-23 22:37 ` Jeremy Soller
2019-09-20 18:40 ` [edk2-platforms][PATCH V1 06/12] KabylakeOpenBoardPkg: Move flash map to board Kubacki, Michael A
2019-09-23 8:09 ` Nate DeSimone
2019-09-23 8:41 ` Chiu, Chasel
2019-09-23 22:36 ` Jeremy Soller
2019-09-20 18:40 ` Kubacki, Michael A [this message]
2019-09-23 8:10 ` [edk2-platforms][PATCH V1 07/12] KabylakeOpenBoardPkg: Add PeiSerialPortLibSpiFlash Nate DeSimone
2019-09-23 8:27 ` Chiu, Chasel
2019-09-23 22:37 ` Jeremy Soller
2019-09-20 18:40 ` [edk2-platforms][PATCH V1 08/12] KabylakeOpenBoardPkg/GalagoPro3: Add headers Kubacki, Michael A
2019-09-23 8:11 ` Nate DeSimone
2019-09-23 8:42 ` Chiu, Chasel
2019-09-23 22:35 ` [edk2-devel] " Jeremy Soller
2019-09-20 18:40 ` [edk2-platforms][PATCH V1 09/12] KabylakeOpenBoardPkg/GalagoPro3: Add library instances Kubacki, Michael A
2019-09-23 8:14 ` Nate DeSimone
2019-09-23 8:28 ` Chiu, Chasel
2019-09-23 22:36 ` Jeremy Soller
2019-09-23 22:36 ` Jeremy Soller
2019-09-20 18:40 ` [edk2-platforms][PATCH V1 10/12] KabylakeOpenBoardPkg/GalagoPro3: Add modules Kubacki, Michael A
2019-09-23 8:15 ` Nate DeSimone
2019-09-23 17:41 ` [edk2-devel] " Kubacki, Michael A
2019-09-23 8:45 ` Chiu, Chasel
2019-09-23 22:35 ` Jeremy Soller
2019-09-20 18:40 ` [edk2-platforms][PATCH V1 11/12] KabylakeOpenBoardPkg/GalagoPro3: Add build files Kubacki, Michael A
2019-09-23 8:16 ` Nate DeSimone
2019-09-23 8:36 ` [edk2-devel] " Chiu, Chasel
2019-09-23 22:36 ` Jeremy Soller
2019-09-20 18:40 ` [edk2-platforms][PATCH V1 12/12] Add GalagoPro3 board details to global build and documentation Kubacki, Michael A
2019-09-23 0:51 ` [edk2-devel] " Chiu, Chasel
2019-09-23 8:18 ` Nate DeSimone
2019-09-23 22:38 ` Jeremy Soller
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=20190920184030.6148-8-michael.a.kubacki@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