TianoCore EDK2 master
Loading...
Searching...
No Matches
EarlyFdtPL011SerialPortLib.c
Go to the documentation of this file.
1
13#include <Base.h>
14
15#include <Library/PcdLib.h>
19
20RETURN_STATUS
21EFIAPI
23 VOID
24 )
25{
26 //
27 // This SerialPortInitialize() function is completely empty, for a number of
28 // reasons:
29 // - if we are executing from flash, it is hard to keep state (i.e., store the
30 // discovered base address in a global), and the most robust way to deal
31 // with this is to discover the base address at every Write ();
32 // - calls to the Write() function in this module may be issued before this
33 // initialization function is called: this is not a problem when the base
34 // address of the UART is hardcoded, and only the baud rate may be wrong,
35 // but if we don't know the base address yet, we may be poking into memory
36 // that does not tolerate being poked into;
37 // - SEC and PEI phases produce debug output only, so with debug disabled, no
38 // initialization (or device tree parsing) is performed at all.
39 //
40 // Note that this means that on *every* Write () call, the device tree will be
41 // parsed and the UART re-initialized. However, this is a small price to pay
42 // for having serial debug output on a UART with no fixed base address.
43 //
44 return RETURN_SUCCESS;
45}
46
48UINT64
49SerialPortGetBaseAddress (
50 VOID
51 )
52{
53 UINT64 BaudRate;
54 UINT32 ReceiveFifoDepth;
55 EFI_PARITY_TYPE Parity;
56 UINT8 DataBits;
57 EFI_STOP_BITS_TYPE StopBits;
58 VOID *DeviceTreeBase;
59 FDT_SERIAL_PORTS Ports;
60 UINT64 UartBase;
61 RETURN_STATUS Status;
62
63 DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);
64
65 if (DeviceTreeBase == NULL) {
66 return 0;
67 }
68
69 Status = FdtSerialGetPorts (DeviceTreeBase, "arm,pl011", &Ports);
70 if (RETURN_ERROR (Status)) {
71 return 0;
72 }
73
74 //
75 // Default to the first port found, but (if there are multiple ports) allow
76 // the "/chosen" node to override it. Note that if FdtSerialGetConsolePort()
77 // fails, it does not modify UartBase.
78 //
79 UartBase = Ports.BaseAddress[0];
80 if (Ports.NumberOfPorts > 1) {
81 FdtSerialGetConsolePort (DeviceTreeBase, &UartBase);
82 }
83
84 BaudRate = (UINTN)FixedPcdGet64 (PcdUartDefaultBaudRate);
85 ReceiveFifoDepth = 0; // Use the default value for Fifo depth
86 Parity = (EFI_PARITY_TYPE)FixedPcdGet8 (PcdUartDefaultParity);
87 DataBits = FixedPcdGet8 (PcdUartDefaultDataBits);
88 StopBits = (EFI_STOP_BITS_TYPE)FixedPcdGet8 (PcdUartDefaultStopBits);
89
91 UartBase,
92 FixedPcdGet32 (PL011UartClkInHz),
93 &BaudRate,
94 &ReceiveFifoDepth,
95 &Parity,
96 &DataBits,
97 &StopBits
98 );
99 if (!RETURN_ERROR (Status)) {
100 return UartBase;
101 }
102
103 return 0;
104}
105
116UINTN
117EFIAPI
119 IN UINT8 *Buffer,
120 IN UINTN NumberOfBytes
121 )
122{
123 UINT64 SerialRegisterBase;
124
125 SerialRegisterBase = SerialPortGetBaseAddress ();
126 if (SerialRegisterBase != 0) {
127 return PL011UartWrite ((UINTN)SerialRegisterBase, Buffer, NumberOfBytes);
128 }
129
130 return 0;
131}
132
143UINTN
144EFIAPI
146 OUT UINT8 *Buffer,
147 IN UINTN NumberOfBytes
148 )
149{
150 return 0;
151}
152
160BOOLEAN
161EFIAPI
163 VOID
164 )
165{
166 return FALSE;
167}
168
179RETURN_STATUS
180EFIAPI
182 IN UINT32 Control
183 )
184{
185 return RETURN_UNSUPPORTED;
186}
187
198RETURN_STATUS
199EFIAPI
201 OUT UINT32 *Control
202 )
203{
204 return RETURN_UNSUPPORTED;
205}
206
240RETURN_STATUS
241EFIAPI
243 IN OUT UINT64 *BaudRate,
244 IN OUT UINT32 *ReceiveFifoDepth,
245 IN OUT UINT32 *Timeout,
246 IN OUT EFI_PARITY_TYPE *Parity,
247 IN OUT UINT8 *DataBits,
248 IN OUT EFI_STOP_BITS_TYPE *StopBits
249 )
250{
251 return RETURN_UNSUPPORTED;
252}
UINT64 UINTN
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)
RETURN_STATUS EFIAPI FdtSerialGetConsolePort(IN CONST VOID *DeviceTree, OUT UINT64 *BaseAddress)
RETURN_STATUS EFIAPI FdtSerialGetPorts(IN CONST VOID *DeviceTree, IN CONST CHAR8 *Compatible, OUT FDT_SERIAL_PORTS *Ports)
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define RETURN_ERROR(StatusCode)
Definition: Base.h:1061
#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
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 FixedPcdGet64(TokenName)
Definition: PcdLib.h:106
#define FixedPcdGet8(TokenName)
Definition: PcdLib.h:64
EFI_STOP_BITS_TYPE
Definition: SerialIo.h:53
EFI_PARITY_TYPE
Definition: SerialIo.h:41