aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd
diff options
context:
space:
mode:
authorAlex Deucher <alexander.deucher@amd.com>2017-12-14 15:23:14 -0500
committerAlex Deucher <alexander.deucher@amd.com>2017-12-18 10:59:01 -0500
commit75758255dc0fae76a845fd5185cfcdf60990cc99 (patch)
treef1dedc5ebce0d3043666a0f70bb08b90c35f5052 /drivers/gpu/drm/amd
parentcdd61df614851d18b8ee72f0615202bef67f5b91 (diff)
drm/amdgpu: move debugfs functions to their own file
amdgpu_device.c was getting pretty cluttered. Acked-by: Christian König <christian.koenig@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/Makefile2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu.h16
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c792
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h42
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_device.c769
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c2
6 files changed, 838 insertions, 785 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile b/drivers/gpu/drm/amd/amdgpu/Makefile
index f778a3b4abe6..d8da12c114b1 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -52,7 +52,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \
52 amdgpu_prime.o amdgpu_vm.o amdgpu_ib.o amdgpu_pll.o \ 52 amdgpu_prime.o amdgpu_vm.o amdgpu_ib.o amdgpu_pll.o \
53 amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_sync.o \ 53 amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_sync.o \
54 amdgpu_gtt_mgr.o amdgpu_vram_mgr.o amdgpu_virt.o amdgpu_atomfirmware.o \ 54 amdgpu_gtt_mgr.o amdgpu_vram_mgr.o amdgpu_virt.o amdgpu_atomfirmware.o \
55 amdgpu_queue_mgr.o amdgpu_vf_error.o amdgpu_sched.o 55 amdgpu_queue_mgr.o amdgpu_vf_error.o amdgpu_sched.o amdgpu_debugfs.o
56 56
57# add asic specific block 57# add asic specific block
58amdgpu-$(CONFIG_DRM_AMDGPU_CIK)+= cik.o cik_ih.o kv_smc.o kv_dpm.o \ 58amdgpu-$(CONFIG_DRM_AMDGPU_CIK)+= cik.o cik_ih.o kv_smc.o kv_dpm.o \
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 169c71d48d49..c15b9441190f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -71,7 +71,7 @@
71#include "amdgpu_dm.h" 71#include "amdgpu_dm.h"
72#include "amdgpu_virt.h" 72#include "amdgpu_virt.h"
73#include "amdgpu_gart.h" 73#include "amdgpu_gart.h"
74 74#include "amdgpu_debugfs.h"
75 75
76/* 76/*
77 * Modules parameters. 77 * Modules parameters.
@@ -425,7 +425,6 @@ struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
425void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj); 425void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
426void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr); 426void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
427int amdgpu_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma); 427int amdgpu_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
428int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
429 428
430/* sub-allocation manager, it has to be protected by another lock. 429/* sub-allocation manager, it has to be protected by another lock.
431 * By conception this is an helper for other part of the driver 430 * By conception this is an helper for other part of the driver
@@ -1240,19 +1239,6 @@ void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
1240 */ 1239 */
1241void amdgpu_test_moves(struct amdgpu_device *adev); 1240void amdgpu_test_moves(struct amdgpu_device *adev);
1242 1241
1243/*
1244 * Debugfs
1245 */
1246struct amdgpu_debugfs {
1247 const struct drm_info_list *files;
1248 unsigned num_files;
1249};
1250
1251int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
1252 const struct drm_info_list *files,
1253 unsigned nfiles);
1254int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
1255int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
1256 1242
1257/* 1243/*
1258 * amdgpu smumgr functions 1244 * amdgpu smumgr functions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
new file mode 100644
index 000000000000..ee76b468774a
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
@@ -0,0 +1,792 @@
1/*
2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 */
25
26#include <linux/kthread.h>
27#include <drm/drmP.h>
28#include <linux/debugfs.h>
29#include "amdgpu.h"
30
31/*
32 * Debugfs
33 */
34int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
35 const struct drm_info_list *files,
36 unsigned nfiles)
37{
38 unsigned i;
39
40 for (i = 0; i < adev->debugfs_count; i++) {
41 if (adev->debugfs[i].files == files) {
42 /* Already registered */
43 return 0;
44 }
45 }
46
47 i = adev->debugfs_count + 1;
48 if (i > AMDGPU_DEBUGFS_MAX_COMPONENTS) {
49 DRM_ERROR("Reached maximum number of debugfs components.\n");
50 DRM_ERROR("Report so we increase "
51 "AMDGPU_DEBUGFS_MAX_COMPONENTS.\n");
52 return -EINVAL;
53 }
54 adev->debugfs[adev->debugfs_count].files = files;
55 adev->debugfs[adev->debugfs_count].num_files = nfiles;
56 adev->debugfs_count = i;
57#if defined(CONFIG_DEBUG_FS)
58 drm_debugfs_create_files(files, nfiles,
59 adev->ddev->primary->debugfs_root,
60 adev->ddev->primary);
61#endif
62 return 0;
63}
64
65#if defined(CONFIG_DEBUG_FS)
66
67static ssize_t amdgpu_debugfs_regs_read(struct file *f, char __user *buf,
68 size_t size, loff_t *pos)
69{
70 struct amdgpu_device *adev = file_inode(f)->i_private;
71 ssize_t result = 0;
72 int r;
73 bool pm_pg_lock, use_bank;
74 unsigned instance_bank, sh_bank, se_bank;
75
76 if (size & 0x3 || *pos & 0x3)
77 return -EINVAL;
78
79 /* are we reading registers for which a PG lock is necessary? */
80 pm_pg_lock = (*pos >> 23) & 1;
81
82 if (*pos & (1ULL << 62)) {
83 se_bank = (*pos & GENMASK_ULL(33, 24)) >> 24;
84 sh_bank = (*pos & GENMASK_ULL(43, 34)) >> 34;
85 instance_bank = (*pos & GENMASK_ULL(53, 44)) >> 44;
86
87 if (se_bank == 0x3FF)
88 se_bank = 0xFFFFFFFF;
89 if (sh_bank == 0x3FF)
90 sh_bank = 0xFFFFFFFF;
91 if (instance_bank == 0x3FF)
92 instance_bank = 0xFFFFFFFF;
93 use_bank = 1;
94 } else {
95 use_bank = 0;
96 }
97
98 *pos &= (1UL << 22) - 1;
99
100 if (use_bank) {
101 if ((sh_bank != 0xFFFFFFFF && sh_bank >= adev->gfx.config.max_sh_per_se) ||
102 (se_bank != 0xFFFFFFFF && se_bank >= adev->gfx.config.max_shader_engines))
103 return -EINVAL;
104 mutex_lock(&adev->grbm_idx_mutex);
105 amdgpu_gfx_select_se_sh(adev, se_bank,
106 sh_bank, instance_bank);
107 }
108
109 if (pm_pg_lock)
110 mutex_lock(&adev->pm.mutex);
111
112 while (size) {
113 uint32_t value;
114
115 if (*pos > adev->rmmio_size)
116 goto end;
117
118 value = RREG32(*pos >> 2);
119 r = put_user(value, (uint32_t *)buf);
120 if (r) {
121 result = r;
122 goto end;
123 }
124
125 result += 4;
126 buf += 4;
127 *pos += 4;
128 size -= 4;
129 }
130
131end:
132 if (use_bank) {
133 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
134 mutex_unlock(&adev->grbm_idx_mutex);
135 }
136
137 if (pm_pg_lock)
138 mutex_unlock(&adev->pm.mutex);
139
140 return result;
141}
142
143static ssize_t amdgpu_debugfs_regs_write(struct file *f, const char __user *buf,
144 size_t size, loff_t *pos)
145{
146 struct amdgpu_device *adev = file_inode(f)->i_private;
147 ssize_t result = 0;
148 int r;
149 bool pm_pg_lock, use_bank;
150 unsigned instance_bank, sh_bank, se_bank;
151
152 if (size & 0x3 || *pos & 0x3)
153 return -EINVAL;
154
155 /* are we reading registers for which a PG lock is necessary? */
156 pm_pg_lock = (*pos >> 23) & 1;
157
158 if (*pos & (1ULL << 62)) {
159 se_bank = (*pos & GENMASK_ULL(33, 24)) >> 24;
160 sh_bank = (*pos & GENMASK_ULL(43, 34)) >> 34;
161 instance_bank = (*pos & GENMASK_ULL(53, 44)) >> 44;
162
163 if (se_bank == 0x3FF)
164 se_bank = 0xFFFFFFFF;
165 if (sh_bank == 0x3FF)
166 sh_bank = 0xFFFFFFFF;
167 if (instance_bank == 0x3FF)
168 instance_bank = 0xFFFFFFFF;
169 use_bank = 1;
170 } else {
171 use_bank = 0;
172 }
173
174 *pos &= (1UL << 22) - 1;
175
176 if (use_bank) {
177 if ((sh_bank != 0xFFFFFFFF && sh_bank >= adev->gfx.config.max_sh_per_se) ||
178 (se_bank != 0xFFFFFFFF && se_bank >= adev->gfx.config.max_shader_engines))
179 return -EINVAL;
180 mutex_lock(&adev->grbm_idx_mutex);
181 amdgpu_gfx_select_se_sh(adev, se_bank,
182 sh_bank, instance_bank);
183 }
184
185 if (pm_pg_lock)
186 mutex_lock(&adev->pm.mutex);
187
188 while (size) {
189 uint32_t value;
190
191 if (*pos > adev->rmmio_size)
192 return result;
193
194 r = get_user(value, (uint32_t *)buf);
195 if (r)
196 return r;
197
198 WREG32(*pos >> 2, value);
199
200 result += 4;
201 buf += 4;
202 *pos += 4;
203 size -= 4;
204 }
205
206 if (use_bank) {
207 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
208 mutex_unlock(&adev->grbm_idx_mutex);
209 }
210
211 if (pm_pg_lock)
212 mutex_unlock(&adev->pm.mutex);
213
214 return result;
215}
216
217static ssize_t amdgpu_debugfs_regs_pcie_read(struct file *f, char __user *buf,
218 size_t size, loff_t *pos)
219{
220 struct amdgpu_device *adev = file_inode(f)->i_private;
221 ssize_t result = 0;
222 int r;
223
224 if (size & 0x3 || *pos & 0x3)
225 return -EINVAL;
226
227 while (size) {
228 uint32_t value;
229
230 value = RREG32_PCIE(*pos >> 2);
231 r = put_user(value, (uint32_t *)buf);
232 if (r)
233 return r;
234
235 result += 4;
236 buf += 4;
237 *pos += 4;
238 size -= 4;
239 }
240
241 return result;
242}
243
244static ssize_t amdgpu_debugfs_regs_pcie_write(struct file *f, const char __user *buf,
245 size_t size, loff_t *pos)
246{
247 struct amdgpu_device *adev = file_inode(f)->i_private;
248 ssize_t result = 0;
249 int r;
250
251 if (size & 0x3 || *pos & 0x3)
252 return -EINVAL;
253
254 while (size) {
255 uint32_t value;
256
257 r = get_user(value, (uint32_t *)buf);
258 if (r)
259 return r;
260
261 WREG32_PCIE(*pos >> 2, value);
262
263 result += 4;
264 buf += 4;
265 *pos += 4;
266 size -= 4;
267 }
268
269 return result;
270}
271
272static ssize_t amdgpu_debugfs_regs_didt_read(struct file *f, char __user *buf,
273 size_t size, loff_t *pos)
274{
275 struct amdgpu_device *adev = file_inode(f)->i_private;
276 ssize_t result = 0;
277 int r;
278
279 if (size & 0x3 || *pos & 0x3)
280 return -EINVAL;
281
282 while (size) {
283 uint32_t value;
284
285 value = RREG32_DIDT(*pos >> 2);
286 r = put_user(value, (uint32_t *)buf);
287 if (r)
288 return r;
289
290 result += 4;
291 buf += 4;
292 *pos += 4;
293 size -= 4;
294 }
295
296 return result;
297}
298
299static ssize_t amdgpu_debugfs_regs_didt_write(struct file *f, const char __user *buf,
300 size_t size, loff_t *pos)
301{
302 struct amdgpu_device *adev = file_inode(f)->i_private;
303 ssize_t result = 0;
304 int r;
305
306 if (size & 0x3 || *pos & 0x3)
307 return -EINVAL;
308
309 while (size) {
310 uint32_t value;
311
312 r = get_user(value, (uint32_t *)buf);
313 if (r)
314 return r;
315
316 WREG32_DIDT(*pos >> 2, value);
317
318 result += 4;
319 buf += 4;
320 *pos += 4;
321 size -= 4;
322 }
323
324 return result;
325}
326
327static ssize_t amdgpu_debugfs_regs_smc_read(struct file *f, char __user *buf,
328 size_t size, loff_t *pos)
329{
330 struct amdgpu_device *adev = file_inode(f)->i_private;
331 ssize_t result = 0;
332 int r;
333
334 if (size & 0x3 || *pos & 0x3)
335 return -EINVAL;
336
337 while (size) {
338 uint32_t value;
339
340 value = RREG32_SMC(*pos);
341 r = put_user(value, (uint32_t *)buf);
342 if (r)
343 return r;
344
345 result += 4;
346 buf += 4;
347 *pos += 4;
348 size -= 4;
349 }
350
351 return result;
352}
353
354static ssize_t amdgpu_debugfs_regs_smc_write(struct file *f, const char __user *buf,
355 size_t size, loff_t *pos)
356{
357 struct amdgpu_device *adev = file_inode(f)->i_private;
358 ssize_t result = 0;
359 int r;
360
361 if (size & 0x3 || *pos & 0x3)
362 return -EINVAL;
363
364 while (size) {
365 uint32_t value;
366
367 r = get_user(value, (uint32_t *)buf);
368 if (r)
369 return r;
370
371 WREG32_SMC(*pos, value);
372
373 result += 4;
374 buf += 4;
375 *pos += 4;
376 size -= 4;
377 }
378
379 return result;
380}
381
382static ssize_t amdgpu_debugfs_gca_config_read(struct file *f, char __user *buf,
383 size_t size, loff_t *pos)
384{
385 struct amdgpu_device *adev = file_inode(f)->i_private;
386 ssize_t result = 0;
387 int r;
388 uint32_t *config, no_regs = 0;
389
390 if (size & 0x3 || *pos & 0x3)
391 return -EINVAL;
392
393 config = kmalloc_array(256, sizeof(*config), GFP_KERNEL);
394 if (!config)
395 return -ENOMEM;
396
397 /* version, increment each time something is added */
398 config[no_regs++] = 3;
399 config[no_regs++] = adev->gfx.config.max_shader_engines;
400 config[no_regs++] = adev->gfx.config.max_tile_pipes;
401 config[no_regs++] = adev->gfx.config.max_cu_per_sh;
402 config[no_regs++] = adev->gfx.config.max_sh_per_se;
403 config[no_regs++] = adev->gfx.config.max_backends_per_se;
404 config[no_regs++] = adev->gfx.config.max_texture_channel_caches;
405 config[no_regs++] = adev->gfx.config.max_gprs;
406 config[no_regs++] = adev->gfx.config.max_gs_threads;
407 config[no_regs++] = adev->gfx.config.max_hw_contexts;
408 config[no_regs++] = adev->gfx.config.sc_prim_fifo_size_frontend;
409 config[no_regs++] = adev->gfx.config.sc_prim_fifo_size_backend;
410 config[no_regs++] = adev->gfx.config.sc_hiz_tile_fifo_size;
411 config[no_regs++] = adev->gfx.config.sc_earlyz_tile_fifo_size;
412 config[no_regs++] = adev->gfx.config.num_tile_pipes;
413 config[no_regs++] = adev->gfx.config.backend_enable_mask;
414 config[no_regs++] = adev->gfx.config.mem_max_burst_length_bytes;
415 config[no_regs++] = adev->gfx.config.mem_row_size_in_kb;
416 config[no_regs++] = adev->gfx.config.shader_engine_tile_size;
417 config[no_regs++] = adev->gfx.config.num_gpus;
418 config[no_regs++] = adev->gfx.config.multi_gpu_tile_size;
419 config[no_regs++] = adev->gfx.config.mc_arb_ramcfg;
420 config[no_regs++] = adev->gfx.config.gb_addr_config;
421 config[no_regs++] = adev->gfx.config.num_rbs;
422
423 /* rev==1 */
424 config[no_regs++] = adev->rev_id;
425 config[no_regs++] = adev->pg_flags;
426 config[no_regs++] = adev->cg_flags;
427
428 /* rev==2 */
429 config[no_regs++] = adev->family;
430 config[no_regs++] = adev->external_rev_id;
431
432 /* rev==3 */
433 config[no_regs++] = adev->pdev->device;
434 config[no_regs++] = adev->pdev->revision;
435 config[no_regs++] = adev->pdev->subsystem_device;
436 config[no_regs++] = adev->pdev->subsystem_vendor;
437
438 while (size && (*pos < no_regs * 4)) {
439 uint32_t value;
440
441 value = config[*pos >> 2];
442 r = put_user(value, (uint32_t *)buf);
443 if (r) {
444 kfree(config);
445 return r;
446 }
447
448 result += 4;
449 buf += 4;
450 *pos += 4;
451 size -= 4;
452 }
453
454 kfree(config);
455 return result;
456}
457
458static ssize_t amdgpu_debugfs_sensor_read(struct file *f, char __user *buf,
459 size_t size, loff_t *pos)
460{
461 struct amdgpu_device *adev = file_inode(f)->i_private;
462 int idx, x, outsize, r, valuesize;
463 uint32_t values[16];
464
465 if (size & 3 || *pos & 0x3)
466 return -EINVAL;
467
468 if (amdgpu_dpm == 0)
469 return -EINVAL;
470
471 /* convert offset to sensor number */
472 idx = *pos >> 2;
473
474 valuesize = sizeof(values);
475 if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->read_sensor)
476 r = amdgpu_dpm_read_sensor(adev, idx, &values[0], &valuesize);
477 else
478 return -EINVAL;
479
480 if (size > valuesize)
481 return -EINVAL;
482
483 outsize = 0;
484 x = 0;
485 if (!r) {
486 while (size) {
487 r = put_user(values[x++], (int32_t *)buf);
488 buf += 4;
489 size -= 4;
490 outsize += 4;
491 }
492 }
493
494 return !r ? outsize : r;
495}
496
497static ssize_t amdgpu_debugfs_wave_read(struct file *f, char __user *buf,
498 size_t size, loff_t *pos)
499{
500 struct amdgpu_device *adev = f->f_inode->i_private;
501 int r, x;
502 ssize_t result=0;
503 uint32_t offset, se, sh, cu, wave, simd, data[32];
504
505 if (size & 3 || *pos & 3)
506 return -EINVAL;
507
508 /* decode offset */
509 offset = (*pos & GENMASK_ULL(6, 0));
510 se = (*pos & GENMASK_ULL(14, 7)) >> 7;
511 sh = (*pos & GENMASK_ULL(22, 15)) >> 15;
512 cu = (*pos & GENMASK_ULL(30, 23)) >> 23;
513 wave = (*pos & GENMASK_ULL(36, 31)) >> 31;
514 simd = (*pos & GENMASK_ULL(44, 37)) >> 37;
515
516 /* switch to the specific se/sh/cu */
517 mutex_lock(&adev->grbm_idx_mutex);
518 amdgpu_gfx_select_se_sh(adev, se, sh, cu);
519
520 x = 0;
521 if (adev->gfx.funcs->read_wave_data)
522 adev->gfx.funcs->read_wave_data(adev, simd, wave, data, &x);
523
524 amdgpu_gfx_select_se_sh(adev, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
525 mutex_unlock(&adev->grbm_idx_mutex);
526
527 if (!x)
528 return -EINVAL;
529
530 while (size && (offset < x * 4)) {
531 uint32_t value;
532
533 value = data[offset >> 2];
534 r = put_user(value, (uint32_t *)buf);
535 if (r)
536 return r;
537
538 result += 4;
539 buf += 4;
540 offset += 4;
541 size -= 4;
542 }
543
544 return result;
545}
546
547static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf,
548 size_t size, loff_t *pos)
549{
550 struct amdgpu_device *adev = f->f_inode->i_private;
551 int r;
552 ssize_t result = 0;
553 uint32_t offset, se, sh, cu, wave, simd, thread, bank, *data;
554
555 if (size & 3 || *pos & 3)
556 return -EINVAL;
557
558 /* decode offset */
559 offset = *pos & GENMASK_ULL(11, 0);
560 se = (*pos & GENMASK_ULL(19, 12)) >> 12;
561 sh = (*pos & GENMASK_ULL(27, 20)) >> 20;
562 cu = (*pos & GENMASK_ULL(35, 28)) >> 28;
563 wave = (*pos & GENMASK_ULL(43, 36)) >> 36;
564 simd = (*pos & GENMASK_ULL(51, 44)) >> 44;
565 thread = (*pos & GENMASK_ULL(59, 52)) >> 52;
566 bank = (*pos & GENMASK_ULL(61, 60)) >> 60;
567
568 data = kmalloc_array(1024, sizeof(*data), GFP_KERNEL);
569 if (!data)
570 return -ENOMEM;
571
572 /* switch to the specific se/sh/cu */
573 mutex_lock(&adev->grbm_idx_mutex);
574 amdgpu_gfx_select_se_sh(adev, se, sh, cu);
575
576 if (bank == 0) {
577 if (adev->gfx.funcs->read_wave_vgprs)
578 adev->gfx.funcs->read_wave_vgprs(adev, simd, wave, thread, offset, size>>2, data);
579 } else {
580 if (adev->gfx.funcs->read_wave_sgprs)
581 adev->gfx.funcs->read_wave_sgprs(adev, simd, wave, offset, size>>2, data);
582 }
583
584 amdgpu_gfx_select_se_sh(adev, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
585 mutex_unlock(&adev->grbm_idx_mutex);
586
587 while (size) {
588 uint32_t value;
589
590 value = data[offset++];
591 r = put_user(value, (uint32_t *)buf);
592 if (r) {
593 result = r;
594 goto err;
595 }
596
597 result += 4;
598 buf += 4;
599 size -= 4;
600 }
601
602err:
603 kfree(data);
604 return result;
605}
606
607static const struct file_operations amdgpu_debugfs_regs_fops = {
608 .owner = THIS_MODULE,
609 .read = amdgpu_debugfs_regs_read,
610 .write = amdgpu_debugfs_regs_write,
611 .llseek = default_llseek
612};
613static const struct file_operations amdgpu_debugfs_regs_didt_fops = {
614 .owner = THIS_MODULE,
615 .read = amdgpu_debugfs_regs_didt_read,
616 .write = amdgpu_debugfs_regs_didt_write,
617 .llseek = default_llseek
618};
619static const struct file_operations amdgpu_debugfs_regs_pcie_fops = {
620 .owner = THIS_MODULE,
621 .read = amdgpu_debugfs_regs_pcie_read,
622 .write = amdgpu_debugfs_regs_pcie_write,
623 .llseek = default_llseek
624};
625static const struct file_operations amdgpu_debugfs_regs_smc_fops = {
626 .owner = THIS_MODULE,
627 .read = amdgpu_debugfs_regs_smc_read,
628 .write = amdgpu_debugfs_regs_smc_write,
629 .llseek = default_llseek
630};
631
632static const struct file_operations amdgpu_debugfs_gca_config_fops = {
633 .owner = THIS_MODULE,
634 .read = amdgpu_debugfs_gca_config_read,
635 .llseek = default_llseek
636};
637
638static const struct file_operations amdgpu_debugfs_sensors_fops = {
639 .owner = THIS_MODULE,
640 .read = amdgpu_debugfs_sensor_read,
641 .llseek = default_llseek
642};
643
644static const struct file_operations amdgpu_debugfs_wave_fops = {
645 .owner = THIS_MODULE,
646 .read = amdgpu_debugfs_wave_read,
647 .llseek = default_llseek
648};
649static const struct file_operations amdgpu_debugfs_gpr_fops = {
650 .owner = THIS_MODULE,
651 .read = amdgpu_debugfs_gpr_read,
652 .llseek = default_llseek
653};
654
655static const struct file_operations *debugfs_regs[] = {
656 &amdgpu_debugfs_regs_fops,
657 &amdgpu_debugfs_regs_didt_fops,
658 &amdgpu_debugfs_regs_pcie_fops,
659 &amdgpu_debugfs_regs_smc_fops,
660 &amdgpu_debugfs_gca_config_fops,
661 &amdgpu_debugfs_sensors_fops,
662 &amdgpu_debugfs_wave_fops,
663 &amdgpu_debugfs_gpr_fops,
664};
665
666static const char *debugfs_regs_names[] = {
667 "amdgpu_regs",
668 "amdgpu_regs_didt",
669 "amdgpu_regs_pcie",
670 "amdgpu_regs_smc",
671 "amdgpu_gca_config",
672 "amdgpu_sensors",
673 "amdgpu_wave",
674 "amdgpu_gpr",
675};
676
677int amdgpu_debugfs_regs_init(struct amdgpu_device *adev)
678{
679 struct drm_minor *minor = adev->ddev->primary;
680 struct dentry *ent, *root = minor->debugfs_root;
681 unsigned i, j;
682
683 for (i = 0; i < ARRAY_SIZE(debugfs_regs); i++) {
684 ent = debugfs_create_file(debugfs_regs_names[i],
685 S_IFREG | S_IRUGO, root,
686 adev, debugfs_regs[i]);
687 if (IS_ERR(ent)) {
688 for (j = 0; j < i; j++) {
689 debugfs_remove(adev->debugfs_regs[i]);
690 adev->debugfs_regs[i] = NULL;
691 }
692 return PTR_ERR(ent);
693 }
694
695 if (!i)
696 i_size_write(ent->d_inode, adev->rmmio_size);
697 adev->debugfs_regs[i] = ent;
698 }
699
700 return 0;
701}
702
703void amdgpu_debugfs_regs_cleanup(struct amdgpu_device *adev)
704{
705 unsigned i;
706
707 for (i = 0; i < ARRAY_SIZE(debugfs_regs); i++) {
708 if (adev->debugfs_regs[i]) {
709 debugfs_remove(adev->debugfs_regs[i]);
710 adev->debugfs_regs[i] = NULL;
711 }
712 }
713}
714
715static int amdgpu_debugfs_test_ib(struct seq_file *m, void *data)
716{
717 struct drm_info_node *node = (struct drm_info_node *) m->private;
718 struct drm_device *dev = node->minor->dev;
719 struct amdgpu_device *adev = dev->dev_private;
720 int r = 0, i;
721
722 /* hold on the scheduler */
723 for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
724 struct amdgpu_ring *ring = adev->rings[i];
725
726 if (!ring || !ring->sched.thread)
727 continue;
728 kthread_park(ring->sched.thread);
729 }
730
731 seq_printf(m, "run ib test:\n");
732 r = amdgpu_ib_ring_tests(adev);
733 if (r)
734 seq_printf(m, "ib ring tests failed (%d).\n", r);
735 else
736 seq_printf(m, "ib ring tests passed.\n");
737
738 /* go on the scheduler */
739 for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
740 struct amdgpu_ring *ring = adev->rings[i];
741
742 if (!ring || !ring->sched.thread)
743 continue;
744 kthread_unpark(ring->sched.thread);
745 }
746
747 return 0;
748}
749
750static int amdgpu_debugfs_get_vbios_dump(struct seq_file *m, void *data)
751{
752 struct drm_info_node *node = (struct drm_info_node *) m->private;
753 struct drm_device *dev = node->minor->dev;
754 struct amdgpu_device *adev = dev->dev_private;
755
756 seq_write(m, adev->bios, adev->bios_size);
757 return 0;
758}
759
760static int amdgpu_debugfs_evict_vram(struct seq_file *m, void *data)
761{
762 struct drm_info_node *node = (struct drm_info_node *)m->private;
763 struct drm_device *dev = node->minor->dev;
764 struct amdgpu_device *adev = dev->dev_private;
765
766 seq_printf(m, "(%d)\n", amdgpu_bo_evict_vram(adev));
767 return 0;
768}
769
770static const struct drm_info_list amdgpu_debugfs_list[] = {
771 {"amdgpu_vbios", amdgpu_debugfs_get_vbios_dump},
772 {"amdgpu_test_ib", &amdgpu_debugfs_test_ib},
773 {"amdgpu_evict_vram", &amdgpu_debugfs_evict_vram}
774};
775
776int amdgpu_debugfs_init(struct amdgpu_device *adev)
777{
778 return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_list,
779 ARRAY_SIZE(amdgpu_debugfs_list));
780}
781
782#else
783int amdgpu_debugfs_init(struct amdgpu_device *adev)
784{
785 return 0;
786}
787int amdgpu_debugfs_regs_init(struct amdgpu_device *adev)
788{
789 return 0;
790}
791void amdgpu_debugfs_regs_cleanup(struct amdgpu_device *adev) { }
792#endif
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h
new file mode 100644
index 000000000000..8260d8073c26
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.h
@@ -0,0 +1,42 @@
1/*
2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 */
25
26/*
27 * Debugfs
28 */
29struct amdgpu_debugfs {
30 const struct drm_info_list *files;
31 unsigned num_files;
32};
33
34int amdgpu_debugfs_regs_init(struct amdgpu_device *adev);
35void amdgpu_debugfs_regs_cleanup(struct amdgpu_device *adev);
36int amdgpu_debugfs_init(struct amdgpu_device *adev);
37int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
38 const struct drm_info_list *files,
39 unsigned nfiles);
40int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
41int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
42int amdgpu_debugfs_gem_init(struct amdgpu_device *adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 3beea322bc12..ec078a9a5de8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -28,7 +28,6 @@
28#include <linux/kthread.h> 28#include <linux/kthread.h>
29#include <linux/console.h> 29#include <linux/console.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/debugfs.h>
32#include <drm/drmP.h> 31#include <drm/drmP.h>
33#include <drm/drm_crtc_helper.h> 32#include <drm/drm_crtc_helper.h>
34#include <drm/drm_atomic_helper.h> 33#include <drm/drm_atomic_helper.h>
@@ -64,10 +63,6 @@ MODULE_FIRMWARE("amdgpu/raven_gpu_info.bin");
64 63
65#define AMDGPU_RESUME_MS 2000 64#define AMDGPU_RESUME_MS 2000
66 65
67static int amdgpu_debugfs_regs_init(struct amdgpu_device *adev);
68static void amdgpu_debugfs_regs_cleanup(struct amdgpu_device *adev);
69static int amdgpu_debugfs_init(struct amdgpu_device *adev);
70
71static const char *amdgpu_asic_name[] = { 66static const char *amdgpu_asic_name[] = {
72 "TAHITI", 67 "TAHITI",
73 "PITCAIRN", 68 "PITCAIRN",
@@ -2171,7 +2166,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
2171 if (r) 2166 if (r)
2172 DRM_ERROR("registering pm debugfs failed (%d).\n", r); 2167 DRM_ERROR("registering pm debugfs failed (%d).\n", r);
2173 2168
2174 r = amdgpu_gem_debugfs_init(adev); 2169 r = amdgpu_debugfs_gem_init(adev);
2175 if (r) 2170 if (r)
2176 DRM_ERROR("registering gem debugfs failed (%d).\n", r); 2171 DRM_ERROR("registering gem debugfs failed (%d).\n", r);
2177 2172
@@ -3020,765 +3015,3 @@ void amdgpu_get_pcie_info(struct amdgpu_device *adev)
3020 } 3015 }
3021} 3016}
3022 3017
3023/*
3024 * Debugfs
3025 */
3026int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
3027 const struct drm_info_list *files,
3028 unsigned nfiles)
3029{
3030 unsigned i;
3031
3032 for (i = 0; i < adev->debugfs_count; i++) {
3033 if (adev->debugfs[i].files == files) {
3034 /* Already registered */
3035 return 0;
3036 }
3037 }
3038
3039 i = adev->debugfs_count + 1;
3040 if (i > AMDGPU_DEBUGFS_MAX_COMPONENTS) {
3041 DRM_ERROR("Reached maximum number of debugfs components.\n");
3042 DRM_ERROR("Report so we increase "
3043 "AMDGPU_DEBUGFS_MAX_COMPONENTS.\n");
3044 return -EINVAL;
3045 }
3046 adev->debugfs[adev->debugfs_count].files = files;
3047 adev->debugfs[adev->debugfs_count].num_files = nfiles;
3048 adev->debugfs_count = i;
3049#if defined(CONFIG_DEBUG_FS)
3050 drm_debugfs_create_files(files, nfiles,
3051 adev->ddev->primary->debugfs_root,
3052 adev->ddev->primary);
3053#endif
3054 return 0;
3055}
3056
3057#if defined(CONFIG_DEBUG_FS)
3058
3059static ssize_t amdgpu_debugfs_regs_read(struct file *f, char __user *buf,
3060 size_t size, loff_t *pos)
3061{
3062 struct amdgpu_device *adev = file_inode(f)->i_private;
3063 ssize_t result = 0;
3064 int r;
3065 bool pm_pg_lock, use_bank;
3066 unsigned instance_bank, sh_bank, se_bank;
3067
3068 if (size & 0x3 || *pos & 0x3)
3069 return -EINVAL;
3070
3071 /* are we reading registers for which a PG lock is necessary? */
3072 pm_pg_lock = (*pos >> 23) & 1;
3073
3074 if (*pos & (1ULL << 62)) {
3075 se_bank = (*pos & GENMASK_ULL(33, 24)) >> 24;
3076 sh_bank = (*pos & GENMASK_ULL(43, 34)) >> 34;
3077 instance_bank = (*pos & GENMASK_ULL(53, 44)) >> 44;
3078
3079 if (se_bank == 0x3FF)
3080 se_bank = 0xFFFFFFFF;
3081 if (sh_bank == 0x3FF)
3082 sh_bank = 0xFFFFFFFF;
3083 if (instance_bank == 0x3FF)
3084 instance_bank = 0xFFFFFFFF;
3085 use_bank = 1;
3086 } else {
3087 use_bank = 0;
3088 }
3089
3090 *pos &= (1UL << 22) - 1;
3091
3092 if (use_bank) {
3093 if ((sh_bank != 0xFFFFFFFF && sh_bank >= adev->gfx.config.max_sh_per_se) ||
3094 (se_bank != 0xFFFFFFFF && se_bank >= adev->gfx.config.max_shader_engines))
3095 return -EINVAL;
3096 mutex_lock(&adev->grbm_idx_mutex);
3097 amdgpu_gfx_select_se_sh(adev, se_bank,
3098 sh_bank, instance_bank);
3099 }
3100
3101 if (pm_pg_lock)
3102 mutex_lock(&adev->pm.mutex);
3103
3104 while (size) {
3105 uint32_t value;
3106
3107 if (*pos > adev->rmmio_size)
3108 goto end;
3109
3110 value = RREG32(*pos >> 2);
3111 r = put_user(value, (uint32_t *)buf);
3112 if (r) {
3113 result = r;
3114 goto end;
3115 }
3116
3117 result += 4;
3118 buf += 4;
3119 *pos += 4;
3120 size -= 4;
3121 }
3122
3123end:
3124 if (use_bank) {
3125 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
3126 mutex_unlock(&adev->grbm_idx_mutex);
3127 }
3128
3129 if (pm_pg_lock)
3130 mutex_unlock(&adev->pm.mutex);
3131
3132 return result;
3133}
3134
3135static ssize_t amdgpu_debugfs_regs_write(struct file *f, const char __user *buf,
3136 size_t size, loff_t *pos)
3137{
3138 struct amdgpu_device *adev = file_inode(f)->i_private;
3139 ssize_t result = 0;
3140 int r;
3141 bool pm_pg_lock, use_bank;
3142 unsigned instance_bank, sh_bank, se_bank;
3143
3144 if (size & 0x3 || *pos & 0x3)
3145 return -EINVAL;
3146
3147 /* are we reading registers for which a PG lock is necessary? */
3148 pm_pg_lock = (*pos >> 23) & 1;
3149
3150 if (*pos & (1ULL << 62)) {
3151 se_bank = (*pos & GENMASK_ULL(33, 24)) >> 24;
3152 sh_bank = (*pos & GENMASK_ULL(43, 34)) >> 34;
3153 instance_bank = (*pos & GENMASK_ULL(53, 44)) >> 44;
3154
3155 if (se_bank == 0x3FF)
3156 se_bank = 0xFFFFFFFF;
3157 if (sh_bank == 0x3FF)
3158 sh_bank = 0xFFFFFFFF;
3159 if (instance_bank == 0x3FF)
3160 instance_bank = 0xFFFFFFFF;
3161 use_bank = 1;
3162 } else {
3163 use_bank = 0;
3164 }
3165
3166 *pos &= (1UL << 22) - 1;
3167
3168 if (use_bank) {
3169 if ((sh_bank != 0xFFFFFFFF && sh_bank >= adev->gfx.config.max_sh_per_se) ||
3170 (se_bank != 0xFFFFFFFF && se_bank >= adev->gfx.config.max_shader_engines))
3171 return -EINVAL;
3172 mutex_lock(&adev->grbm_idx_mutex);
3173 amdgpu_gfx_select_se_sh(adev, se_bank,
3174 sh_bank, instance_bank);
3175 }
3176
3177 if (pm_pg_lock)
3178 mutex_lock(&adev->pm.mutex);
3179
3180 while (size) {
3181 uint32_t value;
3182
3183 if (*pos > adev->rmmio_size)
3184 return result;
3185
3186 r = get_user(value, (uint32_t *)buf);
3187 if (r)
3188 return r;
3189
3190 WREG32(*pos >> 2, value);
3191
3192 result += 4;
3193 buf += 4;
3194 *pos += 4;
3195 size -= 4;
3196 }
3197
3198 if (use_bank) {
3199 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
3200 mutex_unlock(&adev->grbm_idx_mutex);
3201 }
3202
3203 if (pm_pg_lock)
3204 mutex_unlock(&adev->pm.mutex);
3205
3206 return result;
3207}
3208
3209static ssize_t amdgpu_debugfs_regs_pcie_read(struct file *f, char __user *buf,
3210 size_t size, loff_t *pos)
3211{
3212 struct amdgpu_device *adev = file_inode(f)->i_private;
3213 ssize_t result = 0;
3214 int r;
3215
3216 if (size & 0x3 || *pos & 0x3)
3217 return -EINVAL;
3218
3219 while (size) {
3220 uint32_t value;
3221
3222 value = RREG32_PCIE(*pos >> 2);
3223 r = put_user(value, (uint32_t *)buf);
3224 if (r)
3225 return r;
3226
3227 result += 4;
3228 buf += 4;
3229 *pos += 4;
3230 size -= 4;
3231 }
3232
3233 return result;
3234}
3235
3236static ssize_t amdgpu_debugfs_regs_pcie_write(struct file *f, const char __user *buf,
3237 size_t size, loff_t *pos)
3238{
3239 struct amdgpu_device *adev = file_inode(f)->i_private;
3240 ssize_t result = 0;
3241 int r;
3242
3243 if (size & 0x3 || *pos & 0x3)
3244 return -EINVAL;
3245
3246 while (size) {
3247 uint32_t value;
3248
3249 r = get_user(value, (uint32_t *)buf);
3250 if (r)
3251 return r;
3252
3253 WREG32_PCIE(*pos >> 2, value);
3254
3255 result += 4;
3256 buf += 4;
3257 *pos += 4;
3258 size -= 4;
3259 }
3260
3261 return result;
3262}
3263
3264static ssize_t amdgpu_debugfs_regs_didt_read(struct file *f, char __user *buf,
3265 size_t size, loff_t *pos)
3266{
3267 struct amdgpu_device *adev = file_inode(f)->i_private;
3268 ssize_t result = 0;
3269 int r;
3270
3271 if (size & 0x3 || *pos & 0x3)
3272 return -EINVAL;
3273
3274 while (size) {
3275 uint32_t value;
3276
3277 value = RREG32_DIDT(*pos >> 2);
3278 r = put_user(value, (uint32_t *)buf);
3279 if (r)
3280 return r;
3281
3282 result += 4;
3283 buf += 4;
3284 *pos += 4;
3285 size -= 4;
3286 }
3287
3288 return result;
3289}
3290
3291static ssize_t amdgpu_debugfs_regs_didt_write(struct file *f, const char __user *buf,
3292 size_t size, loff_t *pos)
3293{
3294 struct amdgpu_device *adev = file_inode(f)->i_private;
3295 ssize_t result = 0;
3296 int r;
3297
3298 if (size & 0x3 || *pos & 0x3)
3299 return -EINVAL;
3300
3301 while (size) {
3302 uint32_t value;
3303
3304 r = get_user(value, (uint32_t *)buf);
3305 if (r)
3306 return r;
3307
3308 WREG32_DIDT(*pos >> 2, value);
3309
3310 result += 4;
3311 buf += 4;
3312 *pos += 4;
3313 size -= 4;
3314 }
3315
3316 return result;
3317}
3318
3319static ssize_t amdgpu_debugfs_regs_smc_read(struct file *f, char __user *buf,
3320 size_t size, loff_t *pos)
3321{
3322 struct amdgpu_device *adev = file_inode(f)->i_private;
3323 ssize_t result = 0;
3324 int r;
3325
3326 if (size & 0x3 || *pos & 0x3)
3327 return -EINVAL;
3328
3329 while (size) {
3330 uint32_t value;
3331
3332 value = RREG32_SMC(*pos);
3333 r = put_user(value, (uint32_t *)buf);
3334 if (r)
3335 return r;
3336
3337 result += 4;
3338 buf += 4;
3339 *pos += 4;
3340 size -= 4;
3341 }
3342
3343 return result;
3344}
3345
3346static ssize_t amdgpu_debugfs_regs_smc_write(struct file *f, const char __user *buf,
3347 size_t size, loff_t *pos)
3348{
3349 struct amdgpu_device *adev = file_inode(f)->i_private;
3350 ssize_t result = 0;
3351 int r;
3352
3353 if (size & 0x3 || *pos & 0x3)
3354 return -EINVAL;
3355
3356 while (size) {
3357 uint32_t value;
3358
3359 r = get_user(value, (uint32_t *)buf);
3360 if (r)
3361 return r;
3362
3363 WREG32_SMC(*pos, value);
3364
3365 result += 4;
3366 buf += 4;
3367 *pos += 4;
3368 size -= 4;
3369 }
3370
3371 return result;
3372}
3373
3374static ssize_t amdgpu_debugfs_gca_config_read(struct file *f, char __user *buf,
3375 size_t size, loff_t *pos)
3376{
3377 struct amdgpu_device *adev = file_inode(f)->i_private;
3378 ssize_t result = 0;
3379 int r;
3380 uint32_t *config, no_regs = 0;
3381
3382 if (size & 0x3 || *pos & 0x3)
3383 return -EINVAL;
3384
3385 config = kmalloc_array(256, sizeof(*config), GFP_KERNEL);
3386 if (!config)
3387 return -ENOMEM;
3388
3389 /* version, increment each time something is added */
3390 config[no_regs++] = 3;
3391 config[no_regs++] = adev->gfx.config.max_shader_engines;
3392 config[no_regs++] = adev->gfx.config.max_tile_pipes;
3393 config[no_regs++] = adev->gfx.config.max_cu_per_sh;
3394 config[no_regs++] = adev->gfx.config.max_sh_per_se;
3395 config[no_regs++] = adev->gfx.config.max_backends_per_se;
3396 config[no_regs++] = adev->gfx.config.max_texture_channel_caches;
3397 config[no_regs++] = adev->gfx.config.max_gprs;
3398 config[no_regs++] = adev->gfx.config.max_gs_threads;
3399 config[no_regs++] = adev->gfx.config.max_hw_contexts;
3400 config[no_regs++] = adev->gfx.config.sc_prim_fifo_size_frontend;
3401 config[no_regs++] = adev->gfx.config.sc_prim_fifo_size_backend;
3402 config[no_regs++] = adev->gfx.config.sc_hiz_tile_fifo_size;
3403 config[no_regs++] = adev->gfx.config.sc_earlyz_tile_fifo_size;
3404 config[no_regs++] = adev->gfx.config.num_tile_pipes;
3405 config[no_regs++] = adev->gfx.config.backend_enable_mask;
3406 config[no_regs++] = adev->gfx.config.mem_max_burst_length_bytes;
3407 config[no_regs++] = adev->gfx.config.mem_row_size_in_kb;
3408 config[no_regs++] = adev->gfx.config.shader_engine_tile_size;
3409 config[no_regs++] = adev->gfx.config.num_gpus;
3410 config[no_regs++] = adev->gfx.config.multi_gpu_tile_size;
3411 config[no_regs++] = adev->gfx.config.mc_arb_ramcfg;
3412 config[no_regs++] = adev->gfx.config.gb_addr_config;
3413 config[no_regs++] = adev->gfx.config.num_rbs;
3414
3415 /* rev==1 */
3416 config[no_regs++] = adev->rev_id;
3417 config[no_regs++] = adev->pg_flags;
3418 config[no_regs++] = adev->cg_flags;
3419
3420 /* rev==2 */
3421 config[no_regs++] = adev->family;
3422 config[no_regs++] = adev->external_rev_id;
3423
3424 /* rev==3 */
3425 config[no_regs++] = adev->pdev->device;
3426 config[no_regs++] = adev->pdev->revision;
3427 config[no_regs++] = adev->pdev->subsystem_device;
3428 config[no_regs++] = adev->pdev->subsystem_vendor;
3429
3430 while (size && (*pos < no_regs * 4)) {
3431 uint32_t value;
3432
3433 value = config[*pos >> 2];
3434 r = put_user(value, (uint32_t *)buf);
3435 if (r) {
3436 kfree(config);
3437 return r;
3438 }
3439
3440 result += 4;
3441 buf += 4;
3442 *pos += 4;
3443 size -= 4;
3444 }
3445
3446 kfree(config);
3447 return result;
3448}
3449
3450static ssize_t amdgpu_debugfs_sensor_read(struct file *f, char __user *buf,
3451 size_t size, loff_t *pos)
3452{
3453 struct amdgpu_device *adev = file_inode(f)->i_private;
3454 int idx, x, outsize, r, valuesize;
3455 uint32_t values[16];
3456
3457 if (size & 3 || *pos & 0x3)
3458 return -EINVAL;
3459
3460 if (amdgpu_dpm == 0)
3461 return -EINVAL;
3462
3463 /* convert offset to sensor number */
3464 idx = *pos >> 2;
3465
3466 valuesize = sizeof(values);
3467 if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->read_sensor)
3468 r = amdgpu_dpm_read_sensor(adev, idx, &values[0], &valuesize);
3469 else
3470 return -EINVAL;
3471
3472 if (size > valuesize)
3473 return -EINVAL;
3474
3475 outsize = 0;
3476 x = 0;
3477 if (!r) {
3478 while (size) {
3479 r = put_user(values[x++], (int32_t *)buf);
3480 buf += 4;
3481 size -= 4;
3482 outsize += 4;
3483 }
3484 }
3485
3486 return !r ? outsize : r;
3487}
3488
3489static ssize_t amdgpu_debugfs_wave_read(struct file *f, char __user *buf,
3490 size_t size, loff_t *pos)
3491{
3492 struct amdgpu_device *adev = f->f_inode->i_private;
3493 int r, x;
3494 ssize_t result=0;
3495 uint32_t offset, se, sh, cu, wave, simd, data[32];
3496
3497 if (size & 3 || *pos & 3)
3498 return -EINVAL;
3499
3500 /* decode offset */
3501 offset = (*pos & GENMASK_ULL(6, 0));
3502 se = (*pos & GENMASK_ULL(14, 7)) >> 7;
3503 sh = (*pos & GENMASK_ULL(22, 15)) >> 15;
3504 cu = (*pos & GENMASK_ULL(30, 23)) >> 23;
3505 wave = (*pos & GENMASK_ULL(36, 31)) >> 31;
3506 simd = (*pos & GENMASK_ULL(44, 37)) >> 37;
3507
3508 /* switch to the specific se/sh/cu */
3509 mutex_lock(&adev->grbm_idx_mutex);
3510 amdgpu_gfx_select_se_sh(adev, se, sh, cu);
3511
3512 x = 0;
3513 if (adev->gfx.funcs->read_wave_data)
3514 adev->gfx.funcs->read_wave_data(adev, simd, wave, data, &x);
3515
3516 amdgpu_gfx_select_se_sh(adev, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
3517 mutex_unlock(&adev->grbm_idx_mutex);
3518
3519 if (!x)
3520 return -EINVAL;
3521
3522 while (size && (offset < x * 4)) {
3523 uint32_t value;
3524
3525 value = data[offset >> 2];
3526 r = put_user(value, (uint32_t *)buf);
3527 if (r)
3528 return r;
3529
3530 result += 4;
3531 buf += 4;
3532 offset += 4;
3533 size -= 4;
3534 }
3535
3536 return result;
3537}
3538
3539static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf,
3540 size_t size, loff_t *pos)
3541{
3542 struct amdgpu_device *adev = f->f_inode->i_private;
3543 int r;
3544 ssize_t result = 0;
3545 uint32_t offset, se, sh, cu, wave, simd, thread, bank, *data;
3546
3547 if (size & 3 || *pos & 3)
3548 return -EINVAL;
3549
3550 /* decode offset */
3551 offset = *pos & GENMASK_ULL(11, 0);
3552 se = (*pos & GENMASK_ULL(19, 12)) >> 12;
3553 sh = (*pos & GENMASK_ULL(27, 20)) >> 20;
3554 cu = (*pos & GENMASK_ULL(35, 28)) >> 28;
3555 wave = (*pos & GENMASK_ULL(43, 36)) >> 36;
3556 simd = (*pos & GENMASK_ULL(51, 44)) >> 44;
3557 thread = (*pos & GENMASK_ULL(59, 52)) >> 52;
3558 bank = (*pos & GENMASK_ULL(61, 60)) >> 60;
3559
3560 data = kmalloc_array(1024, sizeof(*data), GFP_KERNEL);
3561 if (!data)
3562 return -ENOMEM;
3563
3564 /* switch to the specific se/sh/cu */
3565 mutex_lock(&adev->grbm_idx_mutex);
3566 amdgpu_gfx_select_se_sh(adev, se, sh, cu);
3567
3568 if (bank == 0) {
3569 if (adev->gfx.funcs->read_wave_vgprs)
3570 adev->gfx.funcs->read_wave_vgprs(adev, simd, wave, thread, offset, size>>2, data);
3571 } else {
3572 if (adev->gfx.funcs->read_wave_sgprs)
3573 adev->gfx.funcs->read_wave_sgprs(adev, simd, wave, offset, size>>2, data);
3574 }
3575
3576 amdgpu_gfx_select_se_sh(adev, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
3577 mutex_unlock(&adev->grbm_idx_mutex);
3578
3579 while (size) {
3580 uint32_t value;
3581
3582 value = data[offset++];
3583 r = put_user(value, (uint32_t *)buf);
3584 if (r) {
3585 result = r;
3586 goto err;
3587 }
3588
3589 result += 4;
3590 buf += 4;
3591 size -= 4;
3592 }
3593
3594err:
3595 kfree(data);
3596 return result;
3597}
3598
3599static const struct file_operations amdgpu_debugfs_regs_fops = {
3600 .owner = THIS_MODULE,
3601 .read = amdgpu_debugfs_regs_read,
3602 .write = amdgpu_debugfs_regs_write,
3603 .llseek = default_llseek
3604};
3605static const struct file_operations amdgpu_debugfs_regs_didt_fops = {
3606 .owner = THIS_MODULE,
3607 .read = amdgpu_debugfs_regs_didt_read,
3608 .write = amdgpu_debugfs_regs_didt_write,
3609 .llseek = default_llseek
3610};
3611static const struct file_operations amdgpu_debugfs_regs_pcie_fops = {
3612 .owner = THIS_MODULE,
3613 .read = amdgpu_debugfs_regs_pcie_read,
3614 .write = amdgpu_debugfs_regs_pcie_write,
3615 .llseek = default_llseek
3616};
3617static const struct file_operations amdgpu_debugfs_regs_smc_fops = {
3618 .owner = THIS_MODULE,
3619 .read = amdgpu_debugfs_regs_smc_read,
3620 .write = amdgpu_debugfs_regs_smc_write,
3621 .llseek = default_llseek
3622};
3623
3624static const struct file_operations amdgpu_debugfs_gca_config_fops = {
3625 .owner = THIS_MODULE,
3626 .read = amdgpu_debugfs_gca_config_read,
3627 .llseek = default_llseek
3628};
3629
3630static const struct file_operations amdgpu_debugfs_sensors_fops = {
3631 .owner = THIS_MODULE,
3632 .read = amdgpu_debugfs_sensor_read,
3633 .llseek = default_llseek
3634};
3635
3636static const struct file_operations amdgpu_debugfs_wave_fops = {
3637 .owner = THIS_MODULE,
3638 .read = amdgpu_debugfs_wave_read,
3639 .llseek = default_llseek
3640};
3641static const struct file_operations amdgpu_debugfs_gpr_fops = {
3642 .owner = THIS_MODULE,
3643 .read = amdgpu_debugfs_gpr_read,
3644 .llseek = default_llseek
3645};
3646
3647static const struct file_operations *debugfs_regs[] = {
3648 &amdgpu_debugfs_regs_fops,
3649 &amdgpu_debugfs_regs_didt_fops,
3650 &amdgpu_debugfs_regs_pcie_fops,
3651 &amdgpu_debugfs_regs_smc_fops,
3652 &amdgpu_debugfs_gca_config_fops,
3653 &amdgpu_debugfs_sensors_fops,
3654 &amdgpu_debugfs_wave_fops,
3655 &amdgpu_debugfs_gpr_fops,
3656};
3657
3658static const char *debugfs_regs_names[] = {
3659 "amdgpu_regs",
3660 "amdgpu_regs_didt",
3661 "amdgpu_regs_pcie",
3662 "amdgpu_regs_smc",
3663 "amdgpu_gca_config",
3664 "amdgpu_sensors",
3665 "amdgpu_wave",
3666 "amdgpu_gpr",
3667};
3668
3669static int amdgpu_debugfs_regs_init(struct amdgpu_device *adev)
3670{
3671 struct drm_minor *minor = adev->ddev->primary;
3672 struct dentry *ent, *root = minor->debugfs_root;
3673 unsigned i, j;
3674
3675 for (i = 0; i < ARRAY_SIZE(debugfs_regs); i++) {
3676 ent = debugfs_create_file(debugfs_regs_names[i],
3677 S_IFREG | S_IRUGO, root,
3678 adev, debugfs_regs[i]);
3679 if (IS_ERR(ent)) {
3680 for (j = 0; j < i; j++) {
3681 debugfs_remove(adev->debugfs_regs[i]);
3682 adev->debugfs_regs[i] = NULL;
3683 }
3684 return PTR_ERR(ent);
3685 }
3686
3687 if (!i)
3688 i_size_write(ent->d_inode, adev->rmmio_size);
3689 adev->debugfs_regs[i] = ent;
3690 }
3691
3692 return 0;
3693}
3694
3695static void amdgpu_debugfs_regs_cleanup(struct amdgpu_device *adev)
3696{
3697 unsigned i;
3698
3699 for (i = 0; i < ARRAY_SIZE(debugfs_regs); i++) {
3700 if (adev->debugfs_regs[i]) {
3701 debugfs_remove(adev->debugfs_regs[i]);
3702 adev->debugfs_regs[i] = NULL;
3703 }
3704 }
3705}
3706
3707static int amdgpu_debugfs_test_ib(struct seq_file *m, void *data)
3708{
3709 struct drm_info_node *node = (struct drm_info_node *) m->private;
3710 struct drm_device *dev = node->minor->dev;
3711 struct amdgpu_device *adev = dev->dev_private;
3712 int r = 0, i;
3713
3714 /* hold on the scheduler */
3715 for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
3716 struct amdgpu_ring *ring = adev->rings[i];
3717
3718 if (!ring || !ring->sched.thread)
3719 continue;
3720 kthread_park(ring->sched.thread);
3721 }
3722
3723 seq_printf(m, "run ib test:\n");
3724 r = amdgpu_ib_ring_tests(adev);
3725 if (r)
3726 seq_printf(m, "ib ring tests failed (%d).\n", r);
3727 else
3728 seq_printf(m, "ib ring tests passed.\n");
3729
3730 /* go on the scheduler */
3731 for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
3732 struct amdgpu_ring *ring = adev->rings[i];
3733
3734 if (!ring || !ring->sched.thread)
3735 continue;
3736 kthread_unpark(ring->sched.thread);
3737 }
3738
3739 return 0;
3740}
3741
3742static int amdgpu_debugfs_get_vbios_dump(struct seq_file *m, void *data)
3743{
3744 struct drm_info_node *node = (struct drm_info_node *) m->private;
3745 struct drm_device *dev = node->minor->dev;
3746 struct amdgpu_device *adev = dev->dev_private;
3747
3748 seq_write(m, adev->bios, adev->bios_size);
3749 return 0;
3750}
3751
3752static int amdgpu_debugfs_evict_vram(struct seq_file *m, void *data)
3753{
3754 struct drm_info_node *node = (struct drm_info_node *)m->private;
3755 struct drm_device *dev = node->minor->dev;
3756 struct amdgpu_device *adev = dev->dev_private;
3757
3758 seq_printf(m, "(%d)\n", amdgpu_bo_evict_vram(adev));
3759 return 0;
3760}
3761
3762static const struct drm_info_list amdgpu_debugfs_list[] = {
3763 {"amdgpu_vbios", amdgpu_debugfs_get_vbios_dump},
3764 {"amdgpu_test_ib", &amdgpu_debugfs_test_ib},
3765 {"amdgpu_evict_vram", &amdgpu_debugfs_evict_vram}
3766};
3767
3768static int amdgpu_debugfs_init(struct amdgpu_device *adev)
3769{
3770 return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_list,
3771 ARRAY_SIZE(amdgpu_debugfs_list));
3772}
3773
3774#else
3775static int amdgpu_debugfs_init(struct amdgpu_device *adev)
3776{
3777 return 0;
3778}
3779static int amdgpu_debugfs_regs_init(struct amdgpu_device *adev)
3780{
3781 return 0;
3782}
3783static void amdgpu_debugfs_regs_cleanup(struct amdgpu_device *adev) { }
3784#endif
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index eb75eb44efc6..10805edcf964 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -851,7 +851,7 @@ static const struct drm_info_list amdgpu_debugfs_gem_list[] = {
851}; 851};
852#endif 852#endif
853 853
854int amdgpu_gem_debugfs_init(struct amdgpu_device *adev) 854int amdgpu_debugfs_gem_init(struct amdgpu_device *adev)
855{ 855{
856#if defined(CONFIG_DEBUG_FS) 856#if defined(CONFIG_DEBUG_FS)
857 return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_gem_list, 1); 857 return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_gem_list, 1);