1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Linaro Limited
10 #include <sandboxtee.h>
13 #include <tee/optee_ta_avb.h>
15 static int open_session(struct udevice *dev, u32 *session)
17 struct tee_open_session_arg arg;
18 const struct tee_optee_ta_uuid uuid = TA_AVB_UUID;
21 memset(&arg, 0, sizeof(arg));
22 tee_optee_ta_uuid_to_octets(arg.uuid, &uuid);
23 rc = tee_open_session(dev, &arg, 0, NULL);
28 *session = arg.session;
33 static int invoke_func(struct udevice *dev, u32 session)
35 struct tee_param param = { .attr = TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT };
36 struct tee_invoke_arg arg;
38 memset(&arg, 0, sizeof(arg));
39 arg.session = session;
40 arg.func = TA_AVB_CMD_READ_LOCK_STATE;
42 if (tee_invoke_func(dev, &arg, 1, ¶m) || arg.ret)
48 static int match(struct tee_version_data *vers, const void *data)
50 return vers->gen_caps & TEE_GEN_CAP_GP;
53 struct test_tee_vars {
54 struct tee_shm *reg_shm;
55 struct tee_shm *alloc_shm;
58 static int test_tee(struct unit_test_state *uts, struct test_tee_vars *vars)
60 struct tee_version_data vers;
62 struct sandbox_tee_state *state;
67 dev = tee_find_device(NULL, match, NULL, &vers);
69 state = dev_get_priv(dev);
70 ut_assert(!state->session);
72 rc = open_session(dev, &session);
74 ut_assert(session == state->session);
76 rc = invoke_func(dev, session);
79 rc = tee_close_session(dev, session);
81 ut_assert(!state->session);
83 ut_assert(!state->num_shms);
84 rc = tee_shm_register(dev, data, sizeof(data), 0, &vars->reg_shm);
86 ut_assert(state->num_shms == 1);
88 rc = tee_shm_alloc(dev, 256, 0, &vars->alloc_shm);
90 ut_assert(state->num_shms == 2);
92 ut_assert(tee_shm_is_registered(vars->reg_shm, dev));
93 ut_assert(tee_shm_is_registered(vars->alloc_shm, dev));
95 tee_shm_free(vars->reg_shm);
97 tee_shm_free(vars->alloc_shm);
98 vars->alloc_shm = NULL;
99 ut_assert(!state->num_shms);
104 static int dm_test_tee(struct unit_test_state *uts)
106 struct test_tee_vars vars = { NULL, NULL };
107 int rc = test_tee(uts, &vars);
109 /* In case test_tee() asserts these may still remain allocated */
110 tee_shm_free(vars.reg_shm);
111 tee_shm_free(vars.alloc_shm);
116 DM_TEST(dm_test_tee, DM_TESTF_SCAN_FDT);