Andrew Walbran | 508e63c | 2018-12-20 17:02:37 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2018 Google LLC |
| 3 | * |
| 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 | */ |
| 27 | void arch_timer_mask(struct arch_regs *regs); |
| 28 | |
| 29 | /** |
| 30 | * Checks whether the virtual timer is enabled and its interrupt not masked. |
| 31 | */ |
| 32 | bool 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 | */ |
| 39 | uint64_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 | */ |
| 46 | uint64_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 | */ |
| 52 | bool 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 | */ |
| 58 | bool arch_timer_enabled_current(void); |
| 59 | |
| 60 | /** |
| 61 | * Returns the number of ticks remaining on the virtual timer of the currently |
| 62 | * active vCPU, or 0 if it has already expired. This is undefined if the timer |
| 63 | * is not enabled. |
| 64 | */ |
| 65 | uint64_t arch_timer_remaining_ticks_current(void); |
| 66 | |
| 67 | /** |
| 68 | * Returns the number of nanoseconds remaining on the virtual timer of the |
| 69 | * currently active vCPU, or 0 if it has already expired. This is undefined if |
| 70 | * the timer is not enabled. |
| 71 | */ |
| 72 | uint64_t arch_timer_remaining_ns_current(void); |