0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #include <linux/debugfs.h>
0025 #include <linux/pm_runtime.h>
0026
0027 #include "amdgpu.h"
0028 #include "amdgpu_rap.h"
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 static ssize_t amdgpu_rap_debugfs_write(struct file *f, const char __user *buf,
0044 size_t size, loff_t *pos)
0045 {
0046 struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private;
0047 struct ta_rap_shared_memory *rap_shared_mem;
0048 struct ta_rap_cmd_output_data *rap_cmd_output;
0049 struct drm_device *dev = adev_to_drm(adev);
0050 uint32_t op;
0051 enum ta_rap_status status;
0052 int ret;
0053
0054 if (*pos || size != 2)
0055 return -EINVAL;
0056
0057 ret = kstrtouint_from_user(buf, size, *pos, &op);
0058 if (ret)
0059 return ret;
0060
0061 ret = pm_runtime_get_sync(dev->dev);
0062 if (ret < 0) {
0063 pm_runtime_put_autosuspend(dev->dev);
0064 return ret;
0065 }
0066
0067
0068
0069
0070 amdgpu_gfx_off_ctrl(adev, false);
0071
0072 switch (op) {
0073 case 2:
0074 ret = psp_rap_invoke(&adev->psp, op, &status);
0075 if (!ret && status == TA_RAP_STATUS__SUCCESS) {
0076 dev_info(adev->dev, "RAP L0 validate test success.\n");
0077 } else {
0078 rap_shared_mem = (struct ta_rap_shared_memory *)
0079 adev->psp.rap_context.context.mem_context.shared_buf;
0080 rap_cmd_output = &(rap_shared_mem->rap_out_message.output);
0081
0082 dev_info(adev->dev, "RAP test failed, the output is:\n");
0083 dev_info(adev->dev, "\tlast_subsection: 0x%08x.\n",
0084 rap_cmd_output->last_subsection);
0085 dev_info(adev->dev, "\tnum_total_validate: 0x%08x.\n",
0086 rap_cmd_output->num_total_validate);
0087 dev_info(adev->dev, "\tnum_valid: 0x%08x.\n",
0088 rap_cmd_output->num_valid);
0089 dev_info(adev->dev, "\tlast_validate_addr: 0x%08x.\n",
0090 rap_cmd_output->last_validate_addr);
0091 dev_info(adev->dev, "\tlast_validate_val: 0x%08x.\n",
0092 rap_cmd_output->last_validate_val);
0093 dev_info(adev->dev, "\tlast_validate_val_exptd: 0x%08x.\n",
0094 rap_cmd_output->last_validate_val_exptd);
0095 }
0096 break;
0097 default:
0098 dev_info(adev->dev, "Unsupported op id: %d, ", op);
0099 dev_info(adev->dev, "Only support op 2(L0 validate test).\n");
0100 break;
0101 }
0102
0103 amdgpu_gfx_off_ctrl(adev, true);
0104 pm_runtime_mark_last_busy(dev->dev);
0105 pm_runtime_put_autosuspend(dev->dev);
0106
0107 return size;
0108 }
0109
0110 static const struct file_operations amdgpu_rap_debugfs_ops = {
0111 .owner = THIS_MODULE,
0112 .read = NULL,
0113 .write = amdgpu_rap_debugfs_write,
0114 .llseek = default_llseek
0115 };
0116
0117 void amdgpu_rap_debugfs_init(struct amdgpu_device *adev)
0118 {
0119 #if defined(CONFIG_DEBUG_FS)
0120 struct drm_minor *minor = adev_to_drm(adev)->primary;
0121
0122 if (!adev->psp.rap_context.context.initialized)
0123 return;
0124
0125 debugfs_create_file("rap_test", S_IWUSR, minor->debugfs_root,
0126 adev, &amdgpu_rap_debugfs_ops);
0127 #endif
0128 }