162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2012 ARM Ltd. 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci#ifndef __CLKSOURCE_ARM_ARCH_TIMER_H 662306a36Sopenharmony_ci#define __CLKSOURCE_ARM_ARCH_TIMER_H 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#include <linux/bitops.h> 962306a36Sopenharmony_ci#include <linux/timecounter.h> 1062306a36Sopenharmony_ci#include <linux/types.h> 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#define ARCH_TIMER_TYPE_CP15 BIT(0) 1362306a36Sopenharmony_ci#define ARCH_TIMER_TYPE_MEM BIT(1) 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#define ARCH_TIMER_CTRL_ENABLE (1 << 0) 1662306a36Sopenharmony_ci#define ARCH_TIMER_CTRL_IT_MASK (1 << 1) 1762306a36Sopenharmony_ci#define ARCH_TIMER_CTRL_IT_STAT (1 << 2) 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci#define CNTHCTL_EL1PCTEN (1 << 0) 2062306a36Sopenharmony_ci#define CNTHCTL_EL1PCEN (1 << 1) 2162306a36Sopenharmony_ci#define CNTHCTL_EVNTEN (1 << 2) 2262306a36Sopenharmony_ci#define CNTHCTL_EVNTDIR (1 << 3) 2362306a36Sopenharmony_ci#define CNTHCTL_EVNTI (0xF << 4) 2462306a36Sopenharmony_ci#define CNTHCTL_ECV (1 << 12) 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_cienum arch_timer_reg { 2762306a36Sopenharmony_ci ARCH_TIMER_REG_CTRL, 2862306a36Sopenharmony_ci ARCH_TIMER_REG_CVAL, 2962306a36Sopenharmony_ci}; 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_cienum arch_timer_ppi_nr { 3262306a36Sopenharmony_ci ARCH_TIMER_PHYS_SECURE_PPI, 3362306a36Sopenharmony_ci ARCH_TIMER_PHYS_NONSECURE_PPI, 3462306a36Sopenharmony_ci ARCH_TIMER_VIRT_PPI, 3562306a36Sopenharmony_ci ARCH_TIMER_HYP_PPI, 3662306a36Sopenharmony_ci ARCH_TIMER_HYP_VIRT_PPI, 3762306a36Sopenharmony_ci ARCH_TIMER_MAX_TIMER_PPI 3862306a36Sopenharmony_ci}; 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_cienum arch_timer_spi_nr { 4162306a36Sopenharmony_ci ARCH_TIMER_PHYS_SPI, 4262306a36Sopenharmony_ci ARCH_TIMER_VIRT_SPI, 4362306a36Sopenharmony_ci ARCH_TIMER_MAX_TIMER_SPI 4462306a36Sopenharmony_ci}; 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci#define ARCH_TIMER_PHYS_ACCESS 0 4762306a36Sopenharmony_ci#define ARCH_TIMER_VIRT_ACCESS 1 4862306a36Sopenharmony_ci#define ARCH_TIMER_MEM_PHYS_ACCESS 2 4962306a36Sopenharmony_ci#define ARCH_TIMER_MEM_VIRT_ACCESS 3 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci#define ARCH_TIMER_MEM_MAX_FRAMES 8 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci#define ARCH_TIMER_USR_PCT_ACCESS_EN (1 << 0) /* physical counter */ 5462306a36Sopenharmony_ci#define ARCH_TIMER_USR_VCT_ACCESS_EN (1 << 1) /* virtual counter */ 5562306a36Sopenharmony_ci#define ARCH_TIMER_VIRT_EVT_EN (1 << 2) 5662306a36Sopenharmony_ci#define ARCH_TIMER_EVT_TRIGGER_SHIFT (4) 5762306a36Sopenharmony_ci#define ARCH_TIMER_EVT_TRIGGER_MASK (0xF << ARCH_TIMER_EVT_TRIGGER_SHIFT) 5862306a36Sopenharmony_ci#define ARCH_TIMER_USR_VT_ACCESS_EN (1 << 8) /* virtual timer registers */ 5962306a36Sopenharmony_ci#define ARCH_TIMER_USR_PT_ACCESS_EN (1 << 9) /* physical timer registers */ 6062306a36Sopenharmony_ci#define ARCH_TIMER_EVT_INTERVAL_SCALE (1 << 17) /* EVNTIS in the ARMv8 ARM */ 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci#define ARCH_TIMER_EVT_STREAM_PERIOD_US 100 6362306a36Sopenharmony_ci#define ARCH_TIMER_EVT_STREAM_FREQ \ 6462306a36Sopenharmony_ci (USEC_PER_SEC / ARCH_TIMER_EVT_STREAM_PERIOD_US) 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_cistruct arch_timer_kvm_info { 6762306a36Sopenharmony_ci struct timecounter timecounter; 6862306a36Sopenharmony_ci int virtual_irq; 6962306a36Sopenharmony_ci int physical_irq; 7062306a36Sopenharmony_ci}; 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_cistruct arch_timer_mem_frame { 7362306a36Sopenharmony_ci bool valid; 7462306a36Sopenharmony_ci phys_addr_t cntbase; 7562306a36Sopenharmony_ci size_t size; 7662306a36Sopenharmony_ci int phys_irq; 7762306a36Sopenharmony_ci int virt_irq; 7862306a36Sopenharmony_ci}; 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_cistruct arch_timer_mem { 8162306a36Sopenharmony_ci phys_addr_t cntctlbase; 8262306a36Sopenharmony_ci size_t size; 8362306a36Sopenharmony_ci struct arch_timer_mem_frame frame[ARCH_TIMER_MEM_MAX_FRAMES]; 8462306a36Sopenharmony_ci}; 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci#ifdef CONFIG_ARM_ARCH_TIMER 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ciextern u32 arch_timer_get_rate(void); 8962306a36Sopenharmony_ciextern u64 (*arch_timer_read_counter)(void); 9062306a36Sopenharmony_ciextern struct arch_timer_kvm_info *arch_timer_get_kvm_info(void); 9162306a36Sopenharmony_ciextern bool arch_timer_evtstrm_available(void); 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci#else 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_cistatic inline u32 arch_timer_get_rate(void) 9662306a36Sopenharmony_ci{ 9762306a36Sopenharmony_ci return 0; 9862306a36Sopenharmony_ci} 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_cistatic inline u64 arch_timer_read_counter(void) 10162306a36Sopenharmony_ci{ 10262306a36Sopenharmony_ci return 0; 10362306a36Sopenharmony_ci} 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_cistatic inline bool arch_timer_evtstrm_available(void) 10662306a36Sopenharmony_ci{ 10762306a36Sopenharmony_ci return false; 10862306a36Sopenharmony_ci} 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci#endif 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ci#endif 113