summaryrefslogtreecommitdiffstats
path: root/drivers/trusty/trusty-otf-iface.c
blob: 4eeb9801686cf62e6f53df7adf4869eee598c454 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * Copyright (c) 2017-2018 NVIDIA Corporation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
  */

#include <linux/err.h>
#include <linux/trusty/trusty.h>
#include <linux/trusty/trusty_ipc.h>
#include <linux/ote_protocol.h>

#define OTF_PORT_NAME		"com.nvidia.tos.74629d40-1378-4d17-94d0e0af5d861d88"
#define OTF_REPROGRAM_KEYS	5

void trusty_restore_keyslots(void)
{
	void *opaque_channel_context = NULL;
	int ret = 0;

	/* Return if Trusty Device is not enabled */
	if (!is_trusty_dev_enabled())
		return;

	ret = te_open_trusted_session(OTF_PORT_NAME, &opaque_channel_context);

	/* Return if this Trusty port or TA is not supported without pr_err */
	if (ret == -EOPNOTSUPP)
		return;
	else if (ret) {
		pr_err("%s:ERROR(%d): Failed to open trusted session\n",
			__func__, ret);
		return;
	}

	ret = te_launch_trusted_oper(NULL, 0U, OTF_REPROGRAM_KEYS,
					opaque_channel_context);
	if (ret) {
		pr_err("%s:ERROR(%d): Failed to launch operation\n",
			__func__, ret);
		/* Fall Through */
	}

	te_close_trusted_session(opaque_channel_context);
}
EXPORT_SYMBOL(trusty_restore_keyslots);