From patchwork Wed Dec 19 20:40:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 154296 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5369567ljp; Wed, 19 Dec 2018 12:40:45 -0800 (PST) X-Google-Smtp-Source: AFSGD/UhW/J9Egp7pFLbJOsVxxvSYNXevGC+y/eHfYxmHsiAG9EbiJHzRyWNyP8827HDdaNKa6eM X-Received: by 2002:a17:902:9887:: with SMTP id s7mr21091367plp.199.1545252045374; Wed, 19 Dec 2018 12:40:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545252045; cv=none; d=google.com; s=arc-20160816; b=V39c/keDNKyO4jgI0GsNrt4gF+rXOm8FjxXHX3h84OnfLK45cqI+aohOWqdR9FnNtE UccJr2gHmsEgQ2RsuzwWPIj7X2lUPUKQx8spGPMr91hhvZBpZTjNCNSBqfEYT1iRbLV7 ZNQzN5WsTMbUR9isEY+ysoN1l9xCkhWeLErHUEeQPPPrd7R2UVwar+4oyOt+uqaOsZCM fIA+IeKXLT3dpY3VSjD9nWGXl1oGlUzPmZbVlK2ypAyMLKAPV2UQVM9UM/KPj2ckg/ux fFv+YZY+cX87nHuUmJEm4Zx5mQ9SzxgW5GU3CMdroN3iC2Jk8w7nXg5EJDmP6xurDRFQ M3rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:delivered-to; bh=Q6Au6FBN/MKbqiazPG1uYMgvTHFRCM/5nGKgQzbMjn8=; b=flFu9qx5pb+ef71/jpZeuEmm3Gcoev9J8KklswSQ2WuVNf9/aMxmJJScLMN6hsObnY ivkIV9B2VSelU1RZi6aYubue/r9ph3KxKJd6eGFqp+hFXN1ulcT4JTCouUumxjolTK8y t7YDbbshUgUIFi2xGYKJTgeKb1E+yNw9ZqXsPUdUW5IbPUpaRMgd/2XOwhidedmXtcgF FEXcczj6/ktleeMUbBLtUKnux8qoe/8HItFKBgJK9MmhjLs18uZA4zrnneuVI8zHlGEZ WEyuRs9MKfNLh3rwYlFQ6mmHrRzIY8kfoqb7iLySkUbYKCAqt+Csa8FBg05955NgTPyU Gs4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=cz6ugjHK; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id h20si16735468pgm.366.2018.12.19.12.40.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 12:40:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=cz6ugjHK; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B64CB211A2D8C; Wed, 19 Dec 2018 12:40:41 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::343; helo=mail-wm1-x343.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) (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 EDF6321BADAB3 for ; Wed, 19 Dec 2018 12:40:39 -0800 (PST) Received: by mail-wm1-x343.google.com with SMTP id b11so7330598wmj.1 for ; Wed, 19 Dec 2018 12:40:39 -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=uSkA3HKHt41PYnSH6aPiT28PCDE0wXohPs+7NqtU9uk=; b=cz6ugjHKD8uVgFxHBrHLoY5W7AvB8Tn3NyWZc2X2cwPbE3fIWXCJ7o9UYIVU8AyzmK tIrvNlb3T9oD8QcuG6ikgTUG50X7DAgmN373h0PpZ29pIsDo7BmpRM9fID5N9qVr9x37 q6ZqQESiIRIRX3Buk8GHfYryf9M8oIl3oZP1A= 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=uSkA3HKHt41PYnSH6aPiT28PCDE0wXohPs+7NqtU9uk=; b=YyyUrbnFltPljSJTx6Gj+izCqH5BMBCsJkUVhYr7xFFLmV5fmyGMp3ZyPSmNDiLDG6 bTXgOpF0uGfmCEkauXxYejhRzJsFlaT/uJdDvWvFnoukw23r7vHVNoSVlz0LHlOPMq2a YMNWUtiuI/h61+d8KevGiRNIoQa7ehUgM6KFLBiUqKV/nIpDXNrDRp6KAEuOqx3hPlM1 dCoBz5Ag8KwqdfIkrTjOaZgIITysfueqCYeClQJV1XixET5ZsaVliyPhIg/sf0M2HWAo v7Be2LuKSuTV/qZuYFo5B9JeGIJ4elbcMV3gE3WKXEnMHl/VvDbFqgNwZm3Fl+DR9Dxg gsRw== X-Gm-Message-State: AA+aEWbtqq6V3P+32ttVU9+oJUENee46VNjGF+lgl4nXIbs0+VsqsAdJ LRi+nGkbF7PlQOk3GTvtlIt2MXiWnTc2Sw== X-Received: by 2002:a1c:c58d:: with SMTP id v135mr7865270wmf.88.1545252037530; Wed, 19 Dec 2018 12:40:37 -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.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 12:40:36 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Wed, 19 Dec 2018 21:40:22 +0100 Message-Id: <20181219204023.6317-4-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: [edk2] [PATCH v2 3/4] ArmPkg/GenericWatchdogDxe: clean up the code 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: , Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Clean up the code, by adding missing STATIC modifiers, drop redundant casts, and get rid of the 'success handling' anti pattern in the entry point code. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm --- ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.inf | 9 +- ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.c | 109 +++++++++++--------- 2 files changed, 62 insertions(+), 56 deletions(-) -- 2.19.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.inf b/ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.inf index ba0403d7fdc3..171bf5b9e183 100644 --- a/ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.inf +++ b/ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.inf @@ -16,17 +16,16 @@ [Defines] FILE_GUID = 0619f5c2-4858-4caa-a86a-73a21a18df6b MODULE_TYPE = DXE_DRIVER VERSION_STRING = 1.0 - ENTRY_POINT = GenericWatchdogEntry [Sources.common] GenericWatchdogDxe.c [Packages] - MdePkg/MdePkg.dec - EmbeddedPkg/EmbeddedPkg.dec ArmPkg/ArmPkg.dec ArmPlatformPkg/ArmPlatformPkg.dec + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec [LibraryClasses] ArmGenericTimerCounterLib @@ -46,8 +45,8 @@ [Pcd.common] gArmTokenSpaceGuid.PcdGenericWatchdogEl2IntrNum [Protocols] - gEfiWatchdogTimerArchProtocolGuid - gHardwareInterrupt2ProtocolGuid + gEfiWatchdogTimerArchProtocolGuid ## ALWAYS_PRODUCES + gHardwareInterrupt2ProtocolGuid ## ALWAYS_CONSUMES [Depex] gHardwareInterrupt2ProtocolGuid diff --git a/ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.c b/ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.c index 8ccf15366dfa..285727fc0e84 100644 --- a/ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.c +++ b/ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.c @@ -34,15 +34,16 @@ #define TIME_UNITS_PER_SECOND 10000000 // Tick frequency of the generic timer basis of the generic watchdog. -UINTN mTimerFrequencyHz = 0; +STATIC UINTN mTimerFrequencyHz = 0; /* In cases where the compare register was set manually, information about how long the watchdog was asked to wait cannot be retrieved from hardware. It is therefore stored here. 0 means the timer is not running. */ -UINT64 mNumTimerTicks = 0; +STATIC UINT64 mNumTimerTicks = 0; -EFI_HARDWARE_INTERRUPT2_PROTOCOL *mInterruptProtocol; +STATIC EFI_HARDWARE_INTERRUPT2_PROTOCOL *mInterruptProtocol; +STATIC VOID WatchdogWriteOffsetRegister ( UINT32 Value @@ -51,6 +52,7 @@ WatchdogWriteOffsetRegister ( MmioWrite32 (GENERIC_WDOG_OFFSET_REG, Value); } +STATIC VOID WatchdogWriteCompareRegister ( UINT64 Value @@ -60,6 +62,7 @@ WatchdogWriteCompareRegister ( MmioWrite32 (GENERIC_WDOG_COMPARE_VALUE_REG_HIGH, (Value >> 32) & MAX_UINT32); } +STATIC VOID WatchdogEnable ( VOID @@ -68,6 +71,7 @@ WatchdogEnable ( MmioWrite32 (GENERIC_WDOG_CONTROL_STATUS_REG, GENERIC_WDOG_ENABLED); } +STATIC VOID WatchdogDisable ( VOID @@ -79,6 +83,7 @@ WatchdogDisable ( /** On exiting boot services we must make sure the Watchdog Timer is stopped. **/ +STATIC VOID EFIAPI WatchdogExitBootServicesEvent ( @@ -93,6 +98,7 @@ WatchdogExitBootServicesEvent ( /* This function is called when the watchdog's first signal (WS0) goes high. It uses the ResetSystem Runtime Service to reset the board. */ +STATIC VOID EFIAPI WatchdogInterruptHandler ( @@ -141,10 +147,11 @@ WatchdogInterruptHandler ( @retval EFI_UNSUPPORTED The code does not support NotifyFunction. **/ +STATIC EFI_STATUS EFIAPI WatchdogRegisterHandler ( - IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This, + IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This, IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction ) { @@ -167,10 +174,11 @@ WatchdogRegisterHandler ( in TimerPeriod 100ns units. **/ +STATIC EFI_STATUS EFIAPI WatchdogSetTimerPeriod ( - IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This, + IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This, IN UINT64 TimerPeriod // In 100ns units ) { @@ -222,10 +230,11 @@ WatchdogSetTimerPeriod ( @retval EFI_INVALID_PARAMETER TimerPeriod is NULL. **/ +STATIC EFI_STATUS EFIAPI WatchdogGetTimerPeriod ( - IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This, + IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This, OUT UINT64 *TimerPeriod ) { @@ -270,13 +279,13 @@ WatchdogGetTimerPeriod ( Retrieves the period of the timer interrupt in 100ns units. **/ -EFI_WATCHDOG_TIMER_ARCH_PROTOCOL gWatchdogTimer = { - (EFI_WATCHDOG_TIMER_REGISTER_HANDLER)WatchdogRegisterHandler, - (EFI_WATCHDOG_TIMER_SET_TIMER_PERIOD)WatchdogSetTimerPeriod, - (EFI_WATCHDOG_TIMER_GET_TIMER_PERIOD)WatchdogGetTimerPeriod +STATIC EFI_WATCHDOG_TIMER_ARCH_PROTOCOL mWatchdogTimer = { + WatchdogRegisterHandler, + WatchdogSetTimerPeriod, + WatchdogGetTimerPeriod }; -EFI_EVENT EfiExitBootServicesEvent = (EFI_EVENT)NULL; +STATIC EFI_EVENT mEfiExitBootServicesEvent; EFI_STATUS EFIAPI @@ -288,6 +297,10 @@ GenericWatchdogEntry ( EFI_STATUS Status; EFI_HANDLE Handle; + Status = gBS->LocateProtocol (&gHardwareInterrupt2ProtocolGuid, NULL, + (VOID **)&mInterruptProtocol); + ASSERT_EFI_ERROR (Status); + /* Make sure the Watchdog Timer Architectural Protocol has not been installed in the system yet. This will avoid conflicts with the universal watchdog */ @@ -296,51 +309,45 @@ GenericWatchdogEntry ( mTimerFrequencyHz = ArmGenericTimerGetTimerFreq (); ASSERT (mTimerFrequencyHz != 0); + // Install interrupt handler + Status = mInterruptProtocol->RegisterInterruptSource (mInterruptProtocol, + FixedPcdGet32 (PcdGenericWatchdogEl2IntrNum), + WatchdogInterruptHandler); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = mInterruptProtocol->SetTriggerType (mInterruptProtocol, + FixedPcdGet32 (PcdGenericWatchdogEl2IntrNum), + EFI_HARDWARE_INTERRUPT2_TRIGGER_EDGE_RISING); + if (EFI_ERROR (Status)) { + goto UnregisterHandler; + } + + // Install the Timer Architectural Protocol onto a new handle + Handle = NULL; + Status = gBS->InstallMultipleProtocolInterfaces (&Handle, + &gEfiWatchdogTimerArchProtocolGuid, &mWatchdogTimer, + NULL); + if (EFI_ERROR (Status)) { + goto UnregisterHandler; + } + // Register for an ExitBootServicesEvent - Status = gBS->CreateEvent ( - EVT_SIGNAL_EXIT_BOOT_SERVICES, - TPL_NOTIFY, - WatchdogExitBootServicesEvent, - NULL, - &EfiExitBootServicesEvent - ); - if (!EFI_ERROR (Status)) { - // Install interrupt handler - Status = gBS->LocateProtocol ( - &gHardwareInterrupt2ProtocolGuid, - NULL, - (VOID **)&mInterruptProtocol - ); - if (!EFI_ERROR (Status)) { - Status = mInterruptProtocol->RegisterInterruptSource ( - mInterruptProtocol, - FixedPcdGet32 (PcdGenericWatchdogEl2IntrNum), - WatchdogInterruptHandler - ); - if (!EFI_ERROR (Status)) { - Status = mInterruptProtocol->SetTriggerType ( - mInterruptProtocol, - FixedPcdGet32 (PcdGenericWatchdogEl2IntrNum), - EFI_HARDWARE_INTERRUPT2_TRIGGER_EDGE_RISING - ); - if (!EFI_ERROR (Status)) { - // Install the Timer Architectural Protocol onto a new handle - Handle = NULL; - Status = gBS->InstallMultipleProtocolInterfaces ( - &Handle, - &gEfiWatchdogTimerArchProtocolGuid, - &gWatchdogTimer, - NULL - ); - } - } - } - } - + Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, + WatchdogExitBootServicesEvent, NULL, + &mEfiExitBootServicesEvent); ASSERT_EFI_ERROR (Status); mNumTimerTicks = 0; WatchdogDisable (); + return EFI_SUCCESS; + +UnregisterHandler: + // Unregister the handler + mInterruptProtocol->RegisterInterruptSource (mInterruptProtocol, + FixedPcdGet32 (PcdGenericWatchdogEl2IntrNum), + NULL); return Status; }