aboutsummaryrefslogtreecommitdiff
path: root/drivers/sm/sandbox-sm.c
blob: 109ddb2af55768223e18a31bc2cb50f026d120ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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,
};