1 /** @file
2   Platform Hook Library instance for 16550 Uart.
3 
4   Copyright (c) 2020, ARM Ltd. All rights reserved.<BR>
5   SPDX-License-Identifier: BSD-2-Clause-Patent
6 
7 **/
8 
9 #include <Base.h>
10 #include <Uefi.h>
11 
12 #include <Pi/PiBootMode.h>
13 #include <Pi/PiHob.h>
14 
15 #include <Guid/Early16550UartBaseAddress.h>
16 #include <Guid/Fdt.h>
17 #include <Guid/FdtHob.h>
18 
19 #include <Library/BaseLib.h>
20 #include <Library/HobLib.h>
21 #include <Library/PcdLib.h>
22 #include <Library/PlatformHookLib.h>
23 
24 /** Platform hook to retrieve the 16550 UART base address from the GUID Hob
25     that caches the UART base address from early boot stage and store it in
26     PcdSerialRegisterBase.
27 
28   @retval RETURN_SUCCESS    Success.
29   @retval RETURN_NOT_FOUND  Serial Port information not found.
30 
31 **/
32 RETURN_STATUS
33 EFIAPI
PlatformHookSerialPortInitialize(VOID)34 PlatformHookSerialPortInitialize (
35   VOID
36   )
37 {
38   VOID            *Hob;
39   UINT64          *UartBase;
40 
41   if (PcdGet64 (PcdSerialRegisterBase) != 0) {
42     return RETURN_SUCCESS;
43   }
44 
45   Hob = GetFirstGuidHob (&gEarly16550UartBaseAddressGuid);
46   if ((Hob == NULL) || (GET_GUID_HOB_DATA_SIZE (Hob) != sizeof (*UartBase))) {
47     return RETURN_NOT_FOUND;
48   }
49 
50   UartBase = GET_GUID_HOB_DATA (Hob);
51   if ((UINTN)*UartBase == 0) {
52     return RETURN_NOT_FOUND;
53   }
54 
55   return (RETURN_STATUS)PcdSet64S (PcdSerialRegisterBase, (UINTN)*UartBase);
56 }
57