X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FLibrary%2FBaseSerialPortLib16550%2FBaseSerialPortLib16550.c;h=2238749215d42c07c2fe6a65ec43dcf5ae8fd516;hb=acaa2726fbaa32a1adfa57caf8679eae316a8750;hp=dfccbc384753e472cb74070198f6acec98358576;hpb=467d15ae63fb9d36904f06f11cde6c4cd5c297a2;p=mirror_edk2.git diff --git a/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c b/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c index dfccbc3847..2238749215 100644 --- a/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c +++ b/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c @@ -1,7 +1,7 @@ /** @file 16550 UART Serial Port library functions - Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2011, 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 @@ -38,7 +38,7 @@ #define B_UART_LSR_TEMT BIT6 #define R_UART_MSR 6 #define B_UART_MSR_CTS BIT4 -#define B_UART_MSR_DCD BIT7 +#define B_UART_MSR_DSR BIT5 /** Read an 8-bit 16550 register. If PcdSerialUseMmio is TRUE, then the value is read from @@ -69,7 +69,8 @@ SerialPortReadRegister ( parameter Offset is added to the base address of the 16550 registers that is specified by PcdSerialRegisterBase. - @param Offset The offset of the 16550 register to read. + @param Offset The offset of the 16550 register to write. + @param Value The value to write to the 16550 register specified by Offset. @return The value written to the 16550 register. @@ -128,9 +129,10 @@ SerialPortInitialize ( if ((SerialPortReadRegister (R_UART_LCR) & 0x3F) != (PcdGet8 (PcdSerialLineControl) & 0x3F)) { Initialized = FALSE; } - SerialPortWriteRegister (R_UART_LCR, SerialPortReadRegister (R_UART_LCR) | B_UART_LCR_DLAB); - Divisor = (SerialPortReadRegister (R_UART_BAUD_HIGH) << 8) | SerialPortReadRegister (R_UART_BAUD_LOW); - SerialPortWriteRegister (R_UART_LCR, SerialPortReadRegister (R_UART_LCR) & ~B_UART_LCR_DLAB); + SerialPortWriteRegister (R_UART_LCR, (UINT8)(SerialPortReadRegister (R_UART_LCR) | B_UART_LCR_DLAB)); + Divisor = SerialPortReadRegister (R_UART_BAUD_HIGH) << 8; + Divisor |= SerialPortReadRegister (R_UART_BAUD_LOW); + SerialPortWriteRegister (R_UART_LCR, (UINT8)(SerialPortReadRegister (R_UART_LCR) & ~B_UART_LCR_DLAB)); if (Divisor != 115200 / PcdGet32 (PcdSerialBaudRate)) { Initialized = FALSE; } @@ -150,13 +152,13 @@ SerialPortInitialize ( // Clear DLAB and configure Data Bits, Parity, and Stop Bits. // Strip reserved bits from PcdSerialLineControl // - SerialPortWriteRegister (R_UART_LCR, PcdGet8 (PcdSerialLineControl) & 0x3F); + SerialPortWriteRegister (R_UART_LCR, (UINT8)(PcdGet8 (PcdSerialLineControl) & 0x3F)); // // Enable and reset FIFOs // Strip reserved bits from PcdSerialFifoControl // - SerialPortWriteRegister (R_UART_FCR, PcdGet8 (PcdSerialFifoControl) & 0x17); + SerialPortWriteRegister (R_UART_FCR, (UINT8)(PcdGet8 (PcdSerialFifoControl) & 0x27)); // // Put Modem Control Register(MCR) into its reset state of 0x00. @@ -192,9 +194,9 @@ SerialPortWrite ( IN UINTN NumberOfBytes ) { - UINTN Result; - UINTN Index; - UINTN FifoSize; + UINTN Result; + UINTN Index; + UINTN FifoSize; if (Buffer == NULL) { return 0; @@ -211,7 +213,7 @@ SerialPortWrite ( FifoSize = 64; } } - + Result = NumberOfBytes; while (NumberOfBytes != 0) { // @@ -225,10 +227,35 @@ SerialPortWrite ( // for (Index = 0; Index < FifoSize && NumberOfBytes != 0; Index++, NumberOfBytes--, Buffer++) { if (PcdGetBool (PcdSerialUseHardwareFlowControl)) { - // - // Wait for notification from peer to send data - // - while ((SerialPortReadRegister (R_UART_MSR) & (B_UART_MSR_CTS | B_UART_MSR_DCD)) == B_UART_MSR_DCD); + if (PcdGetBool (PcdSerialDetectCable)) { + // + // Wait for both DSR and CTS to be set + // DSR is set if a cable is connected. + // CTS is set if it is ok to transmit data + // + // DSR CTS Description Action + // === === ======================================== ======== + // 0 0 No cable connected. Wait + // 0 1 No cable connected. Wait + // 1 0 Cable connected, but not clear to send. Wait + // 1 1 Cable connected, and clear to send. Transmit + // + while ((SerialPortReadRegister (R_UART_MSR) & (B_UART_MSR_DSR | B_UART_MSR_CTS)) != (B_UART_MSR_DSR | B_UART_MSR_CTS)); + } else { + // + // Wait for both DSR and CTS to be set OR for DSR to be clear. + // DSR is set if a cable is connected. + // CTS is set if it is ok to transmit data + // + // DSR CTS Description Action + // === === ======================================== ======== + // 0 0 No cable connected. Transmit + // 0 1 No cable connected. Transmit + // 1 0 Cable connected, but not clear to send. Wait + // 1 1 Cable connected, and clar to send. Transmit + // + while ((SerialPortReadRegister (R_UART_MSR) & (B_UART_MSR_DSR | B_UART_MSR_CTS)) == (B_UART_MSR_DSR)); + } } // @@ -265,7 +292,7 @@ SerialPortRead ( return 0; } - Mcr = SerialPortReadRegister (R_UART_MCR) & ~B_UART_MCR_RTS; + Mcr = (UINT8)(SerialPortReadRegister (R_UART_MCR) & ~B_UART_MCR_RTS); for (Result = 0; NumberOfBytes-- != 0; Result++, Buffer++) { // @@ -276,7 +303,7 @@ SerialPortRead ( // // Set RTS to let the peer send some data // - SerialPortWriteRegister (R_UART_MCR, Mcr | B_UART_MCR_RTS); + SerialPortWriteRegister (R_UART_MCR, (UINT8)(Mcr | B_UART_MCR_RTS)); } } if (PcdGetBool (PcdSerialUseHardwareFlowControl)) { @@ -320,7 +347,7 @@ SerialPortPoll ( // // Clear RTS to prevent peer from sending data // - SerialPortWriteRegister (R_UART_MCR, SerialPortReadRegister (R_UART_MCR) & ~B_UART_MCR_RTS); + SerialPortWriteRegister (R_UART_MCR, (UINT8)(SerialPortReadRegister (R_UART_MCR) & ~B_UART_MCR_RTS)); } return TRUE; } @@ -329,7 +356,7 @@ SerialPortPoll ( // // Set RTS to let the peer send some data // - SerialPortWriteRegister (R_UART_MCR, SerialPortReadRegister (R_UART_MCR) | B_UART_MCR_RTS); + SerialPortWriteRegister (R_UART_MCR, (UINT8)(SerialPortReadRegister (R_UART_MCR) | B_UART_MCR_RTS)); } return FALSE;