blob: f708f7b9d9c5e0e6e2af6dca6ec6d0548a39e9cf [file] [log] [blame]
Andrew Walbran508e63c2018-12-20 17:02:37 +00001/*
Andrew Walbran692b3252019-03-07 15:51:31 +00002 * Copyright 2018 The Hafnium Authors.
Andrew Walbran508e63c2018-12-20 17:02:37 +00003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <stdbool.h>
20#include <stdint.h>
21
22#include "hf/arch/types.h"
23
24/**
25 * Sets the bit to mask virtual timer interrupts.
26 */
27void arch_timer_mask(struct arch_regs *regs);
28
29/**
30 * Checks whether the virtual timer is enabled and its interrupt not masked.
31 */
32bool arch_timer_enabled(struct arch_regs *regs);
33
34/**
35 * Returns the number of ticks remaining on the virtual timer as stored in
36 * the given `arch_regs`, or 0 if it has already expired. This is undefined if
37 * the timer is not enabled.
38 */
39uint64_t arch_timer_remaining_ticks(struct arch_regs *regs);
40
41/**
42 * Returns the number of nanoseconds remaining on the virtual timer as stored in
43 * the given `arch_regs`, or 0 if it has already expired. This is undefined if
44 * the timer is not enabled.
45 */
46uint64_t arch_timer_remaining_ns(struct arch_regs *regs);
47
48/**
49 * Returns whether the timer is ready to fire: i.e. it is enabled, not masked,
50 * and the condition is met.
51 */
52bool arch_timer_pending(struct arch_regs *regs);
53
54/**
55 * Checks whether the virtual timer is enabled and its interrupt not masked, for
56 * the currently active vCPU.
57 */
58bool arch_timer_enabled_current(void);
59
60/**
Andrew Walbran33645652019-04-15 12:29:31 +010061 * Disable the virtual timer for the currently active vCPU.
62 */
63void arch_timer_disable_current(void);
64
65/**
Andrew Walbran508e63c2018-12-20 17:02:37 +000066 * Returns the number of ticks remaining on the virtual timer of the currently
67 * active vCPU, or 0 if it has already expired. This is undefined if the timer
68 * is not enabled.
69 */
70uint64_t arch_timer_remaining_ticks_current(void);
71
72/**
73 * Returns the number of nanoseconds remaining on the virtual timer of the
74 * currently active vCPU, or 0 if it has already expired. This is undefined if
75 * the timer is not enabled.
76 */
77uint64_t arch_timer_remaining_ns_current(void);