From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) by mx.groups.io with SMTP id smtpd.web10.12361.1631419714339972997 for ; Sat, 11 Sep 2021 21:08:34 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dlh66RKH; spf=pass (domain: gmail.com, ip: 209.85.219.46, mailfrom: benjamin.doron00@gmail.com) Received: by mail-qv1-f46.google.com with SMTP id g11so4010838qvd.2 for ; Sat, 11 Sep 2021 21:08:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=9aQJ6/zA4WGlQiZd7qyPMrv/LC0u3eWy4ATJ5Hu9E38=; b=dlh66RKH+2XhLE2dDcissjqaCb30+YrJPLZkphbVrtwYdOldHWGJR2WMwt/RTwGYOs LQD34E4ed8nvn4EhOoIqDKOTVd46V97sulLcM1lbLYJz8GF2r9n6xk8CqYWZ4MjY8xV7 NMCIMnWUgRmKiLhwRKJ0RDXllJhf5KDwMQ22ZGDsoT/m5b0h02nKpH05wrxBzfD1RKe/ mGCyzHGkAmZsD4eSO4OHfgly7V6hbnQ3Aciq8uPnkZ4cGpjU18LhHBMnrQExiO/e2EUS qiKgOVZ8V04TJE3QgaM+Z8UZ0L5p7Z5SCUUTzesAgaP916nwcbK2KPrJDwZDhPsL5sxh TJhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=9aQJ6/zA4WGlQiZd7qyPMrv/LC0u3eWy4ATJ5Hu9E38=; b=dr5dxOh0HDhgQ2UNrL22tu3NXGhxu4FSkkerHcMUL2mYLzn43WydUjqPcbA1x2CyuA cq4VHD2ssQmhiUpBhsBnOuDZudpskgQhxMAHewmeP+lSSEkDSmVPs/kAtFJgCR53E7ZT lC2tdM8akKqgzRa2o2toYN9scL6/N02Pnb6qErohmMmHvpLOz31kbNThmxdS/CzkXeVk GUZT1T1jSBFAp5WUa17QSqyYvkdcdv2k+eO2BlJpz4wZeI2JNzJ/kFxs2DIgLXeeAJvX 5BRGjhWO+X3XNcM7NuFBFzCoxy0mYEiZJj6ox+19lWkf5BxuLPKqdKvZu2xoR+J5ec+A fZrQ== X-Gm-Message-State: AOAM530xH42J8l4qQDil2t0PfCHA7ynpFWyvcAQqES+3X1fGqhuIuUaO /MtI0KGHgrSO4Y7MkVJVd3Ghk1QKyHE= X-Google-Smtp-Source: ABdhPJwb24mdpS0bnehYHIxUXqJGh0BHtCfACuLr8Ls+9YhBliFZKZUeCq89UYN3Wyk57U/181pW2Q== X-Received: by 2002:ad4:5508:: with SMTP id az8mr906162qvb.10.1631419713269; Sat, 11 Sep 2021 21:08:33 -0700 (PDT) Return-Path: Received: from benjamind-benjamindomain.. ([2607:f2c0:e98c:24:a84f:66e9:b28b:eae6]) by smtp.gmail.com with ESMTPSA id n11sm1992145qtx.45.2021.09.11.21.08.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Sep 2021 21:08:33 -0700 (PDT) From: "Benjamin Doron" To: devel@edk2.groups.io Cc: Chasel Chiu , Nate DeSimone Subject: [edk2-platforms][PATCH v1 1/3] KabylakeOpenBoardPkg/AspireVn7Dash572G/DxeBoardInitLib: Resets notify EC Date: Sun, 12 Sep 2021 00:08:04 -0400 Message-Id: <20210912040806.8451-1-benjamin.doron00@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Add a callback to notify the EC of platform resets. Cc: Chasel Chiu Cc: Nate DeSimone Signed-off-by: Benjamin Doron --- 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/Aspire= Vn7Dash572G/Library/BoardInitLib/DxeBoardInitLib.c index 4bce51886e3a..eb3ab9acb6bd 100644 --- a/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/Library/BoardIn= itLib/DxeBoardInitLib.c +++ b/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/Library/BoardIn= itLib/DxeBoardInitLib.c @@ -7,17 +7,22 @@ **/=0D =0D #include =0D -#include =0D +#include =0D #include =0D #include =0D #include =0D -#include =0D +#include =0D +#include =0D +#include =0D +=0D +EFI_RESET_NOTIFICATION_PROTOCOL *mResetNotify;=0D =0D /**=0D - Update the EC's clock?=0D + Update the EC's clock.=0D =0D **/=0D VOID=0D +EFIAPI=0D EcSendTime (=0D VOID=0D )=0D @@ -30,6 +35,8 @@ EcSendTime ( INTN Index;=0D UINT8 EcResponse;=0D =0D + DEBUG ((DEBUG_INFO, "%a() Starts\n", __FUNCTION__));=0D +=0D Status =3D gRT->GetTime (&EfiTime, NULL);=0D if (EFI_ERROR (Status)) {=0D DEBUG ((DEBUG_INFO, "Failed to retrieve current time\n"));=0D @@ -55,25 +62,72 @@ EcSendTime ( if (!EFI_ERROR (Status)) {=0D DEBUG ((DEBUG_INFO, "EC: response 0x%x\n", EcResponse));=0D }=0D +=0D + DEBUG ((DEBUG_INFO, "%a() Ends\n", __FUNCTION__));=0D }=0D =0D /**=0D - Configure EC=0D + Process an EC time request.=0D =0D **/=0D VOID=0D +EFIAPI=0D EcRequestsTime (=0D VOID=0D )=0D {=0D UINT8 Dat;=0D =0D + DEBUG ((DEBUG_INFO, "%a() Starts\n", __FUNCTION__));=0D +=0D /* This is executed as protocol notify in vendor's RtKbcDriver when *Com= monService=0D * protocol is installed. Effectively, this code could execute from the = entrypoint */=0D EcCmd90Read (0x79, &Dat);=0D if (Dat & BIT0) {=0D EcSendTime ();=0D }=0D +=0D + DEBUG ((DEBUG_INFO, "%a() Ends\n", __FUNCTION__));=0D +}=0D +=0D +/**=0D + Notify EC of reset events.=0D +=0D + @param[in] ResetType The type of reset to perform.=0D + @param[in] ResetStatus The status code for the reset.=0D + @param[in] DataSize The size, in bytes, of ResetData.=0D + @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, o= r EfiResetShutdown=0D + the data buffer starts with a Null-terminated st= ring, optionally=0D + followed by additional binary data. The string i= s a description=0D + that the caller may use to further indicate the = reason for the=0D + system reset. For a ResetType of EfiResetPlatfor= mSpecific the data=0D + buffer also starts with a Null-terminated string= that is followed=0D + by an EFI_GUID that describes the specific type = of reset to=0D + perform.=0D +=0D +**/=0D +VOID=0D +EFIAPI=0D +EcResetSystemHook (=0D + IN EFI_RESET_TYPE ResetType,=0D + IN EFI_STATUS ResetStatus,=0D + IN UINTN DataSize,=0D + IN VOID *ResetData OPTIONAL=0D + )=0D +{=0D + // If boolean PCD tokens 0xBD, 0xBE and 0xBF are set in vendor FW,=0D + // OEM also sends command 0x5A with argument 0xAA via ACPI "CMDB" method= and stalls for=0D + // 100000, then sets ResetType to EfiResetShutdown.=0D + // PCD token 0xBF may be set in a separate function of DxeOemDriver if=0D + // some bits of EC RAM offset 0x5E are set.=0D + // TODO: Continue reversing the control flow of this driver=0D + if (ResetType =3D=3D EfiResetShutdown) {=0D + EcCmd91Write (0x76, 7); // "ECSS" register=0D + // TODO: Write twice, like OEM?=0D + EcCmd91Write (0x76, 7); // "ECSS" register=0D + // Now OEM calls function offset 2 in ACER_BOOT_DEVICE_SERVICE_PROTOCO= L_GUID.=0D + // TODO: What does this do?=0D + }=0D }=0D =0D /**=0D @@ -88,7 +142,23 @@ BoardInitAfterPciEnumeration ( VOID=0D )=0D {=0D + EFI_STATUS Status;=0D +=0D + DEBUG ((DEBUG_INFO, "%a() Starts\n", __FUNCTION__));=0D +=0D + // Send EC the present time, if requested=0D EcRequestsTime ();=0D +=0D + // Add a callback to gRT->ResetSystem() to notify EC, rather than hookin= g the table,=0D + // (as vendor's DxeOemDriver does)=0D + Status =3D gBS->LocateProtocol (&gEfiResetNotificationProtocolGuid, NULL= , (VOID **) &mResetNotify);=0D + if (!EFI_ERROR (Status)) {=0D + Status =3D mResetNotify->RegisterResetNotify (mResetNotify, EcResetSys= temHook);=0D + ASSERT_EFI_ERROR (Status);=0D + DEBUG ((DEBUG_INFO, "EC: Added callback to notify EC of resets\n"));=0D + }=0D +=0D + DEBUG ((DEBUG_INFO, "%a() Ends\n", __FUNCTION__));=0D return EFI_SUCCESS;=0D }=0D =0D @@ -119,5 +189,17 @@ BoardInitEndOfFirmware ( VOID=0D )=0D {=0D + EFI_STATUS Status;=0D +=0D + DEBUG ((DEBUG_INFO, "%a() Starts\n", __FUNCTION__));=0D +=0D + // Remove ResetSystem callback. ACPI will be notifying EC of events=0D + if (mResetNotify !=3D NULL) {=0D + Status =3D mResetNotify->UnregisterResetNotify (mResetNotify, EcResetS= ystemHook);=0D + ASSERT_EFI_ERROR (Status);=0D + DEBUG ((DEBUG_INFO, "EC: Removed callback to notify EC of resets\n"));= =0D + }=0D +=0D + DEBUG ((DEBUG_INFO, "%a() Ends\n", __FUNCTION__));=0D return EFI_SUCCESS;=0D }=0D diff --git a/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/Library/= BoardInitLib/DxeBoardInitLib.inf b/Platform/Intel/KabylakeOpenBoardPkg/Aspi= reVn7Dash572G/Library/BoardInitLib/DxeBoardInitLib.inf index 9a868ee15fb2..24747fa7b224 100644 --- a/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/Library/BoardIn= itLib/DxeBoardInitLib.inf +++ b/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/Library/BoardIn= itLib/DxeBoardInitLib.inf @@ -15,6 +15,7 @@ LIBRARY_CLASS =3D BoardInitLib=0D =0D [LibraryClasses]=0D + UefiBootServicesTableLib=0D UefiRuntimeServicesTableLib=0D DebugLib=0D EcLib=0D @@ -27,3 +28,6 @@ =0D [Sources]=0D DxeBoardInitLib.c=0D +=0D +[Protocols]=0D + gEfiResetNotificationProtocolGuid ## CONSUMES=0D --=20 2.31.1