X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=IntelFrameworkModulePkg%2FBus%2FIsa%2FIsaSerialDxe%2FSerial.c;h=57ee669d140682e922f5b0d632eef765e4e411a7;hp=c62e60b6f5c3806c83e9f76870678410b29cf5e9;hb=684fec3c964dd125160d47992413b3c95170f885;hpb=180a5a35cb49699bd249dee19e41cee34c856a58 diff --git a/IntelFrameworkModulePkg/Bus/Isa/IsaSerialDxe/Serial.c b/IntelFrameworkModulePkg/Bus/Isa/IsaSerialDxe/Serial.c index c62e60b6f5..57ee669d14 100644 --- a/IntelFrameworkModulePkg/Bus/Isa/IsaSerialDxe/Serial.c +++ b/IntelFrameworkModulePkg/Bus/Isa/IsaSerialDxe/Serial.c @@ -1,7 +1,7 @@ /** @file Serial driver for standard UARTS on an ISA bus. -Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2015, 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 @@ -43,11 +43,11 @@ SERIAL_DEV gSerialDevTempate = { { // SerialMode SERIAL_PORT_SUPPORT_CONTROL_MASK, SERIAL_PORT_DEFAULT_TIMEOUT, - FixedPcdGet64 (PcdUartDefaultBaudRate), // BaudRate + 0, SERIAL_PORT_DEFAULT_RECEIVE_FIFO_DEPTH, - FixedPcdGet8 (PcdUartDefaultDataBits), // DataBits - FixedPcdGet8 (PcdUartDefaultParity), // Parity - FixedPcdGet8 (PcdUartDefaultStopBits) // StopBits + 0, + 0, + 0 }, NULL, NULL, @@ -61,10 +61,10 @@ SERIAL_DEV gSerialDevTempate = { } }, 0, - FixedPcdGet64 (PcdUartDefaultBaudRate), - FixedPcdGet8 (PcdUartDefaultDataBits), - FixedPcdGet8 (PcdUartDefaultParity), - FixedPcdGet8 (PcdUartDefaultStopBits) + 0, + 0, + 0, + 0 }, NULL, 0, //BaseAddress @@ -163,6 +163,17 @@ InitializeIsaSerial ( ); ASSERT_EFI_ERROR (Status); + // + // Initialize UART default setting in gSerialDevTempate + // + gSerialDevTempate.SerialMode.BaudRate = PcdGet64 (PcdUartDefaultBaudRate); + gSerialDevTempate.SerialMode.DataBits = PcdGet8 (PcdUartDefaultDataBits); + gSerialDevTempate.SerialMode.Parity = PcdGet8 (PcdUartDefaultParity); + gSerialDevTempate.SerialMode.StopBits = PcdGet8 (PcdUartDefaultStopBits); + gSerialDevTempate.UartDevicePath.BaudRate = PcdGet64 (PcdUartDefaultBaudRate); + gSerialDevTempate.UartDevicePath.DataBits = PcdGet8 (PcdUartDefaultDataBits); + gSerialDevTempate.UartDevicePath.Parity = PcdGet8 (PcdUartDefaultParity); + gSerialDevTempate.UartDevicePath.StopBits = PcdGet8 (PcdUartDefaultStopBits); return Status; } @@ -1382,7 +1393,7 @@ IsaSerialSetAttributes ( // Compute divisor use to program the baud rate using a round determination // Divisor = (UINT32) DivU64x32Remainder ( - SERIAL_PORT_INPUT_CLOCK, + PcdGet32 (PcdSerialClockRate), ((UINT32) BaudRate * 16), &Remained ); @@ -1399,7 +1410,7 @@ IsaSerialSetAttributes ( // // Compute the actual baud rate that the serial port will be programmed for. // - BaudRate = SERIAL_PORT_INPUT_CLOCK / Divisor / 16; + BaudRate = PcdGet32 (PcdSerialClockRate) / Divisor / 16; // // Put serial port on Divisor Latch Mode @@ -1744,6 +1755,8 @@ IsaSerialWrite ( UINTN Elapsed; UINTN ActualWrite; EFI_TPL Tpl; + UINTN Timeout; + UINTN BitsPerCharacter; SerialDevice = SERIAL_DEV_FROM_THIS (This); Elapsed = 0; @@ -1767,6 +1780,36 @@ IsaSerialWrite ( CharBuffer = (UINT8 *) Buffer; + // + // Compute the number of bits in a single character. This is a start bit, + // followed by the number of data bits, followed by the number of stop bits. + // The number of stop bits is specified by an enumeration that includes + // support for 1.5 stop bits. Treat 1.5 stop bits as 2 stop bits. + // + BitsPerCharacter = + 1 + + This->Mode->DataBits + + ((This->Mode->StopBits == TwoStopBits) ? 2 : This->Mode->StopBits); + + // + // Compute the timeout in microseconds to wait for a single byte to be + // transmitted. The Mode structure contans a Timeout field that is the + // maximum time to transmit or receive a character. However, many UARTs + // have a FIFO for transmits, so the time required to add one new character + // to the transmit FIFO may be the time required to flush a full FIFO. If + // the Timeout in the Mode structure is smaller than the time required to + // flush a full FIFO at the current baud rate, then use a timeout value that + // is required to flush a full transmit FIFO. + // + Timeout = MAX ( + This->Mode->Timeout, + (UINTN)DivU64x64Remainder ( + BitsPerCharacter * (SERIAL_PORT_MAX_RECEIVE_FIFO_DEPTH + 1) * 1000000, + This->Mode->BaudRate, + NULL + ) + ); + for (Index = 0; Index < *BufferSize; Index++) { IsaSerialFifoAdd (&SerialDevice->Transmit, CharBuffer[Index]); @@ -1775,7 +1818,7 @@ IsaSerialWrite ( // Unsuccessful write so check if timeout has expired, if not, // stall for a bit, increment time elapsed, and try again // - if (Elapsed >= This->Mode->Timeout) { + if (Elapsed >= Timeout) { *BufferSize = ActualWrite; gBS->RestoreTPL (Tpl); return EFI_TIMEOUT;