/** Sets the baud rate, receive FIFO depth, transmit/receive time out, parity, data bits, and stop bits on a serial device. @param This Protocol instance pointer. @param BaudRate The requested baud rate. A BaudRate value of 0 will use the the device's default interface speed. @param ReceiveFifoDepth The requested depth of the FIFO on the receive side of the serial interface. A ReceiveFifoDepth value of 0 will use the device's default FIFO depth. @param Timeout The requested time out for a single character in microseconds. This timeout applies to both the transmit and receive side of the interface. A Timeout value of 0 will use the device's default time out value. @param Parity The type of parity to use on this serial device. A Parity value of DefaultParity will use the device's default parity value. @param DataBits The number of data bits to use on the serial device. A DataBits value of 0 will use the device's default data bit setting. @param StopBits The number of stop bits to use on this serial device. A StopBits value of DefaultStopBits will use the device's default number of stop bits. @retval EFI_SUCCESS The device was reset. @retval EFI_INVALID_PARAMETER One or more attributes has an unsupported value. @retval EFI_DEVICE_ERROR The serial device is not functioning correctly. **/ EFI_STATUS EFIAPI SerialSetAttributes ( IN EFI_SERIAL_IO_PROTOCOL *This, IN UINT64 BaudRate, IN UINT32 ReceiveFifoDepth, IN UINT32 Timeout, IN EFI_PARITY_TYPE Parity, IN UINT8 DataBits, IN EFI_STOP_BITS_TYPE StopBits ) { EFI_STATUS Status; EFI_TPL Tpl; UINT64 OriginalBaudRate; UINT32 OriginalReceiveFifoDepth; UINT32 OriginalTimeout; EFI_PARITY_TYPE OriginalParity; UINT8 OriginalDataBits; EFI_STOP_BITS_TYPE OriginalStopBits; // // Preserve the original input values in case // SerialPortSetAttributes() updates the input/output // parameters even on error. // OriginalBaudRate = BaudRate; OriginalReceiveFifoDepth = ReceiveFifoDepth; OriginalTimeout = Timeout; OriginalParity = Parity; OriginalDataBits = DataBits; OriginalStopBits = StopBits; Status = SerialPortSetAttributes (&BaudRate, &ReceiveFifoDepth, &Timeout, &Parity, &DataBits, &StopBits); if (EFI_ERROR (Status)) { // // If it is just to set Timeout value and unsupported is returned, // do not return error. // if ((Status == EFI_UNSUPPORTED) && (This->Mode->Timeout != OriginalTimeout) && (This->Mode->ReceiveFifoDepth == OriginalReceiveFifoDepth) && (This->Mode->BaudRate == OriginalBaudRate) && (This->Mode->DataBits == (UINT32) OriginalDataBits) && (This->Mode->Parity == (UINT32) OriginalParity) && (This->Mode->StopBits == (UINT32) OriginalStopBits)) { // // Restore to the original input values. // BaudRate = OriginalBaudRate; ReceiveFifoDepth = OriginalReceiveFifoDepth; Timeout = OriginalTimeout; Parity = OriginalParity; DataBits = OriginalDataBits; StopBits = OriginalStopBits; Status = EFI_SUCCESS; } else if (Status == EFI_INVALID_PARAMETER || Status == EFI_UNSUPPORTED) { return EFI_INVALID_PARAMETER; } else { return EFI_DEVICE_ERROR; } } // // Set the Serial I/O mode and update the device path // Tpl = gBS->RaiseTPL (TPL_NOTIFY); // // Set the Serial I/O mode // This->Mode->ReceiveFifoDepth = ReceiveFifoDepth; This->Mode->Timeout = Timeout; This->Mode->BaudRate = BaudRate; This->Mode->DataBits = (UINT32) DataBits; This->Mode->Parity = (UINT32) Parity; This->Mode->StopBits = (UINT32) StopBits; // // Check if the device path has actually changed // if (mSerialDevicePath.Uart.BaudRate == BaudRate && mSerialDevicePath.Uart.DataBits == DataBits && mSerialDevicePath.Uart.Parity == (UINT8) Parity && mSerialDevicePath.Uart.StopBits == (UINT8) StopBits ) { gBS->RestoreTPL (Tpl); return EFI_SUCCESS; } // // Update the device path // mSerialDevicePath.Uart.BaudRate = BaudRate; mSerialDevicePath.Uart.DataBits = DataBits; mSerialDevicePath.Uart.Parity = (UINT8) Parity; mSerialDevicePath.Uart.StopBits = (UINT8) StopBits; Status = gBS->ReinstallProtocolInterface ( mSerialHandle, &gEfiDevicePathProtocolGuid, &mSerialDevicePath, &mSerialDevicePath ); gBS->RestoreTPL (Tpl); return Status; }
/** Sets the baud rate, receive FIFO depth, transmit/receive time out, parity, data buts, and stop bits on a serial device. @param This Protocol instance pointer. @param BaudRate The requested baud rate. A BaudRate value of 0 will use the the device's default interface speed. @param ReceiveFifoDepth The requested depth of the FIFO on the receive side of the serial interface. A ReceiveFifoDepth value of 0 will use the device's default FIFO depth. @param Timeout The requested time out for a single character in microseconds. This timeout applies to both the transmit and receive side of the interface. A Timeout value of 0 will use the device's default time out value. @param Parity The type of parity to use on this serial device. A Parity value of DefaultParity will use the device's default parity value. @param DataBits The number of data bits to use on the serial device. A DataBits value of 0 will use the device's default data bit setting. @param StopBits The number of stop bits to use on this serial device. A StopBits value of DefaultStopBits will use the device's default number of stop bits. @retval EFI_SUCCESS The device was reset. @retval EFI_DEVICE_ERROR The serial device could not be reset. **/ EFI_STATUS EFIAPI SerialSetAttributes ( IN EFI_SERIAL_IO_PROTOCOL *This, IN UINT64 BaudRate, IN UINT32 ReceiveFifoDepth, IN UINT32 Timeout, IN EFI_PARITY_TYPE Parity, IN UINT8 DataBits, IN EFI_STOP_BITS_TYPE StopBits ) { EFI_STATUS Status; EFI_TPL Tpl; Status = SerialPortSetAttributes (&BaudRate, &ReceiveFifoDepth, &Timeout, &Parity, &DataBits, &StopBits); if (EFI_ERROR(Status)) { return Status; } // // Set the Serial I/O mode and update the device path // Tpl = gBS->RaiseTPL (TPL_NOTIFY); // // Set the Serial I/O mode // This->Mode->BaudRate = BaudRate; This->Mode->ReceiveFifoDepth = ReceiveFifoDepth; This->Mode->Timeout = Timeout; This->Mode->Parity = (UINT32)Parity; This->Mode->DataBits = (UINT32)DataBits; This->Mode->StopBits = (UINT32)StopBits; // // Check if the device path has actually changed // if (mDevicePath.Uart.BaudRate == BaudRate && mDevicePath.Uart.Parity == (UINT8)Parity && mDevicePath.Uart.DataBits == DataBits && mDevicePath.Uart.StopBits == (UINT8)StopBits ) { gBS->RestoreTPL (Tpl); return EFI_SUCCESS; } // // Update the device path // mDevicePath.Uart.BaudRate = BaudRate; mDevicePath.Uart.DataBits = DataBits; mDevicePath.Uart.Parity = (UINT8) Parity; mDevicePath.Uart.StopBits = (UINT8) StopBits; Status = gBS->ReinstallProtocolInterface ( gHandle, &gEfiDevicePathProtocolGuid, &mDevicePath, &mDevicePath ); gBS->RestoreTPL (Tpl); return Status; }