From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) by mx.groups.io with SMTP id smtpd.web08.12323.1631420591768715623 for ; Sat, 11 Sep 2021 21:23:11 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=KfqRYp7L; spf=pass (domain: gmail.com, ip: 209.85.222.182, mailfrom: benjamin.doron00@gmail.com) Received: by mail-qk1-f182.google.com with SMTP id t4so6858053qkb.9 for ; Sat, 11 Sep 2021 21:23:11 -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=KfqRYp7La5snm7Fvm6QOQZrWc15OXAMZqr5OHAQevVLp6nchW806kR6wRZrEM1eyID O5Vj24/cm98RO3VI91LvQySCVmNhxFnngIfxAt7kFHDGlTkvtB+7UOW0EvzUA42LkYoE wLr80tHPAaEaiTiXA/qx/Wn37EoIdPc5kiYJ50sWG3durV41DbjoaQinZbupOz2KXUza gi79iEvNcrGwcA+G+Lw3y3f6EgMBh/uoXggAyN+7tvTaZ4dEXDnfiSez+u+xPLydwohO tHGoymSDFWB5xqc10WEQrXVc73kCNdFFJjKBzZySMB8QviBnCxTn+EJtLq2a3GGFcU2w z0CA== 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=w/m4kpUcYoqmf4EEyCP9yZRdAtqF9FU9wBE5EYIygL3Xxf6Gg2OuAAYcTqOUO3tI4c ibJ4+niC1hPygQu16GJoDKlQg5I0566+AFUKwedjOlTXOE4DUhZXG9pPNjGVEZ88P7mj U0gTPHoRNYWQ4jE4ySoK1yn0bSWVTXk9+WVsprvclzyxuO7O6uVrxH+vdR6PqYvXY1sV 93HRGL7Fo3FG+1ZFLQFCEDWn4e25sBoq/Mhfr56VLrplGPUectXFL4zwIAhSOEaRqZLU vOrY/Yajs0hs5e0SJk/vSC57DESeroh97wxtgl2ILVXzZcyI7j90XhteEl4amnAx8znm nY2Q== X-Gm-Message-State: AOAM533Rnb8qlXDIz3lK4XmDmSfeTf0uwvgWFhRuU0p5t+fyWoj41ZAo VK/sIkCAWwk9VEpYR2/CzWBvle01KU4= X-Google-Smtp-Source: ABdhPJzNd91nxwjfUBsZHSouDSdqdvBAw4OFckK5z+9/9Xr/2Tm/51HyCFdGkFGlUs1HZY3q6OwFaA== X-Received: by 2002:ae9:e858:: with SMTP id a85mr4347769qkg.97.1631420590619; Sat, 11 Sep 2021 21:23:10 -0700 (PDT) Return-Path: Received: from benjamind-benjamindomain.. ([2607:f2c0:e98c:24:a84f:66e9:b28b:eae6]) by smtp.gmail.com with ESMTPSA id p187sm2592909qkd.101.2021.09.11.21.23.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Sep 2021 21:23:10 -0700 (PDT) From: "Benjamin Doron" To: devel@edk2.groups.io Cc: Chasel Chiu , Nate DeSimone Subject: [edk2-platforms][PATCH v2 1/3] KabylakeOpenBoardPkg/AspireVn7Dash572G/DxeBoardInitLib: Resets notify EC Date: Sun, 12 Sep 2021 00:22:43 -0400 Message-Id: <20210912042245.9512-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