ns16550.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*++
  2. Copyright (c) 2015 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. ns16550.h
  9. Abstract:
  10. This header contains definitions for the NS 16550 Serial UART.
  11. Author:
  12. Chris Stevens 10-Jul-2015
  13. --*/
  14. //
  15. // ------------------------------------------------------------------- Includes
  16. //
  17. //
  18. // ---------------------------------------------------------------- Definitions
  19. //
  20. //
  21. // Define the set of NS 16550 flags.
  22. //
  23. #define NS16550_FLAG_64_BYTE_FIFO 0x00000001
  24. #define NS16550_FLAG_TRANSMIT_TRIGGER_2_CHARACTERS 0x00000002
  25. //
  26. // Define the possible register shift values.
  27. //
  28. #define NS16550_1_BYTE_REGISTER_SHIFT 0
  29. #define NS16550_2_BYTE_REGISTER_SHIFT 1
  30. #define NS16550_4_BYTE_REGISTER_SHIFT 2
  31. //
  32. // ------------------------------------------------------ Data Type Definitions
  33. //
  34. /*++
  35. Structure Description:
  36. This structure defines the context for a 16550 UART.
  37. Members:
  38. MemoryBase - Stores the optional address of the registers, if the registers
  39. are memory mapped. This contains NULL for I/O port implementations.
  40. IoBase - Stores the I/O port base of the registers if they are accessed via
  41. I/O ports.
  42. RegisterOffset - Stores the offset in bytes from the start of the register
  43. base to the 16550 registers.
  44. RegisterShift - Stores the amount to shift the register number by to get
  45. the real register.
  46. BaudRateDivisor - Stores the baud rate divisor.
  47. Flags - Stores a bitmask of flags. See NS16550_FLAG_* for definitions.
  48. Read8 - Stores the pointer to the function used to read from the registers.
  49. Write8 - Stores the pointer to the function used to write to the registers.
  50. --*/
  51. typedef struct _NS16550_CONTEXT {
  52. VOID *MemoryBase;
  53. UINT16 IoBase;
  54. UINTN RegisterOffset;
  55. UINT32 RegisterShift;
  56. UINT16 BaudRateDivisor;
  57. UINT32 Flags;
  58. VOID *Read8;
  59. VOID *Write8;
  60. } NS16550_CONTEXT, *PNS16550_CONTEXT;
  61. //
  62. // -------------------------------------------------------------------- Globals
  63. //
  64. //
  65. // -------------------------------------------------------- Function Prototypes
  66. //
  67. EFI_STATUS
  68. EfipNs16550ComputeDivisor (
  69. UINT32 BaseBaud,
  70. UINT32 BaudRate,
  71. UINT16 *Divisor
  72. );
  73. /*++
  74. Routine Description:
  75. This routine computes the divisor rates for a NS 16550 UART at a given baud
  76. rate.
  77. Arguments:
  78. BaseBaud - Supplies the baud rate for a divisor of 1.
  79. BaudRate - Supplies the desired baud rate.
  80. Divisor - Supplies a pointer where the divisor will be returned on success.
  81. Return Value:
  82. EFI_SUCCESS on success.
  83. EFI_UNSUPPORTED if the given baud rate cannot be achieved.
  84. --*/
  85. EFI_STATUS
  86. EfipNs16550Initialize (
  87. PNS16550_CONTEXT Context
  88. );
  89. /*++
  90. Routine Description:
  91. This routine initializes the NS 16550 serial port hardware. The caller
  92. should have initialized at least some of the context structure.
  93. Arguments:
  94. Context - Supplies the pointer to the port's initialized context.
  95. Return Value:
  96. EFI Status code.
  97. --*/
  98. EFI_STATUS
  99. EfipNs16550Transmit (
  100. PNS16550_CONTEXT Context,
  101. VOID *Data,
  102. UINTN Size
  103. );
  104. /*++
  105. Routine Description:
  106. This routine writes data out the serial port. This routine should busily
  107. spin if the previously sent byte has not finished transmitting.
  108. Arguments:
  109. Context - Supplies the pointer to the port context.
  110. Data - Supplies a pointer to the data to write.
  111. Size - Supplies the size to write, in bytes.
  112. Return Value:
  113. EFI_SUCCESS on success.
  114. EFI_DEVICE_ERROR if a device error occurred.
  115. --*/
  116. EFI_STATUS
  117. EfipNs16550Receive (
  118. PNS16550_CONTEXT Context,
  119. VOID *Data,
  120. UINTN *Size
  121. );
  122. /*++
  123. Routine Description:
  124. This routine reads bytes from the serial port.
  125. Arguments:
  126. Context - Supplies the pointer to the port context.
  127. Data - Supplies a pointer where the read data will be returned on success.
  128. Size - Supplies a pointer that on input contains the size of the receive
  129. buffer. On output, returns the number of bytes read.
  130. Return Value:
  131. EFI_SUCCESS on success.
  132. EFI_NOT_READY if there was no data to be read at the current time.
  133. EFI_DEVICE_ERROR if a device error occurred.
  134. --*/
  135. EFI_STATUS
  136. EfipNs16550GetStatus (
  137. PNS16550_CONTEXT Context,
  138. BOOLEAN *ReceiveDataAvailable
  139. );
  140. /*++
  141. Routine Description:
  142. This routine returns the current device status.
  143. Arguments:
  144. Context - Supplies a pointer to the serial port context.
  145. ReceiveDataAvailable - Supplies a pointer where a boolean will be returned
  146. indicating whether or not receive data is available.
  147. Return Value:
  148. EFI_SUCCESS on success.
  149. EFI_DEVICE_ERROR if a device error occurred.
  150. --*/