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 _ADSPMSGD_ADSP_STUB_H
31*418b791dSBob Badour #define _ADSPMSGD_ADSP_STUB_H
32*418b791dSBob Badour #include "adspmsgd_adsp.h"
33*418b791dSBob Badour #ifndef _QAIC_ENV_H
34*418b791dSBob Badour #define _QAIC_ENV_H
35*418b791dSBob Badour
36*418b791dSBob Badour #ifdef __GNUC__
37*418b791dSBob Badour #ifdef __clang__
38*418b791dSBob Badour #pragma GCC diagnostic ignored "-Wunknown-pragmas"
39*418b791dSBob Badour #else
40*418b791dSBob Badour #pragma GCC diagnostic ignored "-Wpragmas"
41*418b791dSBob Badour #endif
42*418b791dSBob Badour #pragma GCC diagnostic ignored "-Wuninitialized"
43*418b791dSBob Badour #pragma GCC diagnostic ignored "-Wunused-parameter"
44*418b791dSBob Badour #pragma GCC diagnostic ignored "-Wunused-function"
45*418b791dSBob Badour #endif
46*418b791dSBob Badour
47*418b791dSBob Badour #ifndef _ATTRIBUTE_UNUSED
48*418b791dSBob Badour
49*418b791dSBob Badour #ifdef _WIN32
50*418b791dSBob Badour #define _ATTRIBUTE_UNUSED
51*418b791dSBob Badour #else
52*418b791dSBob Badour #define _ATTRIBUTE_UNUSED __attribute__ ((unused))
53*418b791dSBob Badour #endif
54*418b791dSBob Badour
55*418b791dSBob Badour #endif // _ATTRIBUTE_UNUSED
56*418b791dSBob Badour
57*418b791dSBob Badour #ifndef __QAIC_REMOTE
58*418b791dSBob Badour #define __QAIC_REMOTE(ff) ff
59*418b791dSBob Badour #endif //__QAIC_REMOTE
60*418b791dSBob Badour
61*418b791dSBob Badour #ifndef __QAIC_HEADER
62*418b791dSBob Badour #define __QAIC_HEADER(ff) ff
63*418b791dSBob Badour #endif //__QAIC_HEADER
64*418b791dSBob Badour
65*418b791dSBob Badour #ifndef __QAIC_HEADER_EXPORT
66*418b791dSBob Badour #define __QAIC_HEADER_EXPORT
67*418b791dSBob Badour #endif // __QAIC_HEADER_EXPORT
68*418b791dSBob Badour
69*418b791dSBob Badour #ifndef __QAIC_HEADER_ATTRIBUTE
70*418b791dSBob Badour #define __QAIC_HEADER_ATTRIBUTE
71*418b791dSBob Badour #endif // __QAIC_HEADER_ATTRIBUTE
72*418b791dSBob Badour
73*418b791dSBob Badour #ifndef __QAIC_IMPL
74*418b791dSBob Badour #define __QAIC_IMPL(ff) ff
75*418b791dSBob Badour #endif //__QAIC_IMPL
76*418b791dSBob Badour
77*418b791dSBob Badour #ifndef __QAIC_IMPL_EXPORT
78*418b791dSBob Badour #define __QAIC_IMPL_EXPORT
79*418b791dSBob Badour #endif // __QAIC_IMPL_EXPORT
80*418b791dSBob Badour
81*418b791dSBob Badour #ifndef __QAIC_IMPL_ATTRIBUTE
82*418b791dSBob Badour #define __QAIC_IMPL_ATTRIBUTE
83*418b791dSBob Badour #endif // __QAIC_IMPL_ATTRIBUTE
84*418b791dSBob Badour
85*418b791dSBob Badour #ifndef __QAIC_STUB
86*418b791dSBob Badour #define __QAIC_STUB(ff) ff
87*418b791dSBob Badour #endif //__QAIC_STUB
88*418b791dSBob Badour
89*418b791dSBob Badour #ifndef __QAIC_STUB_EXPORT
90*418b791dSBob Badour #define __QAIC_STUB_EXPORT
91*418b791dSBob Badour #endif // __QAIC_STUB_EXPORT
92*418b791dSBob Badour
93*418b791dSBob Badour #ifndef __QAIC_STUB_ATTRIBUTE
94*418b791dSBob Badour #define __QAIC_STUB_ATTRIBUTE
95*418b791dSBob Badour #endif // __QAIC_STUB_ATTRIBUTE
96*418b791dSBob Badour
97*418b791dSBob Badour #ifndef __QAIC_SKEL
98*418b791dSBob Badour #define __QAIC_SKEL(ff) ff
99*418b791dSBob Badour #endif //__QAIC_SKEL__
100*418b791dSBob Badour
101*418b791dSBob Badour #ifndef __QAIC_SKEL_EXPORT
102*418b791dSBob Badour #define __QAIC_SKEL_EXPORT
103*418b791dSBob Badour #endif // __QAIC_SKEL_EXPORT
104*418b791dSBob Badour
105*418b791dSBob Badour #ifndef __QAIC_SKEL_ATTRIBUTE
106*418b791dSBob Badour #define __QAIC_SKEL_ATTRIBUTE
107*418b791dSBob Badour #endif // __QAIC_SKEL_ATTRIBUTE
108*418b791dSBob Badour
109*418b791dSBob Badour #ifdef __QAIC_DEBUG__
110*418b791dSBob Badour #ifndef __QAIC_DBG_PRINTF__
111*418b791dSBob Badour #include <stdio.h>
112*418b791dSBob Badour #define __QAIC_DBG_PRINTF__( ee ) do { printf ee ; } while(0)
113*418b791dSBob Badour #endif
114*418b791dSBob Badour #else
115*418b791dSBob Badour #define __QAIC_DBG_PRINTF__( ee ) (void)0
116*418b791dSBob Badour #endif
117*418b791dSBob Badour
118*418b791dSBob Badour
119*418b791dSBob Badour #define _OFFSET(src, sof) ((void*)(((char*)(src)) + (sof)))
120*418b791dSBob Badour
121*418b791dSBob Badour #define _COPY(dst, dof, src, sof, sz) \
122*418b791dSBob Badour do {\
123*418b791dSBob Badour struct __copy { \
124*418b791dSBob Badour char ar[sz]; \
125*418b791dSBob Badour };\
126*418b791dSBob Badour *(struct __copy*)_OFFSET(dst, dof) = *(struct __copy*)_OFFSET(src, sof);\
127*418b791dSBob Badour } while (0)
128*418b791dSBob Badour
129*418b791dSBob Badour #define _COPYIF(dst, dof, src, sof, sz) \
130*418b791dSBob Badour do {\
131*418b791dSBob Badour if(_OFFSET(dst, dof) != _OFFSET(src, sof)) {\
132*418b791dSBob Badour _COPY(dst, dof, src, sof, sz); \
133*418b791dSBob Badour } \
134*418b791dSBob Badour } while (0)
135*418b791dSBob Badour
136*418b791dSBob Badour _ATTRIBUTE_UNUSED
_qaic_memmove(void * dst,void * src,int size)137*418b791dSBob Badour static __inline void _qaic_memmove(void* dst, void* src, int size) {
138*418b791dSBob Badour int i;
139*418b791dSBob Badour for(i = 0; i < size; ++i) {
140*418b791dSBob Badour ((char*)dst)[i] = ((char*)src)[i];
141*418b791dSBob Badour }
142*418b791dSBob Badour }
143*418b791dSBob Badour
144*418b791dSBob Badour #define _MEMMOVEIF(dst, src, sz) \
145*418b791dSBob Badour do {\
146*418b791dSBob Badour if(dst != src) {\
147*418b791dSBob Badour _qaic_memmove(dst, src, sz);\
148*418b791dSBob Badour } \
149*418b791dSBob Badour } while (0)
150*418b791dSBob Badour
151*418b791dSBob Badour
152*418b791dSBob Badour #define _ASSIGN(dst, src, sof) \
153*418b791dSBob Badour do {\
154*418b791dSBob Badour dst = OFFSET(src, sof); \
155*418b791dSBob Badour } while (0)
156*418b791dSBob Badour
157*418b791dSBob Badour #define _STD_STRLEN_IF(str) (str == 0 ? 0 : strlen(str))
158*418b791dSBob Badour
159*418b791dSBob Badour #include "AEEStdErr.h"
160*418b791dSBob Badour
161*418b791dSBob Badour #define _TRY(ee, func) \
162*418b791dSBob Badour do { \
163*418b791dSBob Badour if (AEE_SUCCESS != ((ee) = func)) {\
164*418b791dSBob Badour __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", __LINE__, (int)(ee),#func));\
165*418b791dSBob Badour goto ee##bail;\
166*418b791dSBob Badour } \
167*418b791dSBob Badour } while (0)
168*418b791dSBob Badour
169*418b791dSBob Badour #define _CATCH(exception) exception##bail: if (exception != AEE_SUCCESS)
170*418b791dSBob Badour
171*418b791dSBob Badour #define _ASSERT(nErr, ff) _TRY(nErr, 0 == (ff) ? AEE_EBADPARM : AEE_SUCCESS)
172*418b791dSBob Badour
173*418b791dSBob Badour #ifdef __QAIC_DEBUG__
174*418b791dSBob Badour #define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, (void**)&pv))
175*418b791dSBob Badour #else
176*418b791dSBob Badour #define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void**)&pv))
177*418b791dSBob Badour #endif
178*418b791dSBob Badour
179*418b791dSBob Badour
180*418b791dSBob Badour #endif // _QAIC_ENV_H
181*418b791dSBob Badour
182*418b791dSBob Badour #include "remote.h"
183*418b791dSBob Badour #ifndef _ALLOCATOR_H
184*418b791dSBob Badour #define _ALLOCATOR_H
185*418b791dSBob Badour
186*418b791dSBob Badour #include <stdlib.h>
187*418b791dSBob Badour #include <stdint.h>
188*418b791dSBob Badour
189*418b791dSBob Badour typedef struct _heap _heap;
190*418b791dSBob Badour struct _heap {
191*418b791dSBob Badour _heap* pPrev;
192*418b791dSBob Badour const char* loc;
193*418b791dSBob Badour uint64_t buf;
194*418b791dSBob Badour };
195*418b791dSBob Badour
196*418b791dSBob Badour typedef struct _allocator {
197*418b791dSBob Badour _heap* pheap;
198*418b791dSBob Badour uint8_t* stack;
199*418b791dSBob Badour uint8_t* stackEnd;
200*418b791dSBob Badour int nSize;
201*418b791dSBob Badour } _allocator;
202*418b791dSBob Badour
203*418b791dSBob Badour _ATTRIBUTE_UNUSED
_heap_alloc(_heap ** ppa,const char * loc,int size,void ** ppbuf)204*418b791dSBob Badour static __inline int _heap_alloc(_heap** ppa, const char* loc, int size, void** ppbuf) {
205*418b791dSBob Badour _heap* pn = 0;
206*418b791dSBob Badour pn = malloc(size + sizeof(_heap) - sizeof(uint64_t));
207*418b791dSBob Badour if(pn != 0) {
208*418b791dSBob Badour pn->pPrev = *ppa;
209*418b791dSBob Badour pn->loc = loc;
210*418b791dSBob Badour *ppa = pn;
211*418b791dSBob Badour *ppbuf = (void*)&(pn->buf);
212*418b791dSBob Badour return 0;
213*418b791dSBob Badour } else {
214*418b791dSBob Badour return -1;
215*418b791dSBob Badour }
216*418b791dSBob Badour }
217*418b791dSBob Badour #define _ALIGN_SIZE(x, y) (((x) + (y-1)) & ~(y-1))
218*418b791dSBob Badour
219*418b791dSBob Badour _ATTRIBUTE_UNUSED
_allocator_alloc(_allocator * me,const char * loc,int size,unsigned int al,void ** ppbuf)220*418b791dSBob Badour static __inline int _allocator_alloc(_allocator* me,
221*418b791dSBob Badour const char* loc,
222*418b791dSBob Badour int size,
223*418b791dSBob Badour unsigned int al,
224*418b791dSBob Badour void** ppbuf) {
225*418b791dSBob Badour if(size < 0) {
226*418b791dSBob Badour return -1;
227*418b791dSBob Badour } else if (size == 0) {
228*418b791dSBob Badour *ppbuf = 0;
229*418b791dSBob Badour return 0;
230*418b791dSBob Badour }
231*418b791dSBob Badour if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size) < (uintptr_t)me->stack + me->nSize) {
232*418b791dSBob Badour *ppbuf = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al);
233*418b791dSBob Badour me->stackEnd = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size;
234*418b791dSBob Badour return 0;
235*418b791dSBob Badour } else {
236*418b791dSBob Badour return _heap_alloc(&me->pheap, loc, size, ppbuf);
237*418b791dSBob Badour }
238*418b791dSBob Badour }
239*418b791dSBob Badour
240*418b791dSBob Badour _ATTRIBUTE_UNUSED
_allocator_deinit(_allocator * me)241*418b791dSBob Badour static __inline void _allocator_deinit(_allocator* me) {
242*418b791dSBob Badour _heap* pa = me->pheap;
243*418b791dSBob Badour while(pa != 0) {
244*418b791dSBob Badour _heap* pn = pa;
245*418b791dSBob Badour const char* loc = pn->loc;
246*418b791dSBob Badour (void)loc;
247*418b791dSBob Badour pa = pn->pPrev;
248*418b791dSBob Badour free(pn);
249*418b791dSBob Badour }
250*418b791dSBob Badour }
251*418b791dSBob Badour
252*418b791dSBob Badour _ATTRIBUTE_UNUSED
_allocator_init(_allocator * me,uint8_t * stack,int stackSize)253*418b791dSBob Badour static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSize) {
254*418b791dSBob Badour me->stack = stack;
255*418b791dSBob Badour me->stackEnd = stack + stackSize;
256*418b791dSBob Badour me->nSize = stackSize;
257*418b791dSBob Badour me->pheap = 0;
258*418b791dSBob Badour }
259*418b791dSBob Badour
260*418b791dSBob Badour
261*418b791dSBob Badour #endif // _ALLOCATOR_H
262*418b791dSBob Badour
263*418b791dSBob Badour #ifndef SLIM_H
264*418b791dSBob Badour #define SLIM_H
265*418b791dSBob Badour
266*418b791dSBob Badour #include <stdint.h>
267*418b791dSBob Badour
268*418b791dSBob Badour //a C data structure for the idl types that can be used to implement
269*418b791dSBob Badour //static and dynamic language bindings fairly efficiently.
270*418b791dSBob Badour //
271*418b791dSBob Badour //the goal is to have a minimal ROM and RAM footprint and without
272*418b791dSBob Badour //doing too many allocations. A good way to package these things seemed
273*418b791dSBob Badour //like the module boundary, so all the idls within one module can share
274*418b791dSBob Badour //all the type references.
275*418b791dSBob Badour
276*418b791dSBob Badour
277*418b791dSBob Badour #define PARAMETER_IN 0x0
278*418b791dSBob Badour #define PARAMETER_OUT 0x1
279*418b791dSBob Badour #define PARAMETER_INOUT 0x2
280*418b791dSBob Badour #define PARAMETER_ROUT 0x3
281*418b791dSBob Badour #define PARAMETER_INROUT 0x4
282*418b791dSBob Badour
283*418b791dSBob Badour //the types that we get from idl
284*418b791dSBob Badour #define TYPE_OBJECT 0x0
285*418b791dSBob Badour #define TYPE_INTERFACE 0x1
286*418b791dSBob Badour #define TYPE_PRIMITIVE 0x2
287*418b791dSBob Badour #define TYPE_ENUM 0x3
288*418b791dSBob Badour #define TYPE_STRING 0x4
289*418b791dSBob Badour #define TYPE_WSTRING 0x5
290*418b791dSBob Badour #define TYPE_STRUCTURE 0x6
291*418b791dSBob Badour #define TYPE_UNION 0x7
292*418b791dSBob Badour #define TYPE_ARRAY 0x8
293*418b791dSBob Badour #define TYPE_SEQUENCE 0x9
294*418b791dSBob Badour
295*418b791dSBob Badour //these require the pack/unpack to recurse
296*418b791dSBob Badour //so it's a hint to those languages that can optimize in cases where
297*418b791dSBob Badour //recursion isn't necessary.
298*418b791dSBob Badour #define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE)
299*418b791dSBob Badour #define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION)
300*418b791dSBob Badour #define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY)
301*418b791dSBob Badour #define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE)
302*418b791dSBob Badour
303*418b791dSBob Badour
304*418b791dSBob Badour typedef struct Type Type;
305*418b791dSBob Badour
306*418b791dSBob Badour #define INHERIT_TYPE\
307*418b791dSBob Badour int32_t nativeSize; /*in the simple case its the same as wire size and alignment*/\
308*418b791dSBob Badour union {\
309*418b791dSBob Badour struct {\
310*418b791dSBob Badour const uintptr_t p1;\
311*418b791dSBob Badour const uintptr_t p2;\
312*418b791dSBob Badour } _cast;\
313*418b791dSBob Badour struct {\
314*418b791dSBob Badour uint32_t iid;\
315*418b791dSBob Badour uint32_t bNotNil;\
316*418b791dSBob Badour } object;\
317*418b791dSBob Badour struct {\
318*418b791dSBob Badour const Type *arrayType;\
319*418b791dSBob Badour int32_t nItems;\
320*418b791dSBob Badour } array;\
321*418b791dSBob Badour struct {\
322*418b791dSBob Badour const Type *seqType;\
323*418b791dSBob Badour int32_t nMaxLen;\
324*418b791dSBob Badour } seqSimple; \
325*418b791dSBob Badour struct {\
326*418b791dSBob Badour uint32_t bFloating;\
327*418b791dSBob Badour uint32_t bSigned;\
328*418b791dSBob Badour } prim; \
329*418b791dSBob Badour const SequenceType* seqComplex;\
330*418b791dSBob Badour const UnionType *unionType;\
331*418b791dSBob Badour const StructType *structType;\
332*418b791dSBob Badour int32_t stringMaxLen;\
333*418b791dSBob Badour uint8_t bInterfaceNotNil;\
334*418b791dSBob Badour } param;\
335*418b791dSBob Badour uint8_t type;\
336*418b791dSBob Badour uint8_t nativeAlignment\
337*418b791dSBob Badour
338*418b791dSBob Badour typedef struct UnionType UnionType;
339*418b791dSBob Badour typedef struct StructType StructType;
340*418b791dSBob Badour typedef struct SequenceType SequenceType;
341*418b791dSBob Badour struct Type {
342*418b791dSBob Badour INHERIT_TYPE;
343*418b791dSBob Badour };
344*418b791dSBob Badour
345*418b791dSBob Badour struct SequenceType {
346*418b791dSBob Badour const Type * seqType;
347*418b791dSBob Badour uint32_t nMaxLen;
348*418b791dSBob Badour uint32_t inSize;
349*418b791dSBob Badour uint32_t routSizePrimIn;
350*418b791dSBob Badour uint32_t routSizePrimROut;
351*418b791dSBob Badour };
352*418b791dSBob Badour
353*418b791dSBob Badour //byte offset from the start of the case values for
354*418b791dSBob Badour //this unions case value array. it MUST be aligned
355*418b791dSBob Badour //at the alignment requrements for the descriptor
356*418b791dSBob Badour //
357*418b791dSBob Badour //if negative it means that the unions cases are
358*418b791dSBob Badour //simple enumerators, so the value read from the descriptor
359*418b791dSBob Badour //can be used directly to find the correct case
360*418b791dSBob Badour typedef union CaseValuePtr CaseValuePtr;
361*418b791dSBob Badour union CaseValuePtr {
362*418b791dSBob Badour const uint8_t* value8s;
363*418b791dSBob Badour const uint16_t* value16s;
364*418b791dSBob Badour const uint32_t* value32s;
365*418b791dSBob Badour const uint64_t* value64s;
366*418b791dSBob Badour };
367*418b791dSBob Badour
368*418b791dSBob Badour //these are only used in complex cases
369*418b791dSBob Badour //so I pulled them out of the type definition as references to make
370*418b791dSBob Badour //the type smaller
371*418b791dSBob Badour struct UnionType {
372*418b791dSBob Badour const Type *descriptor;
373*418b791dSBob Badour uint32_t nCases;
374*418b791dSBob Badour const CaseValuePtr caseValues;
375*418b791dSBob Badour const Type * const *cases;
376*418b791dSBob Badour int32_t inSize;
377*418b791dSBob Badour int32_t routSizePrimIn;
378*418b791dSBob Badour int32_t routSizePrimROut;
379*418b791dSBob Badour uint8_t inAlignment;
380*418b791dSBob Badour uint8_t routAlignmentPrimIn;
381*418b791dSBob Badour uint8_t routAlignmentPrimROut;
382*418b791dSBob Badour uint8_t inCaseAlignment;
383*418b791dSBob Badour uint8_t routCaseAlignmentPrimIn;
384*418b791dSBob Badour uint8_t routCaseAlignmentPrimROut;
385*418b791dSBob Badour uint8_t nativeCaseAlignment;
386*418b791dSBob Badour uint8_t bDefaultCase;
387*418b791dSBob Badour };
388*418b791dSBob Badour
389*418b791dSBob Badour struct StructType {
390*418b791dSBob Badour uint32_t nMembers;
391*418b791dSBob Badour const Type * const *members;
392*418b791dSBob Badour int32_t inSize;
393*418b791dSBob Badour int32_t routSizePrimIn;
394*418b791dSBob Badour int32_t routSizePrimROut;
395*418b791dSBob Badour uint8_t inAlignment;
396*418b791dSBob Badour uint8_t routAlignmentPrimIn;
397*418b791dSBob Badour uint8_t routAlignmentPrimROut;
398*418b791dSBob Badour };
399*418b791dSBob Badour
400*418b791dSBob Badour typedef struct Parameter Parameter;
401*418b791dSBob Badour struct Parameter {
402*418b791dSBob Badour INHERIT_TYPE;
403*418b791dSBob Badour uint8_t mode;
404*418b791dSBob Badour uint8_t bNotNil;
405*418b791dSBob Badour };
406*418b791dSBob Badour
407*418b791dSBob Badour #define SLIM_IFPTR32(is32,is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64))
408*418b791dSBob Badour #define SLIM_SCALARS_IS_DYNAMIC(u) (((u) & 0x00ffffff) == 0x00ffffff)
409*418b791dSBob Badour
410*418b791dSBob Badour typedef struct Method Method;
411*418b791dSBob Badour struct Method {
412*418b791dSBob Badour uint32_t uScalars; //no method index
413*418b791dSBob Badour int32_t primInSize;
414*418b791dSBob Badour int32_t primROutSize;
415*418b791dSBob Badour int maxArgs;
416*418b791dSBob Badour int numParams;
417*418b791dSBob Badour const Parameter * const *params;
418*418b791dSBob Badour uint8_t primInAlignment;
419*418b791dSBob Badour uint8_t primROutAlignment;
420*418b791dSBob Badour };
421*418b791dSBob Badour
422*418b791dSBob Badour typedef struct Interface Interface;
423*418b791dSBob Badour
424*418b791dSBob Badour struct Interface {
425*418b791dSBob Badour int nMethods;
426*418b791dSBob Badour const Method * const *methodArray;
427*418b791dSBob Badour int nIIds;
428*418b791dSBob Badour const uint32_t *iids;
429*418b791dSBob Badour const uint16_t* methodStringArray;
430*418b791dSBob Badour const uint16_t* methodStrings;
431*418b791dSBob Badour const char* strings;
432*418b791dSBob Badour };
433*418b791dSBob Badour
434*418b791dSBob Badour
435*418b791dSBob Badour #endif //SLIM_H
436*418b791dSBob Badour
437*418b791dSBob Badour
438*418b791dSBob Badour #ifndef _ADSPMSGD_ADSP_SLIM_H
439*418b791dSBob Badour #define _ADSPMSGD_ADSP_SLIM_H
440*418b791dSBob Badour #include "remote.h"
441*418b791dSBob Badour #include <stdint.h>
442*418b791dSBob Badour
443*418b791dSBob Badour #ifndef __QAIC_SLIM
444*418b791dSBob Badour #define __QAIC_SLIM(ff) ff
445*418b791dSBob Badour #endif
446*418b791dSBob Badour #ifndef __QAIC_SLIM_EXPORT
447*418b791dSBob Badour #define __QAIC_SLIM_EXPORT
448*418b791dSBob Badour #endif
449*418b791dSBob Badour
450*418b791dSBob Badour static const Parameter parameters[3] = {{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)0}}, 2,0x4,0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0}};
451*418b791dSBob Badour static const Parameter* const parameterArrays[5] = {(&(parameters[0])),(&(parameters[1])),(&(parameters[1])),(&(parameters[1])),(&(parameters[2]))};
452*418b791dSBob Badour static const Method methods[2] = {{REMOTE_SCALARS_MAKEX(0,0,0x1,0x1,0x0,0x0),0x10,0x4,5,5,(&(parameterArrays[0])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x0,0x0,0x0,0x0),0x0,0x0,0,0,0,0x0,0x0}};
453*418b791dSBob Badour static const Method* const methodArrays[3] = {&(methods[0]),&(methods[1]),&(methods[1])};
454*418b791dSBob Badour static const char strings[56] = "buff_addr\0ion_flags\0buf_size\0deinit\0filter\0heapid\0init2\0";
455*418b791dSBob Badour static const uint16_t methodStrings[8] = {31,43,10,36,20,0,29,50};
456*418b791dSBob Badour static const uint16_t methodStringsArrays[3] = {0,7,6};
457*418b791dSBob Badour __QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adspmsgd_adsp_slim) = {3,&(methodArrays[0]),0,0,&(methodStringsArrays [0]),methodStrings,strings};
458*418b791dSBob Badour #endif //_ADSPMSGD_ADSP_SLIM_H
459*418b791dSBob Badour #ifdef __cplusplus
460*418b791dSBob Badour extern "C" {
461*418b791dSBob Badour #endif
462*418b791dSBob Badour
463*418b791dSBob Badour #ifndef _const_adspmsgd_adsp_handle
464*418b791dSBob Badour #define _const_adspmsgd_adsp_handle ((remote_handle)-1)
465*418b791dSBob Badour #endif //_const_adspmsgd_adsp_handle
466*418b791dSBob Badour
_adspmsgd_adsp_pls_dtor(void * data)467*418b791dSBob Badour static void _adspmsgd_adsp_pls_dtor(void* data) {
468*418b791dSBob Badour remote_handle* ph = (remote_handle*)data;
469*418b791dSBob Badour if(_const_adspmsgd_adsp_handle != *ph) {
470*418b791dSBob Badour (void)__QAIC_REMOTE(remote_handle_close)(*ph);
471*418b791dSBob Badour *ph = _const_adspmsgd_adsp_handle;
472*418b791dSBob Badour }
473*418b791dSBob Badour }
474*418b791dSBob Badour
_adspmsgd_adsp_pls_ctor(void * ctx,void * data)475*418b791dSBob Badour static int _adspmsgd_adsp_pls_ctor(void* ctx, void* data) {
476*418b791dSBob Badour remote_handle* ph = (remote_handle*)data;
477*418b791dSBob Badour *ph = _const_adspmsgd_adsp_handle;
478*418b791dSBob Badour if(*ph == (remote_handle)-1) {
479*418b791dSBob Badour return __QAIC_REMOTE(remote_handle_open)((const char*)ctx, ph);
480*418b791dSBob Badour }
481*418b791dSBob Badour return 0;
482*418b791dSBob Badour }
483*418b791dSBob Badour
484*418b791dSBob Badour #if (defined __qdsp6__) || (defined __hexagon__)
485*418b791dSBob Badour #pragma weak adsp_pls_add_lookup
486*418b791dSBob Badour extern int adsp_pls_add_lookup(uint32_t type, uint32_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void* ctx), void** ppo);
487*418b791dSBob Badour #pragma weak HAP_pls_add_lookup
488*418b791dSBob Badour extern int HAP_pls_add_lookup(uint32_t type, uint32_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void* ctx), void** ppo);
489*418b791dSBob Badour
_adspmsgd_adsp_handle(void)490*418b791dSBob Badour __QAIC_STUB_EXPORT remote_handle _adspmsgd_adsp_handle(void) {
491*418b791dSBob Badour remote_handle* ph;
492*418b791dSBob Badour if(adsp_pls_add_lookup) {
493*418b791dSBob Badour if(0 == adsp_pls_add_lookup((uint32_t)_adspmsgd_adsp_handle, 0, sizeof(*ph), _adspmsgd_adsp_pls_ctor, "adspmsgd_adsp", _adspmsgd_adsp_pls_dtor, (void**)&ph)) {
494*418b791dSBob Badour return *ph;
495*418b791dSBob Badour }
496*418b791dSBob Badour return (remote_handle)-1;
497*418b791dSBob Badour } else if(HAP_pls_add_lookup) {
498*418b791dSBob Badour if(0 == HAP_pls_add_lookup((uint32_t)_adspmsgd_adsp_handle, 0, sizeof(*ph), _adspmsgd_adsp_pls_ctor, "adspmsgd_adsp", _adspmsgd_adsp_pls_dtor, (void**)&ph)) {
499*418b791dSBob Badour return *ph;
500*418b791dSBob Badour }
501*418b791dSBob Badour return (remote_handle)-1;
502*418b791dSBob Badour }
503*418b791dSBob Badour return(remote_handle)-1;
504*418b791dSBob Badour }
505*418b791dSBob Badour
506*418b791dSBob Badour #else //__qdsp6__ || __hexagon__
507*418b791dSBob Badour
508*418b791dSBob Badour uint32_t _adspmsgd_adsp_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare);
509*418b791dSBob Badour
510*418b791dSBob Badour #ifdef _WIN32
511*418b791dSBob Badour #include "Windows.h"
_adspmsgd_adsp_atomic_CompareAndExchange(uint32_t * volatile puDest,uint32_t uExchange,uint32_t uCompare)512*418b791dSBob Badour uint32_t _adspmsgd_adsp_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare) {
513*418b791dSBob Badour return (uint32_t)InterlockedCompareExchange((volatile LONG*)puDest, (LONG)uExchange, (LONG)uCompare);
514*418b791dSBob Badour }
515*418b791dSBob Badour #elif __GNUC__
_adspmsgd_adsp_atomic_CompareAndExchange(uint32_t * volatile puDest,uint32_t uExchange,uint32_t uCompare)516*418b791dSBob Badour uint32_t _adspmsgd_adsp_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare) {
517*418b791dSBob Badour return __sync_val_compare_and_swap(puDest, uCompare, uExchange);
518*418b791dSBob Badour }
519*418b791dSBob Badour #endif //_WIN32
520*418b791dSBob Badour
521*418b791dSBob Badour
_adspmsgd_adsp_handle(void)522*418b791dSBob Badour __QAIC_STUB_EXPORT remote_handle _adspmsgd_adsp_handle(void) {
523*418b791dSBob Badour static remote_handle handle = _const_adspmsgd_adsp_handle;
524*418b791dSBob Badour if((remote_handle)-1 != handle) {
525*418b791dSBob Badour return handle;
526*418b791dSBob Badour } else {
527*418b791dSBob Badour remote_handle tmp;
528*418b791dSBob Badour int nErr = _adspmsgd_adsp_pls_ctor("adspmsgd_adsp", (void*)&tmp);
529*418b791dSBob Badour if(nErr) {
530*418b791dSBob Badour return (remote_handle)-1;
531*418b791dSBob Badour }
532*418b791dSBob Badour if(((remote_handle)-1 != handle) || ((remote_handle)-1 != (remote_handle)_adspmsgd_adsp_atomic_CompareAndExchange((uint32_t*)&handle, (uint32_t)tmp, (uint32_t)-1))) {
533*418b791dSBob Badour _adspmsgd_adsp_pls_dtor(&tmp);
534*418b791dSBob Badour }
535*418b791dSBob Badour return handle;
536*418b791dSBob Badour }
537*418b791dSBob Badour }
538*418b791dSBob Badour
539*418b791dSBob Badour #endif //__qdsp6__
540*418b791dSBob Badour
__QAIC_STUB(adspmsgd_adsp_skel_invoke)541*418b791dSBob Badour __QAIC_STUB_EXPORT int __QAIC_STUB(adspmsgd_adsp_skel_invoke)(uint32_t _sc, remote_arg* _pra) __QAIC_STUB_ATTRIBUTE {
542*418b791dSBob Badour return __QAIC_REMOTE(remote_handle_invoke)(_adspmsgd_adsp_handle(), _sc, _pra);
543*418b791dSBob Badour }
544*418b791dSBob Badour
545*418b791dSBob Badour #ifdef __cplusplus
546*418b791dSBob Badour }
547*418b791dSBob Badour #endif
548*418b791dSBob Badour
549*418b791dSBob Badour
550*418b791dSBob Badour #ifdef __cplusplus
551*418b791dSBob Badour extern "C" {
552*418b791dSBob Badour #endif
_stub_method(remote_handle _handle,uint32_t _mid,uint32_t _in0[1],uint32_t _in1[1],uint32_t _in2[1],uint32_t _in3[1],uint32_t _rout4[1])553*418b791dSBob Badour static __inline int _stub_method(remote_handle _handle, uint32_t _mid, uint32_t _in0[1], uint32_t _in1[1], uint32_t _in2[1], uint32_t _in3[1], uint32_t _rout4[1]) {
554*418b791dSBob Badour int _numIn[1];
555*418b791dSBob Badour remote_arg _pra[2];
556*418b791dSBob Badour uint32_t _primIn[4];
557*418b791dSBob Badour uint32_t _primROut[1];
558*418b791dSBob Badour int _nErr = 0;
559*418b791dSBob Badour _numIn[0] = 0;
560*418b791dSBob Badour _pra[0].buf.pv = (void*)_primIn;
561*418b791dSBob Badour _pra[0].buf.nLen = sizeof(_primIn);
562*418b791dSBob Badour _pra[(_numIn[0] + 1)].buf.pv = (void*)_primROut;
563*418b791dSBob Badour _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut);
564*418b791dSBob Badour _COPY(_primIn, 0, _in0, 0, 4);
565*418b791dSBob Badour _COPY(_primIn, 4, _in1, 0, 4);
566*418b791dSBob Badour _COPY(_primIn, 8, _in2, 0, 4);
567*418b791dSBob Badour _COPY(_primIn, 12, _in3, 0, 4);
568*418b791dSBob Badour _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 1, 0, 0), _pra));
569*418b791dSBob Badour _COPY(_rout4, 0, _primROut, 0, 4);
570*418b791dSBob Badour _CATCH(_nErr) {}
571*418b791dSBob Badour return _nErr;
572*418b791dSBob Badour }
__QAIC_STUB(adspmsgd_adsp_init)573*418b791dSBob Badour __QAIC_STUB_EXPORT int __QAIC_STUB(adspmsgd_adsp_init)(int heapid, uint32 ion_flags, uint32 filter, uint32 buf_size, int* buff_addr) __QAIC_STUB_ATTRIBUTE {
574*418b791dSBob Badour uint32_t _mid = 0;
575*418b791dSBob Badour return _stub_method(_adspmsgd_adsp_handle(), _mid, (uint32_t*)&heapid, (uint32_t*)&ion_flags, (uint32_t*)&filter, (uint32_t*)&buf_size, (uint32_t*)buff_addr);
576*418b791dSBob Badour }
_stub_method_1(remote_handle _handle,uint32_t _mid)577*418b791dSBob Badour static __inline int _stub_method_1(remote_handle _handle, uint32_t _mid) {
578*418b791dSBob Badour remote_arg* _pra = 0;
579*418b791dSBob Badour int _nErr = 0;
580*418b791dSBob Badour _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _pra));
581*418b791dSBob Badour _CATCH(_nErr) {}
582*418b791dSBob Badour return _nErr;
583*418b791dSBob Badour }
__QAIC_STUB(adspmsgd_adsp_init2)584*418b791dSBob Badour __QAIC_STUB_EXPORT int __QAIC_STUB(adspmsgd_adsp_init2)(void) __QAIC_STUB_ATTRIBUTE {
585*418b791dSBob Badour uint32_t _mid = 1;
586*418b791dSBob Badour return _stub_method_1(_adspmsgd_adsp_handle(), _mid);
587*418b791dSBob Badour }
__QAIC_STUB(adspmsgd_adsp_deinit)588*418b791dSBob Badour __QAIC_STUB_EXPORT int __QAIC_STUB(adspmsgd_adsp_deinit)(void) __QAIC_STUB_ATTRIBUTE {
589*418b791dSBob Badour uint32_t _mid = 2;
590*418b791dSBob Badour return _stub_method_1(_adspmsgd_adsp_handle(), _mid);
591*418b791dSBob Badour }
592*418b791dSBob Badour #ifdef __cplusplus
593*418b791dSBob Badour }
594*418b791dSBob Badour #endif
595*418b791dSBob Badour #endif //_ADSPMSGD_ADSP_STUB_H
596