]> git.proxmox.com Git - mirror_edk2.git/blame - UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.c
UefiPayloadPkg: Remove asm code and sharing libraries
[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\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
04af8bf2
DG
32\r
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
422e5d2f
GD
50 RETURN_STATUS Status;\r
51 UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO *SerialPortInfo;\r
52 UINT8 *GuidHob;\r
53 UNIVERSAL_PAYLOAD_GENERIC_HEADER *GenericHeader;\r
04af8bf2 54\r
422e5d2f
GD
55 GuidHob = GetFirstGuidHob (&gUniversalPayloadSerialPortInfoGuid);\r
56 if (GuidHob == NULL) {\r
57 return EFI_NOT_FOUND;\r
04af8bf2
DG
58 }\r
59\r
422e5d2f
GD
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
04af8bf2
DG
63 }\r
64\r
422e5d2f
GD
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
04af8bf2 73\r
422e5d2f
GD
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
04af8bf2 90\r
422e5d2f 91 return RETURN_SUCCESS;\r
04af8bf2
DG
92 }\r
93\r
422e5d2f 94 return EFI_NOT_FOUND;\r
04af8bf2 95}\r