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>
Subject: [edk2-platforms][PATCH v2 1/3] KabylakeOpenBoardPkg/AspireVn7Dash572G/DxeBoardInitLib: Resets notify EC
Date: Sun, 12 Sep 2021 00:22:43 -0400 [thread overview]
Message-ID: <20210912042245.9512-1-benjamin.doron00@gmail.com> (raw)
Add a callback to notify the EC of platform resets.
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Signed-off-by: Benjamin Doron <benjamin.doron00@gmail.com>
---
Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/Library/BoardInitLib/DxeBoardInitLib.c | 90 +++++++++++++++++++-
Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/Library/BoardInitLib/DxeBoardInitLib.inf | 4 +
2 files changed, 90 insertions(+), 4 deletions(-)
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/Library/BoardInitLib/DxeBoardInitLib.c b/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/Library/BoardInitLib/DxeBoardInitLib.c
index 4bce51886e3a..eb3ab9acb6bd 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/Library/BoardInitLib/DxeBoardInitLib.c
+++ b/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/Library/BoardInitLib/DxeBoardInitLib.c
@@ -7,17 +7,22 @@
**/
#include <PiDxe.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
+#include <Library/BoardEcLib.h>
#include <Library/BoardInitLib.h>
#include <Library/DebugLib.h>
#include <Library/EcLib.h>
-#include <Library/BoardEcLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+#include <Protocol/ResetNotification.h>
+
+EFI_RESET_NOTIFICATION_PROTOCOL *mResetNotify;
/**
- Update the EC's clock?
+ Update the EC's clock.
**/
VOID
+EFIAPI
EcSendTime (
VOID
)
@@ -30,6 +35,8 @@ EcSendTime (
INTN Index;
UINT8 EcResponse;
+ DEBUG ((DEBUG_INFO, "%a() Starts\n", __FUNCTION__));
+
Status = gRT->GetTime (&EfiTime, NULL);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "Failed to retrieve current time\n"));
@@ -55,25 +62,72 @@ EcSendTime (
if (!EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "EC: response 0x%x\n", EcResponse));
}
+
+ DEBUG ((DEBUG_INFO, "%a() Ends\n", __FUNCTION__));
}
/**
- Configure EC
+ Process an EC time request.
**/
VOID
+EFIAPI
EcRequestsTime (
VOID
)
{
UINT8 Dat;
+ DEBUG ((DEBUG_INFO, "%a() Starts\n", __FUNCTION__));
+
/* This is executed as protocol notify in vendor's RtKbcDriver when *CommonService
* protocol is installed. Effectively, this code could execute from the entrypoint */
EcCmd90Read (0x79, &Dat);
if (Dat & BIT0) {
EcSendTime ();
}
+
+ DEBUG ((DEBUG_INFO, "%a() Ends\n", __FUNCTION__));
+}
+
+/**
+ Notify EC of reset events.
+
+ @param[in] ResetType The type of reset to perform.
+ @param[in] ResetStatus The status code for the reset.
+ @param[in] DataSize The size, in bytes, of ResetData.
+ @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown
+ the data buffer starts with a Null-terminated string, optionally
+ followed by additional binary data. The string is a description
+ that the caller may use to further indicate the reason for the
+ system reset. For a ResetType of EfiResetPlatformSpecific the data
+ buffer also starts with a Null-terminated string that is followed
+ by an EFI_GUID that describes the specific type of reset to
+ perform.
+
+**/
+VOID
+EFIAPI
+EcResetSystemHook (
+ IN EFI_RESET_TYPE ResetType,
+ IN EFI_STATUS ResetStatus,
+ IN UINTN DataSize,
+ IN VOID *ResetData OPTIONAL
+ )
+{
+ // If boolean PCD tokens 0xBD, 0xBE and 0xBF are set in vendor FW,
+ // OEM also sends command 0x5A with argument 0xAA via ACPI "CMDB" method and stalls for
+ // 100000, then sets ResetType to EfiResetShutdown.
+ // PCD token 0xBF may be set in a separate function of DxeOemDriver if
+ // some bits of EC RAM offset 0x5E are set.
+ // TODO: Continue reversing the control flow of this driver
+ if (ResetType == EfiResetShutdown) {
+ EcCmd91Write (0x76, 7); // "ECSS" register
+ // TODO: Write twice, like OEM?
+ EcCmd91Write (0x76, 7); // "ECSS" register
+ // Now OEM calls function offset 2 in ACER_BOOT_DEVICE_SERVICE_PROTOCOL_GUID.
+ // TODO: What does this do?
+ }
}
/**
@@ -88,7 +142,23 @@ BoardInitAfterPciEnumeration (
VOID
)
{
+ EFI_STATUS Status;
+
+ DEBUG ((DEBUG_INFO, "%a() Starts\n", __FUNCTION__));
+
+ // Send EC the present time, if requested
EcRequestsTime ();
+
+ // Add a callback to gRT->ResetSystem() to notify EC, rather than hooking the table,
+ // (as vendor's DxeOemDriver does)
+ Status = gBS->LocateProtocol (&gEfiResetNotificationProtocolGuid, NULL, (VOID **) &mResetNotify);
+ if (!EFI_ERROR (Status)) {
+ Status = mResetNotify->RegisterResetNotify (mResetNotify, EcResetSystemHook);
+ ASSERT_EFI_ERROR (Status);
+ DEBUG ((DEBUG_INFO, "EC: Added callback to notify EC of resets\n"));
+ }
+
+ DEBUG ((DEBUG_INFO, "%a() Ends\n", __FUNCTION__));
return EFI_SUCCESS;
}
@@ -119,5 +189,17 @@ BoardInitEndOfFirmware (
VOID
)
{
+ EFI_STATUS Status;
+
+ DEBUG ((DEBUG_INFO, "%a() Starts\n", __FUNCTION__));
+
+ // Remove ResetSystem callback. ACPI will be notifying EC of events
+ if (mResetNotify != NULL) {
+ Status = mResetNotify->UnregisterResetNotify (mResetNotify, EcResetSystemHook);
+ ASSERT_EFI_ERROR (Status);
+ DEBUG ((DEBUG_INFO, "EC: Removed callback to notify EC of resets\n"));
+ }
+
+ DEBUG ((DEBUG_INFO, "%a() Ends\n", __FUNCTION__));
return EFI_SUCCESS;
}
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/Library/BoardInitLib/DxeBoardInitLib.inf b/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/Library/BoardInitLib/DxeBoardInitLib.inf
index 9a868ee15fb2..24747fa7b224 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/Library/BoardInitLib/DxeBoardInitLib.inf
+++ b/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/Library/BoardInitLib/DxeBoardInitLib.inf
@@ -15,6 +15,7 @@
LIBRARY_CLASS = BoardInitLib
[LibraryClasses]
+ UefiBootServicesTableLib
UefiRuntimeServicesTableLib
DebugLib
EcLib
@@ -27,3 +28,6 @@
[Sources]
DxeBoardInitLib.c
+
+[Protocols]
+ gEfiResetNotificationProtocolGuid ## CONSUMES
--
2.31.1
next reply other threads:[~2021-09-12 4:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-12 4:22 Benjamin Doron [this message]
2021-09-12 4:22 ` [edk2-platforms][PATCH v2 2/3] KabylakeOpenBoardPkg/AspireVn7Dash572G: Use Setup to control security Benjamin Doron
2021-09-12 4:22 ` [edk2-platforms][PATCH v2 3/3] KabylakeOpenBoardPkg/AspireVn7Dash572G: Cleanup library includes 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=20210912042245.9512-1-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