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 This program and the accompanying materials
11 are licensed and made available under the terms and conditions of the BSD License
12 which accompanies this distribution. The full text of the license may be found at
13 http://opensource.org/licenses/bsd-license.php
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
16 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 #include <Library/PcdLib.h>
23 #include <Library/PL011UartLib.h>
24 #include <Library/SerialPortLib.h>
25 #include <Pi/PiBootMode.h>
26 #include <Uefi/UefiBaseType.h>
27 #include <Uefi/UefiMultiPhase.h>
29 #include <Library/HobLib.h>
30 #include <Guid/EarlyPL011BaseAddress.h>
32 STATIC UINTN mSerialBaseAddress
;
36 SerialPortInitialize (
40 return RETURN_SUCCESS
;
45 Program hardware of Serial port
47 @return RETURN_NOT_FOUND if no PL011 base address could be found
48 Otherwise, result of PL011UartInitializePort () is returned
53 FdtPL011SerialPortLibInitialize (
58 CONST UINT64
*UartBase
;
60 UINT32 ReceiveFifoDepth
;
61 EFI_PARITY_TYPE Parity
;
63 EFI_STOP_BITS_TYPE StopBits
;
65 Hob
= GetFirstGuidHob (&gEarlyPL011BaseAddressGuid
);
66 if (Hob
== NULL
|| GET_GUID_HOB_DATA_SIZE (Hob
) != sizeof *UartBase
) {
67 return RETURN_NOT_FOUND
;
69 UartBase
= GET_GUID_HOB_DATA (Hob
);
71 mSerialBaseAddress
= (UINTN
)*UartBase
;
72 if (mSerialBaseAddress
== 0) {
73 return RETURN_NOT_FOUND
;
76 BaudRate
= (UINTN
)PcdGet64 (PcdUartDefaultBaudRate
);
77 ReceiveFifoDepth
= 0; // Use the default value for Fifo depth
78 Parity
= (EFI_PARITY_TYPE
)PcdGet8 (PcdUartDefaultParity
);
79 DataBits
= PcdGet8 (PcdUartDefaultDataBits
);
80 StopBits
= (EFI_STOP_BITS_TYPE
) PcdGet8 (PcdUartDefaultStopBits
);
82 return PL011UartInitializePort (
84 FixedPcdGet32 (PL011UartClkInHz
),
94 Write data to serial device.
96 @param Buffer Point of data buffer which need to be written.
97 @param NumberOfBytes Number of output bytes which are cached in Buffer.
99 @retval 0 Write data failed.
100 @retval !0 Actual number of bytes written to serial device.
107 IN UINTN NumberOfBytes
110 if (mSerialBaseAddress
!= 0) {
111 return PL011UartWrite (mSerialBaseAddress
, Buffer
, NumberOfBytes
);
117 Read data from serial device and save the data in buffer.
119 @param Buffer Point of data buffer which need to be written.
120 @param NumberOfBytes Number of output bytes which are cached in Buffer.
122 @retval 0 Read data failed.
123 @retval !0 Actual number of bytes read from serial device.
130 IN UINTN NumberOfBytes
133 if (mSerialBaseAddress
!= 0) {
134 return PL011UartRead (mSerialBaseAddress
, Buffer
, NumberOfBytes
);
140 Check to see if any data is available to be read from the debug device.
142 @retval TRUE At least one byte of data is available to be read
143 @retval FALSE No data is available to be read
152 if (mSerialBaseAddress
!= 0) {
153 return PL011UartPoll (mSerialBaseAddress
);
159 Sets the baud rate, receive FIFO depth, transmit/receice time out, parity,
160 data bits, and stop bits on a serial device.
162 @param BaudRate The requested baud rate. A BaudRate value of 0 will use the
163 device's default interface speed.
164 On output, the value actually set.
165 @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the
166 serial interface. A ReceiveFifoDepth value of 0 will use
167 the device's default FIFO depth.
168 On output, the value actually set.
169 @param Timeout The requested time out for a single character in microseconds.
170 This timeout applies to both the transmit and receive side of the
171 interface. A Timeout value of 0 will use the device's default time
173 On output, the value actually set.
174 @param Parity The type of parity to use on this serial device. A Parity value of
175 DefaultParity will use the device's default parity value.
176 On output, the value actually set.
177 @param DataBits The number of data bits to use on the serial device. A DataBits
178 vaule of 0 will use the device's default data bit setting.
179 On output, the value actually set.
180 @param StopBits The number of stop bits to use on this serial device. A StopBits
181 value of DefaultStopBits will use the device's default number of
183 On output, the value actually set.
185 @retval RETURN_SUCCESS The new attributes were set on the serial device.
186 @retval RETURN_UNSUPPORTED The serial device does not support this operation.
187 @retval RETURN_INVALID_PARAMETER One or more of the attributes has an unsupported value.
188 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
193 SerialPortSetAttributes (
194 IN OUT UINT64
*BaudRate
,
195 IN OUT UINT32
*ReceiveFifoDepth
,
196 IN OUT UINT32
*Timeout
,
197 IN OUT EFI_PARITY_TYPE
*Parity
,
198 IN OUT UINT8
*DataBits
,
199 IN OUT EFI_STOP_BITS_TYPE
*StopBits
202 RETURN_STATUS Status
;
204 if (mSerialBaseAddress
== 0) {
205 Status
= RETURN_UNSUPPORTED
;
207 Status
= PL011UartInitializePort (
209 FixedPcdGet32 (PL011UartClkInHz
),
222 Sets the control bits on a serial device.
224 @param Control Sets the bits of Control that are settable.
226 @retval RETURN_SUCCESS The new control bits were set on the serial device.
227 @retval RETURN_UNSUPPORTED The serial device does not support this operation.
228 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
233 SerialPortSetControl (
237 RETURN_STATUS Status
;
239 if (mSerialBaseAddress
== 0) {
240 Status
= RETURN_UNSUPPORTED
;
242 Status
= PL011UartSetControl (mSerialBaseAddress
, Control
);
249 Retrieve the status of the control bits on a serial device.
251 @param Control A pointer to return the current control signals from the serial device.
253 @retval RETURN_SUCCESS The control bits were read from the serial device.
254 @retval RETURN_UNSUPPORTED The serial device does not support this operation.
255 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
260 SerialPortGetControl (
264 RETURN_STATUS Status
;
266 if (mSerialBaseAddress
== 0) {
267 Status
= RETURN_UNSUPPORTED
;
269 Status
= PL011UartGetControl (mSerialBaseAddress
, Control
);