/** 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; }
/** Update the multi-instance device path of Terminal Device based on the global TerminalMenu. If ChangeTernimal is TRUE, the terminal device path in the Terminal Device in TerminalMenu is also updated. @param DevicePath The multi-instance device path. @param ChangeTerminal TRUE, then device path in the Terminal Device in TerminalMenu is also updated; FALSE, no update. @return EFI_SUCCESS The function completes successfully. **/ EFI_STATUS ChangeTerminalDevicePath ( IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath, IN BOOLEAN ChangeTerminal ) { EFI_DEVICE_PATH_PROTOCOL *Node; EFI_DEVICE_PATH_PROTOCOL *Node1; ACPI_HID_DEVICE_PATH *Acpi; UART_DEVICE_PATH *Uart; UART_DEVICE_PATH *Uart1; UINTN Com; BM_TERMINAL_CONTEXT *NewTerminalContext; BM_MENU_ENTRY *NewMenuEntry; UART_FLOW_CONTROL_DEVICE_PATH *FlowControlNode; Node = *DevicePath; Node = NextDevicePathNode (Node); Com = 0; while (!IsDevicePathEnd (Node)) { Acpi = (ACPI_HID_DEVICE_PATH *) Node; if (IsIsaSerialNode (Acpi)) { CopyMem (&Com, &Acpi->UID, sizeof (UINT32)); } NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Com); NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext; if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) { Uart = (UART_DEVICE_PATH *) Node; CopyMem ( &Uart->BaudRate, &NewTerminalContext->BaudRate, sizeof (UINT64) ); CopyMem ( &Uart->DataBits, &NewTerminalContext->DataBits, sizeof (UINT8) ); CopyMem ( &Uart->Parity, &NewTerminalContext->Parity, sizeof (UINT8) ); CopyMem ( &Uart->StopBits, &NewTerminalContext->StopBits, sizeof (UINT8) ); FlowControlNode = (UART_FLOW_CONTROL_DEVICE_PATH *) NextDevicePathNode (Node); if (IsUartFlowControlNode (FlowControlNode)) { FlowControlNode->FlowControlMap = NewTerminalContext->FlowControl; } else { // // Append the Flow control device node when user enable flow control. // if (NewTerminalContext->FlowControl != 0) { mFlowControlDevicePath.FlowControlMap = NewTerminalContext->FlowControl; *DevicePath = AppendDevicePathNode ( *DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) (&mFlowControlDevicePath) ); } } // // Change the device path in the ComPort // if (ChangeTerminal) { Node1 = NewTerminalContext->DevicePath; Node1 = NextDevicePathNode (Node1); while (!IsDevicePathEnd (Node1)) { if ((DevicePathType (Node1) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node1) == MSG_UART_DP)) { Uart1 = (UART_DEVICE_PATH *) Node1; CopyMem ( &Uart1->BaudRate, &NewTerminalContext->BaudRate, sizeof (UINT64) ); CopyMem ( &Uart1->DataBits, &NewTerminalContext->DataBits, sizeof (UINT8) ); CopyMem ( &Uart1->Parity, &NewTerminalContext->Parity, sizeof (UINT8) ); CopyMem ( &Uart1->StopBits, &NewTerminalContext->StopBits, sizeof (UINT8) ); break; } // // end if // Node1 = NextDevicePathNode (Node1); } // // end while // break; } } Node = NextDevicePathNode (Node); } return EFI_SUCCESS; }
/** Update Com Ports attributes from DevicePath @param DevicePath DevicePath that contains Com ports @retval EFI_SUCCESS The update is successful. @retval EFI_NOT_FOUND Can not find specific menu entry **/ EFI_STATUS UpdateComAttributeFromVariable ( EFI_DEVICE_PATH_PROTOCOL *DevicePath ) { EFI_DEVICE_PATH_PROTOCOL *Node; EFI_DEVICE_PATH_PROTOCOL *SerialNode; ACPI_HID_DEVICE_PATH *Acpi; UART_DEVICE_PATH *Uart; UART_DEVICE_PATH *Uart1; UINTN TerminalNumber; BM_MENU_ENTRY *NewMenuEntry; BM_TERMINAL_CONTEXT *NewTerminalContext; UINTN Index; UART_FLOW_CONTROL_DEVICE_PATH *FlowControlNode; BOOLEAN HasFlowControlNode; HasFlowControlNode = FALSE; Node = DevicePath; Node = NextDevicePathNode (Node); TerminalNumber = 0; for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) { while (!IsDevicePathEnd (Node)) { Acpi = (ACPI_HID_DEVICE_PATH *) Node; if (IsIsaSerialNode (Acpi)) { CopyMem (&TerminalNumber, &Acpi->UID, sizeof (UINT32)); } if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) { Uart = (UART_DEVICE_PATH *) Node; NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, TerminalNumber); if (NULL == NewMenuEntry) { return EFI_NOT_FOUND; } NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext; CopyMem ( &NewTerminalContext->BaudRate, &Uart->BaudRate, sizeof (UINT64) ); CopyMem ( &NewTerminalContext->DataBits, &Uart->DataBits, sizeof (UINT8) ); CopyMem ( &NewTerminalContext->Parity, &Uart->Parity, sizeof (UINT8) ); CopyMem ( &NewTerminalContext->StopBits, &Uart->StopBits, sizeof (UINT8) ); FlowControlNode = (UART_FLOW_CONTROL_DEVICE_PATH *) NextDevicePathNode (Node); if (IsUartFlowControlNode (FlowControlNode)) { HasFlowControlNode = TRUE; NewTerminalContext->FlowControl = (UINT8) ReadUnaligned32 (&FlowControlNode->FlowControlMap); } else if (NewTerminalContext->FlowControl != 0) { // // No Flow Control device path node, assumption no Flow control // NewTerminalContext->FlowControl = 0; } SerialNode = NewTerminalContext->DevicePath; SerialNode = NextDevicePathNode (SerialNode); while (!IsDevicePathEnd (SerialNode)) { if ((DevicePathType (SerialNode) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (SerialNode) == MSG_UART_DP)) { // // Update following device paths according to // previous acquired uart attributes // Uart1 = (UART_DEVICE_PATH *) SerialNode; CopyMem ( &Uart1->BaudRate, &NewTerminalContext->BaudRate, sizeof (UINT64) ); CopyMem ( &Uart1->DataBits, &NewTerminalContext->DataBits, sizeof (UINT8) ); CopyMem ( &Uart1->Parity, &NewTerminalContext->Parity, sizeof (UINT8) ); CopyMem ( &Uart1->StopBits, &NewTerminalContext->StopBits, sizeof (UINT8) ); FlowControlNode = (UART_FLOW_CONTROL_DEVICE_PATH *) NextDevicePathNode (SerialNode); if (IsUartFlowControlNode (FlowControlNode)) { FlowControlNode->FlowControlMap = NewTerminalContext->FlowControl; } else { if (HasFlowControlNode) { mFlowControlDevicePath.FlowControlMap = NewTerminalContext->FlowControl; NewTerminalContext->DevicePath = AppendDevicePathNode ( NewTerminalContext->DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) (&mFlowControlDevicePath) ); } } break; } SerialNode = NextDevicePathNode (SerialNode); } // // end while // } Node = NextDevicePathNode (Node); } // // end while // } return EFI_SUCCESS; }
EFI_STATUS EFIAPI WinNtSerialIoDriverBindingStart ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Handle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath ) /*++ Routine Description: Arguments: Returns: None --*/ // TODO: This - add argument and description to function comment // TODO: Handle - add argument and description to function comment // TODO: RemainingDevicePath - add argument and description to function comment // TODO: EFI_SUCCESS - add return value to function comment // TODO: EFI_SUCCESS - add return value to function comment { EFI_STATUS Status; EFI_WIN_NT_IO_PROTOCOL *WinNtIo; WIN_NT_SERIAL_IO_PRIVATE_DATA *Private; HANDLE NtHandle; 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; // // Get the Parent Device Path // Status = gBS->OpenProtocol ( Handle, &gEfiDevicePathProtocolGuid, (VOID **) &ParentDevicePath, This->DriverBindingHandle, Handle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) { return Status; } // // Grab the IO abstraction we need to get any work done // Status = gBS->OpenProtocol ( Handle, &gEfiWinNtIoProtocolGuid, (VOID **) &WinNtIo, This->DriverBindingHandle, Handle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) { gBS->CloseProtocol ( Handle, &gEfiDevicePathProtocolGuid, This->DriverBindingHandle, Handle ); return Status; } if (Status == EFI_ALREADY_STARTED) { if (RemainingDevicePath == NULL || IsDevicePathEnd (RemainingDevicePath)) { // // If RemainingDevicePath is NULL or is the End of Device Path Node // return EFI_SUCCESS; } // // Make sure a child handle does not already exist. This driver can only // produce one child per serial port. // Status = gBS->OpenProtocolInformation ( Handle, &gEfiWinNtIoProtocolGuid, &OpenInfoBuffer, &EntryCount ); if (EFI_ERROR (Status)) { return Status; } Status = EFI_ALREADY_STARTED; for (Index = 0; Index < EntryCount; Index++) { if ((OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) { Status = gBS->OpenProtocol ( OpenInfoBuffer[Index].ControllerHandle, &gEfiSerialIoProtocolGuid, (VOID **) &SerialIo, This->DriverBindingHandle, Handle, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (!EFI_ERROR (Status)) { Uart = (UART_DEVICE_PATH *) RemainingDevicePath; Status = SerialIo->SetAttributes ( 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; } } FreePool (OpenInfoBuffer); 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. // NtHandle = WinNtIo->WinNtThunk->CreateFile ( WinNtIo->EnvString, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL ); if (NtHandle == INVALID_HANDLE_VALUE) { Status = EFI_DEVICE_ERROR; goto Error; } // // Construct Private data // Private = AllocatePool (sizeof (WIN_NT_SERIAL_IO_PRIVATE_DATA)); if (Private == NULL) { goto Error; } // // This signature must be valid before any member function is called // Private->Signature = WIN_NT_SERIAL_IO_PRIVATE_DATA_SIGNATURE; Private->NtHandle = NtHandle; Private->ControllerHandle = Handle; Private->Handle = NULL; Private->WinNtThunk = WinNtIo->WinNtThunk; Private->ParentDevicePath = ParentDevicePath; Private->ControllerNameTable = NULL; Private->SoftwareLoopbackEnable = FALSE; Private->HardwareLoopbackEnable = 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, &Private->ControllerNameTable, WinNtIo->EnvString, TRUE ); AddUnicodeString2 ( "en", gWinNtSerialIoComponentName2.SupportedLanguages, &Private->ControllerNameTable, WinNtIo->EnvString, FALSE ); Private->SerialIo.Revision = SERIAL_IO_INTERFACE_REVISION; Private->SerialIo.Reset = WinNtSerialIoReset; Private->SerialIo.SetAttributes = WinNtSerialIoSetAttributes; Private->SerialIo.SetControl = WinNtSerialIoSetControl; Private->SerialIo.GetControl = WinNtSerialIoGetControl; Private->SerialIo.Write = WinNtSerialIoWrite; Private->SerialIo.Read = WinNtSerialIoRead; Private->SerialIo.Mode = &Private->SerialIoMode; // // 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 current setings. // Private->DevicePath = AppendDevicePathNode ( 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; } // // Fill in Serial I/O Mode structure based on either the RemainingDevicePath or defaults. // Private->SerialIoMode.ControlMask = SERIAL_CONTROL_MASK; Private->SerialIoMode.Timeout = SERIAL_TIMEOUT_DEFAULT; Private->SerialIoMode.BaudRate = Private->UartDevicePath.BaudRate; Private->SerialIoMode.ReceiveFifoDepth = SERIAL_FIFO_DEFAULT; Private->SerialIoMode.DataBits = Private->UartDevicePath.DataBits; Private->SerialIoMode.Parity = Private->UartDevicePath.Parity; Private->SerialIoMode.StopBits = Private->UartDevicePath.StopBits; // // Issue a reset to initialize the COM port // Status = Private->SerialIo.Reset (&Private->SerialIo); if (EFI_ERROR (Status)) { goto Error; } // // Create new child handle // Status = gBS->InstallMultipleProtocolInterfaces ( &Private->Handle, &gEfiSerialIoProtocolGuid, &Private->SerialIo, &gEfiDevicePathProtocolGuid, Private->DevicePath, NULL ); if (EFI_ERROR (Status)) { goto Error; } // // Open For Child Device // Status = gBS->OpenProtocol ( Handle, &gEfiWinNtIoProtocolGuid, (VOID **) &WinNtIo, This->DriverBindingHandle, Private->Handle, EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER ); if (EFI_ERROR (Status)) { goto Error; } return EFI_SUCCESS; Error: // // Use the Stop() function to free all resources allocated in Start() // if (Private != NULL) { if (Private->Handle != NULL) { This->Stop (This, Handle, 1, &Private->Handle); } else { if (NtHandle != INVALID_HANDLE_VALUE) { Private->WinNtThunk->CloseHandle (NtHandle); } if (Private->DevicePath != NULL) { FreePool (Private->DevicePath); } FreeUnicodeStringTable (Private->ControllerNameTable); FreePool (Private); } } This->Stop (This, Handle, 0, NULL); return Status; }
EFI_STATUS EFIAPI WinNtSerialIoDriverBindingSupported ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Handle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath ) /*++ Routine Description: Arguments: Returns: None --*/ // TODO: This - add argument and description to function comment // TODO: Handle - add argument and description to function comment // TODO: RemainingDevicePath - add argument and description to function comment // 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_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, &gEfiWinNtIoProtocolGuid, (VOID **) &WinNtIo, This->DriverBindingHandle, Handle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (Status == EFI_ALREADY_STARTED) { 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, &gEfiWinNtIoProtocolGuid, This->DriverBindingHandle, Handle ); // // Open the EFI Device Path protocol needed to perform the supported test // Status = gBS->OpenProtocol ( Handle, &gEfiDevicePathProtocolGuid, (VOID **) &ParentDevicePath, This->DriverBindingHandle, Handle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (Status == EFI_ALREADY_STARTED) { return EFI_SUCCESS; } if (EFI_ERROR (Status)) { 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 // if (WinNtIo->WinNtThunk->Signature != EFI_WIN_NT_THUNK_PROTOCOL_SIGNATURE) { Status = EFI_UNSUPPORTED; goto Error; } // // Check the GUID to see if this is a handle type the driver supports // if (!CompareGuid (WinNtIo->TypeGuid, &gEfiWinNtSerialPortGuid)) { Status = EFI_UNSUPPORTED; goto Error; } return EFI_SUCCESS; Error: return Status; }
EFI_STATUS EFIAPI WinNtSerialIoSetControl ( IN EFI_SERIAL_IO_PROTOCOL *This, IN UINT32 Control ) /*++ Routine Description: TODO: Add function description Arguments: This - TODO: add argument description Control - TODO: add argument description Returns: EFI_DEVICE_ERROR - TODO: Add description for return value EFI_DEVICE_ERROR - TODO: Add description for return value EFI_SUCCESS - TODO: Add description for return value --*/ { WIN_NT_SERIAL_IO_PRIVATE_DATA *Private; BOOL Result; DCB Dcb; EFI_TPL Tpl; UART_FLOW_CONTROL_DEVICE_PATH *FlowControl; EFI_STATUS Status; // // first determine the parameter is invalid // if (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))) { return EFI_UNSUPPORTED; } Tpl = gBS->RaiseTPL (TPL_NOTIFY); Private = WIN_NT_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This); Result = Private->WinNtThunk->GetCommState (Private->NtHandle, &Dcb); if (!Result) { Private->NtError = Private->WinNtThunk->GetLastError (); DEBUG ((EFI_D_ERROR, "SerialSetControl: GetCommState %d\n", Private->NtError)); gBS->RestoreTPL (Tpl); return EFI_DEVICE_ERROR; } Dcb.fRtsControl = RTS_CONTROL_DISABLE; Dcb.fDtrControl = DTR_CONTROL_DISABLE; Private->HardwareFlowControl = FALSE; Private->SoftwareLoopbackEnable = FALSE; Private->HardwareLoopbackEnable = FALSE; if (Control & EFI_SERIAL_REQUEST_TO_SEND) { Dcb.fRtsControl = RTS_CONTROL_ENABLE; } if (Control & EFI_SERIAL_DATA_TERMINAL_READY) { Dcb.fDtrControl = DTR_CONTROL_ENABLE; } if (Control & EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE) { Private->HardwareFlowControl = TRUE; } if (Control & EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE) { Private->SoftwareLoopbackEnable = TRUE; } if (Control & EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE) { Private->HardwareLoopbackEnable = TRUE; } Result = Private->WinNtThunk->SetCommState ( Private->NtHandle, &Dcb ); if (!Result) { Private->NtError = Private->WinNtThunk->GetLastError (); DEBUG ((EFI_D_ERROR, "SerialSetControl: SetCommState %d\n", Private->NtError)); gBS->RestoreTPL (Tpl); 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 Status; }