TianoCore EDK2 master
Loading...
Searching...
No Matches
Ram.c
Go to the documentation of this file.
1
9#include <Uefi/UefiBaseType.h>
10#include <Uefi/UefiMultiPhase.h>
11#include <Pi/PiBootMode.h>
12#include <Pi/PiHob.h>
13#include <Library/HobLib.h>
15#include <Library/PcdLib.h>
17
18#include "Ram.h"
19#include "Write.h"
20
21UINTN mDebugLibFdtPL011UartAddress;
22RETURN_STATUS mDebugLibFdtPL011UartPermanentStatus = RETURN_SUCCESS;
23
28RETURN_STATUS
30 VOID
31 )
32{
33 CONST VOID *Hob;
35 RETURN_STATUS Status;
36 UINTN DebugAddress;
37 UINT64 BaudRate;
38 UINT32 ReceiveFifoDepth;
39 EFI_PARITY_TYPE Parity;
40 UINT8 DataBits;
41 EFI_STOP_BITS_TYPE StopBits;
42
43 if (mDebugLibFdtPL011UartAddress != 0) {
44 return RETURN_SUCCESS;
45 }
46
47 if (RETURN_ERROR (mDebugLibFdtPL011UartPermanentStatus)) {
48 return mDebugLibFdtPL011UartPermanentStatus;
49 }
50
51 Hob = GetFirstGuidHob (&gEarlyPL011BaseAddressGuid);
52 if ((Hob == NULL) || (GET_GUID_HOB_DATA_SIZE (Hob) != sizeof *UartBase)) {
53 Status = RETURN_NOT_FOUND;
54 goto Failed;
55 }
56
57 UartBase = GET_GUID_HOB_DATA (Hob);
58
59 DebugAddress = (UINTN)UartBase->DebugAddress;
60 if (DebugAddress == 0) {
61 Status = RETURN_NOT_FOUND;
62 goto Failed;
63 }
64
65 BaudRate = (UINTN)PcdGet64 (PcdUartDefaultBaudRate);
66 ReceiveFifoDepth = 0; // Use the default value for Fifo depth
67 Parity = (EFI_PARITY_TYPE)PcdGet8 (PcdUartDefaultParity);
68 DataBits = PcdGet8 (PcdUartDefaultDataBits);
69 StopBits = (EFI_STOP_BITS_TYPE)PcdGet8 (PcdUartDefaultStopBits);
70
72 DebugAddress,
73 FixedPcdGet32 (PL011UartClkInHz),
74 &BaudRate,
75 &ReceiveFifoDepth,
76 &Parity,
77 &DataBits,
78 &StopBits
79 );
80 if (RETURN_ERROR (Status)) {
81 goto Failed;
82 }
83
84 mDebugLibFdtPL011UartAddress = DebugAddress;
85 return RETURN_SUCCESS;
86
87Failed:
88 mDebugLibFdtPL011UartPermanentStatus = Status;
89 return Status;
90}
91
110UINTN
112 IN UINT8 *Buffer,
113 IN UINTN NumberOfBytes
114 )
115{
116 RETURN_STATUS Status;
117
118 Status = Initialize ();
119 if (RETURN_ERROR (Status)) {
120 return 0;
121 }
122
123 return PL011UartWrite (mDebugLibFdtPL011UartAddress, Buffer, NumberOfBytes);
124}
UINT64 UINTN
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
Definition: HobLib.c:215
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define RETURN_ERROR(StatusCode)
Definition: Base.h:1061
#define RETURN_NOT_FOUND
Definition: Base.h:1142
#define RETURN_SUCCESS
Definition: Base.h:1066
#define IN
Definition: Base.h:279
RETURN_STATUS EFIAPI PL011UartInitializePort(IN UINTN UartBase, IN UINT32 UartClkInHz, IN OUT UINT64 *BaudRate, IN OUT UINT32 *ReceiveFifoDepth, IN OUT EFI_PARITY_TYPE *Parity, IN OUT UINT8 *DataBits, IN OUT EFI_STOP_BITS_TYPE *StopBits)
Definition: PL011UartLib.c:66
UINTN EFIAPI PL011UartWrite(IN UINTN UartBase, IN UINT8 *Buffer, IN UINTN NumberOfBytes)
Definition: PL011UartLib.c:417
#define PcdGet64(TokenName)
Definition: PcdLib.h:375
#define FixedPcdGet32(TokenName)
Definition: PcdLib.h:92
#define PcdGet8(TokenName)
Definition: PcdLib.h:336
STATIC RETURN_STATUS Initialize(VOID)
Definition: Ram.c:29
UINTN DebugLibFdtPL011UartWrite(IN UINT8 *Buffer, IN UINTN NumberOfBytes)
Definition: Ram.c:111
EFI_STOP_BITS_TYPE
Definition: SerialIo.h:53
EFI_PARITY_TYPE
Definition: SerialIo.h:41