DxeSmmI2cHdmiDebugSerialPortLib.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /** @file
  2. Serial I/O Port library implementation for the HDMI I2C Debug Port
  3. DXE/SMM Library implementation
  4. Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include <Base.h>
  8. #include <Library/BaseLib.h>
  9. #include <Library/SerialPortLib.h>
  10. #include <Library/PcdLib.h>
  11. #include <Library/TimerLib.h>
  12. #include <IgfxI2c.h>
  13. #include <I2cDebugPortProtocol.h>
  14. //Once we reach DXE phase we can start assuming global variables are writeable.
  15. STATIC PCH_TYPE mPchType = PchTypeUnknown;
  16. STATIC UINT32 mControlBits = 0;
  17. STATIC UINT8 mI2cHdmiDebugDdcBusPinPair = 0;
  18. STATIC BOOLEAN mIgdBusMasterReset = FALSE;
  19. /**
  20. Sets the control bits on a serial device.
  21. @param Control Sets the bits of Control that are settable.
  22. @retval RETURN_SUCCESS The new control bits were set on the serial device.
  23. @retval RETURN_UNSUPPORTED The serial device does not support this operation.
  24. @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
  25. **/
  26. RETURN_STATUS
  27. EFIAPI
  28. SerialPortSetControl (
  29. IN UINT32 Control
  30. )
  31. {
  32. //
  33. // check for invalid control parameters
  34. //
  35. if ((Control & (~(EFI_SERIAL_REQUEST_TO_SEND |
  36. EFI_SERIAL_DATA_TERMINAL_READY |
  37. EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE |
  38. EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE |
  39. EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE))) != 0 ) {
  40. return EFI_UNSUPPORTED;
  41. }
  42. Control &= (UINT32) ~(EFI_SERIAL_INPUT_BUFFER_EMPTY);
  43. mControlBits = Control;
  44. return EFI_SUCCESS;
  45. }
  46. /**
  47. Retrieve the status of the control bits on a serial device.
  48. @param Control A pointer to return the current control signals from the serial device.
  49. @retval RETURN_SUCCESS The control bits were read from the serial device.
  50. @retval RETURN_UNSUPPORTED The serial device does not support this operation.
  51. @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
  52. **/
  53. RETURN_STATUS
  54. EFIAPI
  55. SerialPortGetControl (
  56. OUT UINT32 *Control
  57. )
  58. {
  59. EFI_STATUS Status;
  60. UINT8 NumberOfBytesInFifoBuffer;
  61. Status = I2cDebugPortReadyToRead (&NumberOfBytesInFifoBuffer);
  62. if (EFI_ERROR (Status)) {
  63. return Status;
  64. }
  65. *Control = (EFI_SERIAL_CLEAR_TO_SEND | EFI_SERIAL_DATA_SET_READY |
  66. EFI_SERIAL_CARRIER_DETECT | EFI_SERIAL_OUTPUT_BUFFER_EMPTY);
  67. if (NumberOfBytesInFifoBuffer <= 0) {
  68. *Control |= EFI_SERIAL_INPUT_BUFFER_EMPTY;
  69. }
  70. *Control |= mControlBits;
  71. return Status;
  72. }
  73. /**
  74. Returns the type of PCH on the system
  75. @retval The PCH type.
  76. **/
  77. PCH_TYPE
  78. GetPchType (
  79. VOID
  80. )
  81. {
  82. if (mPchType == PchTypeUnknown) {
  83. mPchType = GetPchTypeInternal ();
  84. }
  85. return mPchType;
  86. }
  87. /**
  88. Returns the GPIO pin pair to use for the I2C HDMI debug port
  89. @param[out] DdcBusPinPair - The GPIO pin pair for the I2C HDMI debug port.
  90. @retval EFI_SUCCESS - The GPIO pin pair was successfully determined
  91. @retval EFI_INVALID_PARAMETER - The given DDC I2C channel does not exist.
  92. @retval EFI_UNSUPPORTED - The platform is using a PCH that is not supported yet.
  93. **/
  94. EFI_STATUS
  95. GetGmbusBusPinPairForI2cDebugPort (
  96. OUT UINT8 *DdcBusPinPair
  97. )
  98. {
  99. EFI_STATUS Status;
  100. if (mI2cHdmiDebugDdcBusPinPair == 0) {
  101. Status = GetGmbusBusPinPair (
  102. (IGFX_I2C_CHANNEL) PcdGet32 (PcdI2cHdmiDebugPortDdcI2cChannel),
  103. &mI2cHdmiDebugDdcBusPinPair
  104. );
  105. if (EFI_ERROR (Status)) {
  106. mI2cHdmiDebugDdcBusPinPair = 0;
  107. return Status;
  108. }
  109. }
  110. *DdcBusPinPair = mI2cHdmiDebugDdcBusPinPair;
  111. return EFI_SUCCESS;
  112. }
  113. /**
  114. Returns a flag indicating whether the IGD device bus master enable needs to
  115. be disabled at the end of the current transaction
  116. @retval TRUE - IGD Bus Master Enable needs to be reset
  117. @retval FALSE - IGD Bus Master Enable does not need to be reset
  118. **/
  119. BOOLEAN
  120. GetIgdBusMasterReset (
  121. VOID
  122. )
  123. {
  124. return mIgdBusMasterReset;
  125. }
  126. /**
  127. Sets a flag indicating whether the IGD device bus master enable needs to
  128. be disabled at the end of the current transaction
  129. @param[in] IgdBusMasterReset - IGD device bus master enable flag
  130. **/
  131. VOID
  132. SetIgdBusMasterReset (
  133. BOOLEAN IgdBusMasterReset
  134. )
  135. {
  136. mIgdBusMasterReset = IgdBusMasterReset;
  137. }