1 /* SPDX-License-Identifier: MIT */ 2 /* 3 * Copyright 2025 Advanced Micro Devices, Inc. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 * OTHER DEALINGS IN THE SOFTWARE. 22 */ 23 24 #ifndef __AMDGPU_REG_ACCESS_H__ 25 #define __AMDGPU_REG_ACCESS_H__ 26 27 #include <linux/types.h> 28 #include <linux/spinlock.h> 29 30 struct amdgpu_device; 31 32 typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device *, uint32_t); 33 typedef void (*amdgpu_wreg_t)(struct amdgpu_device *, uint32_t, uint32_t); 34 35 struct amdgpu_reg_ind { 36 spinlock_t lock; 37 amdgpu_rreg_t rreg; 38 amdgpu_wreg_t wreg; 39 }; 40 41 struct amdgpu_reg_access { 42 struct amdgpu_reg_ind smc; 43 struct amdgpu_reg_ind uvd_ctx; 44 struct amdgpu_reg_ind didt; 45 }; 46 47 void amdgpu_reg_access_init(struct amdgpu_device *adev); 48 uint32_t amdgpu_reg_smc_rd32(struct amdgpu_device *adev, uint32_t reg); 49 void amdgpu_reg_smc_wr32(struct amdgpu_device *adev, uint32_t reg, uint32_t v); 50 uint32_t amdgpu_reg_uvd_ctx_rd32(struct amdgpu_device *adev, uint32_t reg); 51 void amdgpu_reg_uvd_ctx_wr32(struct amdgpu_device *adev, uint32_t reg, uint32_t v); 52 uint32_t amdgpu_reg_didt_rd32(struct amdgpu_device *adev, uint32_t reg); 53 void amdgpu_reg_didt_wr32(struct amdgpu_device *adev, uint32_t reg, uint32_t v); 54 55 typedef uint32_t (*amdgpu_rreg_ext_t)(struct amdgpu_device *, uint64_t); 56 typedef void (*amdgpu_wreg_ext_t)(struct amdgpu_device *, uint64_t, uint32_t); 57 58 typedef uint64_t (*amdgpu_rreg64_t)(struct amdgpu_device *, uint32_t); 59 typedef void (*amdgpu_wreg64_t)(struct amdgpu_device *, uint32_t, uint64_t); 60 61 typedef uint64_t (*amdgpu_rreg64_ext_t)(struct amdgpu_device *, uint64_t); 62 typedef void (*amdgpu_wreg64_ext_t)(struct amdgpu_device *, uint64_t, uint64_t); 63 64 typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device *, uint32_t, 65 uint32_t); 66 typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device *, uint32_t, uint32_t, 67 uint32_t); 68 69 uint32_t amdgpu_device_rreg(struct amdgpu_device *adev, uint32_t reg, 70 uint32_t acc_flags); 71 uint32_t amdgpu_device_xcc_rreg(struct amdgpu_device *adev, uint32_t reg, 72 uint32_t acc_flags, uint32_t xcc_id); 73 void amdgpu_device_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v, 74 uint32_t acc_flags); 75 void amdgpu_device_xcc_wreg(struct amdgpu_device *adev, uint32_t reg, 76 uint32_t v, uint32_t acc_flags, uint32_t xcc_id); 77 void amdgpu_mm_wreg_mmio_rlc(struct amdgpu_device *adev, uint32_t reg, 78 uint32_t v, uint32_t xcc_id); 79 void amdgpu_mm_wreg8(struct amdgpu_device *adev, uint32_t offset, 80 uint8_t value); 81 uint8_t amdgpu_mm_rreg8(struct amdgpu_device *adev, uint32_t offset); 82 83 u32 amdgpu_device_indirect_rreg(struct amdgpu_device *adev, u32 reg_addr); 84 u32 amdgpu_device_indirect_rreg_ext(struct amdgpu_device *adev, u64 reg_addr); 85 u64 amdgpu_device_indirect_rreg64(struct amdgpu_device *adev, u32 reg_addr); 86 u64 amdgpu_device_indirect_rreg64_ext(struct amdgpu_device *adev, u64 reg_addr); 87 void amdgpu_device_indirect_wreg(struct amdgpu_device *adev, u32 reg_addr, 88 u32 reg_data); 89 void amdgpu_device_indirect_wreg_ext(struct amdgpu_device *adev, u64 reg_addr, 90 u32 reg_data); 91 void amdgpu_device_indirect_wreg64(struct amdgpu_device *adev, u32 reg_addr, 92 u64 reg_data); 93 void amdgpu_device_indirect_wreg64_ext(struct amdgpu_device *adev, u64 reg_addr, 94 u64 reg_data); 95 96 u32 amdgpu_device_pcie_port_rreg(struct amdgpu_device *adev, u32 reg); 97 void amdgpu_device_pcie_port_wreg(struct amdgpu_device *adev, u32 reg, u32 v); 98 99 uint32_t amdgpu_device_wait_on_rreg(struct amdgpu_device *adev, uint32_t inst, 100 uint32_t reg_addr, char reg_name[], 101 uint32_t expected_value, uint32_t mask); 102 103 #endif /* __AMDGPU_REG_ACCESS_H__ */ 104