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