adsprpc_shared.h 27 KB

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