adsprpc_shared.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2012-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef ADSPRPC_SHARED_H
  7. #define ADSPRPC_SHARED_H
  8. #include <linux/types.h>
  9. #include <linux/cdev.h>
  10. #define FASTRPC_IOCTL_INVOKE _IOWR('R', 1, struct fastrpc_ioctl_invoke)
  11. #define FASTRPC_IOCTL_MMAP _IOWR('R', 2, struct fastrpc_ioctl_mmap)
  12. #define FASTRPC_IOCTL_MUNMAP _IOWR('R', 3, struct fastrpc_ioctl_munmap)
  13. #define FASTRPC_IOCTL_MMAP_64 _IOWR('R', 14, struct fastrpc_ioctl_mmap_64)
  14. #define FASTRPC_IOCTL_MUNMAP_64 _IOWR('R', 15, struct fastrpc_ioctl_munmap_64)
  15. #define FASTRPC_IOCTL_INVOKE_FD _IOWR('R', 4, struct fastrpc_ioctl_invoke_fd)
  16. #define FASTRPC_IOCTL_SETMODE _IOWR('R', 5, uint32_t)
  17. #define FASTRPC_IOCTL_INIT _IOWR('R', 6, struct fastrpc_ioctl_init)
  18. #define FASTRPC_IOCTL_INVOKE_ATTRS \
  19. _IOWR('R', 7, struct fastrpc_ioctl_invoke_attrs)
  20. #define FASTRPC_IOCTL_GETINFO _IOWR('R', 8, uint32_t)
  21. //#define FASTRPC_IOCTL_GETPERF _IOWR('R', 9, struct fastrpc_ioctl_perf)
  22. #define FASTRPC_IOCTL_INIT_ATTRS _IOWR('R', 10, struct fastrpc_ioctl_init_attrs)
  23. #define FASTRPC_IOCTL_INVOKE_CRC _IOWR('R', 11, struct fastrpc_ioctl_invoke_crc)
  24. #define FASTRPC_IOCTL_CONTROL _IOWR('R', 12, struct fastrpc_ioctl_control)
  25. #define FASTRPC_IOCTL_MUNMAP_FD _IOWR('R', 13, struct fastrpc_ioctl_munmap_fd)
  26. #define FASTRPC_IOCTL_GET_DSP_INFO \
  27. _IOWR('R', 17, struct fastrpc_ioctl_capability)
  28. #define FASTRPC_IOCTL_INVOKE2 _IOWR('R', 18, struct fastrpc_ioctl_invoke2)
  29. #define FASTRPC_IOCTL_MEM_MAP _IOWR('R', 19, struct fastrpc_ioctl_mem_map)
  30. #define FASTRPC_IOCTL_MEM_UNMAP _IOWR('R', 20, struct fastrpc_ioctl_mem_unmap)
  31. #define FASTRPC_IOCTL_INVOKE_PERF \
  32. _IOWR('R', 21, struct fastrpc_ioctl_invoke_perf)
  33. #define FASTRPC_IOCTL_NOTIF_RSP \
  34. _IOWR('R', 22, struct fastrpc_ioctl_notif_rsp)
  35. #define FASTRPC_IOCTL_DSPSIGNAL_CREATE _IOWR('R', 23, struct fastrpc_ioctl_dspsignal_create)
  36. #define FASTRPC_IOCTL_DSPSIGNAL_DESTROY _IOWR('R', 24, struct fastrpc_ioctl_dspsignal_destroy)
  37. #define FASTRPC_IOCTL_DSPSIGNAL_SIGNAL _IOWR('R', 25, struct fastrpc_ioctl_dspsignal_signal)
  38. #define FASTRPC_IOCTL_DSPSIGNAL_WAIT _IOWR('R', 26, struct fastrpc_ioctl_dspsignal_wait)
  39. #define FASTRPC_IOCTL_DSPSIGNAL_CANCEL_WAIT \
  40. _IOWR('R', 27, struct fastrpc_ioctl_dspsignal_cancel_wait)
  41. #define FASTRPC_GLINK_GUID "fastrpcglink-apps-dsp"
  42. #define FASTRPC_SMD_GUID "fastrpcsmd-apps-dsp"
  43. #define DEVICE_NAME "adsprpc-smd"
  44. #define DEVICE_NAME_SECURE "adsprpc-smd-secure"
  45. /* Pre-defined parameter for print gfa structure*/
  46. #define smq_invoke_ctx_params "pid: %d, tgid: %d, handle: %d, sc: 0x%x, fl: %p, fd: %p, magic: %d\n"
  47. #define fastrpc_file_params "fl->tgid: %d, fl->cid: %d, fl->ssrcount: %p, fl->pd: %d, fl->profile: %p, fl->mode: %p, fl->tgid_open: %d, fl->num_cached_buf: %d, num_pers_hdrs: %d, fl->sessionid: %d, fl->servloc_name: %s, fl->file_close: %d, fl->dsp_proc_init: %d,fl->apps: %p, fl->qos_request: %d, fl->dev_minor: %d, fl->debug_buf: %s fl->debug_buf_alloced_attempted: %d, fl->wake_enable: %d, fl->ws_timeout: %d, fl->untrusted_process: %d\n"
  48. #define fastrpc_mmap_params "fd: %d, flags: %p, buf: %p, phys: %p, size : %d, va : %p, map->raddr: %p, len : %d, refs : %d, secure: %d\n"
  49. #define fastrpc_buf_params "buf->fl: %p, buf->phys: %p, buf->virt: %p, buf->size: %d, buf->dma_attr: %ld, buf->raddr: %p, buf->flags: %d, buf->type: %d, buf->in_use: %d\n"
  50. /* Set for buffers that have no virtual mapping in userspace */
  51. #define FASTRPC_ATTR_NOVA 0x1
  52. /* Set for buffers that are NOT dma coherent */
  53. #define FASTRPC_ATTR_NON_COHERENT 0x2
  54. /* Set for buffers that are dma coherent */
  55. #define FASTRPC_ATTR_COHERENT 0x4
  56. /* Fastrpc attribute for keeping the map persistent */
  57. #define FASTRPC_ATTR_KEEP_MAP 0x8
  58. /* Fastrpc attribute for no mapping of fd */
  59. #define FASTRPC_ATTR_NOMAP (16)
  60. /*
  61. * Fastrpc attribute to skip flush by fastrpc
  62. */
  63. #define FASTRPC_ATTR_FORCE_NOFLUSH (32)
  64. /*
  65. * Fastrpc attribute to skip invalidate by fastrpc
  66. */
  67. #define FASTRPC_ATTR_FORCE_NOINVALIDATE (64)
  68. /* Driver should operate in parallel with the co-processor */
  69. #define FASTRPC_MODE_PARALLEL 0
  70. /* Driver should operate in serial mode with the co-processor */
  71. #define FASTRPC_MODE_SERIAL 1
  72. /* Driver should operate in profile mode with the co-processor */
  73. #define FASTRPC_MODE_PROFILE 2
  74. /* Set FastRPC session ID to 1 */
  75. #define FASTRPC_MODE_SESSION 4
  76. /* Retrives number of input buffers from the scalars parameter */
  77. #define REMOTE_SCALARS_INBUFS(sc) (((sc) >> 16) & 0x0ff)
  78. /* Retrives number of output buffers from the scalars parameter */
  79. #define REMOTE_SCALARS_OUTBUFS(sc) (((sc) >> 8) & 0x0ff)
  80. /* Retrives number of input handles from the scalars parameter */
  81. #define REMOTE_SCALARS_INHANDLES(sc) (((sc) >> 4) & 0x0f)
  82. /* Retrives number of output handles from the scalars parameter */
  83. #define REMOTE_SCALARS_OUTHANDLES(sc) ((sc) & 0x0f)
  84. /* Remote domains ID */
  85. #define ADSP_DOMAIN_ID (0)
  86. #define MDSP_DOMAIN_ID (1)
  87. #define SDSP_DOMAIN_ID (2)
  88. #define CDSP_DOMAIN_ID (3)
  89. #define MAX_DOMAIN_ID CDSP_DOMAIN_ID
  90. #define NUM_CHANNELS 4 /* adsp, mdsp, slpi, cdsp*/
  91. #define NUM_SESSIONS 14 /* max 11 compute, 3 cpz */
  92. #define VALID_FASTRPC_CID(cid) \
  93. (cid >= ADSP_DOMAIN_ID && cid < NUM_CHANNELS)
  94. #define REMOTE_SCALARS_LENGTH(sc) (REMOTE_SCALARS_INBUFS(sc) +\
  95. REMOTE_SCALARS_OUTBUFS(sc) +\
  96. REMOTE_SCALARS_INHANDLES(sc) +\
  97. REMOTE_SCALARS_OUTHANDLES(sc))
  98. #define REMOTE_SCALARS_MAKEX(attr, method, in, out, oin, oout) \
  99. ((((uint32_t) (attr) & 0x7) << 29) | \
  100. (((uint32_t) (method) & 0x1f) << 24) | \
  101. (((uint32_t) (in) & 0xff) << 16) | \
  102. (((uint32_t) (out) & 0xff) << 8) | \
  103. (((uint32_t) (oin) & 0x0f) << 4) | \
  104. ((uint32_t) (oout) & 0x0f))
  105. #define REMOTE_SCALARS_MAKE(method, in, out) \
  106. REMOTE_SCALARS_MAKEX(0, method, in, out, 0, 0)
  107. #ifdef VERIFY_PRINT_ERROR
  108. #define VERIFY_EPRINTF(format, ...) pr_err(format, ##__VA_ARGS__)
  109. #else
  110. #define VERIFY_EPRINTF(format, args) ((void)0)
  111. #endif
  112. #ifndef VERIFY_PRINT_INFO
  113. #define VERIFY_IPRINTF(args) ((void)0)
  114. #endif
  115. #ifndef VERIFY
  116. #define __STR__(x) #x ":"
  117. #define __TOSTR__(x) __STR__(x)
  118. #define __FILE_LINE__ __FILE__ ":" __TOSTR__(__LINE__)
  119. #define __ADSPRPC_LINE__ "adsprpc:" __TOSTR__(__LINE__)
  120. #define VERIFY(err, val) \
  121. do {\
  122. VERIFY_IPRINTF(__FILE_LINE__"info: calling: " #val "\n");\
  123. if ((val) == 0) {\
  124. (err) = (err) == 0 ? -1 : (err);\
  125. VERIFY_EPRINTF(__ADSPRPC_LINE__" error: %d: "#val "\n", (err));\
  126. } else {\
  127. VERIFY_IPRINTF(__FILE_LINE__"info: passed: " #val "\n");\
  128. } \
  129. } while (0)
  130. #endif
  131. #define ADSPRPC_ERR(fmt, args...)\
  132. pr_err("Error: adsprpc (%d): %s: %s: " fmt, __LINE__,\
  133. current->comm, __func__, ##args)
  134. #define ADSPRPC_INFO(fmt, args...)\
  135. pr_info("Info: adsprpc (%d): %s: %s: " fmt, __LINE__,\
  136. current->comm, __func__, ##args)
  137. #define ADSPRPC_WARN(fmt, args...)\
  138. pr_warn("Warning: adsprpc (%d): %s: %s: " fmt, __LINE__,\
  139. current->comm, __func__, ##args)
  140. #define ADSPRPC_DEBUG(fmt, args...)\
  141. pr_debug("Debug: adsprpc (%d): %s: %s: " fmt, __LINE__,\
  142. current->comm, __func__, ##args)
  143. #define DEBUG_PRINT_SIZE_LIMIT (512*1024)
  144. #define remote_arg64_t union remote_arg64
  145. struct remote_buf64 {
  146. uint64_t pv;
  147. uint64_t len;
  148. };
  149. struct remote_dma_handle64 {
  150. int fd;
  151. uint32_t offset;
  152. uint32_t len;
  153. };
  154. union remote_arg64 {
  155. struct remote_buf64 buf;
  156. struct remote_dma_handle64 dma;
  157. uint32_t h;
  158. };
  159. #define remote_arg_t union remote_arg
  160. struct remote_buf {
  161. void *pv; /* buffer pointer */
  162. size_t len; /* length of buffer */
  163. };
  164. /* structure to hold fd and size of buffer shared with DSP,
  165. * which contains inital debug parameters that needs to be passed
  166. * during process initialization.
  167. */
  168. struct fastrpc_proc_sharedbuf_info {
  169. int buf_fd;
  170. int buf_size;
  171. };
  172. struct remote_dma_handle {
  173. int fd;
  174. uint32_t offset;
  175. };
  176. union remote_arg {
  177. struct remote_buf buf; /* buffer info */
  178. struct remote_dma_handle dma;
  179. uint32_t h; /* remote handle */
  180. };
  181. struct fastrpc_ioctl_invoke {
  182. uint32_t handle; /* remote handle */
  183. uint32_t sc; /* scalars describing the data */
  184. remote_arg_t *pra; /* remote arguments list */
  185. };
  186. struct fastrpc_ioctl_invoke_fd {
  187. struct fastrpc_ioctl_invoke inv;
  188. int *fds; /* fd list */
  189. };
  190. struct fastrpc_ioctl_invoke_attrs {
  191. struct fastrpc_ioctl_invoke inv;
  192. int *fds; /* fd list */
  193. unsigned int *attrs; /* attribute list */
  194. };
  195. struct fastrpc_ioctl_invoke_crc {
  196. struct fastrpc_ioctl_invoke inv;
  197. int *fds; /* fd list */
  198. unsigned int *attrs; /* attribute list */
  199. unsigned int *crc;
  200. };
  201. struct fastrpc_ioctl_invoke_perf {
  202. struct fastrpc_ioctl_invoke inv;
  203. int *fds;
  204. unsigned int *attrs;
  205. unsigned int *crc;
  206. uint64_t *perf_kernel;
  207. uint64_t *perf_dsp;
  208. };
  209. struct fastrpc_async_job {
  210. uint32_t isasyncjob; /* flag to distinguish async job */
  211. uint64_t jobid; /* job id generated by user */
  212. uint32_t reserved; /* reserved */
  213. };
  214. struct fastrpc_ioctl_invoke_async {
  215. struct fastrpc_ioctl_invoke inv;
  216. int *fds; /* fd list */
  217. unsigned int *attrs; /* attribute list */
  218. unsigned int *crc;
  219. uint64_t *perf_kernel;
  220. uint64_t *perf_dsp;
  221. struct fastrpc_async_job *job; /* async job*/
  222. };
  223. struct fastrpc_ioctl_invoke_async_no_perf {
  224. struct fastrpc_ioctl_invoke inv;
  225. int *fds; /* fd list */
  226. unsigned int *attrs; /* attribute list */
  227. unsigned int *crc;
  228. struct fastrpc_async_job *job; /* async job*/
  229. };
  230. struct fastrpc_ioctl_async_response {
  231. uint64_t jobid;/* job id generated by user */
  232. int result; /* result from DSP */
  233. uint64_t *perf_kernel;
  234. uint64_t *perf_dsp;
  235. uint32_t handle;
  236. uint32_t sc;
  237. };
  238. struct fastrpc_ioctl_notif_rsp {
  239. int domain; /* Domain of User PD */
  240. int session; /* Session ID of User PD */
  241. uint32_t status; /* Status of the process */
  242. };
  243. /* FastRPC ioctl structure to set session related info */
  244. struct fastrpc_proc_sess_info {
  245. uint32_t domain_id; /* Set the remote subsystem, Domain ID of the session */
  246. uint32_t session_id; /* Unused, Set the Session ID on remote subsystem */
  247. uint32_t pd_type; /* Set the process type on remote subsystem */
  248. uint32_t sharedcb; /* Unused, Session can share context bank with other sessions */
  249. };
  250. /* INIT a new process or attach to guestos */
  251. enum fastrpc_init_flags {
  252. FASTRPC_INIT_NO_CREATE = -1,
  253. FASTRPC_INIT_ATTACH = 0,
  254. FASTRPC_INIT_CREATE = 1,
  255. FASTRPC_INIT_CREATE_STATIC = 2,
  256. FASTRPC_INIT_ATTACH_SENSORS = 3,
  257. };
  258. enum fastrpc_invoke2_type {
  259. FASTRPC_INVOKE2_ASYNC = 1,
  260. FASTRPC_INVOKE2_ASYNC_RESPONSE = 2,
  261. FASTRPC_INVOKE2_KERNEL_OPTIMIZATIONS,
  262. FASTRPC_INVOKE2_STATUS_NOTIF,
  263. FASTRPC_INVOKE2_PROC_SHAREDBUF_INFO,
  264. /* Set session info of remote sub system */
  265. FASTRPC_INVOKE2_SESS_INFO,
  266. };
  267. struct fastrpc_ioctl_invoke2 {
  268. uint32_t req; /* type of invocation request */
  269. uintptr_t invparam; /* invocation request param */
  270. uint32_t size; /* size of invocation param */
  271. int err; /* reserved */
  272. };
  273. struct fastrpc_ioctl_init {
  274. uint32_t flags; /* one of FASTRPC_INIT_* macros */
  275. uintptr_t file; /* pointer to elf file */
  276. uint32_t filelen; /* elf file length */
  277. int32_t filefd; /* ION fd for the file */
  278. uintptr_t mem; /* mem for the PD */
  279. uint32_t memlen; /* mem length */
  280. int32_t memfd; /* ION fd for the mem */
  281. };
  282. struct fastrpc_ioctl_init_attrs {
  283. struct fastrpc_ioctl_init init;
  284. int attrs;
  285. unsigned int siglen;
  286. };
  287. struct fastrpc_ioctl_munmap {
  288. uintptr_t vaddrout; /* address to unmap */
  289. size_t size; /* size */
  290. };
  291. struct fastrpc_ioctl_munmap_64 {
  292. uint64_t vaddrout; /* address to unmap */
  293. size_t size; /* size */
  294. };
  295. struct fastrpc_ioctl_mmap {
  296. int fd; /* ion fd */
  297. uint32_t flags; /* flags for dsp to map with */
  298. uintptr_t vaddrin; /* optional virtual address */
  299. size_t size; /* size */
  300. uintptr_t vaddrout; /* dsps virtual address */
  301. };
  302. struct fastrpc_ioctl_mmap_64 {
  303. int fd; /* ion fd */
  304. uint32_t flags; /* flags for dsp to map with */
  305. uint64_t vaddrin; /* optional virtual address */
  306. size_t size; /* size */
  307. uint64_t vaddrout; /* dsps virtual address */
  308. };
  309. struct fastrpc_ioctl_munmap_fd {
  310. int fd; /* fd */
  311. uint32_t flags; /* control flags */
  312. uintptr_t va; /* va */
  313. ssize_t len; /* length */
  314. };
  315. struct fastrpc_ioctl_dspsignal_create {
  316. uint32_t signal_id; /* Signal ID */
  317. uint32_t flags; /* Flags, currently unused */
  318. };
  319. struct fastrpc_ioctl_dspsignal_destroy {
  320. uint32_t signal_id; /* Signal ID */
  321. };
  322. struct fastrpc_ioctl_dspsignal_signal {
  323. uint32_t signal_id; /* Signal ID */
  324. };
  325. struct fastrpc_ioctl_dspsignal_wait {
  326. uint32_t signal_id; /* Signal ID */
  327. uint32_t timeout_usec; /* Timeout in microseconds. UINT32_MAX for an infinite wait */
  328. };
  329. struct fastrpc_ioctl_dspsignal_cancel_wait {
  330. uint32_t signal_id; /* Signal ID */
  331. };
  332. /**
  333. * Control flags for mapping memory on DSP user process
  334. */
  335. enum fastrpc_map_flags {
  336. /**
  337. * Map memory pages with RW- permission and CACHE WRITEBACK.
  338. * The driver is responsible for cache maintenance when passed
  339. * the buffer to FastRPC calls. Same virtual address will be
  340. * assigned for subsequent FastRPC calls.
  341. */
  342. FASTRPC_MAP_STATIC = 0,
  343. /* Reserved */
  344. FASTRPC_MAP_RESERVED,
  345. /**
  346. * Map memory pages with RW- permission and CACHE WRITEBACK.
  347. * Mapping tagged with a file descriptor. User is responsible for
  348. * CPU and DSP cache maintenance for the buffer. Get virtual address
  349. * of buffer on DSP using HAP_mmap_get() and HAP_mmap_put() APIs.
  350. */
  351. FASTRPC_MAP_FD = 2,
  352. /**
  353. * Mapping delayed until user call HAP_mmap() and HAP_munmap()
  354. * functions on DSP. It is useful to map a buffer with cache modes
  355. * other than default modes. User is responsible for CPU and DSP
  356. * cache maintenance for the buffer.
  357. */
  358. FASTRPC_MAP_FD_DELAYED,
  359. /**
  360. * This flag is used to skip CPU mapping,
  361. * otherwise behaves similar to FASTRPC_MAP_FD_DELAYED flag.
  362. */
  363. FASTRPC_MAP_FD_NOMAP = 16,
  364. FASTRPC_MAP_MAX,
  365. };
  366. struct fastrpc_mem_map {
  367. int fd; /* ion fd */
  368. int offset; /* buffer offset */
  369. uint32_t flags; /* flags defined in enum fastrpc_map_flags */
  370. int attrs; /* buffer attributes used for SMMU mapping */
  371. uintptr_t vaddrin; /* buffer virtual address */
  372. size_t length; /* buffer length */
  373. uint64_t vaddrout; /* [out] remote virtual address */
  374. };
  375. /* Map and unmap IOCTL methods reserved memory size for future extensions */
  376. #define MAP_RESERVED_NUM (14)
  377. #define UNMAP_RESERVED_NUM (10)
  378. /* map memory to DSP device */
  379. struct fastrpc_ioctl_mem_map {
  380. int version; /* Initial version 0 */
  381. union {
  382. struct fastrpc_mem_map m;
  383. int reserved[MAP_RESERVED_NUM];
  384. };
  385. };
  386. struct fastrpc_mem_unmap {
  387. int fd; /* ion fd */
  388. uint64_t vaddr; /* remote process (dsp) virtual address */
  389. size_t length; /* buffer size */
  390. };
  391. /* unmap memory to DSP device */
  392. struct fastrpc_ioctl_mem_unmap {
  393. int version; /* Initial version 0 */
  394. union {
  395. struct fastrpc_mem_unmap um;
  396. int reserved[UNMAP_RESERVED_NUM];
  397. };
  398. };
  399. /*
  400. * This enum is shared with DSP. So, existing values should NOT
  401. * be modified. Only new members can be added.
  402. */
  403. enum dsp_map_flags {
  404. /* Add memory to static PD pool, protection thru XPU */
  405. ADSP_MMAP_HEAP_ADDR = 4,
  406. /* MAP static DMA buffer on DSP User PD */
  407. ADSP_MMAP_DMA_BUFFER = 6,
  408. /* Add memory to static PD pool, protection thru hypervisor */
  409. ADSP_MMAP_REMOTE_HEAP_ADDR = 8,
  410. /* Add memory to userPD pool, for user heap */
  411. ADSP_MMAP_ADD_PAGES = 0x1000,
  412. /* Add memory to userPD pool, for LLC heap */
  413. ADSP_MMAP_ADD_PAGES_LLC = 0x3000,
  414. /* Map persistent header buffer on DSP */
  415. ADSP_MMAP_PERSIST_HDR = 0x4000,
  416. };
  417. enum fastrpc_control_type {
  418. FASTRPC_CONTROL_LATENCY = 1,
  419. /* Share SMMU context bank */
  420. FASTRPC_CONTROL_SMMU = 2,
  421. FASTRPC_CONTROL_KALLOC = 3,
  422. FASTRPC_CONTROL_WAKELOCK = 4,
  423. FASTRPC_CONTROL_PM = 5,
  424. /* Clean process on DSP */
  425. FASTRPC_CONTROL_DSPPROCESS_CLEAN = 6,
  426. FASTRPC_CONTROL_RPC_POLL = 7,
  427. FASTRPC_CONTROL_ASYNC_WAKE = 8,
  428. FASTRPC_CONTROL_NOTIF_WAKE = 9,
  429. };
  430. struct fastrpc_ctrl_latency {
  431. uint32_t enable; /* latency control enable */
  432. uint32_t latency; /* latency request in us */
  433. };
  434. struct fastrpc_ctrl_kalloc {
  435. uint32_t kalloc_support; /* Remote memory allocation from kernel */
  436. };
  437. struct fastrpc_ctrl_wakelock {
  438. uint32_t enable; /* wakelock control enable */
  439. };
  440. struct fastrpc_ctrl_pm {
  441. uint32_t timeout; /* timeout(in ms) for PM to keep system awake */
  442. };
  443. struct fastrpc_ctrl_smmu {
  444. uint32_t sharedcb; /* Set to SMMU share context bank */
  445. };
  446. struct fastrpc_ioctl_control {
  447. uint32_t req;
  448. union {
  449. struct fastrpc_ctrl_latency lp;
  450. struct fastrpc_ctrl_kalloc kalloc;
  451. struct fastrpc_ctrl_wakelock wp;
  452. struct fastrpc_ctrl_pm pm;
  453. struct fastrpc_ctrl_smmu smmu;
  454. };
  455. };
  456. #define FASTRPC_MAX_DSP_ATTRIBUTES (256)
  457. #define FASTRPC_MAX_ATTRIBUTES (260)
  458. enum fastrpc_dsp_capability {
  459. ASYNC_FASTRPC_CAP = 9,
  460. DMA_HANDLE_REVERSE_RPC_CAP = 129,
  461. };
  462. struct fastrpc_ioctl_capability {
  463. uint32_t domain;
  464. uint32_t attribute_ID;
  465. uint32_t capability;
  466. };
  467. struct smq_null_invoke {
  468. uint64_t ctx; /* invoke caller context */
  469. uint32_t handle; /* handle to invoke */
  470. uint32_t sc; /* scalars structure describing the data */
  471. };
  472. struct smq_phy_page {
  473. uint64_t addr; /* physical address */
  474. uint64_t size; /* size of contiguous region */
  475. };
  476. struct smq_invoke_buf {
  477. int num; /* number of contiguous regions */
  478. int pgidx; /* index to start of contiguous region */
  479. };
  480. struct smq_invoke {
  481. struct smq_null_invoke header;
  482. struct smq_phy_page page; /* remote arg and list of pages address */
  483. };
  484. struct smq_msg {
  485. uint32_t pid; /* process group id */
  486. uint32_t tid; /* thread id */
  487. struct smq_invoke invoke;
  488. };
  489. struct smq_invoke_rsp {
  490. uint64_t ctx; /* invoke caller context */
  491. int retval; /* invoke return value */
  492. };
  493. enum fastrpc_response_flags {
  494. NORMAL_RESPONSE = 0,
  495. EARLY_RESPONSE = 1,
  496. USER_EARLY_SIGNAL = 2,
  497. COMPLETE_SIGNAL = 3,
  498. STATUS_RESPONSE = 4,
  499. POLL_MODE = 5,
  500. };
  501. enum fastrpc_process_create_state {
  502. PROCESS_CREATE_DEFAULT = 0, /* Process is not created */
  503. PROCESS_CREATE_IS_INPROGRESS = 1, /* Process creation is in progress */
  504. PROCESS_CREATE_SUCCESS = 2, /* Process creation is successful */
  505. };
  506. struct smq_invoke_rspv2 {
  507. uint64_t ctx; /* invoke caller context */
  508. int retval; /* invoke return value */
  509. uint32_t flags; /* early response flags */
  510. uint32_t early_wake_time; /* user predicted early wakeup time in us */
  511. uint32_t version; /* Version number for validation */
  512. };
  513. enum fastrpc_status_flags {
  514. FASTRPC_USERPD_UP = 0,
  515. FASTRPC_USERPD_EXIT = 1,
  516. FASTRPC_USERPD_FORCE_KILL = 2,
  517. FASTRPC_USERPD_EXCEPTION = 3,
  518. FASTRPC_DSP_SSR = 4,
  519. };
  520. struct smq_notif_rspv3 {
  521. uint64_t ctx; /* response context */
  522. uint32_t type; /* Notification type */
  523. int pid; /* user process pid */
  524. uint32_t status; /* userpd status notification */
  525. };
  526. enum fastrpc_process_exit_states {
  527. /* Process Default State */
  528. FASTRPC_PROCESS_DEFAULT_STATE = 0,
  529. /* Process exit initiated */
  530. FASTRPC_PROCESS_EXIT_START = 1,
  531. /* Process exit issued to DSP */
  532. FASTRPC_PROCESS_DSP_EXIT_INIT = 2,
  533. /* Process exit in DSP complete */
  534. FASTRPC_PROCESS_DSP_EXIT_COMPLETE = 3,
  535. /* Process exit in DSP error */
  536. FASTRPC_PROCESS_DSP_EXIT_ERROR = 4,
  537. };
  538. /*
  539. * Process types on remote subsystem
  540. * Always add new PD types at the end, before MAX_PD_TYPE
  541. */
  542. #define DEFAULT_UNUSED 0 /* pd type not configured for context banks */
  543. #define ROOT_PD 1 /* Root PD */
  544. #define AUDIO_STATICPD 2 /* ADSP Audio Static PD */
  545. #define SENSORS_STATICPD 3 /* ADSP Sensors Static PD */
  546. #define SECURE_STATICPD 4 /* CDSP Secure Static PD */
  547. #define OIS_STATICPD 5 /* ADSP OIS Static PD */
  548. #define CPZ_USERPD 6 /* CDSP CPZ USER PD */
  549. #define USERPD 7 /* DSP User Dynamic PD */
  550. #define GUEST_OS_SHARED 8 /* Legacy Guest OS Shared */
  551. #define MAX_PD_TYPE 9 /* Max PD type */
  552. struct fastrpc_file;
  553. int fastrpc_transport_send(int cid, void *rpc_msg, uint32_t rpc_msg_size, int tvm_remote_domain);
  554. inline int fastrpc_handle_rpc_response(void *data, int len, int cid);
  555. inline int verify_transport_device(int cid, int tvm_remote_domain);
  556. int fastrpc_transport_init(void);
  557. void fastrpc_transport_deinit(void);
  558. void fastrpc_transport_session_init(int cid, char *subsys);
  559. void fastrpc_transport_session_deinit(int cid);
  560. int fastrpc_wait_for_transport_interrupt(int cid, unsigned int flags);
  561. int fastrpc_set_tvm_remote_domain(struct fastrpc_file *fl, struct fastrpc_ioctl_init *init);
  562. void fastrpc_restart_drivers(int cid);
  563. static inline struct smq_invoke_buf *smq_invoke_buf_start(remote_arg64_t *pra,
  564. uint32_t sc)
  565. {
  566. unsigned int len = REMOTE_SCALARS_LENGTH(sc);
  567. return (struct smq_invoke_buf *)(&pra[len]);
  568. }
  569. static inline struct smq_phy_page *smq_phy_page_start(uint32_t sc,
  570. struct smq_invoke_buf *buf)
  571. {
  572. unsigned int nTotal = REMOTE_SCALARS_LENGTH(sc);
  573. return (struct smq_phy_page *)(&buf[nTotal]);
  574. }
  575. /*
  576. * Fastrpc context ID bit-map:
  577. *
  578. * bits 0-3 : type of remote PD
  579. * bit 4 : type of job (sync/async)
  580. * bit 5 : reserved
  581. * bits 6-15 : index in context table
  582. * bits 16-63 : incrementing context ID
  583. */
  584. #define FASTRPC_CTX_MAX (1024)
  585. /* Length of glink transaction history to store */
  586. #define GLINK_MSG_HISTORY_LEN (128)
  587. /* Type of fastrpc DMA bufs sent to DSP */
  588. enum fastrpc_buf_type {
  589. METADATA_BUF,
  590. COPYDATA_BUF,
  591. INITMEM_BUF,
  592. USERHEAP_BUF,
  593. };
  594. /* Types of RPC calls to DSP */
  595. enum fastrpc_msg_type {
  596. USER_MSG = 0,
  597. KERNEL_MSG_WITH_ZERO_PID,
  598. KERNEL_MSG_WITH_NONZERO_PID,
  599. };
  600. /* Fastrpc remote pd type */
  601. enum fastrpc_remote_pd_type {
  602. FASTRPC_ROOT_PD = 0,
  603. FASTRPC_USER_PD,
  604. FASTRPC_SENSORS_PD,
  605. };
  606. #define DSPSIGNAL_TIMEOUT_NONE 0xffffffff
  607. #define DSPSIGNAL_NUM_SIGNALS 1024
  608. // Signal state and completions are stored in groups of DSPSIGNAL_GROUP_SIZE.
  609. // Must be a power of two.
  610. #define DSPSIGNAL_GROUP_SIZE 256
  611. struct secure_vm {
  612. int *vmid;
  613. int *vmperm;
  614. int vmcount;
  615. };
  616. struct gid_list {
  617. unsigned int *gids;
  618. unsigned int gidcount;
  619. };
  620. struct fastrpc_buf {
  621. struct hlist_node hn;
  622. struct hlist_node hn_rem;
  623. struct hlist_node hn_init;
  624. struct fastrpc_file *fl;
  625. void *virt;
  626. uint64_t phys;
  627. size_t size;
  628. unsigned long dma_attr;
  629. uintptr_t raddr;
  630. uint32_t flags;
  631. int type; /* One of "fastrpc_buf_type" */
  632. bool in_use; /* Used only for persistent header buffers */
  633. struct timespec64 buf_start_time;
  634. struct timespec64 buf_end_time;
  635. };
  636. struct fastrpc_ctx_lst;
  637. struct fastrpc_tx_msg {
  638. struct smq_msg msg; /* Msg sent to remote subsystem */
  639. int transport_send_err; /* transport error */
  640. int64_t ns; /* Timestamp (in ns) of msg */
  641. uint64_t xo_time_in_us; /* XO Timestamp (in us) of sent message */
  642. uint64_t xo_time_in_us_interrupted; /* XO Timestamp (in us) of interrupted ctx */
  643. uint64_t xo_time_in_us_restored; /* XO Timestamp (in us) of restored ctx */
  644. };
  645. struct fastrpc_rx_msg {
  646. struct smq_invoke_rspv2 rsp; /* Response from remote subsystem */
  647. int64_t ns; /* Timestamp (in ns) of response */
  648. uint64_t xo_time_in_us; /* XO Timestamp (in us) of response */
  649. };
  650. struct fastrpc_transport_log {
  651. unsigned int tx_index; /* Current index of 'tx_msgs' array */
  652. unsigned int rx_index; /* Current index of 'rx_msgs' array */
  653. /* Rolling history of messages sent to remote subsystem */
  654. struct fastrpc_tx_msg tx_msgs[GLINK_MSG_HISTORY_LEN];
  655. /* Rolling history of responses from remote subsystem */
  656. struct fastrpc_rx_msg rx_msgs[GLINK_MSG_HISTORY_LEN];
  657. spinlock_t lock;
  658. };
  659. struct overlap {
  660. uintptr_t start;
  661. uintptr_t end;
  662. int raix;
  663. uintptr_t mstart;
  664. uintptr_t mend;
  665. uintptr_t offset;
  666. int do_cmo; /*used for cache maintenance of inrout buffers*/
  667. };
  668. struct fastrpc_perf {
  669. uint64_t count;
  670. uint64_t flush;
  671. uint64_t map;
  672. uint64_t copy;
  673. uint64_t link;
  674. uint64_t getargs;
  675. uint64_t putargs;
  676. uint64_t invargs;
  677. uint64_t invoke;
  678. uint64_t tid;
  679. };
  680. struct smq_notif_rsp {
  681. struct list_head notifn;
  682. int domain;
  683. int session;
  684. enum fastrpc_status_flags status;
  685. };
  686. struct smq_invoke_ctx {
  687. struct hlist_node hn;
  688. /* Async node to add to async job ctx list */
  689. struct list_head asyncn;
  690. struct completion work;
  691. int retval;
  692. int pid;
  693. int tgid;
  694. remote_arg_t *lpra;
  695. remote_arg64_t *rpra;
  696. remote_arg64_t *lrpra; /* Local copy of rpra for put_args */
  697. int *fds;
  698. unsigned int *attrs;
  699. struct fastrpc_mmap **maps;
  700. struct fastrpc_buf *buf;
  701. struct fastrpc_buf *copybuf; /*used to copy non-ion buffers */
  702. size_t used;
  703. struct fastrpc_file *fl;
  704. uint32_t handle;
  705. uint32_t sc;
  706. struct overlap *overs;
  707. struct overlap **overps;
  708. struct smq_msg msg;
  709. uint32_t *crc;
  710. uint64_t *perf_kernel;
  711. uint64_t *perf_dsp;
  712. unsigned int magic;
  713. uint64_t ctxid;
  714. struct fastrpc_perf *perf;
  715. /* response flags from remote processor */
  716. enum fastrpc_response_flags rsp_flags;
  717. /* user hint of completion time in us */
  718. uint32_t early_wake_time;
  719. /* work done status flag */
  720. bool is_work_done;
  721. /* Store Async job in the context*/
  722. struct fastrpc_async_job asyncjob;
  723. /* Async early flag to check the state of context */
  724. bool is_early_wakeup;
  725. uint32_t sc_interrupted;
  726. struct fastrpc_file *fl_interrupted;
  727. uint32_t handle_interrupted;
  728. uint64_t xo_time_in_us_created; /* XO Timestamp (in us) of ctx creation */
  729. uint64_t xo_time_in_us_interrupted; /* XO Timestamp (in us) of interrupted ctx */
  730. uint64_t xo_time_in_us_restored; /* XO Timestamp (in us) of restored ctx */
  731. int tx_index; /* index of current ctx in channel gmsg_log array */
  732. bool is_job_sent_to_remote_ss; /* Flag to check if job is sent to remote sub system */
  733. };
  734. struct fastrpc_ctx_lst {
  735. struct hlist_head pending;
  736. struct hlist_head interrupted;
  737. /* Number of active contexts queued to DSP */
  738. uint32_t num_active_ctxs;
  739. /* Queue which holds all async job contexts of process */
  740. struct list_head async_queue;
  741. /* Queue which holds all status notifications of process */
  742. struct list_head notif_queue;
  743. };
  744. struct fastrpc_smmu {
  745. struct device *dev;
  746. const char *dev_name;
  747. int cb;
  748. int enabled;
  749. int faults;
  750. int secure;
  751. int coherent;
  752. int sharedcb;
  753. int pd_type; /* Process type on remote sub system */
  754. /* gen pool for QRTR */
  755. struct gen_pool *frpc_genpool;
  756. /* fastrpc gen pool buffer */
  757. struct fastrpc_buf *frpc_genpool_buf;
  758. /* fastrpc gen pool buffer fixed IOVA */
  759. unsigned long genpool_iova;
  760. /* fastrpc gen pool buffer size */
  761. size_t genpool_size;
  762. };
  763. struct fastrpc_session_ctx {
  764. struct device *dev;
  765. struct fastrpc_smmu smmu;
  766. int used;
  767. };
  768. struct fastrpc_static_pd {
  769. char *servloc_name;
  770. char *spdname;
  771. void *pdrhandle;
  772. uint64_t pdrcount;
  773. uint64_t prevpdrcount;
  774. atomic_t ispdup;
  775. int cid;
  776. wait_queue_head_t wait_for_pdup;
  777. };
  778. struct fastrpc_dsp_capabilities {
  779. uint32_t is_cached; //! Flag if dsp attributes are cached
  780. uint32_t dsp_attributes[FASTRPC_MAX_DSP_ATTRIBUTES];
  781. };
  782. struct fastrpc_channel_ctx {
  783. char *name;
  784. char *subsys;
  785. struct device *dev;
  786. struct fastrpc_session_ctx session[NUM_SESSIONS];
  787. struct fastrpc_static_pd spd[NUM_SESSIONS];
  788. struct completion work;
  789. struct completion workport;
  790. struct notifier_block nb;
  791. struct mutex smd_mutex;
  792. uint64_t sesscount;
  793. uint64_t ssrcount;
  794. int in_hib;
  795. void *handle;
  796. uint64_t prevssrcount;
  797. int subsystemstate;
  798. int vmid;
  799. struct secure_vm rhvm;
  800. void *rh_dump_dev;
  801. /* Indicates, if channel is restricted to secure node only */
  802. int secure;
  803. /* Indicates whether the channel supports unsigned PD */
  804. bool unsigned_support;
  805. struct fastrpc_dsp_capabilities dsp_cap_kernel;
  806. /* cpu capabilities shared to DSP */
  807. uint64_t cpuinfo_todsp;
  808. bool cpuinfo_status;
  809. struct smq_invoke_ctx *ctxtable[FASTRPC_CTX_MAX];
  810. spinlock_t ctxlock;
  811. struct fastrpc_transport_log gmsg_log;
  812. struct hlist_head initmems;
  813. /* Store gfa structure debug details */
  814. struct fastrpc_buf *buf;
  815. };
  816. struct fastrpc_apps {
  817. struct fastrpc_channel_ctx *channel;
  818. struct cdev cdev;
  819. struct class *class;
  820. struct smq_phy_page range;
  821. struct hlist_head maps;
  822. uint32_t staticpd_flags;
  823. dev_t dev_no;
  824. int compat;
  825. struct hlist_head drivers;
  826. spinlock_t hlock;
  827. struct device *dev;
  828. /* Indicates fastrpc device node info */
  829. struct device *dev_fastrpc;
  830. unsigned int latency;
  831. int transport_initialized;
  832. /* Flag to determine fastrpc bus registration */
  833. int fastrpc_bus_register;
  834. bool legacy_remote_heap;
  835. /* Unique job id for each message */
  836. uint64_t jobid[NUM_CHANNELS];
  837. struct gid_list gidlist;
  838. struct device *secure_dev;
  839. struct device *non_secure_dev;
  840. /* Secure subsystems like ADSP/SLPI will use secure client */
  841. struct wakeup_source *wake_source_secure;
  842. /* Non-secure subsystem like CDSP will use regular client */
  843. struct wakeup_source *wake_source;
  844. uint32_t duplicate_rsp_err_cnt;
  845. uint32_t max_size_limit;
  846. struct hlist_head frpc_devices;
  847. struct hlist_head frpc_drivers;
  848. struct mutex mut_uid;
  849. /* Indicates cdsp device status */
  850. int remote_cdsp_status;
  851. /* Indicates secure context bank to be shared */
  852. int share_securecb;
  853. /* Indicates process type is configured for SMMU context bank */
  854. bool cb_pd_type;
  855. /* Number of lowest capacity cores for given platform */
  856. unsigned int lowest_capacity_core_count;
  857. /* Flag to check if PM QoS vote needs to be done for only one core */
  858. bool single_core_latency_vote;
  859. };
  860. struct fastrpc_mmap {
  861. struct hlist_node hn;
  862. struct fastrpc_file *fl;
  863. struct fastrpc_apps *apps;
  864. int fd;
  865. uint32_t flags;
  866. struct dma_buf *buf;
  867. struct sg_table *table;
  868. struct dma_buf_attachment *attach;
  869. struct ion_handle *handle;
  870. uint64_t phys;
  871. size_t size;
  872. uintptr_t va;
  873. size_t len;
  874. int refs;
  875. uintptr_t raddr;
  876. int secure;
  877. bool is_persistent; /* the map is persistenet across sessions */
  878. int frpc_md_index; /* Minidump unique index */
  879. uintptr_t attr;
  880. bool in_use; /* Indicates if persistent map is in use*/
  881. struct timespec64 map_start_time;
  882. struct timespec64 map_end_time;
  883. /* Mapping for fastrpc shell */
  884. bool is_filemap;
  885. char *servloc_name; /* Indicate which daemon mapped this */
  886. /* Indicates map is being used by a pending RPC call */
  887. unsigned int ctx_refs;
  888. };
  889. enum fastrpc_perfkeys {
  890. PERF_COUNT = 0,
  891. PERF_FLUSH = 1,
  892. PERF_MAP = 2,
  893. PERF_COPY = 3,
  894. PERF_LINK = 4,
  895. PERF_GETARGS = 5,
  896. PERF_PUTARGS = 6,
  897. PERF_INVARGS = 7,
  898. PERF_INVOKE = 8,
  899. PERF_TID = 9,
  900. PERF_KEY_MAX = 10,
  901. };
  902. struct fastrpc_notif_queue {
  903. /* Number of pending status notifications in queue */
  904. atomic_t notif_queue_count;
  905. /* Wait queue to synchronize notifier thread and response */
  906. wait_queue_head_t notif_wait_queue;
  907. /* IRQ safe spin lock for protecting notif queue */
  908. spinlock_t nqlock;
  909. };
  910. enum fastrpc_dspsignal_state {
  911. DSPSIGNAL_STATE_UNUSED = 0,
  912. DSPSIGNAL_STATE_PENDING,
  913. DSPSIGNAL_STATE_SIGNALED,
  914. DSPSIGNAL_STATE_CANCELED
  915. };
  916. struct fastrpc_dspsignal {
  917. struct completion comp;
  918. int state;
  919. };
  920. struct fastrpc_file {
  921. struct hlist_node hn;
  922. spinlock_t hlock;
  923. struct hlist_head maps;
  924. struct hlist_head cached_bufs;
  925. uint32_t num_cached_buf;
  926. struct hlist_head remote_bufs;
  927. struct fastrpc_ctx_lst clst;
  928. struct fastrpc_session_ctx *sctx;
  929. struct fastrpc_buf *init_mem;
  930. /* No. of persistent headers */
  931. unsigned int num_pers_hdrs;
  932. /* Pre-allocated header buffer */
  933. struct fastrpc_buf *pers_hdr_buf;
  934. /* Pre-allocated buffer divided into N chunks */
  935. struct fastrpc_buf *hdr_bufs;
  936. struct fastrpc_session_ctx *secsctx;
  937. uint32_t mode;
  938. uint32_t profile;
  939. int sessionid;
  940. int tgid_open; /* Process ID during device open */
  941. int tgid; /* Process ID that uses device for RPC calls */
  942. int cid;
  943. int tvm_remote_domain;
  944. uint64_t ssrcount;
  945. int pd;
  946. char *servloc_name;
  947. int file_close;
  948. int dsp_proc_init;
  949. int sharedcb;
  950. int pd_type; /* Process type on remote subsystem */
  951. struct fastrpc_apps *apps;
  952. struct dentry *debugfs_file;
  953. struct dev_pm_qos_request *dev_pm_qos_req;
  954. int qos_request;
  955. struct mutex map_mutex;
  956. struct mutex internal_map_mutex;
  957. /* Identifies the device (MINOR_NUM_DEV / MINOR_NUM_SECURE_DEV) */
  958. int dev_minor;
  959. char *debug_buf;
  960. /* Flag to indicate attempt has been made to allocate memory for debug_buf*/
  961. int debug_buf_alloced_attempted;
  962. /* Flag to enable PM wake/relax voting for every remote invoke */
  963. int wake_enable;
  964. struct gid_list gidlist;
  965. /* Number of jobs pending in Async Queue */
  966. atomic_t async_queue_job_count;
  967. /* Async wait queue to synchronize glink response and async thread */
  968. wait_queue_head_t async_wait_queue;
  969. /* IRQ safe spin lock for protecting async queue */
  970. spinlock_t aqlock;
  971. /* Process status notification queue */
  972. struct fastrpc_notif_queue proc_state_notif;
  973. uint32_t ws_timeout;
  974. bool untrusted_process;
  975. struct fastrpc_device *device;
  976. /* Process kill will wait on work when ram dump collection in progress */
  977. struct completion work;
  978. /* Flag to indicate ram dump collection status*/
  979. bool is_ramdump_pend;
  980. /* Process kill will wait on bus driver invoke thread to complete its process */
  981. struct completion dma_invoke;
  982. /* Flag to indicate invoke pending */
  983. bool is_dma_invoke_pend;
  984. /* Flag to indicate type of process (static, dynamic) */
  985. uint32_t proc_flags;
  986. /* If set, threads will poll for DSP response instead of glink wait */
  987. bool poll_mode;
  988. /* Threads poll for specified timeout and fall back to glink wait */
  989. uint32_t poll_timeout;
  990. /* Flag to indicate dynamic process creation status*/
  991. enum fastrpc_process_create_state dsp_process_state;
  992. bool is_unsigned_pd;
  993. /* Flag to indicate 32 bit driver*/
  994. bool is_compat;
  995. /* Completion objects and state for dspsignals */
  996. struct fastrpc_dspsignal *signal_groups[DSPSIGNAL_NUM_SIGNALS / DSPSIGNAL_GROUP_SIZE];
  997. spinlock_t dspsignals_lock;
  998. struct mutex signal_create_mutex;
  999. struct completion shutdown;
  1000. /* Flag to indicate notif thread exit requested*/
  1001. bool exit_notif;
  1002. /* Flag to indicate async thread exit requested*/
  1003. bool exit_async;
  1004. /*
  1005. * structure to hold fd and size of buffer shared with DSP,
  1006. * which contains initial debug configurations and other initial
  1007. * config paramters.
  1008. */
  1009. struct fastrpc_proc_sharedbuf_info sharedbuf_info;
  1010. };
  1011. union fastrpc_ioctl_param {
  1012. struct fastrpc_ioctl_invoke_async inv;
  1013. struct fastrpc_ioctl_mem_map mem_map;
  1014. struct fastrpc_ioctl_mem_unmap mem_unmap;
  1015. struct fastrpc_ioctl_mmap mmap;
  1016. struct fastrpc_ioctl_mmap_64 mmap64;
  1017. struct fastrpc_ioctl_munmap munmap;
  1018. struct fastrpc_ioctl_munmap_64 munmap64;
  1019. struct fastrpc_ioctl_munmap_fd munmap_fd;
  1020. struct fastrpc_ioctl_init_attrs init;
  1021. struct fastrpc_ioctl_control cp;
  1022. struct fastrpc_ioctl_capability cap;
  1023. struct fastrpc_ioctl_invoke2 inv2;
  1024. struct fastrpc_ioctl_dspsignal_signal sig;
  1025. struct fastrpc_ioctl_dspsignal_wait wait;
  1026. struct fastrpc_ioctl_dspsignal_create cre;
  1027. struct fastrpc_ioctl_dspsignal_destroy des;
  1028. struct fastrpc_ioctl_dspsignal_cancel_wait canc;
  1029. };
  1030. int fastrpc_internal_invoke(struct fastrpc_file *fl, uint32_t mode,
  1031. uint32_t kernel,
  1032. struct fastrpc_ioctl_invoke_async *inv);
  1033. int fastrpc_internal_invoke2(struct fastrpc_file *fl,
  1034. struct fastrpc_ioctl_invoke2 *inv2);
  1035. int fastrpc_internal_munmap(struct fastrpc_file *fl,
  1036. struct fastrpc_ioctl_munmap *ud);
  1037. int fastrpc_internal_mem_map(struct fastrpc_file *fl,
  1038. struct fastrpc_ioctl_mem_map *ud);
  1039. int fastrpc_internal_mem_unmap(struct fastrpc_file *fl,
  1040. struct fastrpc_ioctl_mem_unmap *ud);
  1041. int fastrpc_internal_mmap(struct fastrpc_file *fl,
  1042. struct fastrpc_ioctl_mmap *ud);
  1043. int fastrpc_init_process(struct fastrpc_file *fl,
  1044. struct fastrpc_ioctl_init_attrs *uproc);
  1045. int fastrpc_get_info(struct fastrpc_file *fl, uint32_t *info);
  1046. int fastrpc_internal_control(struct fastrpc_file *fl,
  1047. struct fastrpc_ioctl_control *cp);
  1048. int fastrpc_setmode(unsigned long ioctl_param,
  1049. struct fastrpc_file *fl);
  1050. int fastrpc_get_info_from_kernel(
  1051. struct fastrpc_ioctl_capability *cap,
  1052. struct fastrpc_file *fl);
  1053. int fastrpc_dspsignal_signal(struct fastrpc_file *fl,
  1054. struct fastrpc_ioctl_dspsignal_signal *sig);
  1055. int fastrpc_dspsignal_wait(struct fastrpc_file *fl,
  1056. struct fastrpc_ioctl_dspsignal_wait *wait);
  1057. int fastrpc_dspsignal_create(struct fastrpc_file *fl,
  1058. struct fastrpc_ioctl_dspsignal_create *create);
  1059. int fastrpc_dspsignal_destroy(struct fastrpc_file *fl,
  1060. struct fastrpc_ioctl_dspsignal_destroy *destroy);
  1061. int fastrpc_dspsignal_cancel_wait(struct fastrpc_file *fl,
  1062. struct fastrpc_ioctl_dspsignal_cancel_wait *cancel);
  1063. void fastrpc_rproc_trace_events(const char *name, const char *event,
  1064. const char *subevent);
  1065. #endif