Skip to content

Commit 3da9266

Browse files
committed
LF-12610: drivers: se_fw: fix signed message support
signed message ioctl() is not available due to which test will fail on i.MX8X SECO that have signed message not null. Signed-off-by: Vabhav Sharma <vabhav.sharma@nxp.com> Reviewed-by: Pankaj Gupta <pankaj.gupta@nxp.com> Reviewed-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com> Acked-by: Jason Liu <jason.hui.liu@nxp.com>
1 parent 8612280 commit 3da9266

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed

drivers/firmware/imx/se_fw.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static uint32_t v2x_fw_state;
4848
#define SOC_ID_MASK 0x0000FFFF
4949
#define RESERVED_DMA_POOL BIT(1)
5050
#define SCU_MEM_CFG BIT(2)
51+
#define SCU_SIGNED_MSG_CFG BIT(3)
5152
#define IMX_ELE_FW_DIR "/lib/firmware/imx/ele/"
5253
#define SECURE_RAM_BASE_ADDRESS_SCU (0x20800000u)
5354
#define V2X_NON_FIPS 0x00000c00
@@ -1228,6 +1229,36 @@ static int ele_mu_ioctl_get_mu_info(struct ele_mu_device_ctx *dev_ctx,
12281229
return err;
12291230
}
12301231

1232+
static int ele_mu_ioctl_signed_msg_handler(struct file *fp,
1233+
struct ele_mu_device_ctx *dev_ctx,
1234+
unsigned long arg)
1235+
{
1236+
struct ele_mu_ioctl_signed_message msg;
1237+
int err;
1238+
1239+
err = copy_from_user(&msg, (u8 *)arg, sizeof(msg));
1240+
if (err) {
1241+
dev_err(dev_ctx->priv->dev, "Failed to copy from user: %d\n", err);
1242+
return -EFAULT;
1243+
}
1244+
1245+
err = imx_scu_signed_msg(fp, msg.message, msg.msg_size, &msg.error_code);
1246+
if (err) {
1247+
dev_err(dev_ctx->priv->dev,
1248+
"Failed to send signed message: %d\n",
1249+
err);
1250+
return err;
1251+
}
1252+
1253+
err = copy_to_user((u8 *)arg, &msg, sizeof(msg));
1254+
if (err) {
1255+
dev_err(dev_ctx->priv->dev, "Failed to copy to user: %d\n", err);
1256+
return -EFAULT;
1257+
}
1258+
1259+
return err;
1260+
}
1261+
12311262
/*
12321263
* Copy a buffer of data to/from the user and return the address to use in
12331264
* messages
@@ -1645,6 +1676,10 @@ static long ele_mu_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
16451676
case ELE_MU_IOCTL_GET_TIMER:
16461677
err = ele_mu_ioctl_get_time(dev_ctx, arg);
16471678
break;
1679+
case ELE_MU_IOCTL_SIGNED_MESSAGE:
1680+
if (ele_mu_priv->flags & SCU_SIGNED_MSG_CFG)
1681+
err = ele_mu_ioctl_signed_msg_handler(fp, dev_ctx, arg);
1682+
break;
16481683
default:
16491684
err = -EINVAL;
16501685
dev_dbg(ele_mu_priv->dev,
@@ -1919,6 +1954,7 @@ static int se_fw_probe(struct platform_device *pdev)
19191954
struct imx_info *info = NULL;
19201955
int ret;
19211956
struct device_node *np;
1957+
struct imx_info_list *info_list;
19221958

19231959
info = get_imx_info((struct imx_info_list *)of_id->data,
19241960
pdev->name, strlen(pdev->name) + 1);
@@ -1966,15 +2002,27 @@ static int se_fw_probe(struct platform_device *pdev)
19662002
goto exit;
19672003
}
19682004

2005+
info_list = (struct imx_info_list *)of_id->data;
2006+
19692007
if (info->pre_if_config) {
19702008
/* start initializing ele fw */
19712009
ret = info->pre_if_config(dev);
19722010
if (ret) {
19732011
dev_err(dev, "Failed to initialize scu config.\n");
19742012
priv->flags &= (~SCU_MEM_CFG);
2013+
if ((info_list->soc_id == SOC_ID_OF_IMX8DXL) &&
2014+
((memcmp(info->se_name, "she1", 5)) ||
2015+
(memcmp(info->se_name, "hsm1", 5)))) {
2016+
priv->flags &= (~SCU_SIGNED_MSG_CFG);
2017+
}
19752018
goto exit;
19762019
}
19772020
priv->flags |= SCU_MEM_CFG;
2021+
if ((info_list->soc_id == SOC_ID_OF_IMX8DXL) &&
2022+
((memcmp(info->se_name, "she1", 5)) ||
2023+
(memcmp(info->se_name, "hsm1", 5)))) {
2024+
priv->flags |= SCU_SIGNED_MSG_CFG;
2025+
}
19782026
}
19792027

