SecI2cHdmiDebugSerialPortLib.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /** @file
  2. Serial I/O Port library implementation for the HDMI I2C Debug Port
  3. Generic Base 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 <IgfxI2c.h>
  12. #include <I2cDebugPortProtocol.h>
  13. /**
  14. Sets the control bits on a serial device.
  15. @param Control Sets the bits of Control that are settable.
  16. @retval RETURN_SUCCESS The new control bits were set on the serial device.
  17. @retval RETURN_UNSUPPORTED The serial device does not support this operation.
  18. @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
  19. **/
  20. RETURN_STATUS
  21. EFIAPI
  22. SerialPortSetControl (
  23. IN UINT32 Control
  24. )
  25. {
  26. //
  27. // check for invalid control parameters
  28. //
  29. if ((Control & (~(EFI_SERIAL_REQUEST_TO_SEND |
  30. EFI_SERIAL_DATA_TERMINAL_READY |
  31. EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE |
  32. EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE |
  33. EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE))) != 0 ) {
  34. return EFI_UNSUPPORTED;
  35. }
  36. return EFI_SUCCESS;
  37. }
  38. /**
  39. Retrieve the status of the control bits on a serial device.
  40. @param Control A pointer to return the current control signals from the serial device.
  41. @retval RETURN_SUCCESS The control bits were read from the serial device.
  42. @retval RETURN_UNSUPPORTED The serial device does not support this operation.
  43. @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
  44. **/
  45. RETURN_STATUS
  46. EFIAPI
  47. SerialPortGetControl (
  48. OUT UINT32 *Control
  49. )
  50. {
  51. EFI_STATUS Status;
  52. UINT8 NumberOfBytesInFifoBuffer;
  53. Status = I2cDebugPortReadyToRead (&NumberOfBytesInFifoBuffer);
  54. if (EFI_ERROR (Status)) {
  55. return Status;
  56. }
  57. *Control = (EFI_SERIAL_CLEAR_TO_SEND | EFI_SERIAL_DATA_SET_READY |
  58. EFI_SERIAL_CARRIER_DETECT | EFI_SERIAL_OUTPUT_BUFFER_EMPTY);
  59. if (NumberOfBytesInFifoBuffer <= 0) {
  60. *Control |= EFI_SERIAL_INPUT_BUFFER_EMPTY;
  61. }
  62. return Status;
  63. }
  64. /**
  65. Returns the type of PCH on the system
  66. @retval The PCH type.
  67. **/
  68. PCH_TYPE
  69. GetPchType (
  70. VOID
  71. )
  72. {
  73. return GetPchTypeInternal ();
  74. }
  75. /**
  76. Returns the GPIO pin pair to use for the I2C HDMI debug port
  77. @param[out] DdcBusPinPair - The GPIO pin pair for the I2C HDMI debug port.
  78. @retval EFI_SUCCESS - The GPIO pin pair was successfully determined
  79. @retval EFI_INVALID_PARAMETER - The given DDC I2C channel does not exist.
  80. @retval EFI_UNSUPPORTED - The platform is using a PCH that is not supported yet.
  81. **/
  82. EFI_STATUS
  83. GetGmbusBusPinPairForI2cDebugPort (
  84. OUT UINT8 *DdcBusPinPair
  85. )
  86. {
  87. return GetGmbusBusPinPair ((IGFX_I2C_CHANNEL) FixedPcdGet32 (PcdI2cHdmiDebugPortDdcI2cChannel), DdcBusPinPair);
  88. }
  89. /**
  90. Returns a flag indicating whether the IGD device bus master enable needs to
  91. be disabled at the end of the current transaction
  92. @retval TRUE - IGD Bus Master Enable needs to be reset
  93. @retval FALSE - IGD Bus Master Enable does not need to be reset
  94. **/
  95. BOOLEAN
  96. GetIgdBusMasterReset (
  97. VOID
  98. )
  99. {
  100. return TRUE;
  101. }
  102. /**
  103. Sets a flag indicating whether the IGD device bus master enable needs to
  104. be disabled at the end of the current transaction
  105. @param[in] IgdBusMasterReset - IGD device bus master enable flag
  106. **/
  107. VOID
  108. SetIgdBusMasterReset (
  109. BOOLEAN IgdBusMasterReset
  110. )
  111. {
  112. }