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