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 #ifdef __linux__ 31 32 /** 33 * DOC: AMDGPU RAP debugfs test interface 34 * 35 * how to use? 36 * echo opcode > <debugfs_dir>/dri/xxx/rap_test 37 * 38 * opcode: 39 * currently, only 2 is supported by Linux host driver, 40 * opcode 2 stands for TA_CMD_RAP__VALIDATE_L0, used to 41 * trigger L0 policy validation, you can refer more detail 42 * from header file ta_rap_if.h 43 * 44 */ 45 static ssize_t amdgpu_rap_debugfs_write(struct file *f, const char __user *buf, 46 size_t size, loff_t *pos) 47 { 48 struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private; 49 struct ta_rap_shared_memory *rap_shared_mem; 50 struct ta_rap_cmd_output_data *rap_cmd_output; 51 struct drm_device *dev = adev_to_drm(adev); 52 uint32_t op; 53 int ret; 54 55 if (*pos || size != 2) 56 return -EINVAL; 57 58 ret = kstrtouint_from_user(buf, size, *pos, &op); 59 if (ret) 60 return ret; 61 62 ret = pm_runtime_get_sync(dev->dev); 63 if (ret < 0) { 64 pm_runtime_put_autosuspend(dev->dev); 65 return ret; 66 } 67 68 /* make sure gfx core is on, RAP TA cann't handle 69 * GFX OFF case currently. 70 */ 71 amdgpu_gfx_off_ctrl(adev, false); 72 73 switch (op) { 74 case 2: 75 ret = psp_rap_invoke(&adev->psp, op); 76 77 if (ret == TA_RAP_STATUS__SUCCESS) { 78 dev_info(adev->dev, "RAP L0 validate test success.\n"); 79 } else { 80 rap_shared_mem = (struct ta_rap_shared_memory *) 81 adev->psp.rap_context.rap_shared_buf; 82 rap_cmd_output = &(rap_shared_mem->rap_out_message.output); 83 84 dev_info(adev->dev, "RAP test failed, the output is:\n"); 85 dev_info(adev->dev, "\tlast_subsection: 0x%08x.\n", 86 rap_cmd_output->last_subsection); 87 dev_info(adev->dev, "\tnum_total_validate: 0x%08x.\n", 88 rap_cmd_output->num_total_validate); 89 dev_info(adev->dev, "\tnum_valid: 0x%08x.\n", 90 rap_cmd_output->num_valid); 91 dev_info(adev->dev, "\tlast_validate_addr: 0x%08x.\n", 92 rap_cmd_output->last_validate_addr); 93 dev_info(adev->dev, "\tlast_validate_val: 0x%08x.\n", 94 rap_cmd_output->last_validate_val); 95 dev_info(adev->dev, "\tlast_validate_val_exptd: 0x%08x.\n", 96 rap_cmd_output->last_validate_val_exptd); 97 } 98 break; 99 default: 100 dev_info(adev->dev, "Unsupported op id: %d, ", op); 101 dev_info(adev->dev, "Only support op 2(L0 validate test).\n"); 102 } 103 104 amdgpu_gfx_off_ctrl(adev, true); 105 pm_runtime_mark_last_busy(dev->dev); 106 pm_runtime_put_autosuspend(dev->dev); 107 108 return size; 109 } 110 111 static const struct file_operations amdgpu_rap_debugfs_ops = { 112 .owner = THIS_MODULE, 113 .read = NULL, 114 .write = amdgpu_rap_debugfs_write, 115 .llseek = default_llseek 116 }; 117 118 #endif /* __linux__ */ 119 120 void amdgpu_rap_debugfs_init(struct amdgpu_device *adev) 121 { 122 #if defined(CONFIG_DEBUG_FS) 123 struct drm_minor *minor = adev_to_drm(adev)->primary; 124 125 if (!adev->psp.rap_context.rap_initialized) 126 return; 127 128 debugfs_create_file("rap_test", S_IWUSR, minor->debugfs_root, 129 adev, &amdgpu_rap_debugfs_ops); 130 #endif 131 } 132