DxeEmuSerialPortLib.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /** @file
  2. Serial Port Lib that thunks back to Emulator services to write to StdErr.
  3. All read functions are stubed out.
  4. Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
  5. Portions copyright (c) 2011, Apple Inc. All rights reserved.<BR>
  6. SPDX-License-Identifier: BSD-2-Clause-Patent
  7. **/
  8. #include <PiDxe.h>
  9. #include <Library/SerialPortLib.h>
  10. #include <Library/EmuThunkLib.h>
  11. /**
  12. Initialize the serial device hardware.
  13. If no initialization is required, then return RETURN_SUCCESS.
  14. If the serial device was successfully initialized, then return RETURN_SUCCESS.
  15. If the serial device could not be initialized, then return RETURN_DEVICE_ERROR.
  16. @retval RETURN_SUCCESS The serial device was initialized.
  17. @retval RETURN_DEVICE_ERROR The serial device could not be initialized.
  18. **/
  19. RETURN_STATUS
  20. EFIAPI
  21. SerialPortInitialize (
  22. VOID
  23. )
  24. {
  25. return gEmuThunk->ConfigStdIn ();
  26. }
  27. /**
  28. Write data from buffer to serial device.
  29. Writes NumberOfBytes data bytes from Buffer to the serial device.
  30. The number of bytes actually written to the serial device is returned.
  31. If the return value is less than NumberOfBytes, then the write operation failed.
  32. If Buffer is NULL, then ASSERT().
  33. If NumberOfBytes is zero, then return 0.
  34. @param Buffer The pointer to the data buffer to be written.
  35. @param NumberOfBytes The number of bytes to written to the serial device.
  36. @retval 0 NumberOfBytes is 0.
  37. @retval >0 The number of bytes written to the serial device.
  38. If this value is less than NumberOfBytes, then the read operation failed.
  39. **/
  40. UINTN
  41. EFIAPI
  42. SerialPortWrite (
  43. IN UINT8 *Buffer,
  44. IN UINTN NumberOfBytes
  45. )
  46. {
  47. return gEmuThunk->WriteStdOut (Buffer, NumberOfBytes);
  48. }
  49. /**
  50. Read data from serial device and save the datas in buffer.
  51. Reads NumberOfBytes data bytes from a serial device into the buffer
  52. specified by Buffer. The number of bytes actually read is returned.
  53. If the return value is less than NumberOfBytes, then the rest operation failed.
  54. If Buffer is NULL, then ASSERT().
  55. If NumberOfBytes is zero, then return 0.
  56. @param Buffer The pointer to the data buffer to store the data read from the serial device.
  57. @param NumberOfBytes The number of bytes which will be read.
  58. @retval 0 Read data failed; No data is to be read.
  59. @retval >0 The actual number of bytes read from serial device.
  60. **/
  61. UINTN
  62. EFIAPI
  63. SerialPortRead (
  64. OUT UINT8 *Buffer,
  65. IN UINTN NumberOfBytes
  66. )
  67. {
  68. return gEmuThunk->ReadStdIn (Buffer, NumberOfBytes);
  69. }
  70. /**
  71. Polls a serial device to see if there is any data waiting to be read.
  72. Polls a serial device to see if there is any data waiting to be read.
  73. If there is data waiting to be read from the serial device, then TRUE is returned.
  74. If there is no data waiting to be read from the serial device, then FALSE is returned.
  75. @retval TRUE Data is waiting to be read from the serial device.
  76. @retval FALSE There is no data waiting to be read from the serial device.
  77. **/
  78. BOOLEAN
  79. EFIAPI
  80. SerialPortPoll (
  81. VOID
  82. )
  83. {
  84. return gEmuThunk->PollStdIn ();
  85. }
  86. /**
  87. Sets the control bits on a serial device.
  88. @param Control Sets the bits of Control that are settable.
  89. @retval RETURN_SUCCESS The new control bits were set on the serial device.
  90. @retval RETURN_UNSUPPORTED The serial device does not support this operation.
  91. @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
  92. **/
  93. RETURN_STATUS
  94. EFIAPI
  95. SerialPortSetControl (
  96. IN UINT32 Control
  97. )
  98. {
  99. return RETURN_UNSUPPORTED;
  100. }
  101. /**
  102. Retrieve the status of the control bits on a serial device.
  103. @param Control A pointer to return the current control signals from the serial device.
  104. @retval RETURN_SUCCESS The control bits were read from the serial device.
  105. @retval RETURN_UNSUPPORTED The serial device does not support this operation.
  106. @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
  107. **/
  108. RETURN_STATUS
  109. EFIAPI
  110. SerialPortGetControl (
  111. OUT UINT32 *Control
  112. )
  113. {
  114. *Control = 0;
  115. if (!SerialPortPoll ()) {
  116. *Control = EFI_SERIAL_INPUT_BUFFER_EMPTY;
  117. }
  118. return RETURN_SUCCESS;
  119. }
  120. /**
  121. Sets the baud rate, receive FIFO depth, transmit/receice time out, parity,
  122. data bits, and stop bits on a serial device.
  123. @param BaudRate The requested baud rate. A BaudRate value of 0 will use the
  124. device's default interface speed.
  125. On output, the value actually set.
  126. @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the
  127. serial interface. A ReceiveFifoDepth value of 0 will use
  128. the device's default FIFO depth.
  129. On output, the value actually set.
  130. @param Timeout The requested time out for a single character in microseconds.
  131. This timeout applies to both the transmit and receive side of the
  132. interface. A Timeout value of 0 will use the device's default time
  133. out value.
  134. On output, the value actually set.
  135. @param Parity The type of parity to use on this serial device. A Parity value of
  136. DefaultParity will use the device's default parity value.
  137. On output, the value actually set.
  138. @param DataBits The number of data bits to use on the serial device. A DataBits
  139. vaule of 0 will use the device's default data bit setting.
  140. On output, the value actually set.
  141. @param StopBits The number of stop bits to use on this serial device. A StopBits
  142. value of DefaultStopBits will use the device's default number of
  143. stop bits.
  144. On output, the value actually set.
  145. @retval RETURN_SUCCESS The new attributes were set on the serial device.
  146. @retval RETURN_UNSUPPORTED The serial device does not support this operation.
  147. @retval RETURN_INVALID_PARAMETER One or more of the attributes has an unsupported value.
  148. @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
  149. **/
  150. RETURN_STATUS
  151. EFIAPI
  152. SerialPortSetAttributes (
  153. IN OUT UINT64 *BaudRate,
  154. IN OUT UINT32 *ReceiveFifoDepth,
  155. IN OUT UINT32 *Timeout,
  156. IN OUT EFI_PARITY_TYPE *Parity,
  157. IN OUT UINT8 *DataBits,
  158. IN OUT EFI_STOP_BITS_TYPE *StopBits
  159. )
  160. {
  161. return RETURN_UNSUPPORTED;
  162. }