2 Serial I/O Port library functions with base address discovered from FDT
4 Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
5 Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>
6 Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
7 Copyright (c) 2014, Red Hat, Inc.<BR>
8 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
10 SPDX-License-Identifier: BSD-2-Clause-Patent
16 #include <Library/PcdLib.h>
17 #include <Library/PL011UartLib.h>
18 #include <Library/SerialPortLib.h>
19 #include <Pi/PiBootMode.h>
20 #include <Uefi/UefiBaseType.h>
21 #include <Uefi/UefiMultiPhase.h>
23 #include <Library/HobLib.h>
24 #include <Guid/EarlyPL011BaseAddress.h>
26 STATIC UINTN mSerialBaseAddress
;
30 SerialPortInitialize (
34 return RETURN_SUCCESS
;
39 Program hardware of Serial port
41 @return RETURN_NOT_FOUND if no PL011 base address could be found
42 Otherwise, result of PL011UartInitializePort () is returned
47 FdtPL011SerialPortLibInitialize (
52 CONST UINT64
*UartBase
;
54 UINT32 ReceiveFifoDepth
;
55 EFI_PARITY_TYPE Parity
;
57 EFI_STOP_BITS_TYPE StopBits
;
59 Hob
= GetFirstGuidHob (&gEarlyPL011BaseAddressGuid
);
60 if (Hob
== NULL
|| GET_GUID_HOB_DATA_SIZE (Hob
) != sizeof *UartBase
) {
61 return RETURN_NOT_FOUND
;
63 UartBase
= GET_GUID_HOB_DATA (Hob
);
65 mSerialBaseAddress
= (UINTN
)*UartBase
;
66 if (mSerialBaseAddress
== 0) {
67 return RETURN_NOT_FOUND
;
70 BaudRate
= (UINTN
)PcdGet64 (PcdUartDefaultBaudRate
);
71 ReceiveFifoDepth
= 0; // Use the default value for Fifo depth
72 Parity
= (EFI_PARITY_TYPE
)PcdGet8 (PcdUartDefaultParity
);
73 DataBits
= PcdGet8 (PcdUartDefaultDataBits
);
74 StopBits
= (EFI_STOP_BITS_TYPE
) PcdGet8 (PcdUartDefaultStopBits
);
76 return PL011UartInitializePort (
78 FixedPcdGet32 (PL011UartClkInHz
),
88 Write data to serial device.
90 @param Buffer Point of data buffer which need to be written.
91 @param NumberOfBytes Number of output bytes which are cached in Buffer.
93 @retval 0 Write data failed.
94 @retval !0 Actual number of bytes written to serial device.
101 IN UINTN NumberOfBytes
104 if (mSerialBaseAddress
!= 0) {
105 return PL011UartWrite (mSerialBaseAddress
, Buffer
, NumberOfBytes
);
111 Read data from serial device and save the data in buffer.
113 @param Buffer Point of data buffer which need to be written.
114 @param NumberOfBytes Number of output bytes which are cached in Buffer.
116 @retval 0 Read data failed.
117 @retval !0 Actual number of bytes read from serial device.
124 IN UINTN NumberOfBytes
127 if (mSerialBaseAddress
!= 0) {
128 return PL011UartRead (mSerialBaseAddress
, Buffer
, NumberOfBytes
);
134 Check to see if any data is available to be read from the debug device.
136 @retval TRUE At least one byte of data is available to be read
137 @retval FALSE No data is available to be read
146 if (mSerialBaseAddress
!= 0) {
147 return PL011UartPoll (mSerialBaseAddress
);
153 Sets the baud rate, receive FIFO depth, transmit/receive time out, parity,
154 data bits, and stop bits on a serial device.
156 @param BaudRate The requested baud rate. A BaudRate value of 0 will use the
157 device's default interface speed.
158 On output, the value actually set.
159 @param ReceiveFifoDepth The requested depth of the FIFO on the receive side of the
160 serial interface. A ReceiveFifoDepth value of 0 will use
161 the device's default FIFO depth.
162 On output, the value actually set.
163 @param Timeout The requested time out for a single character in microseconds.
164 This timeout applies to both the transmit and receive side of the
165 interface. A Timeout value of 0 will use the device's default time
167 On output, the value actually set.
168 @param Parity The type of parity to use on this serial device. A Parity value of
169 DefaultParity will use the device's default parity value.
170 On output, the value actually set.
171 @param DataBits The number of data bits to use on the serial device. A DataBits
172 value of 0 will use the device's default data bit setting.
173 On output, the value actually set.
174 @param StopBits The number of stop bits to use on this serial device. A StopBits
175 value of DefaultStopBits will use the device's default number of
177 On output, the value actually set.
179 @retval RETURN_SUCCESS The new attributes were set on the serial device.
180 @retval RETURN_UNSUPPORTED The serial device does not support this operation.
181 @retval RETURN_INVALID_PARAMETER One or more of the attributes has an unsupported value.
182 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
187 SerialPortSetAttributes (
188 IN OUT UINT64
*BaudRate
,
189 IN OUT UINT32
*ReceiveFifoDepth
,
190 IN OUT UINT32
*Timeout
,
191 IN OUT EFI_PARITY_TYPE
*Parity
,
192 IN OUT UINT8
*DataBits
,
193 IN OUT EFI_STOP_BITS_TYPE
*StopBits
196 RETURN_STATUS Status
;
198 if (mSerialBaseAddress
== 0) {
199 Status
= RETURN_UNSUPPORTED
;
201 Status
= PL011UartInitializePort (
203 FixedPcdGet32 (PL011UartClkInHz
),
216 Sets the control bits on a serial device.
218 @param Control Sets the bits of Control that are settable.
220 @retval RETURN_SUCCESS The new control bits were set on the serial device.
221 @retval RETURN_UNSUPPORTED The serial device does not support this operation.
222 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
227 SerialPortSetControl (
231 RETURN_STATUS Status
;
233 if (mSerialBaseAddress
== 0) {
234 Status
= RETURN_UNSUPPORTED
;
236 Status
= PL011UartSetControl (mSerialBaseAddress
, Control
);
243 Retrieve the status of the control bits on a serial device.
245 @param Control A pointer to return the current control signals from the serial device.
247 @retval RETURN_SUCCESS The control bits were read from the serial device.
248 @retval RETURN_UNSUPPORTED The serial device does not support this operation.
249 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
254 SerialPortGetControl (
258 RETURN_STATUS Status
;
260 if (mSerialBaseAddress
== 0) {
261 Status
= RETURN_UNSUPPORTED
;
263 Status
= PL011UartGetControl (mSerialBaseAddress
, Control
);