From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Permerror (SPF Permanent Error: Void lookup limit of 2 exceeded) identity=mailfrom; client-ip=2a01:111:f400:fe0e::628; helo=eur04-vi1-obe.outbound.protection.outlook.com; envelope-from=meenakshi.aggarwal@nxp.com; receiver=edk2-devel@lists.01.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on0628.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0e::628]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id AD74B211B76B1 for ; Mon, 28 Jan 2019 21:32:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gneOpIDBFYHJ5V9Xczi13gaXW9JySIJuoUxKJttfXpM=; b=fMx6mzZfEHaqmN4fthmGu8LrxrJQhRny7L74A7o2S/Ru8AG+pbPMxBf7GrLznH+Ib0vh/pmbMep+4QgSRGjRdcnYrx0SUXH1ZxGDvev+BsB+xLtFv/hwcujKeQlpjkunh+CHaX4sVibPgXlRAaA6QsHn/N+XtvCbgI/qQQSZ+Zk= Received: from VI1PR04MB4685.eurprd04.prod.outlook.com (20.177.56.77) by VI1PR04MB5055.eurprd04.prod.outlook.com (20.177.50.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1558.17; Tue, 29 Jan 2019 05:32:14 +0000 Received: from VI1PR04MB4685.eurprd04.prod.outlook.com ([fe80::f14a:c19b:b324:7d63]) by VI1PR04MB4685.eurprd04.prod.outlook.com ([fe80::f14a:c19b:b324:7d63%4]) with mapi id 15.20.1580.016; Tue, 29 Jan 2019 05:32:14 +0000 From: Meenakshi Aggarwal To: Leif Lindholm CC: "ard.biesheuvel@linaro.org" , "michael.d.kinney@intel.com" , "edk2-devel@lists.01.org" , Udit Kumar , Varun Sethi Thread-Topic: [PATCH edk2-platforms 02/41] Silicon/NXP : Add support for Watchdog driver Thread-Index: AQHUhvr3Dro7qi00WEuYFRvq/tmt2aWDUAkAgELCVKA= Date: Tue, 29 Jan 2019 05:32:14 +0000 Message-ID: References: <1518771035-6733-1-git-send-email-meenakshi.aggarwal@nxp.com> <1543417315-5763-1-git-send-email-meenakshi.aggarwal@nxp.com> <1543417315-5763-3-git-send-email-meenakshi.aggarwal@nxp.com> <20181217173610.j2mlku52bnbnxqex@bivouac.eciton.net> In-Reply-To: <20181217173610.j2mlku52bnbnxqex@bivouac.eciton.net> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=meenakshi.aggarwal@nxp.com; x-originating-ip: [92.120.0.3] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; VI1PR04MB5055; 6:sF+TNS3so5VFqHb3Rrsp1Gu4AFFI5v6cKv1neX+2hUARWR0zhBu18I0+GQ+Yfre3FhCLBVaN8i5a08Lro4RVd73OFpPR6Ke+1iZuuEbwonTWMCwuG6d1MO28ffWas1bSJYSH1YPz6FL9TODqEdwZsLJrkQIlS3cpY33J0Gj6TVsMEPySqGSyVurH/sE3kQFtVZsFxCP0IXGNgBTERwaoaFHUWF2bwODljd7ABVPZ7iWCwcUhsLjfa4tCSGiSbrGiPVSJR9jL/v33wkSjAfQCnQKK9cI7D6VyjUTPnR0SuISVgumtDVzd7SPk+xdL9sYWIoc4E2Ki+H8PblnU4hhglcvBGta2irpmAZ2TXNlbmsMRld/NVkQ8XfHKihBAuKPoFTLbVanKY6lmI8dRVfa+2KjH8XniWp3KkSAuIAm6kbdW0209eVOcUnZTRSydyJDHAfERt2LAkgHbd3NYQ+GR0g==; 5:vg9JGwHQEZJtQ7eTA4AY1tQTn47jaMRk5AQ4jHIwZZ7RFYLi0Ljw8IrV6NinZa264CbDNYcX+Kq5/EI+yRvFidsCwg2Xsqe+Id84OB35JR50cRbNdMkKt3h31v8DQHL5BsLJaXwPPrW1kqq+Yv5jPRNd84sZiUJ7v6E3hXnByCaoT9X+1wNT3VTQ1j00SZt4nrYruR3DEuNm+GcJTP7tBA==; 7:NARt6HEv0Gfg+qz5dtdmXhnMoJu6qsbzXGJi95q4/ow07Cfc/yL+nNSPrPir3iRb8bWAU4qb7G0afNACLGG15vMxCPlCmTU6kfymG/fthw1rqc3YYhE8GgsnOQhYS8vCUiG0wyA2wXLkaWH7NdleOQ== x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: 392e9d47-e5b0-4101-cc27-08d685ab2014 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600110)(711020)(4605077)(4618075)(2017052603328)(7153060)(7193020); SRVR:VI1PR04MB5055; x-ms-traffictypediagnostic: VI1PR04MB5055: x-microsoft-antispam-prvs: x-forefront-prvs: 093290AD39 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(346002)(396003)(376002)(136003)(39860400002)(366004)(13464003)(189003)(199004)(2906002)(966005)(93886005)(74316002)(229853002)(256004)(19627235002)(11346002)(68736007)(14454004)(186003)(97736004)(26005)(25786009)(6246003)(14444005)(446003)(476003)(30864003)(86362001)(6436002)(4326008)(44832011)(7736002)(316002)(76176011)(53546011)(486006)(53946003)(71200400001)(106356001)(102836004)(9686003)(6116002)(71190400001)(305945005)(8936002)(6306002)(16799955002)(6506007)(478600001)(81166006)(81156014)(8676002)(33656002)(54906003)(99286004)(45080400002)(66066001)(105586002)(3846002)(55016002)(7696005)(6916009)(53936002)(171213001)(579004)(44824005); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR04MB5055; H:VI1PR04MB4685.eurprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: M7bRBqX9E1L2EH8MSfp6Tde+5sAwCTPfLXv+URweppgX/WKS/s2aPlgFlaAkGCRCVeFX+nKTZwd0wQio9est+X8J5rafp7YR3EaBSHzG74li6ORnCwA4+XpFyaB5INZ5rHGSGSw1cAxMBbOGNbkCHFtIOpBRB3s628ChR+Y1+aZEk5mtfosPwspO8k6x0J+2XqbUzyX7S8Veop3rRko9eg5TYBZERObmH79yYVW28rjMAj0KdTNFlrieZ/W8Hx7a9niXBFNODVGUXEquE6D0v1mRj59EbP5M7VQnRT7O5ipw+1ZrZfBgD1e1bu8YZuRSKVb6owa7gSYRc6E7anZRwslWPDueltEfWobgzYqyEQt4bw0kkaHRlGGn2RUe4iZ7+gyW2WpNZzkvbZS1W9I58IIK7PMUW/V0PQ7rPAayhaw= MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 392e9d47-e5b0-4101-cc27-08d685ab2014 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Jan 2019 05:32:14.1938 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB5055 Subject: Re: [PATCH edk2-platforms 02/41] Silicon/NXP : Add support for Watchdog driver 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, 29 Jan 2019 05:32:18 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable > -----Original Message----- > From: Leif Lindholm > Sent: Monday, December 17, 2018 11:06 PM > To: Meenakshi Aggarwal > Cc: ard.biesheuvel@linaro.org; michael.d.kinney@intel.com; edk2- > devel@lists.01.org; Udit Kumar ; Varun Sethi > > Subject: Re: [PATCH edk2-platforms 02/41] Silicon/NXP : Add support for > Watchdog driver >=20 > Starting with this one, since that was the biggest pain point last time a= round. >=20 > On Wed, Nov 28, 2018 at 08:31:16PM +0530, Meenakshi Aggarwal wrote: > > Installs watchdog timer arch protocol >=20 > As per the email I just cc:d you on: unless the hardware supports configu= ration in > a mode where it could be used for a compliant > EFI_WATCHDOG_TIMER_ARCH_PROTOCOL (i.e., trigger a software event rather > than a hardware reset), please rewrite this driver such that it does not = register as > that protocol. >=20 Decided to use watchdog driver from MdeModulePkg. > > Contributed-under: TianoCore Contribution Agreement 1.1 > > Signed-off-by: Meenakshi Aggarwal > > --- > > Silicon/NXP/Drivers/WatchDog/WatchDog.c | 402 > +++++++++++++++++++++++++++ > > Silicon/NXP/Drivers/WatchDog/WatchDog.h | 39 +++ > > Silicon/NXP/Drivers/WatchDog/WatchDogDxe.inf | 47 ++++ > > 3 files changed, 488 insertions(+) > > create mode 100644 Silicon/NXP/Drivers/WatchDog/WatchDog.c > > create mode 100644 Silicon/NXP/Drivers/WatchDog/WatchDog.h > > create mode 100644 Silicon/NXP/Drivers/WatchDog/WatchDogDxe.inf >=20 > I would appreciate if you could follow > https://emea01.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fgith= ub. > com%2Ftianocore%2Ftianocore.github.io%2Fwiki%2FLaszlo%27s-unkempt-git- > guide-for-edk2-contributors-and-maintainers%23contrib- > 23&data=3D02%7C01%7Cmeenakshi.aggarwal%40nxp.com%7Cc5cb603bead > b4855f07608d6644624a1%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0 > %7C636806649758902154&sdata=3DNSs8taX%2F4oV0yhHmNEWVR%2Btzp3 > TqzuLnIy97t2R8dvs%3D&reserved=3D0 > when submitting the next revision. It greatly assists with reviewing. >=20 Ok, will do. > > diff --git a/Silicon/NXP/Drivers/WatchDog/WatchDog.c > > b/Silicon/NXP/Drivers/WatchDog/WatchDog.c > > new file mode 100644 > > index 0000000..1b1a3b5 > > --- /dev/null > > +++ b/Silicon/NXP/Drivers/WatchDog/WatchDog.c > > @@ -0,0 +1,402 @@ > > +/** WatchDog.c > > +* > > +* Based on Watchdog driver implemenation available in > > +* ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805Watchdog.c > > +* > > +* Copyright 2017 NXP >=20 > May want to change this to 2017-2018 > Also, format should be > Copyright (c) ... NXP. All rights reserved. >=20 Will change the year to 2017-2019, but I cant add (c) as it will not be approved by NXP's TAs. =20 > > +* > > +* 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 > > +* > > +https://emea01.safelinks.protection.outlook.com/?url=3Dhttp%3A%2F%2Fop= e > > +nsource.org%2Flicenses%2Fbsd- > license.php&data=3D02%7C01%7Cmeenakshi > > > +.aggarwal%40nxp.com%7Cc5cb603beadb4855f07608d6644624a1%7C686ea1d > 3bc2b > > > +4c6fa92cd99c5c301635%7C0%7C0%7C636806649758902154&sdata=3DRLV > E%2Bxi > > +qQaQnHRKR7Spc6QYdx1pHPnKyqheLBqIinU4%3D&reserved=3D0 > > +* > > +* 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 "WatchDog.h" > > + > > +STATIC EFI_EVENT EfiExitBootServicesEvent; STATIC EFI_EVENT > > +WdogFeedEvent; >=20 > m-prefix for both above please. >=20 > Can you do a search-and-replace Wdog -> Watchdog and WDOG -> WATCHDOG > please? >=20 > > +STATIC MMIO_OPERATIONS_16 *mMmioOps; > > + > > + > > +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 Regis= ter > (WDOG_WSR). > > + // This service sequence will reload the counter with the timeout > > +value WT[7:0] of > > + // Watchdog Control Register (WDOG_WCR). > > + // > > + > > + mMmioOps->Write (PcdGet64 (PcdWdog1BaseAddr) + > WDOG_WSR_OFFSET, > > + WDOG_SERVICE_SEQ1); >=20 > The memory access operations really need to encode size. > I would strongly prefer mMmioOps->Write16. >=20 > You could also tidy the call sites up with something like >=20 > #define WATCHDOG_ADDRESS(register) (PcdGet64 (PcdWdog1BaseAddr), > WATCHDOG_ ## register ## _OFFSET) >=20 > So the invocation becomes >=20 > mMmioOps->Write16 (WATCHDOG_ADDRESS (WSR), > WATCHDOG_SERVICE_SEQ1); >=20 >=20 > > + mMmioOps->Write (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 > > + > > + mMmioOps->AndThenOr (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 DX= E 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 unregi= ster the handler. > > + > > + @retval EFI_SUCCESS The watchdog timer handler was registe= red. > > + @retval EFI_ALREADY_STARTED NotifyFunction is not NULL, and a hand= ler > 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, the= n > EFI_UNSUPPORTED is > > + returned. If the timer is programmable, the= n the timer period > > + will be rounded up to the nearest timer per= iod that is > supported > > + by the timer hardware. If TimerPeriod is se= t 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 unit= s > > + ) > > +{ > > + EFI_STATUS Status; > > + UINT64 TimerPeriodInSec; > > + UINT16 Val; > > + > > + Status =3D EFI_SUCCESS; > > + > > + if (TimerPeriod =3D=3D 0) { > > + // This is a watchdog stop request > > + WdogStop (); > > + return Status; > > + } else { > > + // Convert the TimerPeriod (in 100 ns unit) to an equivalent > > + second value > > + > > + 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 b= ut > > + // if a smaller value was requested, this could have the watchdo= g > > + // triggering before it was intended. > > + // Better generate an error to let the caller know. > > + Status =3D EFI_DEVICE_ERROR; > > + return Status; > > + } > > + > > + // set the new timeout value in the WCR > > + // Convert the timeout value from Seconds to timer count > > + Val =3D ((WD_COUNT(TimerPeriodInSec) & WD_COUNT_MASK) << 8); > > + > > + mMmioOps->AndThenOr (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 i= n 100 ns > units. If > > + 0 is returned, then the timer is currently = disabled. > > + > > + > > + @retval EFI_SUCCESS The timer period was returned in Timer= Period. > > + @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 =3D EFI_SUCCESS; > > + > > + if (TimerPeriod =3D=3D NULL) { > > + return EFI_INVALID_PARAMETER; > > + } > > + > > + // Check if the watchdog is stopped if ((mMmioOps->Read (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 v= alue. > > + Val =3D (mMmioOps->Read (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. > > + > > +**/ > > +STATIC > > +EFI_WATCHDOG_TIMER_ARCH_PROTOCOL gWatchdogTimer =3D { >=20 > g implies global (as in visible to all modules). Please use 'm' for modul= e-local > globals. >=20 > > + WdogRegisterHandler, > > + WdogSetTimerPeriod, > > + WdogGetTimerPeriod > > +}; > > + > > +/** > > + Call back function when the timer event is signaled. > > + This function will feed the watchdog with maximum value > > + so that system wont reset in idle case e.g. stopped on UEFI shell. > > + > > + @param[in] Event The Event this notify function registered to. > > + @param[in] Context Pointer to the context data registered to the > > + Event. > > + > > +**/ > > +VOID > > +EFIAPI > > +WdogFeed ( > > + IN EFI_EVENT Event, > > + IN VOID* Context > > + ) > > +{ > > + WdogPing(); > > +} > > +/** > > + Initialize state information for the Watchdog Timer Architectural Pr= otocol. > > + > > + @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 structur= e > > + @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; > > + > > + mMmioOps =3D GetMmioOperations16 (FixedPcdGetBool > > + (PcdWdogBigEndian)); > > + > > + mMmioOps->AndThenOr (PcdGet64 (PcdWdog1BaseAddr) + > WDOG_WCR_OFFSET, > > + (UINT16)(~WDOG_WCR_WT), > > + (WD_COUNT (WT_MAX_TIME) & WD_COUNT_MASK)); > > + > > + mMmioOps->Or (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 =3D gBS->CreateEven= t > > + (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, > > + ExitBootServicesEvent, NULL, > > + &EfiExitBootServicesEvent); if (EFI_ERROR (Status)) { > > + Status =3D EFI_OUT_OF_RESOURCES; > > + return Status; > > + } > > + > > + // > > + // Start the timer to feed Watchdog with maximum timeout value. > > + // > > + Status =3D gBS->CreateEvent ( > > + EVT_TIMER | EVT_NOTIFY_SIGNAL, > > + TPL_NOTIFY, > > + WdogFeed, > > + NULL, > > + &WdogFeedEvent > > + ); > > + if (EFI_ERROR (Status)) { > > + return Status; > > + } > > + > > + Status =3D gBS->SetTimer (WdogFeedEvent, TimerPeriodic, > > + WT_FEED_INTERVAL); if (EFI_ERROR (Status)) { > > + return Status; > > + } > > + > > + // Install the Timer Architectural Protocol onto a new handle > > + Handle =3D NULL; Status =3D gBS->InstallMultipleProtocolInterfaces ( > > + &Handle, > > + &gEfiWatchdogTimerArchProtocolGuid, &gWatchdogTimer, > > + NULL > > + ); > > + if (EFI_ERROR (Status)) { > > + gBS->CloseEvent (EfiExitBootServicesEvent); > > + Status =3D EFI_OUT_OF_RESOURCES; > > + return Status; > > + } > > + > > + WdogPing (); > > + > > + return Status; > > +} > > diff --git a/Silicon/NXP/Drivers/WatchDog/WatchDog.h > > b/Silicon/NXP/Drivers/WatchDog/WatchDog.h > > new file mode 100644 > > index 0000000..9542608 > > --- /dev/null > > +++ b/Silicon/NXP/Drivers/WatchDog/WatchDog.h > > @@ -0,0 +1,39 @@ > > +/** 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 > > +* > > +https://emea01.safelinks.protection.outlook.com/?url=3Dhttp%3A%2F%2Fop= e > > +nsource.org%2Flicenses%2Fbsd- > license.php&data=3D02%7C01%7Cmeenakshi > > > +.aggarwal%40nxp.com%7Cc5cb603beadb4855f07608d6644624a1%7C686ea1d > 3bc2b > > > +4c6fa92cd99c5c301635%7C0%7C0%7C636806649758902154&sdata=3DRLV > E%2Bxi > > +qQaQnHRKR7Spc6QYdx1pHPnKyqheLBqIinU4%3D&reserved=3D0 > > +* > > +* 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 >=20 > WT? >=20 > > +#define WD_COUNT(Sec) (((Sec) * 2 - 1) << 8) > > +#define WD_COUNT_MASK 0xff00 > > +#define WD_SEC(Cnt) (((Cnt) + 1) / 2) >=20 > WD? >=20 > / > Leif >=20 > > + > > +#define NANO_SECOND_BASE 10000000 > > + > > +#define WT_FEED_INTERVAL (WT_MAX_TIME * NANO_SECOND_BASE) > > + > > +#endif //__WATCHDOG_H__ > > diff --git a/Silicon/NXP/Drivers/WatchDog/WatchDogDxe.inf > > b/Silicon/NXP/Drivers/WatchDog/WatchDogDxe.inf > > new file mode 100644 > > index 0000000..a311bdc > > --- /dev/null > > +++ b/Silicon/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 # > > +https://emea01.safelinks.protection.outlook.com/?url=3Dhttp%3A%2F%2Fop= e > > +nsource.org%2Flicenses%2Fbsd- > license.php&data=3D02%7C01%7Cmeenakshi > > > +.aggarwal%40nxp.com%7Cc5cb603beadb4855f07608d6644624a1%7C686ea1d > 3bc2b > > > +4c6fa92cd99c5c301635%7C0%7C0%7C636806649758902154&sdata=3DRLV > E%2Bxi > > +qQaQnHRKR7Spc6QYdx1pHPnKyqheLBqIinU4%3D&reserved=3D0 > > +# > > +# 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 =3D 0x0001001A > > + BASE_NAME =3D WatchDogDxe > > + FILE_GUID =3D 0358b544-ec65-4339-89cd-cad60a3dd= 787 > > + MODULE_TYPE =3D DXE_DRIVER > > + VERSION_STRING =3D 1.0 > > + ENTRY_POINT =3D WdogInitialize > > + > > +[Sources.common] > > + WatchDog.c > > + > > +[Packages] > > + MdePkg/MdePkg.dec > > + Silicon/NXP/NxpQoriqLs.dec > > + > > +[LibraryClasses] > > + BaseLib > > + IoAccessLib > > + PcdLib > > + UefiBootServicesTableLib > > + UefiDriverEntryPoint > > + > > +[Pcd] > > + gNxpQoriqLsTokenSpaceGuid.PcdWdog1BaseAddr > > + gNxpQoriqLsTokenSpaceGuid.PcdWdogBigEndian > > + > > +[Protocols] > > + gEfiWatchdogTimerArchProtocolGuid > > + > > +[Depex] > > + TRUE > > -- > > 1.9.1 > >