Jorge Ramirez-Ortiz | 9127d8b | 2021-02-14 16:27:23 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2021, Foundries.IO |
| 4 | * |
| 5 | */ |
| 6 | |
Jorge Ramirez-Ortiz | 9127d8b | 2021-02-14 16:27:23 +0100 | [diff] [blame] | 7 | #include <scp03.h> |
| 8 | #include <tee.h> |
| 9 | #include <tee/optee_ta_scp03.h> |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 10 | #include <linux/errno.h> |
| 11 | #include <linux/string.h> |
Jorge Ramirez-Ortiz | 9127d8b | 2021-02-14 16:27:23 +0100 | [diff] [blame] | 12 | |
| 13 | static 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(¶m, 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, ¶m)) |
| 39 | return -EIO; |
| 40 | |
| 41 | tee_close_session(tee, session.session); |
| 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | int tee_enable_scp03(void) |
| 47 | { |
| 48 | return scp03_enable(false); |
| 49 | } |
| 50 | |
| 51 | int tee_provision_scp03(void) |
| 52 | { |
| 53 | return scp03_enable(true); |
| 54 | } |