Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2020 Advanced Micro Devices, Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
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  * DOC: AMDGPU RAP debugfs test interface
0032  *
0033  * how to use?
0034  * echo opcode > <debugfs_dir>/dri/xxx/rap_test
0035  *
0036  * opcode:
0037  * currently, only 2 is supported by Linux host driver,
0038  * opcode 2 stands for TA_CMD_RAP__VALIDATE_L0, used to
0039  * trigger L0 policy validation, you can refer more detail
0040  * from header file ta_rap_if.h
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     /* make sure gfx core is on, RAP TA cann't handle
0068      * GFX OFF case currently.
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 }