Before fixing the SP805 driver, let's clean it up a bit. No
functional changes.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
/** @file\r
*\r
* Copyright (c) 2011-2013, ARM Limited. All rights reserved.\r
/** @file\r
*\r
* Copyright (c) 2011-2013, ARM Limited. All rights reserved.\r
+* Copyright (c) 2018, Linaro Limited. All rights reserved.\r
*\r
* This program and the accompanying materials\r
* are licensed and made available under the terms and conditions of the BSD License\r
*\r
* This program and the accompanying materials\r
* are licensed and made available under the terms and conditions of the BSD License\r
#include <Library/BaseMemoryLib.h>\r
#include <Library/DebugLib.h>\r
#include <Library/IoLib.h>\r
#include <Library/BaseMemoryLib.h>\r
#include <Library/DebugLib.h>\r
#include <Library/IoLib.h>\r
-#include <Library/PcdLib.h>\r
#include <Library/UefiBootServicesTableLib.h>\r
#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/UefiRuntimeServicesTableLib.h>\r
-#include <Library/UefiLib.h>\r
\r
#include <Protocol/WatchdogTimer.h>\r
\r
#include "SP805Watchdog.h"\r
\r
\r
#include <Protocol/WatchdogTimer.h>\r
\r
#include "SP805Watchdog.h"\r
\r
-EFI_EVENT EfiExitBootServicesEvent = (EFI_EVENT)NULL;\r
+STATIC EFI_EVENT mEfiExitBootServicesEvent;\r
\r
/**\r
Make sure the SP805 registers are unlocked for writing.\r
\r
/**\r
Make sure the SP805 registers are unlocked for writing.\r
- if( MmioRead32(SP805_WDOG_LOCK_REG) == SP805_WDOG_LOCK_IS_LOCKED ) {\r
- MmioWrite32(SP805_WDOG_LOCK_REG, SP805_WDOG_SPECIAL_UNLOCK_CODE);\r
+ if (MmioRead32 (SP805_WDOG_LOCK_REG) == SP805_WDOG_LOCK_IS_LOCKED) {\r
+ MmioWrite32 (SP805_WDOG_LOCK_REG, SP805_WDOG_SPECIAL_UNLOCK_CODE);\r
- if( MmioRead32(SP805_WDOG_LOCK_REG) == SP805_WDOG_LOCK_IS_UNLOCKED ) {\r
+ if (MmioRead32 (SP805_WDOG_LOCK_REG) == SP805_WDOG_LOCK_IS_UNLOCKED) {\r
// To lock it, just write in any number (except the special unlock code).\r
// To lock it, just write in any number (except the special unlock code).\r
- MmioWrite32(SP805_WDOG_LOCK_REG, SP805_WDOG_LOCK_IS_LOCKED);\r
+ MmioWrite32 (SP805_WDOG_LOCK_REG, SP805_WDOG_LOCK_IS_LOCKED);\r
)\r
{\r
// Disable interrupts\r
)\r
{\r
// Disable interrupts\r
- if ( (MmioRead32(SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_INTEN) != 0 ) {\r
- MmioAnd32(SP805_WDOG_CONTROL_REG, ~SP805_WDOG_CTRL_INTEN);\r
+ if ((MmioRead32 (SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_INTEN) != 0) {\r
+ MmioAnd32 (SP805_WDOG_CONTROL_REG, ~SP805_WDOG_CTRL_INTEN);\r
)\r
{\r
// Enable interrupts\r
)\r
{\r
// Enable interrupts\r
- if ( (MmioRead32(SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_INTEN) == 0 ) {\r
- MmioOr32(SP805_WDOG_CONTROL_REG, SP805_WDOG_CTRL_INTEN);\r
+ if ((MmioRead32 (SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_INTEN) == 0) {\r
+ MmioOr32 (SP805_WDOG_CONTROL_REG, SP805_WDOG_CTRL_INTEN);\r
On exiting boot services we must make sure the SP805 Watchdog Timer\r
is stopped.\r
**/\r
On exiting boot services we must make sure the SP805 Watchdog Timer\r
is stopped.\r
**/\r
VOID\r
EFIAPI\r
ExitBootServicesEvent (\r
VOID\r
EFIAPI\r
ExitBootServicesEvent (\r
IN VOID *Context\r
)\r
{\r
IN VOID *Context\r
)\r
{\r
- SP805Unlock();\r
- SP805Stop();\r
- SP805Lock();\r
+ SP805Unlock ();\r
+ SP805Stop ();\r
+ SP805Lock ();\r
previously registered.\r
\r
**/\r
previously registered.\r
\r
**/\r
EFI_STATUS\r
EFIAPI\r
SP805RegisterHandler (\r
EFI_STATUS\r
EFIAPI\r
SP805RegisterHandler (\r
- IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,\r
+ IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,\r
IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction\r
)\r
{\r
IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction\r
)\r
{\r
@retval EFI_DEVICE_ERROR The timer period could not be changed due to a device error.\r
\r
**/\r
@retval EFI_DEVICE_ERROR The timer period could not be changed due to a device error.\r
\r
**/\r
EFI_STATUS\r
EFIAPI\r
SP805SetTimerPeriod (\r
EFI_STATUS\r
EFIAPI\r
SP805SetTimerPeriod (\r
- IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,\r
+ IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,\r
IN UINT64 TimerPeriod // In 100ns units\r
)\r
{\r
IN UINT64 TimerPeriod // In 100ns units\r
)\r
{\r
- EFI_STATUS Status = EFI_SUCCESS;\r
- if( TimerPeriod == 0 ) {\r
+ Status = EFI_SUCCESS;\r
+\r
+ if (TimerPeriod == 0) {\r
// This is a watchdog stop request\r
// This is a watchdog stop request\r
- SP805Stop();\r
- goto EXIT;\r
} else {\r
// Calculate the Watchdog ticks required for a delay of (TimerTicks * 100) nanoseconds\r
// The SP805 will count down to ZERO once, generate an interrupt and\r
} else {\r
// Calculate the Watchdog ticks required for a delay of (TimerTicks * 100) nanoseconds\r
// The SP805 will count down to ZERO once, generate an interrupt and\r
//\r
// WatchdogTicks = (TimerPeriod * SP805_CLOCK_FREQUENCY) / 20 MHz ;\r
\r
//\r
// WatchdogTicks = (TimerPeriod * SP805_CLOCK_FREQUENCY) / 20 MHz ;\r
\r
- Ticks64bit = DivU64x32(MultU64x32(TimerPeriod, (UINTN)PcdGet32(PcdSP805WatchdogClockFrequencyInHz)), 20000000);\r
+ Ticks64bit = MultU64x32 (TimerPeriod, PcdGet32 (PcdSP805WatchdogClockFrequencyInHz));\r
+ Ticks64bit = DivU64x32 (Ticks64bit, 20000000);\r
\r
// The registers in the SP805 are only 32 bits\r
\r
// The registers in the SP805 are only 32 bits\r
- if(Ticks64bit > (UINT64)0xFFFFFFFF) {\r
+ if (Ticks64bit > MAX_UINT32) {\r
// We could load the watchdog with the maximum supported value but\r
// if a smaller value was requested, this could have the watchdog\r
// triggering before it was intended.\r
// We could load the watchdog with the maximum supported value but\r
// if a smaller value was requested, this could have the watchdog\r
// triggering before it was intended.\r
}\r
\r
// Update the watchdog with a 32-bit value.\r
}\r
\r
// Update the watchdog with a 32-bit value.\r
- MmioWrite32(SP805_WDOG_LOAD_REG, (UINT32)Ticks64bit);\r
+ MmioWrite32 (SP805_WDOG_LOAD_REG, (UINT32)Ticks64bit);\r
\r
// Start the watchdog\r
\r
// Start the watchdog\r
// Ensure the watchdog is locked before exiting.\r
// Ensure the watchdog is locked before exiting.\r
@retval EFI_INVALID_PARAMETER TimerPeriod is NULL.\r
\r
**/\r
@retval EFI_INVALID_PARAMETER TimerPeriod is NULL.\r
\r
**/\r
EFI_STATUS\r
EFIAPI\r
SP805GetTimerPeriod (\r
EFI_STATUS\r
EFIAPI\r
SP805GetTimerPeriod (\r
- IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,\r
+ IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,\r
OUT UINT64 *TimerPeriod\r
)\r
{\r
OUT UINT64 *TimerPeriod\r
)\r
{\r
- EFI_STATUS Status = EFI_SUCCESS;\r
UINT64 ReturnValue;\r
\r
if (TimerPeriod == NULL) {\r
UINT64 ReturnValue;\r
\r
if (TimerPeriod == NULL) {\r
}\r
\r
// Check if the watchdog is stopped\r
}\r
\r
// Check if the watchdog is stopped\r
- if ( (MmioRead32(SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_INTEN) == 0 ) {\r
+ if ((MmioRead32 (SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_INTEN) == 0) {\r
// It is stopped, so return zero.\r
ReturnValue = 0;\r
} else {\r
// Convert the Watchdog ticks into TimerPeriod\r
// Ensure 64bit arithmetic throughout because the Watchdog ticks may already\r
// be at the maximum 32 bit value and we still need to multiply that by 600.\r
// It is stopped, so return zero.\r
ReturnValue = 0;\r
} else {\r
// Convert the Watchdog ticks into TimerPeriod\r
// Ensure 64bit arithmetic throughout because the Watchdog ticks may already\r
// be at the maximum 32 bit value and we still need to multiply that by 600.\r
- ReturnValue = MultU64x32( MmioRead32(SP805_WDOG_LOAD_REG), 600 );\r
+ ReturnValue = MultU64x32 (MmioRead32 (SP805_WDOG_LOAD_REG), 600);\r
}\r
\r
*TimerPeriod = ReturnValue;\r
\r
}\r
\r
*TimerPeriod = ReturnValue;\r
\r
Retrieves the period of the timer interrupt in 100 nS units.\r
\r
**/\r
Retrieves the period of the timer interrupt in 100 nS units.\r
\r
**/\r
-EFI_WATCHDOG_TIMER_ARCH_PROTOCOL gWatchdogTimer = {\r
- (EFI_WATCHDOG_TIMER_REGISTER_HANDLER) SP805RegisterHandler,\r
- (EFI_WATCHDOG_TIMER_SET_TIMER_PERIOD) SP805SetTimerPeriod,\r
- (EFI_WATCHDOG_TIMER_GET_TIMER_PERIOD) SP805GetTimerPeriod\r
+STATIC EFI_WATCHDOG_TIMER_ARCH_PROTOCOL mWatchdogTimer = {\r
+ SP805RegisterHandler,\r
+ SP805SetTimerPeriod,\r
+ SP805GetTimerPeriod\r
SP805Stop ();\r
\r
// Set the watchdog to reset the board when triggered\r
SP805Stop ();\r
\r
// Set the watchdog to reset the board when triggered\r
- if ((MmioRead32(SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_RESEN) == 0) {\r
+ if ((MmioRead32 (SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_RESEN) == 0) {\r
MmioOr32 (SP805_WDOG_CONTROL_REG, SP805_WDOG_CTRL_RESEN);\r
}\r
\r
// Prohibit any rogue access to SP805 registers\r
MmioOr32 (SP805_WDOG_CONTROL_REG, SP805_WDOG_CTRL_RESEN);\r
}\r
\r
// Prohibit any rogue access to SP805 registers\r
\r
//\r
// Make sure the Watchdog Timer Architectural Protocol has not been installed in the system yet.\r
\r
//\r
// Make sure the Watchdog Timer Architectural Protocol has not been installed in the system yet.\r
ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiWatchdogTimerArchProtocolGuid);\r
\r
// Register for an ExitBootServicesEvent\r
ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiWatchdogTimerArchProtocolGuid);\r
\r
// Register for an ExitBootServicesEvent\r
- Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, ExitBootServicesEvent, NULL, &EfiExitBootServicesEvent);\r
- if (EFI_ERROR(Status)) {\r
+ Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY,\r
+ ExitBootServicesEvent, NULL, &mEfiExitBootServicesEvent);\r
+ if (EFI_ERROR (Status)) {\r
Status = EFI_OUT_OF_RESOURCES;\r
goto EXIT;\r
}\r
\r
// Install the Timer Architectural Protocol onto a new handle\r
Handle = NULL;\r
Status = EFI_OUT_OF_RESOURCES;\r
goto EXIT;\r
}\r
\r
// Install the Timer Architectural Protocol onto a new handle\r
Handle = NULL;\r
- Status = gBS->InstallMultipleProtocolInterfaces(\r
+ Status = gBS->InstallMultipleProtocolInterfaces (\r
- &gEfiWatchdogTimerArchProtocolGuid, &gWatchdogTimer,\r
+ &gEfiWatchdogTimerArchProtocolGuid, &mWatchdogTimer,\r
- if (EFI_ERROR(Status)) {\r
+ if (EFI_ERROR (Status)) {\r
Status = EFI_OUT_OF_RESOURCES;\r
goto EXIT;\r
}\r
\r
EXIT:\r
Status = EFI_OUT_OF_RESOURCES;\r
goto EXIT;\r
}\r
\r
EXIT:\r
- if(EFI_ERROR(Status)) {\r
- // The watchdog failed to initialize\r
- ASSERT(FALSE);\r
- }\r
+ ASSERT_EFI_ERROR (Status);\r
/** @file\r
*\r
* Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
/** @file\r
*\r
* Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+* Copyright (c) 2018, Linaro Limited. All rights reserved.\r
*\r
* This program and the accompanying materials\r
* are licensed and made available under the terms and conditions of the BSD License\r
*\r
* This program and the accompanying materials\r
* are licensed and made available under the terms and conditions of the BSD License\r
FILE_GUID = ebd705fb-fa92-46a7-b32b-7f566d944614\r
MODULE_TYPE = DXE_DRIVER\r
VERSION_STRING = 1.0\r
FILE_GUID = ebd705fb-fa92-46a7-b32b-7f566d944614\r
MODULE_TYPE = DXE_DRIVER\r
VERSION_STRING = 1.0\r
ENTRY_POINT = SP805Initialize\r
\r
[Sources.common]\r
SP805Watchdog.c\r
\r
[Packages]\r
ENTRY_POINT = SP805Initialize\r
\r
[Sources.common]\r
SP805Watchdog.c\r
\r
[Packages]\r
- MdePkg/MdePkg.dec\r
- EmbeddedPkg/EmbeddedPkg.dec\r
ArmPkg/ArmPkg.dec\r
ArmPlatformPkg/ArmPlatformPkg.dec\r
ArmPkg/ArmPkg.dec\r
ArmPlatformPkg/ArmPlatformPkg.dec\r
\r
[LibraryClasses]\r
BaseLib\r
\r
[LibraryClasses]\r
BaseLib\r
UefiBootServicesTableLib\r
UefiDriverEntryPoint\r
UefiBootServicesTableLib\r
UefiDriverEntryPoint\r
- UefiRuntimeServicesTableLib\r
\r
[Pcd]\r
gArmPlatformTokenSpaceGuid.PcdSP805WatchdogBase\r
gArmPlatformTokenSpaceGuid.PcdSP805WatchdogClockFrequencyInHz\r
\r
[Protocols]\r
\r
[Pcd]\r
gArmPlatformTokenSpaceGuid.PcdSP805WatchdogBase\r
gArmPlatformTokenSpaceGuid.PcdSP805WatchdogClockFrequencyInHz\r
\r
[Protocols]\r
- gEfiWatchdogTimerArchProtocolGuid\r
+ gEfiWatchdogTimerArchProtocolGuid ## ALWAYS_PRODUCES\r