summaryrefslogtreecommitdiffstats
path: root/include/linux/trusty/trusty_ipc.h
blob: e76e252e45335d40c7cd563234b111575bd50e52 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * Copyright (C) 2015 Google, Inc.
 * Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * 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.
 *
 */
#ifndef __LINUX_TRUSTY_TRUSTY_IPC_H
#define __LINUX_TRUSTY_TRUSTY_IPC_H

/*
 * Errnos below must be in sync with the corresponding errnos
 * defined in 3rdparty/trusty/external/lk/include/err.h
 */
#define NO_ERROR                (0)
#define ERR_NOT_FOUND           (-2)

struct tipc_chan;

struct tipc_msg_buf {
	void *buf_va;
	phys_addr_t buf_pa;
	size_t buf_sz;
	size_t wpos;
	size_t rpos;
	struct list_head node;
};

enum tipc_chan_event {
	TIPC_CHANNEL_CONNECTED = 1,
	TIPC_CHANNEL_DISCONNECTED,
	TIPC_CHANNEL_SHUTDOWN,
	TIPC_CHANNEL_NOT_FOUND,
};

struct tipc_chan_ops {
	void (*handle_event)(void *cb_arg, int event);
	struct tipc_msg_buf *(*handle_msg)(void *cb_arg,
					   struct tipc_msg_buf *mb);
	void (*handle_release)(void *cb_arg);
};

struct tipc_chan *tipc_create_channel(struct device *dev,
				      const struct tipc_chan_ops *ops,
				      void *cb_arg);

int tipc_chan_connect(struct tipc_chan *chan, const char *port);

int tipc_chan_queue_msg(struct tipc_chan *chan, struct tipc_msg_buf *mb);

int tipc_chan_shutdown(struct tipc_chan *chan);

void tipc_chan_destroy(struct tipc_chan *chan);

struct tipc_msg_buf *tipc_chan_get_rxbuf(struct tipc_chan *chan);

void tipc_chan_put_rxbuf(struct tipc_chan *chan, struct tipc_msg_buf *mb);

struct tipc_msg_buf *
tipc_chan_get_txbuf_timeout(struct tipc_chan *chan, long timeout);

void tipc_chan_put_txbuf(struct tipc_chan *chan, struct tipc_msg_buf *mb);

static inline size_t mb_avail_space(struct tipc_msg_buf *mb)
{
	return mb->buf_sz - mb->wpos;
}

static inline size_t mb_avail_data(struct tipc_msg_buf *mb)
{
	return mb->wpos - mb->rpos;
}

static inline void *mb_put_data(struct tipc_msg_buf *mb, size_t len)
{
	void *pos = (u8 *)mb->buf_va + mb->wpos;
	BUG_ON(mb->wpos + len > mb->buf_sz);
	mb->wpos += len;
	return pos;
}

static inline void *mb_get_data(struct tipc_msg_buf *mb, size_t len)
{
	void *pos = (u8 *)mb->buf_va + mb->rpos;
	BUG_ON(mb->rpos + len > mb->wpos);
	mb->rpos += len;
	return pos;
}

/* OTE-TIPC wrapper APIs*/
/*
 * te_open_trusted_session - Establishes the session with TA
 * @name(in): name of the TA to connect to.
 * @ctx(out): pointer to the private data associated to the open session
 * Returns 0 on Success else error code.
 */
int te_open_trusted_session(char *name, void **ctx);
/*
 * te_close_trusted_session - Closes the session established
 * @ctx: ctx returned by open session
 */
void te_close_trusted_session(void *ctx);
/*
 * te_launch_trusted_oper - Communicate with TA to perform any operation
 * @buf: Buffer to sent to secure world.
 * @buf_len: length of the buffer.
 * @ta_cmd: command to sent to secure world.
 * @ctx: ctx returned by open session.
 * Returns 0 on Success else error code.
 */
int te_launch_trusted_oper(void *buf, size_t buf_len, uint32_t ta_cmd,
		void *ctx);

#endif /* __LINUX_TRUSTY_TRUSTY_IPC_H */