blob: 9f964d2a7599f03fbc75a4eb083638f189591c43 [file] [log] [blame]
Sathish Ambley69e1ab02016-10-18 10:28:15 -07001/*
Sathish Ambleya21b5b52017-01-11 16:11:01 -08002 * Copyright (c) 2012-2017, 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)
22#define FASTRPC_IOCTL_INVOKE_FD _IOWR('R', 4, struct fastrpc_ioctl_invoke_fd)
23#define FASTRPC_IOCTL_SETMODE _IOWR('R', 5, uint32_t)
24#define FASTRPC_IOCTL_INIT _IOWR('R', 6, struct fastrpc_ioctl_init)
25#define FASTRPC_IOCTL_INVOKE_ATTRS \
26 _IOWR('R', 7, struct fastrpc_ioctl_invoke_attrs)
27#define FASTRPC_IOCTL_GETINFO _IOWR('R', 8, uint32_t)
Sathish Ambleya21b5b52017-01-11 16:11:01 -080028#define FASTRPC_IOCTL_GETPERF _IOWR('R', 9, struct fastrpc_ioctl_perf)
Sathish Ambleyd6300c32017-01-18 09:50:43 -080029#define FASTRPC_IOCTL_INIT_ATTRS _IOWR('R', 10, struct fastrpc_ioctl_init_attrs)
Sathish Ambleybae51902017-07-03 15:00:49 -070030#define FASTRPC_IOCTL_INVOKE_CRC _IOWR('R', 11, struct fastrpc_ioctl_invoke_crc)
Tharun Kumar Merugu5f6ca61c2017-08-11 11:43:11 +053031#define FASTRPC_IOCTL_CONTROL _IOWR('R', 12, struct fastrpc_ioctl_control)
Sathish Ambley69e1ab02016-10-18 10:28:15 -070032
33#define FASTRPC_GLINK_GUID "fastrpcglink-apps-dsp"
34#define FASTRPC_SMD_GUID "fastrpcsmd-apps-dsp"
35#define DEVICE_NAME "adsprpc-smd"
36
37/* Set for buffers that have no virtual mapping in userspace */
38#define FASTRPC_ATTR_NOVA 0x1
39
Tharun Kumar Merugu2e5f12e2017-07-06 12:04:40 +053040/* Set for buffers that are NOT dma coherent */
41#define FASTRPC_ATTR_NON_COHERENT 0x2
42
43/* Set for buffers that are dma coherent */
44#define FASTRPC_ATTR_COHERENT 0x4
45
Sathish Ambley69e1ab02016-10-18 10:28:15 -070046/* Driver should operate in parallel with the co-processor */
47#define FASTRPC_MODE_PARALLEL 0
48
49/* Driver should operate in serial mode with the co-processor */
50#define FASTRPC_MODE_SERIAL 1
51
Sathish Ambleya21b5b52017-01-11 16:11:01 -080052/* Driver should operate in profile mode with the co-processor */
53#define FASTRPC_MODE_PROFILE 2
54
Sathish Ambley69e1ab02016-10-18 10:28:15 -070055/* INIT a new process or attach to guestos */
56#define FASTRPC_INIT_ATTACH 0
57#define FASTRPC_INIT_CREATE 1
58
59/* Retrives number of input buffers from the scalars parameter */
60#define REMOTE_SCALARS_INBUFS(sc) (((sc) >> 16) & 0x0ff)
61
62/* Retrives number of output buffers from the scalars parameter */
63#define REMOTE_SCALARS_OUTBUFS(sc) (((sc) >> 8) & 0x0ff)
64
65/* Retrives number of input handles from the scalars parameter */
66#define REMOTE_SCALARS_INHANDLES(sc) (((sc) >> 4) & 0x0f)
67
68/* Retrives number of output handles from the scalars parameter */
69#define REMOTE_SCALARS_OUTHANDLES(sc) ((sc) & 0x0f)
70
71#define REMOTE_SCALARS_LENGTH(sc) (REMOTE_SCALARS_INBUFS(sc) +\
72 REMOTE_SCALARS_OUTBUFS(sc) +\
73 REMOTE_SCALARS_INHANDLES(sc) +\
74 REMOTE_SCALARS_OUTHANDLES(sc))
75
76#define REMOTE_SCALARS_MAKEX(attr, method, in, out, oin, oout) \
77 ((((uint32_t) (attr) & 0x7) << 29) | \
78 (((uint32_t) (method) & 0x1f) << 24) | \
79 (((uint32_t) (in) & 0xff) << 16) | \
80 (((uint32_t) (out) & 0xff) << 8) | \
81 (((uint32_t) (oin) & 0x0f) << 4) | \
82 ((uint32_t) (oout) & 0x0f))
83
84#define REMOTE_SCALARS_MAKE(method, in, out) \
85 REMOTE_SCALARS_MAKEX(0, method, in, out, 0, 0)
86
87
88#ifndef VERIFY_PRINT_ERROR
89#define VERIFY_EPRINTF(format, args) (void)0
90#endif
91
92#ifndef VERIFY_PRINT_INFO
93#define VERIFY_IPRINTF(args) (void)0
94#endif
95
96#ifndef VERIFY
97#define __STR__(x) #x ":"
98#define __TOSTR__(x) __STR__(x)
99#define __FILE_LINE__ __FILE__ ":" __TOSTR__(__LINE__)
100
101#define VERIFY(err, val) \
102do {\
103 VERIFY_IPRINTF(__FILE_LINE__"info: calling: " #val "\n");\
Tharun Kumar Merugue3edf3e2017-07-27 12:34:07 +0530104 if ((val) == 0) {\
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700105 (err) = (err) == 0 ? -1 : (err);\
106 VERIFY_EPRINTF(__FILE_LINE__"error: %d: " #val "\n", (err));\
107 } else {\
108 VERIFY_IPRINTF(__FILE_LINE__"info: passed: " #val "\n");\
109 } \
110} while (0)
111#endif
112
113#define remote_arg64_t union remote_arg64
114
115struct remote_buf64 {
116 uint64_t pv;
117 int64_t len;
118};
119
Sathish Ambley58dc64d2016-11-29 17:11:53 -0800120struct remote_dma_handle64 {
121 int fd;
122 uint32_t offset;
123 uint32_t len;
124};
125
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700126union remote_arg64 {
127 struct remote_buf64 buf;
Sathish Ambley58dc64d2016-11-29 17:11:53 -0800128 struct remote_dma_handle64 dma;
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700129 uint32_t h;
130};
131
132#define remote_arg_t union remote_arg
133
134struct remote_buf {
135 void *pv; /* buffer pointer */
136 ssize_t len; /* length of buffer */
137};
138
Sathish Ambley58dc64d2016-11-29 17:11:53 -0800139struct remote_dma_handle {
140 int fd;
141 uint32_t offset;
142};
143
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700144union remote_arg {
145 struct remote_buf buf; /* buffer info */
Sathish Ambley58dc64d2016-11-29 17:11:53 -0800146 struct remote_dma_handle dma;
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700147 uint32_t h; /* remote handle */
148};
149
150struct fastrpc_ioctl_invoke {
151 uint32_t handle; /* remote handle */
152 uint32_t sc; /* scalars describing the data */
153 remote_arg_t *pra; /* remote arguments list */
154};
155
156struct fastrpc_ioctl_invoke_fd {
157 struct fastrpc_ioctl_invoke inv;
158 int *fds; /* fd list */
159};
160
161struct fastrpc_ioctl_invoke_attrs {
162 struct fastrpc_ioctl_invoke inv;
163 int *fds; /* fd list */
164 unsigned int *attrs; /* attribute list */
165};
166
Sathish Ambleybae51902017-07-03 15:00:49 -0700167struct fastrpc_ioctl_invoke_crc {
168 struct fastrpc_ioctl_invoke inv;
169 int *fds; /* fd list */
170 unsigned int *attrs; /* attribute list */
171 unsigned int *crc;
172};
173
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700174struct fastrpc_ioctl_init {
175 uint32_t flags; /* one of FASTRPC_INIT_* macros */
176 uintptr_t __user file; /* pointer to elf file */
177 int32_t filelen; /* elf file length */
178 int32_t filefd; /* ION fd for the file */
179 uintptr_t __user mem; /* mem for the PD */
180 int32_t memlen; /* mem length */
181 int32_t memfd; /* ION fd for the mem */
182};
183
Sathish Ambleyd6300c32017-01-18 09:50:43 -0800184struct fastrpc_ioctl_init_attrs {
185 struct fastrpc_ioctl_init init;
186 int attrs;
187 int siglen;
188};
189
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700190struct fastrpc_ioctl_munmap {
191 uintptr_t vaddrout; /* address to unmap */
192 ssize_t size; /* size */
193};
194
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700195struct fastrpc_ioctl_mmap {
196 int fd; /* ion fd */
197 uint32_t flags; /* flags for dsp to map with */
198 uintptr_t __user *vaddrin; /* optional virtual address */
199 ssize_t size; /* size */
200 uintptr_t vaddrout; /* dsps virtual address */
201};
202
Sathish Ambleya21b5b52017-01-11 16:11:01 -0800203struct fastrpc_ioctl_perf { /* kernel performance data */
204 uintptr_t __user data;
205 uint32_t numkeys;
206 uintptr_t __user keys;
207};
208
Tharun Kumar Merugu5f6ca61c2017-08-11 11:43:11 +0530209#define FASTRPC_CONTROL_LATENCY (1)
210struct fastrpc_ctrl_latency {
211 uint32_t enable; //!latency control enable
212 uint32_t level; //!level of control
213};
214
215struct fastrpc_ioctl_control {
216 uint32_t req;
217 union {
218 struct fastrpc_ctrl_latency lp;
219 };
220};
221
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700222struct smq_null_invoke {
223 uint64_t ctx; /* invoke caller context */
224 uint32_t handle; /* handle to invoke */
225 uint32_t sc; /* scalars structure describing the data */
226};
227
228struct smq_phy_page {
229 uint64_t addr; /* physical address */
230 uint64_t size; /* size of contiguous region */
231};
232
233struct smq_invoke_buf {
234 int num; /* number of contiguous regions */
235 int pgidx; /* index to start of contiguous region */
236};
237
238struct smq_invoke {
239 struct smq_null_invoke header;
240 struct smq_phy_page page; /* remote arg and list of pages address */
241};
242
243struct smq_msg {
244 uint32_t pid; /* process group id */
245 uint32_t tid; /* thread id */
246 struct smq_invoke invoke;
247};
248
249struct smq_invoke_rsp {
250 uint64_t ctx; /* invoke caller context */
251 int retval; /* invoke return value */
252};
253
254static inline struct smq_invoke_buf *smq_invoke_buf_start(remote_arg64_t *pra,
255 uint32_t sc)
256{
257 int len = REMOTE_SCALARS_LENGTH(sc);
258
259 return (struct smq_invoke_buf *)(&pra[len]);
260}
261
262static inline struct smq_phy_page *smq_phy_page_start(uint32_t sc,
263 struct smq_invoke_buf *buf)
264{
Sathish Ambley58dc64d2016-11-29 17:11:53 -0800265 int nTotal = REMOTE_SCALARS_LENGTH(sc);
Sathish Ambley69e1ab02016-10-18 10:28:15 -0700266
267 return (struct smq_phy_page *)(&buf[nTotal]);
268}
269
270#endif