]> git.proxmox.com Git - mirror_edk2.git/blob - UefiPayloadPkg/Library/UniversalPayloadPlatformHookLib/PlatformHookLib.c
bd433bdbe0c5a80f00323b5ff167907378414902
[mirror_edk2.git] / UefiPayloadPkg / Library / UniversalPayloadPlatformHookLib / 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 /**
17 Performs platform specific initialization required for the CPU to access
18 the hardware associated with a SerialPortLib instance. This function does
19 not initialize the serial port hardware itself. Instead, it initializes
20 hardware devices that are required for the CPU to access the serial port
21 hardware. This function may be called more than once.
22
23 @retval RETURN_SUCCESS The platform specific initialization succeeded.
24 @retval RETURN_DEVICE_ERROR The platform specific initialization could not be completed.
25
26 **/
27 RETURN_STATUS
28 EFIAPI
29 PlatformHookSerialPortInitialize (
30 VOID
31 )
32 {
33 RETURN_STATUS Status;
34 UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO *SerialPortInfo;
35 UINT8 *GuidHob;
36 UNIVERSAL_PAYLOAD_GENERIC_HEADER *GenericHeader;
37
38 GuidHob = GetFirstGuidHob (&gUniversalPayloadSerialPortInfoGuid);
39 if (GuidHob == NULL) {
40 return EFI_NOT_FOUND;
41 }
42
43 GenericHeader = (UNIVERSAL_PAYLOAD_GENERIC_HEADER *) GET_GUID_HOB_DATA (GuidHob);
44 if ((sizeof (UNIVERSAL_PAYLOAD_GENERIC_HEADER) > GET_GUID_HOB_DATA_SIZE (GuidHob)) || (GenericHeader->Length > GET_GUID_HOB_DATA_SIZE (GuidHob))) {
45 return EFI_NOT_FOUND;
46 }
47
48 if (GenericHeader->Revision == UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO_REVISION) {
49 SerialPortInfo = (UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO *) GET_GUID_HOB_DATA (GuidHob);
50 if (GenericHeader->Length < UNIVERSAL_PAYLOAD_SIZEOF_THROUGH_FIELD (UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO, RegisterBase)) {
51 //
52 // Return if can't find the Serial Port Info Hob with enough length
53 //
54 return EFI_NOT_FOUND;
55 }
56
57 Status = PcdSetBoolS (PcdSerialUseMmio, SerialPortInfo->UseMmio);
58 if (RETURN_ERROR (Status)) {
59 return Status;
60 }
61 Status = PcdSet64S (PcdSerialRegisterBase, SerialPortInfo->RegisterBase);
62 if (RETURN_ERROR (Status)) {
63 return Status;
64 }
65 Status = PcdSet32S (PcdSerialRegisterStride, SerialPortInfo->RegisterStride);
66 if (RETURN_ERROR (Status)) {
67 return Status;
68 }
69 Status = PcdSet32S (PcdSerialBaudRate, SerialPortInfo->BaudRate);
70 if (RETURN_ERROR (Status)) {
71 return Status;
72 }
73
74 return RETURN_SUCCESS;
75 }
76
77 return EFI_NOT_FOUND;
78 }