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