]>
Commit | Line | Data |
---|---|---|
1d5d0ae9 | 1 | /** @file |
2 | Serial I/O Port library functions with no library constructor/destructor | |
3 | ||
1d5d0ae9 | 4 | Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR> |
051e63bb | 5 | Copyright (c) 2012, ARM Ltd. All rights reserved.<BR> |
1d5d0ae9 | 6 | |
7 | This program and the accompanying materials | |
8 | are licensed and made available under the terms and conditions of the BSD License | |
9 | which accompanies this distribution. The full text of the license may be found at | |
10 | http://opensource.org/licenses/bsd-license.php | |
11 | ||
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. | |
14 | ||
15 | **/ | |
16 | ||
40ab42dd | 17 | #include <Base.h> |
9dcfb8e5 | 18 | |
1d5d0ae9 | 19 | #include <Library/IoLib.h> |
9dcfb8e5 | 20 | #include <Library/PcdLib.h> |
21 | #include <Library/SerialPortLib.h> | |
7d49ced0 | 22 | #include <Library/SerialPortExtLib.h> |
9dcfb8e5 | 23 | |
1d5d0ae9 | 24 | #include <Drivers/PL011Uart.h> |
9dcfb8e5 | 25 | |
1d5d0ae9 | 26 | |
7d49ced0 | 27 | /** |
1d5d0ae9 | 28 | |
29 | Programmed hardware of Serial port. | |
30 | ||
051e63bb | 31 | @return Always return RETURN_UNSUPPORTED. |
1d5d0ae9 | 32 | |
33 | **/ | |
34 | RETURN_STATUS | |
35 | EFIAPI | |
36 | SerialPortInitialize ( | |
37 | VOID | |
38 | ) | |
39 | { | |
051e63bb | 40 | return PL011UartInitializePort ( |
9dcfb8e5 | 41 | (UINTN)PcdGet64 (PcdSerialRegisterBase), |
42 | (UINTN)PcdGet64 (PcdUartDefaultBaudRate), | |
051e63bb | 43 | 0, // Use the default value for Fifo depth |
051e63bb | 44 | (EFI_PARITY_TYPE)PcdGet8 (PcdUartDefaultParity), |
45 | PcdGet8 (PcdUartDefaultDataBits), | |
46 | (EFI_STOP_BITS_TYPE) PcdGet8 (PcdUartDefaultStopBits)); | |
1d5d0ae9 | 47 | } |
48 | ||
49 | /** | |
50 | Write data to serial device. | |
51 | ||
051e63bb | 52 | @param Buffer Point of data buffer which need to be written. |
1d5d0ae9 | 53 | @param NumberOfBytes Number of output bytes which are cached in Buffer. |
54 | ||
55 | @retval 0 Write data failed. | |
051e63bb | 56 | @retval !0 Actual number of bytes written to serial device. |
1d5d0ae9 | 57 | |
58 | **/ | |
59 | UINTN | |
60 | EFIAPI | |
61 | SerialPortWrite ( | |
62 | IN UINT8 *Buffer, | |
63 | IN UINTN NumberOfBytes | |
9dcfb8e5 | 64 | ) |
1d5d0ae9 | 65 | { |
9dcfb8e5 | 66 | return PL011UartWrite ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes); |
1d5d0ae9 | 67 | } |
68 | ||
69 | /** | |
051e63bb | 70 | Read data from serial device and save the data in buffer. |
1d5d0ae9 | 71 | |
051e63bb | 72 | @param Buffer Point of data buffer which need to be written. |
1d5d0ae9 | 73 | @param NumberOfBytes Number of output bytes which are cached in Buffer. |
74 | ||
75 | @retval 0 Read data failed. | |
051e63bb | 76 | @retval !0 Actual number of bytes read from serial device. |
1d5d0ae9 | 77 | |
78 | **/ | |
79 | UINTN | |
80 | EFIAPI | |
81 | SerialPortRead ( | |
82 | OUT UINT8 *Buffer, | |
83 | IN UINTN NumberOfBytes | |
84 | ) | |
85 | { | |
9dcfb8e5 | 86 | return PL011UartRead ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes); |
1d5d0ae9 | 87 | } |
88 | ||
89 | /** | |
051e63bb | 90 | Check to see if any data is available to be read from the debug device. |
1d5d0ae9 | 91 | |
051e63bb | 92 | @retval EFI_SUCCESS At least one byte of data is available to be read |
93 | @retval EFI_NOT_READY No data is available to be read | |
1d5d0ae9 | 94 | @retval EFI_DEVICE_ERROR The serial device is not functioning properly |
95 | ||
96 | **/ | |
97 | BOOLEAN | |
98 | EFIAPI | |
99 | SerialPortPoll ( | |
100 | VOID | |
101 | ) | |
102 | { | |
9dcfb8e5 | 103 | return PL011UartPoll ((UINTN)PcdGet64 (PcdSerialRegisterBase)); |
1d5d0ae9 | 104 | } |
7d49ced0 | 105 | |
106 | /** | |
107 | Set new attributes to PL011. | |
108 | ||
109 | @param BaudRate The baud rate of the serial device. If the baud rate is not supported, | |
110 | the speed will be reduced down to the nearest supported one and the | |
111 | variable's value will be updated accordingly. | |
112 | @param ReceiveFifoDepth The number of characters the device will buffer on input. If the specified | |
113 | value is not supported, the variable's value will be reduced down to the | |
114 | nearest supported one. | |
115 | @param Timeout If applicable, the number of microseconds the device will wait | |
116 | before timing out a Read or a Write operation. | |
117 | @param Parity If applicable, this is the EFI_PARITY_TYPE that is computer or checked | |
118 | as each character is transmitted or received. If the device does not | |
119 | support parity, the value is the default parity value. | |
120 | @param DataBits The number of data bits in each character | |
121 | @param StopBits If applicable, the EFI_STOP_BITS_TYPE number of stop bits per character. | |
122 | If the device does not support stop bits, the value is the default stop | |
123 | bit value. | |
124 | ||
125 | @retval EFI_SUCCESS All attributes were set correctly on the serial device. | |
126 | @retval EFI_INVALID_PARAMETERS One or more of the attributes has an unsupported value. | |
127 | ||
128 | **/ | |
129 | RETURN_STATUS | |
130 | EFIAPI | |
131 | SerialPortSetAttributes ( | |
132 | IN UINT64 BaudRate, | |
133 | IN UINT32 ReceiveFifoDepth, | |
134 | IN UINT32 Timeout, | |
135 | IN EFI_PARITY_TYPE Parity, | |
136 | IN UINT8 DataBits, | |
137 | IN EFI_STOP_BITS_TYPE StopBits | |
138 | ) | |
139 | { | |
140 | return PL011UartInitializePort ( | |
141 | (UINTN)PcdGet64 (PcdSerialRegisterBase), | |
142 | BaudRate, | |
143 | ReceiveFifoDepth, | |
144 | Parity, | |
145 | DataBits, | |
146 | StopBits); | |
147 | } | |
148 | ||
149 | /** | |
150 | Set the serial device control bits. | |
151 | ||
152 | @param Control Control bits which are to be set on the serial device. | |
153 | ||
154 | @retval EFI_SUCCESS The new control bits were set on the serial device. | |
155 | @retval EFI_UNSUPPORTED The serial device does not support this operation. | |
156 | @retval EFI_DEVICE_ERROR The serial device is not functioning correctly. | |
157 | ||
158 | **/ | |
159 | RETURN_STATUS | |
160 | EFIAPI | |
161 | SerialPortSetControl ( | |
162 | IN UINT32 Control | |
163 | ) | |
164 | { | |
165 | return PL011UartSetControl((UINTN)PcdGet64 (PcdSerialRegisterBase), Control); | |
166 | } | |
167 | ||
168 | /** | |
169 | Get the serial device control bits. | |
170 | ||
171 | @param Control Control signals read from the serial device. | |
172 | ||
173 | @retval EFI_SUCCESS The control bits were read from the serial device. | |
174 | @retval EFI_DEVICE_ERROR The serial device is not functioning correctly. | |
175 | ||
176 | **/ | |
177 | RETURN_STATUS | |
178 | EFIAPI | |
179 | SerialPortGetControl ( | |
180 | OUT UINT32 *Control | |
181 | ) | |
182 | { | |
183 | return PL011UartGetControl((UINTN)PcdGet64 (PcdSerialRegisterBase), Control); | |
184 | } |