Files
slimbootloader/BootloaderCommonPkg/Library/DebugAgentLib/DebugTimer.c
Mike Crowe 990e3e81e6 Use LF line endings in the repository
Convert the line endings stored for all text files in the repository to
LF. The majority previously used DOS-style CRLF line endings. Add a
.gitattributes file to enforce this and treat certain extensions as
never being text files.

Update PatchCheck.py to insist on LF line endings rather than CRLF.
However, its other checks fail on this commit due to lots of
pre-existing complaints that it only notices because the line endings
have changed.

Silicon/QemuSocPkg/FspBin/Patches/0001-Build-QEMU-FSP-2.0-binaries.patch
needs to be treated as binary since it contains a mixture of line
endings.

This change has implications depending on the client platform you are
using the repository from:

* Windows

The usual configuration for Git on Windows means that text files will
be checked out to the work tree with DOS-style CRLF line endings. If
that's not the case then you can configure Git to do so for the entire
machine with:

 git config --global core.autocrlf true

or for just the repository with:

 git config core.autocrlf true

Line endings will be normalised to LF when they are committed to the
repository. If you commit a text file with only LF line endings then it
will be converted to CRLF line endings in your work tree.

* Linux, MacOS and other Unices

The usual configuration for Git on such platforms is to check files out
of the repository with LF line endings. This is probably the right thing
for you. In the unlikely even that you are using Git on Unix but editing
or compiling on Windows for some reason then you may need to tweak your
configuration to force the use of CRLF line endings as described above.

* General

For more information see
https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings .

Fixes: https://github.com/slimbootloader/slimbootloader/issues/1400
Signed-off-by: Mike Crowe <mac@mcrowe.com>
2021-11-10 12:46:42 -08:00

144 lines
3.8 KiB
C

/** @file
Code for debug timer to support debug agent library implementation.
Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "DebugAgent.h"
/**
Initialize CPU local APIC timer.
@param[out] TimerFrequency Local APIC timer frequency returned.
@param[in] DumpFlag If TRUE, dump Local APIC timer's parameter.
@return 32-bit Local APIC timer init count.
**/
UINT32
InitializeDebugTimer (
OUT UINT32 *TimerFrequency,
IN BOOLEAN DumpFlag
)
{
UINTN ApicTimerDivisor;
UINT32 InitialCount;
UINT32 ApicTimerFrequency;
InitializeLocalApicSoftwareEnable (TRUE);
GetApicTimerState (&ApicTimerDivisor, NULL, NULL);
ApicTimerFrequency = PcdGet32(PcdFSBClock) / (UINT32)ApicTimerDivisor;
//
// Cpu Local Apic timer interrupt frequency, it is set to 0.1s
//
InitialCount = (UINT32)DivU64x32 (
MultU64x64 (
ApicTimerFrequency,
DEBUG_TIMER_INTERVAL
),
1000000u
);
InitializeApicTimer (ApicTimerDivisor, InitialCount, TRUE, DEBUG_TIMER_VECTOR);
//
// Disable Debug Timer interrupt to avoid it is delivered before Debug Port
// is initialized
//
DisableApicTimerInterrupt ();
if (DumpFlag) {
DEBUG ((DEBUG_INFO, "Debug Timer: FSB Clock = %d\n", PcdGet32(PcdFSBClock)));
DEBUG ((DEBUG_INFO, "Debug Timer: Divisor = %d\n", ApicTimerDivisor));
DEBUG ((DEBUG_INFO, "Debug Timer: Frequency = %d\n", ApicTimerFrequency));
DEBUG ((DEBUG_INFO, "Debug Timer: InitialCount = %d\n", InitialCount));
}
if (TimerFrequency != NULL) {
*TimerFrequency = ApicTimerFrequency;
}
return InitialCount;
}
/**
Enable/Disable the interrupt of debug timer and return the interrupt state
prior to the operation.
If EnableStatus is TRUE, enable the interrupt of debug timer.
If EnableStatus is FALSE, disable the interrupt of debug timer.
@param[in] EnableStatus Enable/Disable.
@retval TRUE Debug timer interrupt were enabled on entry to this call.
@retval FALSE Debug timer interrupt were disabled on entry to this call.
**/
BOOLEAN
EFIAPI
SaveAndSetDebugTimerInterrupt (
IN BOOLEAN EnableStatus
)
{
BOOLEAN OldDebugTimerInterruptState;
OldDebugTimerInterruptState = GetApicTimerInterruptState ();
if (OldDebugTimerInterruptState != EnableStatus) {
if (EnableStatus) {
EnableApicTimerInterrupt ();
} else {
DisableApicTimerInterrupt ();
}
//
// Validate the Debug Timer interrupt state
// This will make additional delay after Local Apic Timer interrupt state is changed.
// Thus, CPU could handle the potential pending interrupt of Local Apic timer.
//
while (GetApicTimerInterruptState () != EnableStatus) {
CpuPause ();
}
}
return OldDebugTimerInterruptState;
}
/**
Check if the timer is time out.
@param[in] TimerCycle Timer initial count.
@param[in] Timer The start timer from the begin.
@param[in] TimeoutTicker Ticker number need time out.
@return TRUE Timer time out occurs.
@retval FALSE Timer does not time out.
**/
BOOLEAN
IsDebugTimerTimeout (
IN UINT32 TimerCycle,
IN UINT32 Timer,
IN UINT32 TimeoutTicker
)
{
UINT64 CurrentTimer;
UINT64 Delta;
CurrentTimer = GetApicTimerCurrentCount ();
//
// This timer counter counts down. Check for roll over condition.
// If CurrentTimer is equal to Timer, it does not mean that roll over
// happened.
//
if (CurrentTimer <= Timer) {
Delta = Timer - CurrentTimer;
} else {
//
// Handle one roll-over.
//
Delta = TimerCycle - (CurrentTimer - Timer) + 1;
}
return (BOOLEAN) (Delta >= TimeoutTicker);
}