diff options
author | Alexey Romanov <avromanov@salutedevices.com> | 2023-09-21 11:13:35 +0300 |
---|---|---|
committer | Neil Armstrong <neil.armstrong@linaro.org> | 2023-10-15 12:23:48 +0200 |
commit | 9ec6db32ca04b41330225d96f44eb6a4d8e97e7e (patch) | |
tree | 9d89c8065e65d7f286172d4d313ede9aedd12396 | |
parent | c52cd07407af6467d68f1ed9dd180fb72bbf0313 (diff) | |
download | u-boot-9ec6db32ca04b41330225d96f44eb6a4d8e97e7e.zip u-boot-9ec6db32ca04b41330225d96f44eb6a4d8e97e7e.tar.gz u-boot-9ec6db32ca04b41330225d96f44eb6a4d8e97e7e.tar.bz2 |
sandbox: add sandbox sm uclass driver
This patch adds sandbox secure monitor driver.
Signed-off-by: Alexey Romanov <avromanov@salutedevices.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Link: https://lore.kernel.org/r/20230921081346.22157-3-avromanov@salutedevices.com
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
-rw-r--r-- | drivers/sm/Makefile | 1 | ||||
-rw-r--r-- | drivers/sm/sandbox-sm.c | 76 | ||||
-rw-r--r-- | include/sandbox-sm.h | 18 |
3 files changed, 95 insertions, 0 deletions
diff --git a/drivers/sm/Makefile b/drivers/sm/Makefile index 9f4683b..af5f475 100644 --- a/drivers/sm/Makefile +++ b/drivers/sm/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-y += sm-uclass.o +obj-$(CONFIG_SANDBOX) += sandbox-sm.o diff --git a/drivers/sm/sandbox-sm.c b/drivers/sm/sandbox-sm.c new file mode 100644 index 0000000..109ddb2 --- /dev/null +++ b/drivers/sm/sandbox-sm.c @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2023 SberDevices, Inc. + * + * Author: Alexey Romanov <avromanov@salutedevices.com> + */ + +#include <common.h> +#include <sm.h> +#include <sm-uclass.h> +#include <sandbox-sm.h> +#include <asm/ptrace.h> +#include <dm/device.h> +#include <linux/sizes.h> + +static u8 test_buffer[SZ_4K]; + +static int sandbox_sm_call(struct udevice *dev, u32 cmd_index, s32 *smc_ret, + struct pt_regs *args) +{ + if (cmd_index >= SANDBOX_SMC_CMD_COUNT) + return -EINVAL; + + if (smc_ret) + *smc_ret = 0; + + return 0; +} + +static int sandbox_sm_call_read(struct udevice *dev, void *buffer, size_t size, + u32 cmd_index, struct pt_regs *args) +{ + if (cmd_index >= SANDBOX_SMC_CMD_COUNT || !buffer) + return -EINVAL; + + if (size > sizeof(test_buffer)) + return -EINVAL; + + memcpy(buffer, test_buffer, size); + + return size; +} + +static int sandbox_sm_call_write(struct udevice *dev, void *buffer, size_t size, + u32 cmd_index, struct pt_regs *args) +{ + if (cmd_index >= SANDBOX_SMC_CMD_COUNT || !buffer) + return -EINVAL; + + if (size > sizeof(test_buffer)) + return -EINVAL; + + memcpy(test_buffer, buffer, size); + + return size; +} + +static const struct udevice_id sandbox_sm_ids[] = { + { + .compatible = "sandbox,sm", + }, + {}, +}; + +static const struct sm_ops sandbox_sm_ops = { + .sm_call = sandbox_sm_call, + .sm_call_read = sandbox_sm_call_read, + .sm_call_write = sandbox_sm_call_write, +}; + +U_BOOT_DRIVER(sm) = { + .name = "sm", + .id = UCLASS_SM, + .of_match = sandbox_sm_ids, + .ops = &sandbox_sm_ops, +}; diff --git a/include/sandbox-sm.h b/include/sandbox-sm.h new file mode 100644 index 0000000..91c30d5 --- /dev/null +++ b/include/sandbox-sm.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2023 SberDevices, Inc. + * + * Author: Alexey Romanov <avromanov@salutedevices.com> + */ + +#ifndef __SANDBOX_SM_H__ +#define __SANDBOX_SM_H__ + +enum sandbox_smc_cmd { + SANDBOX_SMC_CMD_READ_MEM, + SANDBOX_SMC_CMD_WRITE_MEM, + SANDBOX_SMC_CMD_COMMON, + SANDBOX_SMC_CMD_COUNT, +}; + +#endif |