1*52cd9bc4SPratik Vishwakarma /* 2*52cd9bc4SPratik Vishwakarma * Copyright 2025 Advanced Micro Devices, Inc. 3*52cd9bc4SPratik Vishwakarma * 4*52cd9bc4SPratik Vishwakarma * Permission is hereby granted, free of charge, to any person obtaining a 5*52cd9bc4SPratik Vishwakarma * copy of this software and associated documentation files (the "Software"), 6*52cd9bc4SPratik Vishwakarma * to deal in the Software without restriction, including without limitation 7*52cd9bc4SPratik Vishwakarma * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8*52cd9bc4SPratik Vishwakarma * and/or sell copies of the Software, and to permit persons to whom the 9*52cd9bc4SPratik Vishwakarma * Software is furnished to do so, subject to the following conditions: 10*52cd9bc4SPratik Vishwakarma * 11*52cd9bc4SPratik Vishwakarma * The above copyright notice and this permission notice shall be included in 12*52cd9bc4SPratik Vishwakarma * all copies or substantial portions of the Software. 13*52cd9bc4SPratik Vishwakarma * 14*52cd9bc4SPratik Vishwakarma * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15*52cd9bc4SPratik Vishwakarma * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16*52cd9bc4SPratik Vishwakarma * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17*52cd9bc4SPratik Vishwakarma * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18*52cd9bc4SPratik Vishwakarma * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19*52cd9bc4SPratik Vishwakarma * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20*52cd9bc4SPratik Vishwakarma * OTHER DEALINGS IN THE SOFTWARE. 21*52cd9bc4SPratik Vishwakarma * 22*52cd9bc4SPratik Vishwakarma */ 23*52cd9bc4SPratik Vishwakarma #include "amdgpu.h" 24*52cd9bc4SPratik Vishwakarma #include "smuio_v15_0_0.h" 25*52cd9bc4SPratik Vishwakarma #include "smuio/smuio_15_0_0_offset.h" 26*52cd9bc4SPratik Vishwakarma #include "smuio/smuio_15_0_0_sh_mask.h" 27*52cd9bc4SPratik Vishwakarma #include <linux/preempt.h> 28*52cd9bc4SPratik Vishwakarma 29*52cd9bc4SPratik Vishwakarma static u64 smuio_v15_0_0_get_gpu_clock_counter(struct amdgpu_device *adev) 30*52cd9bc4SPratik Vishwakarma { 31*52cd9bc4SPratik Vishwakarma u64 clock; 32*52cd9bc4SPratik Vishwakarma u64 clock_counter_lo, clock_counter_hi_pre, clock_counter_hi_after; 33*52cd9bc4SPratik Vishwakarma 34*52cd9bc4SPratik Vishwakarma preempt_disable(); 35*52cd9bc4SPratik Vishwakarma clock_counter_hi_pre = (u64)RREG32_SOC15(SMUIO, 0, regGOLDEN_TSC_COUNT_UPPER); 36*52cd9bc4SPratik Vishwakarma clock_counter_lo = (u64)RREG32_SOC15(SMUIO, 0, regGOLDEN_TSC_COUNT_LOWER); 37*52cd9bc4SPratik Vishwakarma /* the clock counter may be udpated during polling the counters */ 38*52cd9bc4SPratik Vishwakarma clock_counter_hi_after = (u64)RREG32_SOC15(SMUIO, 0, regGOLDEN_TSC_COUNT_UPPER); 39*52cd9bc4SPratik Vishwakarma if (clock_counter_hi_pre != clock_counter_hi_after) 40*52cd9bc4SPratik Vishwakarma clock_counter_lo = (u64)RREG32_SOC15(SMUIO, 0, regGOLDEN_TSC_COUNT_LOWER); 41*52cd9bc4SPratik Vishwakarma preempt_enable(); 42*52cd9bc4SPratik Vishwakarma 43*52cd9bc4SPratik Vishwakarma clock = clock_counter_lo | (clock_counter_hi_after << 32ULL); 44*52cd9bc4SPratik Vishwakarma 45*52cd9bc4SPratik Vishwakarma return clock; 46*52cd9bc4SPratik Vishwakarma } 47*52cd9bc4SPratik Vishwakarma 48*52cd9bc4SPratik Vishwakarma const struct amdgpu_smuio_funcs smuio_v15_0_0_funcs = { 49*52cd9bc4SPratik Vishwakarma .get_gpu_clock_counter = smuio_v15_0_0_get_gpu_clock_counter, 50*52cd9bc4SPratik Vishwakarma }; 51