public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Benjamin Doron" <benjamin.doron00@gmail.com>
To: devel@edk2.groups.io
Cc: Chasel Chiu <chasel.chiu@intel.com>,
	Nate DeSimone <nathaniel.l.desimone@intel.com>,
	Michael Kubacki <michael.kubacki@microsoft.com>
Subject: [edk2-platforms][PATCH v2 1/5] KabylakeOpenBoardPkg/BaseEcLib: Add some common EC commands
Date: Fri, 13 Aug 2021 20:24:41 -0400	[thread overview]
Message-ID: <20210814002445.10084-2-benjamin.doron00@gmail.com> (raw)
In-Reply-To: <20210814002445.10084-1-benjamin.doron00@gmail.com>

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: Michael Kubacki <michael.kubacki@microsoft.com>
Signed-off-by: Benjamin Doron <benjamin.doron00@gmail.com>
---
 Platform/Intel/KabylakeOpenBoardPkg/Include/Library/EcLib.h           | 32 +++++++++
 Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/Include/EcCommands.h |  2 +
 Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/BaseEcLib.c     |  4 +-
 Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/BaseEcLib.inf   |  1 +
 Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/EcCommands.c    | 76 ++++++++++++++++++++
 5 files changed, 114 insertions(+), 1 deletion(-)

diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Include/Library/EcLib.h b/Platform/Intel/KabylakeOpenBoardPkg/Include/Library/EcLib.h
index 04ce076f91b7..7c58e592d965 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Include/Library/EcLib.h
+++ b/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
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/Include/EcCommands.h b/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/Include/EcCommands.h
index be56d134edc7..a4ab192d8ce1 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/Include/EcCommands.h
+++ b/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_
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/BaseEcLib.c b/Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/BaseEcLib.c
index eda6f7d2e142..66bd478906fb 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/BaseEcLib.c
+++ b/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
 };
 
 //
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/BaseEcLib.inf b/Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/BaseEcLib.inf
index c7de77d80f3d..f0b4c67fffc2 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/BaseEcLib.inf
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/BaseEcLib.inf
@@ -27,3 +27,4 @@
 
 [Sources]
   BaseEcLib.c
+  EcCommands.c
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/EcCommands.c b/Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/EcCommands.c
new file mode 100644
index 000000000000..d14edb75de36
--- /dev/null
+++ b/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);
+}
-- 
2.31.1


  reply	other threads:[~2021-08-14  0:24 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-04 20:36 [edk2-platforms][PATCH v1 0/4] KabylakeOpenBoardPkg: Add AspireVn7Dash572G Benjamin Doron
2021-08-04 20:36 ` [edk2-platforms][PATCH v1 1/4] KabylakeOpenBoardPkg/AspireVn7Dash572G: Duplicate KabylakeRvp3 directory Benjamin Doron
2021-08-04 20:36 ` [edk2-platforms][PATCH v1 2/4] KabylakeOpenBoardPkg/AspireVn7Dash572G: Rename KabylakeRvp3 files Benjamin Doron
2021-08-04 20:36 ` [edk2-platforms][PATCH v1 3/4] Platform/Intel: Early hook-up Acer Aspire VN7-572G Benjamin Doron
2021-08-04 20:36 ` [edk2-platforms][PATCH v1 4/4] KabylakeOpenBoardPkg/AspireVn7Dash572G: Add initial support Benjamin Doron
2021-08-14  0:24 ` [edk2-platforms][PATCH v2 0/5] KabylakeOpenBoardPkg: Add AspireVn7Dash572G Benjamin Doron
2021-08-14  0:24   ` Benjamin Doron [this message]
2021-08-16  5:32     ` [edk2-devel] [edk2-platforms][PATCH v2 1/5] KabylakeOpenBoardPkg/BaseEcLib: Add some common EC commands Nate DeSimone
2021-08-16 15:50     ` Michael Kubacki
2021-08-14  0:24   ` [edk2-platforms][PATCH v2 2/5] KabylakeOpenBoardPkg/AspireVn7Dash572G: Duplicate KabylakeRvp3 directory Benjamin Doron
2021-08-16  5:32     ` Nate DeSimone
2021-08-16 15:50     ` [edk2-devel] " Michael Kubacki
2021-08-14  0:24   ` [edk2-platforms][PATCH v2 3/5] KabylakeOpenBoardPkg/AspireVn7Dash572G: Rename KabylakeRvp3 files Benjamin Doron
2021-08-16  5:32     ` Nate DeSimone
2021-08-16 15:50     ` [edk2-devel] " Michael Kubacki
2021-08-14  0:24   ` [edk2-platforms][PATCH v2 4/5] Platform/Intel: Early hook-up Acer Aspire VN7-572G Benjamin Doron
2021-08-16  5:32     ` Nate DeSimone
2021-08-16 15:51     ` [edk2-devel] " Michael Kubacki
2021-08-14  0:24   ` [edk2-platforms][PATCH v2 5/5] KabylakeOpenBoardPkg/AspireVn7Dash572G: Add initial support Benjamin Doron
2021-08-16  5:21     ` Nate DeSimone
2021-08-16 15:49       ` [edk2-devel] " Michael Kubacki
2021-08-18 20:17         ` Benjamin Doron
2021-08-16  5:22   ` [edk2-devel] [edk2-platforms][PATCH v2 0/5] KabylakeOpenBoardPkg: Add AspireVn7Dash572G Nate DeSimone
2021-08-18 20:05     ` Benjamin Doron
     [not found]   ` <169BB1F1F47FC595.23238@groups.io>
2021-08-16  5:31     ` Nate DeSimone
2021-08-18 20:31       ` Benjamin Doron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210814002445.10084-2-benjamin.doron00@gmail.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox