Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdgpu: add debugfs interface for RAP test

After amdgpu driver loading successfully, we can use
RAP debugfs interface <debugfs_dir>/dri/xxx/rap_test
to trigger RAP test.

Currently only L0 validate test is supported.

v2: refine amdgpu_rap.h

Signed-off-by: Wenhui Sheng <Wenhui.Sheng@amd.com>
Reviewed-by: Guchun Chen <Guchun.Chen@amd.com>
Reviewed-by: Hawking Zhang <Hawking.Zhang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Wenhui Sheng and committed by
Alex Deucher
a4322e18 8602692b

+161 -1
+1 -1
drivers/gpu/drm/amd/amdgpu/Makefile
··· 55 55 amdgpu_vf_error.o amdgpu_sched.o amdgpu_debugfs.o amdgpu_ids.o \ 56 56 amdgpu_gmc.o amdgpu_mmhub.o amdgpu_xgmi.o amdgpu_csa.o amdgpu_ras.o amdgpu_vm_cpu.o \ 57 57 amdgpu_vm_sdma.o amdgpu_discovery.o amdgpu_ras_eeprom.o amdgpu_nbio.o \ 58 - amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o 58 + amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o 59 59 60 60 amdgpu-$(CONFIG_PERF_EVENTS) += amdgpu_pmu.o 61 61
+3
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
··· 34 34 #include "amdgpu_pm.h" 35 35 #include "amdgpu_dm_debugfs.h" 36 36 #include "amdgpu_ras.h" 37 + #include "amdgpu_rap.h" 37 38 38 39 /** 39 40 * amdgpu_debugfs_add_files - Add simple debugfs entries ··· 1623 1622 amdgpu_ras_debugfs_create_all(adev); 1624 1623 1625 1624 amdgpu_debugfs_autodump_init(adev); 1625 + 1626 + amdgpu_rap_debugfs_init(adev); 1626 1627 1627 1628 return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_list, 1628 1629 ARRAY_SIZE(amdgpu_debugfs_list));
+127
drivers/gpu/drm/amd/amdgpu/amdgpu_rap.c
··· 1 + /* 2 + * Copyright 2020 Advanced Micro Devices, Inc. 3 + * 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: 10 + * 11 + * The above copyright notice and this permission notice shall be included in 12 + * all copies or substantial portions of the Software. 13 + * 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. 21 + * 22 + * 23 + */ 24 + #include <linux/debugfs.h> 25 + #include <linux/pm_runtime.h> 26 + 27 + #include "amdgpu.h" 28 + #include "amdgpu_rap.h" 29 + 30 + /** 31 + * DOC: AMDGPU RAP debugfs test interface 32 + * 33 + * how to use? 34 + * echo opcode > <debugfs_dir>/dri/xxx/rap_test 35 + * 36 + * opcode: 37 + * currently, only 2 is supported by Linux host driver, 38 + * opcode 2 stands for TA_CMD_RAP__VALIDATE_L0, used to 39 + * trigger L0 policy validation, you can refer more detail 40 + * from header file ta_rap_if.h 41 + * 42 + */ 43 + static ssize_t amdgpu_rap_debugfs_write(struct file *f, const char __user *buf, 44 + size_t size, loff_t *pos) 45 + { 46 + struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private; 47 + struct ta_rap_shared_memory *rap_shared_mem; 48 + struct ta_rap_cmd_output_data *rap_cmd_output; 49 + struct drm_device *dev = adev->ddev; 50 + uint32_t op; 51 + int ret; 52 + 53 + if (*pos || size != 2) 54 + return -EINVAL; 55 + 56 + ret = kstrtouint_from_user(buf, size, *pos, &op); 57 + if (ret) 58 + return ret; 59 + 60 + ret = pm_runtime_get_sync(dev->dev); 61 + if (ret < 0) { 62 + pm_runtime_put_autosuspend(dev->dev); 63 + return ret; 64 + } 65 + 66 + /* make sure gfx core is on, RAP TA cann't handle 67 + * GFX OFF case currently. 68 + */ 69 + amdgpu_gfx_off_ctrl(adev, false); 70 + 71 + switch (op) { 72 + case 2: 73 + ret = psp_rap_invoke(&adev->psp, op); 74 + 75 + if (ret == TA_RAP_STATUS__SUCCESS) { 76 + dev_info(adev->dev, "RAP L0 validate test success.\n"); 77 + } else { 78 + rap_shared_mem = (struct ta_rap_shared_memory *) 79 + adev->psp.rap_context.rap_shared_buf; 80 + rap_cmd_output = &(rap_shared_mem->rap_out_message.output); 81 + 82 + dev_info(adev->dev, "RAP test failed, the output is:\n"); 83 + dev_info(adev->dev, "\tlast_subsection: 0x%08x.\n", 84 + rap_cmd_output->last_subsection); 85 + dev_info(adev->dev, "\tnum_total_validate: 0x%08x.\n", 86 + rap_cmd_output->num_total_validate); 87 + dev_info(adev->dev, "\tnum_valid: 0x%08x.\n", 88 + rap_cmd_output->num_valid); 89 + dev_info(adev->dev, "\tlast_validate_addr: 0x%08x.\n", 90 + rap_cmd_output->last_validate_addr); 91 + dev_info(adev->dev, "\tlast_validate_val: 0x%08x.\n", 92 + rap_cmd_output->last_validate_val); 93 + dev_info(adev->dev, "\tlast_validate_val_exptd: 0x%08x.\n", 94 + rap_cmd_output->last_validate_val_exptd); 95 + } 96 + break; 97 + default: 98 + dev_info(adev->dev, "Unsupported op id: %d, ", op); 99 + dev_info(adev->dev, "Only support op 2(L0 validate test).\n"); 100 + } 101 + 102 + amdgpu_gfx_off_ctrl(adev, true); 103 + pm_runtime_mark_last_busy(dev->dev); 104 + pm_runtime_put_autosuspend(dev->dev); 105 + 106 + return size; 107 + } 108 + 109 + static const struct file_operations amdgpu_rap_debugfs_ops = { 110 + .owner = THIS_MODULE, 111 + .read = NULL, 112 + .write = amdgpu_rap_debugfs_write, 113 + .llseek = default_llseek 114 + }; 115 + 116 + void amdgpu_rap_debugfs_init(struct amdgpu_device *adev) 117 + { 118 + #if defined(CONFIG_DEBUG_FS) 119 + struct drm_minor *minor = adev->ddev->primary; 120 + 121 + if (!adev->psp.rap_context.rap_initialized) 122 + return; 123 + 124 + debugfs_create_file("rap_test", S_IWUSR, minor->debugfs_root, 125 + adev, &amdgpu_rap_debugfs_ops); 126 + #endif 127 + }
+30
drivers/gpu/drm/amd/amdgpu/amdgpu_rap.h
··· 1 + /* 2 + * Copyright 2020 Advanced Micro Devices, Inc. 3 + * 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: 10 + * 11 + * The above copyright notice and this permission notice shall be included in 12 + * all copies or substantial portions of the Software. 13 + * 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. 21 + * 22 + * 23 + */ 24 + #ifndef _AMDGPU_RAP_H 25 + #define _AMDGPU_RAP_H 26 + 27 + #include "amdgpu.h" 28 + 29 + void amdgpu_rap_debugfs_init(struct amdgpu_device *adev); 30 + #endif