x86: timer: Use a separate flag for whether timer is inited
authorSimon Glass <sjg@chromium.org>
Mon, 21 Oct 2019 03:37:47 +0000 (21:37 -0600)
committerBin Meng <bmeng.cn@gmail.com>
Sat, 2 Nov 2019 23:20:27 +0000 (07:20 +0800)
At present the value of the timer base is used to determine whether the
timer has been set up or not. It is true that the timer is essentially
never exactly 0 when it is read. However 'time 0' may indicate the time
that the machine was reset so it is useful to be able to denote that.

Update the code to use a separate flag instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Aiden Park <aiden.park@intel.com>
Reviewed-by: Aiden Park <aiden.park@intel.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
arch/x86/include/asm/global_data.h
drivers/timer/tsc_timer.c

index 17a4d344913ffbb4532ff03c4939368e89baf6c3..7f3ada06f6166b0916c79455511fe42864476248 100644 (file)
@@ -76,6 +76,7 @@ struct arch_global_data {
        uint8_t x86_mask;
        uint32_t x86_device;
        uint64_t tsc_base;              /* Initial value returned by rdtsc() */
+       bool tsc_inited;                /* true if tsc is ready for use */
        unsigned long clock_rate;       /* Clock rate of timer in Hz */
        void *new_fdt;                  /* Relocated FDT */
        uint32_t bist;                  /* Built-in self test value */
index f19d2237e4f33818079592e1f27648aebd240b6e..637c8ff25a5cab47aee23201d28a0ef26de11b41 100644 (file)
@@ -394,7 +394,7 @@ static int tsc_timer_get_count(struct udevice *dev, u64 *count)
 
 static void tsc_timer_ensure_setup(bool early)
 {
-       if (gd->arch.tsc_base)
+       if (gd->arch.tsc_inited)
                return;
        gd->arch.tsc_base = rdtsc();
 
@@ -425,6 +425,7 @@ static void tsc_timer_ensure_setup(bool early)
 done:
                gd->arch.clock_rate = fast_calibrate * 1000000;
        }
+       gd->arch.tsc_inited = true;
 }
 
 static int tsc_timer_probe(struct udevice *dev)