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_securedisplay.h"
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 void psp_securedisplay_parse_resp_status(struct psp_context *psp,
0049 enum ta_securedisplay_status status)
0050 {
0051 switch (status) {
0052 case TA_SECUREDISPLAY_STATUS__SUCCESS:
0053 break;
0054 case TA_SECUREDISPLAY_STATUS__GENERIC_FAILURE:
0055 dev_err(psp->adev->dev, "Secure display: Generic Failure.");
0056 break;
0057 case TA_SECUREDISPLAY_STATUS__INVALID_PARAMETER:
0058 dev_err(psp->adev->dev, "Secure display: Invalid Parameter.");
0059 break;
0060 case TA_SECUREDISPLAY_STATUS__NULL_POINTER:
0061 dev_err(psp->adev->dev, "Secure display: Null Pointer.");
0062 break;
0063 case TA_SECUREDISPLAY_STATUS__I2C_WRITE_ERROR:
0064 dev_err(psp->adev->dev, "Secure display: Failed to write to I2C.");
0065 break;
0066 case TA_SECUREDISPLAY_STATUS__READ_DIO_SCRATCH_ERROR:
0067 dev_err(psp->adev->dev, "Secure display: Failed to Read DIO Scratch Register.");
0068 break;
0069 case TA_SECUREDISPLAY_STATUS__READ_CRC_ERROR:
0070 dev_err(psp->adev->dev, "Secure display: Failed to Read CRC");
0071 break;
0072 case TA_SECUREDISPLAY_STATUS__I2C_INIT_ERROR:
0073 dev_err(psp->adev->dev, "Secure display: Failed to initialize I2C.");
0074 break;
0075 default:
0076 dev_err(psp->adev->dev, "Secure display: Failed to parse status: %d\n", status);
0077 }
0078 }
0079
0080 void psp_prep_securedisplay_cmd_buf(struct psp_context *psp, struct securedisplay_cmd **cmd,
0081 enum ta_securedisplay_command command_id)
0082 {
0083 *cmd = (struct securedisplay_cmd *)psp->securedisplay_context.context.mem_context.shared_buf;
0084 memset(*cmd, 0, sizeof(struct securedisplay_cmd));
0085 (*cmd)->status = TA_SECUREDISPLAY_STATUS__GENERIC_FAILURE;
0086 (*cmd)->cmd_id = command_id;
0087 }
0088
0089 #if defined(CONFIG_DEBUG_FS)
0090
0091 static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __user *buf,
0092 size_t size, loff_t *pos)
0093 {
0094 struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private;
0095 struct psp_context *psp = &adev->psp;
0096 struct securedisplay_cmd *securedisplay_cmd;
0097 struct drm_device *dev = adev_to_drm(adev);
0098 uint32_t phy_id;
0099 uint32_t op;
0100 char str[64];
0101 int ret;
0102
0103 if (*pos || size > sizeof(str) - 1)
0104 return -EINVAL;
0105
0106 memset(str, 0, sizeof(str));
0107 ret = copy_from_user(str, buf, size);
0108 if (ret)
0109 return -EFAULT;
0110
0111 ret = pm_runtime_get_sync(dev->dev);
0112 if (ret < 0) {
0113 pm_runtime_put_autosuspend(dev->dev);
0114 return ret;
0115 }
0116
0117 if (size < 3)
0118 sscanf(str, "%u ", &op);
0119 else
0120 sscanf(str, "%u %u", &op, &phy_id);
0121
0122 switch (op) {
0123 case 1:
0124 psp_prep_securedisplay_cmd_buf(psp, &securedisplay_cmd,
0125 TA_SECUREDISPLAY_COMMAND__QUERY_TA);
0126 ret = psp_securedisplay_invoke(psp, TA_SECUREDISPLAY_COMMAND__QUERY_TA);
0127 if (!ret) {
0128 if (securedisplay_cmd->status == TA_SECUREDISPLAY_STATUS__SUCCESS)
0129 dev_info(adev->dev, "SECUREDISPLAY: query securedisplay TA ret is 0x%X\n",
0130 securedisplay_cmd->securedisplay_out_message.query_ta.query_cmd_ret);
0131 else
0132 psp_securedisplay_parse_resp_status(psp, securedisplay_cmd->status);
0133 }
0134 break;
0135 case 2:
0136 psp_prep_securedisplay_cmd_buf(psp, &securedisplay_cmd,
0137 TA_SECUREDISPLAY_COMMAND__SEND_ROI_CRC);
0138 securedisplay_cmd->securedisplay_in_message.send_roi_crc.phy_id = phy_id;
0139 ret = psp_securedisplay_invoke(psp, TA_SECUREDISPLAY_COMMAND__SEND_ROI_CRC);
0140 if (!ret) {
0141 if (securedisplay_cmd->status == TA_SECUREDISPLAY_STATUS__SUCCESS) {
0142 dev_info(adev->dev, "SECUREDISPLAY: I2C buffer out put is: %*ph\n",
0143 TA_SECUREDISPLAY_I2C_BUFFER_SIZE,
0144 securedisplay_cmd->securedisplay_out_message.send_roi_crc.i2c_buf);
0145 } else {
0146 psp_securedisplay_parse_resp_status(psp, securedisplay_cmd->status);
0147 }
0148 }
0149 break;
0150 default:
0151 dev_err(adev->dev, "Invalid input: %s\n", str);
0152 }
0153
0154 pm_runtime_mark_last_busy(dev->dev);
0155 pm_runtime_put_autosuspend(dev->dev);
0156
0157 return size;
0158 }
0159
0160 static const struct file_operations amdgpu_securedisplay_debugfs_ops = {
0161 .owner = THIS_MODULE,
0162 .read = NULL,
0163 .write = amdgpu_securedisplay_debugfs_write,
0164 .llseek = default_llseek
0165 };
0166
0167 #endif
0168
0169 void amdgpu_securedisplay_debugfs_init(struct amdgpu_device *adev)
0170 {
0171 #if defined(CONFIG_DEBUG_FS)
0172
0173 if (!adev->psp.securedisplay_context.context.initialized)
0174 return;
0175
0176 debugfs_create_file("securedisplay_test", S_IWUSR, adev_to_drm(adev)->primary->debugfs_root,
0177 adev, &amdgpu_securedisplay_debugfs_ops);
0178 #endif
0179 }