18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* timer.h: System timer definitions for sun5. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (C) 1997, 2008 David S. Miller (davem@davemloft.net) 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#ifndef _SPARC64_TIMER_H 88c2ecf20Sopenharmony_ci#define _SPARC64_TIMER_H 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <uapi/asm/asi.h> 118c2ecf20Sopenharmony_ci#include <linux/types.h> 128c2ecf20Sopenharmony_ci#include <linux/init.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci/* The most frequently accessed fields should be first, 158c2ecf20Sopenharmony_ci * to fit into the same cacheline. 168c2ecf20Sopenharmony_ci */ 178c2ecf20Sopenharmony_cistruct sparc64_tick_ops { 188c2ecf20Sopenharmony_ci unsigned long ticks_per_nsec_quotient; 198c2ecf20Sopenharmony_ci unsigned long offset; 208c2ecf20Sopenharmony_ci unsigned long long (*get_tick)(void); 218c2ecf20Sopenharmony_ci int (*add_compare)(unsigned long); 228c2ecf20Sopenharmony_ci unsigned long softint_mask; 238c2ecf20Sopenharmony_ci void (*disable_irq)(void); 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci void (*init_tick)(void); 268c2ecf20Sopenharmony_ci unsigned long (*add_tick)(unsigned long); 278c2ecf20Sopenharmony_ci unsigned long (*get_frequency)(void); 288c2ecf20Sopenharmony_ci unsigned long frequency; 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci char *name; 318c2ecf20Sopenharmony_ci}; 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ciextern struct sparc64_tick_ops *tick_ops; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ciunsigned long sparc64_get_clock_tick(unsigned int cpu); 368c2ecf20Sopenharmony_civoid setup_sparc64_timer(void); 378c2ecf20Sopenharmony_civoid __init time_init(void); 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#define TICK_PRIV_BIT BIT(63) 408c2ecf20Sopenharmony_ci#define TICKCMP_IRQ_BIT BIT(63) 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define HBIRD_STICKCMP_ADDR 0x1fe0000f060UL 438c2ecf20Sopenharmony_ci#define HBIRD_STICK_ADDR 0x1fe0000f070UL 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define GET_TICK_NINSTR 13 468c2ecf20Sopenharmony_cistruct get_tick_patch { 478c2ecf20Sopenharmony_ci unsigned int addr; 488c2ecf20Sopenharmony_ci unsigned int tick[GET_TICK_NINSTR]; 498c2ecf20Sopenharmony_ci unsigned int stick[GET_TICK_NINSTR]; 508c2ecf20Sopenharmony_ci}; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ciextern struct get_tick_patch __get_tick_patch; 538c2ecf20Sopenharmony_ciextern struct get_tick_patch __get_tick_patch_end; 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_cistatic inline unsigned long get_tick(void) 568c2ecf20Sopenharmony_ci{ 578c2ecf20Sopenharmony_ci unsigned long tick, tmp1, tmp2; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci __asm__ __volatile__( 608c2ecf20Sopenharmony_ci /* read hbtick 13 instructions */ 618c2ecf20Sopenharmony_ci "661:\n" 628c2ecf20Sopenharmony_ci " mov 0x1fe, %1\n" 638c2ecf20Sopenharmony_ci " sllx %1, 0x20, %1\n" 648c2ecf20Sopenharmony_ci " sethi %%hi(0xf000), %2\n" 658c2ecf20Sopenharmony_ci " or %2, 0x70, %2\n" 668c2ecf20Sopenharmony_ci " or %1, %2, %1\n" /* %1 = HBIRD_STICK_ADDR */ 678c2ecf20Sopenharmony_ci " add %1, 8, %2\n" 688c2ecf20Sopenharmony_ci " ldxa [%2]%3, %0\n" 698c2ecf20Sopenharmony_ci " ldxa [%1]%3, %1\n" 708c2ecf20Sopenharmony_ci " ldxa [%2]%3, %2\n" 718c2ecf20Sopenharmony_ci " sub %2, %0, %0\n" /* don't modify %xcc */ 728c2ecf20Sopenharmony_ci " brnz,pn %0, 661b\n" /* restart to save one register */ 738c2ecf20Sopenharmony_ci " sllx %2, 32, %2\n" 748c2ecf20Sopenharmony_ci " or %2, %1, %0\n" 758c2ecf20Sopenharmony_ci /* Common/not patched code */ 768c2ecf20Sopenharmony_ci " sllx %0, 1, %0\n" 778c2ecf20Sopenharmony_ci " srlx %0, 1, %0\n" /* Clear TICK_PRIV_BIT */ 788c2ecf20Sopenharmony_ci /* Beginning of patch section */ 798c2ecf20Sopenharmony_ci " .section .get_tick_patch, \"ax\"\n" 808c2ecf20Sopenharmony_ci " .word 661b\n" 818c2ecf20Sopenharmony_ci /* read tick 2 instructions and 11 skipped */ 828c2ecf20Sopenharmony_ci " ba 1f\n" 838c2ecf20Sopenharmony_ci " rd %%tick, %0\n" 848c2ecf20Sopenharmony_ci " .skip 4 * (%4 - 2)\n" 858c2ecf20Sopenharmony_ci "1:\n" 868c2ecf20Sopenharmony_ci /* read stick 2 instructions and 11 skipped */ 878c2ecf20Sopenharmony_ci " ba 1f\n" 888c2ecf20Sopenharmony_ci " rd %%asr24, %0\n" 898c2ecf20Sopenharmony_ci " .skip 4 * (%4 - 2)\n" 908c2ecf20Sopenharmony_ci "1:\n" 918c2ecf20Sopenharmony_ci /* End of patch section */ 928c2ecf20Sopenharmony_ci " .previous\n" 938c2ecf20Sopenharmony_ci : "=&r" (tick), "=&r" (tmp1), "=&r" (tmp2) 948c2ecf20Sopenharmony_ci : "i" (ASI_PHYS_BYPASS_EC_E), "i" (GET_TICK_NINSTR)); 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci return tick; 978c2ecf20Sopenharmony_ci} 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci#endif /* _SPARC64_TIMER_H */ 100