]>
Commit | Line | Data |
---|---|---|
fb0b259e | 1 | /** @file\r |
2 | Definitions and prototypes for DebugPort driver.\r | |
c1f23d63 | 3 | \r |
284ee2e8 | 4 | Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r |
e5eed7d3 | 5 | This program and the accompanying materials\r |
fb0b259e | 6 | are licensed and made available under the terms and conditions of the BSD License\r |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
c1f23d63 | 9 | \r |
fb0b259e | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
c1f23d63 | 12 | \r |
fb0b259e | 13 | **/\r |
c1f23d63 | 14 | \r |
15 | #ifndef __DEBUGPORT_H__\r | |
16 | #define __DEBUGPORT_H__\r | |
17 | \r | |
ed7748fe | 18 | \r |
c1f23d63 | 19 | #include <Uefi.h>\r |
ed7748fe | 20 | \r |
c1f23d63 | 21 | #include <Protocol/DevicePath.h>\r |
22 | #include <Protocol/ComponentName.h>\r | |
23 | #include <Protocol/DriverBinding.h>\r | |
24 | #include <Protocol/SerialIo.h>\r | |
25 | #include <Protocol/DebugPort.h>\r | |
ed7748fe | 26 | \r |
c1f23d63 | 27 | #include <Library/DebugLib.h>\r |
28 | #include <Library/UefiDriverEntryPoint.h>\r | |
29 | #include <Library/UefiLib.h>\r | |
30 | #include <Library/BaseMemoryLib.h>\r | |
31 | #include <Library/MemoryAllocationLib.h>\r | |
32 | #include <Library/UefiBootServicesTableLib.h>\r | |
33 | #include <Library/UefiRuntimeServicesTableLib.h>\r | |
34 | #include <Library/DevicePathLib.h>\r | |
35 | \r | |
36 | //\r | |
37 | // Driver Binding Externs\r | |
38 | //\r | |
19f97f7e | 39 | extern EFI_DRIVER_BINDING_PROTOCOL gDebugPortDriverBinding;\r |
40 | extern EFI_COMPONENT_NAME_PROTOCOL gDebugPortComponentName;\r | |
41 | extern EFI_COMPONENT_NAME2_PROTOCOL gDebugPortComponentName2;\r | |
c1f23d63 | 42 | \r |
43 | //\r | |
44 | // local type definitions\r | |
45 | //\r | |
f3f2e05d | 46 | #define DEBUGPORT_DEVICE_SIGNATURE SIGNATURE_32 ('D', 'B', 'G', 'P')\r |
c1f23d63 | 47 | \r |
48 | //\r | |
49 | // Device structure used by driver\r | |
50 | //\r | |
51 | typedef struct {\r | |
52 | UINT32 Signature;\r | |
53 | EFI_HANDLE DriverBindingHandle;\r | |
54 | EFI_HANDLE DebugPortDeviceHandle;\r | |
55 | VOID *DebugPortVariable;\r | |
56 | \r | |
c1f23d63 | 57 | EFI_DEVICE_PATH_PROTOCOL *DebugPortDevicePath;\r |
58 | EFI_DEBUGPORT_PROTOCOL DebugPortInterface;\r | |
59 | \r | |
60 | EFI_HANDLE SerialIoDeviceHandle;\r | |
61 | EFI_SERIAL_IO_PROTOCOL *SerialIoBinding;\r | |
62 | UINT64 BaudRate;\r | |
63 | UINT32 ReceiveFifoDepth;\r | |
64 | UINT32 Timeout;\r | |
65 | EFI_PARITY_TYPE Parity;\r | |
66 | UINT8 DataBits;\r | |
67 | EFI_STOP_BITS_TYPE StopBits;\r | |
68 | } DEBUGPORT_DEVICE;\r | |
69 | \r | |
70 | #define DEBUGPORT_DEVICE_FROM_THIS(a) CR (a, DEBUGPORT_DEVICE, DebugPortInterface, DEBUGPORT_DEVICE_SIGNATURE)\r | |
71 | \r | |
72 | #define EFI_ACPI_PC_COMPORT_HID EISA_PNP_ID (0x0500)\r | |
73 | #define EFI_ACPI_16550UART_HID EISA_PNP_ID (0x0501)\r | |
74 | \r | |
75 | #define DEBUGPORT_UART_DEFAULT_BAUDRATE 115200\r | |
76 | #define DEBUGPORT_UART_DEFAULT_PARITY 0\r | |
77 | #define DEBUGPORT_UART_DEFAULT_FIFO_DEPTH 16\r | |
2d285faa | 78 | #define DEBUGPORT_UART_DEFAULT_TIMEOUT 50000 ///< 5 ms\r |
c1f23d63 | 79 | #define DEBUGPORT_UART_DEFAULT_DATA_BITS 8\r |
80 | #define DEBUGPORT_UART_DEFAULT_STOP_BITS 1\r | |
81 | \r | |
82 | #define DEBUGPORT_DRIVER_VERSION 1\r | |
83 | \r | |
49c8b87c | 84 | #define IS_UART_DEVICEPATH(dp) (DevicePathType (dp) == MESSAGING_DEVICE_PATH && DevicePathSubType (dp) == MSG_UART_DP)\r |
c1f23d63 | 85 | \r |
49c8b87c | 86 | /**\r |
7601dbe7 | 87 | Debug Port Driver entry point. \r |
49c8b87c | 88 | \r |
89 | Reads DebugPort variable to determine what device and settings to use as the\r | |
90 | debug port. Binds exclusively to SerialIo. Reverts to defaults if no variable\r | |
91 | is found.\r | |
92 | \r | |
93 | @param[in] ImageHandle The firmware allocated handle for the EFI image. \r | |
94 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
95 | \r | |
96 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
97 | @retval EFI_OUT_OF_RESOURCES Fails to allocate memory for device.\r | |
98 | @retval other Some error occurs when executing this entry point.\r | |
99 | \r | |
100 | **/\r | |
c1f23d63 | 101 | EFI_STATUS\r |
49c8b87c | 102 | EFIAPI\r |
103 | InitializeDebugPortDriver (\r | |
c1f23d63 | 104 | IN EFI_HANDLE ImageHandle,\r |
105 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
ed66e1bc | 106 | );\r |
c1f23d63 | 107 | \r |
49c8b87c | 108 | /**\r |
109 | Checks to see if there's not already a DebugPort interface somewhere. \r | |
110 | \r | |
111 | If there's a DEBUGPORT variable, the device path must match exactly. If there's\r | |
112 | no DEBUGPORT variable, then device path is not checked and does not matter.\r | |
113 | Checks to see that there's a serial io interface on the controller handle\r | |
114 | that can be bound BY_DRIVER | EXCLUSIVE.\r | |
115 | If all these tests succeed, then we return EFI_SUCCESS, else, EFI_UNSUPPORTED\r | |
116 | or other error returned by OpenProtocol.\r | |
117 | \r | |
118 | @param This Protocol instance pointer.\r | |
119 | @param ControllerHandle Handle of device to test.\r | |
120 | @param RemainingDevicePath Optional parameter use to pick a specific child\r | |
121 | device to start.\r | |
122 | \r | |
123 | @retval EFI_SUCCESS This driver supports this device.\r | |
124 | @retval EFI_UNSUPPORTED Debug Port device is not supported.\r | |
125 | @retval EFI_OUT_OF_RESOURCES Fails to allocate memory for device.\r | |
126 | @retval others Some error occurs.\r | |
127 | \r | |
128 | **/\r | |
c1f23d63 | 129 | EFI_STATUS\r |
130 | EFIAPI\r | |
131 | DebugPortSupported (\r | |
132 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
133 | IN EFI_HANDLE Controller,\r | |
134 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
ed66e1bc | 135 | );\r |
c1f23d63 | 136 | \r |
49c8b87c | 137 | /**\r |
138 | Binds exclusively to serial io on the controller handle, Produces DebugPort\r | |
139 | protocol and DevicePath on new handle.\r | |
140 | \r | |
141 | @param This Protocol instance pointer.\r | |
142 | @param ControllerHandle Handle of device to bind driver to.\r | |
143 | @param RemainingDevicePath Optional parameter use to pick a specific child\r | |
144 | device to start.\r | |
145 | \r | |
146 | @retval EFI_SUCCESS This driver is added to ControllerHandle.\r | |
147 | @retval EFI_OUT_OF_RESOURCES Fails to allocate memory for device.\r | |
148 | @retval others Some error occurs. \r | |
149 | \r | |
150 | **/\r | |
c1f23d63 | 151 | EFI_STATUS\r |
152 | EFIAPI\r | |
153 | DebugPortStart (\r | |
154 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
155 | IN EFI_HANDLE Controller,\r | |
156 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
ed66e1bc | 157 | );\r |
c1f23d63 | 158 | \r |
49c8b87c | 159 | /**\r |
160 | Stop this driver on ControllerHandle by removing Serial IO protocol on\r | |
161 | the ControllerHandle.\r | |
162 | \r | |
163 | @param This Protocol instance pointer.\r | |
164 | @param ControllerHandle Handle of device to stop driver on\r | |
165 | @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r | |
166 | children is zero stop the entire bus driver.\r | |
167 | @param ChildHandleBuffer List of Child Handles to Stop.\r | |
168 | \r | |
169 | @retval EFI_SUCCESS This driver is removed ControllerHandle.\r | |
170 | @retval other This driver was not removed from this device.\r | |
171 | \r | |
172 | **/\r | |
c1f23d63 | 173 | EFI_STATUS\r |
174 | EFIAPI\r | |
175 | DebugPortStop (\r | |
176 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
177 | IN EFI_HANDLE Controller,\r | |
178 | IN UINTN NumberOfChildren,\r | |
179 | IN EFI_HANDLE *ChildHandleBuffer\r | |
ed66e1bc | 180 | );\r |
c1f23d63 | 181 | \r |
182 | //\r | |
183 | // EFI Component Name Functions\r | |
184 | //\r | |
19f97f7e | 185 | /**\r |
186 | Retrieves a Unicode string that is the user readable name of the driver.\r | |
187 | \r | |
188 | This function retrieves the user readable name of a driver in the form of a\r | |
189 | Unicode string. If the driver specified by This has a user readable name in\r | |
190 | the language specified by Language, then a pointer to the driver name is\r | |
191 | returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r | |
192 | by This does not support the language specified by Language,\r | |
193 | then EFI_UNSUPPORTED is returned.\r | |
194 | \r | |
195 | @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
196 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
197 | \r | |
198 | @param Language[in] A pointer to a Null-terminated ASCII string\r | |
199 | array indicating the language. This is the\r | |
200 | language of the driver name that the caller is\r | |
201 | requesting, and it must match one of the\r | |
202 | languages specified in SupportedLanguages. The\r | |
203 | number of languages supported by a driver is up\r | |
204 | to the driver writer. Language is specified\r | |
0254efc0 | 205 | in RFC 4646 or ISO 639-2 language code format.\r |
19f97f7e | 206 | \r |
207 | @param DriverName[out] A pointer to the Unicode string to return.\r | |
208 | This Unicode string is the name of the\r | |
209 | driver specified by This in the language\r | |
210 | specified by Language.\r | |
211 | \r | |
212 | @retval EFI_SUCCESS The Unicode string for the Driver specified by\r | |
213 | This and the language specified by Language was\r | |
214 | returned in DriverName.\r | |
215 | \r | |
216 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
217 | \r | |
218 | @retval EFI_INVALID_PARAMETER DriverName is NULL.\r | |
219 | \r | |
220 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
221 | the language specified by Language.\r | |
222 | \r | |
223 | **/\r | |
c1f23d63 | 224 | EFI_STATUS\r |
225 | EFIAPI\r | |
226 | DebugPortComponentNameGetDriverName (\r | |
19f97f7e | 227 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r |
228 | IN CHAR8 *Language,\r | |
229 | OUT CHAR16 **DriverName\r | |
230 | );\r | |
231 | \r | |
232 | \r | |
233 | /**\r | |
234 | Retrieves a Unicode string that is the user readable name of the controller\r | |
235 | that is being managed by a driver.\r | |
236 | \r | |
237 | This function retrieves the user readable name of the controller specified by\r | |
238 | ControllerHandle and ChildHandle in the form of a Unicode string. If the\r | |
239 | driver specified by This has a user readable name in the language specified by\r | |
240 | Language, then a pointer to the controller name is returned in ControllerName,\r | |
241 | and EFI_SUCCESS is returned. If the driver specified by This is not currently\r | |
242 | managing the controller specified by ControllerHandle and ChildHandle,\r | |
243 | then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r | |
244 | support the language specified by Language, then EFI_UNSUPPORTED is returned.\r | |
245 | \r | |
246 | @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r | |
247 | EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
c1f23d63 | 248 | \r |
19f97f7e | 249 | @param ControllerHandle[in] The handle of a controller that the driver\r |
250 | specified by This is managing. This handle\r | |
251 | specifies the controller whose name is to be\r | |
252 | returned.\r | |
253 | \r | |
254 | @param ChildHandle[in] The handle of the child controller to retrieve\r | |
255 | the name of. This is an optional parameter that\r | |
256 | may be NULL. It will be NULL for device\r | |
257 | drivers. It will also be NULL for a bus drivers\r | |
258 | that wish to retrieve the name of the bus\r | |
259 | controller. It will not be NULL for a bus\r | |
260 | driver that wishes to retrieve the name of a\r | |
261 | child controller.\r | |
262 | \r | |
263 | @param Language[in] A pointer to a Null-terminated ASCII string\r | |
264 | array indicating the language. This is the\r | |
265 | language of the driver name that the caller is\r | |
266 | requesting, and it must match one of the\r | |
267 | languages specified in SupportedLanguages. The\r | |
268 | number of languages supported by a driver is up\r | |
269 | to the driver writer. Language is specified in\r | |
0254efc0 | 270 | RFC 4646 or ISO 639-2 language code format.\r |
19f97f7e | 271 | \r |
272 | @param ControllerName[out] A pointer to the Unicode string to return.\r | |
273 | This Unicode string is the name of the\r | |
274 | controller specified by ControllerHandle and\r | |
275 | ChildHandle in the language specified by\r | |
276 | Language from the point of view of the driver\r | |
277 | specified by This.\r | |
278 | \r | |
279 | @retval EFI_SUCCESS The Unicode string for the user readable name in\r | |
280 | the language specified by Language for the\r | |
281 | driver specified by This was returned in\r | |
282 | DriverName.\r | |
283 | \r | |
284ee2e8 | 284 | @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r |
19f97f7e | 285 | \r |
286 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r | |
287 | EFI_HANDLE.\r | |
288 | \r | |
289 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
290 | \r | |
291 | @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r | |
292 | \r | |
293 | @retval EFI_UNSUPPORTED The driver specified by This is not currently\r | |
294 | managing the controller specified by\r | |
295 | ControllerHandle and ChildHandle.\r | |
296 | \r | |
297 | @retval EFI_UNSUPPORTED The driver specified by This does not support\r | |
298 | the language specified by Language.\r | |
299 | \r | |
300 | **/\r | |
c1f23d63 | 301 | EFI_STATUS\r |
302 | EFIAPI\r | |
303 | DebugPortComponentNameGetControllerName (\r | |
19f97f7e | 304 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r |
305 | IN EFI_HANDLE ControllerHandle,\r | |
306 | IN EFI_HANDLE ChildHandle OPTIONAL,\r | |
307 | IN CHAR8 *Language,\r | |
308 | OUT CHAR16 **ControllerName\r | |
309 | );\r | |
310 | \r | |
c1f23d63 | 311 | \r |
49c8b87c | 312 | /**\r |
313 | DebugPort protocol member function. Calls SerialIo:GetControl to flush buffer.\r | |
314 | We cannot call SerialIo:SetAttributes because it uses pool services, which use\r | |
315 | locks, which affect TPL, so it's not interrupt context safe or re-entrant.\r | |
316 | SerialIo:Reset() calls SetAttributes, so it can't be used either.\r | |
317 | \r | |
318 | The port itself should be fine since it was set up during initialization.\r | |
319 | \r | |
320 | @param This Protocol instance pointer. \r | |
321 | \r | |
322 | @return EFI_SUCCESS Always.\r | |
323 | \r | |
324 | **/\r | |
c1f23d63 | 325 | EFI_STATUS\r |
326 | EFIAPI\r | |
327 | DebugPortReset (\r | |
328 | IN EFI_DEBUGPORT_PROTOCOL *This\r | |
ed66e1bc | 329 | );\r |
c1f23d63 | 330 | \r |
49c8b87c | 331 | /**\r |
332 | DebugPort protocol member function. Calls SerialIo:Read() after setting\r | |
333 | if it's different than the last SerialIo access.\r | |
334 | \r | |
335 | @param This Pointer to DebugPort protocol.\r | |
336 | @param Timeout Timeout value.\r | |
337 | @param BufferSize On input, the size of Buffer.\r | |
338 | On output, the amount of data actually written.\r | |
339 | @param Buffer Pointer to buffer to read.\r | |
340 | \r | |
341 | @retval EFI_SUCCESS \r | |
342 | @retval others \r | |
343 | \r | |
344 | **/\r | |
c1f23d63 | 345 | EFI_STATUS\r |
346 | EFIAPI\r | |
347 | DebugPortRead (\r | |
348 | IN EFI_DEBUGPORT_PROTOCOL *This,\r | |
349 | IN UINT32 Timeout,\r | |
350 | IN OUT UINTN *BufferSize,\r | |
351 | IN VOID *Buffer\r | |
ed66e1bc | 352 | );\r |
c1f23d63 | 353 | \r |
49c8b87c | 354 | /**\r |
355 | DebugPort protocol member function. Calls SerialIo:Write() Writes 8 bytes at\r | |
356 | a time and does a GetControl between 8 byte writes to help insure reads are\r | |
357 | interspersed This is poor-man's flow control.\r | |
358 | \r | |
359 | @param This Pointer to DebugPort protocol.\r | |
360 | @param Timeout Timeout value.\r | |
361 | @param BufferSize On input, the size of Buffer.\r | |
362 | On output, the amount of data actually written.\r | |
363 | @param Buffer Pointer to buffer to read.\r | |
364 | \r | |
365 | @retval EFI_SUCCESS The data was written.\r | |
366 | @retval others Fails when writting datas to debug port device.\r | |
367 | \r | |
368 | **/\r | |
c1f23d63 | 369 | EFI_STATUS\r |
370 | EFIAPI\r | |
371 | DebugPortWrite (\r | |
372 | IN EFI_DEBUGPORT_PROTOCOL *This,\r | |
373 | IN UINT32 Timeout,\r | |
374 | IN OUT UINTN *BufferSize,\r | |
375 | OUT VOID *Buffer\r | |
ed66e1bc | 376 | );\r |
c1f23d63 | 377 | \r |
49c8b87c | 378 | /**\r |
379 | DebugPort protocol member function. Calls SerialIo:Write() after setting\r | |
380 | if it's different than the last SerialIo access.\r | |
381 | \r | |
382 | @param This Pointer to DebugPort protocol.\r | |
383 | \r | |
384 | @retval EFI_SUCCESS At least 1 character is ready to be read from\r | |
385 | the DebugPort interface.\r | |
386 | @retval EFI_NOT_READY There are no characters ready to read from the\r | |
387 | DebugPort interface\r | |
388 | @retval EFI_DEVICE_ERROR A hardware failure occured... (from SerialIo)\r | |
389 | \r | |
390 | **/ \r | |
c1f23d63 | 391 | EFI_STATUS\r |
392 | EFIAPI\r | |
393 | DebugPortPoll (\r | |
394 | IN EFI_DEBUGPORT_PROTOCOL *This\r | |
ed66e1bc | 395 | );\r |
c1f23d63 | 396 | \r |
397 | #endif\r |