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::344; helo=mail-wm1-x344.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) (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 C2358211A2D8C for ; Wed, 19 Dec 2018 12:40:40 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id y139so7330777wmc.5 for ; Wed, 19 Dec 2018 12:40:40 -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 :mime-version:content-transfer-encoding; bh=15zem50kbRvhzT/VBjLW0Z4bvtO5RuPdnEB1XBOHkZs=; b=LHf5vKpGaGl5Mn5iS0uzkb0nRaluIFeOKRDxui29EzLGMOsaGXOOKLYot/gE1VP30g 3mPWN+be4CrJOzfHlEdukI4qiOArSxmQbJ00UWHdgdbxNSBOVBjnOurkUTuyxbDWGiey 1bpWEPxpwl/Rv3FPvt/VrSR/LTX0/eOpznIjs= 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:mime-version:content-transfer-encoding; bh=15zem50kbRvhzT/VBjLW0Z4bvtO5RuPdnEB1XBOHkZs=; b=aDjdeHPp/xgQp8Nn94lcKg/TlYAeByOE5Zo+Utw3kuqAxcR2KqeaLsstvBZ6BXAl0a jtPFoNPd1PiDYI+rtAFUCaqB8ODuJe4HxesKM3LM2k3ezVde0DyQOWbd/0PgjjSYry/3 yKhmhIeguUi/8YdAzfV7cLBCtUDD8SJBnnbBR+upXGrMQ5kDZGi9sLkx9RiiA1Pg9ljd zNqtCk/K0JnYCWXiG9yasahRJBxRUXyKueD+bRx7xol8/YUkpd/NLl4YWDYvTRxcJmBl Ww+P0Vo6EbJik6IXUzaPQTxyjU4ilpWE6XbJNlv3IFsIMRocsnI8rxvsBIDxANv4Afyc XrWQ== X-Gm-Message-State: AA+aEWYaiHCkR7CsIYvjlsw6VVE3DX0XH6svuWqXvqIQQPsSepA2Qpq2 xhloXLRE0t5zh7kckK45a07eJrBWLB/vJw== X-Google-Smtp-Source: AFSGD/WuiXsgB/cew11iIbH6YP3v/qpsEmUHed7CluZ4wAHWoQIgAloFSMsM4n/oOHoQiyOcn22HBA== X-Received: by 2002:a1c:760c:: with SMTP id r12mr7601988wmc.127.1545252038957; Wed, 19 Dec 2018 12:40:38 -0800 (PST) Received: from harold.home ([2a01:cb1d:112:6f00:e5c9:6e00:25cb:e32e]) by smtp.gmail.com with ESMTPSA id h16sm13738439wrb.62.2018.12.19.12.40.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 12:40:38 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Wed, 19 Dec 2018 21:40:23 +0100 Message-Id: <20181219204023.6317-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181219204023.6317-1-ard.biesheuvel@linaro.org> References: <20181219204023.6317-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Subject: [PATCH v2 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: Wed, 19 Dec 2018 20:40:41 -0000 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Leif Lindholm --- 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 285727fc0e84..a1ef0363eb39 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); + } + + 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.19.2