This patch adds time stamp infrastructure using the TSC. It attempts to determine TSC frequency inside virtual machines, but not on read hardware.
Signed-off-by: Alexander Graf <g...@amazon.com> --- .../BaseDebugBootlog/DebugBootlogX86.c | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 MdePkg/Library/BaseDebugBootlog/DebugBootlogX86.c diff --git a/MdePkg/Library/BaseDebugBootlog/DebugBootlogX86.c b/MdePkg/Library/BaseDebugBootlog/DebugBootlogX86.c new file mode 100644 index 0000000000..1b6f677ce8 --- /dev/null +++ b/MdePkg/Library/BaseDebugBootlog/DebugBootlogX86.c @@ -0,0 +1,50 @@ +/** @file + Base Debug library instance for a RAM based boot log + It provides functions to store debug messages in RAM and make them available as + Bootlog Configuration Table. + + Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR> + Copyright (c) 2022, Amazon Development Center Germany GmbH.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "BaseDebugBootlog.h" + +UINT64 +EFIAPI +BaseDebugLibBootlogTicksPerSecond ( + VOID + ) +{ + UINT32 MaxLeaf = 0; + UINT32 TscKhz = 0; + + /* Look up VMware's TSC leaf first */ + AsmCpuid (0x40000000, &MaxLeaf, NULL, NULL, NULL); + if (MaxLeaf >= 0x40000010 && MaxLeaf < 0x50000000) { + /* We're in a VM that supports the TSC leaf. */ + AsmCpuid (0x40000010, &TscKhz, NULL, NULL, NULL); + + return (UINT64)TscKhz * 1000; + } + + /* + * The natural fallback path here would be to leverage TimerLib's + * GetPerformanceCounterProperties(), but TimerLib uses DebugLib + * so we can not use it. Let's leave TSC frequency extraction to + * post processing for now. + */ + + return 0; +} + +UINT64 +EFIAPI +BaseDebugLibBootlogTicks ( + VOID + ) +{ + return AsmReadTsc(); +} + -- 2.28.0.394.ge197136389 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#90072): https://edk2.groups.io/g/devel/message/90072 Mute This Topic: https://groups.io/mt/91368912/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-