EcCommands.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /** @file
  2. Common EC commands.
  3. Copyright (c) 2019 - 2021, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <Base.h>
  7. #include <Uefi.h>
  8. #include <Library/EcLib.h>
  9. /**
  10. Read a byte of EC RAM.
  11. @param[in] Address Address to read
  12. @param[out] Data Data received
  13. @retval EFI_SUCCESS Command success
  14. @retval EFI_INVALID_PARAMETER Data is NULL
  15. @retval EFI_DEVICE_ERROR Command error
  16. @retval EFI_TIMEOUT Command timeout
  17. **/
  18. EFI_STATUS
  19. EcRead (
  20. IN UINT8 Address,
  21. OUT UINT8 *Data
  22. )
  23. {
  24. UINT8 DataSize;
  25. UINT8 DataBuffer[1];
  26. EFI_STATUS Status;
  27. if (Data == NULL) {
  28. return EFI_INVALID_PARAMETER;
  29. }
  30. // Prepare arguments for LpcEcInterface()
  31. DataSize = 1;
  32. DataBuffer[0] = Address;
  33. Status = LpcEcInterface (EC_C_ACPI_READ, &DataSize, DataBuffer);
  34. if (EFI_ERROR(Status)) {
  35. return Status;
  36. }
  37. // Write caller's pointer from returned data and return success
  38. *Data = DataBuffer[0];
  39. return EFI_SUCCESS;
  40. }
  41. /**
  42. Write a byte of EC RAM.
  43. @param[in] Address Address to write
  44. @param[in] Data Data to write
  45. @retval EFI_SUCCESS Command success
  46. @retval EFI_DEVICE_ERROR Command error
  47. @retval EFI_TIMEOUT Command timeout
  48. **/
  49. EFI_STATUS
  50. EcWrite (
  51. IN UINT8 Address,
  52. IN UINT8 Data
  53. )
  54. {
  55. UINT8 DataSize;
  56. UINT8 DataBuffer[2];
  57. // Prepare arguments for LpcEcInterface()
  58. DataSize = 2;
  59. DataBuffer[0] = Address;
  60. DataBuffer[1] = Data;
  61. return LpcEcInterface (EC_C_ACPI_WRITE, &DataSize, DataBuffer);
  62. }