Files
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

130 lines
2.8 KiB
C

/** @file
Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Register/Intel/Cpuid.h>
#include <Library/BaseLib.h>
/**
Read current timestamp.
@return 64 bit current timestampe value.
**/
UINT64
EFIAPI
ReadTimeStamp (
VOID
)
{
return AsmReadTsc();
}
/**
Get timestamp frequency in KHZ.
@return Timestamp frequency in KHZ.
**/
UINT32
EFIAPI
GetTimeStampFrequency (
VOID
)
{
UINT32 Ratio;
Ratio = ((UINT32)AsmReadMsr64 (0xCE) >> 8) & 0xFF;
if (Ratio == 0) {
// This might be QEMU case
Ratio = 8;
}
// Ratio * 100000
return (Ratio * 100000);
}
/**
Get timestamp accurate frequency in HZ by CPUID.
The TSC counting frequency is determined by using CPUID leaf 0x15. Frequency in MHz = Core XTAL frequency * EBX/EAX.
In newer flavors of the CPU, core xtal frequency is returned in ECX or 0 if not supported.
@retval The number of TSC counts per second.
**/
UINT64
EFIAPI
GetTimeStampAccurateFrequency (
VOID
)
{
UINT64 TscFrequency;
UINT32 RegEax;
UINT32 RegEbx;
UINT32 RegEcx;
// Use CPUID leaf 0x15 Time Stamp Counter and Nominal Core Crystal Clock Information
// EBX returns 0 if not supported. ECX, if non zero, provides Core Xtal Frequency in hertz.
// TSC frequency = (ECX, Core Xtal Frequency) * EBX/EAX.
AsmCpuid (CPUID_TIME_STAMP_COUNTER, &RegEax, &RegEbx, &RegEcx, NULL);
// If EAX, EBX or ECX returns 0, the XTAL ratio is not enumerated.
if ((RegEax == 0) || (RegEbx == 0 ) || (RegEcx == 0)) {
// Fallback to use GetTimeStampFrequency() instead
TscFrequency = MultU64x32 (GetTimeStampFrequency(), 1000);
} else {
// Calculate TSC frequency = (ECX, Core Xtal Frequency) * EBX/EAX
TscFrequency = DivU64x32 (MultU64x32 (RegEcx, RegEbx) + (UINT64)(RegEax >> 1), RegEax);
}
return TscFrequency;
}
/**
Convert microseconds to timestamp ticks.
@param[in] MicroSeconds The number of microseconds to convert.
@retval Timestamp ticks
**/
UINT64
EFIAPI
MicroSecondToTimeStampTick (
IN UINT64 MicroSeconds
)
{
return DivU64x32 (
MultU64x64 (
GetTimeStampAccurateFrequency (),
MicroSeconds
),
1000000u
);
}
/**
Convert timestamp ticks to microseconds.
@param[in] Ticks The number of timestamp ticks to convert.
@retval MicroSeconds
**/
UINT64
EFIAPI
TimeStampTickToMicroSecond (
IN UINT64 Ticks
)
{
return DivU64x64Remainder (
MultU64x32 (Ticks, 1000000u),
GetTimeStampAccurateFrequency (),
NULL
);
}