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