From nobody Wed Dec 25 13:54:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1510044872328535.4823816384342; Tue, 7 Nov 2017 00:54:32 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id BF8942034D83C; Tue, 7 Nov 2017 00:50:31 -0800 (PST) Received: from NAM02-CY1-obe.outbound.protection.outlook.com (mail-cys01nam02on0083.outbound.protection.outlook.com [104.47.37.83]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 462EC2034D825 for ; Tue, 7 Nov 2017 00:50:30 -0800 (PST) Received: from CY1PR03CA0035.namprd03.prod.outlook.com (10.174.128.45) by CY1PR03MB2363.namprd03.prod.outlook.com (10.166.207.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.197.13; Tue, 7 Nov 2017 08:54:28 +0000 Received: from BY2FFO11FD013.protection.gbl (2a01:111:f400:7c0c::179) by CY1PR03CA0035.outlook.office365.com (2603:10b6:600::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.197.13 via Frontend Transport; Tue, 7 Nov 2017 08:54:28 +0000 Received: from tx30smr01.am.freescale.net (192.88.168.50) by BY2FFO11FD013.mail.protection.outlook.com (10.1.14.75) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.178.5 via Frontend Transport; Tue, 7 Nov 2017 08:54:28 +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 vA78s4Db009319; Tue, 7 Nov 2017 01:54:24 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=104.47.37.83; helo=nam02-cy1-obe.outbound.protection.outlook.com; envelope-from=meenakshi.aggarwal@nxp.com; receiver=edk2-devel@lists.01.org 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; From: Meenakshi Aggarwal To: , , , Date: Tue, 7 Nov 2017 20:12:10 +0530 Message-ID: <1510065736-9394-5-git-send-email-meenakshi.aggarwal@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1510065736-9394-1-git-send-email-meenakshi.aggarwal@nxp.com> References: <1510065736-9394-1-git-send-email-meenakshi.aggarwal@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131545184684466129; (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)(7966004)(336005)(39860400002)(346002)(376002)(39380400002)(2980300002)(1110001)(1109001)(339900001)(199003)(50944005)(189002)(6666003)(48376002)(81166006)(81156014)(15188155005)(47776003)(76176999)(2906002)(105606002)(356003)(50986999)(85426001)(305945005)(53936002)(316002)(68736007)(53376002)(4326008)(8936002)(189998001)(16799955002)(50466002)(8676002)(50226002)(36756003)(2950100002)(104016004)(77096006)(16586007)(6306002)(54906003)(110136005)(86362001)(498600001)(966005)(2201001)(97736004)(5003940100001)(5660300001)(106466001)(8656006)(33646002)(171213001)(44824005)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR03MB2363; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD013; 1:KERFAtQfnvEaYwsTrszVl23IWrnV1xLKoJuwqOl3c3EE2g53pG97/cGd7ZV0dLp6EJiQkg/OEzWX00DFGrdvl4yDBfuYTKEjuewtOY1t/UEYaYo2vPtK+VizTlyHTPId MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: d3d28538-2358-49df-7368-08d525bd2769 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(4534020)(4628075)(201703131517081)(2017052603199); SRVR:CY1PR03MB2363; X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB2363; 3:lqXdk2JLp2EHEFeRk3qPBjrAmhGynIFs+m0k1RESF9pXGqnxDC42p7Q7xysVnI8/bdUKjEk0zseuA9yoOiNKSJy2qulhdocTzfPmwnpUCCcgcfzhGXFnaXz27rrjrH97NAQm0IJd1Vo2wCtoN6PIzHe0cDHoJe/Pn5CZWe69Gst82+tJ/Kads/Td06fE1R/VQYrouonQm2ZdOrTmXX7qJttcFBnGA96Sd36Qk9M+CgC/ArX779Thllr1hOdj79DKsnGmKYQ7+AERTihZlLHM1/U3huLuEDiQ6Ue/XuVrgmOjw2N5V+y3CkiqckyFFq7YrOKRdRa2V0czoQehSsGgFp7wLsL36YoosPOHDnObTx0=; 25:c6fnkUG93CDO0UBUQnguRBigaqEhpVBWY8HkIQ0ALiU7n52IixqqW6/onf83riVdSbKIorseHlzwjkANqgqXW5cF9Y4mteb1u7qW3Ii3cXIEARvRr3H2nTDLZeEp6NcKA3rytwvqHILJG5f3bQ3D1qoiI2OUfwPz2+IEPXBe7gZk26xG/CaH0JT2XEFNaIYlCX05iT9DezGPR4lFILiAY/LvIzprkMjBWKREAxm7tPcFMP8G9VgjmGduHt7G1ri90Utm9ejKO3vOBI504MTSZTQHurZEJECHrksdMGgQxZoBRmkXMs8l4Bzemv/oCXwq+SEKtC6bpb61UDZEVlKgGQ== X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY1PR03MB2363: X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB2363; 31:GP/kpkoOivlAoKsKY4BdhHci4E2LxyG2NxZiLcKW+9s1pjs0mwb22modvBpMAxc9w2rkzW5lj1LJIVwQYYSFHL71NizXmjSZP4/awoyfFqkdpIc4YPu31ukt9sXZGMNS4I2A/whi32gXSmUnKcPzHdCM+oqMEoGE1CHNGi6jPerhz+NttB8petkqS3pBc5PCuKv+rTdUPTNLhpSDMpuTkK2vJ9jzAEPEfSq+rzTo7PI=; 4:l0RuglSRVVeJ30Rsw9gXLJ2PtPWOIXFpD3l0NeZMEZn/yU0oLqz3rFMxLbBbCwR126mNhX06KxT03q/eavA16qeuEQ0EQ/KU3QcQXaWz3pLYfk4dCKVs5ZV9Y43UFGd+YLehwCblAVLn91be8luz+kBcWjmI3SCSJ7//Eos6/ALTdwnG5Oj5jj0S1R3j67aH5buJQ6/IY3mACoi/3PRzCKmoWJusv7qhxfEqUsiDrT1bZw2C4mCyfqS+wGGyewOggZ6n+3G2TfWWc/uHb3V6x583792XHAwSyfGlmQ4hJqPvz8BmNl9vulx/rZj5g0XV X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6095135)(2401047)(5005006)(8121501046)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(3002001)(3231021)(6055026)(6096035)(201703131430075)(201703131441075)(201703131448075)(201703131433075)(201703161259150)(20161123561025)(20161123563025)(20161123559100)(20161123565025)(20161123556025)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:CY1PR03MB2363; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(400006)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:CY1PR03MB2363; X-Forefront-PRVS: 0484063412 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR03MB2363; 23:YZADwLwFOKjCggDR9SvnREGgqw8U2o/czn12WT5I9?= =?us-ascii?Q?AtjSY7C+QJ9iOQ341GAgY6j88FZI8tViJXpWGDFmCYc1G4n4fGc3gRdnO3Vb?= =?us-ascii?Q?bkvSu+k3k/23rs26QbqcwlbSM2krTwgX6mFPvAAtzbRuvFIOs7EGDmzlFSjk?= =?us-ascii?Q?geSuMvfLLVHlKaVG0NApnhrEE0AmaPp4agAHiiUGzih1kVHttJFtmLBxeTTh?= =?us-ascii?Q?co6pBUNoAjpuIIpUWtuBypMHiyHJciWW6WGH0bPVz1QJ7DVgEADpnaX6neoc?= =?us-ascii?Q?2qs/EZvRLJushpELdHR+CpuLSp2i3ZmIlE5xaJJsT+BLWT7YJTqJjsw1s681?= =?us-ascii?Q?dh3vHmQ76YhNVxnCOFc42H/9ofsuz6iKLuiNC8b/1yBE+chDRynCqgUnV3n+?= =?us-ascii?Q?5RVoY9NG6iiwTjpKnjuY1xuTfEads6y4F1mKcEV7kS9v5nzyAAeIgp6C6Igm?= =?us-ascii?Q?tmmfW8zgE645ZT4GZ9NUxwi5R9oGTXhNlMFYhnc94mGq005GEve3+KUbDJ7I?= =?us-ascii?Q?rgWlS/T+KWQGMni1EGAsYyqpPa3N6YouTgEVbGLweMBbta0JTd8MXjZcOAz4?= =?us-ascii?Q?Z5AN1jZPY5YXt80Peb7uGZ9xRytuNNHhs2DLuJeVdpWfE7PfXKzLxlS/khMl?= =?us-ascii?Q?ngVoVWchSy3uNZcRVuIKQdjmydCc5E40v9qcw8+X9DdpvZFPPMy1ll7aYte2?= =?us-ascii?Q?ukr0Nx2irVQ6SXBz8Im7u7CKeA89Q9DL/wv/59sdzZ7XnO+wBABk0G/zSXhV?= =?us-ascii?Q?+McdwOP5eGELszhVk1DU4VuHuK9RQ/WVoWRiPR68/Duqg++sTd1AJFSiI4J4?= =?us-ascii?Q?ZdyggOEbcwROu5KV3iIDvMP8Q1ZpmebpVTqevLq6duMYIiPVEa0nrb/ZUUM8?= =?us-ascii?Q?d24EbLdP3qiWKC9GTESw3ftAWgtq7g5//Q59zdJhOmaKgEWc6eN50Ky3/HvI?= =?us-ascii?Q?b3AZ8gtWdbXKaa1iIrjibspeFofzTrdN+rheCljSCkbG5kdzRACutLiuwROu?= =?us-ascii?Q?MOwROsw/+SJoRoatIKEsJyKMlkyBHHVjjwT/QbcbTvVSimveRB0ZUPVIBnq2?= =?us-ascii?Q?a6OeerQOlVddMUv4km4hfLRK3KwYeDkUXkbAz/JyTUYdTbboAfblW84MfJbf?= =?us-ascii?Q?UYr+O3yqQ3HETrsZhJn4Y0UUNTofqcb84nUrlzuB49SALpjHg5zyEUgwoFTQ?= =?us-ascii?Q?SVy7lih4Rh9SN2WDgwx6REt9k4Ar2LWY/hQLaVRmvftGRXTkG2LL2KszHfCw?= =?us-ascii?Q?jtVhFnoT7WG3S4k8Bpur2ipdLRW/Cvsp/n3k30b3XfHbhvEeJjNNvVeANLHu?= =?us-ascii?Q?S//G6EkN8OGYgO+lL9fVdCdPkSw44gpoWnesX1B5yV6UemHkFJ1fh4jrxiHf?= =?us-ascii?Q?mRw4wE6D7u2OgYSRpKMY1zsXlk=3D?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB2363; 6:ZmIxaB/i/UXqS+gagXaEhz8jv9mbld2N72khg4IXUPqB9J6X3iv5flW7LusjhGSYbMsDlYKdBvNq3sRZGSrtV/j2BVape5nXKrXJjvj6iAWBReIWm4Br6kbQMeyQfwOoULVIiOcxD0N6gXsILmrcRR85IFOTqxbdEJF04iApQlsVW6xadrWjZOx5kURPkyOglzHRKnewhsYDr1d9pXNF+RkcwLjOW/L9UcoBEgGAPVUwMpFLGK3916buAz5xZ9nTF4RO6FdJ96O6MWgRf5nFBgc+KvRSMFIM0Tx+2tY1b/J6De8lb4aqk6BJ0iuXp1b8/a1+lv8D5RXDoEsAQ++mr8fYBgxGRd3ezyGXhoINwu0=; 5:D3QrgJJvBVlk+6iOItMMojmaA6QVhFfGHvzW7dB7s1C6jIFVvUfnloFTxIHWkr7xjo4jIUVWqA3pQ9Sj8aB1jSgm4D0sI3QrjkmHvfgBcvg+cZ9vq59UtNnPU2rxQpFYkTED1YgXXhCdxxS5j2K1gHSI69PkUkt8sr7wmzwvksI=; 24:WK2A3owUS2O41T3b+DijwYNVXy9X9ewfAGoIC1+yqmxibLxKEaUYJ7z2TxtZ8MY/2MoOx4ins3YXkRvx6LBYRUXS9OhTloCWLCKPaaub+A4=; 7:zt/9cqdfZXe/NN1oxmNgHEyLm9MEmSFGpuy9wvgymr9iKcAur9pFBvtn+Je78evCcZXH/9pZ+UIS1rI+NnE5voNI0EZyZpyhXWyGdlTEseo8QaKlTDYjRfSfFIjQeroPDBlsieJYJjZxI7RXITnBTXhCVq4csAffhymyU4jP9y165jJj0ILsxmitAahEwQN3J1/94uMRm0iMJaNIUDFxL6svgFyqeY/vx0sn5M8QP6ekhPnZALg5W7HlGOx5ukuB SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Nov 2017 08:54:28.1190 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d3d28538-2358-49df-7368-08d525bd2769 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: CY1PR03MB2363 Subject: [edk2] [PATCH 04/10] 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: , Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Installs watchdog timer arch protocol Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Meenakshi Aggarwal --- Platform/NXP/Drivers/WatchDog/WatchDog.c | 386 ++++++++++++++++++++++= ++++ Platform/NXP/Drivers/WatchDog/WatchDog.h | 37 +++ Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf | 47 ++++ 3 files changed, 470 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/Driver= s/WatchDog/WatchDog.c new file mode 100644 index 0000000..f257a1d --- /dev/null +++ b/Platform/NXP/Drivers/WatchDog/WatchDog.c @@ -0,0 +1,386 @@ +/** 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 B= SD 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 IM= PLIED. +* +**/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "WatchDog.h" + +EFI_EVENT EfiExitBootServicesEvent =3D (EFI_EVENT)NULL; + +UINT16 +EFIAPI +WdogRead ( + IN UINTN Address + ) +{ + if (FixedPcdGetBool(PcdWdogBigEndian)) { + return BeMmioRead16(Address); + } else { + return MmioRead16(Address); + } +} + +UINT16 +EFIAPI +WdogWrite ( + IN UINTN Address, + IN UINT16 Value + ) +{ + if (FixedPcdGetBool(PcdWdogBigEndian)) { + return BeMmioWrite16(Address, Value); + } else { + return MmioWrite16(Address, Value); + } +} + +STATIC +VOID +WdogPing ( + VOID + ) +{ + 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 pinging the watchdog + 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. +**/ +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 re= gistered, + then EFI_ALREADY_STARTED is returned. + If an attempt is made to unregister a handler when a handler is not regi= stered, + then EFI_INVALID_PARAMETER is returned. + + @param This The EFI_TIMER_ARCH_PROTOCOL instance. + @param NotifyFunction The function to call when a timer interrupt fir= es. This + function executes at TPL_HIGH_LEVEL. The DXE Co= re will + register a handler for the timer interrupt, so = it can know + how much time has passed. This information is u= sed 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. + +**/ +EFI_STATUS +EFIAPI +WdogRegisterHandler ( + IN CONST 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 specif= ied + 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 inter= rupt + 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 t= he + interrupt controller so that a CPU interrupt is not generated when the t= imer + 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 EF= I_UNSUPPORTED is + returned. If the timer is programmable, then th= e 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 t= he timer interrupt. + @retval EFI_DEVICE_ERROR The timer period could not be changed due = to a device error. + +**/ +EFI_STATUS +EFIAPI +WdogSetTimerPeriod ( + IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This, + IN UINT64 TimerPeriod // In 100ns un= its + ) +{ + EFI_STATUS Status; + UINT64 TimerPeriodInSec; + UINT16 Val; + + Status =3D EFI_SUCCESS; + + if (TimerPeriod =3D=3D 0) { + // This is a watchdog stop request + WdogStop(); + goto EXIT; + } else { + // Convert the TimerPeriod (in 100 ns unit) to an equivalent second va= lue + + TimerPeriodInSec =3D 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 =3D EFI_DEVICE_ERROR; + goto EXIT; + } + + // set the new timeout value in the WCR + Val =3D WdogRead(PcdGet64(PcdWdog1BaseAddr) + WDOG_WCR_OFFSET); + Val &=3D ~WDOG_WCR_WT; + // Convert the timeout value from Seconds to timer count + Val |=3D ((WD_COUNT(TimerPeriodInSec) & WD_COUNT_MASK) << 8); + WdogWrite(PcdGet64(PcdWdog1BaseAddr) + WDOG_WCR_OFFSET, Val); + + // Start the watchdog + WdogStart(); + } + + EXIT: + return Status; +} + +/** + This function retrieves the period of timer interrupts in 100 ns units, + returns that value in TimerPeriod, and returns EFI_SUCCESS. If TimerPer= iod + 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 10= 0 ns units. If + 0 is returned, then the timer is currently disa= bled. + + + @retval EFI_SUCCESS The timer period was returned in TimerPeri= od. + @retval EFI_INVALID_PARAMETER TimerPeriod is NULL. + +**/ +EFI_STATUS +EFIAPI +WdogGetTimerPeriod ( + IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This, + OUT UINT64 *TimerPeriod + ) +{ + EFI_STATUS Status; + UINT64 ReturnValue; + UINT16 Val; + + Status =3D EFI_SUCCESS; + + if (TimerPeriod =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // Check if the watchdog is stopped + if ((WdogRead(PcdGet64(PcdWdog1BaseAddr) + WDOG_WCR_OFFSET) + & WDOG_WCR_WDE) =3D=3D 0 ) { + // It is stopped, so return zero. + ReturnValue =3D 0; + } else { + // Convert the Watchdog ticks into equivalent TimerPeriod second value. + Val =3D (WdogRead(PcdGet64(PcdWdog1BaseAddr) + WDOG_WCR_OFFSET) + & WDOG_WCR_WT ) >> 8; + ReturnValue =3D WD_SEC(Val); + } + + *TimerPeriod =3D 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. + +**/ +EFI_WATCHDOG_TIMER_ARCH_PROTOCOL gWatchdogTimer =3D { + (EFI_WATCHDOG_TIMER_REGISTER_HANDLER) WdogRegisterHandler, + (EFI_WATCHDOG_TIMER_SET_TIMER_PERIOD) WdogSetTimerPeriod, + (EFI_WATCHDOG_TIMER_GET_TIMER_PERIOD) WdogGetTimerPeriod +}; + +/** + Initialize state information for the Watchdog Timer Architectural Protoc= ol. + + @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; + UINT16 Val; + + + Val =3D WdogRead(PcdGet64(PcdWdog1BaseAddr) + WDOG_WCR_OFFSET); + + Val &=3D ~WDOG_WCR_WT; + + Val &=3D ~WDOG_WCR_WDE; + + Val |=3D WD_COUNT(WT_MAX_TIME) & WD_COUNT_MASK; + + WdogWrite(PcdGet64(PcdWdog1BaseAddr) + WDOG_WCR_OFFSET, Val); + + Val |=3D 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, &gEfiWatchdogTimerArchProtocolG= uid); + + // Register for an ExitBootServicesEvent + Status =3D gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, + ExitBootServicesEvent, NULL, &EfiExitBootServicesEvent); + if (EFI_ERROR(Status)) { + Status =3D EFI_OUT_OF_RESOURCES; + goto EXIT; + } + + // Install the Timer Architectural Protocol onto a new handle + Handle =3D NULL; + Status =3D gBS->InstallMultipleProtocolInterfaces( + &Handle, + &gEfiWatchdogTimerArchProtocolGuid, &gWatchdogTimer, + NULL + ); + if (EFI_ERROR(Status)) { + Status =3D EFI_OUT_OF_RESOURCES; + goto EXIT; + } + +EXIT: + if(EFI_ERROR(Status)) { + // The watchdog failed to initialize + ASSERT(FALSE); + } + + WdogPing(); + + return Status; +} diff --git a/Platform/NXP/Drivers/WatchDog/WatchDog.h b/Platform/NXP/Driver= s/WatchDog/WatchDog.h new file mode 100644 index 0000000..56ddbde --- /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 B= SD 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 IM= PLIED. +* +**/ + +#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/D= rivers/WatchDog/WatchDogDxe.inf new file mode 100644 index 0000000..4cf7d84 --- /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 B= SD 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 IM= PLIED. +# +# + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D WatchDogDxe + FILE_GUID =3D ebd705fb-fa92-46a7-b32b-7f566d944614 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D WdogInitialize + +[Sources.common] + WatchDog.c + +[Packages] + MdePkg/MdePkg.dec + edk2-platforms/Platform/NXP/NxpQoriqLs.dec + +[LibraryClasses] + BaseLib + BeIoLib + PcdLib + UefiBootServicesTableLib + UefiDriverEntryPoint + +[Pcd] + gNxpQoriqLsTokenSpaceGuid.PcdWdog1BaseAddr + gNxpQoriqLsTokenSpaceGuid.PcdWdogBigEndian + +[Protocols] + gEfiWatchdogTimerArchProtocolGuid + +[Depex] + TRUE --=20 1.9.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel