]>
Commit | Line | Data |
---|---|---|
1e57a462 | 1 | /** @file\r |
2 | Serial I/O Port library functions with no library constructor/destructor\r | |
3 | \r | |
4 | Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r | |
921e987b SZ |
5 | Copyright (c) 2012 - 2014, ARM Ltd. All rights reserved.<BR>\r |
6 | Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r | |
3402aac7 | 7 | \r |
1e57a462 | 8 | This program and the accompanying materials\r |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
16 | **/\r | |
17 | \r | |
18 | #include <Base.h>\r | |
19 | \r | |
20 | #include <Library/IoLib.h>\r | |
21 | #include <Library/PcdLib.h>\r | |
22 | #include <Library/SerialPortLib.h>\r | |
1e57a462 | 23 | \r |
24 | #include <Drivers/PL011Uart.h>\r | |
25 | \r | |
26 | \r | |
27 | /**\r | |
28 | \r | |
29 | Programmed hardware of Serial port.\r | |
30 | \r | |
31 | @return Always return RETURN_UNSUPPORTED.\r | |
32 | \r | |
33 | **/\r | |
34 | RETURN_STATUS\r | |
35 | EFIAPI\r | |
36 | SerialPortInitialize (\r | |
37 | VOID\r | |
38 | )\r | |
39 | {\r | |
15e277d5 | 40 | UINT64 BaudRate;\r |
41 | UINT32 ReceiveFifoDepth;\r | |
42 | EFI_PARITY_TYPE Parity;\r | |
43 | UINT8 DataBits;\r | |
44 | EFI_STOP_BITS_TYPE StopBits;\r | |
45 | \r | |
46 | BaudRate = (UINTN)PcdGet64 (PcdUartDefaultBaudRate);\r | |
47 | ReceiveFifoDepth = 0; // Use the default value for Fifo depth\r | |
48 | Parity = (EFI_PARITY_TYPE)PcdGet8 (PcdUartDefaultParity);\r | |
49 | DataBits = PcdGet8 (PcdUartDefaultDataBits);\r | |
50 | StopBits = (EFI_STOP_BITS_TYPE) PcdGet8 (PcdUartDefaultStopBits);\r | |
51 | \r | |
1e57a462 | 52 | return PL011UartInitializePort (\r |
53 | (UINTN)PcdGet64 (PcdSerialRegisterBase),\r | |
15e277d5 | 54 | &BaudRate, &ReceiveFifoDepth, &Parity, &DataBits, &StopBits);\r |
1e57a462 | 55 | }\r |
56 | \r | |
57 | /**\r | |
58 | Write data to serial device.\r | |
59 | \r | |
60 | @param Buffer Point of data buffer which need to be written.\r | |
61 | @param NumberOfBytes Number of output bytes which are cached in Buffer.\r | |
62 | \r | |
63 | @retval 0 Write data failed.\r | |
64 | @retval !0 Actual number of bytes written to serial device.\r | |
65 | \r | |
66 | **/\r | |
67 | UINTN\r | |
68 | EFIAPI\r | |
69 | SerialPortWrite (\r | |
70 | IN UINT8 *Buffer,\r | |
71 | IN UINTN NumberOfBytes\r | |
72 | )\r | |
73 | {\r | |
74 | return PL011UartWrite ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);\r | |
75 | }\r | |
76 | \r | |
77 | /**\r | |
78 | Read data from serial device and save the data in buffer.\r | |
79 | \r | |
80 | @param Buffer Point of data buffer which need to be written.\r | |
81 | @param NumberOfBytes Number of output bytes which are cached in Buffer.\r | |
82 | \r | |
83 | @retval 0 Read data failed.\r | |
84 | @retval !0 Actual number of bytes read from serial device.\r | |
85 | \r | |
86 | **/\r | |
87 | UINTN\r | |
88 | EFIAPI\r | |
89 | SerialPortRead (\r | |
90 | OUT UINT8 *Buffer,\r | |
91 | IN UINTN NumberOfBytes\r | |
92 | )\r | |
93 | {\r | |
94 | return PL011UartRead ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);\r | |
95 | }\r | |
96 | \r | |
97 | /**\r | |
98 | Check to see if any data is available to be read from the debug device.\r | |
99 | \r | |
100 | @retval EFI_SUCCESS At least one byte of data is available to be read\r | |
101 | @retval EFI_NOT_READY No data is available to be read\r | |
102 | @retval EFI_DEVICE_ERROR The serial device is not functioning properly\r | |
103 | \r | |
104 | **/\r | |
105 | BOOLEAN\r | |
106 | EFIAPI\r | |
107 | SerialPortPoll (\r | |
108 | VOID\r | |
109 | )\r | |
110 | {\r | |
111 | return PL011UartPoll ((UINTN)PcdGet64 (PcdSerialRegisterBase));\r | |
112 | }\r | |
921e987b SZ |
113 | /**\r |
114 | Set new attributes to PL011.\r | |
115 | \r | |
116 | @param BaudRate The baud rate of the serial device. If the baud rate is not supported,\r | |
117 | the speed will be reduced down to the nearest supported one and the\r | |
118 | variable's value will be updated accordingly.\r | |
119 | @param ReceiveFifoDepth The number of characters the device will buffer on input. If the specified\r | |
120 | value is not supported, the variable's value will be reduced down to the\r | |
121 | nearest supported one.\r | |
122 | @param Timeout If applicable, the number of microseconds the device will wait\r | |
123 | before timing out a Read or a Write operation.\r | |
124 | @param Parity If applicable, this is the EFI_PARITY_TYPE that is computed or checked\r | |
125 | as each character is transmitted or received. If the device does not\r | |
126 | support parity, the value is the default parity value.\r | |
127 | @param DataBits The number of data bits in each character\r | |
128 | @param StopBits If applicable, the EFI_STOP_BITS_TYPE number of stop bits per character.\r | |
129 | If the device does not support stop bits, the value is the default stop\r | |
130 | bit value.\r | |
131 | \r | |
132 | @retval EFI_SUCCESS All attributes were set correctly on the serial device.\r | |
133 | @retval EFI_INVALID_PARAMETERS One or more of the attributes has an unsupported value.\r | |
134 | \r | |
135 | **/\r | |
136 | RETURN_STATUS\r | |
137 | EFIAPI\r | |
138 | SerialPortSetAttributes (\r | |
139 | IN OUT UINT64 *BaudRate,\r | |
140 | IN OUT UINT32 *ReceiveFifoDepth,\r | |
141 | IN OUT UINT32 *Timeout,\r | |
142 | IN OUT EFI_PARITY_TYPE *Parity,\r | |
143 | IN OUT UINT8 *DataBits,\r | |
144 | IN OUT EFI_STOP_BITS_TYPE *StopBits\r | |
145 | )\r | |
146 | {\r | |
147 | return PL011UartInitializePort (\r | |
148 | (UINTN)PcdGet64 (PcdSerialRegisterBase),\r | |
149 | BaudRate,\r | |
150 | ReceiveFifoDepth,\r | |
151 | Parity,\r | |
152 | DataBits,\r | |
153 | StopBits);\r | |
154 | }\r | |
155 | \r | |
156 | /**\r | |
157 | \r | |
158 | Assert or deassert the control signals on a serial port.\r | |
159 | The following control signals are set according their bit settings :\r | |
160 | . Request to Send\r | |
161 | . Data Terminal Ready\r | |
162 | \r | |
163 | @param[in] Control The following bits are taken into account :\r | |
164 | . EFI_SERIAL_REQUEST_TO_SEND : assert/deassert the\r | |
165 | "Request To Send" control signal if this bit is\r | |
166 | equal to one/zero.\r | |
167 | . EFI_SERIAL_DATA_TERMINAL_READY : assert/deassert\r | |
168 | the "Data Terminal Ready" control signal if this\r | |
169 | bit is equal to one/zero.\r | |
170 | . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : enable/disable\r | |
171 | the hardware loopback if this bit is equal to\r | |
172 | one/zero.\r | |
173 | . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : not supported.\r | |
174 | . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : enable/\r | |
175 | disable the hardware flow control based on CTS (Clear\r | |
176 | To Send) and RTS (Ready To Send) control signals.\r | |
177 | \r | |
178 | @retval RETURN_SUCCESS The new control bits were set on the serial device.\r | |
179 | @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r | |
180 | \r | |
181 | **/\r | |
182 | RETURN_STATUS\r | |
183 | EFIAPI\r | |
184 | SerialPortSetControl (\r | |
185 | IN UINT32 Control\r | |
186 | )\r | |
187 | {\r | |
188 | return PL011UartSetControl ((UINTN)PcdGet64 (PcdSerialRegisterBase), Control);\r | |
189 | }\r | |
190 | \r | |
191 | /**\r | |
1e57a462 | 192 | \r |
921e987b SZ |
193 | Retrieve the status of the control bits on a serial device.\r |
194 | \r | |
195 | @param[out] Control Status of the control bits on a serial device :\r | |
196 | \r | |
197 | . EFI_SERIAL_DATA_CLEAR_TO_SEND, EFI_SERIAL_DATA_SET_READY,\r | |
198 | EFI_SERIAL_RING_INDICATE, EFI_SERIAL_CARRIER_DETECT,\r | |
199 | EFI_SERIAL_REQUEST_TO_SEND, EFI_SERIAL_DATA_TERMINAL_READY\r | |
200 | are all related to the DTE (Data Terminal Equipment) and\r | |
201 | DCE (Data Communication Equipment) modes of operation of\r | |
202 | the serial device.\r | |
203 | . EFI_SERIAL_INPUT_BUFFER_EMPTY : equal to one if the receive\r | |
204 | buffer is empty, 0 otherwise.\r | |
205 | . EFI_SERIAL_OUTPUT_BUFFER_EMPTY : equal to one if the transmit\r | |
206 | buffer is empty, 0 otherwise.\r | |
207 | . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : equal to one if the\r | |
208 | hardware loopback is enabled (the output feeds the receive\r | |
209 | buffer), 0 otherwise.\r | |
210 | . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : equal to one if a\r | |
211 | loopback is accomplished by software, 0 otherwise.\r | |
212 | . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : equal to one if the\r | |
213 | hardware flow control based on CTS (Clear To Send) and RTS\r | |
214 | (Ready To Send) control signals is enabled, 0 otherwise.\r | |
215 | \r | |
216 | @retval RETURN_SUCCESS The control bits were read from the serial device.\r | |
217 | \r | |
218 | **/\r | |
219 | RETURN_STATUS\r | |
220 | EFIAPI\r | |
221 | SerialPortGetControl (\r | |
222 | OUT UINT32 *Control\r | |
223 | )\r | |
224 | {\r | |
225 | return PL011UartGetControl ((UINTN)PcdGet64 (PcdSerialRegisterBase), Control);\r | |
226 | }\r |