18a4da6e3SMark Rutland /* 28a4da6e3SMark Rutland * Copyright (C) 2012 ARM Ltd. 38a4da6e3SMark Rutland * 48a4da6e3SMark Rutland * This program is free software; you can redistribute it and/or modify 58a4da6e3SMark Rutland * it under the terms of the GNU General Public License version 2 as 68a4da6e3SMark Rutland * published by the Free Software Foundation. 78a4da6e3SMark Rutland * 88a4da6e3SMark Rutland * This program is distributed in the hope that it will be useful, 98a4da6e3SMark Rutland * but WITHOUT ANY WARRANTY; without even the implied warranty of 108a4da6e3SMark Rutland * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 118a4da6e3SMark Rutland * GNU General Public License for more details. 128a4da6e3SMark Rutland * 138a4da6e3SMark Rutland * You should have received a copy of the GNU General Public License 148a4da6e3SMark Rutland * along with this program. If not, see <http://www.gnu.org/licenses/>. 158a4da6e3SMark Rutland */ 168a4da6e3SMark Rutland #ifndef __CLKSOURCE_ARM_ARCH_TIMER_H 178a4da6e3SMark Rutland #define __CLKSOURCE_ARM_ARCH_TIMER_H 188a4da6e3SMark Rutland 1974d23cc7SRichard Cochran #include <linux/timecounter.h> 208a4da6e3SMark Rutland #include <linux/types.h> 218a4da6e3SMark Rutland 228a4da6e3SMark Rutland #define ARCH_TIMER_CTRL_ENABLE (1 << 0) 238a4da6e3SMark Rutland #define ARCH_TIMER_CTRL_IT_MASK (1 << 1) 248a4da6e3SMark Rutland #define ARCH_TIMER_CTRL_IT_STAT (1 << 2) 258a4da6e3SMark Rutland 261431af36SMarc Zyngier #define CNTHCTL_EL1PCTEN (1 << 0) 271431af36SMarc Zyngier #define CNTHCTL_EL1PCEN (1 << 1) 281431af36SMarc Zyngier #define CNTHCTL_EVNTEN (1 << 2) 291431af36SMarc Zyngier #define CNTHCTL_EVNTDIR (1 << 3) 301431af36SMarc Zyngier #define CNTHCTL_EVNTI (0xF << 4) 311431af36SMarc Zyngier 32e09f3cc0SStephen Boyd enum arch_timer_reg { 33e09f3cc0SStephen Boyd ARCH_TIMER_REG_CTRL, 34e09f3cc0SStephen Boyd ARCH_TIMER_REG_TVAL, 35e09f3cc0SStephen Boyd }; 368a4da6e3SMark Rutland 378a4da6e3SMark Rutland #define ARCH_TIMER_PHYS_ACCESS 0 388a4da6e3SMark Rutland #define ARCH_TIMER_VIRT_ACCESS 1 3922006994SStephen Boyd #define ARCH_TIMER_MEM_PHYS_ACCESS 2 4022006994SStephen Boyd #define ARCH_TIMER_MEM_VIRT_ACCESS 3 418a4da6e3SMark Rutland 4228061758SSudeep KarkadaNagesha #define ARCH_TIMER_USR_PCT_ACCESS_EN (1 << 0) /* physical counter */ 4328061758SSudeep KarkadaNagesha #define ARCH_TIMER_USR_VCT_ACCESS_EN (1 << 1) /* virtual counter */ 4428061758SSudeep KarkadaNagesha #define ARCH_TIMER_VIRT_EVT_EN (1 << 2) 4528061758SSudeep KarkadaNagesha #define ARCH_TIMER_EVT_TRIGGER_SHIFT (4) 4628061758SSudeep KarkadaNagesha #define ARCH_TIMER_EVT_TRIGGER_MASK (0xF << ARCH_TIMER_EVT_TRIGGER_SHIFT) 4728061758SSudeep KarkadaNagesha #define ARCH_TIMER_USR_VT_ACCESS_EN (1 << 8) /* virtual timer registers */ 4828061758SSudeep KarkadaNagesha #define ARCH_TIMER_USR_PT_ACCESS_EN (1 << 9) /* physical timer registers */ 4928061758SSudeep KarkadaNagesha 50037f6377SWill Deacon #define ARCH_TIMER_EVT_STREAM_FREQ 10000 /* 100us */ 51037f6377SWill Deacon 52b4d6ce97SJulien Grall struct arch_timer_kvm_info { 53b4d6ce97SJulien Grall struct timecounter timecounter; 54d9b5e415SJulien Grall int virtual_irq; 55b4d6ce97SJulien Grall }; 56b4d6ce97SJulien Grall 578a4da6e3SMark Rutland #ifdef CONFIG_ARM_ARCH_TIMER 588a4da6e3SMark Rutland 598a4da6e3SMark Rutland extern u32 arch_timer_get_rate(void); 6022006994SStephen Boyd extern u64 (*arch_timer_read_counter)(void); 618a4da6e3SMark Rutland extern struct timecounter *arch_timer_get_timecounter(void); 62b4d6ce97SJulien Grall extern struct arch_timer_kvm_info *arch_timer_get_kvm_info(void); 638a4da6e3SMark Rutland 648a4da6e3SMark Rutland #else 658a4da6e3SMark Rutland 668a4da6e3SMark Rutland static inline u32 arch_timer_get_rate(void) 678a4da6e3SMark Rutland { 688a4da6e3SMark Rutland return 0; 698a4da6e3SMark Rutland } 708a4da6e3SMark Rutland 718a4da6e3SMark Rutland static inline u64 arch_timer_read_counter(void) 728a4da6e3SMark Rutland { 738a4da6e3SMark Rutland return 0; 748a4da6e3SMark Rutland } 758a4da6e3SMark Rutland 760582b053SOlof Johansson static inline struct timecounter *arch_timer_get_timecounter(void) 778a4da6e3SMark Rutland { 788a4da6e3SMark Rutland return NULL; 798a4da6e3SMark Rutland } 808a4da6e3SMark Rutland 818a4da6e3SMark Rutland #endif 828a4da6e3SMark Rutland 838a4da6e3SMark Rutland #endif 84