From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=104.47.36.49; helo=nam02-sn1-obe.outbound.protection.outlook.com; envelope-from=meenakshi.aggarwal@nxp.com; receiver=edk2-devel@lists.01.org Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0049.outbound.protection.outlook.com [104.47.36.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B5C2421A1099E for ; Sun, 26 Nov 2017 20:59:36 -0800 (PST) Received: from CY4PR03CA0099.namprd03.prod.outlook.com (10.171.242.168) by MWHPR03MB2702.namprd03.prod.outlook.com (10.168.207.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.260.4; Mon, 27 Nov 2017 05:03:56 +0000 Received: from BN1AFFO11FD011.protection.gbl (2a01:111:f400:7c10::178) by CY4PR03CA0099.outlook.office365.com (2603:10b6:910:4d::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.260.4 via Frontend Transport; Mon, 27 Nov 2017 05:03:56 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD011.mail.protection.outlook.com (10.58.52.71) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.218.12 via Frontend Transport; Mon, 27 Nov 2017 05:03:56 +0000 Received: from uefi-OptiPlex-790.ap.freescale.net (uefi-OptiPlex-790.ap.freescale.net [10.232.132.78]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id vAR53iMU000785; Sun, 26 Nov 2017 22:03:53 -0700 From: Meenakshi Aggarwal To: , , , Date: Mon, 27 Nov 2017 16:21:50 +0530 Message-ID: <1511779917-9255-3-git-send-email-meenakshi.aggarwal@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1511779917-9255-1-git-send-email-meenakshi.aggarwal@nxp.com> References: <1511779917-9255-1-git-send-email-meenakshi.aggarwal@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131562326361799950; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(336005)(376002)(39860400002)(39380400002)(346002)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(50944005)(106466001)(498600001)(76176999)(15188155005)(16799955002)(189998001)(53936002)(50986999)(33646002)(53376002)(105606002)(4326008)(6306002)(5660300001)(50466002)(2950100002)(48376002)(47776003)(966005)(2201001)(305945005)(2906002)(104016004)(356003)(8656006)(81156014)(81166006)(8936002)(86362001)(36756003)(316002)(97736004)(110136005)(50226002)(68736007)(8676002)(54906003)(16586007)(51416003)(77096006)(85426001)(171213001)(44824005)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR03MB2702; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD011; 1:5Fl9SZ8MzjlucoosPMDxd47xOe7zIffAx7G1rDtcrQDRKeNCHzLPxcVZSjOwTV2Om4hLXxrtX9cKH+HU6P+9RYvX7NvNEocAVqEqbgXSYGpwFeDYJ5RkaQ7fB77qQVaz MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 873ab576-b5e1-4996-7d0e-08d535544315 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(5600026)(4604075)(4534020)(4628075)(201703131517081)(2017052603258); SRVR:MWHPR03MB2702; X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2702; 3:EYEDiRS9HjHRtwxZl5pFjml7pjVrezG4BcnqdT87Q+8b1FRVx/0TDHFhcgnTHgOdw6Kxqutt9CqxyAwENuWvCEH4FNRDIS3wgi6vOkmaddn3ZOFYVnMHPpKkR6fGXOP+fBsFzeaYeSg/K8dCFP/zOmit3d5xW54sBM9gEx3cVmPuhbiTYlOV6mxJxCuh4eFHGvJQrTHrxF6ZQbxe5DK/NNcpcDlvc6uNNgzjtVfxSnOo0uAnFF/RZF9n0i26m1A4KT3if7ZEo/ljrBZyJsOrHps1JWYtYlumlwSx1VtDt+LMVAk78FFX4AOre6suh+BssFOavJz1bTJ1ZzxR0abfFDTbG1qjv8tzzUMZ6cr1PVo=; 25:kDnuk0RXx3INsm1AOvcv0WarWdWLkuodIHTjPyiPzt+5ZVLWNbB9yNFFO9aJLsMI1sYhQmn+7H2B8+Z/DflQtb+jO53b33r3VZdnBfWzI6pTO/EBDIchtnvH7+DZUyUaZ7q57/g/jkqm+oSLdCLQ3kTBes0eIInrMQ/jSOj0L7/X90LDEkLlUO4turSh8HeF8eYPpPkzi9pcm52NHU5cHDhiHUF4piZUOOIJk/LOQufy5bKiI4oJxntJpTGOwO38VtNpuhOk3US0DArOGLV4Hm+8LAEt5H7X9pa3CNkE462a5DMJfajZrDgK7hIGa53K9wxbyrOh7ze0hGravOS2ig== X-MS-TrafficTypeDiagnostic: MWHPR03MB2702: X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2702; 31:jnZBWf9Uu1tIPlromPzDqvoW+Ewcf/1sZQGhmEdt1p2epm4ivG1CyEXkOH1K+BYpdIChOr67eqIJ2NG336iTG02eKaiWLK8/RI/PVImuf4+uxxPUHOUgjQl+QG1WJyx4b6vY9A+19qCJgYeoo2/AQxJy1pPjsTXnnuoBRT0fwlXb0rAb8wsS4p/UIbxBJTTEjRd0+/PYU0LStvnxvMYF11Dol3AEOeKw398cs2xx0qU=; 4:wZC/LdjbMPR7tscrTpfCSGiFcubiGw8NfqOsv503TarOZD8JOfYzbwVbhC19v3Zcxger8D00Qu+XENP6GbhKs4IF4Tc0w7oJza7z7+C8TkUiJWZtUjkoh9dfoG3PxaZ2kMOCu0N9DpnuU8a4+a0mASRE6KSJQeAXeYUgfi9RkZMnCqXfVKIiLA3mgb2duVRpt1e/p7Atki0+a8mM+uqEsWuypJgXiYY5RGzr1j2k02Jw/7qa+vhwtE4CAQwDE49mAJP2B9oqCA6UKnhVC1rxDEaV5bMvzxxRCHrL5z7t6QJsSYulue9UqlOlOvrthSS6 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6095135)(2401047)(8121501046)(5005006)(10201501046)(3002001)(3231022)(93006095)(93001095)(6055026)(6096035)(20161123565025)(201703131430075)(201703131433075)(201703131448075)(201703161259150)(201703151042153)(20161123559100)(20161123556025)(20161123561025)(20161123563025)(201708071742011); SRVR:MWHPR03MB2702; BCL:0; PCL:0; RULEID:(100000803101)(100110400095)(400006); SRVR:MWHPR03MB2702; X-Forefront-PRVS: 0504F29D72 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR03MB2702; 23:COQAiSp5FuYED6ArA5hc2u41kIuFa6aLctvmG2ieg?= =?us-ascii?Q?bRblU+MRxkMit1FPjkO+rH7llvMgnqKcnhfKEdBQEE3D8rqQom2LAbzKVrcx?= =?us-ascii?Q?FcQqvd4a9gO7Pjh/89V5REBzdsafAImvPFH897F1hm7jdbH26Sh73qzYdZfQ?= =?us-ascii?Q?EjHzwo8TYCiL3aMW94zsUDavBa0dNPAcuBaXgeTbn3x6DTdNn3Dn6yI8RcmK?= =?us-ascii?Q?KiRptl7dqHBK3tX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G0vgMxqP6NmQvwag5fe4mC5kzO0MPwOEG2N64pUZWGmy+t28NLUn2EpW5stYf8TU1Fyd5yxJchi2kWrtF7u04pOpvaHN/mqST78zptUoAFwFmDUVQrtfOUs6/7Ggj1L80mIC5BDBT1dD1wfU1IN3QHy SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2017 05:03:56.0083 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 873ab576-b5e1-4996-7d0e-08d535544315 X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR03MB2702 Subject: [PATCH edk2-platforms] [PATCH v3 2/9] Platform/NXP : Add support for Watchdog driver X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Nov 2017 04:59:37 -0000 Content-Type: text/plain Installs watchdog timer arch protocol Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Meenakshi Aggarwal --- Platform/NXP/Drivers/WatchDog/WatchDog.c | 421 ++++++++++++++++++++++++++ Platform/NXP/Drivers/WatchDog/WatchDog.h | 37 +++ Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf | 47 +++ 3 files changed, 505 insertions(+) create mode 100644 Platform/NXP/Drivers/WatchDog/WatchDog.c create mode 100644 Platform/NXP/Drivers/WatchDog/WatchDog.h create mode 100644 Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf diff --git a/Platform/NXP/Drivers/WatchDog/WatchDog.c b/Platform/NXP/Drivers/WatchDog/WatchDog.c new file mode 100644 index 0000000..a9c70ef --- /dev/null +++ b/Platform/NXP/Drivers/WatchDog/WatchDog.c @@ -0,0 +1,421 @@ +/** WatchDog.c +* +* Based on Watchdog driver implemenation available in +* ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805Watchdog.c +* +* Copyright (c) 2011-2013, ARM Limited. All rights reserved. +* Copyright 2017 NXP +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "WatchDog.h" + +STATIC EFI_EVENT EfiExitBootServicesEvent; + +STATIC +UINT16 +EFIAPI +WdogRead ( + IN UINTN Address + ) +{ + if (FixedPcdGetBool (PcdWdogBigEndian)) { + return BeMmioRead16 (Address); + } else { + return MmioRead16(Address); + } +} + +STATIC +UINT16 +EFIAPI +WdogWrite ( + IN UINTN Address, + IN UINT16 Value + ) +{ + if (FixedPcdGetBool (PcdWdogBigEndian)) { + return BeMmioWrite16 (Address, Value); + } else { + return MmioWrite16 (Address, Value); + } +} + +STATIC +UINT16 +EFIAPI +WdogAndThenOr ( + IN UINTN Address, + IN UINT16 And, + IN UINT16 Or + ) +{ + if (FixedPcdGetBool (PcdWdogBigEndian)) { + return BeMmioAndThenOr16 (Address, And, Or); + } else { + return MmioAndThenOr16 (Address, And, Or); + } +} + +STATIC +UINT16 +EFIAPI +WdogOr ( + IN UINTN Address, + IN UINT16 Or + ) +{ + if (FixedPcdGetBool (PcdWdogBigEndian)) { + return BeMmioOr16 (Address, Or); + } else { + return MmioOr16 (Address, Or); + } +} + +STATIC +VOID +WdogPing ( + VOID + ) +{ + // + // To reload a timeout value to the counter the proper service sequence begins by + // writing 0x_5555 followed by 0x_AAAA to the Watchdog Service Register (WDOG_WSR). + // This service sequence will reload the counter with the timeout value WT[7:0] of + // Watchdog Control Register (WDOG_WCR). + // + + WdogWrite (PcdGet64 (PcdWdog1BaseAddr) + WDOG_WSR_OFFSET, + WDOG_SERVICE_SEQ1); + WdogWrite (PcdGet64 (PcdWdog1BaseAddr) + WDOG_WSR_OFFSET, + WDOG_SERVICE_SEQ2); +} + +/** + Stop the Wdog watchdog timer from counting down. +**/ +STATIC +VOID +WdogStop ( + VOID + ) +{ + // Watchdog cannot be disabled by software once started. + // At best, we can keep reload counter with maximum value + + WdogAndThenOr (PcdGet64 (PcdWdog1BaseAddr) + WDOG_WCR_OFFSET, + (UINT16)(~WDOG_WCR_WT), + (WD_COUNT (WT_MAX_TIME) & WD_COUNT_MASK)); + WdogPing (); +} + +/** + Starts the Wdog counting down by feeding Service register with + desired pattern. + The count down will start from the value stored in the Load register, + not from the value where it was previously stopped. +**/ +STATIC +VOID +WdogStart ( + VOID + ) +{ + //Reload the timeout value + WdogPing (); +} + +/** + On exiting boot services we must make sure the Wdog Watchdog Timer + is stopped. +**/ +STATIC +VOID +EFIAPI +ExitBootServicesEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + WdogStop (); +} + +/** + This function registers the handler NotifyFunction so it is called every time + the watchdog timer expires. It also passes the amount of time since the last + handler call to the NotifyFunction. + If NotifyFunction is not NULL and a handler is not already registered, + then the new handler is registered and EFI_SUCCESS is returned. + If NotifyFunction is NULL, and a handler is already registered, + then that handler is unregistered. + If an attempt is made to register a handler when a handler is already registered, + then EFI_ALREADY_STARTED is returned. + If an attempt is made to unregister a handler when a handler is not registered, + then EFI_INVALID_PARAMETER is returned. + + @param This The EFI_TIMER_ARCH_PROTOCOL instance. + @param NotifyFunction The function to call when a timer interrupt fires. This + function executes at TPL_HIGH_LEVEL. The DXE Core will + register a handler for the timer interrupt, so it can know + how much time has passed. This information is used to + signal timer based events. NULL will unregister the handler. + + @retval EFI_SUCCESS The watchdog timer handler was registered. + @retval EFI_ALREADY_STARTED NotifyFunction is not NULL, and a handler is already + registered. + @retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a handler was not + previously registered. + +**/ +STATIC +EFI_STATUS +EFIAPI +WdogRegisterHandler ( + IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This, + IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction + ) +{ + // ERROR: This function is not supported. + // The hardware watchdog will reset the board + return EFI_INVALID_PARAMETER; +} + +/** + + This function adjusts the period of timer interrupts to the value specified + by TimerPeriod. If the timer period is updated, then the selected timer + period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned. If + the timer hardware is not programmable, then EFI_UNSUPPORTED is returned. + If an error occurs while attempting to update the timer period, then the + timer hardware will be put back in its state prior to this call, and + EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the timer interrupt + is disabled. This is not the same as disabling the CPU's interrupts. + Instead, it must either turn off the timer hardware, or it must adjust the + interrupt controller so that a CPU interrupt is not generated when the timer + interrupt fires. + + @param This The EFI_TIMER_ARCH_PROTOCOL instance. + @param TimerPeriod The rate to program the timer interrupt in 100 nS units. If + the timer hardware is not programmable, then EFI_UNSUPPORTED is + returned. If the timer is programmable, then the timer period + will be rounded up to the nearest timer period that is supported + by the timer hardware. If TimerPeriod is set to 0, then the + timer interrupts will be disabled. + + + @retval EFI_SUCCESS The timer period was changed. + @retval EFI_UNSUPPORTED The platform cannot change the period of the timer interrupt. + @retval EFI_DEVICE_ERROR The timer period could not be changed due to a device error. + +**/ +STATIC +EFI_STATUS +EFIAPI +WdogSetTimerPeriod ( + IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This, + IN UINT64 TimerPeriod // In 100ns units + ) +{ + EFI_STATUS Status; + UINT64 TimerPeriodInSec; + UINT16 Val; + + Status = EFI_SUCCESS; + + if (TimerPeriod == 0) { + // This is a watchdog stop request + WdogStop (); + return Status; + } else { + // Convert the TimerPeriod (in 100 ns unit) to an equivalent second value + + TimerPeriodInSec = DivU64x32 (TimerPeriod, NANO_SECOND_BASE); + + // The registers in the Wdog are only 32 bits + if (TimerPeriodInSec > WT_MAX_TIME) { + // We could load the watchdog with the maximum supported value but + // if a smaller value was requested, this could have the watchdog + // triggering before it was intended. + // Better generate an error to let the caller know. + Status = EFI_DEVICE_ERROR; + return Status; + } + + // set the new timeout value in the WCR + // Convert the timeout value from Seconds to timer count + Val = ((WD_COUNT(TimerPeriodInSec) & WD_COUNT_MASK) << 8); + + WdogAndThenOr (PcdGet64 (PcdWdog1BaseAddr) + WDOG_WCR_OFFSET, + (UINT16)(~WDOG_WCR_WT), + Val); + // Start the watchdog + WdogStart (); + } + + return Status; +} + +/** + This function retrieves the period of timer interrupts in 100 ns units, + returns that value in TimerPeriod, and returns EFI_SUCCESS. If TimerPeriod + is NULL, then EFI_INVALID_PARAMETER is returned. If a TimerPeriod of 0 is + returned, then the timer is currently disabled. + + @param This The EFI_TIMER_ARCH_PROTOCOL instance. + @param TimerPeriod A pointer to the timer period to retrieve in 100 ns units. If + 0 is returned, then the timer is currently disabled. + + + @retval EFI_SUCCESS The timer period was returned in TimerPeriod. + @retval EFI_INVALID_PARAMETER TimerPeriod is NULL. + +**/ +STATIC +EFI_STATUS +EFIAPI +WdogGetTimerPeriod ( + IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This, + OUT UINT64 *TimerPeriod + ) +{ + EFI_STATUS Status; + UINT64 ReturnValue; + UINT16 Val; + + Status = EFI_SUCCESS; + + if (TimerPeriod == NULL) { + return EFI_INVALID_PARAMETER; + } + + // Check if the watchdog is stopped + if ((WdogRead (PcdGet64 (PcdWdog1BaseAddr) + WDOG_WCR_OFFSET) + & WDOG_WCR_WDE) == 0 ) { + // It is stopped, so return zero. + ReturnValue = 0; + } else { + // Convert the Watchdog ticks into equivalent TimerPeriod second value. + Val = (WdogRead (PcdGet64 (PcdWdog1BaseAddr) + WDOG_WCR_OFFSET) + & WDOG_WCR_WT ) >> 8; + ReturnValue = WD_SEC(Val); + } + + *TimerPeriod = ReturnValue; + return Status; +} + +/** + Interface structure for the Watchdog Architectural Protocol. + + @par Protocol Description: + This protocol provides a service to set the amount of time to wait + before firing the watchdog timer, and it also provides a service to + register a handler that is invoked when the watchdog timer fires. + + @par When the watchdog timer fires, control will be passed to a handler + if one has been registered. If no handler has been registered, + or the registered handler returns, then the system will be + reset by calling the Runtime Service ResetSystem(). + + @param RegisterHandler + Registers a handler that will be called each time the + watchdogtimer interrupt fires. TimerPeriod defines the minimum + time between timer interrupts, so TimerPeriod will also + be the minimum time between calls to the registered + handler. + NOTE: If the watchdog resets the system in hardware, then + this function will not have any chance of executing. + + @param SetTimerPeriod + Sets the period of the timer interrupt in 100 nS units. + This function is optional, and may return EFI_UNSUPPORTED. + If this function is supported, then the timer period will + be rounded up to the nearest supported timer period. + + @param GetTimerPeriod + Retrieves the period of the timer interrupt in 100 nS units. + +**/ +STATIC +EFI_WATCHDOG_TIMER_ARCH_PROTOCOL gWatchdogTimer = { + WdogRegisterHandler, + WdogSetTimerPeriod, + WdogGetTimerPeriod +}; + +/** + Initialize state information for the Watchdog Timer Architectural Protocol. + + @param ImageHandle of the loaded driver + @param SystemTable Pointer to the System Table + + @retval EFI_SUCCESS Protocol registered + @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure + @retval EFI_DEVICE_ERROR Hardware problems + +**/ +EFI_STATUS +EFIAPI +WdogInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_HANDLE Handle; + + WdogAndThenOr (PcdGet64 (PcdWdog1BaseAddr) + WDOG_WCR_OFFSET, + (UINT16)(~WDOG_WCR_WT), + (WD_COUNT (WT_MAX_TIME) & WD_COUNT_MASK)); + + WdogOr (PcdGet64 (PcdWdog1BaseAddr) + WDOG_WCR_OFFSET, WDOG_WCR_WDE); + + // + // Make sure the Watchdog Timer Architectural Protocol + // has not been installed in the system yet. + // This will avoid conflicts with the universal watchdog + // + ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiWatchdogTimerArchProtocolGuid); + + // Register for an ExitBootServicesEvent + Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, + ExitBootServicesEvent, NULL, &EfiExitBootServicesEvent); + if (EFI_ERROR (Status)) { + Status = EFI_OUT_OF_RESOURCES; + return Status; + } + + // Install the Timer Architectural Protocol onto a new handle + Handle = NULL; + Status = gBS->InstallMultipleProtocolInterfaces ( + &Handle, + &gEfiWatchdogTimerArchProtocolGuid, &gWatchdogTimer, + NULL + ); + if (EFI_ERROR (Status)) { + gBS->CloseEvent (EfiExitBootServicesEvent); + Status = EFI_OUT_OF_RESOURCES; + return Status; + } + + WdogPing (); + + return Status; +} diff --git a/Platform/NXP/Drivers/WatchDog/WatchDog.h b/Platform/NXP/Drivers/WatchDog/WatchDog.h new file mode 100644 index 0000000..1de308b --- /dev/null +++ b/Platform/NXP/Drivers/WatchDog/WatchDog.h @@ -0,0 +1,37 @@ +/** WatchDog.h +* +* Copyright 2017 NXP +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/ + +#ifndef __WATCHDOG_H__ +#define __WATCHDOG_H__ + +#define WDOG_SIZE 0x1000 +#define WDOG_WCR_OFFSET 0 +#define WDOG_WSR_OFFSET 2 +#define WDOG_WRSR_OFFSET 4 +#define WDOG_WICR_OFFSET 6 +#define WDOG_WCR_WT (0xFF << 8) +#define WDOG_WCR_WDE (1 << 2) +#define WDOG_SERVICE_SEQ1 0x5555 +#define WDOG_SERVICE_SEQ2 0xAAAA +#define WDOG_WCR_WDZST 0x1 +#define WDOG_WCR_WRE (1 << 3) /* -> WDOG Reset Enable */ + +#define WT_MAX_TIME 128 +#define WD_COUNT(Sec) (((Sec) * 2 - 1) << 8) +#define WD_COUNT_MASK 0xff00 +#define WD_SEC(Cnt) (((Cnt) + 1) / 2) + +#define NANO_SECOND_BASE 10000000 + +#endif //__WATCHDOG_H__ diff --git a/Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf b/Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf new file mode 100644 index 0000000..63b0816 --- /dev/null +++ b/Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf @@ -0,0 +1,47 @@ +# WatchDog.inf +# +# Component description file for WatchDog module +# +# Copyright 2017 NXP +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# + +[Defines] + INF_VERSION = 0x0001001A + BASE_NAME = WatchDogDxe + FILE_GUID = 0358b544-ec65-4339-89cd-cad60a3dd787 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = WdogInitialize + +[Sources.common] + WatchDog.c + +[Packages] + MdePkg/MdePkg.dec + Platform/NXP/NxpQoriqLs.dec + +[LibraryClasses] + BaseLib + BeIoLib + PcdLib + UefiBootServicesTableLib + UefiDriverEntryPoint + +[Pcd] + gNxpQoriqLsTokenSpaceGuid.PcdWdog1BaseAddr + gNxpQoriqLsTokenSpaceGuid.PcdWdogBigEndian + +[Protocols] + gEfiWatchdogTimerArchProtocolGuid + +[Depex] + TRUE -- 1.9.1