]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.c
ArmVirtPkg: Fix various typos
[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
1195b857 23#include <Library/PL011UartLib.h>\r
f1f0ba19
LE
24#include <Library/SerialPortLib.h>\r
25#include <Pi/PiBootMode.h>\r
26#include <Uefi/UefiBaseType.h>\r
27#include <Uefi/UefiMultiPhase.h>\r
28#include <Pi/PiHob.h>\r
29#include <Library/HobLib.h>\r
30#include <Guid/EarlyPL011BaseAddress.h>\r
31\r
f1f0ba19
LE
32STATIC UINTN mSerialBaseAddress;\r
33\r
34RETURN_STATUS\r
35EFIAPI\r
36SerialPortInitialize (\r
37 VOID\r
38 )\r
39{\r
40 return RETURN_SUCCESS;\r
41}\r
42\r
43/**\r
44\r
45 Program hardware of Serial port\r
46\r
47 @return RETURN_NOT_FOUND if no PL011 base address could be found\r
48 Otherwise, result of PL011UartInitializePort () is returned\r
49\r
50**/\r
51RETURN_STATUS\r
52EFIAPI\r
53FdtPL011SerialPortLibInitialize (\r
54 VOID\r
55 )\r
56{\r
57 VOID *Hob;\r
58 CONST UINT64 *UartBase;\r
59 UINT64 BaudRate;\r
60 UINT32 ReceiveFifoDepth;\r
61 EFI_PARITY_TYPE Parity;\r
62 UINT8 DataBits;\r
63 EFI_STOP_BITS_TYPE StopBits;\r
64\r
65 Hob = GetFirstGuidHob (&gEarlyPL011BaseAddressGuid);\r
66 if (Hob == NULL || GET_GUID_HOB_DATA_SIZE (Hob) != sizeof *UartBase) {\r
67 return RETURN_NOT_FOUND;\r
68 }\r
69 UartBase = GET_GUID_HOB_DATA (Hob);\r
70\r
71 mSerialBaseAddress = (UINTN)*UartBase;\r
72 if (mSerialBaseAddress == 0) {\r
73 return RETURN_NOT_FOUND;\r
74 }\r
75\r
76 BaudRate = (UINTN)PcdGet64 (PcdUartDefaultBaudRate);\r
77 ReceiveFifoDepth = 0; // Use the default value for Fifo depth\r
78 Parity = (EFI_PARITY_TYPE)PcdGet8 (PcdUartDefaultParity);\r
79 DataBits = PcdGet8 (PcdUartDefaultDataBits);\r
80 StopBits = (EFI_STOP_BITS_TYPE) PcdGet8 (PcdUartDefaultStopBits);\r
81\r
82 return PL011UartInitializePort (\r
090916d8
EL
83 mSerialBaseAddress,\r
84 FixedPcdGet32 (PL011UartClkInHz),\r
85 &BaudRate,\r
86 &ReceiveFifoDepth,\r
87 &Parity,\r
88 &DataBits,\r
89 &StopBits\r
90 );\r
f1f0ba19
LE
91}\r
92\r
93/**\r
94 Write data to serial device.\r
95\r
96 @param Buffer Point of data buffer which need to be written.\r
97 @param NumberOfBytes Number of output bytes which are cached in Buffer.\r
98\r
99 @retval 0 Write data failed.\r
100 @retval !0 Actual number of bytes written to serial device.\r
101\r
102**/\r
103UINTN\r
104EFIAPI\r
105SerialPortWrite (\r
106 IN UINT8 *Buffer,\r
107 IN UINTN NumberOfBytes\r
108 )\r
109{\r
110 if (mSerialBaseAddress != 0) {\r
111 return PL011UartWrite (mSerialBaseAddress, Buffer, NumberOfBytes);\r
112 }\r
113 return 0;\r
114}\r
115\r
116/**\r
117 Read data from serial device and save the data in buffer.\r
118\r
119 @param Buffer Point of data buffer which need to be written.\r
120 @param NumberOfBytes Number of output bytes which are cached in Buffer.\r
121\r
122 @retval 0 Read data failed.\r
123 @retval !0 Actual number of bytes read from serial device.\r
124\r
125**/\r
126UINTN\r
127EFIAPI\r
128SerialPortRead (\r
129 OUT UINT8 *Buffer,\r
130 IN UINTN NumberOfBytes\r
131)\r
132{\r
133 if (mSerialBaseAddress != 0) {\r
134 return PL011UartRead (mSerialBaseAddress, Buffer, NumberOfBytes);\r
135 }\r
136 return 0;\r
137}\r
138\r
139/**\r
140 Check to see if any data is available to be read from the debug device.\r
141\r
142 @retval TRUE At least one byte of data is available to be read\r
143 @retval FALSE No data is available to be read\r
144\r
145**/\r
146BOOLEAN\r
147EFIAPI\r
148SerialPortPoll (\r
149 VOID\r
150 )\r
151{\r
152 if (mSerialBaseAddress != 0) {\r
153 return PL011UartPoll (mSerialBaseAddress);\r
154 }\r
155 return FALSE;\r
156}\r
ad7f6bc2
SZ
157\r
158/**\r
7a908953 159 Sets the baud rate, receive FIFO depth, transmit/receive time out, parity,\r
ad7f6bc2
SZ
160 data bits, and stop bits on a serial device.\r
161\r
162 @param BaudRate The requested baud rate. A BaudRate value of 0 will use the\r
163 device's default interface speed.\r
164 On output, the value actually set.\r
7a908953 165 @param ReceiveFifoDepth The requested depth of the FIFO on the receive side of the\r
ad7f6bc2
SZ
166 serial interface. A ReceiveFifoDepth value of 0 will use\r
167 the device's default FIFO depth.\r
168 On output, the value actually set.\r
169 @param Timeout The requested time out for a single character in microseconds.\r
170 This timeout applies to both the transmit and receive side of the\r
171 interface. A Timeout value of 0 will use the device's default time\r
172 out value.\r
173 On output, the value actually set.\r
174 @param Parity The type of parity to use on this serial device. A Parity value of\r
175 DefaultParity will use the device's default parity value.\r
176 On output, the value actually set.\r
177 @param DataBits The number of data bits to use on the serial device. A DataBits\r
7a908953 178 value of 0 will use the device's default data bit setting.\r
ad7f6bc2
SZ
179 On output, the value actually set.\r
180 @param StopBits The number of stop bits to use on this serial device. A StopBits\r
181 value of DefaultStopBits will use the device's default number of\r
182 stop bits.\r
183 On output, the value actually set.\r
184\r
185 @retval RETURN_SUCCESS The new attributes were set on the serial device.\r
186 @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r
187 @retval RETURN_INVALID_PARAMETER One or more of the attributes has an unsupported value.\r
188 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r
189\r
190**/\r
191RETURN_STATUS\r
192EFIAPI\r
193SerialPortSetAttributes (\r
194 IN OUT UINT64 *BaudRate,\r
195 IN OUT UINT32 *ReceiveFifoDepth,\r
196 IN OUT UINT32 *Timeout,\r
197 IN OUT EFI_PARITY_TYPE *Parity,\r
198 IN OUT UINT8 *DataBits,\r
199 IN OUT EFI_STOP_BITS_TYPE *StopBits\r
200 )\r
201{\r
5f0f5e90
LE
202 RETURN_STATUS Status;\r
203\r
204 if (mSerialBaseAddress == 0) {\r
205 Status = RETURN_UNSUPPORTED;\r
206 } else {\r
207 Status = PL011UartInitializePort (\r
208 mSerialBaseAddress,\r
209 FixedPcdGet32 (PL011UartClkInHz),\r
210 BaudRate,\r
211 ReceiveFifoDepth,\r
212 Parity,\r
213 DataBits,\r
214 StopBits\r
215 );\r
216 }\r
217\r
218 return Status;\r
ad7f6bc2
SZ
219}\r
220\r
221/**\r
222 Sets the control bits on a serial device.\r
223\r
224 @param Control Sets the bits of Control that are settable.\r
225\r
226 @retval RETURN_SUCCESS The new control bits were set on the serial device.\r
227 @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r
228 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r
229\r
230**/\r
231RETURN_STATUS\r
232EFIAPI\r
233SerialPortSetControl (\r
234 IN UINT32 Control\r
235 )\r
236{\r
5f0f5e90
LE
237 RETURN_STATUS Status;\r
238\r
239 if (mSerialBaseAddress == 0) {\r
240 Status = RETURN_UNSUPPORTED;\r
241 } else {\r
242 Status = PL011UartSetControl (mSerialBaseAddress, Control);\r
243 }\r
244\r
245 return Status;\r
ad7f6bc2
SZ
246}\r
247\r
248/**\r
249 Retrieve the status of the control bits on a serial device.\r
250\r
251 @param Control A pointer to return the current control signals from the serial device.\r
252\r
253 @retval RETURN_SUCCESS The control bits were read from the serial device.\r
254 @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r
255 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r
256\r
257**/\r
258RETURN_STATUS\r
259EFIAPI\r
260SerialPortGetControl (\r
261 OUT UINT32 *Control\r
262 )\r
263{\r
5f0f5e90
LE
264 RETURN_STATUS Status;\r
265\r
266 if (mSerialBaseAddress == 0) {\r
267 Status = RETURN_UNSUPPORTED;\r
268 } else {\r
269 Status = PL011UartGetControl (mSerialBaseAddress, Control);\r
270 }\r
271\r
272 return Status;\r
ad7f6bc2
SZ
273}\r
274\r