dbgser.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*++
  2. Copyright (c) 2014 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. dbgser.c
  5. Abstract:
  6. This module implements common debug device routines.
  7. Author:
  8. Evan Green 26-Feb-2014
  9. Environment:
  10. Kernel
  11. --*/
  12. //
  13. // ------------------------------------------------------------------- Includes
  14. //
  15. #include "ueficore.h"
  16. #include <minoca/kernel/hmod.h>
  17. //
  18. // ---------------------------------------------------------------- Definitions
  19. //
  20. //
  21. // ------------------------------------------------------ Data Type Definitions
  22. //
  23. //
  24. // ----------------------------------------------- Internal Function Prototypes
  25. //
  26. KSTATUS
  27. EfiCoreDebugDeviceReset (
  28. PVOID Context,
  29. ULONG BaudRate
  30. );
  31. KSTATUS
  32. EfiCoreDebugDeviceTransmit (
  33. PVOID Context,
  34. PVOID Data,
  35. ULONG Size
  36. );
  37. KSTATUS
  38. EfiCoreDebugDeviceReceive (
  39. PVOID Context,
  40. PVOID Data,
  41. PULONG Size
  42. );
  43. KSTATUS
  44. EfiCoreDebugDeviceGetStatus (
  45. PVOID Context,
  46. PBOOL ReceiveDataAvailable
  47. );
  48. VOID
  49. EfiCoreDebugDeviceDisconnect (
  50. PVOID Context
  51. );
  52. //
  53. // -------------------------------------------------------------------- Globals
  54. //
  55. //
  56. // Store the EFI debug device description.
  57. //
  58. DEBUG_DEVICE_DESCRIPTION EfiDebugDevice = {
  59. DEBUG_DEVICE_DESCRIPTION_VERSION,
  60. {
  61. EfiCoreDebugDeviceReset,
  62. EfiCoreDebugDeviceTransmit,
  63. EfiCoreDebugDeviceReceive,
  64. EfiCoreDebugDeviceGetStatus,
  65. EfiCoreDebugDeviceDisconnect,
  66. },
  67. NULL,
  68. 1
  69. };
  70. //
  71. // ------------------------------------------------------------------ Functions
  72. //
  73. KSTATUS
  74. EfiCoreDebugDeviceReset (
  75. PVOID Context,
  76. ULONG BaudRate
  77. )
  78. /*++
  79. Routine Description:
  80. This routine initializes and resets a debug device, preparing it to send
  81. and receive data.
  82. Arguments:
  83. Context - Supplies the pointer to the port's context, provided by the
  84. hardware module upon initialization.
  85. BaudRate - Supplies the baud rate to set.
  86. Return Value:
  87. STATUS_SUCCESS on success.
  88. Other status codes on failure. The device will not be used if a failure
  89. status code is returned.
  90. --*/
  91. {
  92. EFI_STATUS EfiStatus;
  93. EfiStatus = EfiPlatformDebugDeviceReset(BaudRate);
  94. if (EfiStatus == EFI_UNSUPPORTED) {
  95. return STATUS_NOT_SUPPORTED;
  96. } else if (EFI_ERROR(EfiStatus)) {
  97. return STATUS_DEVICE_IO_ERROR;
  98. }
  99. return STATUS_SUCCESS;
  100. }
  101. KSTATUS
  102. EfiCoreDebugDeviceTransmit (
  103. PVOID Context,
  104. PVOID Data,
  105. ULONG Size
  106. )
  107. /*++
  108. Routine Description:
  109. This routine transmits data from the host out through the debug device.
  110. Arguments:
  111. Context - Supplies the pointer to the port's context, provided by the
  112. hardware module upon initialization.
  113. Data - Supplies a pointer to the data to write.
  114. Size - Supplies the size to write, in bytes.
  115. Return Value:
  116. STATUS_SUCCESS on success.
  117. STATUS_DEVICE_IO_ERROR if a device error occurred.
  118. --*/
  119. {
  120. EFI_STATUS EfiStatus;
  121. EfiStatus = EfiPlatformDebugDeviceTransmit(Data, Size);
  122. if (EFI_ERROR(EfiStatus)) {
  123. return STATUS_DEVICE_IO_ERROR;
  124. }
  125. return STATUS_SUCCESS;
  126. }
  127. KSTATUS
  128. EfiCoreDebugDeviceReceive (
  129. PVOID Context,
  130. PVOID Data,
  131. PULONG Size
  132. )
  133. /*++
  134. Routine Description:
  135. This routine receives incoming data from the debug device.
  136. Arguments:
  137. Context - Supplies the pointer to the port's context, provided by the
  138. hardware module upon initialization.
  139. Data - Supplies a pointer where the read data will be returned on success.
  140. Size - Supplies a pointer that on input contains the size of the receive
  141. buffer. On output, returns the number of bytes read.
  142. Return Value:
  143. STATUS_SUCCESS on success.
  144. STATUS_NO_DATA_AVAILABLE if there was no data to be read at the current
  145. time.
  146. STATUS_DEVICE_IO_ERROR if a device error occurred.
  147. --*/
  148. {
  149. EFI_STATUS EfiStatus;
  150. UINTN NaturalSize;
  151. NaturalSize = *Size;
  152. EfiStatus = EfiPlatformDebugDeviceReceive(Data, &NaturalSize);
  153. *Size = NaturalSize;
  154. if (EfiStatus == EFI_NOT_READY) {
  155. return STATUS_NO_DATA_AVAILABLE;
  156. } else if (EFI_ERROR(EfiStatus)) {
  157. return STATUS_DEVICE_IO_ERROR;
  158. }
  159. return STATUS_SUCCESS;
  160. }
  161. KSTATUS
  162. EfiCoreDebugDeviceGetStatus (
  163. PVOID Context,
  164. PBOOL ReceiveDataAvailable
  165. )
  166. /*++
  167. Routine Description:
  168. This routine returns the current device status.
  169. Arguments:
  170. Context - Supplies the pointer to the port's context, provided by the
  171. hardware module upon initialization.
  172. ReceiveDataAvailable - Supplies a pointer where a boolean will be returned
  173. indicating whether or not receive data is available.
  174. Return Value:
  175. Status code.
  176. --*/
  177. {
  178. EFI_STATUS EfiStatus;
  179. BOOLEAN ReceiveAvailable;
  180. EfiStatus = EfiPlatformDebugDeviceGetStatus(&ReceiveAvailable);
  181. *ReceiveDataAvailable = ReceiveAvailable;
  182. if (EFI_ERROR(EfiStatus)) {
  183. return STATUS_DEVICE_IO_ERROR;
  184. }
  185. return STATUS_SUCCESS;
  186. }
  187. VOID
  188. EfiCoreDebugDeviceDisconnect (
  189. PVOID Context
  190. )
  191. /*++
  192. Routine Description:
  193. This routine disconnects a device, taking it offline.
  194. Arguments:
  195. Context - Supplies the pointer to the port's context, provided by the
  196. hardware module upon initialization.
  197. Return Value:
  198. None.
  199. --*/
  200. {
  201. EfiPlatformDebugDeviceDisconnect();
  202. return;
  203. }
  204. //
  205. // --------------------------------------------------------- Internal Functions
  206. //