debug.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 19-Mar-2015
  9. Environment:
  10. Firmware
  11. --*/
  12. //
  13. // ------------------------------------------------------------------- Includes
  14. //
  15. #include <uefifw.h>
  16. #include <dev/pl11.h>
  17. #include "rpi2fw.h"
  18. //
  19. // --------------------------------------------------------------------- Macros
  20. //
  21. //
  22. // ---------------------------------------------------------------- Definitions
  23. //
  24. //
  25. // ------------------------------------------------------ Data Type Definitions
  26. //
  27. //
  28. // ----------------------------------------------- Internal Function Prototypes
  29. //
  30. //
  31. // -------------------------------------------------------------------- Globals
  32. //
  33. //
  34. // Define the context for the debug UART.
  35. //
  36. PL11_CONTEXT EfiRaspberryPi2DebugUart;
  37. //
  38. // ------------------------------------------------------------------ Functions
  39. //
  40. EFI_STATUS
  41. EfiPlatformDebugDeviceReset (
  42. UINT32 BaudRate
  43. )
  44. /*++
  45. Routine Description:
  46. This routine attempts to initialize the serial UART used for debugging.
  47. Arguments:
  48. BaudRate - Supplies the desired baud rate.
  49. Return Value:
  50. EFI_SUCCESS on success.
  51. EFI_DEVICE_ERROR if a device error occurred while resetting the device.
  52. EFI_UNSUPPORTED if the given baud rate cannot be achieved.
  53. --*/
  54. {
  55. EFI_STATUS Status;
  56. EfiRaspberryPi2DebugUart.UartBase =
  57. (VOID *)BCM2836_BASE + BCM2709_UART_OFFSET;
  58. Status = EfipPl11ComputeDivisor(
  59. PL11_CLOCK_FREQUENCY_3MHZ,
  60. BaudRate,
  61. &(EfiRaspberryPi2DebugUart.BaudRateInteger),
  62. &(EfiRaspberryPi2DebugUart.BaudRateFraction));
  63. if (EFI_ERROR(Status)) {
  64. return Status;
  65. }
  66. return EfipPl11Initialize(&EfiRaspberryPi2DebugUart);
  67. }
  68. EFI_STATUS
  69. EfiPlatformDebugDeviceTransmit (
  70. VOID *Data,
  71. UINTN Size
  72. )
  73. /*++
  74. Routine Description:
  75. This routine transmits data from the host out through the debug device.
  76. Arguments:
  77. Data - Supplies a pointer to the data to write.
  78. Size - Supplies the size to write, in bytes.
  79. Return Value:
  80. EFI_SUCCESS on success.
  81. EFI_DEVICE_ERROR if a device error occurred.
  82. --*/
  83. {
  84. return EfipPl11Transmit(&EfiRaspberryPi2DebugUart, Data, Size);
  85. }
  86. EFI_STATUS
  87. EfiPlatformDebugDeviceReceive (
  88. VOID *Data,
  89. UINTN *Size
  90. )
  91. /*++
  92. Routine Description:
  93. This routine receives incoming data from the debug device.
  94. Arguments:
  95. Data - Supplies a pointer where the read data will be returned on success.
  96. Size - Supplies a pointer that on input contains the size of the receive
  97. buffer. On output, returns the number of bytes read.
  98. Return Value:
  99. EFI_SUCCESS on success.
  100. EFI_NOT_READY if there was no data to be read at the current time.
  101. EFI_DEVICE_ERROR if a device error occurred.
  102. --*/
  103. {
  104. return EfipPl11Receive(&EfiRaspberryPi2DebugUart, Data, Size);
  105. }
  106. EFI_STATUS
  107. EfiPlatformDebugDeviceGetStatus (
  108. BOOLEAN *ReceiveDataAvailable
  109. )
  110. /*++
  111. Routine Description:
  112. This routine returns the current device status.
  113. Arguments:
  114. ReceiveDataAvailable - Supplies a pointer where a boolean will be returned
  115. indicating whether or not receive data is available.
  116. Return Value:
  117. EFI_SUCCESS on success.
  118. EFI_DEVICE_ERROR if a device error occurred.
  119. --*/
  120. {
  121. return EfipPl11GetStatus(&EfiRaspberryPi2DebugUart, ReceiveDataAvailable);
  122. }
  123. VOID
  124. EfiPlatformDebugDeviceDisconnect (
  125. VOID
  126. )
  127. /*++
  128. Routine Description:
  129. This routine disconnects a device, taking it offline.
  130. Arguments:
  131. None.
  132. Return Value:
  133. None.
  134. --*/
  135. {
  136. return;
  137. }
  138. //
  139. // --------------------------------------------------------- Internal Functions
  140. //