• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2019, The Linux Foundation. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *    * Redistributions of source code must retain the above copyright
8  *      notice, this list of conditions and the following disclaimer.
9  *    * Redistributions in binary form must reproduce the above
10  *      copyright notice, this list of conditions and the following
11  *      disclaimer in the documentation and/or other materials provided
12  *      with the distribution.
13  *    * Neither the name of The Linux Foundation nor the names of its
14  *      contributors may be used to endorse or promote products derived
15  *      from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef REMOTE_H
31 #define REMOTE_H
32 
33 #include <stdint.h>
34 #include <sys/types.h>
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 typedef uint32_t remote_handle;
41 typedef uint64_t remote_handle64; //! used by multi domain modules
42                                   //! 64 bit handles are translated to 32 bit values
43                                   //! by the transport layer
44 
45 typedef struct {
46    void *pv;
47    size_t nLen;
48 } remote_buf;
49 
50 typedef struct {
51    int32_t fd;
52    uint32_t offset;
53 } remote_dma_handle;
54 
55 typedef union {
56    remote_buf     buf;
57    remote_handle    h;
58    remote_handle64 h64; //! used by multi domain modules
59    remote_dma_handle dma;
60 } remote_arg;
61 
62 /*Retrives method attribute from the scalars parameter*/
63 #define REMOTE_SCALARS_METHOD_ATTR(dwScalars)   (((dwScalars) >> 29) & 0x7)
64 
65 /*Retrives method index from the scalars parameter*/
66 #define REMOTE_SCALARS_METHOD(dwScalars)        (((dwScalars) >> 24) & 0x1f)
67 
68 /*Retrives number of input buffers from the scalars parameter*/
69 #define REMOTE_SCALARS_INBUFS(dwScalars)        (((dwScalars) >> 16) & 0x0ff)
70 
71 /*Retrives number of output buffers from the scalars parameter*/
72 #define REMOTE_SCALARS_OUTBUFS(dwScalars)       (((dwScalars) >> 8) & 0x0ff)
73 
74 /*Retrives number of input handles from the scalars parameter*/
75 #define REMOTE_SCALARS_INHANDLES(dwScalars)     (((dwScalars) >> 4) & 0x0f)
76 
77 /*Retrives number of output handles from the scalars parameter*/
78 #define REMOTE_SCALARS_OUTHANDLES(dwScalars)    ((dwScalars) & 0x0f)
79 
80 #define REMOTE_SCALARS_MAKEX(nAttr,nMethod,nIn,nOut,noIn,noOut) \
81           ((((uint32_t)   (nAttr) &  0x7) << 29) | \
82            (((uint32_t) (nMethod) & 0x1f) << 24) | \
83            (((uint32_t)     (nIn) & 0xff) << 16) | \
84            (((uint32_t)    (nOut) & 0xff) <<  8) | \
85            (((uint32_t)    (noIn) & 0x0f) <<  4) | \
86             ((uint32_t)   (noOut) & 0x0f))
87 
88 #define REMOTE_SCALARS_MAKE(nMethod,nIn,nOut)  REMOTE_SCALARS_MAKEX(0,nMethod,nIn,nOut,0,0)
89 
90 #define REMOTE_SCALARS_LENGTH(sc) (REMOTE_SCALARS_INBUFS(sc) +\
91                                    REMOTE_SCALARS_OUTBUFS(sc) +\
92                                    REMOTE_SCALARS_INHANDLES(sc) +\
93                                    REMOTE_SCALARS_OUTHANDLES(sc))
94 
95 #ifndef __QAIC_REMOTE
96 #define __QAIC_REMOTE(ff) ff
97 #endif //__QAIC_REMOTE
98 
99 #ifndef __QAIC_REMOTE_EXPORT
100 #ifdef _WIN32
101 #define __QAIC_REMOTE_EXPORT __declspec(dllexport)
102 #else //_WIN32
103 #define __QAIC_REMOTE_EXPORT
104 #endif //_WIN32
105 #endif //__QAIC_REMOTE_EXPORT
106 
107 #ifndef __QAIC_REMOTE_ATTRIBUTE
108 #define __QAIC_REMOTE_ATTRIBUTE
109 #endif
110 
111 #define NUM_DOMAINS 4
112 #define NUM_SESSIONS 2
113 #define DOMAIN_ID_MASK 3
114 
115 #ifndef DEFAULT_DOMAIN_ID
116 #define DEFAULT_DOMAIN_ID 0
117 #endif
118 
119 #define ADSP_DOMAIN_ID    0
120 #define MDSP_DOMAIN_ID    1
121 #define SDSP_DOMAIN_ID    2
122 #define CDSP_DOMAIN_ID    3
123 
124 #define ADSP_DOMAIN "&_dom=adsp"
125 #define MDSP_DOMAIN "&_dom=mdsp"
126 #define SDSP_DOMAIN "&_dom=sdsp"
127 #define CDSP_DOMAIN "&_dom=cdsp"
128 
129 /* All other values are reserved */
130 
131 /* opens a remote_handle "name"
132  * returns 0 on success
133  */
134 __QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_handle_open)(const char* name, remote_handle *ph) __QAIC_REMOTE_ATTRIBUTE;
135 __QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_handle64_open)(const char* name, remote_handle64 *ph) __QAIC_REMOTE_ATTRIBUTE;
136 
137 /* invokes the remote handle
138  * see retrive macro's on dwScalars format
139  * pra, contains the arguments in the following order, inbufs, outbufs, inhandles, outhandles.
140  * implementors should ignore and pass values asis that the transport doesn't understand.
141  */
142 __QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_handle_invoke)(remote_handle h, uint32_t dwScalars, remote_arg *pra) __QAIC_REMOTE_ATTRIBUTE;
143 __QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_handle64_invoke)(remote_handle64 h, uint32_t dwScalars, remote_arg *pra) __QAIC_REMOTE_ATTRIBUTE;
144 
145 /* closes the remote handle
146  */
147 __QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_handle_close)(remote_handle h) __QAIC_REMOTE_ATTRIBUTE;
148 __QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_handle64_close)(remote_handle64 h) __QAIC_REMOTE_ATTRIBUTE;
149 
150 /* remote handle control interface
151  */
152 /* request ID for fastrpc latency control */
153 #define DSPRPC_CONTROL_LATENCY    (1)
154 struct remote_rpc_control_latency {
155    uint32_t enable;	// enable auto control of rpc latency
156    uint32_t latency;	// latency: reserved
157 };
158 
159 __QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_handle_control)(uint32_t req, void* data, uint32_t datalen) __QAIC_REMOTE_ATTRIBUTE;
160 __QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_handle64_control)(remote_handle64 h, uint32_t req, void* data, uint32_t datalen) __QAIC_REMOTE_ATTRIBUTE;
161 
162 /* remote session control interface
163  */
164 /* request ID for setting DSP user thread params */
165 #define FASTRPC_THREAD_PARAMS    (1)
166 struct remote_rpc_thread_params {
167 	int domain;			// Remote subsystem domain ID, pass -1 to set params for all domains
168 	int prio;			// user thread priority (1 to 255), pass -1 to use default
169 	int stack_size;		// user thread stack size, pass -1 to use default
170 };
171 
172 /* request ID for fastrpc unsigned module */
173 #define DSPRPC_CONTROL_UNSIGNED_MODULE    (2)
174 struct remote_rpc_control_unsigned_module {
175    int domain;				// Remote subsystem domain ID, -1 to set params for all domains
176    int enable; 				// enable unsigned module loading
177 };
178 
179 /* Set remote session parameters
180  *
181  * @param req, request ID
182  * @param data, address of structure with parameters
183  * @param datalen, length of data
184  * @retval, 0 on success
185  */
186 __QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_session_control)(uint32_t req, void *data, uint32_t datalen) __QAIC_REMOTE_ATTRIBUTE;
187 
188 /* map memory to the remote domain
189  *
190  * @param fd, fd assosciated with this memory
191  * @param flags, flags to be used for the mapping
192  * @param vaddrin, input address
193  * @param size, size of buffer
194  * @param vaddrout, output address
195  * @retval, 0 on success
196  */
197 __QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_mmap)(int fd, uint32_t flags, uint32_t vaddrin, int size, uint32_t* vaddrout) __QAIC_REMOTE_ATTRIBUTE;
198 
199 /* unmap memory from the remote domain
200  *
201  * @param vaddrout, remote address mapped
202  * @param size, size to unmap.  Unmapping a range partially may  not be supported.
203  * @retval, 0 on success, may fail if memory is still mapped
204  */
205 __QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_munmap)(uint32_t vaddrout, int size) __QAIC_REMOTE_ATTRIBUTE;
206 
207 /*
208  * Attribute to map a buffer as dma non-coherent
209  * Driver perform cache maintenance.
210  */
211 #define FASTRPC_ATTR_NON_COHERENT  (2)
212 
213 /*
214  * Attribute to map a buffer as dma coherent
215  * Driver skips cache maintenenace
216  * It will be ignored if a device is marked as dma-coherent in device tree.
217  */
218 #define FASTRPC_ATTR_COHERENT  (4)
219 
220 /* Attribute to keep the buffer persistant
221  * until unmap is called explicitly
222  */
223 #define FASTRPC_ATTR_KEEP_MAP  (8)
224 
225 /*
226  * Attribute for secure buffers to skip
227  * smmu mapping in fastrpc driver
228  */
229 #define FASTRPC_ATTR_NOMAP  (16)
230 
231 /* Register a file descriptor for a buffer.  This is only valid on
232  * android with ION allocated memory.  Users of fastrpc should register
233  * a buffer allocated with ION to enable sharing that buffer to the
234  * dsp via the smmu.  Some versions of libadsprpc.so lack this
235  * function, so users should set this symbol as weak.
236  *
237  * #pragma weak  remote_register_buf
238  * #pragma weak  remote_register_buf_attr
239  *
240  * @param buf, virtual address of the buffer
241  * @param size, size of the buffer
242  * @fd, the file descriptor, callers can use -1 to deregister.
243  * @attr, map buffer as coherent or non-coherent
244  */
245 __QAIC_REMOTE_EXPORT void __QAIC_REMOTE(remote_register_buf)(void* buf, int size, int fd) __QAIC_REMOTE_ATTRIBUTE;
246 __QAIC_REMOTE_EXPORT void __QAIC_REMOTE(remote_register_buf_attr)(void* buf, int size, int fd, int attr) __QAIC_REMOTE_ATTRIBUTE;
247 
248 /* Register a dma handle with fastrpc.  This is only valid on
249  * android with ION allocated memory.  Users of fastrpc should register
250  * a file descriptor allocated with ION to enable sharing that memory to the
251  * dsp via the smmu.  Some versions of libadsprpc.so lack this
252  * function, so users should set this symbol as weak.
253  *
254  * #pragma weak  remote_register_dma_handle
255  * #pragma weak  remote_register_dma_handle_attr
256  *
257  * @fd, the file descriptor, callers can use -1 to deregister.
258  * @param len, size of the buffer
259  * @attr, map buffer as coherent or non-coherent or no-map
260  */
261 __QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_register_dma_handle)(int fd, uint32_t len) __QAIC_REMOTE_ATTRIBUTE;
262 __QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_register_dma_handle_attr)(int fd, uint32_t len, uint32_t attr) __QAIC_REMOTE_ATTRIBUTE;
263 
264 /*
265  * This is the default mode for the driver.  While the driver is in parallel
266  * mode it will try to invalidate output buffers after it transfers control
267  * to the dsp.  This allows the invalidate operations to overlap with the
268  * dsp processing the call.  This mode should be used when output buffers
269  * are only read on the application processor and only written on the aDSP.
270  */
271 #define REMOTE_MODE_PARALLEL  0
272 
273 /*
274  * When operating in SERIAL mode the driver will invalidate output buffers
275  * before calling into the dsp.  This mode should be used when output
276  * buffers have been written to somewhere besides the aDSP.
277  */
278 #define REMOTE_MODE_SERIAL    1
279 
280 /*
281  * Internal transport prefix
282  */
283 #define ITRANSPORT_PREFIX "'\":;./\\"
284 
285 /*
286  * Set the mode of operation.
287  *
288  * Some versions of libadsprpc.so lack this function, so users should set
289  * this symbol as weak.
290  *
291  * #pragma weak  remote_set_mode
292  *
293  * @param mode, the mode
294  * @retval, 0 on success
295  */
296 __QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_set_mode)(uint32_t mode) __QAIC_REMOTE_ATTRIBUTE;
297 
298 /* Register a file descriptor.  This can be used when users do not have
299  * a mapping to pass to the RPC layer.  The generated address is a mapping
300  * with PROT_NONE, any access to this memory will fail, so it should only
301  * be used as an ID to identify this file descriptor to the RPC layer.
302  *
303  * To deregister use remote_register_buf(addr, size, -1).
304  *
305  * #pragma weak  remote_register_fd
306  *
307  * @param fd, the file descriptor.
308  * @param size, size to of the buffer
309  * @retval, (void*)-1 on failure, address on success.
310  *
311  */
312 __QAIC_REMOTE_EXPORT void *__QAIC_REMOTE(remote_register_fd)(int fd, int size) __QAIC_REMOTE_ATTRIBUTE;
313 
314 #ifdef __cplusplus
315 }
316 #endif
317 
318 #endif // REMOTE_H
319