Lee Leahy | 87df8d0 | 2016-02-07 14:37:13 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013 Google Inc. |
| 5 | * Copyright (C) 2015-2016 Intel Corporation. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
| 17 | #include <stdint.h> |
| 18 | #include <cpu/x86/msr.h> |
| 19 | #include <cpu/x86/tsc.h> |
Lee Leahy | 68fdb78 | 2016-12-31 08:21:56 -0800 | [diff] [blame] | 20 | #include <timer.h> |
Lee Leahy | 87df8d0 | 2016-02-07 14:37:13 -0800 | [diff] [blame] | 21 | |
| 22 | unsigned long tsc_freq_mhz(void) |
| 23 | { |
Lee Leahy | 68fdb78 | 2016-12-31 08:21:56 -0800 | [diff] [blame] | 24 | /* CPU freq = 400 MHz */ |
| 25 | return 400; |
| 26 | } |
Lee Leahy | 87df8d0 | 2016-02-07 14:37:13 -0800 | [diff] [blame] | 27 | |
Lee Leahy | 68fdb78 | 2016-12-31 08:21:56 -0800 | [diff] [blame] | 28 | void timer_monotonic_get(struct mono_time *mt) |
| 29 | { |
| 30 | uint64_t tsc_value; |
Lee Leahy | 87df8d0 | 2016-02-07 14:37:13 -0800 | [diff] [blame] | 31 | |
Lee Leahy | 68fdb78 | 2016-12-31 08:21:56 -0800 | [diff] [blame] | 32 | tsc_value = rdtscll(); |
| 33 | mt->microseconds = tsc_value / tsc_freq_mhz(); |
Lee Leahy | 87df8d0 | 2016-02-07 14:37:13 -0800 | [diff] [blame] | 34 | } |