PeiSmbusLib.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /** @file
  2. Implementation of SmBusLib class library for PEI phase.
  3. Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "InternalSmbusLib.h"
  7. /**
  8. Gets Smbus PPIs.
  9. This internal function retrieves Smbus PPI from PPI database.
  10. If gEfiPeiSmbusPpiGuid can not be located, then ASSERT()
  11. @return The pointer to Smbus PPI.
  12. **/
  13. EFI_PEI_SMBUS_PPI *
  14. InternalGetSmbusPpi (
  15. VOID
  16. )
  17. {
  18. EFI_STATUS Status;
  19. EFI_PEI_SMBUS_PPI *SmbusPpi;
  20. Status = PeiServicesLocatePpi (&gEfiPeiSmbusPpiGuid, 0, NULL, (VOID **) &SmbusPpi);
  21. ASSERT_EFI_ERROR (Status);
  22. ASSERT (SmbusPpi != NULL);
  23. return SmbusPpi;
  24. }
  25. /**
  26. Executes an SMBus operation to an SMBus controller.
  27. This function provides a standard way to execute Smbus script
  28. as defined in the SmBus Specification. The data can either be of
  29. the Length byte, word, or a block of data.
  30. @param SmbusOperation Signifies which particular SMBus hardware protocol instance that it will use to
  31. execute the SMBus transactions.
  32. @param SmBusAddress Address that encodes the SMBUS Slave Address,
  33. SMBUS Command, SMBUS Data Length, and PEC.
  34. @param Length Signifies the number of bytes that this operation will do. The maximum number of
  35. bytes can be revision specific and operation specific.
  36. @param Buffer Contains the value of data to execute to the SMBus slave device. Not all operations
  37. require this argument. The length of this buffer is identified by Length.
  38. @param Status Return status for the executed command.
  39. This is an optional parameter and may be NULL.
  40. @return The actual number of bytes that are executed for this operation..
  41. **/
  42. UINTN
  43. InternalSmBusExec (
  44. IN EFI_SMBUS_OPERATION SmbusOperation,
  45. IN UINTN SmBusAddress,
  46. IN UINTN Length,
  47. IN OUT VOID *Buffer,
  48. OUT RETURN_STATUS *Status OPTIONAL
  49. )
  50. {
  51. EFI_PEI_SMBUS_PPI *SmbusPpi;
  52. CONST EFI_PEI_SERVICES **PeiServices;
  53. RETURN_STATUS ReturnStatus;
  54. EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress;
  55. PeiServices = GetPeiServicesTablePointer ();
  56. SmbusPpi = InternalGetSmbusPpi ();
  57. SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress);
  58. ReturnStatus = SmbusPpi->Execute (
  59. (EFI_PEI_SERVICES **) PeiServices,
  60. SmbusPpi,
  61. SmbusDeviceAddress,
  62. SMBUS_LIB_COMMAND (SmBusAddress),
  63. SmbusOperation,
  64. SMBUS_LIB_PEC (SmBusAddress),
  65. &Length,
  66. Buffer
  67. );
  68. if (Status != NULL) {
  69. *Status = ReturnStatus;
  70. }
  71. return Length;
  72. }