2616299df7d48c21a71a608dbb93cf61828b15c2
[mirror_edk2.git] / MdeModulePkg / Universal / DebugPortDxe / DebugPort.c
1 /** @file
2 Top level C file for debugport driver. Contains initialization function.
3 This driver layers on top of SerialIo.
4 ALL CODE IN THE SERIALIO STACK MUST BE RE-ENTRANT AND CALLABLE FROM
5 INTERRUPT CONTEXT
6
7 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17
18 #include "DebugPort.h"
19
20 //
21 // Globals
22 //
23 EFI_DRIVER_BINDING_PROTOCOL gDebugPortDriverBinding = {
24 DebugPortSupported,
25 DebugPortStart,
26 DebugPortStop,
27 DEBUGPORT_DRIVER_VERSION,
28 NULL,
29 NULL
30 };
31
32 DEBUGPORT_DEVICE mDebugPortDevice = {
33 DEBUGPORT_DEVICE_SIGNATURE,
34 (EFI_HANDLE) 0,
35 (EFI_HANDLE) 0,
36 (VOID *) NULL,
37 (EFI_DEVICE_PATH_PROTOCOL *) NULL,
38 {
39 DebugPortReset,
40 DebugPortWrite,
41 DebugPortRead,
42 DebugPortPoll
43 },
44 (EFI_HANDLE) 0,
45 (EFI_SERIAL_IO_PROTOCOL *) NULL,
46 DEBUGPORT_UART_DEFAULT_BAUDRATE,
47 DEBUGPORT_UART_DEFAULT_FIFO_DEPTH,
48 DEBUGPORT_UART_DEFAULT_TIMEOUT,
49 (EFI_PARITY_TYPE) DEBUGPORT_UART_DEFAULT_PARITY,
50 DEBUGPORT_UART_DEFAULT_DATA_BITS,
51 (EFI_STOP_BITS_TYPE) DEBUGPORT_UART_DEFAULT_STOP_BITS
52 };
53
54 /**
55 Local worker function to obtain device path information from DebugPort variable.
56
57 Records requested settings in DebugPort device structure.
58
59 **/
60 VOID
61 GetDebugPortVariable (
62 VOID
63 )
64 {
65 UINTN DataSize;
66 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
67 EFI_STATUS Status;
68
69 DataSize = 0;
70
71 Status = gRT->GetVariable (
72 (CHAR16 *) EFI_DEBUGPORT_VARIABLE_NAME,
73 &gEfiDebugPortVariableGuid,
74 NULL,
75 &DataSize,
76 mDebugPortDevice.DebugPortVariable
77 );
78
79 if (Status == EFI_BUFFER_TOO_SMALL) {
80 if (mDebugPortDevice.DebugPortVariable != NULL) {
81 FreePool (mDebugPortDevice.DebugPortVariable);
82 }
83
84 mDebugPortDevice.DebugPortVariable = AllocatePool (DataSize);
85 if (mDebugPortDevice.DebugPortVariable != NULL) {
86 gRT->GetVariable (
87 (CHAR16 *) EFI_DEBUGPORT_VARIABLE_NAME,
88 &gEfiDebugPortVariableGuid,
89 NULL,
90 &DataSize,
91 mDebugPortDevice.DebugPortVariable
92 );
93 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) mDebugPortDevice.DebugPortVariable;
94 while (!IsDevicePathEnd (DevicePath) && !IS_UART_DEVICEPATH (DevicePath)) {
95 DevicePath = NextDevicePathNode (DevicePath);
96 }
97
98 if (IsDevicePathEnd (DevicePath)) {
99 FreePool (mDebugPortDevice.DebugPortVariable);
100 mDebugPortDevice.DebugPortVariable = NULL;
101 } else {
102 CopyMem (
103 &mDebugPortDevice.BaudRate,
104 &((UART_DEVICE_PATH *) DevicePath)->BaudRate,
105 sizeof (((UART_DEVICE_PATH *) DevicePath)->BaudRate)
106 );
107 mDebugPortDevice.ReceiveFifoDepth = DEBUGPORT_UART_DEFAULT_FIFO_DEPTH;
108 mDebugPortDevice.Timeout = DEBUGPORT_UART_DEFAULT_TIMEOUT;
109 CopyMem (
110 &mDebugPortDevice.Parity,
111 &((UART_DEVICE_PATH *) DevicePath)->Parity,
112 sizeof (((UART_DEVICE_PATH *) DevicePath)->Parity)
113 );
114 CopyMem (
115 &mDebugPortDevice.DataBits,
116 &((UART_DEVICE_PATH *) DevicePath)->DataBits,
117 sizeof (((UART_DEVICE_PATH *) DevicePath)->DataBits)
118 );
119 CopyMem (
120 &mDebugPortDevice.StopBits,
121 &((UART_DEVICE_PATH *) DevicePath)->StopBits,
122 sizeof (((UART_DEVICE_PATH *) DevicePath)->StopBits)
123 );
124 }
125 }
126 }
127 }
128
129 /**
130 Debug Port Driver entry point.
131
132 Reads DebugPort variable to determine what device and settings to use as the
133 debug port. Binds exclusively to SerialIo. Reverts to defaults if no variable
134 is found.
135
136 @param[in] ImageHandle The firmware allocated handle for the EFI image.
137 @param[in] SystemTable A pointer to the EFI System Table.
138
139 @retval EFI_SUCCESS The entry point is executed successfully.
140 @retval EFI_OUT_OF_RESOURCES Fails to allocate memory for device.
141 @retval other Some error occurs when executing this entry point.
142
143 **/
144 EFI_STATUS
145 EFIAPI
146 InitializeDebugPortDriver (
147 IN EFI_HANDLE ImageHandle,
148 IN EFI_SYSTEM_TABLE *SystemTable
149 )
150 {
151 EFI_STATUS Status;
152
153 //
154 // Install driver model protocol(s).
155 //
156 Status = EfiLibInstallDriverBindingComponentName2 (
157 ImageHandle,
158 SystemTable,
159 &gDebugPortDriverBinding,
160 ImageHandle,
161 &gDebugPortComponentName,
162 &gDebugPortComponentName2
163 );
164 ASSERT_EFI_ERROR (Status);
165
166 return EFI_SUCCESS;
167 }
168
169 /**
170 Checks to see if there's not already a DebugPort interface somewhere.
171
172 If there's a DEBUGPORT variable, the device path must match exactly. If there's
173 no DEBUGPORT variable, then device path is not checked and does not matter.
174 Checks to see that there's a serial io interface on the controller handle
175 that can be bound BY_DRIVER | EXCLUSIVE.
176 If all these tests succeed, then we return EFI_SUCCESS, else, EFI_UNSUPPORTED
177 or other error returned by OpenProtocol.
178
179 @param This Protocol instance pointer.
180 @param ControllerHandle Handle of device to test.
181 @param RemainingDevicePath Optional parameter use to pick a specific child
182 device to start.
183
184 @retval EFI_SUCCESS This driver supports this device.
185 @retval EFI_UNSUPPORTED Debug Port device is not supported.
186 @retval EFI_OUT_OF_RESOURCES Fails to allocate memory for device.
187 @retval others Some error occurs.
188
189 **/
190 EFI_STATUS
191 EFIAPI
192 DebugPortSupported (
193 IN EFI_DRIVER_BINDING_PROTOCOL *This,
194 IN EFI_HANDLE ControllerHandle,
195 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
196 )
197 {
198 EFI_STATUS Status;
199 EFI_DEVICE_PATH_PROTOCOL *Dp1;
200 EFI_DEVICE_PATH_PROTOCOL *Dp2;
201 EFI_SERIAL_IO_PROTOCOL *SerialIo;
202 EFI_DEBUGPORT_PROTOCOL *DebugPortInterface;
203 EFI_HANDLE TempHandle;
204
205 //
206 // Check to see that there's not a debugport protocol already published,
207 // since only one standard UART serial port could be supported by this driver.
208 //
209 if (gBS->LocateProtocol (&gEfiDebugPortProtocolGuid, NULL, (VOID **) &DebugPortInterface) != EFI_NOT_FOUND) {
210 return EFI_UNSUPPORTED;
211 }
212 //
213 // Read DebugPort variable to determine debug port selection and parameters
214 //
215 GetDebugPortVariable ();
216
217 if (mDebugPortDevice.DebugPortVariable != NULL) {
218 //
219 // There's a DEBUGPORT variable, so do LocateDevicePath and check to see if
220 // the closest matching handle matches the controller handle, and if it does,
221 // check to see that the remaining device path has the DebugPort GUIDed messaging
222 // device path only. Otherwise, it's a mismatch and EFI_UNSUPPORTED is returned.
223 //
224 Dp1 = DuplicateDevicePath ((EFI_DEVICE_PATH_PROTOCOL *) mDebugPortDevice.DebugPortVariable);
225 if (Dp1 == NULL) {
226 return EFI_OUT_OF_RESOURCES;
227 }
228
229 Dp2 = Dp1;
230
231 Status = gBS->LocateDevicePath (
232 &gEfiSerialIoProtocolGuid,
233 &Dp2,
234 &TempHandle
235 );
236
237 if (Status == EFI_SUCCESS && TempHandle != ControllerHandle) {
238 Status = EFI_UNSUPPORTED;
239 }
240
241 if (Status == EFI_SUCCESS &&
242 (Dp2->Type != MESSAGING_DEVICE_PATH ||
243 Dp2->SubType != MSG_VENDOR_DP ||
244 *((UINT16 *) Dp2->Length) != sizeof (DEBUGPORT_DEVICE_PATH))) {
245
246 Status = EFI_UNSUPPORTED;
247 }
248
249 if (Status == EFI_SUCCESS && !CompareGuid (&gEfiDebugPortDevicePathGuid, (GUID *) (Dp2 + 1))) {
250 Status = EFI_UNSUPPORTED;
251 }
252
253 FreePool (Dp1);
254 if (EFI_ERROR (Status)) {
255 return Status;
256 }
257 }
258
259 Status = gBS->OpenProtocol (
260 ControllerHandle,
261 &gEfiSerialIoProtocolGuid,
262 (VOID **) &SerialIo,
263 This->DriverBindingHandle,
264 ControllerHandle,
265 EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE
266 );
267 if (EFI_ERROR (Status)) {
268 return Status;
269 }
270
271 gBS->CloseProtocol (
272 ControllerHandle,
273 &gEfiSerialIoProtocolGuid,
274 This->DriverBindingHandle,
275 ControllerHandle
276 );
277
278 return EFI_SUCCESS;
279 }
280
281 /**
282 Binds exclusively to serial io on the controller handle, Produces DebugPort
283 protocol and DevicePath on new handle.
284
285 @param This Protocol instance pointer.
286 @param ControllerHandle Handle of device to bind driver to.
287 @param RemainingDevicePath Optional parameter use to pick a specific child
288 device to start.
289
290 @retval EFI_SUCCESS This driver is added to ControllerHandle.
291 @retval EFI_OUT_OF_RESOURCES Fails to allocate memory for device.
292 @retval others Some error occurs.
293
294 **/
295 EFI_STATUS
296 EFIAPI
297 DebugPortStart (
298 IN EFI_DRIVER_BINDING_PROTOCOL *This,
299 IN EFI_HANDLE ControllerHandle,
300 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
301 )
302 {
303 EFI_STATUS Status;
304 DEBUGPORT_DEVICE_PATH DebugPortDP;
305 EFI_DEVICE_PATH_PROTOCOL EndDP;
306 EFI_DEVICE_PATH_PROTOCOL *Dp1;
307
308 Status = gBS->OpenProtocol (
309 ControllerHandle,
310 &gEfiSerialIoProtocolGuid,
311 (VOID **) &mDebugPortDevice.SerialIoBinding,
312 This->DriverBindingHandle,
313 ControllerHandle,
314 EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE
315 );
316 if (EFI_ERROR (Status)) {
317 return Status;
318 }
319
320 mDebugPortDevice.SerialIoDeviceHandle = ControllerHandle;
321
322 //
323 // Initialize the Serial Io interface...
324 //
325 Status = mDebugPortDevice.SerialIoBinding->SetAttributes (
326 mDebugPortDevice.SerialIoBinding,
327 mDebugPortDevice.BaudRate,
328 mDebugPortDevice.ReceiveFifoDepth,
329 mDebugPortDevice.Timeout,
330 mDebugPortDevice.Parity,
331 mDebugPortDevice.DataBits,
332 mDebugPortDevice.StopBits
333 );
334 if (EFI_ERROR (Status)) {
335 mDebugPortDevice.BaudRate = 0;
336 mDebugPortDevice.Parity = DefaultParity;
337 mDebugPortDevice.DataBits = 0;
338 mDebugPortDevice.StopBits = DefaultStopBits;
339 mDebugPortDevice.ReceiveFifoDepth = 0;
340 Status = mDebugPortDevice.SerialIoBinding->SetAttributes (
341 mDebugPortDevice.SerialIoBinding,
342 mDebugPortDevice.BaudRate,
343 mDebugPortDevice.ReceiveFifoDepth,
344 mDebugPortDevice.Timeout,
345 mDebugPortDevice.Parity,
346 mDebugPortDevice.DataBits,
347 mDebugPortDevice.StopBits
348 );
349 if (EFI_ERROR (Status)) {
350 gBS->CloseProtocol (
351 ControllerHandle,
352 &gEfiSerialIoProtocolGuid,
353 This->DriverBindingHandle,
354 ControllerHandle
355 );
356 return Status;
357 }
358 }
359
360 mDebugPortDevice.SerialIoBinding->Reset (mDebugPortDevice.SerialIoBinding);
361
362 //
363 // Create device path instance for DebugPort
364 //
365 DebugPortDP.Header.Type = MESSAGING_DEVICE_PATH;
366 DebugPortDP.Header.SubType = MSG_VENDOR_DP;
367 SetDevicePathNodeLength (&(DebugPortDP.Header), sizeof (DebugPortDP));
368 CopyGuid (&DebugPortDP.Guid, &gEfiDebugPortDevicePathGuid);
369
370 Dp1 = DevicePathFromHandle (ControllerHandle);
371 if (Dp1 == NULL) {
372 Dp1 = &EndDP;
373 SetDevicePathEndNode (Dp1);
374 }
375
376 mDebugPortDevice.DebugPortDevicePath = AppendDevicePathNode (Dp1, (EFI_DEVICE_PATH_PROTOCOL *) &DebugPortDP);
377 if (mDebugPortDevice.DebugPortDevicePath == NULL) {
378 return EFI_OUT_OF_RESOURCES;
379 }
380 //
381 // Publish DebugPort and Device Path protocols
382 //
383 Status = gBS->InstallMultipleProtocolInterfaces (
384 &mDebugPortDevice.DebugPortDeviceHandle,
385 &gEfiDevicePathProtocolGuid,
386 mDebugPortDevice.DebugPortDevicePath,
387 &gEfiDebugPortProtocolGuid,
388 &mDebugPortDevice.DebugPortInterface,
389 NULL
390 );
391
392 if (EFI_ERROR (Status)) {
393 gBS->CloseProtocol (
394 ControllerHandle,
395 &gEfiSerialIoProtocolGuid,
396 This->DriverBindingHandle,
397 ControllerHandle
398 );
399 return Status;
400 }
401 //
402 // Connect debugport child to serial io
403 //
404 Status = gBS->OpenProtocol (
405 ControllerHandle,
406 &gEfiSerialIoProtocolGuid,
407 (VOID **) &mDebugPortDevice.SerialIoBinding,
408 This->DriverBindingHandle,
409 mDebugPortDevice.DebugPortDeviceHandle,
410 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
411 );
412
413 if (EFI_ERROR (Status)) {
414 gBS->CloseProtocol (
415 ControllerHandle,
416 &gEfiSerialIoProtocolGuid,
417 This->DriverBindingHandle,
418 ControllerHandle
419 );
420 return Status;
421 }
422
423 return EFI_SUCCESS;
424 }
425
426 /**
427 Stop this driver on ControllerHandle by removing Serial IO protocol on
428 the ControllerHandle.
429
430 @param This Protocol instance pointer.
431 @param ControllerHandle Handle of device to stop driver on
432 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
433 children is zero stop the entire bus driver.
434 @param ChildHandleBuffer List of Child Handles to Stop.
435
436 @retval EFI_SUCCESS This driver is removed ControllerHandle.
437 @retval other This driver was not removed from this device.
438
439 **/
440 EFI_STATUS
441 EFIAPI
442 DebugPortStop (
443 IN EFI_DRIVER_BINDING_PROTOCOL *This,
444 IN EFI_HANDLE ControllerHandle,
445 IN UINTN NumberOfChildren,
446 IN EFI_HANDLE *ChildHandleBuffer
447 )
448 {
449 EFI_STATUS Status;
450
451 if (NumberOfChildren == 0) {
452 //
453 // Close the bus driver
454 //
455 gBS->CloseProtocol (
456 ControllerHandle,
457 &gEfiSerialIoProtocolGuid,
458 This->DriverBindingHandle,
459 ControllerHandle
460 );
461
462 mDebugPortDevice.SerialIoBinding = NULL;
463
464 gBS->CloseProtocol (
465 ControllerHandle,
466 &gEfiDevicePathProtocolGuid,
467 This->DriverBindingHandle,
468 ControllerHandle
469 );
470
471 FreePool (mDebugPortDevice.DebugPortDevicePath);
472
473 return EFI_SUCCESS;
474 } else {
475 //
476 // Disconnect SerialIo child handle
477 //
478 Status = gBS->CloseProtocol (
479 mDebugPortDevice.SerialIoDeviceHandle,
480 &gEfiSerialIoProtocolGuid,
481 This->DriverBindingHandle,
482 mDebugPortDevice.DebugPortDeviceHandle
483 );
484
485 if (EFI_ERROR (Status)) {
486 return Status;
487 }
488 //
489 // Unpublish our protocols (DevicePath, DebugPort)
490 //
491 Status = gBS->UninstallMultipleProtocolInterfaces (
492 mDebugPortDevice.DebugPortDeviceHandle,
493 &gEfiDevicePathProtocolGuid,
494 mDebugPortDevice.DebugPortDevicePath,
495 &gEfiDebugPortProtocolGuid,
496 &mDebugPortDevice.DebugPortInterface,
497 NULL
498 );
499
500 if (EFI_ERROR (Status)) {
501 gBS->OpenProtocol (
502 ControllerHandle,
503 &gEfiSerialIoProtocolGuid,
504 (VOID **) &mDebugPortDevice.SerialIoBinding,
505 This->DriverBindingHandle,
506 mDebugPortDevice.DebugPortDeviceHandle,
507 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
508 );
509 } else {
510 mDebugPortDevice.DebugPortDeviceHandle = NULL;
511 }
512 }
513
514 return Status;
515 }
516
517 /**
518 DebugPort protocol member function. Calls SerialIo:GetControl to flush buffer.
519 We cannot call SerialIo:SetAttributes because it uses pool services, which use
520 locks, which affect TPL, so it's not interrupt context safe or re-entrant.
521 SerialIo:Reset() calls SetAttributes, so it can't be used either.
522
523 The port itself should be fine since it was set up during initialization.
524
525 @param This Protocol instance pointer.
526
527 @return EFI_SUCCESS Always.
528
529 **/
530 EFI_STATUS
531 EFIAPI
532 DebugPortReset (
533 IN EFI_DEBUGPORT_PROTOCOL *This
534 )
535 {
536 UINTN BufferSize;
537 UINTN BitBucket;
538
539 while (This->Poll (This) == EFI_SUCCESS) {
540 BufferSize = 1;
541 This->Read (This, 0, &BufferSize, &BitBucket);
542 }
543
544 return EFI_SUCCESS;
545 }
546
547 /**
548 DebugPort protocol member function. Calls SerialIo:Read() after setting
549 if it's different than the last SerialIo access.
550
551 @param This Pointer to DebugPort protocol.
552 @param Timeout Timeout value.
553 @param BufferSize On input, the size of Buffer.
554 On output, the amount of data actually written.
555 @param Buffer Pointer to buffer to read.
556
557 @retval EFI_SUCCESS
558 @retval others
559
560 **/
561 EFI_STATUS
562 EFIAPI
563 DebugPortRead (
564 IN EFI_DEBUGPORT_PROTOCOL *This,
565 IN UINT32 Timeout,
566 IN OUT UINTN *BufferSize,
567 IN VOID *Buffer
568 )
569 {
570 DEBUGPORT_DEVICE *DebugPortDevice;
571 UINTN LocalBufferSize;
572 EFI_STATUS Status;
573 UINT8 *BufferPtr;
574
575 DebugPortDevice = DEBUGPORT_DEVICE_FROM_THIS (This);
576 BufferPtr = Buffer;
577 LocalBufferSize = *BufferSize;
578
579 do {
580 Status = DebugPortDevice->SerialIoBinding->Read (
581 DebugPortDevice->SerialIoBinding,
582 &LocalBufferSize,
583 BufferPtr
584 );
585 if (Status == EFI_TIMEOUT) {
586 if (Timeout > DEBUGPORT_UART_DEFAULT_TIMEOUT) {
587 Timeout -= DEBUGPORT_UART_DEFAULT_TIMEOUT;
588 } else {
589 Timeout = 0;
590 }
591 } else if (EFI_ERROR (Status)) {
592 break;
593 }
594
595 BufferPtr += LocalBufferSize;
596 LocalBufferSize = *BufferSize - (BufferPtr - (UINT8 *) Buffer);
597 } while (LocalBufferSize != 0 && Timeout > 0);
598
599 *BufferSize = (UINTN) (BufferPtr - (UINT8 *) Buffer);
600
601 return Status;
602 }
603
604 /**
605 DebugPort protocol member function. Calls SerialIo:Write() Writes 8 bytes at
606 a time and does a GetControl between 8 byte writes to help insure reads are
607 interspersed This is poor-man's flow control.
608
609 @param This Pointer to DebugPort protocol.
610 @param Timeout Timeout value.
611 @param BufferSize On input, the size of Buffer.
612 On output, the amount of data actually written.
613 @param Buffer Pointer to buffer to read.
614
615 @retval EFI_SUCCESS The data was written.
616 @retval others Fails when writting datas to debug port device.
617
618 **/
619 EFI_STATUS
620 EFIAPI
621 DebugPortWrite (
622 IN EFI_DEBUGPORT_PROTOCOL *This,
623 IN UINT32 Timeout,
624 IN OUT UINTN *BufferSize,
625 OUT VOID *Buffer
626 )
627 {
628 DEBUGPORT_DEVICE *DebugPortDevice;
629 UINTN Position;
630 UINTN WriteSize;
631 EFI_STATUS Status;
632 UINT32 SerialControl;
633
634 Status = EFI_SUCCESS;
635 DebugPortDevice = DEBUGPORT_DEVICE_FROM_THIS (This);
636
637 WriteSize = 8;
638 for (Position = 0; Position < *BufferSize && !EFI_ERROR (Status); Position += WriteSize) {
639 DebugPortDevice->SerialIoBinding->GetControl (
640 DebugPortDevice->SerialIoBinding,
641 &SerialControl
642 );
643 if (*BufferSize - Position < 8) {
644 WriteSize = *BufferSize - Position;
645 }
646
647 Status = DebugPortDevice->SerialIoBinding->Write (
648 DebugPortDevice->SerialIoBinding,
649 &WriteSize,
650 &((UINT8 *) Buffer)[Position]
651 );
652 }
653
654 *BufferSize = Position;
655 return Status;
656 }
657
658 /**
659 DebugPort protocol member function. Calls SerialIo:Write() after setting
660 if it's different than the last SerialIo access.
661
662 @param This Pointer to DebugPort protocol.
663
664 @retval EFI_SUCCESS At least 1 character is ready to be read from
665 the DebugPort interface.
666 @retval EFI_NOT_READY There are no characters ready to read from the
667 DebugPort interface
668 @retval EFI_DEVICE_ERROR A hardware failure occured... (from SerialIo)
669
670 **/
671 EFI_STATUS
672 EFIAPI
673 DebugPortPoll (
674 IN EFI_DEBUGPORT_PROTOCOL *This
675 )
676 {
677 EFI_STATUS Status;
678 UINT32 SerialControl;
679 DEBUGPORT_DEVICE *DebugPortDevice;
680
681 DebugPortDevice = DEBUGPORT_DEVICE_FROM_THIS (This);
682
683 Status = DebugPortDevice->SerialIoBinding->GetControl (
684 DebugPortDevice->SerialIoBinding,
685 &SerialControl
686 );
687
688 if (!EFI_ERROR (Status)) {
689 if ((SerialControl & EFI_SERIAL_INPUT_BUFFER_EMPTY) != 0) {
690 Status = EFI_NOT_READY;
691 } else {
692 Status = EFI_SUCCESS;
693 }
694 }
695
696 return Status;
697 }
698
699 /**
700 Unload function that is registered in the LoadImage protocol. It un-installs
701 protocols produced and deallocates pool used by the driver. Called by the core
702 when unloading the driver.
703
704 @param ImageHandle
705
706 @retval EFI_SUCCESS Unload Debug Port driver successfully.
707 @retval EFI_ABORTED Serial IO is still binding.
708
709 **/
710 EFI_STATUS
711 EFIAPI
712 ImageUnloadHandler (
713 EFI_HANDLE ImageHandle
714 )
715 {
716 if (mDebugPortDevice.SerialIoBinding != NULL) {
717 return EFI_ABORTED;
718 }
719
720 //
721 // Clean up allocations
722 //
723 if (mDebugPortDevice.DebugPortVariable != NULL) {
724 FreePool (mDebugPortDevice.DebugPortVariable);
725 }
726
727 return EFI_SUCCESS;
728 }