debug.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*++
  2. Copyright (c) 2015 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. Chris Stevens 10-Jul-2015
  9. Environment:
  10. Firmware
  11. --*/
  12. //
  13. // ------------------------------------------------------------------- Includes
  14. //
  15. #include <uefifw.h>
  16. #include <dev/ns16550.h>
  17. #include "veyronfw.h"
  18. //
  19. // --------------------------------------------------------------------- Macros
  20. //
  21. //
  22. // ---------------------------------------------------------------- Definitions
  23. //
  24. //
  25. // Define the hard-coded debug serial port.
  26. //
  27. #define EFI_VEYRON_DEBUG_SERIAL_BASE (VOID *)RK32_UART_DEBUG_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. NS16550_CONTEXT EfiVeyronDebugUart;
  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. //
  61. // Make sure any platform specific UART initialization steps have been
  62. // completed.
  63. //
  64. EfipVeyronInitializeUart();
  65. //
  66. // Compute the NS 16550 UART divisor and initialize the device.
  67. //
  68. Status = EfipNs16550ComputeDivisor(RK32_UART_BASE_BAUD,
  69. BaudRate,
  70. &(EfiVeyronDebugUart.BaudRateDivisor));
  71. if (EFI_ERROR(Status)) {
  72. return Status;
  73. }
  74. EfiVeyronDebugUart.MemoryBase = EFI_VEYRON_DEBUG_SERIAL_BASE;
  75. EfiVeyronDebugUart.RegisterOffset = RK32_UART_REGISTER_OFFSET;
  76. EfiVeyronDebugUart.RegisterShift = RK32_UART_REGISTER_SHIFT;
  77. EfiVeyronDebugUart.Flags = NS16550_FLAG_TRANSMIT_TRIGGER_2_CHARACTERS;
  78. return EfipNs16550Initialize(&EfiVeyronDebugUart);
  79. }
  80. EFI_STATUS
  81. EfiPlatformDebugDeviceTransmit (
  82. VOID *Data,
  83. UINTN Size
  84. )
  85. /*++
  86. Routine Description:
  87. This routine transmits data from the host out through the debug device.
  88. Arguments:
  89. Data - Supplies a pointer to the data to write.
  90. Size - Supplies the size to write, in bytes.
  91. Return Value:
  92. EFI_SUCCESS on success.
  93. EFI_DEVICE_ERROR if a device error occurred.
  94. --*/
  95. {
  96. return EfipNs16550Transmit(&EfiVeyronDebugUart, Data, Size);
  97. }
  98. EFI_STATUS
  99. EfiPlatformDebugDeviceReceive (
  100. VOID *Data,
  101. UINTN *Size
  102. )
  103. /*++
  104. Routine Description:
  105. This routine receives incoming data from the debug device.
  106. Arguments:
  107. Data - Supplies a pointer where the read data will be returned on success.
  108. Size - Supplies a pointer that on input contains the size of the receive
  109. buffer. On output, returns the number of bytes read.
  110. Return Value:
  111. EFI_SUCCESS on success.
  112. EFI_NOT_READY if there was no data to be read at the current time.
  113. EFI_DEVICE_ERROR if a device error occurred.
  114. --*/
  115. {
  116. return EfipNs16550Receive(&EfiVeyronDebugUart, Data, Size);
  117. }
  118. EFI_STATUS
  119. EfiPlatformDebugDeviceGetStatus (
  120. BOOLEAN *ReceiveDataAvailable
  121. )
  122. /*++
  123. Routine Description:
  124. This routine returns the current device status.
  125. Arguments:
  126. ReceiveDataAvailable - Supplies a pointer where a boolean will be returned
  127. indicating whether or not receive data is available.
  128. Return Value:
  129. EFI_SUCCESS on success.
  130. EFI_DEVICE_ERROR if a device error occurred.
  131. --*/
  132. {
  133. return EfipNs16550GetStatus(&EfiVeyronDebugUart, ReceiveDataAvailable);
  134. }
  135. VOID
  136. EfiPlatformDebugDeviceDisconnect (
  137. VOID
  138. )
  139. /*++
  140. Routine Description:
  141. This routine disconnects a device, taking it offline.
  142. Arguments:
  143. None.
  144. Return Value:
  145. None.
  146. --*/
  147. {
  148. return;
  149. }
  150. //
  151. // --------------------------------------------------------- Internal Functions
  152. //