]>
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 | |
9 | Copyright (c) 2008-2009, Apple Inc. All rights reserved.\r | |
10 | \r | |
11 | All rights reserved. This program and the accompanying materials\r | |
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 | |
26 | \r | |
27 | #include <Protocol/SerialIo.h>\r | |
28 | \r | |
29 | /**\r | |
30 | Reset the serial device.\r | |
31 | \r | |
32 | @param This Protocol instance pointer.\r | |
33 | \r | |
34 | @retval EFI_SUCCESS The device was reset.\r | |
35 | @retval EFI_DEVICE_ERROR The serial device could not be reset.\r | |
36 | \r | |
37 | **/\r | |
38 | EFI_STATUS\r | |
39 | EFIAPI\r | |
40 | SerialReset (\r | |
41 | IN EFI_SERIAL_IO_PROTOCOL *This\r | |
42 | )\r | |
43 | {\r | |
44 | SerialPortInitialize ();\r | |
45 | return EFI_SUCCESS;\r | |
46 | }\r | |
47 | \r | |
48 | \r | |
49 | /**\r | |
50 | Sets the baud rate, receive FIFO depth, transmit/receice time out, parity, \r | |
51 | data buts, and stop bits on a serial device.\r | |
52 | \r | |
53 | @param This Protocol instance pointer.\r | |
54 | @param BaudRate The requested baud rate. A BaudRate value of 0 will use the the\r | |
55 | device's default interface speed.\r | |
56 | @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the\r | |
57 | serial interface. A ReceiveFifoDepth value of 0 will use\r | |
58 | the device's dfault FIFO depth.\r | |
59 | @param Timeout The requested time out for a single character in microseconds.\r | |
60 | This timeout applies to both the transmit and receive side of the\r | |
61 | interface. A Timeout value of 0 will use the device's default time\r | |
62 | out value.\r | |
63 | @param Parity The type of parity to use on this serial device. A Parity value of\r | |
64 | DefaultParity will use the device's default parity value.\r | |
65 | @param DataBits The number of data bits to use on the serial device. A DataBits\r | |
66 | vaule of 0 will use the device's default data bit setting.\r | |
67 | @param StopBits The number of stop bits to use on this serial device. A StopBits\r | |
68 | value of DefaultStopBits will use the device's default number of\r | |
69 | stop bits.\r | |
70 | \r | |
71 | @retval EFI_SUCCESS The device was reset.\r | |
72 | @retval EFI_DEVICE_ERROR The serial device could not be reset.\r | |
73 | \r | |
74 | **/\r | |
75 | EFI_STATUS\r | |
76 | EFIAPI\r | |
77 | SerialSetAttributes (\r | |
78 | IN EFI_SERIAL_IO_PROTOCOL *This,\r | |
79 | IN UINT64 BaudRate,\r | |
80 | IN UINT32 ReceiveFifoDepth,\r | |
81 | IN UINT32 Timeout,\r | |
82 | IN EFI_PARITY_TYPE Parity,\r | |
83 | IN UINT8 DataBits,\r | |
84 | IN EFI_STOP_BITS_TYPE StopBits\r | |
85 | )\r | |
86 | {\r | |
87 | return EFI_UNSUPPORTED;\r | |
88 | }\r | |
89 | \r | |
90 | \r | |
91 | /**\r | |
92 | Set the control bits on a serial device\r | |
93 | \r | |
94 | @param This Protocol instance pointer.\r | |
95 | @param Control Set the bits of Control that are settable.\r | |
96 | \r | |
97 | @retval EFI_SUCCESS The new control bits were set on the serial device.\r | |
98 | @retval EFI_UNSUPPORTED The serial device does not support this operation.\r | |
99 | @retval EFI_DEVICE_ERROR The serial device is not functioning correctly.\r | |
100 | \r | |
101 | **/\r | |
102 | EFI_STATUS\r | |
103 | EFIAPI\r | |
104 | SerialSetControl (\r | |
105 | IN EFI_SERIAL_IO_PROTOCOL *This,\r | |
106 | IN UINT32 Control\r | |
107 | )\r | |
108 | {\r | |
109 | return EFI_UNSUPPORTED;\r | |
110 | }\r | |
111 | \r | |
112 | \r | |
113 | /**\r | |
114 | Retrieves the status of thecontrol bits on a serial device\r | |
115 | \r | |
116 | @param This Protocol instance pointer.\r | |
117 | @param Control A pointer to return the current Control signals from the serial device.\r | |
118 | \r | |
119 | @retval EFI_SUCCESS The control bits were read from the serial device.\r | |
120 | @retval EFI_DEVICE_ERROR The serial device is not functioning correctly.\r | |
121 | \r | |
122 | **/\r | |
123 | EFI_STATUS\r | |
124 | EFIAPI\r | |
125 | SerialGetControl (\r | |
126 | IN EFI_SERIAL_IO_PROTOCOL *This,\r | |
127 | OUT UINT32 *Control\r | |
128 | )\r | |
129 | {\r | |
130 | if (SerialPortPoll ()) {\r | |
131 | // If a character is pending don't set EFI_SERIAL_INPUT_BUFFER_EMPTY\r | |
132 | *Control = EFI_SERIAL_OUTPUT_BUFFER_EMPTY;\r | |
133 | } else {\r | |
134 | *Control = EFI_SERIAL_INPUT_BUFFER_EMPTY | EFI_SERIAL_OUTPUT_BUFFER_EMPTY;\r | |
135 | }\r | |
136 | return EFI_SUCCESS;\r | |
137 | }\r | |
138 | \r | |
139 | \r | |
140 | /**\r | |
141 | Writes data to a serial device.\r | |
142 | \r | |
143 | @param This Protocol instance pointer.\r | |
144 | @param BufferSize On input, the size of the Buffer. On output, the amount of\r | |
145 | data actually written.\r | |
146 | @param Buffer The buffer of data to write\r | |
147 | \r | |
148 | @retval EFI_SUCCESS The data was written.\r | |
149 | @retval EFI_DEVICE_ERROR The device reported an error.\r | |
150 | @retval EFI_TIMEOUT The data write was stopped due to a timeout.\r | |
151 | \r | |
152 | **/\r | |
153 | EFI_STATUS\r | |
154 | EFIAPI\r | |
155 | SerialWrite (\r | |
156 | IN EFI_SERIAL_IO_PROTOCOL *This,\r | |
157 | IN OUT UINTN *BufferSize,\r | |
158 | IN VOID *Buffer\r | |
159 | )\r | |
160 | {\r | |
161 | UINTN Count;\r | |
162 | \r | |
163 | Count = SerialPortWrite (Buffer, *BufferSize);\r | |
164 | *BufferSize = Count;\r | |
165 | return (Count == 0) ? EFI_DEVICE_ERROR : EFI_SUCCESS;\r | |
166 | }\r | |
167 | \r | |
168 | /**\r | |
169 | Writes data to a serial device.\r | |
170 | \r | |
171 | @param This Protocol instance pointer.\r | |
172 | @param BufferSize On input, the size of the Buffer. On output, the amount of\r | |
173 | data returned in Buffer.\r | |
174 | @param Buffer The buffer to return the data into.\r | |
175 | \r | |
176 | @retval EFI_SUCCESS The data was read.\r | |
177 | @retval EFI_DEVICE_ERROR The device reported an error.\r | |
178 | @retval EFI_TIMEOUT The data write was stopped due to a timeout.\r | |
179 | \r | |
180 | **/\r | |
181 | \r | |
182 | EFI_STATUS\r | |
183 | EFIAPI\r | |
184 | SerialRead (\r | |
185 | IN EFI_SERIAL_IO_PROTOCOL *This,\r | |
186 | IN OUT UINTN *BufferSize,\r | |
187 | OUT VOID *Buffer\r | |
188 | )\r | |
189 | {\r | |
190 | UINTN Count;\r | |
191 | \r | |
192 | Count = SerialPortWrite (Buffer, *BufferSize);\r | |
193 | *BufferSize = Count;\r | |
194 | return (Count == 0) ? EFI_DEVICE_ERROR : EFI_SUCCESS;\r | |
195 | }\r | |
196 | \r | |
197 | \r | |
198 | EFI_HANDLE gHandle = NULL;\r | |
199 | \r | |
200 | // \r | |
201 | // Template used to initailize the GDB Serial IO protocols\r | |
202 | //\r | |
203 | EFI_SERIAL_IO_MODE gSerialIoMode = {\r | |
204 | 0, // ControlMask\r | |
205 | 0, // Timeout\r | |
206 | 0, // BaudRate\r | |
207 | 1, // RceiveFifoDepth\r | |
208 | 0, // DataBits\r | |
209 | 0, // Parity\r | |
210 | 0 // StopBits\r | |
211 | };\r | |
212 | \r | |
213 | \r | |
214 | EFI_SERIAL_IO_PROTOCOL gSerialIoTemplate = {\r | |
215 | SERIAL_IO_INTERFACE_REVISION,\r | |
216 | SerialReset,\r | |
217 | SerialSetAttributes,\r | |
218 | SerialSetControl,\r | |
219 | SerialGetControl,\r | |
220 | SerialWrite,\r | |
221 | SerialRead,\r | |
222 | &gSerialIoMode\r | |
223 | };\r | |
224 | \r | |
225 | \r | |
226 | /**\r | |
227 | Initialize the state information for the Serial Io Protocol\r | |
228 | \r | |
229 | @param ImageHandle of the loaded driver\r | |
230 | @param SystemTable Pointer to the System Table\r | |
231 | \r | |
232 | @retval EFI_SUCCESS Protocol registered\r | |
233 | @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure\r | |
234 | @retval EFI_DEVICE_ERROR Hardware problems\r | |
235 | \r | |
236 | **/\r | |
237 | EFI_STATUS\r | |
238 | EFIAPI\r | |
239 | SerialDxeInitialize (\r | |
240 | IN EFI_HANDLE ImageHandle,\r | |
241 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
242 | )\r | |
243 | {\r | |
244 | EFI_STATUS Status;\r | |
245 | \r | |
246 | \r | |
247 | // Make a new handle with Serial IO protocol and its device path on it.\r | |
248 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
249 | &gHandle, \r | |
250 | &gEfiSerialIoProtocolGuid, &gSerialIoTemplate,\r | |
251 | &gEfiDevicePathProtocolGuid, NULL, // BugBug: Need a device path\r | |
252 | NULL\r | |
253 | );\r | |
254 | ASSERT_EFI_ERROR (Status);\r | |
255 | \r | |
256 | return Status;\r | |
257 | }\r | |
258 | \r |