]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.c
ArmVirtPkg: Use SerialDxe in MdeModulePkg instead of EmbeddedPkg
[mirror_edk2.git] / ArmVirtPkg / Library / FdtPL011SerialPortLib / FdtPL011SerialPortLib.c
CommitLineData
f1f0ba19
LE
1/** @file\r
2 Serial I/O Port library functions with base address discovered from FDT\r
3\r
4 Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
5 Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>\r
6 Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>\r
7 Copyright (c) 2014, Red Hat, Inc.<BR>\r
ad7f6bc2 8 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
f1f0ba19
LE
9\r
10 This program and the accompanying materials\r
11 are licensed and made available under the terms and conditions of the BSD License\r
12 which accompanies this distribution. The full text of the license may be found at\r
13 http://opensource.org/licenses/bsd-license.php\r
14\r
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
16 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
17\r
18**/\r
19\r
20#include <Base.h>\r
21\r
22#include <Library/PcdLib.h>\r
23#include <Library/SerialPortLib.h>\r
24#include <Pi/PiBootMode.h>\r
25#include <Uefi/UefiBaseType.h>\r
26#include <Uefi/UefiMultiPhase.h>\r
27#include <Pi/PiHob.h>\r
28#include <Library/HobLib.h>\r
29#include <Guid/EarlyPL011BaseAddress.h>\r
30\r
31#include <Drivers/PL011Uart.h>\r
32\r
33STATIC UINTN mSerialBaseAddress;\r
34\r
35RETURN_STATUS\r
36EFIAPI\r
37SerialPortInitialize (\r
38 VOID\r
39 )\r
40{\r
41 return RETURN_SUCCESS;\r
42}\r
43\r
44/**\r
45\r
46 Program hardware of Serial port\r
47\r
48 @return RETURN_NOT_FOUND if no PL011 base address could be found\r
49 Otherwise, result of PL011UartInitializePort () is returned\r
50\r
51**/\r
52RETURN_STATUS\r
53EFIAPI\r
54FdtPL011SerialPortLibInitialize (\r
55 VOID\r
56 )\r
57{\r
58 VOID *Hob;\r
59 CONST UINT64 *UartBase;\r
60 UINT64 BaudRate;\r
61 UINT32 ReceiveFifoDepth;\r
62 EFI_PARITY_TYPE Parity;\r
63 UINT8 DataBits;\r
64 EFI_STOP_BITS_TYPE StopBits;\r
65\r
66 Hob = GetFirstGuidHob (&gEarlyPL011BaseAddressGuid);\r
67 if (Hob == NULL || GET_GUID_HOB_DATA_SIZE (Hob) != sizeof *UartBase) {\r
68 return RETURN_NOT_FOUND;\r
69 }\r
70 UartBase = GET_GUID_HOB_DATA (Hob);\r
71\r
72 mSerialBaseAddress = (UINTN)*UartBase;\r
73 if (mSerialBaseAddress == 0) {\r
74 return RETURN_NOT_FOUND;\r
75 }\r
76\r
77 BaudRate = (UINTN)PcdGet64 (PcdUartDefaultBaudRate);\r
78 ReceiveFifoDepth = 0; // Use the default value for Fifo depth\r
79 Parity = (EFI_PARITY_TYPE)PcdGet8 (PcdUartDefaultParity);\r
80 DataBits = PcdGet8 (PcdUartDefaultDataBits);\r
81 StopBits = (EFI_STOP_BITS_TYPE) PcdGet8 (PcdUartDefaultStopBits);\r
82\r
83 return PL011UartInitializePort (\r
84 mSerialBaseAddress, &BaudRate, &ReceiveFifoDepth,\r
85 &Parity, &DataBits, &StopBits);\r
86}\r
87\r
88/**\r
89 Write data to serial device.\r
90\r
91 @param Buffer Point of data buffer which need to be written.\r
92 @param NumberOfBytes Number of output bytes which are cached in Buffer.\r
93\r
94 @retval 0 Write data failed.\r
95 @retval !0 Actual number of bytes written to serial device.\r
96\r
97**/\r
98UINTN\r
99EFIAPI\r
100SerialPortWrite (\r
101 IN UINT8 *Buffer,\r
102 IN UINTN NumberOfBytes\r
103 )\r
104{\r
105 if (mSerialBaseAddress != 0) {\r
106 return PL011UartWrite (mSerialBaseAddress, Buffer, NumberOfBytes);\r
107 }\r
108 return 0;\r
109}\r
110\r
111/**\r
112 Read data from serial device and save the data in buffer.\r
113\r
114 @param Buffer Point of data buffer which need to be written.\r
115 @param NumberOfBytes Number of output bytes which are cached in Buffer.\r
116\r
117 @retval 0 Read data failed.\r
118 @retval !0 Actual number of bytes read from serial device.\r
119\r
120**/\r
121UINTN\r
122EFIAPI\r
123SerialPortRead (\r
124 OUT UINT8 *Buffer,\r
125 IN UINTN NumberOfBytes\r
126)\r
127{\r
128 if (mSerialBaseAddress != 0) {\r
129 return PL011UartRead (mSerialBaseAddress, Buffer, NumberOfBytes);\r
130 }\r
131 return 0;\r
132}\r
133\r
134/**\r
135 Check to see if any data is available to be read from the debug device.\r
136\r
137 @retval TRUE At least one byte of data is available to be read\r
138 @retval FALSE No data is available to be read\r
139\r
140**/\r
141BOOLEAN\r
142EFIAPI\r
143SerialPortPoll (\r
144 VOID\r
145 )\r
146{\r
147 if (mSerialBaseAddress != 0) {\r
148 return PL011UartPoll (mSerialBaseAddress);\r
149 }\r
150 return FALSE;\r
151}\r
ad7f6bc2
SZ
152\r
153/**\r
154 Sets the baud rate, receive FIFO depth, transmit/receice time out, parity,\r
155 data bits, and stop bits on a serial device.\r
156\r
157 @param BaudRate The requested baud rate. A BaudRate value of 0 will use the\r
158 device's default interface speed.\r
159 On output, the value actually set.\r
160 @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the\r
161 serial interface. A ReceiveFifoDepth value of 0 will use\r
162 the device's default FIFO depth.\r
163 On output, the value actually set.\r
164 @param Timeout The requested time out for a single character in microseconds.\r
165 This timeout applies to both the transmit and receive side of the\r
166 interface. A Timeout value of 0 will use the device's default time\r
167 out value.\r
168 On output, the value actually set.\r
169 @param Parity The type of parity to use on this serial device. A Parity value of\r
170 DefaultParity will use the device's default parity value.\r
171 On output, the value actually set.\r
172 @param DataBits The number of data bits to use on the serial device. A DataBits\r
173 vaule of 0 will use the device's default data bit setting.\r
174 On output, the value actually set.\r
175 @param StopBits The number of stop bits to use on this serial device. A StopBits\r
176 value of DefaultStopBits will use the device's default number of\r
177 stop bits.\r
178 On output, the value actually set.\r
179\r
180 @retval RETURN_SUCCESS The new attributes were set on the serial device.\r
181 @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r
182 @retval RETURN_INVALID_PARAMETER One or more of the attributes has an unsupported value.\r
183 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r
184\r
185**/\r
186RETURN_STATUS\r
187EFIAPI\r
188SerialPortSetAttributes (\r
189 IN OUT UINT64 *BaudRate,\r
190 IN OUT UINT32 *ReceiveFifoDepth,\r
191 IN OUT UINT32 *Timeout,\r
192 IN OUT EFI_PARITY_TYPE *Parity,\r
193 IN OUT UINT8 *DataBits,\r
194 IN OUT EFI_STOP_BITS_TYPE *StopBits\r
195 )\r
196{\r
197 return RETURN_UNSUPPORTED;\r
198}\r
199\r
200/**\r
201 Sets the control bits on a serial device.\r
202\r
203 @param Control Sets the bits of Control that are settable.\r
204\r
205 @retval RETURN_SUCCESS The new control bits were set on the serial device.\r
206 @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r
207 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r
208\r
209**/\r
210RETURN_STATUS\r
211EFIAPI\r
212SerialPortSetControl (\r
213 IN UINT32 Control\r
214 )\r
215{\r
216 return RETURN_UNSUPPORTED;\r
217}\r
218\r
219/**\r
220 Retrieve the status of the control bits on a serial device.\r
221\r
222 @param Control A pointer to return the current control signals from the serial device.\r
223\r
224 @retval RETURN_SUCCESS The control bits were read from the serial device.\r
225 @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r
226 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r
227\r
228**/\r
229RETURN_STATUS\r
230EFIAPI\r
231SerialPortGetControl (\r
232 OUT UINT32 *Control\r
233 )\r
234{\r
235 return RETURN_UNSUPPORTED;\r
236}\r
237\r