mirror of https://github.com/acidanthera/audk.git
ArmPlatformPkg/SP805WatchdogDxe: cosmetic cleanup
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>
This commit is contained in:
parent
87b920fe22
commit
e3fa3d83e7
|
@ -1,6 +1,7 @@
|
||||||
/** @file
|
/** @file
|
||||||
*
|
*
|
||||||
* Copyright (c) 2011-2013, ARM Limited. All rights reserved.
|
* Copyright (c) 2011-2013, ARM Limited. All rights reserved.
|
||||||
|
* Copyright (c) 2018, Linaro Limited. All rights reserved.
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials
|
* This program and the accompanying materials
|
||||||
* are licensed and made available under the terms and conditions of the BSD License
|
* are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
@ -19,16 +20,13 @@
|
||||||
#include <Library/BaseMemoryLib.h>
|
#include <Library/BaseMemoryLib.h>
|
||||||
#include <Library/DebugLib.h>
|
#include <Library/DebugLib.h>
|
||||||
#include <Library/IoLib.h>
|
#include <Library/IoLib.h>
|
||||||
#include <Library/PcdLib.h>
|
|
||||||
#include <Library/UefiBootServicesTableLib.h>
|
#include <Library/UefiBootServicesTableLib.h>
|
||||||
#include <Library/UefiRuntimeServicesTableLib.h>
|
|
||||||
#include <Library/UefiLib.h>
|
|
||||||
|
|
||||||
#include <Protocol/WatchdogTimer.h>
|
#include <Protocol/WatchdogTimer.h>
|
||||||
|
|
||||||
#include "SP805Watchdog.h"
|
#include "SP805Watchdog.h"
|
||||||
|
|
||||||
EFI_EVENT EfiExitBootServicesEvent = (EFI_EVENT)NULL;
|
STATIC EFI_EVENT mEfiExitBootServicesEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Make sure the SP805 registers are unlocked for writing.
|
Make sure the SP805 registers are unlocked for writing.
|
||||||
|
@ -103,6 +101,7 @@ SP805Start (
|
||||||
On exiting boot services we must make sure the SP805 Watchdog Timer
|
On exiting boot services we must make sure the SP805 Watchdog Timer
|
||||||
is stopped.
|
is stopped.
|
||||||
**/
|
**/
|
||||||
|
STATIC
|
||||||
VOID
|
VOID
|
||||||
EFIAPI
|
EFIAPI
|
||||||
ExitBootServicesEvent (
|
ExitBootServicesEvent (
|
||||||
|
@ -142,10 +141,11 @@ ExitBootServicesEvent (
|
||||||
previously registered.
|
previously registered.
|
||||||
|
|
||||||
**/
|
**/
|
||||||
|
STATIC
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
SP805RegisterHandler (
|
SP805RegisterHandler (
|
||||||
IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
||||||
IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction
|
IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
@ -182,22 +182,24 @@ SP805RegisterHandler (
|
||||||
@retval EFI_DEVICE_ERROR The timer period could not be changed due to a device error.
|
@retval EFI_DEVICE_ERROR The timer period could not be changed due to a device error.
|
||||||
|
|
||||||
**/
|
**/
|
||||||
|
STATIC
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
SP805SetTimerPeriod (
|
SP805SetTimerPeriod (
|
||||||
IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
||||||
IN UINT64 TimerPeriod // In 100ns units
|
IN UINT64 TimerPeriod // In 100ns units
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status = EFI_SUCCESS;
|
EFI_STATUS Status;
|
||||||
UINT64 Ticks64bit;
|
UINT64 Ticks64bit;
|
||||||
|
|
||||||
SP805Unlock ();
|
SP805Unlock ();
|
||||||
|
|
||||||
|
Status = EFI_SUCCESS;
|
||||||
|
|
||||||
if (TimerPeriod == 0) {
|
if (TimerPeriod == 0) {
|
||||||
// This is a watchdog stop request
|
// This is a watchdog stop request
|
||||||
SP805Stop ();
|
SP805Stop ();
|
||||||
goto EXIT;
|
|
||||||
} else {
|
} else {
|
||||||
// Calculate the Watchdog ticks required for a delay of (TimerTicks * 100) nanoseconds
|
// Calculate the Watchdog ticks required for a delay of (TimerTicks * 100) nanoseconds
|
||||||
// The SP805 will count down to ZERO once, generate an interrupt and
|
// The SP805 will count down to ZERO once, generate an interrupt and
|
||||||
|
@ -211,10 +213,11 @@ SP805SetTimerPeriod (
|
||||||
//
|
//
|
||||||
// WatchdogTicks = (TimerPeriod * SP805_CLOCK_FREQUENCY) / 20 MHz ;
|
// WatchdogTicks = (TimerPeriod * SP805_CLOCK_FREQUENCY) / 20 MHz ;
|
||||||
|
|
||||||
Ticks64bit = DivU64x32(MultU64x32(TimerPeriod, (UINTN)PcdGet32(PcdSP805WatchdogClockFrequencyInHz)), 20000000);
|
Ticks64bit = MultU64x32 (TimerPeriod, PcdGet32 (PcdSP805WatchdogClockFrequencyInHz));
|
||||||
|
Ticks64bit = DivU64x32 (Ticks64bit, 20000000);
|
||||||
|
|
||||||
// The registers in the SP805 are only 32 bits
|
// The registers in the SP805 are only 32 bits
|
||||||
if(Ticks64bit > (UINT64)0xFFFFFFFF) {
|
if (Ticks64bit > MAX_UINT32) {
|
||||||
// We could load the watchdog with the maximum supported value but
|
// We could load the watchdog with the maximum supported value but
|
||||||
// if a smaller value was requested, this could have the watchdog
|
// if a smaller value was requested, this could have the watchdog
|
||||||
// triggering before it was intended.
|
// triggering before it was intended.
|
||||||
|
@ -251,14 +254,14 @@ SP805SetTimerPeriod (
|
||||||
@retval EFI_INVALID_PARAMETER TimerPeriod is NULL.
|
@retval EFI_INVALID_PARAMETER TimerPeriod is NULL.
|
||||||
|
|
||||||
**/
|
**/
|
||||||
|
STATIC
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
SP805GetTimerPeriod (
|
SP805GetTimerPeriod (
|
||||||
IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
||||||
OUT UINT64 *TimerPeriod
|
OUT UINT64 *TimerPeriod
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status = EFI_SUCCESS;
|
|
||||||
UINT64 ReturnValue;
|
UINT64 ReturnValue;
|
||||||
|
|
||||||
if (TimerPeriod == NULL) {
|
if (TimerPeriod == NULL) {
|
||||||
|
@ -278,7 +281,7 @@ SP805GetTimerPeriod (
|
||||||
|
|
||||||
*TimerPeriod = ReturnValue;
|
*TimerPeriod = ReturnValue;
|
||||||
|
|
||||||
return Status;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -313,10 +316,10 @@ SP805GetTimerPeriod (
|
||||||
Retrieves the period of the timer interrupt in 100 nS units.
|
Retrieves the period of the timer interrupt in 100 nS units.
|
||||||
|
|
||||||
**/
|
**/
|
||||||
EFI_WATCHDOG_TIMER_ARCH_PROTOCOL gWatchdogTimer = {
|
STATIC EFI_WATCHDOG_TIMER_ARCH_PROTOCOL mWatchdogTimer = {
|
||||||
(EFI_WATCHDOG_TIMER_REGISTER_HANDLER) SP805RegisterHandler,
|
SP805RegisterHandler,
|
||||||
(EFI_WATCHDOG_TIMER_SET_TIMER_PERIOD) SP805SetTimerPeriod,
|
SP805SetTimerPeriod,
|
||||||
(EFI_WATCHDOG_TIMER_GET_TIMER_PERIOD) SP805GetTimerPeriod
|
SP805GetTimerPeriod
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -361,7 +364,8 @@ SP805Initialize (
|
||||||
ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiWatchdogTimerArchProtocolGuid);
|
ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiWatchdogTimerArchProtocolGuid);
|
||||||
|
|
||||||
// Register for an ExitBootServicesEvent
|
// Register for an ExitBootServicesEvent
|
||||||
Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, ExitBootServicesEvent, NULL, &EfiExitBootServicesEvent);
|
Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY,
|
||||||
|
ExitBootServicesEvent, NULL, &mEfiExitBootServicesEvent);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
Status = EFI_OUT_OF_RESOURCES;
|
Status = EFI_OUT_OF_RESOURCES;
|
||||||
goto EXIT;
|
goto EXIT;
|
||||||
|
@ -371,7 +375,7 @@ SP805Initialize (
|
||||||
Handle = NULL;
|
Handle = NULL;
|
||||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||||
&Handle,
|
&Handle,
|
||||||
&gEfiWatchdogTimerArchProtocolGuid, &gWatchdogTimer,
|
&gEfiWatchdogTimerArchProtocolGuid, &mWatchdogTimer,
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
|
@ -380,9 +384,6 @@ SP805Initialize (
|
||||||
}
|
}
|
||||||
|
|
||||||
EXIT:
|
EXIT:
|
||||||
if(EFI_ERROR(Status)) {
|
ASSERT_EFI_ERROR (Status);
|
||||||
// The watchdog failed to initialize
|
|
||||||
ASSERT(FALSE);
|
|
||||||
}
|
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/** @file
|
/** @file
|
||||||
*
|
*
|
||||||
* Copyright (c) 2011-2012, ARM Limited. All rights reserved.
|
* Copyright (c) 2011-2012, ARM Limited. All rights reserved.
|
||||||
|
* Copyright (c) 2018, Linaro Limited. All rights reserved.
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials
|
* This program and the accompanying materials
|
||||||
* are licensed and made available under the terms and conditions of the BSD License
|
* are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
@ -18,35 +19,29 @@
|
||||||
FILE_GUID = ebd705fb-fa92-46a7-b32b-7f566d944614
|
FILE_GUID = ebd705fb-fa92-46a7-b32b-7f566d944614
|
||||||
MODULE_TYPE = DXE_DRIVER
|
MODULE_TYPE = DXE_DRIVER
|
||||||
VERSION_STRING = 1.0
|
VERSION_STRING = 1.0
|
||||||
|
|
||||||
ENTRY_POINT = SP805Initialize
|
ENTRY_POINT = SP805Initialize
|
||||||
|
|
||||||
[Sources.common]
|
[Sources.common]
|
||||||
SP805Watchdog.c
|
SP805Watchdog.c
|
||||||
|
|
||||||
[Packages]
|
[Packages]
|
||||||
MdePkg/MdePkg.dec
|
|
||||||
EmbeddedPkg/EmbeddedPkg.dec
|
|
||||||
ArmPkg/ArmPkg.dec
|
ArmPkg/ArmPkg.dec
|
||||||
ArmPlatformPkg/ArmPlatformPkg.dec
|
ArmPlatformPkg/ArmPlatformPkg.dec
|
||||||
|
MdePkg/MdePkg.dec
|
||||||
|
|
||||||
[LibraryClasses]
|
[LibraryClasses]
|
||||||
BaseLib
|
BaseLib
|
||||||
BaseMemoryLib
|
|
||||||
DebugLib
|
DebugLib
|
||||||
IoLib
|
IoLib
|
||||||
PcdLib
|
|
||||||
UefiLib
|
|
||||||
UefiBootServicesTableLib
|
UefiBootServicesTableLib
|
||||||
UefiDriverEntryPoint
|
UefiDriverEntryPoint
|
||||||
UefiRuntimeServicesTableLib
|
|
||||||
|
|
||||||
[Pcd]
|
[Pcd]
|
||||||
gArmPlatformTokenSpaceGuid.PcdSP805WatchdogBase
|
gArmPlatformTokenSpaceGuid.PcdSP805WatchdogBase
|
||||||
gArmPlatformTokenSpaceGuid.PcdSP805WatchdogClockFrequencyInHz
|
gArmPlatformTokenSpaceGuid.PcdSP805WatchdogClockFrequencyInHz
|
||||||
|
|
||||||
[Protocols]
|
[Protocols]
|
||||||
gEfiWatchdogTimerArchProtocolGuid
|
gEfiWatchdogTimerArchProtocolGuid ## ALWAYS_PRODUCES
|
||||||
|
|
||||||
[Depex]
|
[Depex]
|
||||||
TRUE
|
TRUE
|
||||||
|
|
Loading…
Reference in New Issue