I2CIoLibPei.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /** @file
  2. Functions for access I2C MMIO register.
  3. Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <PiPei.h>
  7. #include <Library/DebugLib.h>
  8. #include <Library/PeiServicesTablePointerLib.h>
  9. /**
  10. Reads an 8-bit MMIO register.
  11. Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
  12. returned. This function must guarantee that all MMIO read and write
  13. operations are serialized.
  14. If 8-bit MMIO register operations are not supported, then ASSERT().
  15. @param Address The MMIO register to read.
  16. @return The value read.
  17. **/
  18. UINT8
  19. EFIAPI
  20. I2CLibPeiMmioRead8 (
  21. IN UINTN Address
  22. )
  23. {
  24. UINT8 Value;
  25. Value = *(volatile UINT8*)Address;
  26. return Value;
  27. }
  28. /**
  29. Reads a 16-bit MMIO register.
  30. Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
  31. returned. This function must guarantee that all MMIO read and write
  32. operations are serialized.
  33. If 16-bit MMIO register operations are not supported, then ASSERT().
  34. If Address is not aligned on a 16-bit boundary, then ASSERT().
  35. @param Address The MMIO register to read.
  36. @return The value read.
  37. **/
  38. UINT16
  39. EFIAPI
  40. I2CLibPeiMmioRead16 (
  41. IN UINTN Address
  42. )
  43. {
  44. UINT16 Value;
  45. ASSERT ((Address & 1) == 0);
  46. Value = *(volatile UINT16*)Address;
  47. return Value;
  48. }
  49. /**
  50. Writes a 16-bit MMIO register.
  51. Writes the 16-bit MMIO register specified by Address with the value specified
  52. by Value and returns Value. This function must guarantee that all MMIO read
  53. and write operations are serialized.
  54. If 16-bit MMIO register operations are not supported, then ASSERT().
  55. If Address is not aligned on a 16-bit boundary, then ASSERT().
  56. @param Address The MMIO register to write.
  57. @param Value The value to write to the MMIO register.
  58. @return Value.
  59. **/
  60. UINT16
  61. EFIAPI
  62. I2CLibPeiMmioWrite16 (
  63. IN UINTN Address,
  64. IN UINT16 Value
  65. )
  66. {
  67. ASSERT ((Address & 1) == 0);
  68. *(volatile UINT16*)Address = Value;
  69. return Value;
  70. }
  71. /**
  72. Reads a 32-bit MMIO register.
  73. Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
  74. returned. This function must guarantee that all MMIO read and write
  75. operations are serialized.
  76. If 32-bit MMIO register operations are not supported, then ASSERT().
  77. If Address is not aligned on a 32-bit boundary, then ASSERT().
  78. @param Address The MMIO register to read.
  79. @return The value read.
  80. **/
  81. UINT32
  82. EFIAPI
  83. I2CLibPeiMmioRead32 (
  84. IN UINTN Address
  85. )
  86. {
  87. UINT32 Value;
  88. ASSERT ((Address & 3) == 0);
  89. Value = *(volatile UINT32*)Address;
  90. return Value;
  91. }
  92. /**
  93. Writes a 32-bit MMIO register.
  94. Writes the 32-bit MMIO register specified by Address with the value specified
  95. by Value and returns Value. This function must guarantee that all MMIO read
  96. and write operations are serialized.
  97. If 32-bit MMIO register operations are not supported, then ASSERT().
  98. If Address is not aligned on a 32-bit boundary, then ASSERT().
  99. @param Address The MMIO register to write.
  100. @param Value The value to write to the MMIO register.
  101. @return Value.
  102. **/
  103. UINT32
  104. EFIAPI
  105. I2CLibPeiMmioWrite32 (
  106. IN UINTN Address,
  107. IN UINT32 Value
  108. )
  109. {
  110. ASSERT ((Address & 3) == 0);
  111. *(volatile UINT32*)Address = Value;
  112. return Value;
  113. }
  114. /**
  115. OR a 32-bit MMIO register.
  116. OR the 32-bit MMIO register specified by Address with the value specified
  117. by Value and returns Value. This function must guarantee that all MMIO read
  118. and write operations are serialized.
  119. If 32-bit MMIO register operations are not supported, then ASSERT().
  120. If Address is not aligned on a 32-bit boundary, then ASSERT().
  121. @param Address The MMIO register to write OR.
  122. @param Value The value to OR to the MMIO register.
  123. @return Value.
  124. **/
  125. UINT32
  126. EFIAPI
  127. I2CLibPeiMmioOr32 (
  128. IN UINTN Address,
  129. IN UINT32 OrData
  130. )
  131. {
  132. return I2CLibPeiMmioWrite32 (Address, I2CLibPeiMmioRead32(Address) | OrData);
  133. }