]> xenbits.xensource.com Git - seabios.git/commitdiff
timer: add tsctimer_setfreq()
authorGerd Hoffmann <kraxel@redhat.com>
Tue, 10 Mar 2020 10:22:45 +0000 (11:22 +0100)
committerGerd Hoffmann <kraxel@redhat.com>
Mon, 16 Mar 2020 13:29:41 +0000 (14:29 +0100)
Add function to set tsc frequency directly, without calibration.
Also tweak timer setup functions a bit: skip setup in case TimerPort
has not the default value any more, i.e. another timer has been setup
already.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-id: 20200310102248.28412-1-kraxel@redhat.com

src/hw/timer.c
src/util.h

index bdcb3bfca211417b00434318fec75ef3878131d1..56bb289a4adce30ce8afd4137440987957aacddd 100644 (file)
@@ -101,8 +101,10 @@ tsctimer_setup(void)
 void
 timer_setup(void)
 {
-    if (!CONFIG_TSC_TIMER || (CONFIG_PMTIMER && TimerPort != PORT_PIT_COUNTER0))
+    if (!CONFIG_TSC_TIMER)
         return;
+    if (TimerPort != PORT_PIT_COUNTER0)
+        return; // have timer already
 
     // Check if CPU has a timestamp counter
     u32 eax, ebx, ecx, edx, cpuid_features = 0;
@@ -113,11 +115,33 @@ timer_setup(void)
         tsctimer_setup();
 }
 
+void
+tsctimer_setfreq(u32 khz, const char *src)
+{
+    if (!CONFIG_TSC_TIMER)
+        return;
+    if (TimerPort != PORT_PIT_COUNTER0)
+        return; // have timer already
+
+    TimerKHz = khz;
+    ShiftTSC = 0;
+    while (TimerKHz >= 6000) {
+        ShiftTSC++;
+        TimerKHz = (TimerKHz + 1) >> 1;
+    }
+    TimerPort = 0;
+
+    dprintf(1, "CPU Mhz=%u (%s)\n", (TimerKHz << ShiftTSC) / 1000, src);
+}
+
 void
 pmtimer_setup(u16 ioport)
 {
     if (!CONFIG_PMTIMER)
         return;
+    if (TimerPort != PORT_PIT_COUNTER0)
+        return; // have timer already
+
     dprintf(1, "Using pmtimer, ioport 0x%x\n", ioport);
     TimerPort = ioport;
     TimerKHz = DIV_ROUND_UP(PMTIMER_HZ, 1000);
index d96db788d1b8fb207d3ab411addf4bb990940918..94592a2d2e8d56b9f1f3e2749bc848f1902578eb 100644 (file)
@@ -171,6 +171,7 @@ void sdcard_setup(void);
 // hw/timer.c
 void timer_setup(void);
 void pmtimer_setup(u16 ioport);
+void tsctimer_setfreq(u32 khz, const char *src);
 u32 timer_calc(u32 msecs);
 u32 timer_calc_usec(u32 usecs);
 int timer_check(u32 end);