Fdt16550SerialPortHookLib.c 1.3 KB

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