TianoCore EDK2 master
Loading...
Searching...
No Matches
FdtPL011SerialPortLib.c
Go to the documentation of this file.
1
14#include <Base.h>
15
16#include <Library/PcdLib.h>
19#include <Pi/PiBootMode.h>
20#include <Uefi/UefiBaseType.h>
21#include <Uefi/UefiMultiPhase.h>
22#include <Pi/PiHob.h>
23#include <Library/HobLib.h>
25
26STATIC UINTN mSerialBaseAddress;
27STATIC RETURN_STATUS mPermanentStatus = RETURN_SUCCESS;
28
41RETURN_STATUS
42EFIAPI
44 VOID
45 )
46{
47 VOID *Hob;
48 RETURN_STATUS Status;
50 UINTN SerialBaseAddress;
51 UINT64 BaudRate;
52 UINT32 ReceiveFifoDepth;
53 EFI_PARITY_TYPE Parity;
54 UINT8 DataBits;
55 EFI_STOP_BITS_TYPE StopBits;
56
57 if (mSerialBaseAddress != 0) {
58 return RETURN_SUCCESS;
59 }
60
61 if (RETURN_ERROR (mPermanentStatus)) {
62 return mPermanentStatus;
63 }
64
65 Hob = GetFirstGuidHob (&gEarlyPL011BaseAddressGuid);
66 if ((Hob == NULL) || (GET_GUID_HOB_DATA_SIZE (Hob) != sizeof *UartBase)) {
67 Status = RETURN_NOT_FOUND;
68 goto Failed;
69 }
70
71 UartBase = GET_GUID_HOB_DATA (Hob);
72
73 SerialBaseAddress = (UINTN)UartBase->ConsoleAddress;
74 if (SerialBaseAddress == 0) {
75 Status = RETURN_NOT_FOUND;
76 goto Failed;
77 }
78
79 BaudRate = (UINTN)PcdGet64 (PcdUartDefaultBaudRate);
80 ReceiveFifoDepth = 0; // Use the default value for Fifo depth
81 Parity = (EFI_PARITY_TYPE)PcdGet8 (PcdUartDefaultParity);
82 DataBits = PcdGet8 (PcdUartDefaultDataBits);
83 StopBits = (EFI_STOP_BITS_TYPE)PcdGet8 (PcdUartDefaultStopBits);
84
86 SerialBaseAddress,
87 FixedPcdGet32 (PL011UartClkInHz),
88 &BaudRate,
89 &ReceiveFifoDepth,
90 &Parity,
91 &DataBits,
92 &StopBits
93 );
94 if (RETURN_ERROR (Status)) {
95 goto Failed;
96 }
97
98 mSerialBaseAddress = SerialBaseAddress;
99 return RETURN_SUCCESS;
100
101Failed:
102 mPermanentStatus = Status;
103 return Status;
104}
105
116UINTN
117EFIAPI
119 IN UINT8 *Buffer,
120 IN UINTN NumberOfBytes
121 )
122{
124 return PL011UartWrite (mSerialBaseAddress, Buffer, NumberOfBytes);
125 }
126
127 return 0;
128}
129
140UINTN
141EFIAPI
143 OUT UINT8 *Buffer,
144 IN UINTN NumberOfBytes
145 )
146{
148 return PL011UartRead (mSerialBaseAddress, Buffer, NumberOfBytes);
149 }
150
151 return 0;
152}
153
161BOOLEAN
162EFIAPI
164 VOID
165 )
166{
168 return PL011UartPoll (mSerialBaseAddress);
169 }
170
171 return FALSE;
172}
173
207RETURN_STATUS
208EFIAPI
210 IN OUT UINT64 *BaudRate,
211 IN OUT UINT32 *ReceiveFifoDepth,
212 IN OUT UINT32 *Timeout,
213 IN OUT EFI_PARITY_TYPE *Parity,
214 IN OUT UINT8 *DataBits,
215 IN OUT EFI_STOP_BITS_TYPE *StopBits
216 )
217{
218 RETURN_STATUS Status;
219
221 Status = RETURN_UNSUPPORTED;
222 } else {
223 Status = PL011UartInitializePort (
224 mSerialBaseAddress,
225 FixedPcdGet32 (PL011UartClkInHz),
226 BaudRate,
227 ReceiveFifoDepth,
228 Parity,
229 DataBits,
230 StopBits
231 );
232 }
233
234 return Status;
235}
236
247RETURN_STATUS
248EFIAPI
250 IN UINT32 Control
251 )
252{
253 RETURN_STATUS Status;
254
256 Status = RETURN_UNSUPPORTED;
257 } else {
258 Status = PL011UartSetControl (mSerialBaseAddress, Control);
259 }
260
261 return Status;
262}
263
274RETURN_STATUS
275EFIAPI
277 OUT UINT32 *Control
278 )
279{
280 RETURN_STATUS Status;
281
283 Status = RETURN_UNSUPPORTED;
284 } else {
285 Status = PL011UartGetControl (mSerialBaseAddress, Control);
286 }
287
288 return Status;
289}
UINT64 UINTN
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
Definition: HobLib.c:215
BOOLEAN EFIAPI SerialPortPoll(VOID)
RETURN_STATUS EFIAPI SerialPortSetAttributes(IN OUT UINT64 *BaudRate, IN OUT UINT32 *ReceiveFifoDepth, IN OUT UINT32 *Timeout, IN OUT EFI_PARITY_TYPE *Parity, IN OUT UINT8 *DataBits, IN OUT EFI_STOP_BITS_TYPE *StopBits)
UINTN EFIAPI SerialPortRead(OUT UINT8 *Buffer, IN UINTN NumberOfBytes)
RETURN_STATUS EFIAPI SerialPortInitialize(VOID)
RETURN_STATUS EFIAPI SerialPortSetControl(IN UINT32 Control)
RETURN_STATUS EFIAPI SerialPortGetControl(OUT UINT32 *Control)
UINTN EFIAPI SerialPortWrite(IN UINT8 *Buffer, IN UINTN NumberOfBytes)
#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_UNSUPPORTED
Definition: Base.h:1081
#define RETURN_SUCCESS
Definition: Base.h:1066
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
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
RETURN_STATUS EFIAPI PL011UartSetControl(IN UINTN UartBase, IN UINT32 Control)
Definition: PL011UartLib.c:270
UINTN EFIAPI PL011UartWrite(IN UINTN UartBase, IN UINT8 *Buffer, IN UINTN NumberOfBytes)
Definition: PL011UartLib.c:417
UINTN EFIAPI PL011UartRead(IN UINTN UartBase, OUT UINT8 *Buffer, IN UINTN NumberOfBytes)
Definition: PL011UartLib.c:448
BOOLEAN EFIAPI PL011UartPoll(IN UINTN UartBase)
Definition: PL011UartLib.c:475
RETURN_STATUS EFIAPI PL011UartGetControl(IN UINTN UartBase, OUT UINT32 *Control)
Definition: PL011UartLib.c:347
#define PcdGet64(TokenName)
Definition: PcdLib.h:375
#define FixedPcdGet32(TokenName)
Definition: PcdLib.h:92
#define PcdGet8(TokenName)
Definition: PcdLib.h:336
EFI_STOP_BITS_TYPE
Definition: SerialIo.h:53
EFI_PARITY_TYPE
Definition: SerialIo.h:41