blob: 46bb34b7da789be899bf8ac609c2d82ce67631ed [file] [log] [blame]
Felix Held4a8cd722020-04-18 22:26:39 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbin24079322018-01-23 10:53:05 -07002
3#include <cpu/x86/msr.h>
4#include <timer.h>
Aaron Durbin51e4c1a2018-01-24 17:42:51 -07005#include <timestamp.h>
Aaron Durbin24079322018-01-23 10:53:05 -07006
7#define CU_PTSC_MSR 0xc0010280
8#define PTSC_FREQ_MHZ 100
9
10void timer_monotonic_get(struct mono_time *mt)
11{
Aaron Durbin51e4c1a2018-01-24 17:42:51 -070012 mono_time_set_usecs(mt, timestamp_get());
13}
14
15uint64_t timestamp_get(void)
16{
Aaron Durbin24079322018-01-23 10:53:05 -070017 unsigned long long val;
18 msr_t msr;
19
20 msr = rdmsr(CU_PTSC_MSR);
21
22 val = ((unsigned long long)msr.hi << 32) | msr.lo;
23
Aaron Durbin51e4c1a2018-01-24 17:42:51 -070024 return val / PTSC_FREQ_MHZ;
Aaron Durbin24079322018-01-23 10:53:05 -070025}