18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2012 ARM Ltd. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci#ifndef __CLKSOURCE_ARM_ARCH_TIMER_H 68c2ecf20Sopenharmony_ci#define __CLKSOURCE_ARM_ARCH_TIMER_H 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/bitops.h> 98c2ecf20Sopenharmony_ci#include <linux/timecounter.h> 108c2ecf20Sopenharmony_ci#include <linux/types.h> 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#define ARCH_TIMER_TYPE_CP15 BIT(0) 138c2ecf20Sopenharmony_ci#define ARCH_TIMER_TYPE_MEM BIT(1) 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define ARCH_TIMER_CTRL_ENABLE (1 << 0) 168c2ecf20Sopenharmony_ci#define ARCH_TIMER_CTRL_IT_MASK (1 << 1) 178c2ecf20Sopenharmony_ci#define ARCH_TIMER_CTRL_IT_STAT (1 << 2) 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define CNTHCTL_EL1PCTEN (1 << 0) 208c2ecf20Sopenharmony_ci#define CNTHCTL_EL1PCEN (1 << 1) 218c2ecf20Sopenharmony_ci#define CNTHCTL_EVNTEN (1 << 2) 228c2ecf20Sopenharmony_ci#define CNTHCTL_EVNTDIR (1 << 3) 238c2ecf20Sopenharmony_ci#define CNTHCTL_EVNTI (0xF << 4) 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_cienum arch_timer_reg { 268c2ecf20Sopenharmony_ci ARCH_TIMER_REG_CTRL, 278c2ecf20Sopenharmony_ci ARCH_TIMER_REG_TVAL, 288c2ecf20Sopenharmony_ci}; 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_cienum arch_timer_ppi_nr { 318c2ecf20Sopenharmony_ci ARCH_TIMER_PHYS_SECURE_PPI, 328c2ecf20Sopenharmony_ci ARCH_TIMER_PHYS_NONSECURE_PPI, 338c2ecf20Sopenharmony_ci ARCH_TIMER_VIRT_PPI, 348c2ecf20Sopenharmony_ci ARCH_TIMER_HYP_PPI, 358c2ecf20Sopenharmony_ci ARCH_TIMER_MAX_TIMER_PPI 368c2ecf20Sopenharmony_ci}; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_cienum arch_timer_spi_nr { 398c2ecf20Sopenharmony_ci ARCH_TIMER_PHYS_SPI, 408c2ecf20Sopenharmony_ci ARCH_TIMER_VIRT_SPI, 418c2ecf20Sopenharmony_ci ARCH_TIMER_MAX_TIMER_SPI 428c2ecf20Sopenharmony_ci}; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci#define ARCH_TIMER_PHYS_ACCESS 0 458c2ecf20Sopenharmony_ci#define ARCH_TIMER_VIRT_ACCESS 1 468c2ecf20Sopenharmony_ci#define ARCH_TIMER_MEM_PHYS_ACCESS 2 478c2ecf20Sopenharmony_ci#define ARCH_TIMER_MEM_VIRT_ACCESS 3 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci#define ARCH_TIMER_MEM_MAX_FRAMES 8 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci#define ARCH_TIMER_USR_PCT_ACCESS_EN (1 << 0) /* physical counter */ 528c2ecf20Sopenharmony_ci#define ARCH_TIMER_USR_VCT_ACCESS_EN (1 << 1) /* virtual counter */ 538c2ecf20Sopenharmony_ci#define ARCH_TIMER_VIRT_EVT_EN (1 << 2) 548c2ecf20Sopenharmony_ci#define ARCH_TIMER_EVT_TRIGGER_SHIFT (4) 558c2ecf20Sopenharmony_ci#define ARCH_TIMER_EVT_TRIGGER_MASK (0xF << ARCH_TIMER_EVT_TRIGGER_SHIFT) 568c2ecf20Sopenharmony_ci#define ARCH_TIMER_USR_VT_ACCESS_EN (1 << 8) /* virtual timer registers */ 578c2ecf20Sopenharmony_ci#define ARCH_TIMER_USR_PT_ACCESS_EN (1 << 9) /* physical timer registers */ 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci#define ARCH_TIMER_EVT_STREAM_PERIOD_US 100 608c2ecf20Sopenharmony_ci#define ARCH_TIMER_EVT_STREAM_FREQ \ 618c2ecf20Sopenharmony_ci (USEC_PER_SEC / ARCH_TIMER_EVT_STREAM_PERIOD_US) 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_cistruct arch_timer_kvm_info { 648c2ecf20Sopenharmony_ci struct timecounter timecounter; 658c2ecf20Sopenharmony_ci int virtual_irq; 668c2ecf20Sopenharmony_ci int physical_irq; 678c2ecf20Sopenharmony_ci}; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_cistruct arch_timer_mem_frame { 708c2ecf20Sopenharmony_ci bool valid; 718c2ecf20Sopenharmony_ci phys_addr_t cntbase; 728c2ecf20Sopenharmony_ci size_t size; 738c2ecf20Sopenharmony_ci int phys_irq; 748c2ecf20Sopenharmony_ci int virt_irq; 758c2ecf20Sopenharmony_ci}; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistruct arch_timer_mem { 788c2ecf20Sopenharmony_ci phys_addr_t cntctlbase; 798c2ecf20Sopenharmony_ci size_t size; 808c2ecf20Sopenharmony_ci struct arch_timer_mem_frame frame[ARCH_TIMER_MEM_MAX_FRAMES]; 818c2ecf20Sopenharmony_ci}; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci#ifdef CONFIG_ARM_ARCH_TIMER 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ciextern u32 arch_timer_get_rate(void); 868c2ecf20Sopenharmony_ciextern u64 (*arch_timer_read_counter)(void); 878c2ecf20Sopenharmony_ciextern struct arch_timer_kvm_info *arch_timer_get_kvm_info(void); 888c2ecf20Sopenharmony_ciextern bool arch_timer_evtstrm_available(void); 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci#else 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_cistatic inline u32 arch_timer_get_rate(void) 938c2ecf20Sopenharmony_ci{ 948c2ecf20Sopenharmony_ci return 0; 958c2ecf20Sopenharmony_ci} 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_cistatic inline u64 arch_timer_read_counter(void) 988c2ecf20Sopenharmony_ci{ 998c2ecf20Sopenharmony_ci return 0; 1008c2ecf20Sopenharmony_ci} 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_cistatic inline bool arch_timer_evtstrm_available(void) 1038c2ecf20Sopenharmony_ci{ 1048c2ecf20Sopenharmony_ci return false; 1058c2ecf20Sopenharmony_ci} 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci#endif 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci#endif 110