]> git.proxmox.com Git - mirror_edk2.git/blame - UefiPayloadPkg/Library/UniversalPayloadPlatformHookLib/PlatformHookLib.c
UefiPayloadPkg: Use dummy constructor for PlatformHookLib
[mirror_edk2.git] / UefiPayloadPkg / Library / UniversalPayloadPlatformHookLib / PlatformHookLib.c
CommitLineData
a75c029f
ZL
1/** @file\r
2 Platform Hook Library instance for UART device.\r
3\r
4 Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>\r
5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
6\r
7**/\r
8\r
9#include <Base.h>\r
10#include <PiDxe.h>\r
11#include <UniversalPayload/SerialPortInfo.h>\r
12#include <Library/PlatformHookLib.h>\r
13#include <Library/PcdLib.h>\r
14#include <Library/HobLib.h>\r
15\r
dc430ccf
GD
16\r
17/** Library Constructor\r
18\r
19 @retval RETURN_SUCCESS Success.\r
20**/\r
21EFI_STATUS\r
22EFIAPI\r
23PlatformHookSerialPortConstructor (\r
24 VOID\r
25 )\r
26{\r
27 // Nothing to do here. This constructor is added to\r
28 // enable the chain of constructor invocation for\r
29 // dependent libraries.\r
30 return RETURN_SUCCESS;\r
31}\r
32\r
a75c029f
ZL
33/**\r
34 Performs platform specific initialization required for the CPU to access\r
35 the hardware associated with a SerialPortLib instance. This function does\r
36 not initialize the serial port hardware itself. Instead, it initializes\r
37 hardware devices that are required for the CPU to access the serial port\r
38 hardware. This function may be called more than once.\r
39\r
40 @retval RETURN_SUCCESS The platform specific initialization succeeded.\r
41 @retval RETURN_DEVICE_ERROR The platform specific initialization could not be completed.\r
42\r
43**/\r
44RETURN_STATUS\r
45EFIAPI\r
46PlatformHookSerialPortInitialize (\r
47 VOID\r
48 )\r
49{\r
50 RETURN_STATUS Status;\r
51 UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO *SerialPortInfo;\r
52 UINT8 *GuidHob;\r
53 UNIVERSAL_PAYLOAD_GENERIC_HEADER *GenericHeader;\r
54\r
55 GuidHob = GetFirstGuidHob (&gUniversalPayloadSerialPortInfoGuid);\r
56 if (GuidHob == NULL) {\r
57 return EFI_NOT_FOUND;\r
58 }\r
59\r
60 GenericHeader = (UNIVERSAL_PAYLOAD_GENERIC_HEADER *) GET_GUID_HOB_DATA (GuidHob);\r
61 if ((sizeof (UNIVERSAL_PAYLOAD_GENERIC_HEADER) > GET_GUID_HOB_DATA_SIZE (GuidHob)) || (GenericHeader->Length > GET_GUID_HOB_DATA_SIZE (GuidHob))) {\r
62 return EFI_NOT_FOUND;\r
63 }\r
64\r
65 if (GenericHeader->Revision == UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO_REVISION) {\r
66 SerialPortInfo = (UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO *) GET_GUID_HOB_DATA (GuidHob);\r
67 if (GenericHeader->Length < UNIVERSAL_PAYLOAD_SIZEOF_THROUGH_FIELD (UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO, RegisterBase)) {\r
68 //\r
69 // Return if can't find the Serial Port Info Hob with enough length\r
70 //\r
71 return EFI_NOT_FOUND;\r
72 }\r
73\r
74 Status = PcdSetBoolS (PcdSerialUseMmio, SerialPortInfo->UseMmio);\r
75 if (RETURN_ERROR (Status)) {\r
76 return Status;\r
77 }\r
78 Status = PcdSet64S (PcdSerialRegisterBase, SerialPortInfo->RegisterBase);\r
79 if (RETURN_ERROR (Status)) {\r
80 return Status;\r
81 }\r
82 Status = PcdSet32S (PcdSerialRegisterStride, SerialPortInfo->RegisterStride);\r
83 if (RETURN_ERROR (Status)) {\r
84 return Status;\r
85 }\r
86 Status = PcdSet32S (PcdSerialBaudRate, SerialPortInfo->BaudRate);\r
87 if (RETURN_ERROR (Status)) {\r
88 return Status;\r
89 }\r
a75c029f
ZL
90\r
91 return RETURN_SUCCESS;\r
92 }\r
93\r
94 return EFI_NOT_FOUND;\r
95}\r