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