debug.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*++
  2. Copyright (c) 2014 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. debug.c
  5. Abstract:
  6. This module implements debug UART support for UEFI platforms.
  7. Author:
  8. Evan Green 19-Dec-2014
  9. Environment:
  10. Firmware
  11. --*/
  12. //
  13. // ------------------------------------------------------------------- Includes
  14. //
  15. #include "uefifw.h"
  16. #include "dev/omapuart.h"
  17. #include <minoca/soc/am335x.h>
  18. //
  19. // --------------------------------------------------------------------- Macros
  20. //
  21. //
  22. // ---------------------------------------------------------------- Definitions
  23. //
  24. //
  25. // Define the hard-coded debug serial port.
  26. //
  27. #define EFI_BEAGLEBONE_DEBUG_SERIAL_BASE (VOID *)AM335_UART_0_BASE
  28. //
  29. // ------------------------------------------------------ Data Type Definitions
  30. //
  31. //
  32. // ----------------------------------------------- Internal Function Prototypes
  33. //
  34. //
  35. // -------------------------------------------------------------------- Globals
  36. //
  37. //
  38. // Define the context for the debug UART.
  39. //
  40. OMAP_UART_CONTEXT EfiBeagleBoneDebugUart;
  41. //
  42. // ------------------------------------------------------------------ Functions
  43. //
  44. EFI_STATUS
  45. EfiPlatformDebugDeviceReset (
  46. UINT32 BaudRate
  47. )
  48. /*++
  49. Routine Description:
  50. This routine attempts to initialize the serial UART used for debugging.
  51. Arguments:
  52. BaudRate - Supplies the desired baud rate.
  53. Return Value:
  54. EFI_SUCCESS on success.
  55. EFI_DEVICE_ERROR if a device error occurred while resetting the device.
  56. EFI_UNSUPPORTED if the given baud rate cannot be achieved.
  57. --*/
  58. {
  59. EFI_STATUS Status;
  60. Status = EfipUartOmapComputeDivisor(
  61. BaudRate,
  62. &(EfiBeagleBoneDebugUart.BaudRateRegister));
  63. if (EFI_ERROR(Status)) {
  64. return Status;
  65. }
  66. EfiBeagleBoneDebugUart.UartBase = EFI_BEAGLEBONE_DEBUG_SERIAL_BASE;
  67. Status = EfipUartOmapInitialize(&EfiBeagleBoneDebugUart);
  68. if (EFI_ERROR(Status)) {
  69. return Status;
  70. }
  71. return EFI_SUCCESS;
  72. }
  73. EFI_STATUS
  74. EfiPlatformDebugDeviceTransmit (
  75. VOID *Data,
  76. UINTN Size
  77. )
  78. /*++
  79. Routine Description:
  80. This routine transmits data from the host out through the debug device.
  81. Arguments:
  82. Data - Supplies a pointer to the data to write.
  83. Size - Supplies the size to write, in bytes.
  84. Return Value:
  85. EFI_SUCCESS on success.
  86. EFI_DEVICE_ERROR if a device error occurred.
  87. --*/
  88. {
  89. EFI_STATUS Status;
  90. Status = EfipUartOmapTransmit(&EfiBeagleBoneDebugUart, Data, Size);
  91. return Status;
  92. }
  93. EFI_STATUS
  94. EfiPlatformDebugDeviceReceive (
  95. VOID *Data,
  96. UINTN *Size
  97. )
  98. /*++
  99. Routine Description:
  100. This routine receives incoming data from the debug device.
  101. Arguments:
  102. Data - Supplies a pointer where the read data will be returned on success.
  103. Size - Supplies a pointer that on input contains the size of the receive
  104. buffer. On output, returns the number of bytes read.
  105. Return Value:
  106. EFI_SUCCESS on success.
  107. EFI_NOT_READY if there was no data to be read at the current time.
  108. EFI_DEVICE_ERROR if a device error occurred.
  109. --*/
  110. {
  111. EFI_STATUS Status;
  112. Status = EfipUartOmapReceive(&EfiBeagleBoneDebugUart, Data, Size);
  113. return Status;
  114. }
  115. EFI_STATUS
  116. EfiPlatformDebugDeviceGetStatus (
  117. BOOLEAN *ReceiveDataAvailable
  118. )
  119. /*++
  120. Routine Description:
  121. This routine returns the current device status.
  122. Arguments:
  123. ReceiveDataAvailable - Supplies a pointer where a boolean will be returned
  124. indicating whether or not receive data is available.
  125. Return Value:
  126. EFI_SUCCESS on success.
  127. EFI_DEVICE_ERROR if a device error occurred.
  128. --*/
  129. {
  130. return EfipUartOmapGetStatus(&EfiBeagleBoneDebugUart, ReceiveDataAvailable);
  131. }
  132. VOID
  133. EfiPlatformDebugDeviceDisconnect (
  134. VOID
  135. )
  136. /*++
  137. Routine Description:
  138. This routine disconnects a device, taking it offline.
  139. Arguments:
  140. None.
  141. Return Value:
  142. None.
  143. --*/
  144. {
  145. return;
  146. }
  147. //
  148. // --------------------------------------------------------- Internal Functions
  149. //