Pārlūkot izejas kodu

KabylakeOpenBoardPkg/BaseEcLib: Add some common EC commands

Add EC read (0x80) and write (0x81) commands, as defined by ACPI.

Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Michael Kubacki <michael.kubacki@microsoft.com>
Signed-off-by: Benjamin Doron <benjamin.doron00@gmail.com>
Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
Reviewed-by: Michael Kubacki <michael.kubacki@microsoft.com>
Benjamin Doron 2 gadi atpakaļ
vecāks
revīzija
4659ef048a

+ 32 - 0
Platform/Intel/KabylakeOpenBoardPkg/Include/Library/EcLib.h

@@ -103,4 +103,36 @@ LpcEcInterface (
   IN OUT UINT8                 *DataBuffer
   );
 
+/**
+  Read a byte of EC RAM.
+
+  @param[in]  Address          Address to read
+  @param[out] Data             Data received
+
+  @retval    EFI_SUCCESS       Command success
+  @retval    EFI_DEVICE_ERROR  Command error
+  @retval    EFI_TIMEOUT       Command timeout
+**/
+EFI_STATUS
+EcRead (
+  IN  UINT8                  Address,
+  OUT UINT8                  *Data
+  );
+
+/**
+  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
+  );
+
 #endif

+ 2 - 0
Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/Include/EcCommands.h

@@ -40,5 +40,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 // Data read from the EC data port is valid only when OBF=1.
 //
 #define EC_C_FAB_ID                    0x0D    // Get the board fab ID in the lower 3 bits
+#define EC_C_ACPI_READ                 0x80    // Read a byte of EC RAM
+#define EC_C_ACPI_WRITE                0x81    // Write a byte of EC RAM
 
 #endif // EC_COMMANDS_H_

+ 3 - 1
Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/BaseEcLib.c

@@ -32,7 +32,9 @@ typedef struct {
 } EC_COMMAND_TABLE;
 
 EC_COMMAND_TABLE mEcCommand[] = {
-  {EC_C_FAB_ID                   , 0, 2, TRUE}   // Get the board fab ID in the lower 3 bits
+  {EC_C_FAB_ID                   , 0, 2, TRUE},  // Get the board fab ID in the lower 3 bits
+  {EC_C_ACPI_READ                , 1, 1, TRUE},  // Read a byte of EC RAM
+  {EC_C_ACPI_WRITE               , 2, 0, TRUE}   // Write a byte of EC RAM
 };
 
 //

+ 1 - 0
Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/BaseEcLib.inf

@@ -27,3 +27,4 @@
 
 [Sources]
   BaseEcLib.c
+  EcCommands.c

+ 76 - 0
Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/EcCommands.c

@@ -0,0 +1,76 @@
+/** @file
+  Common EC commands.
+
+Copyright (c) 2019, 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_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);
+}