#define LSR_TXRDY 0x20\r
#define LSR_RXDA 0x01\r
#define DLAB 0x01\r
+#define MCR_DTRC 0x01\r
+#define MCR_RTS 0x02\r
+#define MSR_CTS 0x10\r
+#define MSR_DSR 0x20\r
+#define MSR_RI 0x40\r
+#define MSR_DCD 0x80\r
\r
//---------------------------------------------\r
// UART Settings\r
return (BOOLEAN) ((Data & LSR_RXDA) != 0);\r
}\r
\r
+/**\r
+ Sets the control bits on a serial device.\r
+\r
+ @param Control Sets the bits of Control that are settable.\r
+\r
+ @retval RETURN_SUCCESS The new control bits were set on the serial device.\r
+ @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r
+ @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+SerialPortSetControl (\r
+ IN UINT32 Control\r
+ )\r
+{\r
+ UINT8 Mcr;\r
+\r
+ //\r
+ // First determine the parameter is invalid.\r
+ //\r
+ if ((Control & (~(EFI_SERIAL_REQUEST_TO_SEND | EFI_SERIAL_DATA_TERMINAL_READY))) != 0) {\r
+ return RETURN_UNSUPPORTED;\r
+ }\r
+\r
+ //\r
+ // Read the Modem Control Register.\r
+ //\r
+ Mcr = IoRead8 ((UINT16) gUartBase + MCR_OFFSET);\r
+ Mcr &= (~(MCR_DTRC | MCR_RTS));\r
+\r
+ if ((Control & EFI_SERIAL_DATA_TERMINAL_READY) == EFI_SERIAL_DATA_TERMINAL_READY) {\r
+ Mcr |= MCR_DTRC;\r
+ }\r
+\r
+ if ((Control & EFI_SERIAL_REQUEST_TO_SEND) == EFI_SERIAL_REQUEST_TO_SEND) {\r
+ Mcr |= MCR_RTS;\r
+ }\r
+\r
+ //\r
+ // Write the Modem Control Register.\r
+ //\r
+ IoWrite8 ((UINT16) gUartBase + MCR_OFFSET, Mcr);\r
+\r
+ return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+ Retrieve the status of the control bits on a serial device.\r
+\r
+ @param Control A pointer to return the current control signals from the serial device.\r
+\r
+ @retval RETURN_SUCCESS The control bits were read from the serial device.\r
+ @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r
+ @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+SerialPortGetControl (\r
+ OUT UINT32 *Control\r
+ )\r
+{\r
+ UINT8 Msr;\r
+ UINT8 Mcr;\r
+ UINT8 Lsr;\r
+\r
+ *Control = 0;\r
+\r
+ //\r
+ // Read the Modem Status Register.\r
+ //\r
+ Msr = IoRead8 ((UINT16) gUartBase + MSR_OFFSET);\r
+\r
+ if ((Msr & MSR_CTS) == MSR_CTS) {\r
+ *Control |= EFI_SERIAL_CLEAR_TO_SEND;\r
+ }\r
+\r
+ if ((Msr & MSR_DSR) == MSR_DSR) {\r
+ *Control |= EFI_SERIAL_DATA_SET_READY;\r
+ }\r
+\r
+ if ((Msr & MSR_RI) == MSR_RI) {\r
+ *Control |= EFI_SERIAL_RING_INDICATE;\r
+ }\r
+\r
+ if ((Msr & MSR_DCD) == MSR_DCD) {\r
+ *Control |= EFI_SERIAL_CARRIER_DETECT;\r
+ }\r
+\r
+ //\r
+ // Read the Modem Control Register.\r
+ //\r
+ Mcr = IoRead8 ((UINT16) gUartBase + MCR_OFFSET);\r
+\r
+ if ((Mcr & MCR_DTRC) == MCR_DTRC) {\r
+ *Control |= EFI_SERIAL_DATA_TERMINAL_READY;\r
+ }\r
+\r
+ if ((Mcr & MCR_RTS) == MCR_RTS) {\r
+ *Control |= EFI_SERIAL_REQUEST_TO_SEND;\r
+ }\r
+\r
+ //\r
+ // Read the Line Status Register.\r
+ //\r
+ Lsr = IoRead8 ((UINT16) gUartBase + LSR_OFFSET);\r
+\r
+ if ((Lsr & LSR_TXRDY) == LSR_TXRDY) {\r
+ *Control |= EFI_SERIAL_OUTPUT_BUFFER_EMPTY;\r
+ }\r
+\r
+ if ((Lsr & LSR_RXDA) == 0) {\r
+ *Control |= EFI_SERIAL_INPUT_BUFFER_EMPTY;\r
+ }\r
+\r
+ return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+ Sets the baud rate, receive FIFO depth, transmit/receice time out, parity,\r
+ data bits, and stop bits on a serial device.\r
+\r
+ @param BaudRate The requested baud rate. A BaudRate value of 0 will use the\r
+ device's default interface speed.\r
+ On output, the value actually set.\r
+ @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the\r
+ serial interface. A ReceiveFifoDepth value of 0 will use\r
+ the device's default FIFO depth.\r
+ On output, the value actually set.\r
+ @param Timeout The requested time out for a single character in microseconds.\r
+ This timeout applies to both the transmit and receive side of the\r
+ interface. A Timeout value of 0 will use the device's default time\r
+ out value.\r
+ On output, the value actually set.\r
+ @param Parity The type of parity to use on this serial device. A Parity value of\r
+ DefaultParity will use the device's default parity value.\r
+ On output, the value actually set.\r
+ @param DataBits The number of data bits to use on the serial device. A DataBits\r
+ vaule of 0 will use the device's default data bit setting.\r
+ On output, the value actually set.\r
+ @param StopBits The number of stop bits to use on this serial device. A StopBits\r
+ value of DefaultStopBits will use the device's default number of\r
+ stop bits.\r
+ On output, the value actually set.\r
+\r
+ @retval RETURN_SUCCESS The new attributes were set on the serial device.\r
+ @retval RETURN_UNSUPPORTED The serial device does not support this operation.\r
+ @retval RETURN_INVALID_PARAMETER One or more of the attributes has an unsupported value.\r
+ @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+SerialPortSetAttributes (\r
+ IN OUT UINT64 *BaudRate,\r
+ IN OUT UINT32 *ReceiveFifoDepth,\r
+ IN OUT UINT32 *Timeout,\r
+ IN OUT EFI_PARITY_TYPE *Parity,\r
+ IN OUT UINT8 *DataBits,\r
+ IN OUT EFI_STOP_BITS_TYPE *StopBits\r
+ )\r
+{\r
+ UINTN Divisor;\r
+ UINT8 OutputData;\r
+ UINT8 LcrData;\r
+ UINT8 LcrParity;\r
+ UINT8 LcrStop;\r
+\r
+ //\r
+ // Check for default settings and fill in actual values.\r
+ //\r
+ if (*BaudRate == 0) {\r
+ *BaudRate = gBps;\r
+ }\r
+\r
+ if (*DataBits == 0) {\r
+ *DataBits = gData;\r
+ }\r
+\r
+ if (*Parity == DefaultParity) {\r
+ *Parity = NoParity;\r
+ }\r
+\r
+ if (*StopBits == DefaultStopBits) {\r
+ *StopBits = OneStopBit;\r
+ }\r
+\r
+ if ((*DataBits < 5) || (*DataBits > 8)) {\r
+ return RETURN_INVALID_PARAMETER;\r
+ }\r
+\r
+ if ((*Parity < NoParity) || (*Parity > SpaceParity)) {\r
+ return RETURN_INVALID_PARAMETER;\r
+ }\r
+\r
+ if ((*StopBits < OneStopBit) || (*StopBits > TwoStopBits)) {\r
+ return RETURN_INVALID_PARAMETER;\r
+ }\r
+\r
+ //\r
+ // Map 5..8 to 0..3\r
+ //\r
+ LcrData = (UINT8) (*DataBits - (UINT8) 5);\r
+\r
+ switch (*Parity) {\r
+ case NoParity:\r
+ LcrParity = 0;\r
+ break;\r
+\r
+ case EvenParity:\r
+ LcrParity = 3;\r
+ break;\r
+\r
+ case OddParity:\r
+ LcrParity = 1;\r
+ break;\r
+\r
+ case SpaceParity:\r
+ LcrParity = 7;\r
+ break;\r
+\r
+ case MarkParity:\r
+ LcrParity = 5;\r
+ break;\r
+\r
+ default:\r
+ break;\r
+ }\r
+\r
+ switch (*StopBits) {\r
+ case OneStopBit:\r
+ LcrStop = 0;\r
+ break;\r
+\r
+ case OneFiveStopBits:\r
+ case TwoStopBits:\r
+ LcrStop = 1;\r
+ break;\r
+\r
+ default:\r
+ break;\r
+ }\r
+\r
+ //\r
+ // Calculate divisor for baud generator\r
+ //\r
+ Divisor = 115200 / (UINTN) *BaudRate;\r
+\r
+ //\r
+ // Set communications format\r
+ //\r
+ OutputData = (UINT8) ((DLAB << 7) | (gBreakSet << 6) | (LcrParity << 3) | (LcrStop << 2) | LcrData);\r
+ IoWrite8 ((UINTN) (gUartBase + LCR_OFFSET), OutputData);\r
+\r
+ //\r
+ // Configure baud rate\r
+ //\r
+ IoWrite8 ((UINTN) (gUartBase + BAUD_HIGH_OFFSET), (UINT8) (Divisor >> 8));\r
+ IoWrite8 ((UINTN) (gUartBase + BAUD_LOW_OFFSET), (UINT8) (Divisor & 0xff));\r
+\r
+ //\r
+ // Switch back to bank 0\r
+ //\r
+ OutputData = (UINT8) ((~DLAB << 7) | (gBreakSet << 6) | (LcrParity << 3) | (LcrStop << 2) | LcrData);\r
+ IoWrite8 ((UINTN) (gUartBase + LCR_OFFSET), OutputData);\r
+\r
+ return RETURN_SUCCESS;\r
+}\r
+\r