1c085f386SAlexander von Gluck IV /* 2c15bf9b7SX512 * Copyright 2019-2021, Haiku Inc. All rights reserved. 3c085f386SAlexander von Gluck IV * Distributed under the terms of the MIT License. 4c085f386SAlexander von Gluck IV * 5c085f386SAlexander von Gluck IV * Authors: 6c085f386SAlexander von Gluck IV * Adrien Destugues <pulkomandy@pulkomandy.tk> 7c085f386SAlexander von Gluck IV */ 8c085f386SAlexander von Gluck IV 9c085f386SAlexander von Gluck IV 10c15bf9b7SX512 #include <arch_cpu_defs.h> 11c15bf9b7SX512 #include <arch_int.h> 12c085f386SAlexander von Gluck IV #include <arch/timer.h> 13c15bf9b7SX512 #include <boot/kernel_args.h> 14c15bf9b7SX512 #include <debug.h> 15c15bf9b7SX512 #include <kernel.h> 16c15bf9b7SX512 #include <platform/sbi/sbi_syscalls.h> 17c15bf9b7SX512 #include <timer.h> 18c15bf9b7SX512 #include <Clint.h> 19c15bf9b7SX512 20*8ca0f03dSX512 #include <smp.h> 21*8ca0f03dSX512 22c15bf9b7SX512 23fa41d6faSX512 extern uint32 gPlatform; 24c085f386SAlexander von Gluck IV 25c085f386SAlexander von Gluck IV 26c085f386SAlexander von Gluck IV void 27c085f386SAlexander von Gluck IV arch_timer_set_hardware_timer(bigtime_t timeout) 28c085f386SAlexander von Gluck IV { 29*8ca0f03dSX512 // dprintf("arch_timer_set_hardware_timer(%" B_PRIu64 "), cpu: %" B_PRId32 "\n", timeout, smp_get_current_cpu()); 30*8ca0f03dSX512 31c15bf9b7SX512 // TODO: Read timer frequency from FDT 32fa41d6faSX512 switch (gPlatform) { 33fa41d6faSX512 case kPlatformMNative: 34c15bf9b7SX512 MSyscall(kMSyscallSetTimer, true, 35c15bf9b7SX512 gClintRegs->mtime + timeout * 10); 36c15bf9b7SX512 break; 37fa41d6faSX512 case kPlatformSbi: { 38c15bf9b7SX512 sbi_set_timer(CpuTime() + timeout); 39c15bf9b7SX512 break; 40c15bf9b7SX512 } 41c15bf9b7SX512 default: 42c15bf9b7SX512 ; 43c15bf9b7SX512 } 44*8ca0f03dSX512 45*8ca0f03dSX512 // SetSie(Sie() | (1 << sTimerInt)); 46c085f386SAlexander von Gluck IV } 47c085f386SAlexander von Gluck IV 48c085f386SAlexander von Gluck IV 49c085f386SAlexander von Gluck IV void 50c085f386SAlexander von Gluck IV arch_timer_clear_hardware_timer() 51c085f386SAlexander von Gluck IV { 52*8ca0f03dSX512 // SetSie(Sie() & ~(1 << sTimerInt)); 53*8ca0f03dSX512 54fa41d6faSX512 switch (gPlatform) { 55fa41d6faSX512 case kPlatformMNative: 56c15bf9b7SX512 MSyscall(kMSyscallSetTimer, false); 57c15bf9b7SX512 break; 58fa41d6faSX512 case kPlatformSbi: { 59c15bf9b7SX512 sbi_set_timer(CpuTime() + (uint64)10000000 * 3600); 60c15bf9b7SX512 break; 61c15bf9b7SX512 } 62c15bf9b7SX512 default: 63c15bf9b7SX512 ; 64c15bf9b7SX512 } 65c085f386SAlexander von Gluck IV } 66c085f386SAlexander von Gluck IV 67c085f386SAlexander von Gluck IV 68c085f386SAlexander von Gluck IV int 69c085f386SAlexander von Gluck IV arch_init_timer(kernel_args *args) 70c085f386SAlexander von Gluck IV { 71c085f386SAlexander von Gluck IV return B_OK; 72c085f386SAlexander von Gluck IV } 73