X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=Nt32Pkg%2FWinNtSerialIoDxe%2FWinNtSerialIo.c;h=23d3329d9db10fc383aa6f6f6e4ab2e56ad1615c;hb=c4122dcaadb964a3e5d2fe106939bca4f1c261e8;hp=5a55fa428c0aa4fa8a9d710f6e3a44a9a7b7bf8d;hpb=a00ec39b52224a40bf9a0a813b69cb43e14407a8;p=mirror_edk2.git diff --git a/Nt32Pkg/WinNtSerialIoDxe/WinNtSerialIo.c b/Nt32Pkg/WinNtSerialIoDxe/WinNtSerialIo.c index 5a55fa428c..23d3329d9d 100644 --- a/Nt32Pkg/WinNtSerialIoDxe/WinNtSerialIo.c +++ b/Nt32Pkg/WinNtSerialIoDxe/WinNtSerialIo.c @@ -1,7 +1,7 @@ /**@file -Copyright (c) 2006 - 2007, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2006 - 2010, 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 @@ -61,6 +61,51 @@ EFI_DRIVER_BINDING_PROTOCOL gWinNtSerialIoDriverBinding = { // UINT64 mBaudRateCurrentSupport[] = {50, 75, 110, 134, 150, 300, 600, 1200, 1800, 2000, 2400, 3600, 4800, 7200, 9600, 19200, 38400, 57600, 115200, SERIAL_PORT_MAX_BAUD_RATE + 1}; +/** + Check the device path node whether it's the Flow Control node or not. + + @param[in] FlowControl The device path node to be checked. + + @retval TRUE It's the Flow Control node. + @retval FALSE It's not. + +**/ +BOOLEAN +IsUartFlowControlNode ( + IN UART_FLOW_CONTROL_DEVICE_PATH *FlowControl + ) +{ + return (BOOLEAN) ( + (DevicePathType (FlowControl) == MESSAGING_DEVICE_PATH) && + (DevicePathSubType (FlowControl) == MSG_VENDOR_DP) && + (CompareGuid (&FlowControl->Guid, &gEfiUartDevicePathGuid)) + ); +} + +/** + Check the device path node whether it contains Flow Control node or not. + + @param[in] DevicePath The device path to be checked. + + @retval TRUE It contains the Flow Control node. + @retval FALSE It doesn't. + +**/ +BOOLEAN +ContainsFlowControl ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + while (!IsDevicePathEnd (DevicePath)) { + if (IsUartFlowControlNode ((UART_FLOW_CONTROL_DEVICE_PATH *) DevicePath)) { + return TRUE; + } + DevicePath = NextDevicePathNode (DevicePath); + } + + return FALSE; +} + /** The user Entry Point for module WinNtSerialIo. The user code starts with this function. @@ -121,41 +166,150 @@ Returns: // TODO: EFI_SUCCESS - add return value to function comment // TODO: EFI_SUCCESS - add return value to function comment { - EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath; - EFI_WIN_NT_IO_PROTOCOL *WinNtIo; - UART_DEVICE_PATH *UartNode; + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath; + EFI_WIN_NT_IO_PROTOCOL *WinNtIo; + UART_DEVICE_PATH *UartNode; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + UART_FLOW_CONTROL_DEVICE_PATH *FlowControlNode; + EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer; + UINTN EntryCount; + UINTN Index; + BOOLEAN RemainingDevicePathContainsFlowControl; + + // + // Check RemainingDevicePath validation + // + if (RemainingDevicePath != NULL) { + // + // Check if RemainingDevicePath is the End of Device Path Node, + // if yes, go on checking other conditions + // + if (!IsDevicePathEnd (RemainingDevicePath)) { + // + // If RemainingDevicePath isn't the End of Device Path Node, + // check its validation + // + Status = EFI_UNSUPPORTED; + + UartNode = (UART_DEVICE_PATH *) RemainingDevicePath; + if (UartNode->Header.Type != MESSAGING_DEVICE_PATH || + UartNode->Header.SubType != MSG_UART_DP || + DevicePathNodeLength((EFI_DEVICE_PATH_PROTOCOL *)UartNode) != sizeof(UART_DEVICE_PATH)) { + goto Error; + } + if ( UartNode->BaudRate > SERIAL_PORT_MAX_BAUD_RATE) { + goto Error; + } + if (UartNode->Parity < NoParity || UartNode->Parity > SpaceParity) { + goto Error; + } + if (UartNode->DataBits < 5 || UartNode->DataBits > 8) { + goto Error; + } + if (UartNode->StopBits < OneStopBit || UartNode->StopBits > TwoStopBits) { + goto Error; + } + if ((UartNode->DataBits == 5) && (UartNode->StopBits == TwoStopBits)) { + goto Error; + } + if ((UartNode->DataBits >= 6) && (UartNode->DataBits <= 8) && (UartNode->StopBits == OneFiveStopBits)) { + goto Error; + } + + FlowControlNode = (UART_FLOW_CONTROL_DEVICE_PATH *) NextDevicePathNode (UartNode); + if (IsUartFlowControlNode (FlowControlNode)) { + // + // If the second node is Flow Control Node, + // return error when it request other than hardware flow control. + // + if ((FlowControlNode->FlowControlMap & ~UART_FLOW_CONTROL_HARDWARE) != 0) { + goto Error; + } + } + } + } // // Open the IO Abstraction(s) needed to perform the supported test // Status = gBS->OpenProtocol ( Handle, - &gEfiDevicePathProtocolGuid, - (VOID **) &ParentDevicePath, + &gEfiWinNtIoProtocolGuid, + (VOID **) &WinNtIo, This->DriverBindingHandle, Handle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (Status == EFI_ALREADY_STARTED) { - return EFI_SUCCESS; + if (RemainingDevicePath == NULL || IsDevicePathEnd (RemainingDevicePath)) { + // + // If RemainingDevicePath is NULL or is the End of Device Path Node + // + return EFI_SUCCESS; + } + // + // When the driver has produced device path with flow control node but RemainingDevicePath only contains UART node, + // return unsupported, and vice versa. + // + Status = gBS->OpenProtocolInformation ( + Handle, + &gEfiWinNtIoProtocolGuid, + &OpenInfoBuffer, + &EntryCount + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // See if RemainingDevicePath has a Flow Control device path node + // + RemainingDevicePathContainsFlowControl = ContainsFlowControl (RemainingDevicePath); + + for (Index = 0; Index < EntryCount; Index++) { + if ((OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) { + Status = gBS->OpenProtocol ( + OpenInfoBuffer[Index].ControllerHandle, + &gEfiDevicePathProtocolGuid, + (VOID **) &DevicePath, + This->DriverBindingHandle, + Handle, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (!EFI_ERROR (Status)) { + if (RemainingDevicePathContainsFlowControl ^ ContainsFlowControl (DevicePath)) { + Status = EFI_UNSUPPORTED; + } + } + break; + } + } + FreePool (OpenInfoBuffer); + return Status; } if (EFI_ERROR (Status)) { return Status; } + // + // Close the I/O Abstraction(s) used to perform the supported test + // gBS->CloseProtocol ( Handle, - &gEfiDevicePathProtocolGuid, + &gEfiWinNtIoProtocolGuid, This->DriverBindingHandle, Handle ); + // + // Open the EFI Device Path protocol needed to perform the supported test + // Status = gBS->OpenProtocol ( Handle, - &gEfiWinNtIoProtocolGuid, - (VOID **) &WinNtIo, + &gEfiDevicePathProtocolGuid, + (VOID **) &ParentDevicePath, This->DriverBindingHandle, Handle, EFI_OPEN_PROTOCOL_BY_DRIVER @@ -168,6 +322,16 @@ Returns: return Status; } + // + // Close protocol, don't use device path protocol in the Support() function + // + gBS->CloseProtocol ( + Handle, + &gEfiDevicePathProtocolGuid, + This->DriverBindingHandle, + Handle + ); + // // Make sure that the WinNt Thunk Protocol is valid // @@ -184,46 +348,9 @@ Returns: goto Error; } - if (RemainingDevicePath != NULL) { - Status = EFI_UNSUPPORTED; - UartNode = (UART_DEVICE_PATH *) RemainingDevicePath; - if (UartNode->Header.Type != MESSAGING_DEVICE_PATH || - UartNode->Header.SubType != MSG_UART_DP || - DevicePathNodeLength((EFI_DEVICE_PATH_PROTOCOL *)UartNode) != sizeof(UART_DEVICE_PATH)) { - goto Error; - } - if ( UartNode->BaudRate > SERIAL_PORT_MAX_BAUD_RATE) { - goto Error; - } - if (UartNode->Parity < NoParity || UartNode->Parity > SpaceParity) { - goto Error; - } - if (UartNode->DataBits < 5 || UartNode->DataBits > 8) { - goto Error; - } - if (UartNode->StopBits < OneStopBit || UartNode->StopBits > TwoStopBits) { - goto Error; - } - if ((UartNode->DataBits == 5) && (UartNode->StopBits == TwoStopBits)) { - goto Error; - } - if ((UartNode->DataBits >= 6) && (UartNode->DataBits <= 8) && (UartNode->StopBits == OneFiveStopBits)) { - goto Error; - } - Status = EFI_SUCCESS; - } + return EFI_SUCCESS; Error: - // - // Close the I/O Abstraction(s) used to perform the supported test - // - gBS->CloseProtocol ( - Handle, - &gEfiWinNtIoProtocolGuid, - This->DriverBindingHandle, - Handle - ); - return Status; } @@ -255,18 +382,23 @@ Returns: EFI_WIN_NT_IO_PROTOCOL *WinNtIo; WIN_NT_SERIAL_IO_PRIVATE_DATA *Private; HANDLE NtHandle; - UART_DEVICE_PATH Node; + UART_DEVICE_PATH UartNode; EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath; EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer; UINTN EntryCount; UINTN Index; EFI_SERIAL_IO_PROTOCOL *SerialIo; + UART_DEVICE_PATH *Uart; + UINT32 FlowControlMap; + UART_FLOW_CONTROL_DEVICE_PATH *FlowControl; + EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; + UINT32 Control; Private = NULL; NtHandle = INVALID_HANDLE_VALUE; // - // Grab the protocols we need + // Get the Parent Device Path // Status = gBS->OpenProtocol ( Handle, @@ -303,7 +435,10 @@ Returns: if (Status == EFI_ALREADY_STARTED) { - if (RemainingDevicePath == NULL) { + if (RemainingDevicePath == NULL || IsDevicePathEnd (RemainingDevicePath)) { + // + // If RemainingDevicePath is NULL or is the End of Device Path Node + // return EFI_SUCCESS; } @@ -323,7 +458,7 @@ Returns: Status = EFI_ALREADY_STARTED; for (Index = 0; Index < EntryCount; Index++) { - if (OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) { + if ((OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) { Status = gBS->OpenProtocol ( OpenInfoBuffer[Index].ControllerHandle, &gEfiSerialIoProtocolGuid, @@ -333,16 +468,34 @@ Returns: EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (!EFI_ERROR (Status)) { - CopyMem (&Node, RemainingDevicePath, sizeof (UART_DEVICE_PATH)); + Uart = (UART_DEVICE_PATH *) RemainingDevicePath; Status = SerialIo->SetAttributes ( - SerialIo, - Node.BaudRate, - SerialIo->Mode->ReceiveFifoDepth, - SerialIo->Mode->Timeout, - (EFI_PARITY_TYPE)Node.Parity, - Node.DataBits, - (EFI_STOP_BITS_TYPE)Node.StopBits - ); + SerialIo, + Uart->BaudRate, + SerialIo->Mode->ReceiveFifoDepth, + SerialIo->Mode->Timeout, + (EFI_PARITY_TYPE) Uart->Parity, + Uart->DataBits, + (EFI_STOP_BITS_TYPE) Uart->StopBits + ); + FlowControl = (UART_FLOW_CONTROL_DEVICE_PATH *) NextDevicePathNode (Uart); + if (!EFI_ERROR (Status) && IsUartFlowControlNode (FlowControl)) { + Status = SerialIo->GetControl (SerialIo, &Control); + if (!EFI_ERROR (Status)) { + if (FlowControl->FlowControlMap == UART_FLOW_CONTROL_HARDWARE) { + Control |= EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE; + } else { + Control &= ~EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE; + } + // + // Clear the bits that are not allowed to pass to SetControl + // + Control &= (EFI_SERIAL_REQUEST_TO_SEND | EFI_SERIAL_DATA_TERMINAL_READY | + EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE | EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE | + EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE); + Status = SerialIo->SetControl (SerialIo, Control); + } + } } break; } @@ -352,6 +505,45 @@ Returns: return Status; } + FlowControl = NULL; + FlowControlMap = 0; + if (RemainingDevicePath == NULL) { + // + // Build the device path by appending the UART node to the ParentDevicePath + // from the WinNtIo handle. The Uart setings are zero here, since + // SetAttribute() will update them to match the default setings. + // + ZeroMem (&UartNode, sizeof (UART_DEVICE_PATH)); + UartNode.Header.Type = MESSAGING_DEVICE_PATH; + UartNode.Header.SubType = MSG_UART_DP; + SetDevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) &UartNode, sizeof (UART_DEVICE_PATH)); + + } else if (!IsDevicePathEnd (RemainingDevicePath)) { + // + // If RemainingDevicePath isn't the End of Device Path Node, + // only scan the specified device by RemainingDevicePath + // + // + // Match the configuration of the RemainingDevicePath. IsHandleSupported() + // already checked to make sure the RemainingDevicePath contains settings + // that we can support. + // + CopyMem (&UartNode, RemainingDevicePath, sizeof (UART_DEVICE_PATH)); + FlowControl = (UART_FLOW_CONTROL_DEVICE_PATH *) NextDevicePathNode (RemainingDevicePath); + if (IsUartFlowControlNode (FlowControl)) { + FlowControlMap = FlowControl->FlowControlMap; + } else { + FlowControl = NULL; + } + + } else { + // + // If RemainingDevicePath is the End of Device Path Node, + // skip enumerate any device and return EFI_SUCESSS + // + return EFI_SUCCESS; + } + // // Check to see if we can access the hardware device. If it's Open in NT we // will not get access. @@ -391,11 +583,13 @@ Returns: Private->SoftwareLoopbackEnable = FALSE; Private->HardwareLoopbackEnable = FALSE; - Private->HardwareFlowControl = FALSE; + Private->HardwareFlowControl = (BOOLEAN) (FlowControlMap == UART_FLOW_CONTROL_HARDWARE); Private->Fifo.First = 0; Private->Fifo.Last = 0; Private->Fifo.Surplus = SERIAL_MAX_BUFFER_SIZE; + CopyMem (&Private->UartDevicePath, &UartNode, sizeof (UART_DEVICE_PATH)); + AddUnicodeString2 ( "eng", gWinNtSerialIoComponentName.SupportedLanguages, @@ -421,25 +615,6 @@ Returns: Private->SerialIo.Read = WinNtSerialIoRead; Private->SerialIo.Mode = &Private->SerialIoMode; - if (RemainingDevicePath != NULL) { - // - // Match the configuration of the RemainingDevicePath. IsHandleSupported() - // already checked to make sure the RemainingDevicePath contains settings - // that we can support. - // - CopyMem (&Private->UartDevicePath, RemainingDevicePath, sizeof (UART_DEVICE_PATH)); - } else { - // - // Build the device path by appending the UART node to the ParentDevicePath - // from the WinNtIo handle. The Uart setings are zero here, since - // SetAttribute() will update them to match the default setings. - // - ZeroMem (&Private->UartDevicePath, sizeof (UART_DEVICE_PATH)); - Private->UartDevicePath.Header.Type = MESSAGING_DEVICE_PATH; - Private->UartDevicePath.Header.SubType = MSG_UART_DP; - SetDevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) &Private->UartDevicePath, sizeof (UART_DEVICE_PATH)); - } - // // Build the device path by appending the UART node to the ParentDevicePath // from the WinNtIo handle. The Uart setings are zero here, since @@ -449,6 +624,19 @@ Returns: ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &Private->UartDevicePath ); + // + // Only produce the FlowControl node when remaining device path has it + // + if (FlowControl != NULL) { + TempDevicePath = Private->DevicePath; + if (TempDevicePath != NULL) { + Private->DevicePath = AppendDevicePathNode ( + TempDevicePath, + (EFI_DEVICE_PATH_PROTOCOL *) FlowControl + ); + FreePool (TempDevicePath); + } + } if (Private->DevicePath == NULL) { Status = EFI_OUT_OF_RESOURCES; goto Error; @@ -752,7 +940,7 @@ Returns: COMMTIMEOUTS PortTimeOuts; DWORD ConvertedTime; BOOL Result; - EFI_DEVICE_PATH_PROTOCOL *NewDevicePath; + UART_DEVICE_PATH *Uart; EFI_TPL Tpl; Private = WIN_NT_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This); @@ -762,7 +950,7 @@ Returns: // we must set the default values if a null argument is passed in. // if (BaudRate == 0) { - BaudRate = FixedPcdGet64 (PcdUartDefaultBaudRate); + BaudRate = PcdGet64 (PcdUartDefaultBaudRate); } if (ReceiveFifoDepth == 0) { @@ -774,15 +962,15 @@ Returns: } if (Parity == DefaultParity) { - Parity = (EFI_PARITY_TYPE) (FixedPcdGet8 (PcdUartDefaultParity)); + Parity = (EFI_PARITY_TYPE) (PcdGet8 (PcdUartDefaultParity)); } if (DataBits == 0) { - DataBits = FixedPcdGet8 (PcdUartDefaultDataBits); + DataBits = PcdGet8 (PcdUartDefaultDataBits); } if (StopBits == DefaultStopBits) { - StopBits = (EFI_STOP_BITS_TYPE) FixedPcdGet8 (PcdUartDefaultStopBits); + StopBits = (EFI_STOP_BITS_TYPE) PcdGet8 (PcdUartDefaultStopBits); } // @@ -796,13 +984,13 @@ Returns: //The lower baud rate supported by the serial device will be selected without exceeding the unsupported BaudRate parameter // - for (Index = 1; Index < (sizeof (mBaudRateCurrentSupport) / sizeof (mBaudRateCurrentSupport[0])); Index++) { + for (Index = 1; Index < (ARRAY_SIZE (mBaudRateCurrentSupport)); Index++) { if (BaudRate < mBaudRateCurrentSupport[Index]) { BaudRate = mBaudRateCurrentSupport[Index-1]; break; } } - + if ((ReceiveFifoDepth < 1) || (ReceiveFifoDepth > SERIAL_PORT_MAX_RECEIVE_FIFO_DEPTH)) { return EFI_INVALID_PARAMETER; } @@ -937,37 +1125,25 @@ Returns: Private->UartDevicePath.Parity = (UINT8) Parity; Private->UartDevicePath.StopBits = (UINT8) StopBits; - NewDevicePath = AppendDevicePathNode ( - Private->ParentDevicePath, - (EFI_DEVICE_PATH_PROTOCOL *) &Private->UartDevicePath - ); - if (NewDevicePath == NULL) { - gBS->RestoreTPL (Tpl); - return EFI_DEVICE_ERROR; - } - + Status = EFI_SUCCESS; if (Private->Handle != NULL) { + Uart = (UART_DEVICE_PATH *) ( + (UINTN) Private->DevicePath + + GetDevicePathSize (Private->ParentDevicePath) + - END_DEVICE_PATH_LENGTH + ); + CopyMem (Uart, &Private->UartDevicePath, sizeof (UART_DEVICE_PATH)); Status = gBS->ReinstallProtocolInterface ( Private->Handle, &gEfiDevicePathProtocolGuid, Private->DevicePath, - NewDevicePath + Private->DevicePath ); - if (EFI_ERROR (Status)) { - gBS->RestoreTPL (Tpl); - return Status; - } } - if (Private->DevicePath != NULL) { - FreePool (Private->DevicePath); - } - - Private->DevicePath = NewDevicePath; - gBS->RestoreTPL (Tpl); - return EFI_SUCCESS; + return Status; } EFI_STATUS @@ -999,6 +1175,8 @@ Returns: BOOL Result; DCB Dcb; EFI_TPL Tpl; + UART_FLOW_CONTROL_DEVICE_PATH *FlowControl; + EFI_STATUS Status; // // first determine the parameter is invalid @@ -1060,9 +1238,32 @@ Returns: return EFI_DEVICE_ERROR; } + Status = EFI_SUCCESS; + if (Private->Handle != NULL) { + FlowControl = (UART_FLOW_CONTROL_DEVICE_PATH *) ( + (UINTN) Private->DevicePath + + GetDevicePathSize (Private->ParentDevicePath) + - END_DEVICE_PATH_LENGTH + + sizeof (UART_DEVICE_PATH) + ); + if (IsUartFlowControlNode (FlowControl) && + ((FlowControl->FlowControlMap == UART_FLOW_CONTROL_HARDWARE) ^ Private->HardwareFlowControl)) { + // + // Flow Control setting is changed, need to reinstall device path protocol + // + FlowControl->FlowControlMap = Private->HardwareFlowControl ? UART_FLOW_CONTROL_HARDWARE : 0; + Status = gBS->ReinstallProtocolInterface ( + Private->Handle, + &gEfiDevicePathProtocolGuid, + Private->DevicePath, + Private->DevicePath + ); + } + } + gBS->RestoreTPL (Tpl); - return EFI_SUCCESS; + return Status; } EFI_STATUS