xref: /openbmc/qemu/target/alpha/clk_helper.c (revision 2df1eb27)
1 /*
2  *  QEMU Alpha clock helpers.
3  *
4  *  Copyright (c) 2007 Jocelyn Mayer
5  *
6  * SPDX-License-Identifier: LGPL-2.1-or-later
7  */
8 
9 #include "qemu/osdep.h"
10 #include "qemu/timer.h"
11 #include "exec/helper-proto.h"
12 #include "cpu.h"
13 
14 uint64_t helper_load_pcc(CPUAlphaState *env)
15 {
16 #ifndef CONFIG_USER_ONLY
17     /*
18      * In system mode we have access to a decent high-resolution clock.
19      * In order to make OS-level time accounting work with the RPCC,
20      * present it with a well-timed clock fixed at 250MHz.
21      */
22     return (((uint64_t)env->pcc_ofs << 32)
23             | (uint32_t)(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) >> 2));
24 #else
25     /*
26      * In user-mode, QEMU_CLOCK_VIRTUAL doesn't exist.  Just pass through
27      * the host cpu clock ticks.  Also, don't bother taking PCC_OFS into
28      * account.
29      */
30     return (uint32_t)cpu_get_host_ticks();
31 #endif
32 }
33