/** @file\r
Platform Hook Library instance for UART device.\r
\r
- Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>\r
SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
#include <Base.h>\r
-#include <Uefi/UefiBaseType.h>\r
-#include <Library/PciLib.h>\r
+#include <PiDxe.h>\r
+#include <UniversalPayload/SerialPortInfo.h>\r
#include <Library/PlatformHookLib.h>\r
-#include <Library/BlParseLib.h>\r
#include <Library/PcdLib.h>\r
+#include <Library/HobLib.h>\r
\r
-typedef struct {\r
- UINT16 VendorId; ///< Vendor ID to match the PCI device. The value 0xFFFF terminates the list of entries.\r
- UINT16 DeviceId; ///< Device ID to match the PCI device\r
- UINT32 ClockRate; ///< UART clock rate. Set to 0 for default clock rate of 1843200 Hz\r
- UINT64 Offset; ///< The byte offset into to the BAR\r
- UINT8 BarIndex; ///< Which BAR to get the UART base address\r
- UINT8 RegisterStride; ///< UART register stride in bytes. Set to 0 for default register stride of 1 byte.\r
- UINT16 ReceiveFifoDepth; ///< UART receive FIFO depth in bytes. Set to 0 for a default FIFO depth of 16 bytes.\r
- UINT16 TransmitFifoDepth; ///< UART transmit FIFO depth in bytes. Set to 0 for a default FIFO depth of 16 bytes.\r
- UINT8 Reserved[2];\r
-} PCI_SERIAL_PARAMETER;\r
+\r
+/** Library Constructor\r
+\r
+ @retval RETURN_SUCCESS Success.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PlatformHookSerialPortConstructor (\r
+ VOID\r
+ )\r
+{\r
+ // Nothing to do here. This constructor is added to\r
+ // enable the chain of constructor invocation for\r
+ // dependent libraries.\r
+ return RETURN_SUCCESS;\r
+}\r
\r
/**\r
Performs platform specific initialization required for the CPU to access\r
VOID\r
)\r
{\r
- RETURN_STATUS Status;\r
- UINT32 DeviceVendor;\r
- PCI_SERIAL_PARAMETER *SerialParam;\r
- SERIAL_PORT_INFO SerialPortInfo;\r
-\r
- Status = ParseSerialInfo (&SerialPortInfo);\r
- if (RETURN_ERROR (Status)) {\r
- return Status;\r
- }\r
+ RETURN_STATUS Status;\r
+ UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO *SerialPortInfo;\r
+ UINT8 *GuidHob;\r
+ UNIVERSAL_PAYLOAD_GENERIC_HEADER *GenericHeader;\r
\r
- if (SerialPortInfo.Type == PLD_SERIAL_TYPE_MEMORY_MAPPED) {\r
- Status = PcdSetBoolS (PcdSerialUseMmio, TRUE);\r
- } else { //IO\r
- Status = PcdSetBoolS (PcdSerialUseMmio, FALSE);\r
- }\r
- if (RETURN_ERROR (Status)) {\r
- return Status;\r
- }\r
- Status = PcdSet64S (PcdSerialRegisterBase, SerialPortInfo.BaseAddr);\r
- if (RETURN_ERROR (Status)) {\r
- return Status;\r
+ GuidHob = GetFirstGuidHob (&gUniversalPayloadSerialPortInfoGuid);\r
+ if (GuidHob == NULL) {\r
+ return EFI_NOT_FOUND;\r
}\r
\r
- Status = PcdSet32S (PcdSerialRegisterStride, SerialPortInfo.RegWidth);\r
- if (RETURN_ERROR (Status)) {\r
- return Status;\r
+ GenericHeader = (UNIVERSAL_PAYLOAD_GENERIC_HEADER *) GET_GUID_HOB_DATA (GuidHob);\r
+ if ((sizeof (UNIVERSAL_PAYLOAD_GENERIC_HEADER) > GET_GUID_HOB_DATA_SIZE (GuidHob)) || (GenericHeader->Length > GET_GUID_HOB_DATA_SIZE (GuidHob))) {\r
+ return EFI_NOT_FOUND;\r
}\r
\r
- Status = PcdSet32S (PcdSerialBaudRate, SerialPortInfo.Baud);\r
- if (RETURN_ERROR (Status)) {\r
- return Status;\r
- }\r
+ if (GenericHeader->Revision == UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO_REVISION) {\r
+ SerialPortInfo = (UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO *) GET_GUID_HOB_DATA (GuidHob);\r
+ if (GenericHeader->Length < UNIVERSAL_PAYLOAD_SIZEOF_THROUGH_FIELD (UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO, RegisterBase)) {\r
+ //\r
+ // Return if can't find the Serial Port Info Hob with enough length\r
+ //\r
+ return EFI_NOT_FOUND;\r
+ }\r
\r
- Status = PcdSet32S (PcdSerialClockRate, SerialPortInfo.InputHertz);\r
- if (RETURN_ERROR (Status)) {\r
- return Status;\r
- }\r
+ Status = PcdSetBoolS (PcdSerialUseMmio, SerialPortInfo->UseMmio);\r
+ if (RETURN_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+ Status = PcdSet64S (PcdSerialRegisterBase, SerialPortInfo->RegisterBase);\r
+ if (RETURN_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+ Status = PcdSet32S (PcdSerialRegisterStride, SerialPortInfo->RegisterStride);\r
+ if (RETURN_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+ Status = PcdSet32S (PcdSerialBaudRate, SerialPortInfo->BaudRate);\r
+ if (RETURN_ERROR (Status)) {\r
+ return Status;\r
+ }\r
\r
- if (SerialPortInfo.UartPciAddr >= 0x80000000) {\r
- DeviceVendor = PciRead32 (SerialPortInfo.UartPciAddr & 0x0ffff000);\r
- SerialParam = PcdGetPtr(PcdPciSerialParameters);\r
- SerialParam->VendorId = (UINT16)DeviceVendor;\r
- SerialParam->DeviceId = DeviceVendor >> 16;\r
- SerialParam->ClockRate = SerialPortInfo.InputHertz;\r
- SerialParam->RegisterStride = (UINT8)SerialPortInfo.RegWidth;\r
+ return RETURN_SUCCESS;\r
}\r
\r
- return RETURN_SUCCESS;\r
+ return EFI_NOT_FOUND;\r
}\r