1 /* Copyright 2018 SiFive, Inc */
2 /* SPDX-License-Identifier: Apache-2.0 */
7 #include <metal/timer.h>
8 #include <metal/machine.h>
10 #if defined(__METAL_DT_MAX_HARTS)
11 /* This implementation serves as a small shim that interfaces with the first
12 * timer on a system. */
13 int metal_timer_get_cyclecount(int hartid, unsigned long long *mcc)
15 struct metal_cpu *cpu = metal_cpu_get(hartid);
18 *mcc = metal_cpu_get_timer(cpu);
24 int metal_timer_get_timebase_frequency(int hartid, unsigned long long *timebase)
26 struct metal_cpu *cpu = metal_cpu_get(hartid);
29 *timebase = metal_cpu_get_timebase(cpu);
35 int metal_timer_get_machine_time(int hartid)
37 struct metal_cpu *cpu = metal_cpu_get(hartid);
40 return metal_cpu_get_mtime(cpu);
45 int metal_timer_set_machine_time(int hartid, unsigned long long time)
47 struct metal_cpu *cpu = metal_cpu_get(hartid);
50 return metal_cpu_set_mtimecmp(cpu, time);
57 /* This implementation of gettimeofday doesn't actually do anything, it's just there to
58 * provide a shim and return 0 so we can ensure that everything can link to _gettimeofday.
60 int nop_cyclecount(int id, unsigned long long *c) __attribute__((section(".text.metal.nop.cyclecount")));
61 int nop_cyclecount(int id, unsigned long long *c) { return -1; }
62 int nop_timebase(unsigned long long *t) __attribute__((section(".text.metal.nop.timebase")));
63 int nop_timebase(unsigned long long *t) { return -1; }
64 int nop_tick(int second) __attribute__((section(".text.metal.nop.tick")));
65 int nop_tick(int second) { return -1; }
66 int metal_timer_get_cyclecount(int hartid, unsigned long long *c) __attribute__((weak, alias("nop_cyclecount")))
68 #pragma message("There is no default timer device, metal_timer_get_cyclecount() will always return cyclecount -1.")
70 int metal_timer_get_timebase_frequency(unsigned long long *t) __attribute__((weak, alias("nop_timebase")))
72 #pragma message("There is no default timer device, metal_timer_get_timebase_frequency() will always return timebase -1.")
74 int metal_timer_set_tick(int second) __attribute__((weak, alias("nop_tick")))
76 #pragma message("There is no default timer device, metal_timer_set_tick) will always return -1.")