From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::541; helo=mail-ed1-x541.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C39FF2194D3B9 for ; Tue, 18 Dec 2018 05:10:24 -0800 (PST) Received: by mail-ed1-x541.google.com with SMTP id p6so13851007eds.0 for ; Tue, 18 Dec 2018 05:10:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MaFR7XwBQn3hF+JpwiiKJbqLzCP1Uis9dfEvQOgw14w=; b=HPQzYmTKsJQBtTvYays883TPh9P4oBCTsJGJS3eYA+sMyga/plh6cA043bfkGNuhnO yXX04KlNwA2WHML82Heo34JV3RRq5IprCg4VPqo4EgZEHdcvtadb66jvA7Hn5nSN3SR5 a91rLepLpwbw4fyreBAiBNRFDpo6bSsO/Ydfg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MaFR7XwBQn3hF+JpwiiKJbqLzCP1Uis9dfEvQOgw14w=; b=kCNRkvzskYC7SDpwCo88+XQ/Q60uJhIQ27UnfgAEEVjLvWbNkp1FC1gujSMRU2Knvi L4zYKktgeRTURMowJMSSEBjGsApW5Hxuy9EE7D0nSAz78df50d9cIXEoHiuQlDrLcaaZ XeTNgfNQZ8x859z2M4NDC+JWZrE+8uH5ib7a5Fn0jLbuzHgMzyRlpxTofNc72Ao2zvqY 6nv/pmedxYNn79wI/1G8tiCHYEUVOVSbYGryyHrk4+F9KiypSS31co8RXUyJpmzexE3Y eCPIVXouVRQOtX9sTeqGziOfx5oOqZBhqz5szu4MlxgLgESFe8+bRA4aBbMDs+goRFcR 0hKw== X-Gm-Message-State: AA+aEWYYNymtGjvhan17jDuFM5mQrGPCZAo1O5Sxyn1iClXQwFL+uSQG hN1u9JqINpBSzsydU7mnf2Douh4C6GrDgK28 X-Google-Smtp-Source: AFSGD/X/dpIMWCm0ajtQTxogGN0/05nTYosZKyAXlzBEI9KDC5qlSfk2HAt6mgVufaa1lCXk+PZ6BQ== X-Received: by 2002:a17:906:8052:: with SMTP id x18-v6mr13315814ejw.131.1545138622977; Tue, 18 Dec 2018 05:10:22 -0800 (PST) Received: from mba13.arnhem.chello.nl (dhcp-077-251-017-237.chello.nl. [77.251.17.237]) by smtp.gmail.com with ESMTPSA id f6sm4384755ede.53.2018.12.18.05.10.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Dec 2018 05:10:22 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Tue, 18 Dec 2018 14:10:14 +0100 Message-Id: <20181218131015.20062-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181218131015.20062-1-ard.biesheuvel@linaro.org> References: <20181218131015.20062-1-ard.biesheuvel@linaro.org> Subject: [PATCH 4/4] ArmPkg/GenericWatchdogDxe: implement RegisterHandler() method X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Dec 2018 13:10:25 -0000 Even though UEFI does not appear to use it, let's implement the complete PI watchdog protocol, including handler registration, which will be invoked instead of the ResetSystem() runtime service when the watchdog timer expires. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.c | 34 ++++++++++++++------ 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.c b/ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.c index 717a180a64ec..21118a3c88d1 100644 --- a/ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.c +++ b/ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.c @@ -42,6 +42,7 @@ STATIC UINTN mTimerFrequencyHz = 0; STATIC UINT64 mNumTimerTicks = 0; STATIC EFI_HARDWARE_INTERRUPT2_PROTOCOL *mInterruptProtocol; +STATIC EFI_WATCHDOG_TIMER_NOTIFY mWatchdogNotify; STATIC VOID @@ -107,17 +108,25 @@ WatchdogInterruptHandler ( ) { STATIC CONST CHAR16 ResetString[]= L"The generic watchdog timer ran out."; + UINT64 TimerPeriod; WatchdogDisable (); mInterruptProtocol->EndOfInterrupt (mInterruptProtocol, Source); - gRT->ResetSystem ( - EfiResetCold, - EFI_TIMEOUT, - StrSize (ResetString), - (VOID *) &ResetString - ); + // + // The notify function should be called with the elapsed number of ticks + // since the watchdog was armed, which should exceed the timer period. + // We don't actually know the elapsed number of ticks, so let's return + // the timer period plus 1. + // + if (mWatchdogNotify != NULL) { + TimerPeriod = ((TIME_UNITS_PER_SECOND / mTimerFrequencyHz) * mNumTimerTicks); + mWatchdogNotify (TimerPeriod + 1); + } else { + gRT->ResetSystem (EfiResetCold, EFI_TIMEOUT, StrSize (ResetString), + (CHAR16 *)ResetString); + } // If we got here then the reset didn't work ASSERT (FALSE); @@ -155,9 +164,16 @@ WatchdogRegisterHandler ( IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction ) { - // ERROR: This function is not supported. - // The watchdog will reset the board - return EFI_UNSUPPORTED; + if (mWatchdogNotify == NULL && NotifyFunction == NULL) { + return EFI_INVALID_PARAMETER; + } + + if (mWatchdogNotify != NULL && NotifyFunction != NULL) { + return EFI_ALREADY_STARTED; + } + + mWatchdogNotify = NotifyFunction; + return EFI_SUCCESS; } /** -- 2.17.1