X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FDebugPortDxe%2FDebugPort.c;h=00889a246d8fc801a6ad4b274d51877f6ef0fdae;hp=5881668d7fe3569866a1d83fdef457ca3c19ffc0;hb=20182c7ea10f9f2ec48037ad7b0338185e45ecac;hpb=0da0de5ed842d9111965157d465110af90dbeecd diff --git a/MdeModulePkg/Universal/DebugPortDxe/DebugPort.c b/MdeModulePkg/Universal/DebugPortDxe/DebugPort.c index 5881668d7f..00889a246d 100644 --- a/MdeModulePkg/Universal/DebugPortDxe/DebugPort.c +++ b/MdeModulePkg/Universal/DebugPortDxe/DebugPort.c @@ -4,8 +4,8 @@ ALL CODE IN THE SERIALIO STACK MUST BE RE-ENTRANT AND CALLABLE FROM INTERRUPT CONTEXT -Copyright (c) 2006 - 2008, Intel Corporation.
-All rights reserved. This program and the accompanying materials +Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -33,13 +33,12 @@ DEBUGPORT_DEVICE mDebugPortDevice = { DEBUGPORT_DEVICE_SIGNATURE, (EFI_HANDLE) 0, (EFI_HANDLE) 0, - (VOID *) NULL, (EFI_DEVICE_PATH_PROTOCOL *) NULL, { DebugPortReset, - DebugPortRead, - DebugPortWrite, - DebugPortPoll + DebugPortWrite, + DebugPortRead, + DebugPortPoll }, (EFI_HANDLE) 0, (EFI_SERIAL_IO_PROTOCOL *) NULL, @@ -57,85 +56,65 @@ DEBUGPORT_DEVICE mDebugPortDevice = { Records requested settings in DebugPort device structure. **/ -VOID +EFI_DEVICE_PATH_PROTOCOL * GetDebugPortVariable ( VOID ) { UINTN DataSize; + EFI_DEVICE_PATH_PROTOCOL *DebugPortVariable; EFI_DEVICE_PATH_PROTOCOL *DevicePath; - EFI_STATUS Status; - - DataSize = 0; - - Status = gRT->GetVariable ( - (CHAR16 *) EFI_DEBUGPORT_VARIABLE_NAME, - &gEfiDebugPortVariableGuid, - NULL, - &DataSize, - mDebugPortDevice.DebugPortVariable - ); - if (Status == EFI_BUFFER_TOO_SMALL) { - if (mDebugPortDevice.DebugPortVariable != NULL) { - FreePool (mDebugPortDevice.DebugPortVariable); - } + GetVariable2 (EFI_DEBUGPORT_VARIABLE_NAME, &gEfiDebugPortVariableGuid, (VOID **) &DebugPortVariable, &DataSize); + if (DebugPortVariable == NULL) { + return NULL; + } - mDebugPortDevice.DebugPortVariable = AllocatePool (DataSize); - if (mDebugPortDevice.DebugPortVariable != NULL) { - gRT->GetVariable ( - (CHAR16 *) EFI_DEBUGPORT_VARIABLE_NAME, - &gEfiDebugPortVariableGuid, - NULL, - &DataSize, - mDebugPortDevice.DebugPortVariable - ); - DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) mDebugPortDevice.DebugPortVariable; - while (!IsDevicePathEnd (DevicePath) && !IS_UART_DEVICEPATH (DevicePath)) { - DevicePath = NextDevicePathNode (DevicePath); - } + DevicePath = DebugPortVariable; + while (!IsDevicePathEnd (DevicePath) && !IS_UART_DEVICEPATH (DevicePath)) { + DevicePath = NextDevicePathNode (DevicePath); + } - if (IsDevicePathEnd (DevicePath)) { - FreePool (mDebugPortDevice.DebugPortVariable); - mDebugPortDevice.DebugPortVariable = NULL; - } else { - CopyMem ( - &mDebugPortDevice.BaudRate, - &((UART_DEVICE_PATH *) DevicePath)->BaudRate, - sizeof (((UART_DEVICE_PATH *) DevicePath)->BaudRate) - ); - mDebugPortDevice.ReceiveFifoDepth = DEBUGPORT_UART_DEFAULT_FIFO_DEPTH; - mDebugPortDevice.Timeout = DEBUGPORT_UART_DEFAULT_TIMEOUT; - CopyMem ( - &mDebugPortDevice.Parity, - &((UART_DEVICE_PATH *) DevicePath)->Parity, - sizeof (((UART_DEVICE_PATH *) DevicePath)->Parity) - ); - CopyMem ( - &mDebugPortDevice.DataBits, - &((UART_DEVICE_PATH *) DevicePath)->DataBits, - sizeof (((UART_DEVICE_PATH *) DevicePath)->DataBits) - ); - CopyMem ( - &mDebugPortDevice.StopBits, - &((UART_DEVICE_PATH *) DevicePath)->StopBits, - sizeof (((UART_DEVICE_PATH *) DevicePath)->StopBits) - ); - } - } + if (IsDevicePathEnd (DevicePath)) { + FreePool (DebugPortVariable); + return NULL; + } else { + CopyMem ( + &mDebugPortDevice.BaudRate, + &((UART_DEVICE_PATH *) DevicePath)->BaudRate, + sizeof (((UART_DEVICE_PATH *) DevicePath)->BaudRate) + ); + mDebugPortDevice.ReceiveFifoDepth = DEBUGPORT_UART_DEFAULT_FIFO_DEPTH; + mDebugPortDevice.Timeout = DEBUGPORT_UART_DEFAULT_TIMEOUT; + CopyMem ( + &mDebugPortDevice.Parity, + &((UART_DEVICE_PATH *) DevicePath)->Parity, + sizeof (((UART_DEVICE_PATH *) DevicePath)->Parity) + ); + CopyMem ( + &mDebugPortDevice.DataBits, + &((UART_DEVICE_PATH *) DevicePath)->DataBits, + sizeof (((UART_DEVICE_PATH *) DevicePath)->DataBits) + ); + CopyMem ( + &mDebugPortDevice.StopBits, + &((UART_DEVICE_PATH *) DevicePath)->StopBits, + sizeof (((UART_DEVICE_PATH *) DevicePath)->StopBits) + ); + return DebugPortVariable; } } /** - Debug Port Driver entry point. + Debug Port Driver entry point. Reads DebugPort variable to determine what device and settings to use as the debug port. Binds exclusively to SerialIo. Reverts to defaults if no variable is found. - @param[in] ImageHandle The firmware allocated handle for the EFI image. + @param[in] ImageHandle The firmware allocated handle for the EFI image. @param[in] SystemTable A pointer to the EFI System Table. - + @retval EFI_SUCCESS The entry point is executed successfully. @retval EFI_OUT_OF_RESOURCES Fails to allocate memory for device. @retval other Some error occurs when executing this entry point. @@ -167,7 +146,7 @@ InitializeDebugPortDriver ( } /** - Checks to see if there's not already a DebugPort interface somewhere. + Checks to see if there's not already a DebugPort interface somewhere. If there's a DEBUGPORT variable, the device path must match exactly. If there's no DEBUGPORT variable, then device path is not checked and does not matter. @@ -196,8 +175,8 @@ DebugPortSupported ( ) { EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *Dp1; - EFI_DEVICE_PATH_PROTOCOL *Dp2; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_DEVICE_PATH_PROTOCOL *DebugPortVariable; EFI_SERIAL_IO_PROTOCOL *SerialIo; EFI_DEBUGPORT_PROTOCOL *DebugPortInterface; EFI_HANDLE TempHandle; @@ -212,25 +191,19 @@ DebugPortSupported ( // // Read DebugPort variable to determine debug port selection and parameters // - GetDebugPortVariable (); + DebugPortVariable = GetDebugPortVariable (); - if (mDebugPortDevice.DebugPortVariable != NULL) { + if (DebugPortVariable != NULL) { // // There's a DEBUGPORT variable, so do LocateDevicePath and check to see if // the closest matching handle matches the controller handle, and if it does, // check to see that the remaining device path has the DebugPort GUIDed messaging // device path only. Otherwise, it's a mismatch and EFI_UNSUPPORTED is returned. // - Dp1 = DuplicateDevicePath ((EFI_DEVICE_PATH_PROTOCOL *) mDebugPortDevice.DebugPortVariable); - if (Dp1 == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - Dp2 = Dp1; - + DevicePath = DebugPortVariable; Status = gBS->LocateDevicePath ( &gEfiSerialIoProtocolGuid, - &Dp2, + &DevicePath, &TempHandle ); @@ -238,19 +211,19 @@ DebugPortSupported ( Status = EFI_UNSUPPORTED; } - if (Status == EFI_SUCCESS && - (Dp2->Type != MESSAGING_DEVICE_PATH || - Dp2->SubType != MSG_VENDOR_DP || - *((UINT16 *) Dp2->Length) != sizeof (DEBUGPORT_DEVICE_PATH))) { + if (Status == EFI_SUCCESS && + (DevicePath->Type != MESSAGING_DEVICE_PATH || + DevicePath->SubType != MSG_VENDOR_DP || + *((UINT16 *) DevicePath->Length) != sizeof (DEBUGPORT_DEVICE_PATH))) { Status = EFI_UNSUPPORTED; } - if (Status == EFI_SUCCESS && CompareMem (&gEfiDebugPortDevicePathGuid, Dp2 + 1, sizeof (EFI_GUID))) { + if (Status == EFI_SUCCESS && !CompareGuid (&gEfiDebugPortDevicePathGuid, (GUID *) (DevicePath + 1))) { Status = EFI_UNSUPPORTED; } - FreePool (Dp1); + FreePool (DebugPortVariable); if (EFI_ERROR (Status)) { return Status; } @@ -289,7 +262,7 @@ DebugPortSupported ( @retval EFI_SUCCESS This driver is added to ControllerHandle. @retval EFI_OUT_OF_RESOURCES Fails to allocate memory for device. - @retval others Some error occurs. + @retval others Some error occurs. **/ EFI_STATUS @@ -365,7 +338,7 @@ DebugPortStart ( DebugPortDP.Header.Type = MESSAGING_DEVICE_PATH; DebugPortDP.Header.SubType = MSG_VENDOR_DP; SetDevicePathNodeLength (&(DebugPortDP.Header), sizeof (DebugPortDP)); - CopyMem (&DebugPortDP.Guid, &gEfiDebugPortDevicePathGuid, sizeof (EFI_GUID)); + CopyGuid (&DebugPortDP.Guid, &gEfiDebugPortDevicePathGuid); Dp1 = DevicePathFromHandle (ControllerHandle); if (Dp1 == NULL) { @@ -411,18 +384,6 @@ DebugPortStart ( ); if (EFI_ERROR (Status)) { - DEBUG_CODE_BEGIN (); - UINTN BufferSize; - - BufferSize = 48; - DebugPortWrite ( - &mDebugPortDevice.DebugPortInterface, - 0, - &BufferSize, - "DebugPort driver failed to open child controller\n\n" - ); - DEBUG_CODE_END (); - gBS->CloseProtocol ( ControllerHandle, &gEfiSerialIoProtocolGuid, @@ -432,19 +393,6 @@ DebugPortStart ( return Status; } - DEBUG_CODE_BEGIN (); - UINTN BufferSize; - - BufferSize = 38; - DebugPortWrite ( - &mDebugPortDevice.DebugPortInterface, - 0, - &BufferSize, - "Hello World from the DebugPort driver\n\n" - ); - - DEBUG_CODE_END (); - return EFI_SUCCESS; } @@ -547,11 +495,11 @@ DebugPortStop ( The port itself should be fine since it was set up during initialization. - @param This Protocol instance pointer. + @param This Protocol instance pointer. @return EFI_SUCCESS Always. -**/ +**/ EFI_STATUS EFIAPI DebugPortReset ( @@ -579,8 +527,8 @@ DebugPortReset ( On output, the amount of data actually written. @param Buffer Pointer to buffer to read. - @retval EFI_SUCCESS - @retval others + @retval EFI_SUCCESS + @retval others **/ EFI_STATUS @@ -692,7 +640,7 @@ DebugPortWrite ( DebugPort interface @retval EFI_DEVICE_ERROR A hardware failure occured... (from SerialIo) -**/ +**/ EFI_STATUS EFIAPI DebugPortPoll ( @@ -738,16 +686,60 @@ ImageUnloadHandler ( EFI_HANDLE ImageHandle ) { + EFI_STATUS Status; + VOID *ComponentName; + VOID *ComponentName2; + if (mDebugPortDevice.SerialIoBinding != NULL) { return EFI_ABORTED; } // - // Clean up allocations + // Driver is stopped already. // - if (mDebugPortDevice.DebugPortVariable != NULL) { - FreePool (mDebugPortDevice.DebugPortVariable); + Status = gBS->HandleProtocol (ImageHandle, &gEfiComponentNameProtocolGuid, &ComponentName); + if (EFI_ERROR (Status)) { + ComponentName = NULL; } - return EFI_SUCCESS; + Status = gBS->HandleProtocol (ImageHandle, &gEfiComponentName2ProtocolGuid, &ComponentName2); + if (EFI_ERROR (Status)) { + ComponentName2 = NULL; + } + + if (ComponentName == NULL) { + if (ComponentName2 == NULL) { + Status = gBS->UninstallMultipleProtocolInterfaces ( + ImageHandle, + &gEfiDriverBindingProtocolGuid, &gDebugPortDriverBinding, + NULL + ); + } else { + Status = gBS->UninstallMultipleProtocolInterfaces ( + ImageHandle, + &gEfiDriverBindingProtocolGuid, &gDebugPortDriverBinding, + &gEfiComponentName2ProtocolGuid, ComponentName2, + NULL + ); + } + } else { + if (ComponentName2 == NULL) { + Status = gBS->UninstallMultipleProtocolInterfaces ( + ImageHandle, + &gEfiDriverBindingProtocolGuid, &gDebugPortDriverBinding, + &gEfiComponentNameProtocolGuid, ComponentName, + NULL + ); + } else { + Status = gBS->UninstallMultipleProtocolInterfaces ( + ImageHandle, + &gEfiDriverBindingProtocolGuid, &gDebugPortDriverBinding, + &gEfiComponentNameProtocolGuid, ComponentName, + &gEfiComponentName2ProtocolGuid, ComponentName2, + NULL + ); + } + } + + return Status; }