1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2021, Foundries.IO
4  *
5  */
6 
7 #include <common.h>
8 #include <scp03.h>
9 #include <tee.h>
10 #include <tee/optee_ta_scp03.h>
11 
scp03_enable(bool provision)12 static int scp03_enable(bool provision)
13 {
14 	const struct tee_optee_ta_uuid uuid = PTA_SCP03_UUID;
15 	struct tee_open_session_arg session;
16 	struct tee_invoke_arg invoke;
17 	struct tee_param param;
18 	struct udevice *tee = NULL;
19 
20 	tee = tee_find_device(tee, NULL, NULL, NULL);
21 	if (!tee)
22 		return -ENODEV;
23 
24 	memset(&session, 0, sizeof(session));
25 	tee_optee_ta_uuid_to_octets(session.uuid, &uuid);
26 	if (tee_open_session(tee, &session, 0, NULL))
27 		return -ENXIO;
28 
29 	memset(&param, 0, sizeof(param));
30 	param.attr = TEE_PARAM_ATTR_TYPE_VALUE_INPUT;
31 	param.u.value.a = provision;
32 
33 	memset(&invoke, 0, sizeof(invoke));
34 	invoke.func = PTA_CMD_ENABLE_SCP03;
35 	invoke.session = session.session;
36 
37 	if (tee_invoke_func(tee, &invoke, 1, &param))
38 		return -EIO;
39 
40 	tee_close_session(tee, session.session);
41 
42 	return 0;
43 }
44 
tee_enable_scp03(void)45 int tee_enable_scp03(void)
46 {
47 	return scp03_enable(false);
48 }
49 
tee_provision_scp03(void)50 int tee_provision_scp03(void)
51 {
52 	return scp03_enable(true);
53 }
54