xref: /linux/drivers/gpu/drm/amd/amdgpu/amdgpu_reg_access.h (revision 57052d293eff5fcb6b8f5653370fe7df26ca62ec)
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 
29 struct amdgpu_device;
30 
31 /*
32  * Registers read & write functions.
33  */
34 typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device *, uint32_t);
35 typedef void (*amdgpu_wreg_t)(struct amdgpu_device *, uint32_t, uint32_t);
36 
37 typedef uint32_t (*amdgpu_rreg_ext_t)(struct amdgpu_device *, uint64_t);
38 typedef void (*amdgpu_wreg_ext_t)(struct amdgpu_device *, uint64_t, uint32_t);
39 
40 typedef uint64_t (*amdgpu_rreg64_t)(struct amdgpu_device *, uint32_t);
41 typedef void (*amdgpu_wreg64_t)(struct amdgpu_device *, uint32_t, uint64_t);
42 
43 typedef uint64_t (*amdgpu_rreg64_ext_t)(struct amdgpu_device *, uint64_t);
44 typedef void (*amdgpu_wreg64_ext_t)(struct amdgpu_device *, uint64_t, uint64_t);
45 
46 typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device *, uint32_t,
47 					uint32_t);
48 typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device *, uint32_t, uint32_t,
49 				    uint32_t);
50 
51 uint32_t amdgpu_device_rreg(struct amdgpu_device *adev, uint32_t reg,
52 			    uint32_t acc_flags);
53 uint32_t amdgpu_device_xcc_rreg(struct amdgpu_device *adev, uint32_t reg,
54 				uint32_t acc_flags, uint32_t xcc_id);
55 void amdgpu_device_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
56 			uint32_t acc_flags);
57 void amdgpu_device_xcc_wreg(struct amdgpu_device *adev, uint32_t reg,
58 			    uint32_t v, uint32_t acc_flags, uint32_t xcc_id);
59 void amdgpu_mm_wreg_mmio_rlc(struct amdgpu_device *adev, uint32_t reg,
60 			     uint32_t v, uint32_t xcc_id);
61 void amdgpu_mm_wreg8(struct amdgpu_device *adev, uint32_t offset,
62 		     uint8_t value);
63 uint8_t amdgpu_mm_rreg8(struct amdgpu_device *adev, uint32_t offset);
64 
65 u32 amdgpu_device_indirect_rreg(struct amdgpu_device *adev, u32 reg_addr);
66 u32 amdgpu_device_indirect_rreg_ext(struct amdgpu_device *adev, u64 reg_addr);
67 u64 amdgpu_device_indirect_rreg64(struct amdgpu_device *adev, u32 reg_addr);
68 u64 amdgpu_device_indirect_rreg64_ext(struct amdgpu_device *adev, u64 reg_addr);
69 void amdgpu_device_indirect_wreg(struct amdgpu_device *adev, u32 reg_addr,
70 				 u32 reg_data);
71 void amdgpu_device_indirect_wreg_ext(struct amdgpu_device *adev, u64 reg_addr,
72 				     u32 reg_data);
73 void amdgpu_device_indirect_wreg64(struct amdgpu_device *adev, u32 reg_addr,
74 				   u64 reg_data);
75 void amdgpu_device_indirect_wreg64_ext(struct amdgpu_device *adev, u64 reg_addr,
76 				       u64 reg_data);
77 
78 u32 amdgpu_device_pcie_port_rreg(struct amdgpu_device *adev, u32 reg);
79 void amdgpu_device_pcie_port_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
80 
81 uint32_t amdgpu_device_wait_on_rreg(struct amdgpu_device *adev, uint32_t inst,
82 				    uint32_t reg_addr, char reg_name[],
83 				    uint32_t expected_value, uint32_t mask);
84 
85 #endif /* __AMDGPU_REG_ACCESS_H__ */
86