Alexey Romanov | f6c19e1 | 2023-09-21 11:13:37 +0300 | [diff] [blame] | 1 | // 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 | |
| 18 | static 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, ®s); |
| 30 | ut_asserteq(ret, -EINVAL); |
| 31 | |
| 32 | ret = sm_call(dev, SANDBOX_SMC_CMD_COMMON, &val, ®s); |
| 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, ®s); |
| 38 | ut_asserteq(ret, -EINVAL); |
| 39 | |
| 40 | ret = sm_call_write(dev, buffer, SZ_4K + 1, |
| 41 | SANDBOX_SMC_CMD_WRITE_MEM, ®s); |
| 42 | ut_asserteq(ret, -EINVAL); |
| 43 | |
| 44 | ret = sm_call_write(dev, buffer, sizeof(buffer), |
| 45 | SANDBOX_SMC_CMD_COUNT, ®s); |
| 46 | ut_asserteq(ret, -EINVAL); |
| 47 | |
| 48 | ret = sm_call_write(dev, buffer, SZ_4K + 1, |
| 49 | SANDBOX_SMC_CMD_READ_MEM, ®s); |
| 50 | ut_asserteq(ret, -EINVAL); |
| 51 | |
| 52 | ret = sm_call_write(dev, test_string, sizeof(test_string), |
| 53 | SANDBOX_SMC_CMD_WRITE_MEM, ®s); |
| 54 | ut_asserteq(ret, sizeof(test_string)); |
| 55 | |
| 56 | ret = sm_call_read(dev, buffer, sizeof(buffer), |
| 57 | SANDBOX_SMC_CMD_READ_MEM, ®s); |
| 58 | ut_asserteq(ret, sizeof(buffer)); |
| 59 | |
| 60 | ut_asserteq_str(buffer, test_string); |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | DM_TEST(dm_test_sm, UT_TESTF_SCAN_FDT); |