From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) by mx.groups.io with SMTP id smtpd.web09.2363.1662486190522809487 for ; Tue, 06 Sep 2022 10:43:13 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ckOWzQkp; spf=pass (domain: gmail.com, ip: 209.85.222.179, mailfrom: benjamin.doron00@gmail.com) Received: by mail-qk1-f179.google.com with SMTP id i9so2784075qka.0 for ; Tue, 06 Sep 2022 10:43:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=9Myvv1eH/DXTSxXjdOjU9Of/s/LoNKiRp5T6MTAzdtU=; b=ckOWzQkpiOZe2+E292cIBbSOIxAqJeLPHc6Bxc4Bqv+6RXrgFsah9wsF+bXb3cKBdE rg12g3D001XzAkPgaJ1zRrjGimWLKy4joe9SI7tKKwmauQjlJtq2YS9+giXFjh3wZ4Le yfHUiNFajhwy4tjw9+lR7HvDLlz2wkUj3o8dgAB8taFPm/wp31baqlZzcsDDrbgesO6m d9vzSY99HbWVtP/GWai6WYH5FxaIc+Zs0GRy51VKG+6PHM0mYrI00gCkZ91sYpc3iTOH KFZtN9DqUvyG/2P4jVYhePT/ZlpiOxi3r52qge8yKGvj23SspDlJyLo9U47/OzhwXvAQ KXfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=9Myvv1eH/DXTSxXjdOjU9Of/s/LoNKiRp5T6MTAzdtU=; b=pS+Ia6Ki0zfgYuJ8HttwaO3JXUWN+IZClw9aKNYU2FQ3NfKP5XPRXQ1vFQCyZytHFp 6Y6wQ2ZlSpcPI8P6WK57VWM+xIMZrHOX+8NvPoP3smz+zNgZGrLYDJIbEoXR4n66nWiN tOEtIC499ErurjrgUAnW34uNshgeNkR3ZT/WAAKZ+be5LYIK7xVFUs7MKV6YldVirRK2 qVVhaPWzN2XZX0+Pyz569TAnFv1+c1kT6NiQ0u5DYCHPYLrGakYnbz5XzSoMTY/31l4W 393RuegD/Q+klW87spfBDK1NIAPYtmDOzAqxoD97Fmv72m7NoKL0Yc/O/f6JZZEkqsGc g2cw== X-Gm-Message-State: ACgBeo0gY3RFjJlg9STw8SBJCrm/9LrOYOIfud9dWwuZayuOmKsbFV/d pXXEwaDAwxB1e7dRwJ4GfDRKzOWmEfFmLg== X-Google-Smtp-Source: AA6agR6YehigM1Y+Mtxxzyj5j2ZandHz9guDu78F1ZVtgPpLoxzlRz2mYuPSIGBuLSJnhcZsBtljAg== X-Received: by 2002:ae9:e71a:0:b0:6bb:c3a7:936d with SMTP id m26-20020ae9e71a000000b006bbc3a7936dmr36440838qka.95.1662486192962; Tue, 06 Sep 2022 10:43:12 -0700 (PDT) Return-Path: Received: from aturtleortwo-benjamindomain.. ([2607:f2c0:e98c:e:b132:3785:fa38:a51]) by smtp.gmail.com with ESMTPSA id bi3-20020a05620a318300b006b61b2cb1d2sm11221482qkb.46.2022.09.06.10.43.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 10:43:12 -0700 (PDT) From: "Benjamin Doron" To: devel@edk2.groups.io Cc: Sai Chaganty , Isaac Oram , Chasel Chiu , Nate DeSimone Subject: [edk2-devel][edk2-platforms][PATCH v1 4/7] KabylakeOpenBoardPkg/AspireVn7Dash572G/DxeBoardInitLib: Resets notify EC Date: Tue, 6 Sep 2022 13:42:55 -0400 Message-Id: <0438eacb8567e8a7b032900e88872445fca791c0.1662485273.git.benjamin.doron00@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Add a callback to notify the EC of platform resets. Cc: Sai Chaganty Cc: Isaac Oram Cc: Chasel Chiu Cc: Nate DeSimone Signed-off-by: Benjamin Doron --- .../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/Aspire= Vn7Dash572G/Library/BoardInitLib/DxeBoardInitLib.c index 5c5c26d85c58..07278d956ddc 100644 --- a/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/Library/BoardIn= itLib/DxeBoardInitLib.c +++ b/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/Library/BoardIn= itLib/DxeBoardInitLib.c @@ -8,17 +8,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 =3D NULL;=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 @@ -26,11 +31,13 @@ EcSendTime ( EFI_STATUS Status;=0D EFI_TIME EfiTime;=0D // Time could be negative (before 2016)=0D - INTN EcTime;=0D + INT32 EcTime;=0D UINT8 EcTimeByte;=0D 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 @@ -56,25 +63,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: More information is needed=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 @@ -89,7 +143,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 @@ -120,5 +190,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.37.2