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