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