IpmiProtocol.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /** @file
  2. This file provides IPMI Protocol implementation.
  3. Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <PiDxe.h>
  7. #include <Library/DebugLib.h>
  8. #include <Library/BaseMemoryLib.h>
  9. #include <Library/MemoryAllocationLib.h>
  10. #include <Library/ManageabilityTransportLib.h>
  11. #include <Library/ManageabilityTransportIpmiLib.h>
  12. #include <Library/ManageabilityTransportHelperLib.h>
  13. #include <Library/UefiBootServicesTableLib.h>
  14. #include <Protocol/IpmiProtocol.h>
  15. #include "IpmiProtocolCommon.h"
  16. MANAGEABILITY_TRANSPORT_TOKEN *mTransportToken = NULL;
  17. CHAR16 *mTransportName;
  18. MANAGEABILITY_TRANSPORT_HARDWARE_INFORMATION mHardwareInformation;
  19. /**
  20. This service enables submitting commands via Ipmi.
  21. @param[in] This This point for IPMI_PROTOCOL structure.
  22. @param[in] NetFunction Net function of the command.
  23. @param[in] Command IPMI Command.
  24. @param[in] RequestData Command Request Data.
  25. @param[in] RequestDataSize Size of Command Request Data.
  26. @param[out] ResponseData Command Response Data. The completion code is the first byte of response data.
  27. @param[in, out] ResponseDataSize Size of Command Response Data.
  28. @retval EFI_SUCCESS The command byte stream was successfully submit to the device and a response was successfully received.
  29. @retval EFI_NOT_FOUND The command was not successfully sent to the device or a response was not successfully received from the device.
  30. @retval EFI_NOT_READY Ipmi Device is not ready for Ipmi command access.
  31. @retval EFI_DEVICE_ERROR Ipmi Device hardware error.
  32. @retval EFI_TIMEOUT The command time out.
  33. @retval EFI_UNSUPPORTED The command was not successfully sent to the device.
  34. @retval EFI_OUT_OF_RESOURCES The resource allocation is out of resource or data size error.
  35. **/
  36. EFI_STATUS
  37. EFIAPI
  38. DxeIpmiSubmitCommand (
  39. IN IPMI_PROTOCOL *This,
  40. IN UINT8 NetFunction,
  41. IN UINT8 Command,
  42. IN UINT8 *RequestData,
  43. IN UINT32 RequestDataSize,
  44. OUT UINT8 *ResponseData,
  45. IN OUT UINT32 *ResponseDataSize
  46. )
  47. {
  48. EFI_STATUS Status;
  49. Status = CommonIpmiSubmitCommand (
  50. mTransportToken,
  51. NetFunction,
  52. Command,
  53. RequestData,
  54. RequestDataSize,
  55. ResponseData,
  56. ResponseDataSize
  57. );
  58. return Status;
  59. }
  60. static IPMI_PROTOCOL mIpmiProtocol = {
  61. DxeIpmiSubmitCommand
  62. };
  63. /**
  64. The entry point of the Ipmi DXE driver.
  65. @param[in] ImageHandle - Handle of this driver image
  66. @param[in] SystemTable - Table containing standard EFI services
  67. @retval EFI_SUCCESS - IPMI Protocol is installed successfully.
  68. @retval Otherwise - Other errors.
  69. **/
  70. EFI_STATUS
  71. EFIAPI
  72. DxeIpmiEntry (
  73. IN EFI_HANDLE ImageHandle,
  74. IN EFI_SYSTEM_TABLE *SystemTable
  75. )
  76. {
  77. EFI_STATUS Status;
  78. EFI_HANDLE Handle;
  79. MANAGEABILITY_TRANSPORT_CAPABILITY TransportCapability;
  80. MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS TransportAdditionalStatus;
  81. GetTransportCapability (&TransportCapability);
  82. Status = HelperAcquireManageabilityTransport (
  83. &gManageabilityProtocolIpmiGuid,
  84. &mTransportToken
  85. );
  86. if (EFI_ERROR (Status)) {
  87. DEBUG ((DEBUG_ERROR, "%a: Failed to acquire transport interface for IPMI protocol - %r\n", __FUNCTION__, Status));
  88. return Status;
  89. }
  90. mTransportName = HelperManageabilitySpecName (mTransportToken->Transport->ManageabilityTransportSpecification);
  91. DEBUG ((DEBUG_INFO, "%a: IPMI protocol over %s.\n", __FUNCTION__, mTransportName));
  92. //
  93. // Setup hardware information according to the transport interface.
  94. Status = SetupIpmiTransportHardwareInformation (
  95. mTransportToken,
  96. &mHardwareInformation
  97. );
  98. if (EFI_ERROR (Status)) {
  99. if (Status == EFI_UNSUPPORTED) {
  100. DEBUG ((DEBUG_ERROR, "%a: No hardware information of %s transport interface.\n", __FUNCTION__, mTransportName));
  101. }
  102. return Status;
  103. }
  104. //
  105. // Initial transport interface with the hardware information assigned.
  106. Status = HelperInitManageabilityTransport (
  107. mTransportToken,
  108. mHardwareInformation,
  109. &TransportAdditionalStatus
  110. );
  111. if (EFI_ERROR (Status)) {
  112. return Status;
  113. }
  114. Handle = NULL;
  115. Status = gBS->InstallProtocolInterface (
  116. &Handle,
  117. &gIpmiProtocolGuid,
  118. EFI_NATIVE_INTERFACE,
  119. (VOID **)&mIpmiProtocol
  120. );
  121. if (EFI_ERROR (Status)) {
  122. DEBUG ((DEBUG_ERROR, "%a: Failed to install IPMI protocol - %r\n", __FUNCTION__, Status));
  123. }
  124. return Status;
  125. }
  126. /**
  127. This is the unload handler for IPMI protocol module.
  128. Release the MANAGEABILITY_TRANSPORT_TOKEN acquired at entry point.
  129. @param[in] ImageHandle The drivers' driver image.
  130. @retval EFI_SUCCESS The image is unloaded.
  131. @retval Others Failed to unload the image.
  132. **/
  133. EFI_STATUS
  134. EFIAPI
  135. IpmiUnloadImage (
  136. IN EFI_HANDLE ImageHandle
  137. )
  138. {
  139. EFI_STATUS Status;
  140. Status = EFI_SUCCESS;
  141. if (mTransportToken != NULL) {
  142. Status = ReleaseTransportSession (mTransportToken);
  143. }
  144. if (mHardwareInformation.Pointer != NULL) {
  145. FreePool (mHardwareInformation.Pointer);
  146. }
  147. return Status;
  148. }