19802028
/* Initialize the mutex. */

drivers/firmware/imx/seco.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,51 @@ int imx_scu_mem_access(struct file *fp)
344344
return ret;
345345
}
346346
EXPORT_SYMBOL(imx_scu_mem_access);
347+
348+
int imx_scu_signed_msg(struct file *fp,
349+
uint8_t *msg,
350+
uint32_t size,
351+
uint32_t *error)
352+
{
353+
struct ele_mu_device_ctx *dev_ctx
354+
= container_of(fp->private_data,
355+
struct ele_mu_device_ctx,
356+
miscdev);
357+
struct ele_mu_priv *priv = dev_ctx->priv;
358+
struct ele_shared_mem *shared_mem = &dev_ctx->non_secure_mem;
359+
int err;
360+
u64 addr;
361+
u32 pos;
362+
363+
/* Check there is enough space in the shared memory. */
364+
if (size >= shared_mem->size - shared_mem->pos) {
365+
dev_err(dev_ctx->priv->dev,
366+
"Not enough mem: %d left, %d required\n",
367+
shared_mem->size - shared_mem->pos, size);
368+
return -ENOMEM;
369+
}
370+
371+
/* Allocate space in shared memory. 8 bytes aligned. */
372+
pos = shared_mem->pos;
373+
374+
/* get physical address from the pos */
375+
addr = (u64)shared_mem->dma_addr + pos;
376+
377+
/* copy signed message from user space to this allocated buffer */
378+
err = copy_from_user(shared_mem->ptr + pos, msg, size);
379+
if (err) {
380+
dev_err(dev_ctx->priv->dev,
381+
"Failed to signed message from user: %d\n",
382+
err);
383+
return -EFAULT;
384+
}
385+
386+
*error = imx_sc_seco_sab_msg(priv->ipc_scu, addr);
387+
err = *error;
388+
if (err) {
389+
dev_err(dev_ctx->priv->dev, "Failt to send signed message\n");
390+
}
391+
392+
return err;
393+
}
394+
EXPORT_SYMBOL(imx_scu_signed_msg);

include/linux/firmware/imx/ele_mu_ioctl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ struct ele_time_frame {
9191
*/
9292
#define ELE_MU_IOCTL_GET_MU_INFO _IOR(ELE_MU_IOCTL, 0x04, \
9393
struct ele_mu_ioctl_get_mu_info)
94+
95+
/*
96+
* ioctl to send signed message to SE.
97+
*/
98+
#define ELE_MU_IOCTL_SIGNED_MESSAGE _IOR(ELE_MU_IOCTL, 0x05, \
99+
struct ele_mu_ioctl_signed_message)
100+
94101
/*
95102
* ioctl to get SoC Info from user-space.
96103
*/

include/linux/firmware/imx/svc/seco.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ int imx_sc_seco_secvio_dgo_config(struct imx_sc_ipc *ipc, u8 id, u8 access,
4545
int imx_scu_init_fw(struct device *dev);
4646
int imx_scu_sec_mem_cfg(struct file *fp, uint32_t offset, uint32_t size);
4747
int imx_scu_mem_access(struct file *fp);
48+
int imx_scu_signed_msg(struct file *fp, uint8_t *msg, uint32_t size, uint32_t *error);
4849
#else /* IS_ENABLED(CONFIG_IMX_SCU) */
4950
static inline
5051
int imx_sc_seco_build_info(struct imx_sc_ipc *ipc, uint32_t *version,
@@ -92,6 +93,12 @@ int imx_scu_sec_mem_cfg(struct file *fp, uint32_t offset, uint32_t size)
9293
return -EOPNOTSUPP;
9394
}
9495

96+
static inline
97+
int imx_scu_signed_msg(struct file *fp, uint8_t *msg, uint32_t size, uint32_t *error)
98+
{
99+
return -EOPNOTSUPP;
100+
}
101+
95102
static inline
96103
int imx_scu_mem_access(struct file *fp)//device *dev)
97104
{

0 commit comments

Comments
 (0)