blob: 4d95c2ad75bd578e7242eed62c69a8d5487a0d6f [file] [log] [blame]
Alexey Romanovf6c19e12023-09-21 11:13:37 +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 Romanovf6c19e12023-09-21 11:13:37 +03008#include <dm.h>
9#include <sm.h>
10#include <sandbox-sm.h>
11#include <asm/ptrace.h>
12#include <dm/device-internal.h>
13#include <dm/test.h>
14#include <test/ut.h>
15#include <linux/sizes.h>
16
17static int dm_test_sm(struct unit_test_state *uts)
18{
19 struct udevice *dev;
20 struct pt_regs regs;
21 char buffer[128] = { 0 };
22 char test_string[] = "secure-monitor";
23 int ret, val;
24
25 ut_assertok(uclass_get_device_by_name(UCLASS_SM,
26 "secure-monitor", &dev));
27
28 ret = sm_call(dev, SANDBOX_SMC_CMD_COUNT, NULL, &regs);
29 ut_asserteq(ret, -EINVAL);
30
31 ret = sm_call(dev, SANDBOX_SMC_CMD_COMMON, &val, &regs);
32 ut_asserteq(ret, 0);
33 ut_asserteq(val, 0);
34
35 ret = sm_call_write(dev, buffer, sizeof(buffer),
36 SANDBOX_SMC_CMD_COUNT, &regs);
37 ut_asserteq(ret, -EINVAL);
38
39 ret = sm_call_write(dev, buffer, SZ_4K + 1,
40 SANDBOX_SMC_CMD_WRITE_MEM, &regs);
41 ut_asserteq(ret, -EINVAL);
42
43 ret = sm_call_write(dev, buffer, sizeof(buffer),
44 SANDBOX_SMC_CMD_COUNT, &regs);
45 ut_asserteq(ret, -EINVAL);
46
47 ret = sm_call_write(dev, buffer, SZ_4K + 1,
48 SANDBOX_SMC_CMD_READ_MEM, &regs);
49 ut_asserteq(ret, -EINVAL);
50
51 ret = sm_call_write(dev, test_string, sizeof(test_string),
52 SANDBOX_SMC_CMD_WRITE_MEM, &regs);
53 ut_asserteq(ret, sizeof(test_string));
54
55 ret = sm_call_read(dev, buffer, sizeof(buffer),
56 SANDBOX_SMC_CMD_READ_MEM, &regs);
57 ut_asserteq(ret, sizeof(buffer));
58
59 ut_asserteq_str(buffer, test_string);
60
61 return 0;
62}
63
64DM_TEST(dm_test_sm, UT_TESTF_SCAN_FDT);