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