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