DxeUbaGpioPlatformConfigLib.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. /** @file
  2. @copyright
  3. Copyright 2012 - 2017 Intel Corporation. <BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <Base.h>
  7. #include <Uefi.h>
  8. #include <Library/BaseLib.h>
  9. #include <Library/BaseMemoryLib.h>
  10. #include <Library/MemoryAllocationLib.h>
  11. #include <Library/UefiBootServicesTableLib.h>
  12. #include <Library/DebugLib.h>
  13. #include <Protocol/UbaCfgDb.h>
  14. #include <Library/SmmServicesTableLib.h>
  15. #include <Protocol/SmmBase2.h>
  16. #include <Protocol/DynamicSiLibraryProtocol.h>
  17. //
  18. // UBA and GPIO headers
  19. //
  20. #include <Library/UbaGpioPlatformConfig.h>
  21. #include <Library/GpioLib.h>
  22. STATIC PLATFORM_GPIO_CONFIG_TABLE mGpioParams;
  23. DYNAMIC_SI_LIBARY_PROTOCOL *mDynamicSiLibraryProtocol = NULL;
  24. /**
  25. The library constructor call. Gets required protocols and stores for later usage
  26. This also applies for SMM mode usage
  27. @param[in] None
  28. @retval EFI_SUCCESS The function completed successfully
  29. **/
  30. EFI_STATUS
  31. EFIAPI
  32. InitializeDxeUbaPlatLib (
  33. IN EFI_HANDLE ImageHandle,
  34. IN EFI_SYSTEM_TABLE *SystemTable
  35. )
  36. {
  37. EFI_STATUS Status;
  38. UBA_CONFIG_DATABASE_PROTOCOL *UbaConfigProtocol = NULL;
  39. UINTN TableSize;
  40. Status = gBS->LocateProtocol (&gDynamicSiLibraryProtocolGuid, NULL, &mDynamicSiLibraryProtocol);
  41. if (EFI_ERROR (Status)) {
  42. ASSERT_EFI_ERROR (Status);
  43. return EFI_NOT_FOUND;
  44. }
  45. Status = gBS->LocateProtocol (
  46. &gUbaConfigDatabaseProtocolGuid,
  47. NULL,
  48. &UbaConfigProtocol
  49. );
  50. if (EFI_ERROR (Status)) {
  51. return Status;
  52. }
  53. TableSize = sizeof (PLATFORM_GPIO_CONFIG_TABLE);
  54. Status = UbaConfigProtocol->GetData (
  55. UbaConfigProtocol,
  56. &gPlatformGpioPlatformConfigDataGuid,
  57. &mGpioParams,
  58. &TableSize
  59. );
  60. return Status;
  61. }
  62. /**
  63. Reads GPIO pin to get DFX jumper status
  64. @param[out] DfxJumper - The pointer to the DFX jumper input
  65. @retval Status - Success if GPIO's are read properly
  66. **/
  67. EFI_STATUS
  68. GpioGetDfxPadVal (
  69. OUT UINT32 *DfxJumper
  70. )
  71. {
  72. EFI_STATUS Status;
  73. if (mGpioParams.ReservedM == UNUSED_GPIO) {
  74. return EFI_UNSUPPORTED;
  75. }
  76. Status = mDynamicSiLibraryProtocol->GpioGetInputValue (mGpioParams.ReservedM, DfxJumper);
  77. return Status;
  78. }
  79. /**
  80. Reads GPIO pin to get recovery jumper status
  81. @param[out] RcvJumper - The pointer to the Recovery jumper input
  82. @retval Status - Success if GPIO's are read properly
  83. **/
  84. EFI_STATUS
  85. GpioGetRcvPadVal (
  86. OUT UINT32 *RcvJumper
  87. )
  88. {
  89. EFI_STATUS Status;
  90. if (mGpioParams.RcvJumper == UNUSED_GPIO) {
  91. return EFI_UNSUPPORTED;
  92. }
  93. Status = mDynamicSiLibraryProtocol->GpioGetInputValue (mGpioParams.RcvJumper, RcvJumper);
  94. return Status;
  95. }
  96. /**
  97. Reads GPIO pin to get FM ADR trigger pin
  98. @param[out] FmAdrTrigger - The pointer to the ADR trigger input
  99. @retval Status - Success if GPIO's are read properly
  100. **/
  101. EFI_STATUS
  102. GpioGetFmAdrTriggerPadVal (
  103. OUT UINT32 *FmAdrTrigger
  104. )
  105. {
  106. EFI_STATUS Status;
  107. if (mGpioParams.FmAdrTrigger == UNUSED_GPIO) {
  108. return EFI_UNSUPPORTED;
  109. }
  110. Status = mDynamicSiLibraryProtocol->GpioGetInputValue (mGpioParams.FmAdrTrigger, FmAdrTrigger);
  111. return Status;
  112. }
  113. /**
  114. Sets GPIO pin to enable ADR on the board
  115. @param Set[in] - If TRUE means the pas should go 'high', otherwise 'low'
  116. @retval Status - Success if GPIO set properly
  117. **/
  118. EFI_STATUS
  119. GpioSetAdrEnablePadOutVal (
  120. IN BOOLEAN Set
  121. )
  122. {
  123. EFI_STATUS Status;
  124. if (mGpioParams.AdrEnable == UNUSED_GPIO) {
  125. return EFI_UNSUPPORTED;
  126. }
  127. if (Set) {
  128. Status = mDynamicSiLibraryProtocol->GpioSetOutputValue (mGpioParams.AdrEnable, GpioOutHigh);
  129. } else {
  130. Status = mDynamicSiLibraryProtocol->GpioSetOutputValue (mGpioParams.AdrEnable, GpioOutLow);
  131. }
  132. return Status;
  133. }
  134. /**
  135. Reads GPIO pin to Force to S1 config mode pad
  136. @param[out] ForceS1ConfigPad - Input value of the Force S1 Config pad
  137. @retval Status - Success if GPIO's are read properly
  138. **/
  139. EFI_STATUS
  140. GpioGetForcetoS1ConfigModePadVal (
  141. OUT UINT32 *ForceS1ConfigPad
  142. )
  143. {
  144. EFI_STATUS Status;
  145. if (mGpioParams.ForceTo1SConfigModePad == UNUSED_GPIO) {
  146. return EFI_UNSUPPORTED;
  147. }
  148. Status = mDynamicSiLibraryProtocol->GpioGetInputValue (mGpioParams.ForceTo1SConfigModePad, ForceS1ConfigPad);
  149. return Status;
  150. }
  151. /**
  152. Reads GPIO pin related to QAT
  153. @param[out] QATPad - Input value of the QAT pad
  154. @retval Status - Success if GPIO's are read properly
  155. **/
  156. EFI_STATUS
  157. GpioGetQATPadVal (
  158. OUT UINT32 *QATPad
  159. )
  160. {
  161. EFI_STATUS Status;
  162. if (mGpioParams.QATGpio == UNUSED_GPIO) {
  163. return EFI_UNSUPPORTED;
  164. }
  165. Status = mDynamicSiLibraryProtocol->GpioGetInputValue (mGpioParams.QATGpio, QATPad);
  166. return Status;
  167. }
  168. /**
  169. Get GPIO pin for SCI detection for WHEA RAS functionality
  170. @param[out] WheaSciPad - Input value of the Whea SCI pad
  171. @retval Status - Success if GPIO's pad read properly
  172. **/
  173. EFI_STATUS
  174. GpioGetWheaSciPad (
  175. OUT UINT32 *WheaSciPad
  176. )
  177. {
  178. if (mGpioParams.WheaSciPad == UNUSED_GPIO) {
  179. return EFI_UNSUPPORTED;
  180. }
  181. *WheaSciPad = (UINT32) mGpioParams.WheaSciPad;
  182. return EFI_SUCCESS;
  183. }
  184. /**
  185. Get GPIO pin for FPGA error detection RAS functionality
  186. @param[out] FpgaErrorPad -The input value of the FPGA error 1 pad
  187. @retval Status - Success if GPIO's pad read properly
  188. **/
  189. EFI_STATUS
  190. GpioGetFpgaErrorPad1 (
  191. OUT UINT32 *FpgaErrorPad
  192. )
  193. {
  194. if (mGpioParams.FpgaErrorSingnalPad1 == UNUSED_GPIO) {
  195. return EFI_UNSUPPORTED;
  196. }
  197. *FpgaErrorPad = (UINT32) mGpioParams.FpgaErrorSingnalPad1;
  198. return EFI_SUCCESS;
  199. }
  200. /**
  201. Get GPIO pin for FPGA error detection RAS functionality
  202. @param[out] FpgaErrorPad -The input value of the FPGA error 2 pad
  203. @retval Status - Success if GPIO's pad read properly
  204. **/
  205. EFI_STATUS
  206. GpioGetFpgaErrorPad2 (
  207. OUT UINT32 *FpgaErrorPad
  208. )
  209. {
  210. if (mGpioParams.FpgaErrorSingnalPad2 == UNUSED_GPIO) {
  211. return EFI_UNSUPPORTED;
  212. }
  213. *FpgaErrorPad = (UINT32) mGpioParams.FpgaErrorSingnalPad2;
  214. return EFI_SUCCESS;
  215. }
  216. /**
  217. Get GPIO pin for CPU HP SMI detection for RAS functionality
  218. @retval Status - Success if GPIO's pad read properly
  219. **/
  220. EFI_STATUS
  221. GpioGetCpuHpSmiPad (
  222. OUT UINT32 *CpuHpSmiPad
  223. )
  224. {
  225. if (mGpioParams.CpuHpSmiPad == UNUSED_GPIO) {
  226. return EFI_UNSUPPORTED;
  227. }
  228. *CpuHpSmiPad = (UINT32) mGpioParams.CpuHpSmiPad;
  229. return EFI_SUCCESS;
  230. }
  231. /**
  232. Reads GPIO pin that is first bit of the Board ID indication word
  233. @param[out] BoardID0Gpio - Input value of the first Board ID pad
  234. @retval Status - Success if GPIO's are read properly
  235. **/
  236. EFI_STATUS
  237. GpioGetBoardId0PadVal (
  238. OUT UINT32 *BoardID0Gpio
  239. )
  240. {
  241. EFI_STATUS Status;
  242. if (mGpioParams.BoardID0Gpio == UNUSED_GPIO) {
  243. return EFI_UNSUPPORTED;
  244. }
  245. Status = mDynamicSiLibraryProtocol->GpioGetInputValue (mGpioParams.BoardID0Gpio, BoardID0Gpio);
  246. return Status;
  247. }
  248. /**
  249. Sets GPIO's used for Boot Mode
  250. @param None
  251. @retval Status - Success if GPIO's are configured
  252. **/
  253. EFI_STATUS
  254. GpioConfigForMFGMode (
  255. VOID
  256. )
  257. {
  258. EFI_STATUS Status;
  259. if (mGpioParams.GpioMfgPad.GpioPad == UNUSED_GPIO) {
  260. return EFI_UNSUPPORTED;
  261. }
  262. DEBUG ((DEBUG_INFO, "Start ConfigureGpio() for BootMode Detection.\n"));
  263. Status = mDynamicSiLibraryProtocol->GpioSetPadConfig (mGpioParams.GpioMfgPad.GpioPad,
  264. &mGpioParams.GpioMfgPad.GpioConfig);
  265. ASSERT_EFI_ERROR (Status);
  266. DEBUG ((DEBUG_INFO, "End ConfigureGpio() for BootMode Detection.\n"));
  267. return Status;
  268. }
  269. /**
  270. Checks whether the MDF jumper has been set
  271. @param None
  272. @retval ManufacturingMode - TRUE when MFG jumper is on, FALSE otherwise
  273. **/
  274. BOOLEAN
  275. IsManufacturingMode (
  276. VOID
  277. )
  278. {
  279. BOOLEAN ManufacturingMode = TRUE;
  280. EFI_STATUS Status;
  281. UINT32 GpiValue;
  282. if (mGpioParams.GpioMfgPad.GpioPad == UNUSED_GPIO) {
  283. return FALSE;
  284. }
  285. Status = GpioConfigForMFGMode ();
  286. ASSERT_EFI_ERROR (Status);
  287. Status = mDynamicSiLibraryProtocol->GpioGetInputValue (mGpioParams.GpioMfgPad.GpioPad, &GpiValue);
  288. ASSERT_EFI_ERROR (Status);
  289. if (!GpiValue) {
  290. ManufacturingMode = FALSE;
  291. }
  292. return ManufacturingMode;
  293. }