1/* 2 * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) 3 * 4 * SPDX-License-Identifier: GPL-2.0-only 5 */ 6 7#pragma once 8 9#include <config.h> 10#include <arch/model/statedata.h> 11#include <plat/machine.h> 12 13#ifdef CONFIG_KERNEL_MCS 14#include <mode/util.h> 15#include <arch/kernel/xapic.h> 16 17static inline CONST time_t getKernelWcetUs(void) 18{ 19 return 10u; 20} 21 22static inline PURE ticks_t usToTicks(time_t us) 23{ 24 assert(x86KStscMhz > 0); 25 return us * x86KStscMhz; 26} 27 28static inline PURE time_t getMaxUsToTicks(void) 29{ 30 return div64(UINT64_MAX, x86KStscMhz); 31} 32 33static inline PURE ticks_t getTimerPrecision(void) 34{ 35 return usToTicks(1u); 36} 37 38static inline void ackDeadlineIRQ(void) 39{ 40} 41 42static inline ticks_t getCurrentTime(void) 43{ 44 return x86_rdtsc(); 45} 46 47static inline CONST ticks_t getMaxTicksToUs(void) 48{ 49 return UINT64_MAX; 50} 51 52static inline PURE time_t ticksToUs(ticks_t ticks) 53{ 54 return div64(ticks, x86KStscMhz); 55} 56 57static inline void setDeadline(ticks_t deadline) 58{ 59 assert(deadline > NODE_STATE(ksCurTime)); 60 if (likely(x86KSapicRatio == 0)) { 61 x86_wrmsr(IA32_TSC_DEADLINE_MSR, deadline); 62 } else { 63 /* convert deadline from tscKhz to apic khz */ 64 deadline -= getCurrentTime(); 65 apic_write_reg(APIC_TIMER_COUNT, div64(deadline, x86KSapicRatio)); 66 } 67} 68#else 69static inline void resetTimer(void) 70{ 71 /* nothing to do */ 72} 73#endif /* CONFIG_KERNEL_MCS */ 74 75 76BOOT_CODE uint32_t tsc_init(void); 77 78