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