From: "Benjamin Doron" <benjamin.doron00@gmail.com>
To: devel@edk2.groups.io
Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>,
Isaac Oram <isaac.w.oram@intel.com>,
Chasel Chiu <chasel.chiu@intel.com>,
Nate DeSimone <nathaniel.l.desimone@intel.com>
Subject: [edk2-devel][edk2-platforms][PATCH v1 4/7] KabylakeOpenBoardPkg/AspireVn7Dash572G/DxeBoardInitLib: Resets notify EC
Date: Tue, 6 Sep 2022 13:42:55 -0400 [thread overview]
Message-ID: <0438eacb8567e8a7b032900e88872445fca791c0.1662485273.git.benjamin.doron00@gmail.com> (raw)
In-Reply-To: <cover.1662485273.git.benjamin.doron00@gmail.com>
Add a callback to notify the EC of platform resets.
Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Signed-off-by: Benjamin Doron <benjamin.doron00@gmail.com>
---
.../Library/BoardInitLib/DxeBoardInitLib.c | 92 ++++++++++++++++++-
.../Library/BoardInitLib/DxeBoardInitLib.inf | 4 +
2 files changed, 91 insertions(+), 5 deletions(-)
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/Library/BoardInitLib/DxeBoardInitLib.c b/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/Library/BoardInitLib/DxeBoardInitLib.c
index 5c5c26d85c58..07278d956ddc 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/Library/BoardInitLib/DxeBoardInitLib.c
+++ b/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/Library/BoardInitLib/DxeBoardInitLib.c
@@ -8,17 +8,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 = NULL;
/**
- Update the EC's clock?
+ Update the EC's clock.
**/
VOID
+EFIAPI
EcSendTime (
VOID
)
@@ -26,11 +31,13 @@ EcSendTime (
EFI_STATUS Status;
EFI_TIME EfiTime;
// Time could be negative (before 2016)
- INTN EcTime;
+ INT32 EcTime;
UINT8 EcTimeByte;
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"));
@@ -56,25 +63,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: More information is needed
+ 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?
+ }
}
/**
@@ -89,7 +143,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;
}
@@ -120,5 +190,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.37.2
next prev parent reply other threads:[~2022-09-06 17:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-06 17:42 [edk2-devel][edk2-platforms][PATCH v1 0/7] Benjamin Doron
2022-09-06 17:42 ` [edk2-devel][edk2-platforms][PATCH v1 1/7] KabylakeOpenBoardPkg/AspireVn7Dash572G: Cleanup library includes Benjamin Doron
2022-09-09 21:41 ` Isaac Oram
2022-09-06 17:42 ` [edk2-devel][edk2-platforms][PATCH v1 2/7] KabylakeOpenBoardPkg/AspireVn7Dash572G: Enhance the build-logic Benjamin Doron
2022-09-06 17:42 ` [edk2-devel][edk2-platforms][PATCH v1 3/7] KabylakeOpenBoardPkg/AspireVn7Dash572G/Acpi: Improvements for EC ACPI Benjamin Doron
2022-09-06 17:42 ` Benjamin Doron [this message]
2022-09-06 17:42 ` [edk2-devel][edk2-platforms][PATCH v1 5/7] KabylakeOpenBoardPkg/AspireVn7Dash572G: Use Setup to control security Benjamin Doron
2022-09-06 17:42 ` [edk2-devel][edk2-platforms][PATCH v1 6/7] KabylakeOpenBoardPkg/AspireVn7Dash572G: Improve board detection Benjamin Doron
2022-09-06 17:42 ` [edk2-devel][edk2-platforms][PATCH v1 7/7] KabylakeOpenBoardPkg/AspireVn7Dash572G: Align DEBUG() use 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=0438eacb8567e8a7b032900e88872445fca791c0.1662485273.git.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