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

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