coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
arch_timer.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <timer.h>
4 #include <delay.h>
5 #include <cpu/power/spr.h>
6 
7 /* Refer to hostboot/src/kernel/timemgr.C */
8 
9 /* Time base frequency is 512 MHz so 512 ticks per usec */
10 #define TB_TICKS_PER_USEC 512
11 
12 __weak void init_timer(void) { /* do nothing */ }
13 
14 static struct monotonic_counter {
16  struct mono_time time;
19 
21 {
22  uint64_t current_tick;
23  uint64_t usecs_elapsed;
24 
28  }
29 
30  current_tick = read_spr(SPR_TB);
31  usecs_elapsed = (current_tick - mono_counter.last_value) / TB_TICKS_PER_USEC;
32 
33  /* Update current time and tick values only if a full tick occurred. */
34  if (usecs_elapsed) {
35  mono_time_add_usecs(&mono_counter.time, usecs_elapsed);
36  mono_counter.last_value = current_tick;
37  }
38 
39  /* Save result. */
40  *mt = mono_counter.time;
41 }
void timer_monotonic_get(struct mono_time *mt)
Definition: arch_timer.c:6
static void mono_time_add_usecs(struct mono_time *mt, long us)
Definition: timer.h:65
#define TB_TICKS_PER_USEC
Definition: arch_timer.c:10
__weak void init_timer(void)
Definition: arch_timer.c:12
static struct monotonic_counter mono_counter
const struct smm_save_state_ops *legacy_ops __weak
Definition: save_state.c:8
#define SPR_TB
Definition: spr.h:6
static uint64_t read_spr(int spr)
Definition: spr.h:38
unsigned long long uint64_t
Definition: stdint.h:17
uint64_t last_value
Definition: arch_timer.c:17
struct mono_time time
Definition: arch_timer.c:16