Cleanup SerailIO drivers to have a device path and use PCD settings for various stuff...
[mirror_edk2.git] / EmbeddedPkg / SimpleTextInOutSerial / SimpleTextInOut.c
index f491de6..bdc67fb 100644 (file)
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/SerialPortLib.h>\r
+#include <Library/PcdLib.h>\r
 \r
 #include <Protocol/SerialIo.h>\r
 #include <Protocol/SimpleTextIn.h>\r
 #include <Protocol/SimpleTextOut.h>\r
+#include <Protocol/DevicePath.h>\r
 \r
 \r
 #define MODE0_COLUMN_COUNT        80\r
@@ -198,7 +200,30 @@ EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL mSimpleTextOut = {
   &mSimpleTextOutMode\r
 };\r
 \r
- EFI_HANDLE           mInstallHandle = NULL;\r
+EFI_HANDLE           mInstallHandle = NULL;\r
+\r
+typedef struct {\r
+  VENDOR_DEVICE_PATH        Guid;\r
+  UART_DEVICE_PATH          Uart;\r
+  EFI_DEVICE_PATH_PROTOCOL  End;\r
+} SIMPLE_TEXT_OUT_DEVICE_PATH;\r
+\r
+SIMPLE_TEXT_OUT_DEVICE_PATH mDevicePath = {\r
+  {\r
+    { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, sizeof (VENDOR_DEVICE_PATH), 0},\r
+    EFI_CALLER_ID_GUID\r
+  },\r
+  {\r
+    { END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, sizeof (UART_DEVICE_PATH), 0},\r
+    0,        // Reserved\r
+    FixedPcdGet64 (PcdUartDefaultBaudRate),   // BaudRate\r
+    FixedPcdGet8 (PcdUartDefaultDataBits),    // DataBits\r
+    FixedPcdGet8 (PcdUartDefaultParity),      // Parity (N)\r
+    FixedPcdGet8 (PcdUartDefaultStopBits)     // StopBits\r
+  },\r
+  { END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, sizeof (EFI_DEVICE_PATH_PROTOCOL), 0}\r
+};\r
+\r
 \r
 \r
 \r
@@ -271,6 +296,10 @@ ReadKeyStroke (
 {\r
   CHAR8             Char;\r
   \r
+  if (!SerialPortPoll ()) {\r
+    return EFI_NOT_READY;\r
+  }\r
+  \r
   SerialPortRead ((UINT8 *)&Char, 1);\r
   \r
   //\r
@@ -660,7 +689,8 @@ SimpleTextInOutEntryPoint (
                   &mInstallHandle,\r
                   &gEfiSimpleTextInProtocolGuid,   &mSimpleTextIn,\r
                   &gEfiSimpleTextOutProtocolGuid,  &mSimpleTextOut,\r
-                  NULL \r
+                  &gEfiDevicePathProtocolGuid,     &mDevicePath,\r
+                  NULL\r
                   );\r
   if (!EFI_ERROR (Status)) {\r
     gST->ConOut = &mSimpleTextOut;\r