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