blob: 952b87ca319b5701b46bef6ad5a6a9a17391462f [file] [log] [blame]
Sathish Ambley69e1ab02016-10-18 10:28:15 -07001/*
Tharun Kumar Merugu35a94a52018-02-01 21:09:04 +05302 * Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
Sathish Ambley69e1ab02016-10-18 10:28:15 -07003 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 */
14#ifndef ADSPRPC_SHARED_H
15#define ADSPRPC_SHARED_H
16
17#include <linux/types.h>
18
19#define FASTRPC_IOCTL_INVOKE _IOWR('R', 1, struct fastrpc_ioctl_invoke)
20#define FASTRPC_IOCTL_MMAP _IOWR('R', 2, struct fastrpc_ioctl_mmap)
21#define FASTRPC_IOCTL_MUNMAP _IOWR('R', 3, struct fastrpc_ioctl_munmap)
Tharun Kumar Merugu55be90d2018-05-31 11:41:03 +053022#define FASTRPC_IOCTL_MMAP_64 _IOWR('R', 14, struct fastrpc_ioctl_mmap_64)
23#define FASTRPC_IOCTL_MUNMAP_64 _IOWR('R', 15, struct fastrpc_ioctl_munmap_64)
Sathish Ambley69e1ab02016-10-18 10:28:15 -070024#define FASTRPC_IOCTL_INVOKE_FD _IOWR('R', 4, struct fastrpc_ioctl_invoke_fd)
25#define FASTRPC_IOCTL_SETMODE _IOWR('R', 5, uint32_t)
26#define FASTRPC_IOCTL_INIT _IOWR('R', 6, struct fastrpc_ioctl_init)
27#define FASTRPC_IOCTL_INVOKE_ATTRS \
28 _IOWR('R', 7, struct fastrpc_ioctl_invoke_attrs)
29#define FASTRPC_IOCTL_GETINFO _IOWR('R', 8, uint32_t)
Sathish Ambleya21b5b52017-01-11 16:11:01 -080030#define FASTRPC_IOCTL_GETPERF _IOWR('R', 9, struct fastrpc_ioctl_perf)
Sathish Ambleyd6300c32017-01-18 09:50:43 -080031#define FASTRPC_IOCTL_INIT_ATTRS _IOWR('R', 10, struct fastrpc_ioctl_init_attrs)
Sathish Ambleybae51902017-07-03 15:00:49 -070032#define FASTRPC_IOCTL_INVOKE_CRC _IOWR('R', 11, struct fastrpc_ioctl_invoke_crc)
Tharun Kumar Merugu5f6ca61c2017-08-11 11:43:11 +053033#define FASTRPC_IOCTL_CONTROL _IOWR('R', 12, struct fastrpc_ioctl_control)
c_mtharu7bd6a422017-10-17 18:15:37 +053034#define FASTRPC_IOCTL_MUNMAP_FD _IOWR('R', 13, struct fastrpc_ioctl_munmap_fd)
Sathish Ambley69e1ab02016-10-18 10:28:15 -070035
36#define FASTRPC_GLINK_GUID "fastrpcglink-apps-dsp"
37#define FASTRPC_SMD_GUID "fastrpcsmd-apps-dsp"
38#define DEVICE_NAME "adsprpc-smd"
39
40/* Set for buffers that have no virtual mapping in userspace */
41#define FASTRPC_ATTR_NOVA 0x1
42
Tharun Kumar Merugu2e5f12e2017-07-06 12:04:40 +053043/* Set for buffers that are NOT dma coherent */
44#define FASTRPC_ATTR_NON_COHERENT 0x2
45
46/* Set for buffers that are dma coherent */
47#define FASTRPC_ATTR_COHERENT 0x4
48
c_mtharu7bd6a422017-10-17 18:15:37 +053049/* Fastrpc attribute for keeping the map persistent */
50#define FASTRPC_ATTR_KEEP_MAP 0x8
51
Tharun Kumar Merugu35a94a52018-02-01 21:09:04 +053052/* Fastrpc attribute for no map */
53#define FASTRPC_ATTR_NOMAP (16)
54
Sathish Ambley69e1ab02016-10-18 10:28:15 -070055/* Driver should operate in parallel with the co-processor */
56#define FASTRPC_MODE_PARALLEL 0
57
58/* Driver should operate in serial mode with the co-processor */
59#define FASTRPC_MODE_SERIAL 1
60
Sathish Ambleya21b5b52017-01-11 16:11:01 -080061/* Driver should operate in profile mode with the co-processor */
62#define FASTRPC_MODE_PROFILE 2
63
Tharun Kumar Merugud4d079482017-09-06 11:22:19 +053064/* Set FastRPC session ID to 1 */
65#define FASTRPC_MODE_SESSION 4
66
Sathish Ambley69e1ab02016-10-18 10:28:15 -070067/* INIT a new process or attach to guestos */
68#define FASTRPC_INIT_ATTACH 0
69#define FASTRPC_INIT_CREATE 1
c_mtharue1a5ce12017-10-13 20:47:09 +053070#define FASTRPC_INIT_CREATE_STATIC 2
Tharun Kumar Merugu848c0952018-02-07 21:37:19 +053071#define FASTRPC_INIT_ATTACH_SENSORS 3
Sathish Ambley69e1ab02016-10-18 10:28:15 -070072
73/* Retrives number of input buffers from the scalars parameter */
74#define REMOTE_SCALARS_INBUFS(sc) (((sc) >> 16) & 0x0ff)
75
76/* Retrives number of output buffers from the scalars parameter */
77#define REMOTE_SCALARS_OUTBUFS(sc) (((sc) >> 8) & 0x0ff)
78
79/* Retrives number of input handles from the scalars parameter */
80#define REMOTE_SCALARS_INHANDLES(sc) (((sc) >> 4) & 0x0f)
81
82/* Retrives number of output handles from the scalars parameter */
83#define REMOTE_SCALARS_OUTHANDLES(sc) ((sc) & 0x0f)
84
85#define REMOTE_SCALARS_LENGTH(sc) (REMOTE_SCALARS_INBUFS(sc) +\
86 REMOTE_SCALARS_OUTBUFS(sc) +\
87 REMOTE_SCALARS_INHANDLES(sc) +\
88 REMOTE_SCALARS_OUTHANDLES(sc))
89
90#define REMOTE_SCALARS_MAKEX(attr, method, in, out, oin, oout) \
91 ((((uint32_t) (attr) & 0x7) << 29) | \
92 (((uint32_t) (method) & 0x1f) << 24) | \
93 (((uint32_t) (in) & 0xff) << 16) | \
94 (((uint32_t) (out) & 0xff) << 8) | \
95 (((uint32_t) (oin) & 0x0f) << 4) | \
96 ((uint32_t) (oout) & 0x0f))
97
98#define REMOTE_SCALARS_MAKE(method, in, out) \
99 REMOTE_SCALARS_MAKEX(0, method, in, out, 0, 0)
100
101
102#ifndef VERIFY_PRINT_ERROR
103#define VERIFY_EPRINTF(format, args) (void)0
104#endif
105
106#ifndef VERIFY_PRINT_INFO
107#define VERIFY_IPRINTF(args) (void)0
108#endif
109
110#ifndef VERIFY
111#define __STR__(x) #x ":"
112#define __TOSTR__(x) __STR__(x)
113#define __FILE_LINE__ __FILE__ ":" __TOSTR__(__LINE__)
114
115#define VERIFY(err, val) \
116do {\
117 VERIFY_IPRINTF(__FILE_LINE__"info: calling: " #val "\n");\
Tharun Kumar Merugue3edf3e2017-07-27 12:34:07 +0530118 if ((val) == 0) {\
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700119 (err) = (err) == 0 ? -1 : (err);\
120 VERIFY_EPRINTF(__FILE_LINE__"error: %d: " #val "\n", (err));\
121 } else {\
122 VERIFY_IPRINTF(__FILE_LINE__"info: passed: " #val "\n");\
123 } \
124} while (0)
125#endif
126
127#define remote_arg64_t union remote_arg64
128
129struct remote_buf64 {
130 uint64_t pv;
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530131 uint64_t len;
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700132};
133
Sathish Ambley58dc64d2016-11-29 17:11:53 -0800134struct remote_dma_handle64 {
135 int fd;
136 uint32_t offset;
137 uint32_t len;
138};
139
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700140union remote_arg64 {
141 struct remote_buf64 buf;
Sathish Ambley58dc64d2016-11-29 17:11:53 -0800142 struct remote_dma_handle64 dma;
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700143 uint32_t h;
144};
145
146#define remote_arg_t union remote_arg
147
148struct remote_buf {
149 void *pv; /* buffer pointer */
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530150 size_t len; /* length of buffer */
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700151};
152
Sathish Ambley58dc64d2016-11-29 17:11:53 -0800153struct remote_dma_handle {
154 int fd;
155 uint32_t offset;
156};
157
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700158union remote_arg {
159 struct remote_buf buf; /* buffer info */
Sathish Ambley58dc64d2016-11-29 17:11:53 -0800160 struct remote_dma_handle dma;
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700161 uint32_t h; /* remote handle */
162};
163
164struct fastrpc_ioctl_invoke {
165 uint32_t handle; /* remote handle */
166 uint32_t sc; /* scalars describing the data */
167 remote_arg_t *pra; /* remote arguments list */
168};
169
170struct fastrpc_ioctl_invoke_fd {
171 struct fastrpc_ioctl_invoke inv;
172 int *fds; /* fd list */
173};
174
175struct fastrpc_ioctl_invoke_attrs {
176 struct fastrpc_ioctl_invoke inv;
177 int *fds; /* fd list */
178 unsigned int *attrs; /* attribute list */
179};
180
Sathish Ambleybae51902017-07-03 15:00:49 -0700181struct fastrpc_ioctl_invoke_crc {
182 struct fastrpc_ioctl_invoke inv;
183 int *fds; /* fd list */
184 unsigned int *attrs; /* attribute list */
185 unsigned int *crc;
186};
187
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700188struct fastrpc_ioctl_init {
189 uint32_t flags; /* one of FASTRPC_INIT_* macros */
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530190 uintptr_t file; /* pointer to elf file */
191 uint32_t filelen; /* elf file length */
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700192 int32_t filefd; /* ION fd for the file */
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530193 uintptr_t mem; /* mem for the PD */
194 uint32_t memlen; /* mem length */
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700195 int32_t memfd; /* ION fd for the mem */
196};
197
Sathish Ambleyd6300c32017-01-18 09:50:43 -0800198struct fastrpc_ioctl_init_attrs {
199 struct fastrpc_ioctl_init init;
200 int attrs;
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530201 unsigned int siglen;
Sathish Ambleyd6300c32017-01-18 09:50:43 -0800202};
203
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700204struct fastrpc_ioctl_munmap {
Tharun Kumar Merugu6c7d37d2018-04-18 12:14:22 +0530205 uintptr_t vaddrout; /* address to unmap */
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530206 size_t size; /* size */
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700207};
208
Tharun Kumar Merugu55be90d2018-05-31 11:41:03 +0530209struct fastrpc_ioctl_munmap_64 {
210 uint64_t vaddrout; /* address to unmap */
211 size_t size; /* size */
212};
213
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700214struct fastrpc_ioctl_mmap {
215 int fd; /* ion fd */
216 uint32_t flags; /* flags for dsp to map with */
Tharun Kumar Merugu6c7d37d2018-04-18 12:14:22 +0530217 uintptr_t vaddrin; /* optional virtual address */
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530218 size_t size; /* size */
Tharun Kumar Merugu6c7d37d2018-04-18 12:14:22 +0530219 uintptr_t vaddrout; /* dsps virtual address */
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700220};
221
Tharun Kumar Merugu55be90d2018-05-31 11:41:03 +0530222struct fastrpc_ioctl_mmap_64 {
223 int fd; /* ion fd */
224 uint32_t flags; /* flags for dsp to map with */
225 uint64_t vaddrin; /* optional virtual address */
226 size_t size; /* size */
227 uint64_t vaddrout; /* dsps virtual address */
228};
229
c_mtharu7bd6a422017-10-17 18:15:37 +0530230struct fastrpc_ioctl_munmap_fd {
231 int fd; /* fd */
232 uint32_t flags; /* control flags */
233 uintptr_t va; /* va */
234 ssize_t len; /* length */
235};
236
Sathish Ambleya21b5b52017-01-11 16:11:01 -0800237struct fastrpc_ioctl_perf { /* kernel performance data */
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530238 uintptr_t data;
Sathish Ambleya21b5b52017-01-11 16:11:01 -0800239 uint32_t numkeys;
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530240 uintptr_t keys;
Sathish Ambleya21b5b52017-01-11 16:11:01 -0800241};
242
Tharun Kumar Merugu5f6ca61c2017-08-11 11:43:11 +0530243#define FASTRPC_CONTROL_LATENCY (1)
244struct fastrpc_ctrl_latency {
245 uint32_t enable; //!latency control enable
246 uint32_t level; //!level of control
247};
Tharun Kumar Merugu848c0952018-02-07 21:37:19 +0530248#define FASTRPC_CONTROL_SMMU (2)
249struct fastrpc_ctrl_smmu {
250 uint32_t sharedcb;
251};
Tharun Kumar Merugu5f6ca61c2017-08-11 11:43:11 +0530252struct fastrpc_ioctl_control {
253 uint32_t req;
254 union {
255 struct fastrpc_ctrl_latency lp;
Tharun Kumar Merugu848c0952018-02-07 21:37:19 +0530256 struct fastrpc_ctrl_smmu smmu;
Tharun Kumar Merugu5f6ca61c2017-08-11 11:43:11 +0530257 };
258};
259
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700260struct smq_null_invoke {
261 uint64_t ctx; /* invoke caller context */
262 uint32_t handle; /* handle to invoke */
263 uint32_t sc; /* scalars structure describing the data */
264};
265
266struct smq_phy_page {
267 uint64_t addr; /* physical address */
268 uint64_t size; /* size of contiguous region */
269};
270
271struct smq_invoke_buf {
272 int num; /* number of contiguous regions */
273 int pgidx; /* index to start of contiguous region */
274};
275
276struct smq_invoke {
277 struct smq_null_invoke header;
278 struct smq_phy_page page; /* remote arg and list of pages address */
279};
280
281struct smq_msg {
282 uint32_t pid; /* process group id */
283 uint32_t tid; /* thread id */
284 struct smq_invoke invoke;
285};
286
287struct smq_invoke_rsp {
288 uint64_t ctx; /* invoke caller context */
289 int retval; /* invoke return value */
290};
291
292static inline struct smq_invoke_buf *smq_invoke_buf_start(remote_arg64_t *pra,
293 uint32_t sc)
294{
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530295 unsigned int len = REMOTE_SCALARS_LENGTH(sc);
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700296
297 return (struct smq_invoke_buf *)(&pra[len]);
298}
299
300static inline struct smq_phy_page *smq_phy_page_start(uint32_t sc,
301 struct smq_invoke_buf *buf)
302{
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530303 unsigned int nTotal = REMOTE_SCALARS_LENGTH(sc);
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700304
305 return (struct smq_phy_page *)(&buf[nTotal]);
306}
307
308#endif