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@xxxxxxx> --- drivers/crypto/ccp/dbc.c | 37 ++++++++++++++++++------------------- drivers/crypto/ccp/dbc.h | 27 ++++++++------------------- 2 files changed, 26 insertions(+), 38 deletions(-) diff --git a/drivers/crypto/ccp/dbc.c b/drivers/crypto/ccp/dbc.c index 6f33149ef80d..ebd7279d4001 100644 --- a/drivers/crypto/ccp/dbc.c +++ b/drivers/crypto/ccp/dbc.c @@ -42,17 +42,17 @@ static int send_dbc_cmd(struct psp_dbc_device *dbc_dev, { 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); if (ret == -EIO) { int i; dev_dbg(dbc_dev->dev, "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++) { - if (dbc_dev->mbox->req.header.status == error_codes[i].psp) + if (*dbc_dev->result == error_codes[i].psp) return error_codes[i].ret; } } @@ -64,7 +64,7 @@ static int send_dbc_nonce(struct psp_dbc_device *dbc_dev) { 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); if (ret == -EAGAIN) { 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) { - 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_PWR_CAP: case PARAM_SET_GFX_MODE: @@ -125,8 +125,7 @@ static long dbc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) switch (cmd) { case DBCIOCNONCE: - if (copy_from_user(&dbc_dev->mbox->dbc_nonce.user, argp, - sizeof(struct dbc_user_nonce))) { + if (copy_from_user(dbc_dev->payload, argp, sizeof(struct dbc_user_nonce))) { ret = -EFAULT; goto unlock; } @@ -135,43 +134,39 @@ static long dbc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) if (ret) goto unlock; - if (copy_to_user(argp, &dbc_dev->mbox->dbc_nonce.user, - sizeof(struct dbc_user_nonce))) { + if (copy_to_user(argp, dbc_dev->payload, sizeof(struct dbc_user_nonce))) { ret = -EFAULT; goto unlock; } break; case DBCIOCUID: - dbc_dev->mbox->req.header.payload_size = sizeof(dbc_dev->mbox->dbc_set_uid); - if (copy_from_user(&dbc_dev->mbox->dbc_set_uid.user, argp, - sizeof(struct dbc_user_setuid))) { + if (copy_from_user(dbc_dev->payload, argp, sizeof(struct dbc_user_setuid))) { ret = -EFAULT; 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); if (ret) goto unlock; - if (copy_to_user(argp, &dbc_dev->mbox->dbc_set_uid.user, - sizeof(struct dbc_user_setuid))) { + if (copy_to_user(argp, dbc_dev->payload, sizeof(struct dbc_user_setuid))) { ret = -EFAULT; goto unlock; } break; case DBCIOCPARAM: - if (copy_from_user(&dbc_dev->mbox->dbc_param.user, argp, - sizeof(struct dbc_user_param))) { + if (copy_from_user(dbc_dev->payload, argp, sizeof(struct dbc_user_param))) { ret = -EFAULT; goto unlock; } + *dbc_dev->payload_size = dbc_dev->header_size + sizeof(struct dbc_user_param); ret = send_dbc_parameter(dbc_dev); if (ret) goto unlock; - if (copy_to_user(argp, &dbc_dev->mbox->dbc_param.user, - sizeof(struct dbc_user_param))) { + if (copy_to_user(argp, dbc_dev->payload, sizeof(struct dbc_user_param))) { ret = -EFAULT; goto unlock; } @@ -213,6 +208,10 @@ int dbc_dev_init(struct psp_device *psp) psp->dbc_data = dbc_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); if (ret == -EACCES) { diff --git a/drivers/crypto/ccp/dbc.h b/drivers/crypto/ccp/dbc.h index e963099ca38e..184646ee55bb 100644 --- a/drivers/crypto/ccp/dbc.h +++ b/drivers/crypto/ccp/dbc.h @@ -26,28 +26,17 @@ struct psp_dbc_device { struct mutex ioctl_mutex; struct miscdevice char_dev; -}; - -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; + /* used to abstract communication path */ + bool use_ext; + u32 header_size; + u32 *payload_size; + u32 *result; + void *payload; +}; union dbc_buffer { - struct psp_request req; - struct dbc_nonce dbc_nonce; - struct dbc_set_uid dbc_set_uid; - struct dbc_param dbc_param; + struct psp_request pa_req; }; void dbc_dev_destroy(struct psp_device *psp); -- 2.34.1