nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0174-calibrate_tsc-use-the-Stall-EFI-boot-service-on-GRUB.patch

ecb9bb
From af355a7fe160c6c798e416f8f14e059aaf16ea13 Mon Sep 17 00:00:00 2001
ecb9bb
From: Laszlo Ersek <lersek@redhat.com>
ecb9bb
Date: Fri, 10 Oct 2014 11:11:09 +0200
ecb9bb
Subject: [PATCH 17/23] calibrate_tsc(): use the Stall() EFI boot service on
ecb9bb
 GRUB_MACHINE_EFI
ecb9bb
ecb9bb
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1150698
ecb9bb
ecb9bb
HyperV Gen2 virtual machines have no PIT; guest code should rely on UEFI
ecb9bb
services instead.
ecb9bb
ecb9bb
Signed-off-by: RHEL Ninjas <example@example.com>
ecb9bb
---
ecb9bb
 grub-core/kern/i386/tsc.c | 20 ++++++++++++++++----
ecb9bb
 1 file changed, 16 insertions(+), 4 deletions(-)
ecb9bb
ecb9bb
diff --git a/grub-core/kern/i386/tsc.c b/grub-core/kern/i386/tsc.c
ecb9bb
index 3a4cae6..e499648 100644
ecb9bb
--- a/grub-core/kern/i386/tsc.c
ecb9bb
+++ b/grub-core/kern/i386/tsc.c
ecb9bb
@@ -26,9 +26,14 @@
ecb9bb
 #include <grub/i386/tsc.h>
ecb9bb
 #include <grub/i386/cpuid.h>
ecb9bb
 #ifdef GRUB_MACHINE_XEN
ecb9bb
-#include <grub/xen.h>
ecb9bb
+# include <grub/xen.h>
ecb9bb
 #else
ecb9bb
-#include <grub/i386/pit.h>
ecb9bb
+# ifdef GRUB_MACHINE_EFI
ecb9bb
+#  include <grub/efi/efi.h>
ecb9bb
+#  include <grub/efi/api.h>
ecb9bb
+# else
ecb9bb
+#  include <grub/i386/pit.h>
ecb9bb
+# endif
ecb9bb
 #endif
ecb9bb
 #include <grub/cpu/io.h>
ecb9bb
 
ecb9bb
@@ -72,8 +77,14 @@ grub_cpu_is_tsc_supported (void)
ecb9bb
 #ifndef GRUB_MACHINE_XEN
ecb9bb
 
ecb9bb
 static void
ecb9bb
-grub_pit_wait (grub_uint16_t tics)
ecb9bb
+grub_stall (grub_uint16_t tics)
ecb9bb
 {
ecb9bb
+# ifdef GRUB_MACHINE_EFI
ecb9bb
+  grub_uint64_t microseconds;
ecb9bb
+
ecb9bb
+  microseconds = (grub_uint64_t)tics * 1000 * 1000 * 3 / 3579545;
ecb9bb
+  efi_call_1 (grub_efi_system_table->boot_services->stall, microseconds);
ecb9bb
+# else
ecb9bb
   /* Disable timer2 gate and speaker.  */
ecb9bb
   grub_outb (grub_inb (GRUB_PIT_SPEAKER_PORT)
ecb9bb
 	     & ~ (GRUB_PIT_SPK_DATA | GRUB_PIT_SPK_TMR2),
ecb9bb
@@ -97,6 +108,7 @@ grub_pit_wait (grub_uint16_t tics)
ecb9bb
   grub_outb (grub_inb (GRUB_PIT_SPEAKER_PORT)
ecb9bb
 	     & ~ (GRUB_PIT_SPK_DATA | GRUB_PIT_SPK_TMR2),
ecb9bb
              GRUB_PIT_SPEAKER_PORT);
ecb9bb
+# endif
ecb9bb
 }
ecb9bb
 #endif
ecb9bb
 
ecb9bb
@@ -119,7 +131,7 @@ calibrate_tsc (void)
ecb9bb
   grub_uint64_t end_tsc;
ecb9bb
 
ecb9bb
   tsc_boot_time = grub_get_tsc ();
ecb9bb
-  grub_pit_wait (0xffff);
ecb9bb
+  grub_stall (0xffff);
ecb9bb
   end_tsc = grub_get_tsc ();
ecb9bb
 
ecb9bb
   grub_tsc_rate = grub_divmod64 ((55ULL << 32), end_tsc - tsc_boot_time, 0);
ecb9bb
-- 
ecb9bb
2.4.3
ecb9bb