]>
Commit | Line | Data |
---|---|---|
2ef2b01e A |
1 | /** @file\r |
2 | Serial IO Abstraction for GDB stub. This allows an EFI consoles that shows up on the system \r | |
3 | running GDB. One consle for error information and another console for user input/output.\r | |
4 | \r | |
5 | Basic packet format is $packet-data#checksum. So every comand has 4 bytes of overhead: $, \r | |
6 | #, 0, 0. The 0 and 0 are the ascii characters for the checksum. \r | |
7 | \r | |
8 | \r | |
60274cca | 9 | Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r |
2ef2b01e | 10 | \r |
60274cca | 11 | This program and the accompanying materials\r |
2ef2b01e A |
12 | are licensed and made available under the terms and conditions of the BSD License\r |
13 | which accompanies this distribution. The full text of the license may be found at\r | |
14 | http://opensource.org/licenses/bsd-license.php\r | |
15 | \r | |
16 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
17 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
18 | \r | |
19 | **/\r | |
20 | \r | |
21 | #include <PiDxe.h>\r | |
22 | #include <Library/UefiLib.h>\r | |
23 | #include <Library/UefiBootServicesTableLib.h>\r | |
24 | #include <Library/DebugLib.h>\r | |
25 | #include <Library/SerialPortLib.h>\r | |
026e30c4 | 26 | #include <Library/PcdLib.h>\r |
2ef2b01e A |
27 | \r |
28 | #include <Protocol/SerialIo.h>\r | |
29 | \r | |
30 | /**\r | |
31 | Reset the serial device.\r | |
32 | \r | |
33 | @param This Protocol instance pointer.\r | |
34 | \r | |
35 | @retval EFI_SUCCESS The device was reset.\r | |
36 | @retval EFI_DEVICE_ERROR The serial device could not be reset.\r | |
37 | \r | |
38 | **/\r | |
39 | EFI_STATUS\r | |
40 | EFIAPI\r | |
41 | SerialReset (\r | |
42 | IN EFI_SERIAL_IO_PROTOCOL *This\r | |
43 | )\r | |
44 | {\r | |
45 | SerialPortInitialize ();\r | |
46 | return EFI_SUCCESS;\r | |
47 | }\r | |
48 | \r | |
49 | \r | |
50 | /**\r | |
51 | Sets the baud rate, receive FIFO depth, transmit/receice time out, parity, \r | |
52 | data buts, and stop bits on a serial device.\r | |
53 | \r | |
54 | @param This Protocol instance pointer.\r | |
55 | @param BaudRate The requested baud rate. A BaudRate value of 0 will use the the\r | |
56 | device's default interface speed.\r | |
57 | @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the\r | |
58 | serial interface. A ReceiveFifoDepth value of 0 will use\r | |
59 | the device's dfault FIFO depth.\r | |
60 | @param Timeout The requested time out for a single character in microseconds.\r | |
61 | This timeout applies to both the transmit and receive side of the\r | |
62 | interface. A Timeout value of 0 will use the device's default time\r | |
63 | out value.\r | |
64 | @param Parity The type of parity to use on this serial device. A Parity value of\r | |
65 | DefaultParity will use the device's default parity value.\r | |
66 | @param DataBits The number of data bits to use on the serial device. A DataBits\r | |
67 | vaule of 0 will use the device's default data bit setting.\r | |
68 | @param StopBits The number of stop bits to use on this serial device. A StopBits\r | |
69 | value of DefaultStopBits will use the device's default number of\r | |
70 | stop bits.\r | |
71 | \r | |
72 | @retval EFI_SUCCESS The device was reset.\r | |
73 | @retval EFI_DEVICE_ERROR The serial device could not be reset.\r | |
74 | \r | |
75 | **/\r | |
76 | EFI_STATUS\r | |
77 | EFIAPI\r | |
78 | SerialSetAttributes (\r | |
79 | IN EFI_SERIAL_IO_PROTOCOL *This,\r | |
80 | IN UINT64 BaudRate,\r | |
81 | IN UINT32 ReceiveFifoDepth,\r | |
82 | IN UINT32 Timeout,\r | |
83 | IN EFI_PARITY_TYPE Parity,\r | |
84 | IN UINT8 DataBits,\r | |
85 | IN EFI_STOP_BITS_TYPE StopBits\r | |
86 | )\r | |
87 | {\r | |
88 | return EFI_UNSUPPORTED;\r | |
89 | }\r | |
90 | \r | |
91 | \r | |
92 | /**\r | |
93 | Set the control bits on a serial device\r | |
94 | \r | |
95 | @param This Protocol instance pointer.\r | |
96 | @param Control Set the bits of Control that are settable.\r | |
97 | \r | |
98 | @retval EFI_SUCCESS The new control bits were set on the serial device.\r | |
99 | @retval EFI_UNSUPPORTED The serial device does not support this operation.\r | |
100 | @retval EFI_DEVICE_ERROR The serial device is not functioning correctly.\r | |
101 | \r | |
102 | **/\r | |
103 | EFI_STATUS\r | |
104 | EFIAPI\r | |
105 | SerialSetControl (\r | |
106 | IN EFI_SERIAL_IO_PROTOCOL *This,\r | |
107 | IN UINT32 Control\r | |
108 | )\r | |
109 | {\r | |
110 | return EFI_UNSUPPORTED;\r | |
111 | }\r | |
112 | \r | |
113 | \r | |
114 | /**\r | |
115 | Retrieves the status of thecontrol bits on a serial device\r | |
116 | \r | |
117 | @param This Protocol instance pointer.\r | |
118 | @param Control A pointer to return the current Control signals from the serial device.\r | |
119 | \r | |
120 | @retval EFI_SUCCESS The control bits were read from the serial device.\r | |
121 | @retval EFI_DEVICE_ERROR The serial device is not functioning correctly.\r | |
122 | \r | |
123 | **/\r | |
124 | EFI_STATUS\r | |
125 | EFIAPI\r | |
126 | SerialGetControl (\r | |
127 | IN EFI_SERIAL_IO_PROTOCOL *This,\r | |
128 | OUT UINT32 *Control\r | |
129 | )\r | |
130 | {\r | |
131 | if (SerialPortPoll ()) {\r | |
132 | // If a character is pending don't set EFI_SERIAL_INPUT_BUFFER_EMPTY\r | |
133 | *Control = EFI_SERIAL_OUTPUT_BUFFER_EMPTY;\r | |
134 | } else {\r | |
135 | *Control = EFI_SERIAL_INPUT_BUFFER_EMPTY | EFI_SERIAL_OUTPUT_BUFFER_EMPTY;\r | |
136 | }\r | |
137 | return EFI_SUCCESS;\r | |
138 | }\r | |
139 | \r | |
140 | \r | |
141 | /**\r | |
142 | Writes data to a serial device.\r | |
143 | \r | |
144 | @param This Protocol instance pointer.\r | |
145 | @param BufferSize On input, the size of the Buffer. On output, the amount of\r | |
146 | data actually written.\r | |
147 | @param Buffer The buffer of data to write\r | |
148 | \r | |
149 | @retval EFI_SUCCESS The data was written.\r | |
150 | @retval EFI_DEVICE_ERROR The device reported an error.\r | |
151 | @retval EFI_TIMEOUT The data write was stopped due to a timeout.\r | |
152 | \r | |
153 | **/\r | |
154 | EFI_STATUS\r | |
155 | EFIAPI\r | |
156 | SerialWrite (\r | |
157 | IN EFI_SERIAL_IO_PROTOCOL *This,\r | |
158 | IN OUT UINTN *BufferSize,\r | |
159 | IN VOID *Buffer\r | |
160 | )\r | |
161 | {\r | |
162 | UINTN Count;\r | |
163 | \r | |
164 | Count = SerialPortWrite (Buffer, *BufferSize);\r | |
165 | *BufferSize = Count;\r | |
166 | return (Count == 0) ? EFI_DEVICE_ERROR : EFI_SUCCESS;\r | |
167 | }\r | |
168 | \r | |
169 | /**\r | |
170 | Writes data to a serial device.\r | |
171 | \r | |
172 | @param This Protocol instance pointer.\r | |
173 | @param BufferSize On input, the size of the Buffer. On output, the amount of\r | |
174 | data returned in Buffer.\r | |
175 | @param Buffer The buffer to return the data into.\r | |
176 | \r | |
177 | @retval EFI_SUCCESS The data was read.\r | |
178 | @retval EFI_DEVICE_ERROR The device reported an error.\r | |
179 | @retval EFI_TIMEOUT The data write was stopped due to a timeout.\r | |
180 | \r | |
181 | **/\r | |
182 | \r | |
183 | EFI_STATUS\r | |
184 | EFIAPI\r | |
185 | SerialRead (\r | |
186 | IN EFI_SERIAL_IO_PROTOCOL *This,\r | |
187 | IN OUT UINTN *BufferSize,\r | |
188 | OUT VOID *Buffer\r | |
189 | )\r | |
190 | {\r | |
010bb3d2 | 191 | UINTN Count = 0;\r |
2ef2b01e | 192 | \r |
010bb3d2 | 193 | if (SerialPortPoll()) {\r |
194 | Count = SerialPortRead (Buffer, *BufferSize);\r | |
195 | *BufferSize = Count;\r | |
f65dc3be | 196 | return (Count == 0) ? EFI_DEVICE_ERROR : EFI_SUCCESS;\r |
010bb3d2 | 197 | }\r |
f65dc3be | 198 | \r |
199 | // No data to return\r | |
200 | *BufferSize = 0;\r | |
201 | return EFI_SUCCESS;\r | |
2ef2b01e A |
202 | }\r |
203 | \r | |
204 | \r | |
205 | EFI_HANDLE gHandle = NULL;\r | |
206 | \r | |
207 | // \r | |
208 | // Template used to initailize the GDB Serial IO protocols\r | |
209 | //\r | |
210 | EFI_SERIAL_IO_MODE gSerialIoMode = {\r | |
026e30c4 | 211 | 0, // ControlMask\r |
212 | 0, // Timeout\r | |
213 | FixedPcdGet64 (PcdUartDefaultBaudRate), // BaudRate\r | |
214 | 1, // RceiveFifoDepth\r | |
215 | FixedPcdGet8 (PcdUartDefaultDataBits), // DataBits\r | |
216 | FixedPcdGet8 (PcdUartDefaultParity), // Parity\r | |
217 | FixedPcdGet8 (PcdUartDefaultStopBits) // StopBits\r | |
2ef2b01e A |
218 | };\r |
219 | \r | |
220 | \r | |
221 | EFI_SERIAL_IO_PROTOCOL gSerialIoTemplate = {\r | |
222 | SERIAL_IO_INTERFACE_REVISION,\r | |
223 | SerialReset,\r | |
224 | SerialSetAttributes,\r | |
225 | SerialSetControl,\r | |
226 | SerialGetControl,\r | |
227 | SerialWrite,\r | |
228 | SerialRead,\r | |
229 | &gSerialIoMode\r | |
230 | };\r | |
231 | \r | |
026e30c4 | 232 | typedef struct {\r |
233 | VENDOR_DEVICE_PATH Guid;\r | |
234 | UART_DEVICE_PATH Uart;\r | |
235 | EFI_DEVICE_PATH_PROTOCOL End;\r | |
236 | } SIMPLE_TEXT_OUT_DEVICE_PATH;\r | |
237 | \r | |
238 | SIMPLE_TEXT_OUT_DEVICE_PATH mDevicePath = {\r | |
239 | {\r | |
240 | { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, sizeof (VENDOR_DEVICE_PATH), 0},\r | |
241 | EFI_CALLER_ID_GUID // Use the drivers GUID\r | |
242 | },\r | |
243 | {\r | |
52721ad5 | 244 | { MESSAGING_DEVICE_PATH, MSG_UART_DP, sizeof (UART_DEVICE_PATH), 0},\r |
026e30c4 | 245 | 0, // Reserved\r |
246 | FixedPcdGet64 (PcdUartDefaultBaudRate), // BaudRate\r | |
247 | FixedPcdGet8 (PcdUartDefaultDataBits), // DataBits\r | |
248 | FixedPcdGet8 (PcdUartDefaultParity), // Parity (N)\r | |
249 | FixedPcdGet8 (PcdUartDefaultStopBits) // StopBits\r | |
250 | },\r | |
251 | { END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, sizeof (EFI_DEVICE_PATH_PROTOCOL), 0}\r | |
252 | };\r | |
253 | \r | |
2ef2b01e A |
254 | \r |
255 | /**\r | |
256 | Initialize the state information for the Serial Io Protocol\r | |
257 | \r | |
258 | @param ImageHandle of the loaded driver\r | |
259 | @param SystemTable Pointer to the System Table\r | |
260 | \r | |
261 | @retval EFI_SUCCESS Protocol registered\r | |
262 | @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure\r | |
263 | @retval EFI_DEVICE_ERROR Hardware problems\r | |
264 | \r | |
265 | **/\r | |
266 | EFI_STATUS\r | |
267 | EFIAPI\r | |
268 | SerialDxeInitialize (\r | |
269 | IN EFI_HANDLE ImageHandle,\r | |
270 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
271 | )\r | |
272 | {\r | |
273 | EFI_STATUS Status;\r | |
274 | \r | |
275 | \r | |
276 | // Make a new handle with Serial IO protocol and its device path on it.\r | |
277 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
278 | &gHandle, \r | |
279 | &gEfiSerialIoProtocolGuid, &gSerialIoTemplate,\r | |
026e30c4 | 280 | &gEfiDevicePathProtocolGuid, &mDevicePath, \r |
2ef2b01e A |
281 | NULL\r |
282 | );\r | |
283 | ASSERT_EFI_ERROR (Status);\r | |
284 | \r | |
285 | return Status;\r | |
286 | }\r | |
287 | \r |