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