]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/SerialDxe/SerialIo.c
Adding support for BeagleBoard.
[mirror_edk2.git] / EmbeddedPkg / SerialDxe / SerialIo.c
diff --git a/EmbeddedPkg/SerialDxe/SerialIo.c b/EmbeddedPkg/SerialDxe/SerialIo.c
new file mode 100644 (file)
index 0000000..aa9653b
--- /dev/null
@@ -0,0 +1,258 @@
+/** @file\r
+  Serial IO Abstraction for GDB stub. This allows an EFI consoles that shows up on the system \r
+  running GDB. One consle for error information and another console for user input/output.\r
+  \r
+  Basic packet format is $packet-data#checksum. So every comand has 4 bytes of overhead: $, \r
+  #, 0, 0. The 0 and 0 are the ascii characters for the checksum. \r
+  \r
+\r
+  Copyright (c) 2008-2009, Apple Inc. All rights reserved.\r
+  \r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <PiDxe.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/SerialPortLib.h>\r
+\r
+#include <Protocol/SerialIo.h>\r
+\r
+/**\r
+  Reset the serial device.\r
+\r
+  @param  This              Protocol instance pointer.\r
+                            \r
+  @retval EFI_SUCCESS       The device was reset.\r
+  @retval EFI_DEVICE_ERROR  The serial device could not be reset.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SerialReset (\r
+  IN EFI_SERIAL_IO_PROTOCOL  *This\r
+  )\r
+{\r
+  SerialPortInitialize ();\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Sets the baud rate, receive FIFO depth, transmit/receice time out, parity, \r
+  data buts, and stop bits on a serial device.\r
+\r
+  @param  This             Protocol instance pointer.\r
+  @param  BaudRate         The requested baud rate. A BaudRate value of 0 will use the the\r
+                           device's default interface speed.\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 dfault FIFO depth.\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
+  @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
+  @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
+  @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
+\r
+  @retval EFI_SUCCESS      The device was reset.\r
+  @retval EFI_DEVICE_ERROR The serial device could not be reset.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SerialSetAttributes (\r
+  IN EFI_SERIAL_IO_PROTOCOL  *This,\r
+  IN UINT64                  BaudRate,\r
+  IN UINT32                  ReceiveFifoDepth,\r
+  IN UINT32                  Timeout,\r
+  IN EFI_PARITY_TYPE         Parity,\r
+  IN UINT8                   DataBits,\r
+  IN EFI_STOP_BITS_TYPE      StopBits\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+  Set the control bits on a serial device\r
+\r
+  @param  This             Protocol instance pointer.\r
+  @param  Control          Set the bits of Control that are settable.\r
+\r
+  @retval EFI_SUCCESS      The new control bits were set on the serial device.\r
+  @retval EFI_UNSUPPORTED  The serial device does not support this operation.\r
+  @retval EFI_DEVICE_ERROR The serial device is not functioning correctly.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SerialSetControl (\r
+  IN EFI_SERIAL_IO_PROTOCOL  *This,\r
+  IN UINT32                  Control\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+  Retrieves the status of thecontrol bits on a serial device\r
+\r
+  @param  This              Protocol instance pointer.\r
+  @param  Control           A pointer to return the current Control signals from the serial device.\r
+                            \r
+  @retval EFI_SUCCESS       The control bits were read from the serial device.\r
+  @retval EFI_DEVICE_ERROR  The serial device is not functioning correctly.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SerialGetControl (\r
+  IN EFI_SERIAL_IO_PROTOCOL  *This,\r
+  OUT UINT32                 *Control\r
+  )\r
+{\r
+  if (SerialPortPoll ()) {\r
+    // If a character is pending don't set EFI_SERIAL_INPUT_BUFFER_EMPTY\r
+    *Control = EFI_SERIAL_OUTPUT_BUFFER_EMPTY;\r
+  } else {\r
+    *Control = EFI_SERIAL_INPUT_BUFFER_EMPTY | EFI_SERIAL_OUTPUT_BUFFER_EMPTY;\r
+  }\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Writes data to a serial device.\r
+\r
+  @param  This              Protocol instance pointer.\r
+  @param  BufferSize        On input, the size of the Buffer. On output, the amount of\r
+                            data actually written.\r
+  @param  Buffer            The buffer of data to write\r
+\r
+  @retval EFI_SUCCESS       The data was written.\r
+  @retval EFI_DEVICE_ERROR  The device reported an error.\r
+  @retval EFI_TIMEOUT       The data write was stopped due to a timeout.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SerialWrite (\r
+  IN EFI_SERIAL_IO_PROTOCOL  *This,\r
+  IN OUT UINTN               *BufferSize,\r
+  IN VOID                    *Buffer\r
+  )\r
+{\r
+  UINTN Count;\r
+  \r
+  Count = SerialPortWrite (Buffer, *BufferSize);\r
+  *BufferSize = Count;\r
+  return (Count == 0) ? EFI_DEVICE_ERROR : EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Writes data to a serial device.\r
+\r
+  @param  This              Protocol instance pointer.\r
+  @param  BufferSize        On input, the size of the Buffer. On output, the amount of\r
+                            data returned in Buffer.\r
+  @param  Buffer            The buffer to return the data into.\r
+\r
+  @retval EFI_SUCCESS       The data was read.\r
+  @retval EFI_DEVICE_ERROR  The device reported an error.\r
+  @retval EFI_TIMEOUT       The data write was stopped due to a timeout.\r
+\r
+**/\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SerialRead (\r
+  IN EFI_SERIAL_IO_PROTOCOL  *This,\r
+  IN OUT UINTN               *BufferSize,\r
+  OUT VOID                   *Buffer\r
+  )\r
+{\r
+  UINTN Count;\r
+  \r
+  Count = SerialPortWrite (Buffer, *BufferSize);\r
+  *BufferSize = Count;\r
+  return (Count == 0) ? EFI_DEVICE_ERROR : EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_HANDLE  gHandle = NULL;\r
+\r
+// \r
+// Template used to initailize the GDB Serial IO protocols\r
+//\r
+EFI_SERIAL_IO_MODE gSerialIoMode = {\r
+  0,      // ControlMask\r
+  0,      // Timeout\r
+  0,      // BaudRate\r
+  1,      // RceiveFifoDepth\r
+  0,      // DataBits\r
+  0,      // Parity\r
+  0       // StopBits\r
+};\r
+\r
+\r
+EFI_SERIAL_IO_PROTOCOL gSerialIoTemplate = {\r
+  SERIAL_IO_INTERFACE_REVISION,\r
+  SerialReset,\r
+  SerialSetAttributes,\r
+  SerialSetControl,\r
+  SerialGetControl,\r
+  SerialWrite,\r
+  SerialRead,\r
+  &gSerialIoMode\r
+};\r
+  \r
+\r
+/**\r
+  Initialize the state information for the Serial Io Protocol\r
+\r
+  @param  ImageHandle   of the loaded driver\r
+  @param  SystemTable   Pointer to the System Table\r
+\r
+  @retval EFI_SUCCESS           Protocol registered\r
+  @retval EFI_OUT_OF_RESOURCES  Cannot allocate protocol data structure\r
+  @retval EFI_DEVICE_ERROR      Hardware problems\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SerialDxeInitialize (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS      Status;\r
+\r
+\r
+  // Make a new handle with Serial IO protocol and its device path on it.\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &gHandle, \r
+                  &gEfiSerialIoProtocolGuid,   &gSerialIoTemplate,\r
+                  &gEfiDevicePathProtocolGuid, NULL, // BugBug: Need a device path\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+  return Status;\r
+}\r
+\r