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