xref: /linux/drivers/gpu/drm/amd/amdgpu/amdgpu_reg_access.h (revision f4eb08f8b216c334752246fe24e1304477d78968)
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 };
44 
45 void amdgpu_reg_access_init(struct amdgpu_device *adev);
46 uint32_t amdgpu_reg_smc_rd32(struct amdgpu_device *adev, uint32_t reg);
47 void amdgpu_reg_smc_wr32(struct amdgpu_device *adev, uint32_t reg, uint32_t v);
48 
49 typedef uint32_t (*amdgpu_rreg_ext_t)(struct amdgpu_device *, uint64_t);
50 typedef void (*amdgpu_wreg_ext_t)(struct amdgpu_device *, uint64_t, uint32_t);
51 
52 typedef uint64_t (*amdgpu_rreg64_t)(struct amdgpu_device *, uint32_t);
53 typedef void (*amdgpu_wreg64_t)(struct amdgpu_device *, uint32_t, uint64_t);
54 
55 typedef uint64_t (*amdgpu_rreg64_ext_t)(struct amdgpu_device *, uint64_t);
56 typedef void (*amdgpu_wreg64_ext_t)(struct amdgpu_device *, uint64_t, uint64_t);
57 
58 typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device *, uint32_t,
59 					uint32_t);
60 typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device *, uint32_t, uint32_t,
61 				    uint32_t);
62 
63 uint32_t amdgpu_device_rreg(struct amdgpu_device *adev, uint32_t reg,
64 			    uint32_t acc_flags);
65 uint32_t amdgpu_device_xcc_rreg(struct amdgpu_device *adev, uint32_t reg,
66 				uint32_t acc_flags, uint32_t xcc_id);
67 void amdgpu_device_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
68 			uint32_t acc_flags);
69 void amdgpu_device_xcc_wreg(struct amdgpu_device *adev, uint32_t reg,
70 			    uint32_t v, uint32_t acc_flags, uint32_t xcc_id);
71 void amdgpu_mm_wreg_mmio_rlc(struct amdgpu_device *adev, uint32_t reg,
72 			     uint32_t v, uint32_t xcc_id);
73 void amdgpu_mm_wreg8(struct amdgpu_device *adev, uint32_t offset,
74 		     uint8_t value);
75 uint8_t amdgpu_mm_rreg8(struct amdgpu_device *adev, uint32_t offset);
76 
77 u32 amdgpu_device_indirect_rreg(struct amdgpu_device *adev, u32 reg_addr);
78 u32 amdgpu_device_indirect_rreg_ext(struct amdgpu_device *adev, u64 reg_addr);
79 u64 amdgpu_device_indirect_rreg64(struct amdgpu_device *adev, u32 reg_addr);
80 u64 amdgpu_device_indirect_rreg64_ext(struct amdgpu_device *adev, u64 reg_addr);
81 void amdgpu_device_indirect_wreg(struct amdgpu_device *adev, u32 reg_addr,
82 				 u32 reg_data);
83 void amdgpu_device_indirect_wreg_ext(struct amdgpu_device *adev, u64 reg_addr,
84 				     u32 reg_data);
85 void amdgpu_device_indirect_wreg64(struct amdgpu_device *adev, u32 reg_addr,
86 				   u64 reg_data);
87 void amdgpu_device_indirect_wreg64_ext(struct amdgpu_device *adev, u64 reg_addr,
88 				       u64 reg_data);
89 
90 u32 amdgpu_device_pcie_port_rreg(struct amdgpu_device *adev, u32 reg);
91 void amdgpu_device_pcie_port_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
92 
93 uint32_t amdgpu_device_wait_on_rreg(struct amdgpu_device *adev, uint32_t inst,
94 				    uint32_t reg_addr, char reg_name[],
95 				    uint32_t expected_value, uint32_t mask);
96 
97 #endif /* __AMDGPU_REG_ACCESS_H__ */
98