]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.c
Omap35xxPkg/MMCHSDxe: fix device path initializer
[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
090916d8
EL
84 mSerialBaseAddress,\r
85 FixedPcdGet32 (PL011UartClkInHz),\r
86 &BaudRate,\r
87 &ReceiveFifoDepth,\r
88 &Parity,\r
89 &DataBits,\r
90 &StopBits\r
91 );\r
f1f0ba19
LE
92}\r
93\r
94/**\r
95 Write data to serial device.\r
96\r
97 @param Buffer Point of data buffer which need to be written.\r
98 @param NumberOfBytes Number of output bytes which are cached in Buffer.\r
99\r
100 @retval 0 Write data failed.\r
101 @retval !0 Actual number of bytes written to serial device.\r
102\r
103**/\r
104UINTN\r
105EFIAPI\r
106SerialPortWrite (\r
107 IN UINT8 *Buffer,\r
108 IN UINTN NumberOfBytes\r
109 )\r
110{\r
111 if (mSerialBaseAddress != 0) {\r
112 return PL011UartWrite (mSerialBaseAddress, Buffer, NumberOfBytes);\r
113 }\r
114 return 0;\r
115}\r
116\r
117/**\r
118 Read data from serial device and save the data in buffer.\r
119\r
120 @param Buffer Point of data buffer which need to be written.\r
121 @param NumberOfBytes Number of output bytes which are cached in Buffer.\r
122\r
123 @retval 0 Read data failed.\r
124 @retval !0 Actual number of bytes read from serial device.\r
125\r
126**/\r
127UINTN\r
128EFIAPI\r
129SerialPortRead (\r
130 OUT UINT8 *Buffer,\r
131 IN UINTN NumberOfBytes\r
132)\r
133{\r
134 if (mSerialBaseAddress != 0) {\r
135 return PL011UartRead (mSerialBaseAddress, Buffer, NumberOfBytes);\r
136 }\r
137 return 0;\r
138}\r
139\r
140/**\r
141 Check to see if any data is available to be read from the debug device.\r
142\r
143 @retval TRUE At least one byte of data is available to be read\r
144 @retval FALSE No data is available to be read\r
145\r
146**/\r
147BOOLEAN\r
148EFIAPI\r
149SerialPortPoll (\r
150 VOID\r
151 )\r
152{\r
153 if (mSerialBaseAddress != 0) {\r
154 return PL011UartPoll (mSerialBaseAddress);\r
155 }\r
156 return FALSE;\r
157}\r
ad7f6bc2
SZ
158\r
159/**\r
160 Sets the baud rate, receive FIFO depth, transmit/receice time out, parity,\r
161 data bits, and stop bits on a serial device.\r
162\r
163 @param BaudRate The requested baud rate. A BaudRate value of 0 will use the\r
164 device's default interface speed.\r
165 On output, the value actually set.\r
166 @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the\r
167 serial interface. A ReceiveFifoDepth value of 0 will use\r
168 the device's default FIFO depth.\r
169 On output, the value actually set.\r
170 @param Timeout The requested time out for a single character in microseconds.\r
171 This timeout applies to both the transmit and receive side of the\r
172 interface. A Timeout value of 0 will use the device's default time\r
173 out value.\r
174 On output, the value actually set.\r
175 @param Parity The type of parity to use on this serial device. A Parity value of\r
176 DefaultParity will use the device's default parity value.\r
177 On output, the value actually set.\r
178 @param DataBits The number of data bits to use on the serial device. A DataBits\r
179 vaule of 0 will use the device's default data bit setting.\r
180 On output, the value actually set.\r
181 @param StopBits The number of stop bits to use on this serial device. A StopBits\r
182 value of DefaultStopBits will use the device's default number of\r
183 stop bits.\r
184 On output, the value actually set.\r
185\r
186 @retval RETURN_SUCCESS The new attributes were set on the serial device.\r
187 @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r
188 @retval RETURN_INVALID_PARAMETER One or more of the attributes has an unsupported value.\r
189 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r
190\r
191**/\r
192RETURN_STATUS\r
193EFIAPI\r
194SerialPortSetAttributes (\r
195 IN OUT UINT64 *BaudRate,\r
196 IN OUT UINT32 *ReceiveFifoDepth,\r
197 IN OUT UINT32 *Timeout,\r
198 IN OUT EFI_PARITY_TYPE *Parity,\r
199 IN OUT UINT8 *DataBits,\r
200 IN OUT EFI_STOP_BITS_TYPE *StopBits\r
201 )\r
202{\r
203 return RETURN_UNSUPPORTED;\r
204}\r
205\r
206/**\r
207 Sets the control bits on a serial device.\r
208\r
209 @param Control Sets the bits of Control that are settable.\r
210\r
211 @retval RETURN_SUCCESS The new control bits were set on the serial device.\r
212 @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r
213 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r
214\r
215**/\r
216RETURN_STATUS\r
217EFIAPI\r
218SerialPortSetControl (\r
219 IN UINT32 Control\r
220 )\r
221{\r
222 return RETURN_UNSUPPORTED;\r
223}\r
224\r
225/**\r
226 Retrieve the status of the control bits on a serial device.\r
227\r
228 @param Control A pointer to return the current control signals from the serial device.\r
229\r
230 @retval RETURN_SUCCESS The control bits were read from the serial device.\r
231 @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r
232 @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r
233\r
234**/\r
235RETURN_STATUS\r
236EFIAPI\r
237SerialPortGetControl (\r
238 OUT UINT32 *Control\r
239 )\r
240{\r
241 return RETURN_UNSUPPORTED;\r
242}\r
243\r