20#define PCI_BRIDGE_32_BIT_IO_SPACE 0x01
27#define R_UART_BAUD_LOW 0
28#define R_UART_BAUD_HIGH 1
31#define B_UART_FCR_FIFOE BIT0
32#define B_UART_FCR_FIFO64 BIT5
34#define B_UART_LCR_DLAB BIT7
36#define B_UART_MCR_DTRC BIT0
37#define B_UART_MCR_RTS BIT1
39#define B_UART_LSR_RXRDY BIT0
40#define B_UART_LSR_TXRDY BIT5
41#define B_UART_LSR_TEMT BIT6
43#define B_UART_MSR_CTS BIT4
44#define B_UART_MSR_DSR BIT5
45#define B_UART_MSR_RI BIT6
46#define B_UART_MSR_DCD BIT7
68 if (
PcdGet8 (PcdSerialRegisterAccessWidth) == 32) {
100 if (
PcdGet8 (PcdSerialRegisterAccessWidth) == 32) {
101 return (UINT8)
MmioWrite32 (Base + Offset *
PcdGet32 (PcdSerialRegisterStride), (UINT8)Value);
106 return IoWrite8 (Base + Offset *
PcdGet32 (PcdSerialRegisterStride), Value);
125 RETURN_STATUS Status;
126 UINT64 SerialConsoleAddress;
128 Base = (VOID *)(
UINTN)
PcdGet64 (PcdDeviceTreeInitialBaseAddress);
134 return SerialConsoleAddress;
148 UINTN SerialRegisterBase
151 if (
PcdGetBool (PcdSerialUseHardwareFlowControl)) {
165 return (BOOLEAN)((
SerialPortReadRegister (SerialRegisterBase, R_UART_MSR) & (B_UART_MSR_DSR | B_UART_MSR_CTS)) == (B_UART_MSR_DSR | B_UART_MSR_CTS));
179 return (BOOLEAN)((
SerialPortReadRegister (SerialRegisterBase, R_UART_MSR) & (B_UART_MSR_DSR | B_UART_MSR_CTS)) != (B_UART_MSR_DSR));
202 UINTN SerialRegisterBase;
204 UINT32 CurrentDivisor;
211 Divisor =
PcdGet32 (PcdSerialClockRate) / (
PcdGet32 (PcdSerialBaudRate) * 16);
220 if (SerialRegisterBase == 0) {
236 if (CurrentDivisor != Divisor) {
248 while ((
SerialPortReadRegister (SerialRegisterBase, R_UART_LSR) & (B_UART_LSR_TEMT | B_UART_LSR_TXRDY)) != (B_UART_LSR_TEMT | B_UART_LSR_TXRDY)) {
310 UINTN SerialRegisterBase;
315 if (Buffer ==
NULL) {
320 if (SerialRegisterBase == 0) {
324 if (NumberOfBytes == 0) {
332 while ((
SerialPortReadRegister (SerialRegisterBase, R_UART_LSR) & (B_UART_LSR_TEMT | B_UART_LSR_TXRDY)) != (B_UART_LSR_TEMT | B_UART_LSR_TXRDY)) {
348 if ((
PcdGet8 (PcdSerialFifoControl) & B_UART_FCR_FIFOE) != 0) {
349 if ((
PcdGet8 (PcdSerialFifoControl) & B_UART_FCR_FIFO64) == 0) {
352 FifoSize =
PcdGet32 (PcdSerialExtendedTxFifoSize);
356 Result = NumberOfBytes;
357 while (NumberOfBytes != 0) {
362 while ((
SerialPortReadRegister (SerialRegisterBase, R_UART_LSR) & (B_UART_LSR_TEMT | B_UART_LSR_TXRDY)) != (B_UART_LSR_TEMT | B_UART_LSR_TXRDY)) {
368 for (Index = 0; Index < FifoSize && NumberOfBytes != 0; Index++, NumberOfBytes--, Buffer++) {
402 UINTN SerialRegisterBase;
406 if (
NULL == Buffer) {
411 if (SerialRegisterBase == 0) {
417 for (Result = 0; NumberOfBytes-- != 0; Result++, Buffer++) {
422 if (
PcdGetBool (PcdSerialUseHardwareFlowControl)) {
430 if (
PcdGetBool (PcdSerialUseHardwareFlowControl)) {
462 UINTN SerialRegisterBase;
465 if (SerialRegisterBase == 0) {
473 if (
PcdGetBool (PcdSerialUseHardwareFlowControl)) {
483 if (
PcdGetBool (PcdSerialUseHardwareFlowControl)) {
508 UINTN SerialRegisterBase;
514 if ((Control & (~(EFI_SERIAL_REQUEST_TO_SEND | EFI_SERIAL_DATA_TERMINAL_READY |
515 EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE))) != 0)
521 if (SerialRegisterBase == 0) {
529 Mcr &= (~(B_UART_MCR_DTRC | B_UART_MCR_RTS));
531 if ((Control & EFI_SERIAL_DATA_TERMINAL_READY) == EFI_SERIAL_DATA_TERMINAL_READY) {
532 Mcr |= B_UART_MCR_DTRC;
535 if ((Control & EFI_SERIAL_REQUEST_TO_SEND) == EFI_SERIAL_REQUEST_TO_SEND) {
536 Mcr |= B_UART_MCR_RTS;
562 UINTN SerialRegisterBase;
568 if (SerialRegisterBase == 0) {
579 if ((Msr & B_UART_MSR_CTS) == B_UART_MSR_CTS) {
580 *Control |= EFI_SERIAL_CLEAR_TO_SEND;
583 if ((Msr & B_UART_MSR_DSR) == B_UART_MSR_DSR) {
584 *Control |= EFI_SERIAL_DATA_SET_READY;
587 if ((Msr & B_UART_MSR_RI) == B_UART_MSR_RI) {
588 *Control |= EFI_SERIAL_RING_INDICATE;
591 if ((Msr & B_UART_MSR_DCD) == B_UART_MSR_DCD) {
592 *Control |= EFI_SERIAL_CARRIER_DETECT;
600 if ((Mcr & B_UART_MCR_DTRC) == B_UART_MCR_DTRC) {
601 *Control |= EFI_SERIAL_DATA_TERMINAL_READY;
604 if ((Mcr & B_UART_MCR_RTS) == B_UART_MCR_RTS) {
605 *Control |= EFI_SERIAL_REQUEST_TO_SEND;
608 if (
PcdGetBool (PcdSerialUseHardwareFlowControl)) {
609 *Control |= EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE;
617 if ((Lsr & (B_UART_LSR_TEMT | B_UART_LSR_TXRDY)) == (B_UART_LSR_TEMT | B_UART_LSR_TXRDY)) {
618 *Control |= EFI_SERIAL_OUTPUT_BUFFER_EMPTY;
621 if ((Lsr & B_UART_LSR_RXRDY) == 0) {
622 *Control |= EFI_SERIAL_INPUT_BUFFER_EMPTY;
663 IN OUT UINT64 *BaudRate,
664 IN OUT UINT32 *ReceiveFifoDepth,
665 IN OUT UINT32 *Timeout,
667 IN OUT UINT8 *DataBits,
671 UINTN SerialRegisterBase;
672 UINT32 SerialBaudRate;
680 if (SerialRegisterBase == 0) {
687 if (*BaudRate == 0) {
688 *BaudRate =
PcdGet32 (PcdSerialBaudRate);
691 SerialBaudRate = (UINT32)*BaudRate;
693 if (*DataBits == 0) {
694 LcrData = (UINT8)(
PcdGet8 (PcdSerialLineControl) & 0x3);
695 *DataBits = LcrData + 5;
697 if ((*DataBits < 5) || (*DataBits > 8)) {
704 LcrData = (UINT8)(*DataBits - (UINT8)5);
707 if (*Parity == DefaultParity) {
708 LcrParity = (UINT8)((
PcdGet8 (PcdSerialLineControl) >> 3) & 0x7);
715 *Parity = EvenParity;
723 *Parity = SpaceParity;
727 *Parity = MarkParity;
760 if (*StopBits == DefaultStopBits) {
761 LcrStop = (UINT8)((
PcdGet8 (PcdSerialLineControl) >> 2) & 0x1);
764 *StopBits = OneStopBit;
768 if (*DataBits == 5) {
769 *StopBits = OneFiveStopBits;
771 *StopBits = TwoStopBits;
785 case OneFiveStopBits:
799 Divisor =
PcdGet32 (PcdSerialClockRate) / (SerialBaudRate * 16);
800 if ((
PcdGet32 (PcdSerialClockRate) % (SerialBaudRate * 16)) >= SerialBaudRate * 8) {
815 Lcr = (UINT8)((LcrParity << 3) | (LcrStop << 2) | LcrData);
BOOLEAN EFIAPI SerialPortPoll(VOID)
STATIC UINT8 SerialPortWriteRegister(UINTN Base, UINTN Offset, UINT8 Value)
RETURN_STATUS EFIAPI SerialPortSetAttributes(IN OUT UINT64 *BaudRate, IN OUT UINT32 *ReceiveFifoDepth, IN OUT UINT32 *Timeout, IN OUT EFI_PARITY_TYPE *Parity, IN OUT UINT8 *DataBits, IN OUT EFI_STOP_BITS_TYPE *StopBits)
STATIC UINT8 SerialPortReadRegister(UINTN Base, UINTN Offset)
STATIC BOOLEAN SerialPortWritable(UINTN SerialRegisterBase)
UINTN EFIAPI SerialPortRead(OUT UINT8 *Buffer, IN UINTN NumberOfBytes)
RETURN_STATUS EFIAPI SerialPortInitialize(VOID)
RETURN_STATUS EFIAPI SerialPortSetControl(IN UINT32 Control)
STATIC UINTN GetSerialRegisterBase(VOID)
RETURN_STATUS EFIAPI SerialPortGetControl(OUT UINT32 *Control)
UINTN EFIAPI SerialPortWrite(IN UINT8 *Buffer, IN UINTN NumberOfBytes)
RETURN_STATUS EFIAPI FdtSerialGetConsolePort(IN CONST VOID *DeviceTree, OUT UINT64 *BaseAddress)
UINT8 EFIAPI IoWrite8(IN UINTN Port, IN UINT8 Value)
UINT8 EFIAPI MmioRead8(IN UINTN Address)
UINT8 EFIAPI MmioWrite8(IN UINTN Address, IN UINT8 Value)
UINT8 EFIAPI IoRead8(IN UINTN Port)
UINT32 EFIAPI MmioRead32(IN UINTN Address)
UINT32 EFIAPI MmioWrite32(IN UINTN Address, IN UINT32 Value)
#define RETURN_ERROR(StatusCode)
#define RETURN_DEVICE_ERROR
#define RETURN_UNSUPPORTED
#define RETURN_INVALID_PARAMETER
#define PcdGet64(TokenName)
#define PcdGet8(TokenName)
#define PcdGet32(TokenName)
#define PcdGetBool(TokenName)