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>,
	Isaac Oram <isaac.w.oram@intel.com>,
	Michael Kubacki <michael.kubacki@microsoft.com>
Subject: [edk2-platforms][PATCH v3 1/7] KabylakeOpenBoardPkg/BaseEcLib: Add some common EC commands
Date: Wed, 18 Aug 2021 14:48:56 -0400	[thread overview]
Message-ID: <20210818184903.7445-2-benjamin.doron00@gmail.com> (raw)
In-Reply-To: <20210818184903.7445-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: Isaac Oram <isaac.w.oram@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-18 18:49 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-18 18:48 [edk2-platforms][PATCH v3 0/7] KabylakeOpenBoardPkg: Add AspireVn7Dash572G Benjamin Doron
2021-08-18 18:48 ` Benjamin Doron [this message]
2021-08-20  0:15   ` [edk2-devel] [edk2-platforms][PATCH v3 1/7] KabylakeOpenBoardPkg/BaseEcLib: Add some common EC commands Michael Kubacki
2021-08-26  3:49   ` Nate DeSimone
2021-08-18 18:48 ` [edk2-platforms][PATCH v3 2/7] KabylakeOpenBoardPkg/AspireVn7Dash572G: Duplicate KabylakeRvp3 directory Benjamin Doron
2021-08-20  0:16   ` [edk2-devel] " Michael Kubacki
2021-08-26  3:50   ` Nate DeSimone
2021-08-18 18:48 ` [edk2-platforms][PATCH v3 3/7] KabylakeOpenBoardPkg/AspireVn7Dash572G: Rename KabylakeRvp3 files Benjamin Doron
2021-08-20  0:16   ` [edk2-devel] " Michael Kubacki
2021-08-26  3:49   ` Nate DeSimone
2021-08-18 18:48 ` [edk2-platforms][PATCH v3 4/7] Platform/Intel: Early hook-up Acer Aspire VN7-572G Benjamin Doron
2021-08-20  0:16   ` [edk2-devel] " Michael Kubacki
2021-08-26  3:49   ` Nate DeSimone
2021-08-18 18:49 ` [edk2-platforms][PATCH v3 5/7] KabylakeOpenBoardPkg/AspireVn7Dash572G: Add initial support Benjamin Doron
2021-08-20  0:17   ` [edk2-devel] " Michael Kubacki
2021-08-26  3:50   ` Nate DeSimone
2021-08-18 18:49 ` [edk2-platforms][PATCH v3 6/7] Maintainers.txt: Add myself as reviewer for AspireVn7Dash572G board Benjamin Doron
2021-08-20  0:18   ` [edk2-devel] " Michael Kubacki
2021-08-26  3:49   ` Nate DeSimone
2021-08-18 18:49 ` [edk2-platforms][PATCH v3 7/7] Platform/Intel/Readme.md: Add AspireVn7Dash572G to supported boards Benjamin Doron
2021-08-20  0:19   ` [edk2-devel] " Michael Kubacki
2021-08-26  3:49   ` Nate DeSimone
2021-08-26  3:53 ` [edk2-devel] [edk2-platforms][PATCH v3 0/7] KabylakeOpenBoardPkg: Add AspireVn7Dash572G Nate DeSimone
2021-08-26  3:58 ` Nate DeSimone
2021-08-26  4:08   ` Benjamin Doron
2021-08-26 21:19     ` Nate DeSimone

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=20210818184903.7445-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