]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiPayloadPkg: Add a separate PlatformHookLib for Universal Payload
authorZhiguang Liu <zhiguang.liu@intel.com>
Sun, 20 Jun 2021 15:30:07 +0000 (23:30 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 24 Jun 2021 09:16:22 +0000 (09:16 +0000)
Add a new separate PlatformHookLib for Universal Payload to consume Guid
Hob gUniversalPayloadSerialPortInfoGuid to get serial port information

Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Guo Dong <guo.dong@intel.com>
Cc: Benjamin You <benjamin.you@intel.com>
Reviewed-by: Guo Dong <guo.dong@intel.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
UefiPayloadPkg/Library/UniversalPayloadPlatformHookLib/PlatformHookLib.c [new file with mode: 0644]
UefiPayloadPkg/Library/UniversalPayloadPlatformHookLib/PlatformHookLib.inf [new file with mode: 0644]

diff --git a/UefiPayloadPkg/Library/UniversalPayloadPlatformHookLib/PlatformHookLib.c b/UefiPayloadPkg/Library/UniversalPayloadPlatformHookLib/PlatformHookLib.c
new file mode 100644 (file)
index 0000000..6705f29
--- /dev/null
@@ -0,0 +1,82 @@
+/** @file\r
+  Platform Hook Library instance for UART device.\r
+\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 <PiDxe.h>\r
+#include <UniversalPayload/SerialPortInfo.h>\r
+#include <Library/PlatformHookLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/HobLib.h>\r
+\r
+/**\r
+  Performs platform specific initialization required for the CPU to access\r
+  the hardware associated with a SerialPortLib instance.  This function does\r
+  not initialize the serial port hardware itself.  Instead, it initializes\r
+  hardware devices that are required for the CPU to access the serial port\r
+  hardware.  This function may be called more than once.\r
+\r
+  @retval RETURN_SUCCESS       The platform specific initialization succeeded.\r
+  @retval RETURN_DEVICE_ERROR  The platform specific initialization could not be completed.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PlatformHookSerialPortInitialize (\r
+  VOID\r
+  )\r
+{\r
+  RETURN_STATUS                       Status;\r
+  UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO  *SerialPortInfo;\r
+  UINT8                               *GuidHob;\r
+  UNIVERSAL_PAYLOAD_GENERIC_HEADER    *GenericHeader;\r
+\r
+  GuidHob = GetFirstGuidHob (&gUniversalPayloadSerialPortInfoGuid);\r
+  if (GuidHob == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\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
+  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 = 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
+    Status = PcdSet64S (PcdUartDefaultBaudRate, SerialPortInfo->BaudRate);\r
+    if (RETURN_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    return RETURN_SUCCESS;\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
diff --git a/UefiPayloadPkg/Library/UniversalPayloadPlatformHookLib/PlatformHookLib.inf b/UefiPayloadPkg/Library/UniversalPayloadPlatformHookLib/PlatformHookLib.inf
new file mode 100644 (file)
index 0000000..41e05dd
--- /dev/null
@@ -0,0 +1,41 @@
+## @file\r
+#  Platform Hook Library instance for UART device for Universal Payload.\r
+#\r
+#  Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PlatformHookLib\r
+  FILE_GUID                      = 807E05AB-9411-429F-97F0-FE425BF6B094\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PlatformHookLib\r
+  CONSTRUCTOR                    = PlatformHookSerialPortInitialize\r
+\r
+[Sources]\r
+  PlatformHookLib.c\r
+\r
+[LibraryClasses]\r
+  PcdLib\r
+  BaseLib\r
+  HobLib\r
+  DxeHobListLib\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  UefiPayloadPkg/UefiPayloadPkg.dec\r
+\r
+[Guids]\r
+  gUniversalPayloadSerialPortInfoGuid\r
+\r
+[Pcd]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio         ## PRODUCES\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase    ## PRODUCES\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate        ## PRODUCES\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride  ## PRODUCES\r
+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate         ## PRODUCES\r