2 16550 UART Serial Port library functions
4 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <IndustryStandard/Pci.h>
17 #include <Library/SerialPortLib.h>
18 #include <Library/PcdLib.h>
19 #include <Library/IoLib.h>
20 #include <Library/PciLib.h>
21 #include <Library/PlatformHookLib.h>
22 #include <Library/BaseLib.h>
27 #define PCI_BRIDGE_32_BIT_IO_SPACE 0x01
30 // 16550 UART register offsets and bitfields
32 #define R_UART_RXBUF 0
33 #define R_UART_TXBUF 0
34 #define R_UART_BAUD_LOW 0
35 #define R_UART_BAUD_HIGH 1
37 #define B_UART_FCR_FIFOE BIT0
38 #define B_UART_FCR_FIFO64 BIT5
40 #define B_UART_LCR_DLAB BIT7
42 #define B_UART_MCR_RTS BIT1
44 #define B_UART_LSR_RXRDY BIT0
45 #define B_UART_LSR_TXRDY BIT5
46 #define B_UART_LSR_TEMT BIT6
48 #define B_UART_MSR_CTS BIT4
49 #define B_UART_MSR_DSR BIT5
52 // 4-byte structure for each PCI node in PcdSerialPciDeviceInfo
57 UINT16 PowerManagementStatusAndControlRegister
;
58 } PCI_UART_DEVICE_INFO
;
61 Read an 8-bit 16550 register. If PcdSerialUseMmio is TRUE, then the value is read from
62 MMIO space. If PcdSerialUseMmio is FALSE, then the value is read from I/O space. The
63 parameter Offset is added to the base address of the 16550 registers that is specified
64 by PcdSerialRegisterBase.
66 @param Offset The offset of the 16550 register to read.
68 @return The value read from the 16550 register.
72 SerialPortReadRegister (
77 if (PcdGetBool (PcdSerialUseMmio
)) {
78 return MmioRead8 (Base
+ Offset
);
80 return IoRead8 (Base
+ Offset
);
85 Write an 8-bit 16550 register. If PcdSerialUseMmio is TRUE, then the value is written to
86 MMIO space. If PcdSerialUseMmio is FALSE, then the value is written to I/O space. The
87 parameter Offset is added to the base address of the 16550 registers that is specified
88 by PcdSerialRegisterBase.
90 @param Offset The offset of the 16550 register to write.
91 @param Value The value to write to the 16550 register specified by Offset.
93 @return The value written to the 16550 register.
97 SerialPortWriteRegister (
103 if (PcdGetBool (PcdSerialUseMmio
)) {
104 return MmioWrite8 (Base
+ Offset
, Value
);
106 return IoWrite8 (Base
+ Offset
, Value
);
111 Update the value of an 16-bit PCI configuration register in a PCI device. If the
112 PCI Configuration register specified by PciAddress is already programmed with a
113 non-zero value, then return the current value. Otherwise update the PCI configuration
114 register specified by PciAddress with the value specified by Value and return the
115 value programmed into the PCI configuration register. All values must be masked
116 using the bitmask specified by Mask.
118 @param PciAddress PCI Library address of the PCI Configuration register to update.
119 @param Value The value to program into the PCI Configuration Register.
120 @param Mask Bitmask of the bits to check and update in the PCI configuration register.
124 SerialPortLibUpdatePciRegister16 (
132 CurrentValue
= PciRead16 (PciAddress
) & Mask
;
133 if (CurrentValue
!= 0) {
136 return PciWrite16 (PciAddress
, Value
& Mask
);
140 Update the value of an 32-bit PCI configuration register in a PCI device. If the
141 PCI Configuration register specified by PciAddress is already programmed with a
142 non-zero value, then return the current value. Otherwise update the PCI configuration
143 register specified by PciAddress with the value specified by Value and return the
144 value programmed into the PCI configuration register. All values must be masked
145 using the bitmask specified by Mask.
147 @param PciAddress PCI Library address of the PCI Configuration register to update.
148 @param Value The value to program into the PCI Configuration Register.
149 @param Mask Bitmask of the bits to check and update in the PCI configuration register.
151 @return The Secondary bus number that is actually programed into the PCI to PCI Bridge device.
155 SerialPortLibUpdatePciRegister32 (
163 CurrentValue
= PciRead32 (PciAddress
) & Mask
;
164 if (CurrentValue
!= 0) {
167 return PciWrite32 (PciAddress
, Value
& Mask
);
171 Retrieve the I/O or MMIO base address register for the PCI UART device.
173 This function assumes Root Bus Numer is Zero, and enables I/O and MMIO in PCI UART
174 Device if they are not already enabled.
176 @return The base address register of the PCI UART device.
180 GetSerialRegisterBase (
185 UINTN PrimaryBusNumber
;
187 UINTN SubordinateBusNumber
;
189 UINT32 ParentIoLimit
;
190 UINT16 ParentMemoryBase
;
191 UINT16 ParentMemoryLimit
;
196 UINTN SerialRegisterBase
;
198 UINT32 RegisterBaseMask
;
199 PCI_UART_DEVICE_INFO
*DeviceInfo
;
202 // Get PCI Device Info
204 DeviceInfo
= (PCI_UART_DEVICE_INFO
*) PcdGetPtr (PcdSerialPciDeviceInfo
);
207 // If PCI Device Info is empty, then assume fixed address UART and return PcdSerialRegisterBase
209 if (DeviceInfo
->Device
== 0xff) {
210 return (UINTN
)PcdGet64 (PcdSerialRegisterBase
);
214 // Assume PCI Bus 0 I/O window is 0-64KB and MMIO windows is 0-4GB
216 ParentMemoryBase
= 0 >> 16;
217 ParentMemoryLimit
= 0xfff00000 >> 16;
218 ParentIoBase
= 0 >> 12;
219 ParentIoLimit
= 0xf000 >> 12;
222 // Enable I/O and MMIO in PCI Bridge
223 // Assume Root Bus Numer is Zero.
225 for (BusNumber
= 0; (DeviceInfo
+ 1)->Device
!= 0xff; DeviceInfo
++) {
227 // Compute PCI Lib Address to PCI to PCI Bridge
229 PciLibAddress
= PCI_LIB_ADDRESS (BusNumber
, DeviceInfo
->Device
, DeviceInfo
->Function
, 0);
232 // Retrieve and verify the bus numbers in the PCI to PCI Bridge
234 PrimaryBusNumber
= PciRead8 (PciLibAddress
+ PCI_BRIDGE_PRIMARY_BUS_REGISTER_OFFSET
);
235 BusNumber
= PciRead8 (PciLibAddress
+ PCI_BRIDGE_SECONDARY_BUS_REGISTER_OFFSET
);
236 SubordinateBusNumber
= PciRead8 (PciLibAddress
+ PCI_BRIDGE_SUBORDINATE_BUS_REGISTER_OFFSET
);
237 if (BusNumber
== 0 || BusNumber
> SubordinateBusNumber
) {
242 // Retrieve and verify the I/O or MMIO decode window in the PCI to PCI Bridge
244 if (PcdGetBool (PcdSerialUseMmio
)) {
245 MemoryLimit
= PciRead16 (PciLibAddress
+ OFFSET_OF (PCI_BRIDGE_CONTROL_REGISTER
, MemoryLimit
)) & 0xfff0;
246 MemoryBase
= PciRead16 (PciLibAddress
+ OFFSET_OF (PCI_BRIDGE_CONTROL_REGISTER
, MemoryBase
)) & 0xfff0;
249 // If PCI Bridge MMIO window is disabled, then return 0
251 if (MemoryLimit
< MemoryBase
) {
256 // If PCI Bridge MMIO window is not in the address range decoded by the parent PCI Bridge, then return 0
258 if (MemoryBase
< ParentMemoryBase
|| MemoryBase
> ParentMemoryLimit
|| MemoryLimit
> ParentMemoryLimit
) {
261 ParentMemoryBase
= MemoryBase
;
262 ParentMemoryLimit
= MemoryLimit
;
264 IoLimit
= PciRead8 (PciLibAddress
+ OFFSET_OF (PCI_BRIDGE_CONTROL_REGISTER
, IoLimit
));
265 if ((IoLimit
& PCI_BRIDGE_32_BIT_IO_SPACE
) == 0) {
266 IoLimit
= IoLimit
>> 4;
268 IoLimit
= (PciRead16 (PciLibAddress
+ OFFSET_OF (PCI_BRIDGE_CONTROL_REGISTER
, IoLimitUpper16
)) << 4) | (IoLimit
>> 4);
270 IoBase
= PciRead8 (PciLibAddress
+ OFFSET_OF (PCI_BRIDGE_CONTROL_REGISTER
, IoBase
));
271 if ((IoBase
& PCI_BRIDGE_32_BIT_IO_SPACE
) == 0) {
272 IoBase
= IoBase
>> 4;
274 IoBase
= (PciRead16 (PciLibAddress
+ OFFSET_OF (PCI_BRIDGE_CONTROL_REGISTER
, IoBaseUpper16
)) << 4) | (IoBase
>> 4);
278 // If PCI Bridge I/O window is disabled, then return 0
280 if (IoLimit
< IoBase
) {
285 // If PCI Bridge I/O window is not in the address range decoded by the parent PCI Bridge, then return 0
287 if (IoBase
< ParentIoBase
|| IoBase
> ParentIoLimit
|| IoLimit
> ParentIoLimit
) {
290 ParentIoBase
= IoBase
;
291 ParentIoLimit
= IoLimit
;
296 // Compute PCI Lib Address to PCI UART
298 PciLibAddress
= PCI_LIB_ADDRESS (BusNumber
, DeviceInfo
->Device
, DeviceInfo
->Function
, 0);
301 // Find the first IO or MMIO BAR
303 RegisterBaseMask
= 0xFFFFFFF0;
304 for (BarIndex
= 0; BarIndex
< PCI_MAX_BAR
; BarIndex
++) {
305 SerialRegisterBase
= PciRead32 (PciLibAddress
+ PCI_BASE_ADDRESSREG_OFFSET
+ BarIndex
* 4);
306 if (PcdGetBool (PcdSerialUseMmio
) && ((SerialRegisterBase
& BIT0
) == 0)) {
310 RegisterBaseMask
= 0xFFFFFFF0;
314 if ((!PcdGetBool (PcdSerialUseMmio
)) && ((SerialRegisterBase
& BIT0
) != 0)) {
318 RegisterBaseMask
= 0xFFFFFFF8;
324 // MMIO or IO BAR is not found.
326 if (BarIndex
== PCI_MAX_BAR
) {
333 SerialRegisterBase
= SerialPortLibUpdatePciRegister32 (
334 PciLibAddress
+ PCI_BASE_ADDRESSREG_OFFSET
+ BarIndex
* 4,
335 (UINT32
)PcdGet64 (PcdSerialRegisterBase
),
340 // Verify that the UART BAR is in the address range decoded by the parent PCI Bridge
342 if (PcdGetBool (PcdSerialUseMmio
)) {
343 if (((SerialRegisterBase
>> 16) & 0xfff0) < ParentMemoryBase
|| ((SerialRegisterBase
>> 16) & 0xfff0) > ParentMemoryLimit
) {
347 if ((SerialRegisterBase
>> 12) < ParentIoBase
|| (SerialRegisterBase
>> 12) > ParentIoLimit
) {
353 // Enable I/O and MMIO in PCI UART Device if they are not already enabled
356 PciLibAddress
+ PCI_COMMAND_OFFSET
,
357 PcdGetBool (PcdSerialUseMmio
) ? EFI_PCI_COMMAND_MEMORY_SPACE
: EFI_PCI_COMMAND_IO_SPACE
361 // Force D0 state if a Power Management and Status Register is specified
363 if (DeviceInfo
->PowerManagementStatusAndControlRegister
!= 0x00) {
364 if ((PciRead16 (PciLibAddress
+ DeviceInfo
->PowerManagementStatusAndControlRegister
) & (BIT0
| BIT1
)) != 0x00) {
365 PciAnd16 (PciLibAddress
+ DeviceInfo
->PowerManagementStatusAndControlRegister
, (UINT16
)~(BIT0
| BIT1
));
367 // If PCI UART was not in D0, then make sure FIFOs are enabled, but do not reset FIFOs
369 SerialPortWriteRegister (SerialRegisterBase
, R_UART_FCR
, (UINT8
)(PcdGet8 (PcdSerialFifoControl
) & (B_UART_FCR_FIFOE
| B_UART_FCR_FIFO64
)));
374 // Get PCI Device Info
376 DeviceInfo
= (PCI_UART_DEVICE_INFO
*) PcdGetPtr (PcdSerialPciDeviceInfo
);
379 // Enable I/O or MMIO in PCI Bridge
380 // Assume Root Bus Numer is Zero.
382 for (BusNumber
= 0; (DeviceInfo
+ 1)->Device
!= 0xff; DeviceInfo
++) {
384 // Compute PCI Lib Address to PCI to PCI Bridge
386 PciLibAddress
= PCI_LIB_ADDRESS (BusNumber
, DeviceInfo
->Device
, DeviceInfo
->Function
, 0);
389 // Enable the I/O or MMIO decode windows in the PCI to PCI Bridge
392 PciLibAddress
+ PCI_COMMAND_OFFSET
,
393 PcdGetBool (PcdSerialUseMmio
) ? EFI_PCI_COMMAND_MEMORY_SPACE
: EFI_PCI_COMMAND_IO_SPACE
397 // Force D0 state if a Power Management and Status Register is specified
399 if (DeviceInfo
->PowerManagementStatusAndControlRegister
!= 0x00) {
400 if ((PciRead16 (PciLibAddress
+ DeviceInfo
->PowerManagementStatusAndControlRegister
) & (BIT0
| BIT1
)) != 0x00) {
401 PciAnd16 (PciLibAddress
+ DeviceInfo
->PowerManagementStatusAndControlRegister
, (UINT16
)~(BIT0
| BIT1
));
405 BusNumber
= PciRead8 (PciLibAddress
+ PCI_BRIDGE_SECONDARY_BUS_REGISTER_OFFSET
);
408 return SerialRegisterBase
;
412 Return whether the hardware flow control signal allows writing.
414 @retval TRUE The serial port is writable.
415 @retval FALSE The serial port is not writable.
419 UINTN SerialRegisterBase
422 if (PcdGetBool (PcdSerialUseHardwareFlowControl
)) {
423 if (PcdGetBool (PcdSerialDetectCable
)) {
425 // Wait for both DSR and CTS to be set
426 // DSR is set if a cable is connected.
427 // CTS is set if it is ok to transmit data
429 // DSR CTS Description Action
430 // === === ======================================== ========
431 // 0 0 No cable connected. Wait
432 // 0 1 No cable connected. Wait
433 // 1 0 Cable connected, but not clear to send. Wait
434 // 1 1 Cable connected, and clear to send. Transmit
436 return (BOOLEAN
) ((SerialPortReadRegister (SerialRegisterBase
, R_UART_MSR
) & (B_UART_MSR_DSR
| B_UART_MSR_CTS
)) == (B_UART_MSR_DSR
| B_UART_MSR_CTS
));
439 // Wait for both DSR and CTS to be set OR for DSR to be clear.
440 // DSR is set if a cable is connected.
441 // CTS is set if it is ok to transmit data
443 // DSR CTS Description Action
444 // === === ======================================== ========
445 // 0 0 No cable connected. Transmit
446 // 0 1 No cable connected. Transmit
447 // 1 0 Cable connected, but not clear to send. Wait
448 // 1 1 Cable connected, and clar to send. Transmit
450 return (BOOLEAN
) ((SerialPortReadRegister (SerialRegisterBase
, R_UART_MSR
) & (B_UART_MSR_DSR
| B_UART_MSR_CTS
)) != (B_UART_MSR_DSR
));
458 Initialize the serial device hardware.
460 If no initialization is required, then return RETURN_SUCCESS.
461 If the serial device was successfully initialized, then return RETURN_SUCCESS.
462 If the serial device could not be initialized, then return RETURN_DEVICE_ERROR.
464 @retval RETURN_SUCCESS The serial device was initialized.
465 @retval RETURN_DEVICE_ERROR The serial device could not be initialized.
470 SerialPortInitialize (
474 RETURN_STATUS Status
;
475 UINTN SerialRegisterBase
;
477 UINT32 CurrentDivisor
;
481 // Perform platform specific initialization required to enable use of the 16550 device
482 // at the location specified by PcdSerialUseMmio and PcdSerialRegisterBase.
484 Status
= PlatformHookSerialPortInitialize ();
485 if (RETURN_ERROR (Status
)) {
490 // Calculate divisor for baud generator
491 // Ref_Clk_Rate / Baud_Rate / 16
493 Divisor
= PcdGet32 (PcdSerialClockRate
) / (PcdGet32 (PcdSerialBaudRate
) * 16);
494 if ((PcdGet32 (PcdSerialClockRate
) % (PcdGet32 (PcdSerialBaudRate
) * 16)) >= PcdGet32 (PcdSerialBaudRate
) * 8) {
499 // Get the base address of the serial port in either I/O or MMIO space
501 SerialRegisterBase
= GetSerialRegisterBase ();
502 if (SerialRegisterBase
==0) {
503 return RETURN_DEVICE_ERROR
;
507 // See if the serial port is already initialized
510 if ((SerialPortReadRegister (SerialRegisterBase
, R_UART_LCR
) & 0x3F) != (PcdGet8 (PcdSerialLineControl
) & 0x3F)) {
513 SerialPortWriteRegister (SerialRegisterBase
, R_UART_LCR
, (UINT8
)(SerialPortReadRegister (SerialRegisterBase
, R_UART_LCR
) | B_UART_LCR_DLAB
));
514 CurrentDivisor
= SerialPortReadRegister (SerialRegisterBase
, R_UART_BAUD_HIGH
) << 8;
515 CurrentDivisor
|= (UINT32
) SerialPortReadRegister (SerialRegisterBase
, R_UART_BAUD_LOW
);
516 SerialPortWriteRegister (SerialRegisterBase
, R_UART_LCR
, (UINT8
)(SerialPortReadRegister (SerialRegisterBase
, R_UART_LCR
) & ~B_UART_LCR_DLAB
));
517 if (CurrentDivisor
!= Divisor
) {
521 return RETURN_SUCCESS
;
525 // Wait for the serial port to be ready.
526 // Verify that both the transmit FIFO and the shift register are empty.
528 while ((SerialPortReadRegister (SerialRegisterBase
, R_UART_LSR
) & (B_UART_LSR_TEMT
| B_UART_LSR_TXRDY
)) != (B_UART_LSR_TEMT
| B_UART_LSR_TXRDY
));
531 // Configure baud rate
533 SerialPortWriteRegister (SerialRegisterBase
, R_UART_LCR
, B_UART_LCR_DLAB
);
534 SerialPortWriteRegister (SerialRegisterBase
, R_UART_BAUD_HIGH
, (UINT8
) (Divisor
>> 8));
535 SerialPortWriteRegister (SerialRegisterBase
, R_UART_BAUD_LOW
, (UINT8
) (Divisor
& 0xff));
538 // Clear DLAB and configure Data Bits, Parity, and Stop Bits.
539 // Strip reserved bits from PcdSerialLineControl
541 SerialPortWriteRegister (SerialRegisterBase
, R_UART_LCR
, (UINT8
)(PcdGet8 (PcdSerialLineControl
) & 0x3F));
544 // Enable and reset FIFOs
545 // Strip reserved bits from PcdSerialFifoControl
547 SerialPortWriteRegister (SerialRegisterBase
, R_UART_FCR
, 0x00);
548 SerialPortWriteRegister (SerialRegisterBase
, R_UART_FCR
, (UINT8
)(PcdGet8 (PcdSerialFifoControl
) & (B_UART_FCR_FIFOE
| B_UART_FCR_FIFO64
)));
551 // Put Modem Control Register(MCR) into its reset state of 0x00.
553 SerialPortWriteRegister (SerialRegisterBase
, R_UART_MCR
, 0x00);
555 return RETURN_SUCCESS
;
559 Write data from buffer to serial device.
561 Writes NumberOfBytes data bytes from Buffer to the serial device.
562 The number of bytes actually written to the serial device is returned.
563 If the return value is less than NumberOfBytes, then the write operation failed.
565 If Buffer is NULL, then ASSERT().
567 If NumberOfBytes is zero, then return 0.
569 @param Buffer Pointer to the data buffer to be written.
570 @param NumberOfBytes Number of bytes to written to the serial device.
572 @retval 0 NumberOfBytes is 0.
573 @retval >0 The number of bytes written to the serial device.
574 If this value is less than NumberOfBytes, then the read operation failed.
581 IN UINTN NumberOfBytes
584 UINTN SerialRegisterBase
;
589 if (Buffer
== NULL
) {
593 SerialRegisterBase
= GetSerialRegisterBase ();
594 if (SerialRegisterBase
==0) {
598 if (NumberOfBytes
== 0) {
600 // Flush the hardware
604 // Wait for both the transmit FIFO and shift register empty.
606 while ((SerialPortReadRegister (SerialRegisterBase
, R_UART_LSR
) & (B_UART_LSR_TEMT
| B_UART_LSR_TXRDY
)) != (B_UART_LSR_TEMT
| B_UART_LSR_TXRDY
));
609 // Wait for the hardware flow control signal
611 while (!SerialPortWritable (SerialRegisterBase
));
616 // Compute the maximum size of the Tx FIFO
619 if ((PcdGet8 (PcdSerialFifoControl
) & B_UART_FCR_FIFOE
) != 0) {
620 if ((PcdGet8 (PcdSerialFifoControl
) & B_UART_FCR_FIFO64
) == 0) {
623 FifoSize
= PcdGet32 (PcdSerialExtendedTxFifoSize
);
627 Result
= NumberOfBytes
;
628 while (NumberOfBytes
!= 0) {
630 // Wait for the serial port to be ready, to make sure both the transmit FIFO
631 // and shift register empty.
633 while ((SerialPortReadRegister (SerialRegisterBase
, R_UART_LSR
) & B_UART_LSR_TEMT
) == 0);
636 // Fill then entire Tx FIFO
638 for (Index
= 0; Index
< FifoSize
&& NumberOfBytes
!= 0; Index
++, NumberOfBytes
--, Buffer
++) {
640 // Wait for the hardware flow control signal
642 while (!SerialPortWritable (SerialRegisterBase
));
645 // Write byte to the transmit buffer.
647 SerialPortWriteRegister (SerialRegisterBase
, R_UART_TXBUF
, *Buffer
);
654 Reads data from a serial device into a buffer.
656 @param Buffer Pointer to the data buffer to store the data read from the serial device.
657 @param NumberOfBytes Number of bytes to read from the serial device.
659 @retval 0 NumberOfBytes is 0.
660 @retval >0 The number of bytes read from the serial device.
661 If this value is less than NumberOfBytes, then the read operation failed.
668 IN UINTN NumberOfBytes
671 UINTN SerialRegisterBase
;
675 if (NULL
== Buffer
) {
679 SerialRegisterBase
= GetSerialRegisterBase ();
680 if (SerialRegisterBase
==0) {
684 Mcr
= (UINT8
)(SerialPortReadRegister (SerialRegisterBase
, R_UART_MCR
) & ~B_UART_MCR_RTS
);
686 for (Result
= 0; NumberOfBytes
-- != 0; Result
++, Buffer
++) {
688 // Wait for the serial port to have some data.
690 while ((SerialPortReadRegister (SerialRegisterBase
, R_UART_LSR
) & B_UART_LSR_RXRDY
) == 0) {
691 if (PcdGetBool (PcdSerialUseHardwareFlowControl
)) {
693 // Set RTS to let the peer send some data
695 SerialPortWriteRegister (SerialRegisterBase
, R_UART_MCR
, (UINT8
)(Mcr
| B_UART_MCR_RTS
));
698 if (PcdGetBool (PcdSerialUseHardwareFlowControl
)) {
700 // Clear RTS to prevent peer from sending data
702 SerialPortWriteRegister (SerialRegisterBase
, R_UART_MCR
, Mcr
);
706 // Read byte from the receive buffer.
708 *Buffer
= SerialPortReadRegister (SerialRegisterBase
, R_UART_RXBUF
);
716 Polls a serial device to see if there is any data waiting to be read.
718 Polls aserial device to see if there is any data waiting to be read.
719 If there is data waiting to be read from the serial device, then TRUE is returned.
720 If there is no data waiting to be read from the serial device, then FALSE is returned.
722 @retval TRUE Data is waiting to be read from the serial device.
723 @retval FALSE There is no data waiting to be read from the serial device.
732 UINTN SerialRegisterBase
;
734 SerialRegisterBase
= GetSerialRegisterBase ();
735 if (SerialRegisterBase
==0) {
740 // Read the serial port status
742 if ((SerialPortReadRegister (SerialRegisterBase
, R_UART_LSR
) & B_UART_LSR_RXRDY
) != 0) {
743 if (PcdGetBool (PcdSerialUseHardwareFlowControl
)) {
745 // Clear RTS to prevent peer from sending data
747 SerialPortWriteRegister (SerialRegisterBase
, R_UART_MCR
, (UINT8
)(SerialPortReadRegister (SerialRegisterBase
, R_UART_MCR
) & ~B_UART_MCR_RTS
));
752 if (PcdGetBool (PcdSerialUseHardwareFlowControl
)) {
754 // Set RTS to let the peer send some data
756 SerialPortWriteRegister (SerialRegisterBase
, R_UART_MCR
, (UINT8
)(SerialPortReadRegister (SerialRegisterBase
, R_UART_MCR
) | B_UART_MCR_RTS
));