| Andrew Walbran | 508e63c | 2018-12-20 17:02:37 +0000 | [diff] [blame] | 1 | /* | 
| Andrew Walbran | 692b325 | 2019-03-07 15:51:31 +0000 | [diff] [blame] | 2 | * Copyright 2018 The Hafnium Authors. | 
| Andrew Walbran | 508e63c | 2018-12-20 17:02:37 +0000 | [diff] [blame] | 3 | * | 
| Andrew Walbran | e959ec1 | 2020-06-17 15:01:09 +0100 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style | 
|  | 5 | * license that can be found in the LICENSE file or at | 
|  | 6 | * https://opensource.org/licenses/BSD-3-Clause. | 
| Andrew Walbran | 508e63c | 2018-12-20 17:02:37 +0000 | [diff] [blame] | 7 | */ | 
|  | 8 |  | 
|  | 9 | #pragma once | 
|  | 10 |  | 
|  | 11 | #include <stdbool.h> | 
|  | 12 | #include <stdint.h> | 
|  | 13 |  | 
|  | 14 | #include "hf/arch/types.h" | 
|  | 15 |  | 
|  | 16 | /** | 
|  | 17 | * Sets the bit to mask virtual timer interrupts. | 
|  | 18 | */ | 
|  | 19 | void arch_timer_mask(struct arch_regs *regs); | 
|  | 20 |  | 
|  | 21 | /** | 
|  | 22 | * Checks whether the virtual timer is enabled and its interrupt not masked. | 
|  | 23 | */ | 
|  | 24 | bool arch_timer_enabled(struct arch_regs *regs); | 
|  | 25 |  | 
|  | 26 | /** | 
| Andrew Walbran | 508e63c | 2018-12-20 17:02:37 +0000 | [diff] [blame] | 27 | * Returns the number of nanoseconds remaining on the virtual timer as stored in | 
|  | 28 | * the given `arch_regs`, or 0 if it has already expired. This is undefined if | 
|  | 29 | * the timer is not enabled. | 
|  | 30 | */ | 
|  | 31 | uint64_t arch_timer_remaining_ns(struct arch_regs *regs); | 
|  | 32 |  | 
|  | 33 | /** | 
|  | 34 | * Returns whether the timer is ready to fire: i.e. it is enabled, not masked, | 
|  | 35 | * and the condition is met. | 
|  | 36 | */ | 
|  | 37 | bool arch_timer_pending(struct arch_regs *regs); | 
|  | 38 |  | 
|  | 39 | /** | 
|  | 40 | * Checks whether the virtual timer is enabled and its interrupt not masked, for | 
|  | 41 | * the currently active vCPU. | 
|  | 42 | */ | 
|  | 43 | bool arch_timer_enabled_current(void); | 
|  | 44 |  | 
|  | 45 | /** | 
| Andrew Walbran | 3364565 | 2019-04-15 12:29:31 +0100 | [diff] [blame] | 46 | * Disable the virtual timer for the currently active vCPU. | 
|  | 47 | */ | 
|  | 48 | void arch_timer_disable_current(void); | 
|  | 49 |  | 
|  | 50 | /** | 
| Andrew Walbran | 508e63c | 2018-12-20 17:02:37 +0000 | [diff] [blame] | 51 | * Returns the number of nanoseconds remaining on the virtual timer of the | 
|  | 52 | * currently active vCPU, or 0 if it has already expired. This is undefined if | 
|  | 53 | * the timer is not enabled. | 
|  | 54 | */ | 
|  | 55 | uint64_t arch_timer_remaining_ns_current(void); |