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