blob: 24fad7664204bec6083e393450139f569ca72603 [file] [log] [blame]
Sathish Ambley69e1ab02016-10-18 10:28:15 -07001/*
Mohammed Nayeem Ur Rahman80162f92019-09-23 19:35:19 +05302 * Copyright (c) 2012-2019, 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"
Tharun Kumar Merugud996b262018-07-18 22:28:53 +053039#define DEVICE_NAME_SECURE "adsprpc-smd-secure"
Sathish Ambley69e1ab02016-10-18 10:28:15 -070040
41/* Set for buffers that have no virtual mapping in userspace */
42#define FASTRPC_ATTR_NOVA 0x1
43
Tharun Kumar Merugu2e5f12e2017-07-06 12:04:40 +053044/* Set for buffers that are NOT dma coherent */
45#define FASTRPC_ATTR_NON_COHERENT 0x2
46
47/* Set for buffers that are dma coherent */
48#define FASTRPC_ATTR_COHERENT 0x4
49
c_mtharu7bd6a422017-10-17 18:15:37 +053050/* Fastrpc attribute for keeping the map persistent */
51#define FASTRPC_ATTR_KEEP_MAP 0x8
52
Tharun Kumar Merugu35a94a52018-02-01 21:09:04 +053053/* Fastrpc attribute for no map */
54#define FASTRPC_ATTR_NOMAP (16)
55
Sathish Ambley69e1ab02016-10-18 10:28:15 -070056/* Driver should operate in parallel with the co-processor */
57#define FASTRPC_MODE_PARALLEL 0
58
59/* Driver should operate in serial mode with the co-processor */
60#define FASTRPC_MODE_SERIAL 1
61
Sathish Ambleya21b5b52017-01-11 16:11:01 -080062/* Driver should operate in profile mode with the co-processor */
63#define FASTRPC_MODE_PROFILE 2
64
Tharun Kumar Merugud4d079482017-09-06 11:22:19 +053065/* Set FastRPC session ID to 1 */
66#define FASTRPC_MODE_SESSION 4
67
Sathish Ambley69e1ab02016-10-18 10:28:15 -070068/* INIT a new process or attach to guestos */
69#define FASTRPC_INIT_ATTACH 0
70#define FASTRPC_INIT_CREATE 1
c_mtharue1a5ce12017-10-13 20:47:09 +053071#define FASTRPC_INIT_CREATE_STATIC 2
Tharun Kumar Merugu848c0952018-02-07 21:37:19 +053072#define FASTRPC_INIT_ATTACH_SENSORS 3
Sathish Ambley69e1ab02016-10-18 10:28:15 -070073
74/* Retrives number of input buffers from the scalars parameter */
75#define REMOTE_SCALARS_INBUFS(sc) (((sc) >> 16) & 0x0ff)
76
77/* Retrives number of output buffers from the scalars parameter */
78#define REMOTE_SCALARS_OUTBUFS(sc) (((sc) >> 8) & 0x0ff)
79
80/* Retrives number of input handles from the scalars parameter */
81#define REMOTE_SCALARS_INHANDLES(sc) (((sc) >> 4) & 0x0f)
82
83/* Retrives number of output handles from the scalars parameter */
84#define REMOTE_SCALARS_OUTHANDLES(sc) ((sc) & 0x0f)
85
86#define REMOTE_SCALARS_LENGTH(sc) (REMOTE_SCALARS_INBUFS(sc) +\
87 REMOTE_SCALARS_OUTBUFS(sc) +\
88 REMOTE_SCALARS_INHANDLES(sc) +\
89 REMOTE_SCALARS_OUTHANDLES(sc))
90
91#define REMOTE_SCALARS_MAKEX(attr, method, in, out, oin, oout) \
92 ((((uint32_t) (attr) & 0x7) << 29) | \
93 (((uint32_t) (method) & 0x1f) << 24) | \
94 (((uint32_t) (in) & 0xff) << 16) | \
95 (((uint32_t) (out) & 0xff) << 8) | \
96 (((uint32_t) (oin) & 0x0f) << 4) | \
97 ((uint32_t) (oout) & 0x0f))
98
99#define REMOTE_SCALARS_MAKE(method, in, out) \
100 REMOTE_SCALARS_MAKEX(0, method, in, out, 0, 0)
101
102
103#ifndef VERIFY_PRINT_ERROR
104#define VERIFY_EPRINTF(format, args) (void)0
105#endif
106
107#ifndef VERIFY_PRINT_INFO
108#define VERIFY_IPRINTF(args) (void)0
109#endif
110
111#ifndef VERIFY
112#define __STR__(x) #x ":"
113#define __TOSTR__(x) __STR__(x)
114#define __FILE_LINE__ __FILE__ ":" __TOSTR__(__LINE__)
115
116#define VERIFY(err, val) \
117do {\
118 VERIFY_IPRINTF(__FILE_LINE__"info: calling: " #val "\n");\
Tharun Kumar Merugue3edf3e2017-07-27 12:34:07 +0530119 if ((val) == 0) {\
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700120 (err) = (err) == 0 ? -1 : (err);\
121 VERIFY_EPRINTF(__FILE_LINE__"error: %d: " #val "\n", (err));\
122 } else {\
123 VERIFY_IPRINTF(__FILE_LINE__"info: passed: " #val "\n");\
124 } \
125} while (0)
126#endif
127
Mohammed Nayeem Ur Rahman80162f92019-09-23 19:35:19 +0530128/* Fall back to older APIS in case API is not supported */
129#define AEE_EUNSUPPORTED 20
130
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700131#define remote_arg64_t union remote_arg64
132
133struct remote_buf64 {
134 uint64_t pv;
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530135 uint64_t len;
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700136};
137
Sathish Ambley58dc64d2016-11-29 17:11:53 -0800138struct remote_dma_handle64 {
139 int fd;
140 uint32_t offset;
141 uint32_t len;
142};
143
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700144union remote_arg64 {
145 struct remote_buf64 buf;
Sathish Ambley58dc64d2016-11-29 17:11:53 -0800146 struct remote_dma_handle64 dma;
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700147 uint32_t h;
148};
149
150#define remote_arg_t union remote_arg
151
152struct remote_buf {
153 void *pv; /* buffer pointer */
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530154 size_t len; /* length of buffer */
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700155};
156
Sathish Ambley58dc64d2016-11-29 17:11:53 -0800157struct remote_dma_handle {
158 int fd;
159 uint32_t offset;
160};
161
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700162union remote_arg {
163 struct remote_buf buf; /* buffer info */
Sathish Ambley58dc64d2016-11-29 17:11:53 -0800164 struct remote_dma_handle dma;
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700165 uint32_t h; /* remote handle */
166};
167
168struct fastrpc_ioctl_invoke {
169 uint32_t handle; /* remote handle */
170 uint32_t sc; /* scalars describing the data */
171 remote_arg_t *pra; /* remote arguments list */
172};
173
174struct fastrpc_ioctl_invoke_fd {
175 struct fastrpc_ioctl_invoke inv;
176 int *fds; /* fd list */
177};
178
179struct fastrpc_ioctl_invoke_attrs {
180 struct fastrpc_ioctl_invoke inv;
181 int *fds; /* fd list */
182 unsigned int *attrs; /* attribute list */
183};
184
Sathish Ambleybae51902017-07-03 15:00:49 -0700185struct fastrpc_ioctl_invoke_crc {
186 struct fastrpc_ioctl_invoke inv;
187 int *fds; /* fd list */
188 unsigned int *attrs; /* attribute list */
189 unsigned int *crc;
190};
191
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700192struct fastrpc_ioctl_init {
193 uint32_t flags; /* one of FASTRPC_INIT_* macros */
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530194 uintptr_t file; /* pointer to elf file */
195 uint32_t filelen; /* elf file length */
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700196 int32_t filefd; /* ION fd for the file */
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530197 uintptr_t mem; /* mem for the PD */
198 uint32_t memlen; /* mem length */
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700199 int32_t memfd; /* ION fd for the mem */
200};
201
Sathish Ambleyd6300c32017-01-18 09:50:43 -0800202struct fastrpc_ioctl_init_attrs {
203 struct fastrpc_ioctl_init init;
204 int attrs;
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530205 unsigned int siglen;
Sathish Ambleyd6300c32017-01-18 09:50:43 -0800206};
207
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700208struct fastrpc_ioctl_munmap {
Tharun Kumar Merugu6c7d37d2018-04-18 12:14:22 +0530209 uintptr_t vaddrout; /* address to unmap */
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530210 size_t size; /* size */
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700211};
212
Tharun Kumar Merugu55be90d2018-05-31 11:41:03 +0530213struct fastrpc_ioctl_munmap_64 {
214 uint64_t vaddrout; /* address to unmap */
215 size_t size; /* size */
216};
217
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700218struct fastrpc_ioctl_mmap {
219 int fd; /* ion fd */
220 uint32_t flags; /* flags for dsp to map with */
Tharun Kumar Merugu6c7d37d2018-04-18 12:14:22 +0530221 uintptr_t vaddrin; /* optional virtual address */
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530222 size_t size; /* size */
Tharun Kumar Merugu6c7d37d2018-04-18 12:14:22 +0530223 uintptr_t vaddrout; /* dsps virtual address */
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700224};
225
Tharun Kumar Merugu55be90d2018-05-31 11:41:03 +0530226struct fastrpc_ioctl_mmap_64 {
Tharun Kumar Merugue073de72018-07-30 23:57:47 +0530227 int fd; /* ion fd */
Tharun Kumar Merugu55be90d2018-05-31 11:41:03 +0530228 uint32_t flags; /* flags for dsp to map with */
229 uint64_t vaddrin; /* optional virtual address */
230 size_t size; /* size */
231 uint64_t vaddrout; /* dsps virtual address */
232};
233
c_mtharu7bd6a422017-10-17 18:15:37 +0530234struct fastrpc_ioctl_munmap_fd {
235 int fd; /* fd */
236 uint32_t flags; /* control flags */
237 uintptr_t va; /* va */
238 ssize_t len; /* length */
239};
240
Sathish Ambleya21b5b52017-01-11 16:11:01 -0800241struct fastrpc_ioctl_perf { /* kernel performance data */
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530242 uintptr_t data;
Sathish Ambleya21b5b52017-01-11 16:11:01 -0800243 uint32_t numkeys;
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530244 uintptr_t keys;
Sathish Ambleya21b5b52017-01-11 16:11:01 -0800245};
246
Tharun Kumar Merugue073de72018-07-30 23:57:47 +0530247#define FASTRPC_CONTROL_LATENCY (1)
Tharun Kumar Merugu5f6ca61c2017-08-11 11:43:11 +0530248struct fastrpc_ctrl_latency {
Tharun Kumar Merugue073de72018-07-30 23:57:47 +0530249 uint32_t enable; /* latency control enable */
250 uint32_t level; /* level of control */
Tharun Kumar Merugu5f6ca61c2017-08-11 11:43:11 +0530251};
Tharun Kumar Merugue073de72018-07-30 23:57:47 +0530252
253#define FASTRPC_CONTROL_SMMU (2)
Tharun Kumar Merugu848c0952018-02-07 21:37:19 +0530254struct fastrpc_ctrl_smmu {
255 uint32_t sharedcb;
256};
Tharun Kumar Merugue073de72018-07-30 23:57:47 +0530257
258#define FASTRPC_CONTROL_KALLOC (3)
259struct fastrpc_ctrl_kalloc {
260 uint32_t kalloc_support; /* Remote memory allocation from kernel */
261};
262
Tharun Kumar Merugu5f6ca61c2017-08-11 11:43:11 +0530263struct fastrpc_ioctl_control {
264 uint32_t req;
265 union {
266 struct fastrpc_ctrl_latency lp;
Tharun Kumar Merugu848c0952018-02-07 21:37:19 +0530267 struct fastrpc_ctrl_smmu smmu;
Tharun Kumar Merugue073de72018-07-30 23:57:47 +0530268 struct fastrpc_ctrl_kalloc kalloc;
Tharun Kumar Merugu5f6ca61c2017-08-11 11:43:11 +0530269 };
270};
271
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700272struct smq_null_invoke {
273 uint64_t ctx; /* invoke caller context */
274 uint32_t handle; /* handle to invoke */
275 uint32_t sc; /* scalars structure describing the data */
276};
277
278struct smq_phy_page {
279 uint64_t addr; /* physical address */
280 uint64_t size; /* size of contiguous region */
281};
282
283struct smq_invoke_buf {
284 int num; /* number of contiguous regions */
285 int pgidx; /* index to start of contiguous region */
286};
287
288struct smq_invoke {
289 struct smq_null_invoke header;
290 struct smq_phy_page page; /* remote arg and list of pages address */
291};
292
293struct smq_msg {
294 uint32_t pid; /* process group id */
295 uint32_t tid; /* thread id */
296 struct smq_invoke invoke;
297};
298
299struct smq_invoke_rsp {
300 uint64_t ctx; /* invoke caller context */
301 int retval; /* invoke return value */
302};
303
304static inline struct smq_invoke_buf *smq_invoke_buf_start(remote_arg64_t *pra,
305 uint32_t sc)
306{
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530307 unsigned int len = REMOTE_SCALARS_LENGTH(sc);
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700308
309 return (struct smq_invoke_buf *)(&pra[len]);
310}
311
312static inline struct smq_phy_page *smq_phy_page_start(uint32_t sc,
313 struct smq_invoke_buf *buf)
314{
Tharun Kumar Merugufb51f942017-12-07 10:32:15 +0530315 unsigned int nTotal = REMOTE_SCALARS_LENGTH(sc);
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700316
317 return (struct smq_phy_page *)(&buf[nTotal]);
318}
319
320#endif