mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-15 15:04:27 +08:00
crypto: ccp - Add a communication path abstraction for DBC
DBC is currently accessed only from the platform access mailbox and a lot of that implementation's communication path is intertwined with DBC. Add an abstraction layer for pointers into the mailbox. No intended functional changes. Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
6e17375c47
commit
2ac85e22e1
@ -42,17 +42,17 @@ static int send_dbc_cmd(struct psp_dbc_device *dbc_dev,
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
dbc_dev->mbox->req.header.status = 0;
|
*dbc_dev->result = 0;
|
||||||
ret = psp_send_platform_access_msg(msg, (struct psp_request *)dbc_dev->mbox);
|
ret = psp_send_platform_access_msg(msg, (struct psp_request *)dbc_dev->mbox);
|
||||||
if (ret == -EIO) {
|
if (ret == -EIO) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
dev_dbg(dbc_dev->dev,
|
dev_dbg(dbc_dev->dev,
|
||||||
"msg 0x%x failed with PSP error: 0x%x\n",
|
"msg 0x%x failed with PSP error: 0x%x\n",
|
||||||
msg, dbc_dev->mbox->req.header.status);
|
msg, *dbc_dev->result);
|
||||||
|
|
||||||
for (i = 0; error_codes[i].psp; i++) {
|
for (i = 0; error_codes[i].psp; i++) {
|
||||||
if (dbc_dev->mbox->req.header.status == error_codes[i].psp)
|
if (*dbc_dev->result == error_codes[i].psp)
|
||||||
return error_codes[i].ret;
|
return error_codes[i].ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ static int send_dbc_nonce(struct psp_dbc_device *dbc_dev)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
dbc_dev->mbox->req.header.payload_size = sizeof(dbc_dev->mbox->dbc_nonce);
|
*dbc_dev->payload_size = dbc_dev->header_size + sizeof(struct dbc_user_nonce);
|
||||||
ret = send_dbc_cmd(dbc_dev, PSP_DYNAMIC_BOOST_GET_NONCE);
|
ret = send_dbc_cmd(dbc_dev, PSP_DYNAMIC_BOOST_GET_NONCE);
|
||||||
if (ret == -EAGAIN) {
|
if (ret == -EAGAIN) {
|
||||||
dev_dbg(dbc_dev->dev, "retrying get nonce\n");
|
dev_dbg(dbc_dev->dev, "retrying get nonce\n");
|
||||||
@ -76,9 +76,9 @@ static int send_dbc_nonce(struct psp_dbc_device *dbc_dev)
|
|||||||
|
|
||||||
static int send_dbc_parameter(struct psp_dbc_device *dbc_dev)
|
static int send_dbc_parameter(struct psp_dbc_device *dbc_dev)
|
||||||
{
|
{
|
||||||
dbc_dev->mbox->req.header.payload_size = sizeof(dbc_dev->mbox->dbc_param);
|
struct dbc_user_param *user_param = (struct dbc_user_param *)dbc_dev->payload;
|
||||||
|
|
||||||
switch (dbc_dev->mbox->dbc_param.user.msg_index) {
|
switch (user_param->msg_index) {
|
||||||
case PARAM_SET_FMAX_CAP:
|
case PARAM_SET_FMAX_CAP:
|
||||||
case PARAM_SET_PWR_CAP:
|
case PARAM_SET_PWR_CAP:
|
||||||
case PARAM_SET_GFX_MODE:
|
case PARAM_SET_GFX_MODE:
|
||||||
@ -125,8 +125,7 @@ static long dbc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
|||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case DBCIOCNONCE:
|
case DBCIOCNONCE:
|
||||||
if (copy_from_user(&dbc_dev->mbox->dbc_nonce.user, argp,
|
if (copy_from_user(dbc_dev->payload, argp, sizeof(struct dbc_user_nonce))) {
|
||||||
sizeof(struct dbc_user_nonce))) {
|
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
goto unlock;
|
goto unlock;
|
||||||
}
|
}
|
||||||
@ -135,43 +134,39 @@ static long dbc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
|||||||
if (ret)
|
if (ret)
|
||||||
goto unlock;
|
goto unlock;
|
||||||
|
|
||||||
if (copy_to_user(argp, &dbc_dev->mbox->dbc_nonce.user,
|
if (copy_to_user(argp, dbc_dev->payload, sizeof(struct dbc_user_nonce))) {
|
||||||
sizeof(struct dbc_user_nonce))) {
|
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
goto unlock;
|
goto unlock;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DBCIOCUID:
|
case DBCIOCUID:
|
||||||
dbc_dev->mbox->req.header.payload_size = sizeof(dbc_dev->mbox->dbc_set_uid);
|
if (copy_from_user(dbc_dev->payload, argp, sizeof(struct dbc_user_setuid))) {
|
||||||
if (copy_from_user(&dbc_dev->mbox->dbc_set_uid.user, argp,
|
|
||||||
sizeof(struct dbc_user_setuid))) {
|
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
goto unlock;
|
goto unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*dbc_dev->payload_size = dbc_dev->header_size + sizeof(struct dbc_user_setuid);
|
||||||
ret = send_dbc_cmd(dbc_dev, PSP_DYNAMIC_BOOST_SET_UID);
|
ret = send_dbc_cmd(dbc_dev, PSP_DYNAMIC_BOOST_SET_UID);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto unlock;
|
goto unlock;
|
||||||
|
|
||||||
if (copy_to_user(argp, &dbc_dev->mbox->dbc_set_uid.user,
|
if (copy_to_user(argp, dbc_dev->payload, sizeof(struct dbc_user_setuid))) {
|
||||||
sizeof(struct dbc_user_setuid))) {
|
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
goto unlock;
|
goto unlock;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DBCIOCPARAM:
|
case DBCIOCPARAM:
|
||||||
if (copy_from_user(&dbc_dev->mbox->dbc_param.user, argp,
|
if (copy_from_user(dbc_dev->payload, argp, sizeof(struct dbc_user_param))) {
|
||||||
sizeof(struct dbc_user_param))) {
|
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
goto unlock;
|
goto unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*dbc_dev->payload_size = dbc_dev->header_size + sizeof(struct dbc_user_param);
|
||||||
ret = send_dbc_parameter(dbc_dev);
|
ret = send_dbc_parameter(dbc_dev);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto unlock;
|
goto unlock;
|
||||||
|
|
||||||
if (copy_to_user(argp, &dbc_dev->mbox->dbc_param.user,
|
if (copy_to_user(argp, dbc_dev->payload, sizeof(struct dbc_user_param))) {
|
||||||
sizeof(struct dbc_user_param))) {
|
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
goto unlock;
|
goto unlock;
|
||||||
}
|
}
|
||||||
@ -213,6 +208,10 @@ int dbc_dev_init(struct psp_device *psp)
|
|||||||
|
|
||||||
psp->dbc_data = dbc_dev;
|
psp->dbc_data = dbc_dev;
|
||||||
dbc_dev->dev = dev;
|
dbc_dev->dev = dev;
|
||||||
|
dbc_dev->payload_size = &dbc_dev->mbox->pa_req.header.payload_size;
|
||||||
|
dbc_dev->result = &dbc_dev->mbox->pa_req.header.status;
|
||||||
|
dbc_dev->payload = &dbc_dev->mbox->pa_req.buf;
|
||||||
|
dbc_dev->header_size = sizeof(struct psp_req_buffer_hdr);
|
||||||
|
|
||||||
ret = send_dbc_nonce(dbc_dev);
|
ret = send_dbc_nonce(dbc_dev);
|
||||||
if (ret == -EACCES) {
|
if (ret == -EACCES) {
|
||||||
|
@ -26,28 +26,17 @@ struct psp_dbc_device {
|
|||||||
struct mutex ioctl_mutex;
|
struct mutex ioctl_mutex;
|
||||||
|
|
||||||
struct miscdevice char_dev;
|
struct miscdevice char_dev;
|
||||||
|
|
||||||
|
/* used to abstract communication path */
|
||||||
|
bool use_ext;
|
||||||
|
u32 header_size;
|
||||||
|
u32 *payload_size;
|
||||||
|
u32 *result;
|
||||||
|
void *payload;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct dbc_nonce {
|
|
||||||
struct psp_req_buffer_hdr header;
|
|
||||||
struct dbc_user_nonce user;
|
|
||||||
} __packed;
|
|
||||||
|
|
||||||
struct dbc_set_uid {
|
|
||||||
struct psp_req_buffer_hdr header;
|
|
||||||
struct dbc_user_setuid user;
|
|
||||||
} __packed;
|
|
||||||
|
|
||||||
struct dbc_param {
|
|
||||||
struct psp_req_buffer_hdr header;
|
|
||||||
struct dbc_user_param user;
|
|
||||||
} __packed;
|
|
||||||
|
|
||||||
union dbc_buffer {
|
union dbc_buffer {
|
||||||
struct psp_request req;
|
struct psp_request pa_req;
|
||||||
struct dbc_nonce dbc_nonce;
|
|
||||||
struct dbc_set_uid dbc_set_uid;
|
|
||||||
struct dbc_param dbc_param;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void dbc_dev_destroy(struct psp_device *psp);
|
void dbc_dev_destroy(struct psp_device *psp);
|
||||||
|
Loading…
Reference in New Issue
Block a user