pl11.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*++
  2. Copyright (c) 2014 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. pl11.h
  9. Abstract:
  10. This header contains definitions for the ARM PrimeCell PL-011 Serial UART.
  11. Author:
  12. Evan Green 27-Feb-2014
  13. --*/
  14. //
  15. // ------------------------------------------------------------------- Includes
  16. //
  17. //
  18. // ---------------------------------------------------------------- Definitions
  19. //
  20. #define PL11_CLOCK_FREQUENCY_3MHZ 3000000
  21. #define PL11_CLOCK_FREQUENCY_14MHZ 14745600
  22. //
  23. // ------------------------------------------------------ Data Type Definitions
  24. //
  25. /*++
  26. Structure Description:
  27. This structure defines the context for a PL011 UART controller. Upon
  28. initialization, the consumer of the library is responsible for initializing
  29. some of these values.
  30. Members:
  31. UartBase - Stores the base address of the UART. The consumer of the library
  32. should have initialized this value before calling the library
  33. initialize function.
  34. BaudRateInteger - Stores the integer portion of the baud rate divisor. The
  35. consumer of this library should have initialized this value before
  36. calling the library initialize function.
  37. BaudRateFraction - Stores the fractional portion of the baud rate divisor.
  38. The consumer of this library should have initialized this value before
  39. calling the library initialize function.
  40. --*/
  41. typedef struct _PL11_CONTEXT {
  42. VOID *UartBase;
  43. UINT16 BaudRateInteger;
  44. UINT16 BaudRateFraction;
  45. } PL11_CONTEXT, *PPL11_CONTEXT;
  46. //
  47. // -------------------------------------------------------------------- Globals
  48. //
  49. //
  50. // -------------------------------------------------------- Function Prototypes
  51. //
  52. EFI_STATUS
  53. EfipPl11ComputeDivisor (
  54. UINT32 InputClock,
  55. UINT32 BaudRate,
  56. UINT16 *IntegerDivisor,
  57. UINT16 *FractionalDivisor
  58. );
  59. /*++
  60. Routine Description:
  61. This routine computes the divisor rates for a PL-011 UART at a given baud
  62. rate.
  63. Arguments:
  64. InputClock - Supplies the input clock frequency in Hertz.
  65. BaudRate - Supplies the desired baud rate.
  66. IntegerDivisor - Supplies a pointer where the integer divisor will be
  67. returned on success.
  68. FractionalDivisor - Supplies a pointer where the fractional divisor will
  69. be returned on success.
  70. Return Value:
  71. EFI_SUCCESS on success.
  72. EFI_UNSUPPORTED if the given baud rate cannot be achieved.
  73. --*/
  74. EFI_STATUS
  75. EfipPl11Initialize (
  76. PPL11_CONTEXT Context
  77. );
  78. /*++
  79. Routine Description:
  80. This routine initializes the PL-11 serial port hardware. The caller should
  81. have initialized at least some of the context structure.
  82. Arguments:
  83. Context - Supplies the pointer to the port's initialized context.
  84. Return Value:
  85. EFI Status code.
  86. --*/
  87. EFI_STATUS
  88. EfipPl11Transmit (
  89. PPL11_CONTEXT Context,
  90. VOID *Data,
  91. UINTN Size
  92. );
  93. /*++
  94. Routine Description:
  95. This routine writes data out the serial port. This routine should busily
  96. spin if the previously sent byte has not finished transmitting.
  97. Arguments:
  98. Context - Supplies the pointer to the port context.
  99. Data - Supplies a pointer to the data to write.
  100. Size - Supplies the size to write, in bytes.
  101. Return Value:
  102. EFI_SUCCESS on success.
  103. EFI_DEVICE_ERROR if a device error occurred.
  104. --*/
  105. EFI_STATUS
  106. EfipPl11Receive (
  107. PPL11_CONTEXT Context,
  108. VOID *Data,
  109. UINTN *Size
  110. );
  111. /*++
  112. Routine Description:
  113. This routine reads bytes from the serial port.
  114. Arguments:
  115. Context - Supplies the pointer to the port context.
  116. Data - Supplies a pointer where the read data will be returned on success.
  117. Size - Supplies a pointer that on input contains the size of the receive
  118. buffer. On output, returns the number of bytes read.
  119. Return Value:
  120. EFI_SUCCESS on success.
  121. EFI_NOT_READY if there was no data to be read at the current time.
  122. EFI_DEVICE_ERROR if a device error occurred.
  123. --*/
  124. EFI_STATUS
  125. EfipPl11GetStatus (
  126. PPL11_CONTEXT Context,
  127. BOOLEAN *ReceiveDataAvailable
  128. );
  129. /*++
  130. Routine Description:
  131. This routine returns the current device status.
  132. Arguments:
  133. Context - Supplies a pointer to the serial port context.
  134. ReceiveDataAvailable - Supplies a pointer where a boolean will be returned
  135. indicating whether or not receive data is available.
  136. Return Value:
  137. EFI_SUCCESS on success.
  138. EFI_DEVICE_ERROR if a device error occurred.
  139. --*/