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>
9 This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #include <Library/PcdLib.h>
22 #include <Library/SerialPortLib.h>
23 #include <Pi/PiBootMode.h>
24 #include <Uefi/UefiBaseType.h>
25 #include <Uefi/UefiMultiPhase.h>
27 #include <Library/HobLib.h>
28 #include <Guid/EarlyPL011BaseAddress.h>
30 #include <Drivers/PL011Uart.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 (
83 mSerialBaseAddress
, &BaudRate
, &ReceiveFifoDepth
,
84 &Parity
, &DataBits
, &StopBits
);
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
);