SmmGenericIpmi.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /** @file
  2. Generic SMM IPMI stack driver
  3. @copyright
  4. Copyright 1999 - 2021 Intel Corporation. <BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. //
  8. // Statements that include other files
  9. //
  10. #include <IndustryStandard/Ipmi.h>
  11. #include <Uefi.h>
  12. #include <Library/BaseLib.h>
  13. #include <Library/SmmLib.h>
  14. #include <Library/DebugLib.h>
  15. #include <Library/BaseMemoryLib.h>
  16. #include <Library/SmmServicesTableLib.h>
  17. #include <Library/MemoryAllocationLib.h>
  18. #include <Library/UefiBootServicesTableLib.h>
  19. #include <Library/IpmiBaseLib.h>
  20. #include <SmStatusCodes.h>
  21. #include "IpmiHooks.h"
  22. #include "IpmiBmcCommon.h"
  23. #include "IpmiBmc.h"
  24. #include <Library/TimerLib.h>
  25. IPMI_BMC_INSTANCE_DATA *mIpmiInstance;
  26. EFI_HANDLE mImageHandle;
  27. EFI_STATUS
  28. GetDeviceId (
  29. IN IPMI_BMC_INSTANCE_DATA *IpmiInstance,
  30. IN EFI_STATUS_CODE_VALUE StatusCodeValue[ ],
  31. IN OUT UINT8 *ErrorCount
  32. )
  33. /*++
  34. Routine Description:
  35. Execute the Get Device ID command to determine whether or not the BMC is in Force Update
  36. Mode. If it is, then report it to the error manager.
  37. Arguments:
  38. IpmiInstance - Data structure describing BMC variables and used for sending commands
  39. StatusCodeValue - An array used to accumulate error codes for later reporting.
  40. ErrorCount - Counter used to keep track of error codes in StatusCodeValue
  41. Returns:
  42. Status
  43. --*/
  44. {
  45. EFI_STATUS Status;
  46. UINT32 DataSize;
  47. SM_CTRL_INFO *ControllerInfo;
  48. UINT8 TimeOut;
  49. UINT8 Retries;
  50. UINT8 TempData[MAX_TEMP_DATA];
  51. TimeOut = 0;
  52. Retries = PcdGet8 (PcdIpmiBmcReadyDelayTimer);
  53. do {
  54. //
  55. // Get the device ID information for the BMC.
  56. //
  57. DataSize = MAX_TEMP_DATA;
  58. Status = IpmiSendCommand (
  59. &IpmiInstance->IpmiTransport,
  60. IPMI_NETFN_APP,
  61. 0,
  62. IPMI_APP_GET_DEVICE_ID,
  63. NULL,
  64. 0,
  65. TempData,
  66. &DataSize
  67. );
  68. if (Status == EFI_SUCCESS) {
  69. DEBUG ((EFI_D_INFO, "IPMI: SendCommand success!\n"));
  70. break;
  71. } else {
  72. //
  73. // Display message and retry.
  74. //
  75. DEBUG (
  76. (EFI_D_ERROR | EFI_D_INFO,
  77. "IPMI: Waiting for BMC (KCS 0x%x)...\n",
  78. IpmiInstance->IpmiIoBase)
  79. );
  80. MicroSecondDelay (500 * 1000);
  81. TimeOut++;
  82. }
  83. } while (TimeOut < Retries);
  84. //
  85. // If there is no error then proceed to check the data returned by the BMC
  86. //
  87. if (!EFI_ERROR (Status)) {
  88. ControllerInfo = (SM_CTRL_INFO *) TempData;
  89. //
  90. // If the controller is in Update Mode and the maximum number of errors has not been exceeded, then
  91. // save the error code to the StatusCode array and increment the counter. Set the BMC Status to indicate
  92. // the BMC is in force update mode.
  93. //
  94. if (ControllerInfo->UpdateMode != 0) {
  95. IpmiInstance->BmcStatus = BMC_UPDATE_IN_PROGRESS;
  96. if (*ErrorCount < MAX_SOFT_COUNT) {
  97. StatusCodeValue[*ErrorCount] = EFI_COMPUTING_UNIT_FIRMWARE_PROCESSOR | CU_FP_EC_FORCE_UPDATE_MODE;
  98. (*ErrorCount)++;
  99. }
  100. }
  101. }
  102. return Status;
  103. }
  104. EFI_STATUS
  105. SmmInitializeIpmiKcsPhysicalLayer (
  106. IN EFI_HANDLE ImageHandle,
  107. IN EFI_SYSTEM_TABLE *SystemTable
  108. )
  109. /*++
  110. Routine Description:
  111. Setup and initialize the BMC for the DXE phase. In order to verify the BMC is functioning
  112. as expected, the BMC Selftest is performed. The results are then checked and any errors are
  113. reported to the error manager. Errors are collected throughout this routine and reported
  114. just prior to installing the driver. If there are more errors than MAX_SOFT_COUNT, then they
  115. will be ignored.
  116. Arguments:
  117. ImageHandle - Handle of this driver image
  118. SystemTable - Table containing standard EFI services
  119. Returns:
  120. EFI_SUCCESS - Successful driver initialization
  121. --*/
  122. {
  123. EFI_STATUS Status;
  124. UINT8 ErrorCount;
  125. EFI_HANDLE Handle;
  126. EFI_STATUS_CODE_VALUE StatusCodeValue[MAX_SOFT_COUNT];
  127. DEBUG ((DEBUG_INFO,"SmmInitializeIpmiKcsPhysicalLayer entry \n"));
  128. ErrorCount = 0;
  129. mImageHandle = ImageHandle;
  130. mIpmiInstance = AllocateZeroPool (sizeof (IPMI_BMC_INSTANCE_DATA));
  131. ASSERT (mIpmiInstance != NULL);
  132. if (mIpmiInstance == NULL) {
  133. DEBUG ((EFI_D_ERROR, "ERROR!! Null Pointer returned by AllocateZeroPool ()\n"));
  134. ASSERT_EFI_ERROR (EFI_OUT_OF_RESOURCES);
  135. return EFI_OUT_OF_RESOURCES;
  136. } else {
  137. //
  138. // Initialize the KCS transaction timeout. Assume delay unit is 1000 us.
  139. //
  140. mIpmiInstance->KcsTimeoutPeriod = (BMC_KCS_TIMEOUT * 1000*1000) / KCS_DELAY_UNIT;
  141. //
  142. // Initialize IPMI IO Base, we still use SMS IO base to get device ID and Seltest result since SMM IF may have different cmds supported
  143. //
  144. mIpmiInstance->IpmiIoBase = PcdGet16 (PcdIpmiSmmIoBaseAddress);
  145. mIpmiInstance->Signature = SM_IPMI_BMC_SIGNATURE;
  146. mIpmiInstance->SlaveAddress = BMC_SLAVE_ADDRESS;
  147. mIpmiInstance->BmcStatus = BMC_NOTREADY;
  148. mIpmiInstance->IpmiTransport.IpmiSubmitCommand = IpmiSendCommand;
  149. mIpmiInstance->IpmiTransport.GetBmcStatus = IpmiGetBmcStatus;
  150. DEBUG ((DEBUG_INFO,"IPMI: Waiting for Getting BMC DID in SMM \n"));
  151. //
  152. // Get the Device ID and check if the system is in Force Update mode.
  153. //
  154. // Just obey the Spec..
  155. // If we want to improve performance, we're going to comment it.
  156. //
  157. Status = GetDeviceId (
  158. mIpmiInstance,
  159. StatusCodeValue,
  160. &ErrorCount
  161. );
  162. ASSERT_EFI_ERROR (Status);
  163. Handle = NULL;
  164. Status = gSmst->SmmInstallProtocolInterface (
  165. &Handle,
  166. &gSmmIpmiTransportProtocolGuid,
  167. EFI_NATIVE_INTERFACE,
  168. &mIpmiInstance->IpmiTransport
  169. );
  170. ASSERT_EFI_ERROR (Status);
  171. DEBUG ((DEBUG_INFO,"SmmInitializeIpmiKcsPhysicalLayer exit \n"));
  172. return EFI_SUCCESS;
  173. }
  174. }
  175. EFI_STATUS
  176. InitializeSmmGenericIpmi (
  177. IN EFI_HANDLE ImageHandle,
  178. IN EFI_SYSTEM_TABLE *SystemTable
  179. )
  180. {
  181. SmmInitializeIpmiKcsPhysicalLayer (ImageHandle, SystemTable);
  182. return EFI_SUCCESS;
  183. }