2 * Copyright 2016 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
24 #include <linux/firmware.h>
27 #include "amdgpu_ucode.h"
28 #include "amdgpu_trace.h"
30 #include "sdma0/sdma0_4_2_offset.h"
31 #include "sdma0/sdma0_4_2_sh_mask.h"
32 #include "sdma1/sdma1_4_2_offset.h"
33 #include "sdma1/sdma1_4_2_sh_mask.h"
34 #include "hdp/hdp_4_0_offset.h"
35 #include "sdma0/sdma0_4_1_default.h"
37 #include "soc15_common.h"
39 #include "vega10_sdma_pkt_open.h"
41 #include "ivsrcid/sdma0/irqsrcs_sdma0_4_0.h"
42 #include "ivsrcid/sdma1/irqsrcs_sdma1_4_0.h"
44 MODULE_FIRMWARE("amdgpu/vega10_sdma.bin");
45 MODULE_FIRMWARE("amdgpu/vega10_sdma1.bin");
46 MODULE_FIRMWARE("amdgpu/vega12_sdma.bin");
47 MODULE_FIRMWARE("amdgpu/vega12_sdma1.bin");
48 MODULE_FIRMWARE("amdgpu/vega20_sdma.bin");
49 MODULE_FIRMWARE("amdgpu/vega20_sdma1.bin");
50 MODULE_FIRMWARE("amdgpu/raven_sdma.bin");
51 MODULE_FIRMWARE("amdgpu/picasso_sdma.bin");
52 MODULE_FIRMWARE("amdgpu/raven2_sdma.bin");
54 #define SDMA0_POWER_CNTL__ON_OFF_CONDITION_HOLD_TIME_MASK 0x000000F8L
55 #define SDMA0_POWER_CNTL__ON_OFF_STATUS_DURATION_TIME_MASK 0xFC000000L
57 #define WREG32_SDMA(instance, offset, value) \
58 WREG32(sdma_v4_0_get_reg_offset(adev, (instance), (offset)), value)
59 #define RREG32_SDMA(instance, offset) \
60 RREG32(sdma_v4_0_get_reg_offset(adev, (instance), (offset)))
62 static void sdma_v4_0_set_ring_funcs(struct amdgpu_device *adev);
63 static void sdma_v4_0_set_buffer_funcs(struct amdgpu_device *adev);
64 static void sdma_v4_0_set_vm_pte_funcs(struct amdgpu_device *adev);
65 static void sdma_v4_0_set_irq_funcs(struct amdgpu_device *adev);
67 static const struct soc15_reg_golden golden_settings_sdma_4[] = {
68 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_CHICKEN_BITS, 0xfe931f07, 0x02831d07),
69 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_CLK_CTRL, 0xff000ff0, 0x3f000100),
70 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_GFX_IB_CNTL, 0x800f0100, 0x00000100),
71 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_GFX_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
72 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_PAGE_IB_CNTL, 0x800f0100, 0x00000100),
73 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_PAGE_RB_WPTR_POLL_CNTL, 0x0000fff0, 0x00403000),
74 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_POWER_CNTL, 0x003ff006, 0x0003c000),
75 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC0_IB_CNTL, 0x800f0100, 0x00000100),
76 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC0_RB_WPTR_POLL_CNTL, 0x0000fff0, 0x00403000),
77 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC1_IB_CNTL, 0x800f0100, 0x00000100),
78 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC1_RB_WPTR_POLL_CNTL, 0x0000fff0, 0x00403000),
79 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_UTCL1_PAGE, 0x000003ff, 0x000003c0),
80 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_UTCL1_WATERMK, 0xfc000000, 0x00000000),
81 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_CHICKEN_BITS, 0xfe931f07, 0x02831f07),
82 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_CLK_CTRL, 0xffffffff, 0x3f000100),
83 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_GFX_IB_CNTL, 0x800f0100, 0x00000100),
84 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_GFX_RB_WPTR_POLL_CNTL, 0x0000fff0, 0x00403000),
85 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_PAGE_IB_CNTL, 0x800f0100, 0x00000100),
86 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_PAGE_RB_WPTR_POLL_CNTL, 0x0000fff0, 0x00403000),
87 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_POWER_CNTL, 0x003ff000, 0x0003c000),
88 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC0_IB_CNTL, 0x800f0100, 0x00000100),
89 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC0_RB_WPTR_POLL_CNTL, 0x0000fff0, 0x00403000),
90 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC1_IB_CNTL, 0x800f0100, 0x00000100),
91 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC1_RB_WPTR_POLL_CNTL, 0x0000fff0, 0x00403000),
92 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_UTCL1_PAGE, 0x000003ff, 0x000003c0),
93 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_UTCL1_WATERMK, 0xfc000000, 0x00000000)
96 static const struct soc15_reg_golden golden_settings_sdma_vg10[] = {
97 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_GB_ADDR_CONFIG, 0x0018773f, 0x00104002),
98 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_GB_ADDR_CONFIG_READ, 0x0018773f, 0x00104002),
99 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_GB_ADDR_CONFIG, 0x0018773f, 0x00104002),
100 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_GB_ADDR_CONFIG_READ, 0x0018773f, 0x00104002)
103 static const struct soc15_reg_golden golden_settings_sdma_vg12[] = {
104 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_GB_ADDR_CONFIG, 0x0018773f, 0x00104001),
105 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_GB_ADDR_CONFIG_READ, 0x0018773f, 0x00104001),
106 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_GB_ADDR_CONFIG, 0x0018773f, 0x00104001),
107 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_GB_ADDR_CONFIG_READ, 0x0018773f, 0x00104001)
110 static const struct soc15_reg_golden golden_settings_sdma_4_1[] = {
111 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_CHICKEN_BITS, 0xfe931f07, 0x02831d07),
112 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_CLK_CTRL, 0xffffffff, 0x3f000100),
113 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_GFX_IB_CNTL, 0x800f0111, 0x00000100),
114 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_GFX_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
115 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_POWER_CNTL, 0xfc3fffff, 0x40000051),
116 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC0_IB_CNTL, 0x800f0111, 0x00000100),
117 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC0_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
118 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC1_IB_CNTL, 0x800f0111, 0x00000100),
119 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC1_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
120 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_UTCL1_PAGE, 0x000003ff, 0x000003c0),
121 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_UTCL1_WATERMK, 0xfc000000, 0x00000000)
124 static const struct soc15_reg_golden golden_settings_sdma0_4_2_init[] = {
125 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC0_RB_WPTR_POLL_CNTL, 0xfffffff0, 0x00403000),
128 static const struct soc15_reg_golden golden_settings_sdma0_4_2[] =
130 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_CHICKEN_BITS, 0xfe931f07, 0x02831d07),
131 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_CLK_CTRL, 0xffffffff, 0x3f000100),
132 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_GB_ADDR_CONFIG, 0x0000773f, 0x00004002),
133 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_GB_ADDR_CONFIG_READ, 0x0000773f, 0x00004002),
134 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_GFX_RB_RPTR_ADDR_LO, 0xfffffffd, 0x00000001),
135 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_GFX_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
136 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_PAGE_RB_RPTR_ADDR_LO, 0xfffffffd, 0x00000001),
137 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_PAGE_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
138 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RD_BURST_CNTL, 0x0000000f, 0x00000003),
139 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC0_RB_RPTR_ADDR_LO, 0xfffffffd, 0x00000001),
140 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC0_RB_WPTR_POLL_CNTL, 0xfffffff0, 0x00403000),
141 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC1_RB_RPTR_ADDR_LO, 0xfffffffd, 0x00000001),
142 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC1_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
143 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC2_RB_RPTR_ADDR_LO, 0xfffffffd, 0x00000001),
144 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC2_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
145 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC3_RB_RPTR_ADDR_LO, 0xfffffffd, 0x00000001),
146 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC3_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
147 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC4_RB_RPTR_ADDR_LO, 0xfffffffd, 0x00000001),
148 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC4_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
149 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC5_RB_RPTR_ADDR_LO, 0xfffffffd, 0x00000001),
150 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC5_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
151 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC6_RB_RPTR_ADDR_LO, 0xfffffffd, 0x00000001),
152 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC6_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
153 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC7_RB_RPTR_ADDR_LO, 0xfffffffd, 0x00000001),
154 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_RLC7_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
155 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_UTCL1_PAGE, 0x000003ff, 0x000003c0),
156 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_UTCL1_WATERMK, 0xFE000000, 0x00000000),
159 static const struct soc15_reg_golden golden_settings_sdma1_4_2[] = {
160 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_CHICKEN_BITS, 0xfe931f07, 0x02831d07),
161 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_CLK_CTRL, 0xffffffff, 0x3f000100),
162 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_GB_ADDR_CONFIG, 0x0000773f, 0x00004002),
163 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_GB_ADDR_CONFIG_READ, 0x0000773f, 0x00004002),
164 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_GFX_RB_RPTR_ADDR_LO, 0xfffffffd, 0x00000001),
165 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_GFX_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
166 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_PAGE_RB_RPTR_ADDR_LO, 0xfffffffd, 0x00000001),
167 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_PAGE_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
168 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RD_BURST_CNTL, 0x0000000f, 0x00000003),
169 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC0_RB_RPTR_ADDR_LO, 0xfffffffd, 0x00000001),
170 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC0_RB_WPTR_POLL_CNTL, 0xfffffff0, 0x00403000),
171 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC1_RB_RPTR_ADDR_LO, 0xfffffffd, 0x00000001),
172 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC1_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
173 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC2_RB_RPTR_ADDR_LO, 0xfffffffd, 0x00000001),
174 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC2_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
175 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC3_RB_RPTR_ADDR_LO, 0xfffffffd, 0x00000001),
176 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC3_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
177 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC4_RB_RPTR_ADDR_LO, 0xfffffffd, 0x00000001),
178 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC4_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
179 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC5_RB_RPTR_ADDR_LO, 0xfffffffd, 0x00000001),
180 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC5_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
181 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC6_RB_RPTR_ADDR_LO, 0xfffffffd, 0x00000001),
182 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC6_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
183 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC7_RB_RPTR_ADDR_LO, 0xfffffffd, 0x00000001),
184 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_RLC7_RB_WPTR_POLL_CNTL, 0xfffffff7, 0x00403000),
185 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_UTCL1_PAGE, 0x000003ff, 0x000003c0),
186 SOC15_REG_GOLDEN_VALUE(SDMA1, 0, mmSDMA1_UTCL1_WATERMK, 0xFE000000, 0x00000000),
189 static const struct soc15_reg_golden golden_settings_sdma_rv1[] =
191 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_GB_ADDR_CONFIG, 0x0018773f, 0x00000002),
192 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_GB_ADDR_CONFIG_READ, 0x0018773f, 0x00000002)
195 static const struct soc15_reg_golden golden_settings_sdma_rv2[] =
197 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_GB_ADDR_CONFIG, 0x0018773f, 0x00003001),
198 SOC15_REG_GOLDEN_VALUE(SDMA0, 0, mmSDMA0_GB_ADDR_CONFIG_READ, 0x0018773f, 0x00003001)
201 static u32 sdma_v4_0_get_reg_offset(struct amdgpu_device *adev,
202 u32 instance, u32 offset)
204 return ( 0 == instance ? (adev->reg_offset[SDMA0_HWIP][0][0] + offset) :
205 (adev->reg_offset[SDMA1_HWIP][0][0] + offset));
208 static void sdma_v4_0_init_golden_registers(struct amdgpu_device *adev)
210 switch (adev->asic_type) {
212 soc15_program_register_sequence(adev,
213 golden_settings_sdma_4,
214 ARRAY_SIZE(golden_settings_sdma_4));
215 soc15_program_register_sequence(adev,
216 golden_settings_sdma_vg10,
217 ARRAY_SIZE(golden_settings_sdma_vg10));
220 soc15_program_register_sequence(adev,
221 golden_settings_sdma_4,
222 ARRAY_SIZE(golden_settings_sdma_4));
223 soc15_program_register_sequence(adev,
224 golden_settings_sdma_vg12,
225 ARRAY_SIZE(golden_settings_sdma_vg12));
228 soc15_program_register_sequence(adev,
229 golden_settings_sdma0_4_2_init,
230 ARRAY_SIZE(golden_settings_sdma0_4_2_init));
231 soc15_program_register_sequence(adev,
232 golden_settings_sdma0_4_2,
233 ARRAY_SIZE(golden_settings_sdma0_4_2));
234 soc15_program_register_sequence(adev,
235 golden_settings_sdma1_4_2,
236 ARRAY_SIZE(golden_settings_sdma1_4_2));
239 soc15_program_register_sequence(adev,
240 golden_settings_sdma_4_1,
241 ARRAY_SIZE(golden_settings_sdma_4_1));
242 if (adev->rev_id >= 8)
243 soc15_program_register_sequence(adev,
244 golden_settings_sdma_rv2,
245 ARRAY_SIZE(golden_settings_sdma_rv2));
247 soc15_program_register_sequence(adev,
248 golden_settings_sdma_rv1,
249 ARRAY_SIZE(golden_settings_sdma_rv1));
257 * sdma_v4_0_init_microcode - load ucode images from disk
259 * @adev: amdgpu_device pointer
261 * Use the firmware interface to load the ucode images into
262 * the driver (not loaded into hw).
263 * Returns 0 on success, error on failure.
266 // emulation only, won't work on real chip
267 // vega10 real chip need to use PSP to load firmware
268 static int sdma_v4_0_init_microcode(struct amdgpu_device *adev)
270 const char *chip_name;
273 struct amdgpu_firmware_info *info = NULL;
274 const struct common_firmware_header *header = NULL;
275 const struct sdma_firmware_header_v1_0 *hdr;
279 switch (adev->asic_type) {
281 chip_name = "vega10";
284 chip_name = "vega12";
287 chip_name = "vega20";
290 if (adev->rev_id >= 8)
291 chip_name = "raven2";
292 else if (adev->pdev->device == 0x15d8)
293 chip_name = "picasso";
301 for (i = 0; i < adev->sdma.num_instances; i++) {
303 snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_sdma.bin", chip_name);
305 snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_sdma1.bin", chip_name);
306 err = request_firmware(&adev->sdma.instance[i].fw, fw_name, adev->dev);
309 err = amdgpu_ucode_validate(adev->sdma.instance[i].fw);
312 hdr = (const struct sdma_firmware_header_v1_0 *)adev->sdma.instance[i].fw->data;
313 adev->sdma.instance[i].fw_version = le32_to_cpu(hdr->header.ucode_version);
314 adev->sdma.instance[i].feature_version = le32_to_cpu(hdr->ucode_feature_version);
315 if (adev->sdma.instance[i].feature_version >= 20)
316 adev->sdma.instance[i].burst_nop = true;
317 DRM_DEBUG("psp_load == '%s'\n",
318 adev->firmware.load_type == AMDGPU_FW_LOAD_PSP ? "true" : "false");
320 if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
321 info = &adev->firmware.ucode[AMDGPU_UCODE_ID_SDMA0 + i];
322 info->ucode_id = AMDGPU_UCODE_ID_SDMA0 + i;
323 info->fw = adev->sdma.instance[i].fw;
324 header = (const struct common_firmware_header *)info->fw->data;
325 adev->firmware.fw_size +=
326 ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
331 DRM_ERROR("sdma_v4_0: Failed to load firmware \"%s\"\n", fw_name);
332 for (i = 0; i < adev->sdma.num_instances; i++) {
333 release_firmware(adev->sdma.instance[i].fw);
334 adev->sdma.instance[i].fw = NULL;
341 * sdma_v4_0_ring_get_rptr - get the current read pointer
343 * @ring: amdgpu ring pointer
345 * Get the current rptr from the hardware (VEGA10+).
347 static uint64_t sdma_v4_0_ring_get_rptr(struct amdgpu_ring *ring)
351 /* XXX check if swapping is necessary on BE */
352 rptr = ((u64 *)&ring->adev->wb.wb[ring->rptr_offs]);
354 DRM_DEBUG("rptr before shift == 0x%016llx\n", *rptr);
355 return ((*rptr) >> 2);
359 * sdma_v4_0_ring_get_wptr - get the current write pointer
361 * @ring: amdgpu ring pointer
363 * Get the current wptr from the hardware (VEGA10+).
365 static uint64_t sdma_v4_0_ring_get_wptr(struct amdgpu_ring *ring)
367 struct amdgpu_device *adev = ring->adev;
370 if (ring->use_doorbell) {
371 /* XXX check if swapping is necessary on BE */
372 wptr = READ_ONCE(*((u64 *)&adev->wb.wb[ring->wptr_offs]));
373 DRM_DEBUG("wptr/doorbell before shift == 0x%016llx\n", wptr);
377 lowbit = RREG32_SDMA(ring->me, mmSDMA0_GFX_RB_WPTR) >> 2;
378 highbit = RREG32_SDMA(ring->me, mmSDMA0_GFX_RB_WPTR_HI) >> 2;
380 DRM_DEBUG("wptr [%i]high== 0x%08x low==0x%08x\n",
381 ring->me, highbit, lowbit);
391 * sdma_v4_0_ring_set_wptr - commit the write pointer
393 * @ring: amdgpu ring pointer
395 * Write the wptr back to the hardware (VEGA10+).
397 static void sdma_v4_0_ring_set_wptr(struct amdgpu_ring *ring)
399 struct amdgpu_device *adev = ring->adev;
401 DRM_DEBUG("Setting write pointer\n");
402 if (ring->use_doorbell) {
403 u64 *wb = (u64 *)&adev->wb.wb[ring->wptr_offs];
405 DRM_DEBUG("Using doorbell -- "
406 "wptr_offs == 0x%08x "
407 "lower_32_bits(ring->wptr) << 2 == 0x%08x "
408 "upper_32_bits(ring->wptr) << 2 == 0x%08x\n",
410 lower_32_bits(ring->wptr << 2),
411 upper_32_bits(ring->wptr << 2));
412 /* XXX check if swapping is necessary on BE */
413 WRITE_ONCE(*wb, (ring->wptr << 2));
414 DRM_DEBUG("calling WDOORBELL64(0x%08x, 0x%016llx)\n",
415 ring->doorbell_index, ring->wptr << 2);
416 WDOORBELL64(ring->doorbell_index, ring->wptr << 2);
418 DRM_DEBUG("Not using doorbell -- "
419 "mmSDMA%i_GFX_RB_WPTR == 0x%08x "
420 "mmSDMA%i_GFX_RB_WPTR_HI == 0x%08x\n",
422 lower_32_bits(ring->wptr << 2),
424 upper_32_bits(ring->wptr << 2));
425 WREG32_SDMA(ring->me, mmSDMA0_GFX_RB_WPTR,
426 lower_32_bits(ring->wptr << 2));
427 WREG32_SDMA(ring->me, mmSDMA0_GFX_RB_WPTR_HI,
428 upper_32_bits(ring->wptr << 2));
433 * sdma_v4_0_page_ring_get_wptr - get the current write pointer
435 * @ring: amdgpu ring pointer
437 * Get the current wptr from the hardware (VEGA10+).
439 static uint64_t sdma_v4_0_page_ring_get_wptr(struct amdgpu_ring *ring)
441 struct amdgpu_device *adev = ring->adev;
444 if (ring->use_doorbell) {
445 /* XXX check if swapping is necessary on BE */
446 wptr = READ_ONCE(*((u64 *)&adev->wb.wb[ring->wptr_offs]));
448 wptr = RREG32_SDMA(ring->me, mmSDMA0_PAGE_RB_WPTR_HI);
450 wptr |= RREG32_SDMA(ring->me, mmSDMA0_PAGE_RB_WPTR);
457 * sdma_v4_0_ring_set_wptr - commit the write pointer
459 * @ring: amdgpu ring pointer
461 * Write the wptr back to the hardware (VEGA10+).
463 static void sdma_v4_0_page_ring_set_wptr(struct amdgpu_ring *ring)
465 struct amdgpu_device *adev = ring->adev;
467 if (ring->use_doorbell) {
468 u64 *wb = (u64 *)&adev->wb.wb[ring->wptr_offs];
470 /* XXX check if swapping is necessary on BE */
471 WRITE_ONCE(*wb, (ring->wptr << 2));
472 WDOORBELL64(ring->doorbell_index, ring->wptr << 2);
474 uint64_t wptr = ring->wptr << 2;
476 WREG32_SDMA(ring->me, mmSDMA0_PAGE_RB_WPTR,
477 lower_32_bits(wptr));
478 WREG32_SDMA(ring->me, mmSDMA0_PAGE_RB_WPTR_HI,
479 upper_32_bits(wptr));
483 static void sdma_v4_0_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count)
485 struct amdgpu_sdma_instance *sdma = amdgpu_get_sdma_instance(ring);
488 for (i = 0; i < count; i++)
489 if (sdma && sdma->burst_nop && (i == 0))
490 amdgpu_ring_write(ring, ring->funcs->nop |
491 SDMA_PKT_NOP_HEADER_COUNT(count - 1));
493 amdgpu_ring_write(ring, ring->funcs->nop);
497 * sdma_v4_0_ring_emit_ib - Schedule an IB on the DMA engine
499 * @ring: amdgpu ring pointer
500 * @ib: IB object to schedule
502 * Schedule an IB in the DMA ring (VEGA10).
504 static void sdma_v4_0_ring_emit_ib(struct amdgpu_ring *ring,
505 struct amdgpu_ib *ib,
506 unsigned vmid, bool ctx_switch)
508 /* IB packet must end on a 8 DW boundary */
509 sdma_v4_0_ring_insert_nop(ring, (10 - (lower_32_bits(ring->wptr) & 7)) % 8);
511 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_INDIRECT) |
512 SDMA_PKT_INDIRECT_HEADER_VMID(vmid & 0xf));
513 /* base must be 32 byte aligned */
514 amdgpu_ring_write(ring, lower_32_bits(ib->gpu_addr) & 0xffffffe0);
515 amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr));
516 amdgpu_ring_write(ring, ib->length_dw);
517 amdgpu_ring_write(ring, 0);
518 amdgpu_ring_write(ring, 0);
522 static void sdma_v4_0_wait_reg_mem(struct amdgpu_ring *ring,
523 int mem_space, int hdp,
524 uint32_t addr0, uint32_t addr1,
525 uint32_t ref, uint32_t mask,
528 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_POLL_REGMEM) |
529 SDMA_PKT_POLL_REGMEM_HEADER_HDP_FLUSH(hdp) |
530 SDMA_PKT_POLL_REGMEM_HEADER_MEM_POLL(mem_space) |
531 SDMA_PKT_POLL_REGMEM_HEADER_FUNC(3)); /* == */
534 amdgpu_ring_write(ring, addr0);
535 amdgpu_ring_write(ring, addr1);
538 amdgpu_ring_write(ring, addr0 << 2);
539 amdgpu_ring_write(ring, addr1 << 2);
541 amdgpu_ring_write(ring, ref); /* reference */
542 amdgpu_ring_write(ring, mask); /* mask */
543 amdgpu_ring_write(ring, SDMA_PKT_POLL_REGMEM_DW5_RETRY_COUNT(0xfff) |
544 SDMA_PKT_POLL_REGMEM_DW5_INTERVAL(inv)); /* retry count, poll interval */
548 * sdma_v4_0_ring_emit_hdp_flush - emit an hdp flush on the DMA ring
550 * @ring: amdgpu ring pointer
552 * Emit an hdp flush packet on the requested DMA ring.
554 static void sdma_v4_0_ring_emit_hdp_flush(struct amdgpu_ring *ring)
556 struct amdgpu_device *adev = ring->adev;
557 u32 ref_and_mask = 0;
558 const struct nbio_hdp_flush_reg *nbio_hf_reg = adev->nbio_funcs->hdp_flush_reg;
561 ref_and_mask = nbio_hf_reg->ref_and_mask_sdma0;
563 ref_and_mask = nbio_hf_reg->ref_and_mask_sdma1;
565 sdma_v4_0_wait_reg_mem(ring, 0, 1,
566 adev->nbio_funcs->get_hdp_flush_done_offset(adev),
567 adev->nbio_funcs->get_hdp_flush_req_offset(adev),
568 ref_and_mask, ref_and_mask, 10);
572 * sdma_v4_0_ring_emit_fence - emit a fence on the DMA ring
574 * @ring: amdgpu ring pointer
575 * @fence: amdgpu fence object
577 * Add a DMA fence packet to the ring to write
578 * the fence seq number and DMA trap packet to generate
579 * an interrupt if needed (VEGA10).
581 static void sdma_v4_0_ring_emit_fence(struct amdgpu_ring *ring, u64 addr, u64 seq,
584 bool write64bit = flags & AMDGPU_FENCE_FLAG_64BIT;
585 /* write the fence */
586 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_FENCE));
587 /* zero in first two bits */
589 amdgpu_ring_write(ring, lower_32_bits(addr));
590 amdgpu_ring_write(ring, upper_32_bits(addr));
591 amdgpu_ring_write(ring, lower_32_bits(seq));
593 /* optionally write high bits as well */
596 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_FENCE));
597 /* zero in first two bits */
599 amdgpu_ring_write(ring, lower_32_bits(addr));
600 amdgpu_ring_write(ring, upper_32_bits(addr));
601 amdgpu_ring_write(ring, upper_32_bits(seq));
604 /* generate an interrupt */
605 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_TRAP));
606 amdgpu_ring_write(ring, SDMA_PKT_TRAP_INT_CONTEXT_INT_CONTEXT(0));
611 * sdma_v4_0_gfx_stop - stop the gfx async dma engines
613 * @adev: amdgpu_device pointer
615 * Stop the gfx async dma ring buffers (VEGA10).
617 static void sdma_v4_0_gfx_stop(struct amdgpu_device *adev)
619 struct amdgpu_ring *sdma0 = &adev->sdma.instance[0].ring;
620 struct amdgpu_ring *sdma1 = &adev->sdma.instance[1].ring;
621 u32 rb_cntl, ib_cntl;
624 if ((adev->mman.buffer_funcs_ring == sdma0) ||
625 (adev->mman.buffer_funcs_ring == sdma1))
626 amdgpu_ttm_set_buffer_funcs_status(adev, false);
628 for (i = 0; i < adev->sdma.num_instances; i++) {
629 rb_cntl = RREG32_SDMA(i, mmSDMA0_GFX_RB_CNTL);
630 rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_ENABLE, 0);
631 WREG32_SDMA(i, mmSDMA0_GFX_RB_CNTL, rb_cntl);
632 ib_cntl = RREG32_SDMA(i, mmSDMA0_GFX_IB_CNTL);
633 ib_cntl = REG_SET_FIELD(ib_cntl, SDMA0_GFX_IB_CNTL, IB_ENABLE, 0);
634 WREG32_SDMA(i, mmSDMA0_GFX_IB_CNTL, ib_cntl);
637 sdma0->ready = false;
638 sdma1->ready = false;
642 * sdma_v4_0_rlc_stop - stop the compute async dma engines
644 * @adev: amdgpu_device pointer
646 * Stop the compute async dma queues (VEGA10).
648 static void sdma_v4_0_rlc_stop(struct amdgpu_device *adev)
654 * sdma_v4_0_page_stop - stop the page async dma engines
656 * @adev: amdgpu_device pointer
658 * Stop the page async dma ring buffers (VEGA10).
660 static void sdma_v4_0_page_stop(struct amdgpu_device *adev)
662 struct amdgpu_ring *sdma0 = &adev->sdma.instance[0].page;
663 struct amdgpu_ring *sdma1 = &adev->sdma.instance[1].page;
664 u32 rb_cntl, ib_cntl;
667 for (i = 0; i < adev->sdma.num_instances; i++) {
668 rb_cntl = RREG32_SDMA(i, mmSDMA0_PAGE_RB_CNTL);
669 rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_PAGE_RB_CNTL,
671 WREG32_SDMA(i, mmSDMA0_PAGE_RB_CNTL, rb_cntl);
672 ib_cntl = RREG32_SDMA(i, mmSDMA0_PAGE_IB_CNTL);
673 ib_cntl = REG_SET_FIELD(ib_cntl, SDMA0_PAGE_IB_CNTL,
675 WREG32_SDMA(i, mmSDMA0_PAGE_IB_CNTL, ib_cntl);
678 sdma0->ready = false;
679 sdma1->ready = false;
683 * sdma_v_0_ctx_switch_enable - stop the async dma engines context switch
685 * @adev: amdgpu_device pointer
686 * @enable: enable/disable the DMA MEs context switch.
688 * Halt or unhalt the async dma engines context switch (VEGA10).
690 static void sdma_v4_0_ctx_switch_enable(struct amdgpu_device *adev, bool enable)
692 u32 f32_cntl, phase_quantum = 0;
695 if (amdgpu_sdma_phase_quantum) {
696 unsigned value = amdgpu_sdma_phase_quantum;
699 while (value > (SDMA0_PHASE0_QUANTUM__VALUE_MASK >>
700 SDMA0_PHASE0_QUANTUM__VALUE__SHIFT)) {
701 value = (value + 1) >> 1;
704 if (unit > (SDMA0_PHASE0_QUANTUM__UNIT_MASK >>
705 SDMA0_PHASE0_QUANTUM__UNIT__SHIFT)) {
706 value = (SDMA0_PHASE0_QUANTUM__VALUE_MASK >>
707 SDMA0_PHASE0_QUANTUM__VALUE__SHIFT);
708 unit = (SDMA0_PHASE0_QUANTUM__UNIT_MASK >>
709 SDMA0_PHASE0_QUANTUM__UNIT__SHIFT);
711 "clamping sdma_phase_quantum to %uK clock cycles\n",
715 value << SDMA0_PHASE0_QUANTUM__VALUE__SHIFT |
716 unit << SDMA0_PHASE0_QUANTUM__UNIT__SHIFT;
719 for (i = 0; i < adev->sdma.num_instances; i++) {
720 f32_cntl = RREG32_SDMA(i, mmSDMA0_CNTL);
721 f32_cntl = REG_SET_FIELD(f32_cntl, SDMA0_CNTL,
722 AUTO_CTXSW_ENABLE, enable ? 1 : 0);
723 if (enable && amdgpu_sdma_phase_quantum) {
724 WREG32_SDMA(i, mmSDMA0_PHASE0_QUANTUM, phase_quantum);
725 WREG32_SDMA(i, mmSDMA0_PHASE1_QUANTUM, phase_quantum);
726 WREG32_SDMA(i, mmSDMA0_PHASE2_QUANTUM, phase_quantum);
728 WREG32_SDMA(i, mmSDMA0_CNTL, f32_cntl);
734 * sdma_v4_0_enable - stop the async dma engines
736 * @adev: amdgpu_device pointer
737 * @enable: enable/disable the DMA MEs.
739 * Halt or unhalt the async dma engines (VEGA10).
741 static void sdma_v4_0_enable(struct amdgpu_device *adev, bool enable)
746 if (enable == false) {
747 sdma_v4_0_gfx_stop(adev);
748 sdma_v4_0_rlc_stop(adev);
749 if (adev->sdma.has_page_queue)
750 sdma_v4_0_page_stop(adev);
753 for (i = 0; i < adev->sdma.num_instances; i++) {
754 f32_cntl = RREG32_SDMA(i, mmSDMA0_F32_CNTL);
755 f32_cntl = REG_SET_FIELD(f32_cntl, SDMA0_F32_CNTL, HALT, enable ? 0 : 1);
756 WREG32_SDMA(i, mmSDMA0_F32_CNTL, f32_cntl);
761 * sdma_v4_0_rb_cntl - get parameters for rb_cntl
763 static uint32_t sdma_v4_0_rb_cntl(struct amdgpu_ring *ring, uint32_t rb_cntl)
765 /* Set ring buffer size in dwords */
766 uint32_t rb_bufsz = order_base_2(ring->ring_size / 4);
768 rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_SIZE, rb_bufsz);
770 rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_SWAP_ENABLE, 1);
771 rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL,
772 RPTR_WRITEBACK_SWAP_ENABLE, 1);
778 * sdma_v4_0_gfx_resume - setup and start the async dma engines
780 * @adev: amdgpu_device pointer
781 * @i: instance to resume
783 * Set up the gfx DMA ring buffers and enable them (VEGA10).
784 * Returns 0 for success, error for failure.
786 static void sdma_v4_0_gfx_resume(struct amdgpu_device *adev, unsigned int i)
788 struct amdgpu_ring *ring = &adev->sdma.instance[i].ring;
789 u32 rb_cntl, ib_cntl, wptr_poll_cntl;
795 wb_offset = (ring->rptr_offs * 4);
797 rb_cntl = RREG32_SDMA(i, mmSDMA0_GFX_RB_CNTL);
798 rb_cntl = sdma_v4_0_rb_cntl(ring, rb_cntl);
799 WREG32_SDMA(i, mmSDMA0_GFX_RB_CNTL, rb_cntl);
801 /* Initialize the ring buffer's read and write pointers */
802 WREG32_SDMA(i, mmSDMA0_GFX_RB_RPTR, 0);
803 WREG32_SDMA(i, mmSDMA0_GFX_RB_RPTR_HI, 0);
804 WREG32_SDMA(i, mmSDMA0_GFX_RB_WPTR, 0);
805 WREG32_SDMA(i, mmSDMA0_GFX_RB_WPTR_HI, 0);
807 /* set the wb address whether it's enabled or not */
808 WREG32_SDMA(i, mmSDMA0_GFX_RB_RPTR_ADDR_HI,
809 upper_32_bits(adev->wb.gpu_addr + wb_offset) & 0xFFFFFFFF);
810 WREG32_SDMA(i, mmSDMA0_GFX_RB_RPTR_ADDR_LO,
811 lower_32_bits(adev->wb.gpu_addr + wb_offset) & 0xFFFFFFFC);
813 rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL,
814 RPTR_WRITEBACK_ENABLE, 1);
816 WREG32_SDMA(i, mmSDMA0_GFX_RB_BASE, ring->gpu_addr >> 8);
817 WREG32_SDMA(i, mmSDMA0_GFX_RB_BASE_HI, ring->gpu_addr >> 40);
821 /* before programing wptr to a less value, need set minor_ptr_update first */
822 WREG32_SDMA(i, mmSDMA0_GFX_MINOR_PTR_UPDATE, 1);
824 doorbell = RREG32_SDMA(i, mmSDMA0_GFX_DOORBELL);
825 doorbell_offset = RREG32_SDMA(i, mmSDMA0_GFX_DOORBELL_OFFSET);
827 doorbell = REG_SET_FIELD(doorbell, SDMA0_GFX_DOORBELL, ENABLE,
829 doorbell_offset = REG_SET_FIELD(doorbell_offset,
830 SDMA0_GFX_DOORBELL_OFFSET,
831 OFFSET, ring->doorbell_index);
832 WREG32_SDMA(i, mmSDMA0_GFX_DOORBELL, doorbell);
833 WREG32_SDMA(i, mmSDMA0_GFX_DOORBELL_OFFSET, doorbell_offset);
834 adev->nbio_funcs->sdma_doorbell_range(adev, i, ring->use_doorbell,
835 ring->doorbell_index);
837 sdma_v4_0_ring_set_wptr(ring);
839 /* set minor_ptr_update to 0 after wptr programed */
840 WREG32_SDMA(i, mmSDMA0_GFX_MINOR_PTR_UPDATE, 0);
842 /* setup the wptr shadow polling */
843 wptr_gpu_addr = adev->wb.gpu_addr + (ring->wptr_offs * 4);
844 WREG32_SDMA(i, mmSDMA0_GFX_RB_WPTR_POLL_ADDR_LO,
845 lower_32_bits(wptr_gpu_addr));
846 WREG32_SDMA(i, mmSDMA0_GFX_RB_WPTR_POLL_ADDR_HI,
847 upper_32_bits(wptr_gpu_addr));
848 wptr_poll_cntl = RREG32_SDMA(i, mmSDMA0_GFX_RB_WPTR_POLL_CNTL);
849 wptr_poll_cntl = REG_SET_FIELD(wptr_poll_cntl,
850 SDMA0_GFX_RB_WPTR_POLL_CNTL,
851 F32_POLL_ENABLE, amdgpu_sriov_vf(adev));
852 WREG32_SDMA(i, mmSDMA0_GFX_RB_WPTR_POLL_CNTL, wptr_poll_cntl);
855 rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_ENABLE, 1);
856 WREG32_SDMA(i, mmSDMA0_GFX_RB_CNTL, rb_cntl);
858 ib_cntl = RREG32_SDMA(i, mmSDMA0_GFX_IB_CNTL);
859 ib_cntl = REG_SET_FIELD(ib_cntl, SDMA0_GFX_IB_CNTL, IB_ENABLE, 1);
861 ib_cntl = REG_SET_FIELD(ib_cntl, SDMA0_GFX_IB_CNTL, IB_SWAP_ENABLE, 1);
864 WREG32_SDMA(i, mmSDMA0_GFX_IB_CNTL, ib_cntl);
870 * sdma_v4_0_page_resume - setup and start the async dma engines
872 * @adev: amdgpu_device pointer
873 * @i: instance to resume
875 * Set up the page DMA ring buffers and enable them (VEGA10).
876 * Returns 0 for success, error for failure.
878 static void sdma_v4_0_page_resume(struct amdgpu_device *adev, unsigned int i)
880 struct amdgpu_ring *ring = &adev->sdma.instance[i].page;
881 u32 rb_cntl, ib_cntl, wptr_poll_cntl;
887 wb_offset = (ring->rptr_offs * 4);
889 rb_cntl = RREG32_SDMA(i, mmSDMA0_PAGE_RB_CNTL);
890 rb_cntl = sdma_v4_0_rb_cntl(ring, rb_cntl);
891 WREG32_SDMA(i, mmSDMA0_PAGE_RB_CNTL, rb_cntl);
893 /* Initialize the ring buffer's read and write pointers */
894 WREG32_SDMA(i, mmSDMA0_PAGE_RB_RPTR, 0);
895 WREG32_SDMA(i, mmSDMA0_PAGE_RB_RPTR_HI, 0);
896 WREG32_SDMA(i, mmSDMA0_PAGE_RB_WPTR, 0);
897 WREG32_SDMA(i, mmSDMA0_PAGE_RB_WPTR_HI, 0);
899 /* set the wb address whether it's enabled or not */
900 WREG32_SDMA(i, mmSDMA0_PAGE_RB_RPTR_ADDR_HI,
901 upper_32_bits(adev->wb.gpu_addr + wb_offset) & 0xFFFFFFFF);
902 WREG32_SDMA(i, mmSDMA0_PAGE_RB_RPTR_ADDR_LO,
903 lower_32_bits(adev->wb.gpu_addr + wb_offset) & 0xFFFFFFFC);
905 rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_PAGE_RB_CNTL,
906 RPTR_WRITEBACK_ENABLE, 1);
908 WREG32_SDMA(i, mmSDMA0_PAGE_RB_BASE, ring->gpu_addr >> 8);
909 WREG32_SDMA(i, mmSDMA0_PAGE_RB_BASE_HI, ring->gpu_addr >> 40);
913 /* before programing wptr to a less value, need set minor_ptr_update first */
914 WREG32_SDMA(i, mmSDMA0_PAGE_MINOR_PTR_UPDATE, 1);
916 doorbell = RREG32_SDMA(i, mmSDMA0_PAGE_DOORBELL);
917 doorbell_offset = RREG32_SDMA(i, mmSDMA0_PAGE_DOORBELL_OFFSET);
919 doorbell = REG_SET_FIELD(doorbell, SDMA0_PAGE_DOORBELL, ENABLE,
921 doorbell_offset = REG_SET_FIELD(doorbell_offset,
922 SDMA0_PAGE_DOORBELL_OFFSET,
923 OFFSET, ring->doorbell_index);
924 WREG32_SDMA(i, mmSDMA0_PAGE_DOORBELL, doorbell);
925 WREG32_SDMA(i, mmSDMA0_PAGE_DOORBELL_OFFSET, doorbell_offset);
926 /* TODO: enable doorbell support */
927 /*adev->nbio_funcs->sdma_doorbell_range(adev, i, ring->use_doorbell,
928 ring->doorbell_index);*/
930 sdma_v4_0_ring_set_wptr(ring);
932 /* set minor_ptr_update to 0 after wptr programed */
933 WREG32_SDMA(i, mmSDMA0_PAGE_MINOR_PTR_UPDATE, 0);
935 /* setup the wptr shadow polling */
936 wptr_gpu_addr = adev->wb.gpu_addr + (ring->wptr_offs * 4);
937 WREG32_SDMA(i, mmSDMA0_PAGE_RB_WPTR_POLL_ADDR_LO,
938 lower_32_bits(wptr_gpu_addr));
939 WREG32_SDMA(i, mmSDMA0_PAGE_RB_WPTR_POLL_ADDR_HI,
940 upper_32_bits(wptr_gpu_addr));
941 wptr_poll_cntl = RREG32_SDMA(i, mmSDMA0_PAGE_RB_WPTR_POLL_CNTL);
942 wptr_poll_cntl = REG_SET_FIELD(wptr_poll_cntl,
943 SDMA0_PAGE_RB_WPTR_POLL_CNTL,
944 F32_POLL_ENABLE, amdgpu_sriov_vf(adev));
945 WREG32_SDMA(i, mmSDMA0_PAGE_RB_WPTR_POLL_CNTL, wptr_poll_cntl);
948 rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_PAGE_RB_CNTL, RB_ENABLE, 1);
949 WREG32_SDMA(i, mmSDMA0_PAGE_RB_CNTL, rb_cntl);
951 ib_cntl = RREG32_SDMA(i, mmSDMA0_PAGE_IB_CNTL);
952 ib_cntl = REG_SET_FIELD(ib_cntl, SDMA0_PAGE_IB_CNTL, IB_ENABLE, 1);
954 ib_cntl = REG_SET_FIELD(ib_cntl, SDMA0_PAGE_IB_CNTL, IB_SWAP_ENABLE, 1);
957 WREG32_SDMA(i, mmSDMA0_PAGE_IB_CNTL, ib_cntl);
963 sdma_v4_1_update_power_gating(struct amdgpu_device *adev, bool enable)
967 if (enable && (adev->pg_flags & AMD_PG_SUPPORT_SDMA)) {
968 /* enable idle interrupt */
969 def = data = RREG32(SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_CNTL));
970 data |= SDMA0_CNTL__CTXEMPTY_INT_ENABLE_MASK;
973 WREG32(SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_CNTL), data);
975 /* disable idle interrupt */
976 def = data = RREG32(SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_CNTL));
977 data &= ~SDMA0_CNTL__CTXEMPTY_INT_ENABLE_MASK;
979 WREG32(SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_CNTL), data);
983 static void sdma_v4_1_init_power_gating(struct amdgpu_device *adev)
987 /* Enable HW based PG. */
988 def = data = RREG32(SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_POWER_CNTL));
989 data |= SDMA0_POWER_CNTL__PG_CNTL_ENABLE_MASK;
991 WREG32(SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_POWER_CNTL), data);
993 /* enable interrupt */
994 def = data = RREG32(SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_CNTL));
995 data |= SDMA0_CNTL__CTXEMPTY_INT_ENABLE_MASK;
997 WREG32(SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_CNTL), data);
999 /* Configure hold time to filter in-valid power on/off request. Use default right now */
1000 def = data = RREG32(SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_POWER_CNTL));
1001 data &= ~SDMA0_POWER_CNTL__ON_OFF_CONDITION_HOLD_TIME_MASK;
1002 data |= (mmSDMA0_POWER_CNTL_DEFAULT & SDMA0_POWER_CNTL__ON_OFF_CONDITION_HOLD_TIME_MASK);
1003 /* Configure switch time for hysteresis purpose. Use default right now */
1004 data &= ~SDMA0_POWER_CNTL__ON_OFF_STATUS_DURATION_TIME_MASK;
1005 data |= (mmSDMA0_POWER_CNTL_DEFAULT & SDMA0_POWER_CNTL__ON_OFF_STATUS_DURATION_TIME_MASK);
1007 WREG32(SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_POWER_CNTL), data);
1010 static void sdma_v4_0_init_pg(struct amdgpu_device *adev)
1012 if (!(adev->pg_flags & AMD_PG_SUPPORT_SDMA))
1015 switch (adev->asic_type) {
1017 sdma_v4_1_init_power_gating(adev);
1018 sdma_v4_1_update_power_gating(adev, true);
1026 * sdma_v4_0_rlc_resume - setup and start the async dma engines
1028 * @adev: amdgpu_device pointer
1030 * Set up the compute DMA queues and enable them (VEGA10).
1031 * Returns 0 for success, error for failure.
1033 static int sdma_v4_0_rlc_resume(struct amdgpu_device *adev)
1035 sdma_v4_0_init_pg(adev);
1041 * sdma_v4_0_load_microcode - load the sDMA ME ucode
1043 * @adev: amdgpu_device pointer
1045 * Loads the sDMA0/1 ucode.
1046 * Returns 0 for success, -EINVAL if the ucode is not available.
1048 static int sdma_v4_0_load_microcode(struct amdgpu_device *adev)
1050 const struct sdma_firmware_header_v1_0 *hdr;
1051 const __le32 *fw_data;
1056 sdma_v4_0_enable(adev, false);
1058 for (i = 0; i < adev->sdma.num_instances; i++) {
1059 if (!adev->sdma.instance[i].fw)
1062 hdr = (const struct sdma_firmware_header_v1_0 *)adev->sdma.instance[i].fw->data;
1063 amdgpu_ucode_print_sdma_hdr(&hdr->header);
1064 fw_size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4;
1066 fw_data = (const __le32 *)
1067 (adev->sdma.instance[i].fw->data +
1068 le32_to_cpu(hdr->header.ucode_array_offset_bytes));
1070 WREG32_SDMA(i, mmSDMA0_UCODE_ADDR, 0);
1072 for (j = 0; j < fw_size; j++)
1073 WREG32_SDMA(i, mmSDMA0_UCODE_DATA,
1074 le32_to_cpup(fw_data++));
1076 WREG32_SDMA(i, mmSDMA0_UCODE_ADDR,
1077 adev->sdma.instance[i].fw_version);
1084 * sdma_v4_0_start - setup and start the async dma engines
1086 * @adev: amdgpu_device pointer
1088 * Set up the DMA engines and enable them (VEGA10).
1089 * Returns 0 for success, error for failure.
1091 static int sdma_v4_0_start(struct amdgpu_device *adev)
1093 struct amdgpu_ring *ring;
1096 if (amdgpu_sriov_vf(adev)) {
1097 sdma_v4_0_ctx_switch_enable(adev, false);
1098 sdma_v4_0_enable(adev, false);
1101 if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP) {
1102 r = sdma_v4_0_load_microcode(adev);
1107 /* unhalt the MEs */
1108 sdma_v4_0_enable(adev, true);
1109 /* enable sdma ring preemption */
1110 sdma_v4_0_ctx_switch_enable(adev, true);
1113 /* start the gfx rings and rlc compute queues */
1114 for (i = 0; i < adev->sdma.num_instances; i++) {
1117 WREG32_SDMA(i, mmSDMA0_SEM_WAIT_FAIL_TIMER_CNTL, 0);
1118 sdma_v4_0_gfx_resume(adev, i);
1119 if (adev->sdma.has_page_queue)
1120 sdma_v4_0_page_resume(adev, i);
1122 /* set utc l1 enable flag always to 1 */
1123 temp = RREG32_SDMA(i, mmSDMA0_CNTL);
1124 temp = REG_SET_FIELD(temp, SDMA0_CNTL, UTC_L1_ENABLE, 1);
1125 WREG32_SDMA(i, mmSDMA0_CNTL, temp);
1127 if (!amdgpu_sriov_vf(adev)) {
1129 temp = RREG32_SDMA(i, mmSDMA0_F32_CNTL);
1130 temp = REG_SET_FIELD(temp, SDMA0_F32_CNTL, HALT, 0);
1131 WREG32_SDMA(i, mmSDMA0_F32_CNTL, temp);
1135 if (amdgpu_sriov_vf(adev)) {
1136 sdma_v4_0_ctx_switch_enable(adev, true);
1137 sdma_v4_0_enable(adev, true);
1139 r = sdma_v4_0_rlc_resume(adev);
1144 for (i = 0; i < adev->sdma.num_instances; i++) {
1145 ring = &adev->sdma.instance[i].ring;
1147 r = amdgpu_ring_test_ring(ring);
1149 ring->ready = false;
1153 if (adev->sdma.has_page_queue) {
1154 struct amdgpu_ring *page = &adev->sdma.instance[i].page;
1156 r = amdgpu_ring_test_ring(page);
1158 page->ready = false;
1163 if (adev->mman.buffer_funcs_ring == ring)
1164 amdgpu_ttm_set_buffer_funcs_status(adev, true);
1171 * sdma_v4_0_ring_test_ring - simple async dma engine test
1173 * @ring: amdgpu_ring structure holding ring information
1175 * Test the DMA engine by writing using it to write an
1176 * value to memory. (VEGA10).
1177 * Returns 0 for success, error for failure.
1179 static int sdma_v4_0_ring_test_ring(struct amdgpu_ring *ring)
1181 struct amdgpu_device *adev = ring->adev;
1188 r = amdgpu_device_wb_get(adev, &index);
1190 dev_err(adev->dev, "(%d) failed to allocate wb slot\n", r);
1194 gpu_addr = adev->wb.gpu_addr + (index * 4);
1196 adev->wb.wb[index] = cpu_to_le32(tmp);
1198 r = amdgpu_ring_alloc(ring, 5);
1200 DRM_ERROR("amdgpu: dma failed to lock ring %d (%d).\n", ring->idx, r);
1201 amdgpu_device_wb_free(adev, index);
1205 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
1206 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR));
1207 amdgpu_ring_write(ring, lower_32_bits(gpu_addr));
1208 amdgpu_ring_write(ring, upper_32_bits(gpu_addr));
1209 amdgpu_ring_write(ring, SDMA_PKT_WRITE_UNTILED_DW_3_COUNT(0));
1210 amdgpu_ring_write(ring, 0xDEADBEEF);
1211 amdgpu_ring_commit(ring);
1213 for (i = 0; i < adev->usec_timeout; i++) {
1214 tmp = le32_to_cpu(adev->wb.wb[index]);
1215 if (tmp == 0xDEADBEEF)
1220 if (i < adev->usec_timeout) {
1221 DRM_DEBUG("ring test on %d succeeded in %d usecs\n", ring->idx, i);
1223 DRM_ERROR("amdgpu: ring %d test failed (0x%08X)\n",
1227 amdgpu_device_wb_free(adev, index);
1233 * sdma_v4_0_ring_test_ib - test an IB on the DMA engine
1235 * @ring: amdgpu_ring structure holding ring information
1237 * Test a simple IB in the DMA ring (VEGA10).
1238 * Returns 0 on success, error on failure.
1240 static int sdma_v4_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)
1242 struct amdgpu_device *adev = ring->adev;
1243 struct amdgpu_ib ib;
1244 struct dma_fence *f = NULL;
1250 r = amdgpu_device_wb_get(adev, &index);
1252 dev_err(adev->dev, "(%ld) failed to allocate wb slot\n", r);
1256 gpu_addr = adev->wb.gpu_addr + (index * 4);
1258 adev->wb.wb[index] = cpu_to_le32(tmp);
1259 memset(&ib, 0, sizeof(ib));
1260 r = amdgpu_ib_get(adev, NULL, 256, &ib);
1262 DRM_ERROR("amdgpu: failed to get ib (%ld).\n", r);
1266 ib.ptr[0] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
1267 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
1268 ib.ptr[1] = lower_32_bits(gpu_addr);
1269 ib.ptr[2] = upper_32_bits(gpu_addr);
1270 ib.ptr[3] = SDMA_PKT_WRITE_UNTILED_DW_3_COUNT(0);
1271 ib.ptr[4] = 0xDEADBEEF;
1272 ib.ptr[5] = SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP);
1273 ib.ptr[6] = SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP);
1274 ib.ptr[7] = SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP);
1277 r = amdgpu_ib_schedule(ring, 1, &ib, NULL, &f);
1281 r = dma_fence_wait_timeout(f, false, timeout);
1283 DRM_ERROR("amdgpu: IB test timed out\n");
1287 DRM_ERROR("amdgpu: fence wait failed (%ld).\n", r);
1290 tmp = le32_to_cpu(adev->wb.wb[index]);
1291 if (tmp == 0xDEADBEEF) {
1292 DRM_DEBUG("ib test on ring %d succeeded\n", ring->idx);
1295 DRM_ERROR("amdgpu: ib test failed (0x%08X)\n", tmp);
1299 amdgpu_ib_free(adev, &ib, NULL);
1302 amdgpu_device_wb_free(adev, index);
1308 * sdma_v4_0_vm_copy_pte - update PTEs by copying them from the GART
1310 * @ib: indirect buffer to fill with commands
1311 * @pe: addr of the page entry
1312 * @src: src addr to copy from
1313 * @count: number of page entries to update
1315 * Update PTEs by copying them from the GART using sDMA (VEGA10).
1317 static void sdma_v4_0_vm_copy_pte(struct amdgpu_ib *ib,
1318 uint64_t pe, uint64_t src,
1321 unsigned bytes = count * 8;
1323 ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
1324 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
1325 ib->ptr[ib->length_dw++] = bytes - 1;
1326 ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
1327 ib->ptr[ib->length_dw++] = lower_32_bits(src);
1328 ib->ptr[ib->length_dw++] = upper_32_bits(src);
1329 ib->ptr[ib->length_dw++] = lower_32_bits(pe);
1330 ib->ptr[ib->length_dw++] = upper_32_bits(pe);
1335 * sdma_v4_0_vm_write_pte - update PTEs by writing them manually
1337 * @ib: indirect buffer to fill with commands
1338 * @pe: addr of the page entry
1339 * @addr: dst addr to write into pe
1340 * @count: number of page entries to update
1341 * @incr: increase next addr by incr bytes
1342 * @flags: access flags
1344 * Update PTEs by writing them manually using sDMA (VEGA10).
1346 static void sdma_v4_0_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe,
1347 uint64_t value, unsigned count,
1350 unsigned ndw = count * 2;
1352 ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
1353 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
1354 ib->ptr[ib->length_dw++] = lower_32_bits(pe);
1355 ib->ptr[ib->length_dw++] = upper_32_bits(pe);
1356 ib->ptr[ib->length_dw++] = ndw - 1;
1357 for (; ndw > 0; ndw -= 2) {
1358 ib->ptr[ib->length_dw++] = lower_32_bits(value);
1359 ib->ptr[ib->length_dw++] = upper_32_bits(value);
1365 * sdma_v4_0_vm_set_pte_pde - update the page tables using sDMA
1367 * @ib: indirect buffer to fill with commands
1368 * @pe: addr of the page entry
1369 * @addr: dst addr to write into pe
1370 * @count: number of page entries to update
1371 * @incr: increase next addr by incr bytes
1372 * @flags: access flags
1374 * Update the page tables using sDMA (VEGA10).
1376 static void sdma_v4_0_vm_set_pte_pde(struct amdgpu_ib *ib,
1378 uint64_t addr, unsigned count,
1379 uint32_t incr, uint64_t flags)
1381 /* for physically contiguous pages (vram) */
1382 ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_PTEPDE);
1383 ib->ptr[ib->length_dw++] = lower_32_bits(pe); /* dst addr */
1384 ib->ptr[ib->length_dw++] = upper_32_bits(pe);
1385 ib->ptr[ib->length_dw++] = lower_32_bits(flags); /* mask */
1386 ib->ptr[ib->length_dw++] = upper_32_bits(flags);
1387 ib->ptr[ib->length_dw++] = lower_32_bits(addr); /* value */
1388 ib->ptr[ib->length_dw++] = upper_32_bits(addr);
1389 ib->ptr[ib->length_dw++] = incr; /* increment size */
1390 ib->ptr[ib->length_dw++] = 0;
1391 ib->ptr[ib->length_dw++] = count - 1; /* number of entries */
1395 * sdma_v4_0_ring_pad_ib - pad the IB to the required number of dw
1397 * @ib: indirect buffer to fill with padding
1400 static void sdma_v4_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)
1402 struct amdgpu_sdma_instance *sdma = amdgpu_get_sdma_instance(ring);
1406 pad_count = (8 - (ib->length_dw & 0x7)) % 8;
1407 for (i = 0; i < pad_count; i++)
1408 if (sdma && sdma->burst_nop && (i == 0))
1409 ib->ptr[ib->length_dw++] =
1410 SDMA_PKT_HEADER_OP(SDMA_OP_NOP) |
1411 SDMA_PKT_NOP_HEADER_COUNT(pad_count - 1);
1413 ib->ptr[ib->length_dw++] =
1414 SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
1419 * sdma_v4_0_ring_emit_pipeline_sync - sync the pipeline
1421 * @ring: amdgpu_ring pointer
1423 * Make sure all previous operations are completed (CIK).
1425 static void sdma_v4_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)
1427 uint32_t seq = ring->fence_drv.sync_seq;
1428 uint64_t addr = ring->fence_drv.gpu_addr;
1431 sdma_v4_0_wait_reg_mem(ring, 1, 0,
1433 upper_32_bits(addr) & 0xffffffff,
1434 seq, 0xffffffff, 4);
1439 * sdma_v4_0_ring_emit_vm_flush - vm flush using sDMA
1441 * @ring: amdgpu_ring pointer
1442 * @vm: amdgpu_vm pointer
1444 * Update the page table base and flush the VM TLB
1445 * using sDMA (VEGA10).
1447 static void sdma_v4_0_ring_emit_vm_flush(struct amdgpu_ring *ring,
1448 unsigned vmid, uint64_t pd_addr)
1450 amdgpu_gmc_emit_flush_gpu_tlb(ring, vmid, pd_addr);
1453 static void sdma_v4_0_ring_emit_wreg(struct amdgpu_ring *ring,
1454 uint32_t reg, uint32_t val)
1456 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_SRBM_WRITE) |
1457 SDMA_PKT_SRBM_WRITE_HEADER_BYTE_EN(0xf));
1458 amdgpu_ring_write(ring, reg);
1459 amdgpu_ring_write(ring, val);
1462 static void sdma_v4_0_ring_emit_reg_wait(struct amdgpu_ring *ring, uint32_t reg,
1463 uint32_t val, uint32_t mask)
1465 sdma_v4_0_wait_reg_mem(ring, 0, 0, reg, 0, val, mask, 10);
1468 static int sdma_v4_0_early_init(void *handle)
1470 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1472 if (adev->asic_type == CHIP_RAVEN) {
1473 adev->sdma.num_instances = 1;
1474 adev->sdma.has_page_queue = false;
1476 adev->sdma.num_instances = 2;
1477 if (adev->asic_type != CHIP_VEGA20)
1478 adev->sdma.has_page_queue = true;
1481 sdma_v4_0_set_ring_funcs(adev);
1482 sdma_v4_0_set_buffer_funcs(adev);
1483 sdma_v4_0_set_vm_pte_funcs(adev);
1484 sdma_v4_0_set_irq_funcs(adev);
1490 static int sdma_v4_0_sw_init(void *handle)
1492 struct amdgpu_ring *ring;
1494 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1496 /* SDMA trap event */
1497 r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_SDMA0, SDMA0_4_0__SRCID__SDMA_TRAP,
1498 &adev->sdma.trap_irq);
1502 /* SDMA trap event */
1503 r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_SDMA1, SDMA1_4_0__SRCID__SDMA_TRAP,
1504 &adev->sdma.trap_irq);
1508 r = sdma_v4_0_init_microcode(adev);
1510 DRM_ERROR("Failed to load sdma firmware!\n");
1514 for (i = 0; i < adev->sdma.num_instances; i++) {
1515 ring = &adev->sdma.instance[i].ring;
1516 ring->ring_obj = NULL;
1517 ring->use_doorbell = true;
1519 DRM_INFO("use_doorbell being set to: [%s]\n",
1520 ring->use_doorbell?"true":"false");
1522 if (adev->asic_type == CHIP_VEGA10)
1523 ring->doorbell_index = (i == 0) ?
1524 (AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE0 << 1) //get DWORD offset
1525 : (AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE1 << 1); // get DWORD offset
1527 ring->doorbell_index = (i == 0) ?
1528 (AMDGPU_DOORBELL64_sDMA_ENGINE0 << 1) //get DWORD offset
1529 : (AMDGPU_DOORBELL64_sDMA_ENGINE1 << 1); // get DWORD offset
1532 sprintf(ring->name, "sdma%d", i);
1533 r = amdgpu_ring_init(adev, ring, 1024,
1534 &adev->sdma.trap_irq,
1536 AMDGPU_SDMA_IRQ_TRAP0 :
1537 AMDGPU_SDMA_IRQ_TRAP1);
1541 if (adev->sdma.has_page_queue) {
1542 ring = &adev->sdma.instance[i].page;
1543 ring->ring_obj = NULL;
1544 ring->use_doorbell = false;
1546 sprintf(ring->name, "page%d", i);
1547 r = amdgpu_ring_init(adev, ring, 1024,
1548 &adev->sdma.trap_irq,
1550 AMDGPU_SDMA_IRQ_TRAP0 :
1551 AMDGPU_SDMA_IRQ_TRAP1);
1560 static int sdma_v4_0_sw_fini(void *handle)
1562 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1565 for (i = 0; i < adev->sdma.num_instances; i++) {
1566 amdgpu_ring_fini(&adev->sdma.instance[i].ring);
1567 if (adev->sdma.has_page_queue)
1568 amdgpu_ring_fini(&adev->sdma.instance[i].page);
1571 for (i = 0; i < adev->sdma.num_instances; i++) {
1572 release_firmware(adev->sdma.instance[i].fw);
1573 adev->sdma.instance[i].fw = NULL;
1579 static int sdma_v4_0_hw_init(void *handle)
1582 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1584 if (adev->asic_type == CHIP_RAVEN && adev->powerplay.pp_funcs &&
1585 adev->powerplay.pp_funcs->set_powergating_by_smu)
1586 amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_SDMA, false);
1588 sdma_v4_0_init_golden_registers(adev);
1590 r = sdma_v4_0_start(adev);
1595 static int sdma_v4_0_hw_fini(void *handle)
1597 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1599 if (amdgpu_sriov_vf(adev))
1602 sdma_v4_0_ctx_switch_enable(adev, false);
1603 sdma_v4_0_enable(adev, false);
1605 if (adev->asic_type == CHIP_RAVEN && adev->powerplay.pp_funcs
1606 && adev->powerplay.pp_funcs->set_powergating_by_smu)
1607 amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_SDMA, true);
1612 static int sdma_v4_0_suspend(void *handle)
1614 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1616 return sdma_v4_0_hw_fini(adev);
1619 static int sdma_v4_0_resume(void *handle)
1621 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1623 return sdma_v4_0_hw_init(adev);
1626 static bool sdma_v4_0_is_idle(void *handle)
1628 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1631 for (i = 0; i < adev->sdma.num_instances; i++) {
1632 u32 tmp = RREG32_SDMA(i, mmSDMA0_STATUS_REG);
1634 if (!(tmp & SDMA0_STATUS_REG__IDLE_MASK))
1641 static int sdma_v4_0_wait_for_idle(void *handle)
1645 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1647 for (i = 0; i < adev->usec_timeout; i++) {
1648 sdma0 = RREG32_SDMA(0, mmSDMA0_STATUS_REG);
1649 sdma1 = RREG32_SDMA(1, mmSDMA0_STATUS_REG);
1651 if (sdma0 & sdma1 & SDMA0_STATUS_REG__IDLE_MASK)
1658 static int sdma_v4_0_soft_reset(void *handle)
1665 static int sdma_v4_0_set_trap_irq_state(struct amdgpu_device *adev,
1666 struct amdgpu_irq_src *source,
1668 enum amdgpu_interrupt_state state)
1670 unsigned int instance = (type == AMDGPU_SDMA_IRQ_TRAP0) ? 0 : 1;
1673 sdma_cntl = RREG32_SDMA(instance, mmSDMA0_CNTL);
1674 sdma_cntl = REG_SET_FIELD(sdma_cntl, SDMA0_CNTL, TRAP_ENABLE,
1675 state == AMDGPU_IRQ_STATE_ENABLE ? 1 : 0);
1676 WREG32_SDMA(instance, mmSDMA0_CNTL, sdma_cntl);
1681 static int sdma_v4_0_process_trap_irq(struct amdgpu_device *adev,
1682 struct amdgpu_irq_src *source,
1683 struct amdgpu_iv_entry *entry)
1687 DRM_DEBUG("IH: SDMA trap\n");
1688 switch (entry->client_id) {
1689 case SOC15_IH_CLIENTID_SDMA0:
1692 case SOC15_IH_CLIENTID_SDMA1:
1699 switch (entry->ring_id) {
1701 amdgpu_fence_process(&adev->sdma.instance[instance].ring);
1710 amdgpu_fence_process(&adev->sdma.instance[instance].page);
1716 static int sdma_v4_0_process_illegal_inst_irq(struct amdgpu_device *adev,
1717 struct amdgpu_irq_src *source,
1718 struct amdgpu_iv_entry *entry)
1722 DRM_ERROR("Illegal instruction in SDMA command stream\n");
1724 switch (entry->client_id) {
1725 case SOC15_IH_CLIENTID_SDMA0:
1728 case SOC15_IH_CLIENTID_SDMA1:
1735 switch (entry->ring_id) {
1737 drm_sched_fault(&adev->sdma.instance[instance].ring.sched);
1743 static void sdma_v4_0_update_medium_grain_clock_gating(
1744 struct amdgpu_device *adev,
1749 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_SDMA_MGCG)) {
1750 /* enable sdma0 clock gating */
1751 def = data = RREG32(SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_CLK_CTRL));
1752 data &= ~(SDMA0_CLK_CTRL__SOFT_OVERRIDE7_MASK |
1753 SDMA0_CLK_CTRL__SOFT_OVERRIDE6_MASK |
1754 SDMA0_CLK_CTRL__SOFT_OVERRIDE5_MASK |
1755 SDMA0_CLK_CTRL__SOFT_OVERRIDE4_MASK |
1756 SDMA0_CLK_CTRL__SOFT_OVERRIDE3_MASK |
1757 SDMA0_CLK_CTRL__SOFT_OVERRIDE2_MASK |
1758 SDMA0_CLK_CTRL__SOFT_OVERRIDE1_MASK |
1759 SDMA0_CLK_CTRL__SOFT_OVERRIDE0_MASK);
1761 WREG32(SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_CLK_CTRL), data);
1763 if (adev->sdma.num_instances > 1) {
1764 def = data = RREG32(SOC15_REG_OFFSET(SDMA1, 0, mmSDMA1_CLK_CTRL));
1765 data &= ~(SDMA1_CLK_CTRL__SOFT_OVERRIDE7_MASK |
1766 SDMA1_CLK_CTRL__SOFT_OVERRIDE6_MASK |
1767 SDMA1_CLK_CTRL__SOFT_OVERRIDE5_MASK |
1768 SDMA1_CLK_CTRL__SOFT_OVERRIDE4_MASK |
1769 SDMA1_CLK_CTRL__SOFT_OVERRIDE3_MASK |
1770 SDMA1_CLK_CTRL__SOFT_OVERRIDE2_MASK |
1771 SDMA1_CLK_CTRL__SOFT_OVERRIDE1_MASK |
1772 SDMA1_CLK_CTRL__SOFT_OVERRIDE0_MASK);
1774 WREG32(SOC15_REG_OFFSET(SDMA1, 0, mmSDMA1_CLK_CTRL), data);
1777 /* disable sdma0 clock gating */
1778 def = data = RREG32(SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_CLK_CTRL));
1779 data |= (SDMA0_CLK_CTRL__SOFT_OVERRIDE7_MASK |
1780 SDMA0_CLK_CTRL__SOFT_OVERRIDE6_MASK |
1781 SDMA0_CLK_CTRL__SOFT_OVERRIDE5_MASK |
1782 SDMA0_CLK_CTRL__SOFT_OVERRIDE4_MASK |
1783 SDMA0_CLK_CTRL__SOFT_OVERRIDE3_MASK |
1784 SDMA0_CLK_CTRL__SOFT_OVERRIDE2_MASK |
1785 SDMA0_CLK_CTRL__SOFT_OVERRIDE1_MASK |
1786 SDMA0_CLK_CTRL__SOFT_OVERRIDE0_MASK);
1789 WREG32(SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_CLK_CTRL), data);
1791 if (adev->sdma.num_instances > 1) {
1792 def = data = RREG32(SOC15_REG_OFFSET(SDMA1, 0, mmSDMA1_CLK_CTRL));
1793 data |= (SDMA1_CLK_CTRL__SOFT_OVERRIDE7_MASK |
1794 SDMA1_CLK_CTRL__SOFT_OVERRIDE6_MASK |
1795 SDMA1_CLK_CTRL__SOFT_OVERRIDE5_MASK |
1796 SDMA1_CLK_CTRL__SOFT_OVERRIDE4_MASK |
1797 SDMA1_CLK_CTRL__SOFT_OVERRIDE3_MASK |
1798 SDMA1_CLK_CTRL__SOFT_OVERRIDE2_MASK |
1799 SDMA1_CLK_CTRL__SOFT_OVERRIDE1_MASK |
1800 SDMA1_CLK_CTRL__SOFT_OVERRIDE0_MASK);
1802 WREG32(SOC15_REG_OFFSET(SDMA1, 0, mmSDMA1_CLK_CTRL), data);
1808 static void sdma_v4_0_update_medium_grain_light_sleep(
1809 struct amdgpu_device *adev,
1814 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_SDMA_LS)) {
1815 /* 1-not override: enable sdma0 mem light sleep */
1816 def = data = RREG32(SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_POWER_CNTL));
1817 data |= SDMA0_POWER_CNTL__MEM_POWER_OVERRIDE_MASK;
1819 WREG32(SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_POWER_CNTL), data);
1821 /* 1-not override: enable sdma1 mem light sleep */
1822 if (adev->sdma.num_instances > 1) {
1823 def = data = RREG32(SOC15_REG_OFFSET(SDMA1, 0, mmSDMA1_POWER_CNTL));
1824 data |= SDMA1_POWER_CNTL__MEM_POWER_OVERRIDE_MASK;
1826 WREG32(SOC15_REG_OFFSET(SDMA1, 0, mmSDMA1_POWER_CNTL), data);
1829 /* 0-override:disable sdma0 mem light sleep */
1830 def = data = RREG32(SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_POWER_CNTL));
1831 data &= ~SDMA0_POWER_CNTL__MEM_POWER_OVERRIDE_MASK;
1833 WREG32(SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_POWER_CNTL), data);
1835 /* 0-override:disable sdma1 mem light sleep */
1836 if (adev->sdma.num_instances > 1) {
1837 def = data = RREG32(SOC15_REG_OFFSET(SDMA1, 0, mmSDMA1_POWER_CNTL));
1838 data &= ~SDMA1_POWER_CNTL__MEM_POWER_OVERRIDE_MASK;
1840 WREG32(SOC15_REG_OFFSET(SDMA1, 0, mmSDMA1_POWER_CNTL), data);
1845 static int sdma_v4_0_set_clockgating_state(void *handle,
1846 enum amd_clockgating_state state)
1848 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1850 if (amdgpu_sriov_vf(adev))
1853 switch (adev->asic_type) {
1858 sdma_v4_0_update_medium_grain_clock_gating(adev,
1859 state == AMD_CG_STATE_GATE ? true : false);
1860 sdma_v4_0_update_medium_grain_light_sleep(adev,
1861 state == AMD_CG_STATE_GATE ? true : false);
1869 static int sdma_v4_0_set_powergating_state(void *handle,
1870 enum amd_powergating_state state)
1872 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1874 switch (adev->asic_type) {
1876 sdma_v4_1_update_power_gating(adev,
1877 state == AMD_PG_STATE_GATE ? true : false);
1886 static void sdma_v4_0_get_clockgating_state(void *handle, u32 *flags)
1888 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1891 if (amdgpu_sriov_vf(adev))
1894 /* AMD_CG_SUPPORT_SDMA_MGCG */
1895 data = RREG32(SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_CLK_CTRL));
1896 if (!(data & SDMA0_CLK_CTRL__SOFT_OVERRIDE7_MASK))
1897 *flags |= AMD_CG_SUPPORT_SDMA_MGCG;
1899 /* AMD_CG_SUPPORT_SDMA_LS */
1900 data = RREG32(SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_POWER_CNTL));
1901 if (data & SDMA0_POWER_CNTL__MEM_POWER_OVERRIDE_MASK)
1902 *flags |= AMD_CG_SUPPORT_SDMA_LS;
1905 const struct amd_ip_funcs sdma_v4_0_ip_funcs = {
1906 .name = "sdma_v4_0",
1907 .early_init = sdma_v4_0_early_init,
1909 .sw_init = sdma_v4_0_sw_init,
1910 .sw_fini = sdma_v4_0_sw_fini,
1911 .hw_init = sdma_v4_0_hw_init,
1912 .hw_fini = sdma_v4_0_hw_fini,
1913 .suspend = sdma_v4_0_suspend,
1914 .resume = sdma_v4_0_resume,
1915 .is_idle = sdma_v4_0_is_idle,
1916 .wait_for_idle = sdma_v4_0_wait_for_idle,
1917 .soft_reset = sdma_v4_0_soft_reset,
1918 .set_clockgating_state = sdma_v4_0_set_clockgating_state,
1919 .set_powergating_state = sdma_v4_0_set_powergating_state,
1920 .get_clockgating_state = sdma_v4_0_get_clockgating_state,
1923 static const struct amdgpu_ring_funcs sdma_v4_0_ring_funcs = {
1924 .type = AMDGPU_RING_TYPE_SDMA,
1926 .nop = SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP),
1927 .support_64bit_ptrs = true,
1928 .vmhub = AMDGPU_MMHUB,
1929 .get_rptr = sdma_v4_0_ring_get_rptr,
1930 .get_wptr = sdma_v4_0_ring_get_wptr,
1931 .set_wptr = sdma_v4_0_ring_set_wptr,
1933 6 + /* sdma_v4_0_ring_emit_hdp_flush */
1934 3 + /* hdp invalidate */
1935 6 + /* sdma_v4_0_ring_emit_pipeline_sync */
1936 /* sdma_v4_0_ring_emit_vm_flush */
1937 SOC15_FLUSH_GPU_TLB_NUM_WREG * 3 +
1938 SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT * 6 +
1939 10 + 10 + 10, /* sdma_v4_0_ring_emit_fence x3 for user fence, vm fence */
1940 .emit_ib_size = 7 + 6, /* sdma_v4_0_ring_emit_ib */
1941 .emit_ib = sdma_v4_0_ring_emit_ib,
1942 .emit_fence = sdma_v4_0_ring_emit_fence,
1943 .emit_pipeline_sync = sdma_v4_0_ring_emit_pipeline_sync,
1944 .emit_vm_flush = sdma_v4_0_ring_emit_vm_flush,
1945 .emit_hdp_flush = sdma_v4_0_ring_emit_hdp_flush,
1946 .test_ring = sdma_v4_0_ring_test_ring,
1947 .test_ib = sdma_v4_0_ring_test_ib,
1948 .insert_nop = sdma_v4_0_ring_insert_nop,
1949 .pad_ib = sdma_v4_0_ring_pad_ib,
1950 .emit_wreg = sdma_v4_0_ring_emit_wreg,
1951 .emit_reg_wait = sdma_v4_0_ring_emit_reg_wait,
1952 .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
1955 static const struct amdgpu_ring_funcs sdma_v4_0_page_ring_funcs = {
1956 .type = AMDGPU_RING_TYPE_SDMA,
1958 .nop = SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP),
1959 .support_64bit_ptrs = true,
1960 .vmhub = AMDGPU_MMHUB,
1961 .get_rptr = sdma_v4_0_ring_get_rptr,
1962 .get_wptr = sdma_v4_0_page_ring_get_wptr,
1963 .set_wptr = sdma_v4_0_page_ring_set_wptr,
1965 6 + /* sdma_v4_0_ring_emit_hdp_flush */
1966 3 + /* hdp invalidate */
1967 6 + /* sdma_v4_0_ring_emit_pipeline_sync */
1968 /* sdma_v4_0_ring_emit_vm_flush */
1969 SOC15_FLUSH_GPU_TLB_NUM_WREG * 3 +
1970 SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT * 6 +
1971 10 + 10 + 10, /* sdma_v4_0_ring_emit_fence x3 for user fence, vm fence */
1972 .emit_ib_size = 7 + 6, /* sdma_v4_0_ring_emit_ib */
1973 .emit_ib = sdma_v4_0_ring_emit_ib,
1974 .emit_fence = sdma_v4_0_ring_emit_fence,
1975 .emit_pipeline_sync = sdma_v4_0_ring_emit_pipeline_sync,
1976 .emit_vm_flush = sdma_v4_0_ring_emit_vm_flush,
1977 .emit_hdp_flush = sdma_v4_0_ring_emit_hdp_flush,
1978 .test_ring = sdma_v4_0_ring_test_ring,
1979 .test_ib = sdma_v4_0_ring_test_ib,
1980 .insert_nop = sdma_v4_0_ring_insert_nop,
1981 .pad_ib = sdma_v4_0_ring_pad_ib,
1982 .emit_wreg = sdma_v4_0_ring_emit_wreg,
1983 .emit_reg_wait = sdma_v4_0_ring_emit_reg_wait,
1984 .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
1987 static void sdma_v4_0_set_ring_funcs(struct amdgpu_device *adev)
1991 for (i = 0; i < adev->sdma.num_instances; i++) {
1992 adev->sdma.instance[i].ring.funcs = &sdma_v4_0_ring_funcs;
1993 adev->sdma.instance[i].ring.me = i;
1994 if (adev->sdma.has_page_queue) {
1995 adev->sdma.instance[i].page.funcs = &sdma_v4_0_page_ring_funcs;
1996 adev->sdma.instance[i].page.me = i;
2001 static const struct amdgpu_irq_src_funcs sdma_v4_0_trap_irq_funcs = {
2002 .set = sdma_v4_0_set_trap_irq_state,
2003 .process = sdma_v4_0_process_trap_irq,
2006 static const struct amdgpu_irq_src_funcs sdma_v4_0_illegal_inst_irq_funcs = {
2007 .process = sdma_v4_0_process_illegal_inst_irq,
2010 static void sdma_v4_0_set_irq_funcs(struct amdgpu_device *adev)
2012 adev->sdma.trap_irq.num_types = AMDGPU_SDMA_IRQ_LAST;
2013 adev->sdma.trap_irq.funcs = &sdma_v4_0_trap_irq_funcs;
2014 adev->sdma.illegal_inst_irq.funcs = &sdma_v4_0_illegal_inst_irq_funcs;
2018 * sdma_v4_0_emit_copy_buffer - copy buffer using the sDMA engine
2020 * @ring: amdgpu_ring structure holding ring information
2021 * @src_offset: src GPU address
2022 * @dst_offset: dst GPU address
2023 * @byte_count: number of bytes to xfer
2025 * Copy GPU buffers using the DMA engine (VEGA10/12).
2026 * Used by the amdgpu ttm implementation to move pages if
2027 * registered as the asic copy callback.
2029 static void sdma_v4_0_emit_copy_buffer(struct amdgpu_ib *ib,
2030 uint64_t src_offset,
2031 uint64_t dst_offset,
2032 uint32_t byte_count)
2034 ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
2035 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
2036 ib->ptr[ib->length_dw++] = byte_count - 1;
2037 ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
2038 ib->ptr[ib->length_dw++] = lower_32_bits(src_offset);
2039 ib->ptr[ib->length_dw++] = upper_32_bits(src_offset);
2040 ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
2041 ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
2045 * sdma_v4_0_emit_fill_buffer - fill buffer using the sDMA engine
2047 * @ring: amdgpu_ring structure holding ring information
2048 * @src_data: value to write to buffer
2049 * @dst_offset: dst GPU address
2050 * @byte_count: number of bytes to xfer
2052 * Fill GPU buffers using the DMA engine (VEGA10/12).
2054 static void sdma_v4_0_emit_fill_buffer(struct amdgpu_ib *ib,
2056 uint64_t dst_offset,
2057 uint32_t byte_count)
2059 ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_CONST_FILL);
2060 ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
2061 ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
2062 ib->ptr[ib->length_dw++] = src_data;
2063 ib->ptr[ib->length_dw++] = byte_count - 1;
2066 static const struct amdgpu_buffer_funcs sdma_v4_0_buffer_funcs = {
2067 .copy_max_bytes = 0x400000,
2069 .emit_copy_buffer = sdma_v4_0_emit_copy_buffer,
2071 .fill_max_bytes = 0x400000,
2073 .emit_fill_buffer = sdma_v4_0_emit_fill_buffer,
2076 static void sdma_v4_0_set_buffer_funcs(struct amdgpu_device *adev)
2078 adev->mman.buffer_funcs = &sdma_v4_0_buffer_funcs;
2079 adev->mman.buffer_funcs_ring = &adev->sdma.instance[0].ring;
2082 static const struct amdgpu_vm_pte_funcs sdma_v4_0_vm_pte_funcs = {
2083 .copy_pte_num_dw = 7,
2084 .copy_pte = sdma_v4_0_vm_copy_pte,
2086 .write_pte = sdma_v4_0_vm_write_pte,
2087 .set_pte_pde = sdma_v4_0_vm_set_pte_pde,
2090 static void sdma_v4_0_set_vm_pte_funcs(struct amdgpu_device *adev)
2092 struct drm_gpu_scheduler *sched;
2095 adev->vm_manager.vm_pte_funcs = &sdma_v4_0_vm_pte_funcs;
2096 for (i = 0; i < adev->sdma.num_instances; i++) {
2097 if (adev->sdma.has_page_queue)
2098 sched = &adev->sdma.instance[i].page.sched;
2100 sched = &adev->sdma.instance[i].ring.sched;
2101 adev->vm_manager.vm_pte_rqs[i] =
2102 &sched->sched_rq[DRM_SCHED_PRIORITY_KERNEL];
2104 adev->vm_manager.vm_pte_num_rqs = adev->sdma.num_instances;
2107 const struct amdgpu_ip_block_version sdma_v4_0_ip_block = {
2108 .type = AMD_IP_BLOCK_TYPE_SDMA,
2112 .funcs = &sdma_v4_0_ip_funcs,