blob: a95e685494c27d53bed730909488500d05685350 [file] [log] [blame]
Alexey Romanov237cfea2023-09-21 11:13:35 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (c) 2023 SberDevices, Inc.
4 *
5 * Author: Alexey Romanov <avromanov@salutedevices.com>
6 */
7
Alexey Romanov237cfea2023-09-21 11:13:35 +03008#include <sm.h>
9#include <sm-uclass.h>
10#include <sandbox-sm.h>
11#include <asm/ptrace.h>
12#include <dm/device.h>
13#include <linux/sizes.h>
14
15static u8 test_buffer[SZ_4K];
16
17static int sandbox_sm_call(struct udevice *dev, u32 cmd_index, s32 *smc_ret,
18 struct pt_regs *args)
19{
20 if (cmd_index >= SANDBOX_SMC_CMD_COUNT)
21 return -EINVAL;
22
23 if (smc_ret)
24 *smc_ret = 0;
25
26 return 0;
27}
28
29static int sandbox_sm_call_read(struct udevice *dev, void *buffer, size_t size,
30 u32 cmd_index, struct pt_regs *args)
31{
32 if (cmd_index >= SANDBOX_SMC_CMD_COUNT || !buffer)
33 return -EINVAL;
34
35 if (size > sizeof(test_buffer))
36 return -EINVAL;
37
38 memcpy(buffer, test_buffer, size);
39
40 return size;
41}
42
43static int sandbox_sm_call_write(struct udevice *dev, void *buffer, size_t size,
44 u32 cmd_index, struct pt_regs *args)
45{
46 if (cmd_index >= SANDBOX_SMC_CMD_COUNT || !buffer)
47 return -EINVAL;
48
49 if (size > sizeof(test_buffer))
50 return -EINVAL;
51
52 memcpy(test_buffer, buffer, size);
53
54 return size;
55}
56
57static const struct udevice_id sandbox_sm_ids[] = {
58 {
59 .compatible = "sandbox,sm",
60 },
61 {},
62};
63
64static const struct sm_ops sandbox_sm_ops = {
65 .sm_call = sandbox_sm_call,
66 .sm_call_read = sandbox_sm_call_read,
67 .sm_call_write = sandbox_sm_call_write,
68};
69
70U_BOOT_DRIVER(sm) = {
71 .name = "sm",
72 .id = UCLASS_SM,
73 .of_match = sandbox_sm_ids,
74 .ops = &sandbox_sm_ops,
75};