msm_cvp_dsp.c 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/module.h>
  6. #include <linux/rpmsg.h>
  7. #include <linux/of_platform.h>
  8. #include <linux/of_fdt.h>
  9. #include <linux/qcom_scm.h>
  10. #include <soc/qcom/secure_buffer.h>
  11. #include "msm_cvp_core.h"
  12. #include "msm_cvp.h"
  13. #include "cvp_hfi.h"
  14. #include "cvp_dump.h"
  15. static atomic_t nr_maps;
  16. struct cvp_dsp_apps gfa_cv;
  17. static int cvp_reinit_dsp(void);
  18. static void cvp_remove_dsp_sessions(void);
  19. static int __fastrpc_driver_register(struct fastrpc_driver *driver)
  20. {
  21. #ifdef CVP_FASTRPC_ENABLED
  22. return fastrpc_driver_register(driver);
  23. #else
  24. return -ENODEV;
  25. #endif
  26. }
  27. static void __fastrpc_driver_unregister(struct fastrpc_driver *driver)
  28. {
  29. #ifdef CVP_FASTRPC_ENABLED
  30. return fastrpc_driver_unregister(driver);
  31. #endif
  32. }
  33. #ifdef CVP_FASTRPC_ENABLED
  34. static int __fastrpc_driver_invoke(struct fastrpc_device *dev,
  35. enum fastrpc_driver_invoke_nums invoke_num,
  36. unsigned long invoke_param)
  37. {
  38. return fastrpc_driver_invoke(dev, invoke_num, invoke_param);
  39. }
  40. #endif /* End of CVP_FASTRPC_ENABLED */
  41. static int cvp_dsp_send_cmd(struct cvp_dsp_cmd_msg *cmd, uint32_t len)
  42. {
  43. int rc = 0;
  44. struct cvp_dsp_apps *me = &gfa_cv;
  45. dprintk(CVP_DSP, "%s: cmd = %d\n", __func__, cmd->type);
  46. if (IS_ERR_OR_NULL(me->chan)) {
  47. dprintk(CVP_ERR, "%s: DSP GLink is not ready\n", __func__);
  48. rc = -EINVAL;
  49. goto exit;
  50. }
  51. rc = rpmsg_send(me->chan->ept, cmd, len);
  52. if (rc) {
  53. dprintk(CVP_ERR, "%s: DSP rpmsg_send failed rc=%d\n",
  54. __func__, rc);
  55. goto exit;
  56. }
  57. exit:
  58. return rc;
  59. }
  60. static int cvp_dsp_send_cmd_sync(struct cvp_dsp_cmd_msg *cmd,
  61. uint32_t len, struct cvp_dsp_rsp_msg *rsp)
  62. {
  63. int rc = 0;
  64. struct cvp_dsp_apps *me = &gfa_cv;
  65. dprintk(CVP_DSP, "%s: cmd = %d\n", __func__, cmd->type);
  66. me->pending_dsp2cpu_rsp.type = cmd->type;
  67. rc = cvp_dsp_send_cmd(cmd, len);
  68. if (rc) {
  69. dprintk(CVP_ERR, "%s: cvp_dsp_send_cmd failed rc=%d\n",
  70. __func__, rc);
  71. goto exit;
  72. }
  73. if (!wait_for_completion_timeout(&me->completions[cmd->type],
  74. msecs_to_jiffies(CVP_DSP_RESPONSE_TIMEOUT))) {
  75. dprintk(CVP_ERR, "%s cmd %d timeout\n", __func__, cmd->type);
  76. rc = -ETIMEDOUT;
  77. goto exit;
  78. }
  79. exit:
  80. rsp->ret = me->pending_dsp2cpu_rsp.ret;
  81. rsp->dsp_state = me->pending_dsp2cpu_rsp.dsp_state;
  82. me->pending_dsp2cpu_rsp.type = CVP_INVALID_RPMSG_TYPE;
  83. return rc;
  84. }
  85. static int cvp_dsp_send_cmd_hfi_queue(phys_addr_t *phys_addr,
  86. uint32_t size_in_bytes,
  87. struct cvp_dsp_rsp_msg *rsp)
  88. {
  89. int rc = 0;
  90. struct cvp_dsp_cmd_msg cmd;
  91. cmd.type = CPU2DSP_SEND_HFI_QUEUE;
  92. cmd.msg_ptr = (uint64_t)phys_addr;
  93. cmd.msg_ptr_len = size_in_bytes;
  94. cmd.ddr_type = cvp_of_fdt_get_ddrtype();
  95. if (cmd.ddr_type < 0) {
  96. dprintk(CVP_WARN,
  97. "%s: Incorrect DDR type value %d, use default %d\n",
  98. __func__, cmd.ddr_type, DDR_TYPE_LPDDR5);
  99. /*return -EINVAL;*/
  100. cmd.ddr_type = DDR_TYPE_LPDDR5;
  101. }
  102. dprintk(CVP_DSP,
  103. "%s: address of buffer, PA=0x%pK size_buff=%d ddr_type=%d\n",
  104. __func__, phys_addr, size_in_bytes, cmd.ddr_type);
  105. rc = cvp_dsp_send_cmd_sync(&cmd, sizeof(struct cvp_dsp_cmd_msg), rsp);
  106. if (rc) {
  107. dprintk(CVP_ERR,
  108. "%s: cvp_dsp_send_cmd failed rc = %d\n",
  109. __func__, rc);
  110. goto exit;
  111. }
  112. exit:
  113. return rc;
  114. }
  115. static int cvp_hyp_assign_to_dsp(uint64_t addr, uint32_t size)
  116. {
  117. int rc = 0;
  118. struct cvp_dsp_apps *me = &gfa_cv;
  119. uint64_t hlosVMid = BIT(VMID_HLOS);
  120. struct qcom_scm_vmperm dspVM[DSP_VM_NUM] = {
  121. {VMID_HLOS, PERM_READ | PERM_WRITE | PERM_EXEC},
  122. {VMID_CDSP_Q6, PERM_READ | PERM_WRITE | PERM_EXEC}
  123. };
  124. if (!me->hyp_assigned) {
  125. rc = qcom_scm_assign_mem(addr, size, &hlosVMid, dspVM, DSP_VM_NUM);
  126. if (rc) {
  127. dprintk(CVP_ERR, "%s failed. rc=%d\n", __func__, rc);
  128. return rc;
  129. }
  130. me->addr = addr;
  131. me->size = size;
  132. me->hyp_assigned = true;
  133. }
  134. return rc;
  135. }
  136. static int cvp_hyp_assign_from_dsp(void)
  137. {
  138. int rc = 0;
  139. struct cvp_dsp_apps *me = &gfa_cv;
  140. uint64_t dspVMids = BIT(VMID_HLOS) | BIT(VMID_CDSP_Q6);
  141. struct qcom_scm_vmperm hlosVM[HLOS_VM_NUM] = {
  142. {VMID_HLOS, PERM_READ | PERM_WRITE | PERM_EXEC},
  143. };
  144. if (me->hyp_assigned) {
  145. rc = qcom_scm_assign_mem(me->addr, me->size, &dspVMids, hlosVM, HLOS_VM_NUM);
  146. if (rc) {
  147. dprintk(CVP_ERR, "%s failed. rc=%d\n", __func__, rc);
  148. return rc;
  149. }
  150. me->addr = 0;
  151. me->size = 0;
  152. me->hyp_assigned = false;
  153. }
  154. return rc;
  155. }
  156. static int cvp_dsp_rpmsg_probe(struct rpmsg_device *rpdev)
  157. {
  158. struct cvp_dsp_apps *me = &gfa_cv;
  159. const char *edge_name = NULL;
  160. int ret = 0;
  161. ret = of_property_read_string(rpdev->dev.parent->of_node,
  162. "label", &edge_name);
  163. if (ret) {
  164. dprintk(CVP_ERR, "glink edge 'label' not found in node\n");
  165. return ret;
  166. }
  167. if (strcmp(edge_name, "cdsp")) {
  168. dprintk(CVP_ERR,
  169. "%s: Failed to probe rpmsg device.Node name:%s\n",
  170. __func__, edge_name);
  171. return -EINVAL;
  172. }
  173. mutex_lock(&me->tx_lock);
  174. me->chan = rpdev;
  175. me->state = DSP_PROBED;
  176. mutex_unlock(&me->tx_lock);
  177. complete(&me->completions[CPU2DSP_MAX_CMD]);
  178. return ret;
  179. }
  180. static int eva_fastrpc_dev_unmap_dma(
  181. struct fastrpc_device *frpc_device,
  182. struct cvp_internal_buf *buf);
  183. static int delete_dsp_session(struct msm_cvp_inst *inst,
  184. struct cvp_dsp_fastrpc_driver_entry *frpc_node)
  185. {
  186. struct msm_cvp_list *buf_list = NULL;
  187. struct list_head *ptr_dsp_buf = NULL, *next_dsp_buf = NULL;
  188. struct cvp_internal_buf *buf = NULL;
  189. struct task_struct *task = NULL;
  190. struct cvp_hfi_device *hdev;
  191. int rc;
  192. if (!inst)
  193. return -EINVAL;
  194. buf_list = &inst->cvpdspbufs;
  195. mutex_lock(&buf_list->lock);
  196. ptr_dsp_buf = &buf_list->list;
  197. list_for_each_safe(ptr_dsp_buf, next_dsp_buf, &buf_list->list) {
  198. buf = list_entry(ptr_dsp_buf, struct cvp_internal_buf, list);
  199. if (buf) {
  200. dprintk(CVP_DSP, "fd in list 0x%x\n", buf->fd);
  201. if (!buf->smem) {
  202. dprintk(CVP_DSP, "Empyt smem\n");
  203. continue;
  204. }
  205. dprintk(CVP_DSP, "%s find device addr 0x%x\n",
  206. __func__, buf->smem->device_addr);
  207. rc = eva_fastrpc_dev_unmap_dma(
  208. frpc_node->cvp_fastrpc_device,
  209. buf);
  210. if (rc)
  211. dprintk(CVP_WARN,
  212. "%s Failed to unmap buffer 0x%x\n",
  213. __func__, rc);
  214. rc = cvp_release_dsp_buffers(inst, buf);
  215. if (rc)
  216. dprintk(CVP_ERR,
  217. "%s Failed to free buffer 0x%x\n",
  218. __func__, rc);
  219. list_del(&buf->list);
  220. cvp_kmem_cache_free(&cvp_driver->buf_cache, buf);
  221. }
  222. }
  223. mutex_unlock(&buf_list->lock);
  224. task = inst->task;
  225. spin_lock(&inst->core->resources.pm_qos.lock);
  226. if (inst->core->resources.pm_qos.off_vote_cnt > 0)
  227. inst->core->resources.pm_qos.off_vote_cnt--;
  228. else
  229. dprintk(CVP_WARN, "%s Unexpected pm_qos off vote %d\n",
  230. __func__,
  231. inst->core->resources.pm_qos.off_vote_cnt);
  232. spin_unlock(&inst->core->resources.pm_qos.lock);
  233. hdev = inst->core->device;
  234. call_hfi_op(hdev, pm_qos_update, hdev->hfi_device_data);
  235. rc = msm_cvp_close(inst);
  236. if (rc)
  237. dprintk(CVP_ERR, "Warning: Failed to close cvp instance\n");
  238. if (task)
  239. put_task_struct(task);
  240. dprintk(CVP_DSP, "%s DSP2CPU_DETELE_SESSION Done\n", __func__);
  241. return rc;
  242. }
  243. static int eva_fastrpc_driver_get_name(
  244. struct cvp_dsp_fastrpc_driver_entry *frpc_node)
  245. {
  246. int i = 0;
  247. struct cvp_dsp_apps *me = &gfa_cv;
  248. for (i = 0; i < MAX_FASTRPC_DRIVER_NUM; i++) {
  249. if (me->cvp_fastrpc_name[i].status == DRIVER_NAME_AVAILABLE) {
  250. frpc_node->driver_name_idx = i;
  251. frpc_node->cvp_fastrpc_driver.driver.name =
  252. me->cvp_fastrpc_name[i].name;
  253. me->cvp_fastrpc_name[i].status = DRIVER_NAME_USED;
  254. dprintk(CVP_DSP, "%s -> handle 0x%x get name %s\n",
  255. __func__, frpc_node->cvp_fastrpc_driver.handle,
  256. frpc_node->cvp_fastrpc_driver.driver.name);
  257. return 0;
  258. }
  259. }
  260. return -1;
  261. }
  262. static void eva_fastrpc_driver_release_name(
  263. struct cvp_dsp_fastrpc_driver_entry *frpc_node)
  264. {
  265. struct cvp_dsp_apps *me = &gfa_cv;
  266. me->cvp_fastrpc_name[frpc_node->driver_name_idx].status =
  267. DRIVER_NAME_AVAILABLE;
  268. }
  269. /* The function may not return for up to 50ms */
  270. static bool dequeue_frpc_node(struct cvp_dsp_fastrpc_driver_entry *node)
  271. {
  272. struct cvp_dsp_apps *me = &gfa_cv;
  273. struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
  274. struct list_head *ptr = NULL, *next = NULL;
  275. u32 refcount, max_count = 10;
  276. bool rc = false;
  277. if (!node)
  278. return rc;
  279. search_again:
  280. ptr = &me->fastrpc_driver_list.list;
  281. mutex_lock(&me->fastrpc_driver_list.lock);
  282. list_for_each_safe(ptr, next, &me->fastrpc_driver_list.list) {
  283. frpc_node = list_entry(ptr,
  284. struct cvp_dsp_fastrpc_driver_entry, list);
  285. if (frpc_node == node) {
  286. refcount = atomic_read(&frpc_node->refcount);
  287. if (refcount > 0) {
  288. mutex_unlock(&me->fastrpc_driver_list.lock);
  289. usleep_range(5000, 10000);
  290. if (max_count-- == 0) {
  291. dprintk(CVP_ERR, "%s timeout\n",
  292. __func__);
  293. goto exit;
  294. }
  295. goto search_again;
  296. }
  297. list_del(&frpc_node->list);
  298. rc = true;
  299. break;
  300. }
  301. }
  302. mutex_unlock(&me->fastrpc_driver_list.lock);
  303. exit:
  304. return rc;
  305. }
  306. /* The function may not return for up to 50ms */
  307. static struct cvp_dsp_fastrpc_driver_entry *pop_frpc_node(void)
  308. {
  309. struct cvp_dsp_apps *me = &gfa_cv;
  310. struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
  311. struct list_head *ptr = NULL, *next = NULL;
  312. u32 refcount, max_count = 10;
  313. search_again:
  314. ptr = &me->fastrpc_driver_list.list;
  315. if (!ptr) {
  316. frpc_node = NULL;
  317. goto exit;
  318. }
  319. mutex_lock(&me->fastrpc_driver_list.lock);
  320. list_for_each_safe(ptr, next, &me->fastrpc_driver_list.list) {
  321. frpc_node = list_entry(ptr,
  322. struct cvp_dsp_fastrpc_driver_entry, list);
  323. if (frpc_node) {
  324. refcount = atomic_read(&frpc_node->refcount);
  325. if (refcount > 0) {
  326. mutex_unlock(&me->fastrpc_driver_list.lock);
  327. usleep_range(5000, 10000);
  328. if (max_count-- == 0) {
  329. dprintk(CVP_ERR, "%s timeout\n",
  330. __func__);
  331. frpc_node = NULL;
  332. goto exit;
  333. }
  334. goto search_again;
  335. }
  336. list_del(&frpc_node->list);
  337. break;
  338. }
  339. }
  340. mutex_unlock(&me->fastrpc_driver_list.lock);
  341. exit:
  342. return frpc_node;
  343. }
  344. static void cvp_dsp_rpmsg_remove(struct rpmsg_device *rpdev)
  345. {
  346. struct cvp_dsp_apps *me = &gfa_cv;
  347. u32 max_num_retries = 100;
  348. dprintk(CVP_WARN, "%s: CDSP SSR triggered\n", __func__);
  349. mutex_lock(&me->rx_lock);
  350. while (max_num_retries > 0) {
  351. if (me->pending_dsp2cpu_cmd.type !=
  352. CVP_INVALID_RPMSG_TYPE) {
  353. mutex_unlock(&me->rx_lock);
  354. usleep_range(1000, 5000);
  355. mutex_lock(&me->rx_lock);
  356. } else {
  357. break;
  358. }
  359. max_num_retries--;
  360. }
  361. if (!max_num_retries)
  362. dprintk(CVP_ERR, "stuck processing pending DSP cmds\n");
  363. mutex_lock(&me->tx_lock);
  364. cvp_hyp_assign_from_dsp();
  365. me->chan = NULL;
  366. me->state = DSP_UNINIT;
  367. mutex_unlock(&me->tx_lock);
  368. mutex_unlock(&me->rx_lock);
  369. cvp_remove_dsp_sessions();
  370. dprintk(CVP_WARN, "%s: CDSP SSR handled nr_maps %d\n", __func__,
  371. atomic_read(&nr_maps));
  372. }
  373. static int cvp_dsp_rpmsg_callback(struct rpmsg_device *rpdev,
  374. void *data, int len, void *priv, u32 addr)
  375. {
  376. struct cvp_dsp_rsp_msg *rsp = (struct cvp_dsp_rsp_msg *)data;
  377. struct cvp_dsp_apps *me = &gfa_cv;
  378. dprintk(CVP_DSP, "%s: type = 0x%x ret = 0x%x len = 0x%x\n",
  379. __func__, rsp->type, rsp->ret, len);
  380. if (rsp->type < CPU2DSP_MAX_CMD && len == sizeof(*rsp)) {
  381. if (me->pending_dsp2cpu_rsp.type == rsp->type) {
  382. memcpy(&me->pending_dsp2cpu_rsp, rsp,
  383. sizeof(struct cvp_dsp_rsp_msg));
  384. complete(&me->completions[rsp->type]);
  385. } else {
  386. dprintk(CVP_ERR, "%s: CPU2DSP resp %d, pending %d\n",
  387. __func__, rsp->type,
  388. me->pending_dsp2cpu_rsp.type);
  389. goto exit;
  390. }
  391. } else if (rsp->type < CVP_DSP_MAX_CMD &&
  392. len == sizeof(struct cvp_dsp2cpu_cmd)) {
  393. if (me->pending_dsp2cpu_cmd.type != CVP_INVALID_RPMSG_TYPE) {
  394. dprintk(CVP_ERR,
  395. "%s: DSP2CPU cmd:%d pending %d %d expect %d\n",
  396. __func__, rsp->type,
  397. me->pending_dsp2cpu_cmd.type, len,
  398. sizeof(struct cvp_dsp2cpu_cmd));
  399. goto exit;
  400. }
  401. memcpy(&me->pending_dsp2cpu_cmd, rsp,
  402. sizeof(struct cvp_dsp2cpu_cmd));
  403. complete(&me->completions[CPU2DSP_MAX_CMD]);
  404. } else {
  405. dprintk(CVP_ERR, "%s: Invalid type: %d\n", __func__, rsp->type);
  406. return 0;
  407. }
  408. return 0;
  409. exit:
  410. dprintk(CVP_ERR, "concurrent dsp cmd type = %d, rsp type = %d\n",
  411. me->pending_dsp2cpu_cmd.type,
  412. me->pending_dsp2cpu_rsp.type);
  413. return 0;
  414. }
  415. int cvp_dsp_suspend(uint32_t session_flag)
  416. {
  417. int rc = 0;
  418. struct cvp_dsp_cmd_msg cmd;
  419. struct cvp_dsp_apps *me = &gfa_cv;
  420. struct cvp_dsp_rsp_msg rsp;
  421. bool retried = false;
  422. cmd.type = CPU2DSP_SUSPEND;
  423. mutex_lock(&me->tx_lock);
  424. if (me->state != DSP_READY)
  425. goto exit;
  426. retry:
  427. /* Use cvp_dsp_send_cmd_sync after dsp driver is ready */
  428. rc = cvp_dsp_send_cmd_sync(&cmd,
  429. sizeof(struct cvp_dsp_cmd_msg),
  430. &rsp);
  431. if (rc) {
  432. dprintk(CVP_ERR,
  433. "%s: cvp_dsp_send_cmd failed rc = %d\n",
  434. __func__, rc);
  435. goto exit;
  436. }
  437. if (rsp.ret == CPU2DSP_EUNAVAILABLE)
  438. goto fatal_exit;
  439. if (rsp.ret == CPU2DSP_EFATAL) {
  440. dprintk(CVP_ERR, "%s: suspend dsp got EFATAL error\n",
  441. __func__);
  442. if (!retried) {
  443. mutex_unlock(&me->tx_lock);
  444. retried = true;
  445. rc = cvp_reinit_dsp();
  446. mutex_lock(&me->tx_lock);
  447. if (rc)
  448. goto fatal_exit;
  449. else
  450. goto retry;
  451. } else {
  452. goto fatal_exit;
  453. }
  454. }
  455. me->state = DSP_SUSPEND;
  456. dprintk(CVP_DSP, "DSP suspended, nr_map: %d\n", atomic_read(&nr_maps));
  457. goto exit;
  458. fatal_exit:
  459. me->state = DSP_INVALID;
  460. cvp_hyp_assign_from_dsp();
  461. rc = -ENOTSUPP;
  462. exit:
  463. mutex_unlock(&me->tx_lock);
  464. return rc;
  465. }
  466. int cvp_dsp_resume(uint32_t session_flag)
  467. {
  468. int rc = 0;
  469. struct cvp_dsp_cmd_msg cmd;
  470. struct cvp_dsp_apps *me = &gfa_cv;
  471. cmd.type = CPU2DSP_RESUME;
  472. /*
  473. * Deadlock against DSP2CPU_CREATE_SESSION in dsp_thread
  474. * Probably get rid of this entirely as discussed before
  475. */
  476. if (me->state != DSP_SUSPEND)
  477. dprintk(CVP_WARN, "%s DSP not in SUSPEND state\n", __func__);
  478. return rc;
  479. }
  480. static void cvp_remove_dsp_sessions(void)
  481. {
  482. struct cvp_dsp_apps *me = &gfa_cv;
  483. struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
  484. struct msm_cvp_inst *inst = NULL;
  485. struct list_head *s = NULL, *next_s = NULL;
  486. while ((frpc_node = pop_frpc_node())) {
  487. s = &frpc_node->dsp_sessions.list;
  488. if (!s)
  489. return;
  490. list_for_each_safe(s, next_s,
  491. &frpc_node->dsp_sessions.list) {
  492. if (!s || !next_s)
  493. return;
  494. inst = list_entry(s, struct msm_cvp_inst,
  495. dsp_list);
  496. if (inst) {
  497. delete_dsp_session(inst, frpc_node);
  498. mutex_lock(&frpc_node->dsp_sessions.lock);
  499. list_del(&inst->dsp_list);
  500. frpc_node->session_cnt--;
  501. mutex_unlock(&frpc_node->dsp_sessions.lock);
  502. }
  503. }
  504. dprintk(CVP_DSP, "%s DEINIT_MSM_CVP_LIST 0x%x\n",
  505. __func__, frpc_node->dsp_sessions);
  506. DEINIT_MSM_CVP_LIST(&frpc_node->dsp_sessions);
  507. dprintk(CVP_DSP, "%s list_del fastrpc node 0x%x\n",
  508. __func__, frpc_node);
  509. __fastrpc_driver_unregister(
  510. &frpc_node->cvp_fastrpc_driver);
  511. dprintk(CVP_DSP,
  512. "%s Unregistered fastrpc handle 0x%x\n",
  513. __func__, frpc_node->handle);
  514. mutex_lock(&me->driver_name_lock);
  515. eva_fastrpc_driver_release_name(frpc_node);
  516. mutex_unlock(&me->driver_name_lock);
  517. kfree(frpc_node);
  518. frpc_node = NULL;
  519. }
  520. dprintk(CVP_WARN, "%s: EVA SSR handled for CDSP\n", __func__);
  521. }
  522. int cvp_dsp_shutdown(uint32_t session_flag)
  523. {
  524. struct cvp_dsp_apps *me = &gfa_cv;
  525. int rc = 0;
  526. struct cvp_dsp_cmd_msg cmd;
  527. struct cvp_dsp_rsp_msg rsp;
  528. cmd.type = CPU2DSP_SHUTDOWN;
  529. mutex_lock(&me->tx_lock);
  530. if (me->state == DSP_INVALID)
  531. goto exit;
  532. me->state = DSP_INACTIVE;
  533. rc = cvp_dsp_send_cmd_sync(&cmd, sizeof(struct cvp_dsp_cmd_msg), &rsp);
  534. if (rc) {
  535. dprintk(CVP_ERR,
  536. "%s: cvp_dsp_send_cmd failed with rc = %d\n",
  537. __func__, rc);
  538. cvp_hyp_assign_from_dsp();
  539. goto exit;
  540. }
  541. rc = cvp_hyp_assign_from_dsp();
  542. exit:
  543. mutex_unlock(&me->tx_lock);
  544. return rc;
  545. }
  546. int cvp_dsp_register_buffer(uint32_t session_id, uint32_t buff_fd,
  547. uint32_t buff_fd_size, uint32_t buff_size,
  548. uint32_t buff_offset, uint32_t buff_index,
  549. uint32_t buff_fd_iova)
  550. {
  551. struct cvp_dsp_cmd_msg cmd;
  552. int rc;
  553. struct cvp_dsp_apps *me = &gfa_cv;
  554. struct cvp_dsp_rsp_msg rsp;
  555. bool retried = false;
  556. cmd.type = CPU2DSP_REGISTER_BUFFER;
  557. cmd.session_id = session_id;
  558. cmd.buff_fd = buff_fd;
  559. cmd.buff_fd_size = buff_fd_size;
  560. cmd.buff_size = buff_size;
  561. cmd.buff_offset = buff_offset;
  562. cmd.buff_index = buff_index;
  563. cmd.buff_fd_iova = buff_fd_iova;
  564. dprintk(CVP_DSP,
  565. "%s: type=0x%x, buff_fd_iova=0x%x buff_index=0x%x\n",
  566. __func__, cmd.type, buff_fd_iova,
  567. cmd.buff_index);
  568. dprintk(CVP_DSP, "%s: buff_size=0x%x session_id=0x%x\n",
  569. __func__, cmd.buff_size, cmd.session_id);
  570. mutex_lock(&me->tx_lock);
  571. retry:
  572. rc = cvp_dsp_send_cmd_sync(&cmd, sizeof(struct cvp_dsp_cmd_msg), &rsp);
  573. if (rc) {
  574. dprintk(CVP_ERR, "%s send failed rc = %d\n", __func__, rc);
  575. goto exit;
  576. }
  577. if (rsp.ret == CPU2DSP_EFAIL || rsp.ret == CPU2DSP_EUNSUPPORTED) {
  578. dprintk(CVP_WARN, "%s, DSP return err %d\n", __func__, rsp.ret);
  579. rc = -EINVAL;
  580. goto exit;
  581. }
  582. if (rsp.ret == CPU2DSP_EUNAVAILABLE)
  583. goto fatal_exit;
  584. if (rsp.ret == CPU2DSP_EFATAL) {
  585. if (!retried) {
  586. mutex_unlock(&me->tx_lock);
  587. retried = true;
  588. rc = cvp_reinit_dsp();
  589. mutex_lock(&me->tx_lock);
  590. if (rc)
  591. goto fatal_exit;
  592. else
  593. goto retry;
  594. } else {
  595. goto fatal_exit;
  596. }
  597. }
  598. goto exit;
  599. fatal_exit:
  600. me->state = DSP_INVALID;
  601. cvp_hyp_assign_from_dsp();
  602. rc = -ENOTSUPP;
  603. exit:
  604. mutex_unlock(&me->tx_lock);
  605. return rc;
  606. }
  607. int cvp_dsp_deregister_buffer(uint32_t session_id, uint32_t buff_fd,
  608. uint32_t buff_fd_size, uint32_t buff_size,
  609. uint32_t buff_offset, uint32_t buff_index,
  610. uint32_t buff_fd_iova)
  611. {
  612. struct cvp_dsp_cmd_msg cmd;
  613. int rc;
  614. struct cvp_dsp_apps *me = &gfa_cv;
  615. struct cvp_dsp_rsp_msg rsp;
  616. bool retried = false;
  617. cmd.type = CPU2DSP_DEREGISTER_BUFFER;
  618. cmd.session_id = session_id;
  619. cmd.buff_fd = buff_fd;
  620. cmd.buff_fd_size = buff_fd_size;
  621. cmd.buff_size = buff_size;
  622. cmd.buff_offset = buff_offset;
  623. cmd.buff_index = buff_index;
  624. cmd.buff_fd_iova = buff_fd_iova;
  625. dprintk(CVP_DSP,
  626. "%s: type=0x%x, buff_fd_iova=0x%x buff_index=0x%x\n",
  627. __func__, cmd.type, buff_fd_iova,
  628. cmd.buff_index);
  629. dprintk(CVP_DSP, "%s: buff_size=0x%x session_id=0x%x\n",
  630. __func__, cmd.buff_size, cmd.session_id);
  631. mutex_lock(&me->tx_lock);
  632. retry:
  633. rc = cvp_dsp_send_cmd_sync(&cmd, sizeof(struct cvp_dsp_cmd_msg), &rsp);
  634. if (rc) {
  635. dprintk(CVP_ERR, "%s send failed rc = %d\n", __func__, rc);
  636. goto exit;
  637. }
  638. if (rsp.ret == CPU2DSP_EFAIL || rsp.ret == CPU2DSP_EUNSUPPORTED) {
  639. dprintk(CVP_WARN, "%s, DSP return err %d\n", __func__, rsp.ret);
  640. rc = -EINVAL;
  641. goto exit;
  642. }
  643. if (rsp.ret == CPU2DSP_EUNAVAILABLE)
  644. goto fatal_exit;
  645. if (rsp.ret == CPU2DSP_EFATAL) {
  646. if (!retried) {
  647. mutex_unlock(&me->tx_lock);
  648. retried = true;
  649. rc = cvp_reinit_dsp();
  650. mutex_lock(&me->tx_lock);
  651. if (rc)
  652. goto fatal_exit;
  653. else
  654. goto retry;
  655. } else {
  656. goto fatal_exit;
  657. }
  658. }
  659. goto exit;
  660. fatal_exit:
  661. me->state = DSP_INVALID;
  662. cvp_hyp_assign_from_dsp();
  663. rc = -ENOTSUPP;
  664. exit:
  665. mutex_unlock(&me->tx_lock);
  666. return rc;
  667. }
  668. static const struct rpmsg_device_id cvp_dsp_rpmsg_match[] = {
  669. { CVP_APPS_DSP_GLINK_GUID },
  670. { },
  671. };
  672. static struct rpmsg_driver cvp_dsp_rpmsg_client = {
  673. .id_table = cvp_dsp_rpmsg_match,
  674. .probe = cvp_dsp_rpmsg_probe,
  675. .remove = cvp_dsp_rpmsg_remove,
  676. .callback = cvp_dsp_rpmsg_callback,
  677. .drv = {
  678. .name = "qcom,msm_cvp_dsp_rpmsg",
  679. },
  680. };
  681. static void cvp_dsp_set_queue_hdr_defaults(struct cvp_hfi_queue_header *q_hdr)
  682. {
  683. q_hdr->qhdr_status = 0x1;
  684. q_hdr->qhdr_type = CVP_IFACEQ_DFLT_QHDR;
  685. q_hdr->qhdr_q_size = CVP_IFACEQ_QUEUE_SIZE / 4;
  686. q_hdr->qhdr_pkt_size = 0;
  687. q_hdr->qhdr_rx_wm = 0x1;
  688. q_hdr->qhdr_tx_wm = 0x1;
  689. q_hdr->qhdr_rx_req = 0x1;
  690. q_hdr->qhdr_tx_req = 0x0;
  691. q_hdr->qhdr_rx_irq_status = 0x0;
  692. q_hdr->qhdr_tx_irq_status = 0x0;
  693. q_hdr->qhdr_read_idx = 0x0;
  694. q_hdr->qhdr_write_idx = 0x0;
  695. }
  696. void cvp_dsp_init_hfi_queue_hdr(struct iris_hfi_device *device)
  697. {
  698. u32 i;
  699. struct cvp_hfi_queue_table_header *q_tbl_hdr;
  700. struct cvp_hfi_queue_header *q_hdr;
  701. struct cvp_iface_q_info *iface_q;
  702. for (i = 0; i < CVP_IFACEQ_NUMQ; i++) {
  703. iface_q = &device->dsp_iface_queues[i];
  704. iface_q->q_hdr = CVP_IFACEQ_GET_QHDR_START_ADDR(
  705. device->dsp_iface_q_table.align_virtual_addr, i);
  706. cvp_dsp_set_queue_hdr_defaults(iface_q->q_hdr);
  707. }
  708. q_tbl_hdr = (struct cvp_hfi_queue_table_header *)
  709. device->dsp_iface_q_table.align_virtual_addr;
  710. q_tbl_hdr->qtbl_version = 0;
  711. q_tbl_hdr->device_addr = (void *)device;
  712. strlcpy(q_tbl_hdr->name, "msm_cvp", sizeof(q_tbl_hdr->name));
  713. q_tbl_hdr->qtbl_size = CVP_IFACEQ_TABLE_SIZE;
  714. q_tbl_hdr->qtbl_qhdr0_offset =
  715. sizeof(struct cvp_hfi_queue_table_header);
  716. q_tbl_hdr->qtbl_qhdr_size = sizeof(struct cvp_hfi_queue_header);
  717. q_tbl_hdr->qtbl_num_q = CVP_IFACEQ_NUMQ;
  718. q_tbl_hdr->qtbl_num_active_q = CVP_IFACEQ_NUMQ;
  719. iface_q = &device->dsp_iface_queues[CVP_IFACEQ_CMDQ_IDX];
  720. q_hdr = iface_q->q_hdr;
  721. q_hdr->qhdr_start_addr = iface_q->q_array.align_device_addr;
  722. q_hdr->qhdr_type |= HFI_Q_ID_HOST_TO_CTRL_CMD_Q;
  723. iface_q = &device->dsp_iface_queues[CVP_IFACEQ_MSGQ_IDX];
  724. q_hdr = iface_q->q_hdr;
  725. q_hdr->qhdr_start_addr = iface_q->q_array.align_device_addr;
  726. q_hdr->qhdr_type |= HFI_Q_ID_CTRL_TO_HOST_MSG_Q;
  727. iface_q = &device->dsp_iface_queues[CVP_IFACEQ_DBGQ_IDX];
  728. q_hdr = iface_q->q_hdr;
  729. q_hdr->qhdr_start_addr = iface_q->q_array.align_device_addr;
  730. q_hdr->qhdr_type |= HFI_Q_ID_CTRL_TO_HOST_DEBUG_Q;
  731. /*
  732. * Set receive request to zero on debug queue as there is no
  733. * need of interrupt from cvp hardware for debug messages
  734. */
  735. q_hdr->qhdr_rx_req = 0;
  736. }
  737. static int __reinit_dsp(void)
  738. {
  739. int rc;
  740. uint32_t flag = 0;
  741. uint64_t addr;
  742. uint32_t size;
  743. struct cvp_dsp_apps *me = &gfa_cv;
  744. struct cvp_dsp_rsp_msg rsp;
  745. struct msm_cvp_core *core;
  746. struct iris_hfi_device *device;
  747. core = list_first_entry(&cvp_driver->cores, struct msm_cvp_core, list);
  748. if (core && core->device)
  749. device = core->device->hfi_device_data;
  750. else
  751. return -EINVAL;
  752. if (!device) {
  753. dprintk(CVP_ERR, "%s: NULL device\n", __func__);
  754. return -EINVAL;
  755. }
  756. /* Force shutdown DSP */
  757. rc = cvp_dsp_shutdown(flag);
  758. if (rc)
  759. return rc;
  760. /*
  761. * Workaround to force delete DSP session resources
  762. * To be removed after DSP optimization ready
  763. */
  764. cvp_remove_dsp_sessions();
  765. dprintk(CVP_WARN, "Reinit EVA DSP interface: nr_map %d\n",
  766. atomic_read(&nr_maps));
  767. /* Resend HFI queue */
  768. mutex_lock(&me->tx_lock);
  769. if (!device->dsp_iface_q_table.align_virtual_addr) {
  770. dprintk(CVP_ERR, "%s: DSP HFI queue released\n", __func__);
  771. rc = -EINVAL;
  772. goto exit;
  773. }
  774. addr = (uint64_t)device->dsp_iface_q_table.mem_data.dma_handle;
  775. size = device->dsp_iface_q_table.mem_data.size;
  776. if (!addr || !size) {
  777. dprintk(CVP_DSP, "%s: HFI queue is not ready\n", __func__);
  778. goto exit;
  779. }
  780. rc = cvp_hyp_assign_to_dsp(addr, size);
  781. if (rc) {
  782. dprintk(CVP_ERR, "%s: cvp_hyp_assign_to_dsp. rc=%d\n",
  783. __func__, rc);
  784. goto exit;
  785. }
  786. rc = cvp_dsp_send_cmd_hfi_queue((phys_addr_t *)addr, size, &rsp);
  787. if (rc) {
  788. dprintk(CVP_WARN, "%s: Send HFI Queue failed rc = %d\n",
  789. __func__, rc);
  790. goto exit;
  791. }
  792. if (rsp.ret) {
  793. dprintk(CVP_ERR, "%s: DSP error %d %d\n", __func__,
  794. rsp.ret, rsp.dsp_state);
  795. rc = -ENODEV;
  796. }
  797. exit:
  798. mutex_unlock(&me->tx_lock);
  799. return rc;
  800. }
  801. static int cvp_reinit_dsp(void)
  802. {
  803. int rc;
  804. struct cvp_dsp_apps *me = &gfa_cv;
  805. rc = __reinit_dsp();
  806. if (rc) {
  807. mutex_lock(&me->tx_lock);
  808. me->state = DSP_INVALID;
  809. cvp_hyp_assign_from_dsp();
  810. mutex_unlock(&me->tx_lock);
  811. }
  812. return rc;
  813. }
  814. static void cvp_put_fastrpc_node(struct cvp_dsp_fastrpc_driver_entry *node)
  815. {
  816. if (node && (atomic_read(&node->refcount) > 0))
  817. atomic_dec(&node->refcount);
  818. }
  819. static struct cvp_dsp_fastrpc_driver_entry *cvp_get_fastrpc_node_with_handle(
  820. uint32_t handle)
  821. {
  822. struct cvp_dsp_apps *me = &gfa_cv;
  823. struct list_head *ptr = NULL, *next = NULL;
  824. struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL, *tmp_node = NULL;
  825. mutex_lock(&me->fastrpc_driver_list.lock);
  826. list_for_each_safe(ptr, next, &me->fastrpc_driver_list.list) {
  827. tmp_node = list_entry(ptr,
  828. struct cvp_dsp_fastrpc_driver_entry, list);
  829. if (handle == tmp_node->handle) {
  830. frpc_node = tmp_node;
  831. atomic_inc(&frpc_node->refcount);
  832. dprintk(CVP_DSP, "Find tmp_node with handle 0x%x\n",
  833. handle);
  834. break;
  835. }
  836. }
  837. mutex_unlock(&me->fastrpc_driver_list.lock);
  838. dprintk(CVP_DSP, "%s found fastrpc probe handle %pK pid 0x%x\n",
  839. __func__, frpc_node, handle);
  840. return frpc_node;
  841. }
  842. static void eva_fastrpc_driver_unregister(uint32_t handle, bool force_exit);
  843. static int cvp_fastrpc_probe(struct fastrpc_device *rpc_dev)
  844. {
  845. struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
  846. dprintk(CVP_DSP, "%s fastrpc probe handle 0x%x\n",
  847. __func__, rpc_dev->handle);
  848. frpc_node = cvp_get_fastrpc_node_with_handle(rpc_dev->handle);
  849. if (frpc_node) {
  850. frpc_node->cvp_fastrpc_device = rpc_dev;
  851. // static structure with signal and pid
  852. complete(&frpc_node->fastrpc_probe_completion);
  853. cvp_put_fastrpc_node(frpc_node);
  854. }
  855. return 0;
  856. }
  857. static int cvp_fastrpc_callback(struct fastrpc_device *rpc_dev,
  858. enum fastrpc_driver_status fastrpc_proc_num)
  859. {
  860. dprintk(CVP_DSP, "%s handle 0x%x, proc %d\n", __func__,
  861. rpc_dev->handle, fastrpc_proc_num);
  862. /* fastrpc drive down when process gone
  863. * any handling can happen here, such as
  864. * eva_fastrpc_driver_unregister(rpc_dev->handle, true);
  865. */
  866. eva_fastrpc_driver_unregister(rpc_dev->handle, true);
  867. return 0;
  868. }
  869. static struct fastrpc_driver cvp_fastrpc_client = {
  870. .probe = cvp_fastrpc_probe,
  871. .callback = cvp_fastrpc_callback,
  872. };
  873. static int eva_fastrpc_dev_map_dma(struct fastrpc_device *frpc_device,
  874. struct cvp_internal_buf *buf,
  875. uint32_t dsp_remote_map,
  876. uint64_t *v_dsp_addr)
  877. {
  878. #ifdef CVP_FASTRPC_ENABLED
  879. struct fastrpc_dev_map_dma frpc_map_buf = {0};
  880. int rc = 0;
  881. if (dsp_remote_map == 1) {
  882. frpc_map_buf.buf = buf->smem->dma_buf;
  883. frpc_map_buf.size = buf->smem->size;
  884. frpc_map_buf.attrs = 0;
  885. dprintk(CVP_DSP,
  886. "%s frpc_map_buf size %d, dma_buf %pK, map %pK, 0x%x\n",
  887. __func__, frpc_map_buf.size, frpc_map_buf.buf,
  888. &frpc_map_buf, (unsigned long)&frpc_map_buf);
  889. rc = __fastrpc_driver_invoke(frpc_device, FASTRPC_DEV_MAP_DMA,
  890. (unsigned long)(&frpc_map_buf));
  891. if (rc) {
  892. dprintk(CVP_ERR,
  893. "%s Failed to map buffer 0x%x\n", __func__, rc);
  894. return rc;
  895. }
  896. buf->fd = (s32)frpc_map_buf.v_dsp_addr;
  897. *v_dsp_addr = frpc_map_buf.v_dsp_addr;
  898. atomic_inc(&nr_maps);
  899. } else {
  900. dprintk(CVP_DSP, "%s Buffer not mapped to dsp\n", __func__);
  901. buf->fd = 0;
  902. }
  903. return rc;
  904. #else
  905. return -ENODEV;
  906. #endif /* End of CVP_FASTRPC_ENABLED */
  907. }
  908. static int eva_fastrpc_dev_unmap_dma(struct fastrpc_device *frpc_device,
  909. struct cvp_internal_buf *buf)
  910. {
  911. #ifdef CVP_FASTRPC_ENABLED
  912. struct fastrpc_dev_unmap_dma frpc_unmap_buf = {0};
  913. int rc = 0;
  914. /* Only if buffer is mapped to dsp */
  915. if (buf->fd != 0) {
  916. frpc_unmap_buf.buf = buf->smem->dma_buf;
  917. rc = __fastrpc_driver_invoke(frpc_device, FASTRPC_DEV_UNMAP_DMA,
  918. (unsigned long)(&frpc_unmap_buf));
  919. if (rc) {
  920. dprintk(CVP_ERR, "%s Failed to unmap buffer 0x%x\n",
  921. __func__, rc);
  922. return rc;
  923. }
  924. if (atomic_read(&nr_maps) > 0)
  925. atomic_dec(&nr_maps);
  926. } else {
  927. dprintk(CVP_DSP, "%s buffer not mapped to dsp\n", __func__);
  928. }
  929. return rc;
  930. #else
  931. return -ENODEV;
  932. #endif /* End of CVP_FASTRPC_ENABLED */
  933. }
  934. static void eva_fastrpc_driver_add_sess(
  935. struct cvp_dsp_fastrpc_driver_entry *frpc,
  936. struct msm_cvp_inst *inst)
  937. {
  938. mutex_lock(&frpc->dsp_sessions.lock);
  939. if (inst)
  940. list_add_tail(&inst->dsp_list, &frpc->dsp_sessions.list);
  941. else
  942. dprintk(CVP_ERR, "%s incorrect input %pK\n", __func__, inst);
  943. frpc->session_cnt++;
  944. mutex_unlock(&frpc->dsp_sessions.lock);
  945. dprintk(CVP_DSP, "add dsp sess %pK fastrpc_driver %pK\n", inst, frpc);
  946. }
  947. int cvp_dsp_fastrpc_unmap(uint32_t process_id, struct cvp_internal_buf *buf)
  948. {
  949. struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
  950. struct fastrpc_device *frpc_device = NULL;
  951. int rc = 0;
  952. frpc_node = cvp_get_fastrpc_node_with_handle(process_id);
  953. if (!frpc_node) {
  954. dprintk(CVP_ERR, "%s no frpc node for process id %d\n",
  955. __func__, process_id);
  956. return -EINVAL;
  957. }
  958. frpc_device = frpc_node->cvp_fastrpc_device;
  959. rc = eva_fastrpc_dev_unmap_dma(frpc_device, buf);
  960. if (rc)
  961. dprintk(CVP_ERR, "%s Fail to unmap buffer 0x%x\n",
  962. __func__, rc);
  963. cvp_put_fastrpc_node(frpc_node);
  964. return rc;
  965. }
  966. int cvp_dsp_del_sess(uint32_t process_id, struct msm_cvp_inst *inst)
  967. {
  968. struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
  969. struct list_head *ptr = NULL, *next = NULL;
  970. struct msm_cvp_inst *sess;
  971. bool found = false;
  972. frpc_node = cvp_get_fastrpc_node_with_handle(process_id);
  973. if (!frpc_node) {
  974. dprintk(CVP_ERR, "%s no frpc node for process id %d\n",
  975. __func__, process_id);
  976. return -EINVAL;
  977. }
  978. mutex_lock(&frpc_node->dsp_sessions.lock);
  979. list_for_each_safe(ptr, next, &frpc_node->dsp_sessions.list) {
  980. sess = list_entry(ptr, struct msm_cvp_inst, dsp_list);
  981. if (sess == inst) {
  982. dprintk(CVP_DSP, "%s Find sess %pK to be deleted\n",
  983. __func__, inst);
  984. found = true;
  985. break;
  986. }
  987. }
  988. if (found) {
  989. list_del(&inst->dsp_list);
  990. frpc_node->session_cnt--;
  991. }
  992. mutex_unlock(&frpc_node->dsp_sessions.lock);
  993. cvp_put_fastrpc_node(frpc_node);
  994. return 0;
  995. }
  996. static int eva_fastrpc_driver_register(uint32_t handle)
  997. {
  998. struct cvp_dsp_apps *me = &gfa_cv;
  999. int rc = 0;
  1000. struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
  1001. bool skip_deregister = true;
  1002. dprintk(CVP_DSP, "%s -> cvp_get_fastrpc_node_with_handle pid 0x%x\n",
  1003. __func__, handle);
  1004. frpc_node = cvp_get_fastrpc_node_with_handle(handle);
  1005. if (frpc_node == NULL) {
  1006. dprintk(CVP_DSP, "%s new fastrpc node pid 0x%x\n",
  1007. __func__, handle);
  1008. frpc_node = kzalloc(sizeof(*frpc_node), GFP_KERNEL);
  1009. if (!frpc_node) {
  1010. dprintk(CVP_DSP, "%s allocate frpc node fail\n",
  1011. __func__);
  1012. return -EINVAL;
  1013. }
  1014. memset(frpc_node, 0, sizeof(*frpc_node));
  1015. /* Setup fastrpc_node */
  1016. frpc_node->handle = handle;
  1017. frpc_node->cvp_fastrpc_driver = cvp_fastrpc_client;
  1018. frpc_node->cvp_fastrpc_driver.handle = handle;
  1019. mutex_lock(&me->driver_name_lock);
  1020. rc = eva_fastrpc_driver_get_name(frpc_node);
  1021. mutex_unlock(&me->driver_name_lock);
  1022. if (rc) {
  1023. dprintk(CVP_ERR, "%s fastrpc get name fail err %d\n",
  1024. __func__, rc);
  1025. goto fail_fastrpc_driver_get_name;
  1026. }
  1027. /* Init completion */
  1028. init_completion(&frpc_node->fastrpc_probe_completion);
  1029. mutex_lock(&me->fastrpc_driver_list.lock);
  1030. list_add_tail(&frpc_node->list, &me->fastrpc_driver_list.list);
  1031. INIT_MSM_CVP_LIST(&frpc_node->dsp_sessions);
  1032. mutex_unlock(&me->fastrpc_driver_list.lock);
  1033. dprintk(CVP_DSP, "Add frpc node 0x%x to list\n", frpc_node);
  1034. /* register fastrpc device to this session */
  1035. rc = __fastrpc_driver_register(&frpc_node->cvp_fastrpc_driver);
  1036. if (rc) {
  1037. dprintk(CVP_ERR, "%s fastrpc driver reg fail err %d\n",
  1038. __func__, rc);
  1039. skip_deregister = true;
  1040. goto fail_fastrpc_driver_register;
  1041. }
  1042. /* signal wait reuse dsp timeout setup for now */
  1043. if (!wait_for_completion_timeout(
  1044. &frpc_node->fastrpc_probe_completion,
  1045. msecs_to_jiffies(CVP_DSP_RESPONSE_TIMEOUT))) {
  1046. dprintk(CVP_ERR, "%s fastrpc driver_register timeout %#x\n",
  1047. __func__, frpc_node->handle);
  1048. skip_deregister = false;
  1049. goto fail_fastrpc_driver_register;
  1050. }
  1051. } else {
  1052. dprintk(CVP_DSP, "%s fastrpc probe hndl %pK pid 0x%x\n",
  1053. __func__, frpc_node, handle);
  1054. cvp_put_fastrpc_node(frpc_node);
  1055. }
  1056. return rc;
  1057. fail_fastrpc_driver_register:
  1058. dequeue_frpc_node(frpc_node);
  1059. if (!skip_deregister)
  1060. __fastrpc_driver_unregister(&frpc_node->cvp_fastrpc_driver);
  1061. mutex_lock(&me->driver_name_lock);
  1062. eva_fastrpc_driver_release_name(frpc_node);
  1063. mutex_unlock(&me->driver_name_lock);
  1064. fail_fastrpc_driver_get_name:
  1065. kfree(frpc_node);
  1066. return -EINVAL;
  1067. }
  1068. static void eva_fastrpc_driver_unregister(uint32_t handle, bool force_exit)
  1069. {
  1070. struct cvp_dsp_apps *me = &gfa_cv;
  1071. struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
  1072. struct cvp_dsp2cpu_cmd *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
  1073. dprintk(CVP_DSP, "%s Unregister fastrpc driver hdl %#x pid %#x, f %d\n",
  1074. __func__, handle, dsp2cpu_cmd->pid, (uint32_t)force_exit);
  1075. if (handle != dsp2cpu_cmd->pid)
  1076. dprintk(CVP_ERR, "Unregister pid != hndl %#x %#x\n",
  1077. handle, dsp2cpu_cmd->pid);
  1078. /* Foundd fastrpc node */
  1079. frpc_node = cvp_get_fastrpc_node_with_handle(handle);
  1080. if (frpc_node == NULL) {
  1081. dprintk(CVP_DSP, "%s fastrpc handle 0x%x unregistered\n",
  1082. __func__, handle);
  1083. return;
  1084. }
  1085. if ((frpc_node->session_cnt == 0) || force_exit) {
  1086. dprintk(CVP_DSP, "%s session cnt %d, force %d\n",
  1087. __func__, frpc_node->session_cnt, (uint32_t)force_exit);
  1088. DEINIT_MSM_CVP_LIST(&frpc_node->dsp_sessions);
  1089. cvp_put_fastrpc_node(frpc_node);
  1090. if (!dequeue_frpc_node(frpc_node))
  1091. /* Don't find the node */
  1092. return;
  1093. __fastrpc_driver_unregister(&frpc_node->cvp_fastrpc_driver);
  1094. mutex_lock(&me->driver_name_lock);
  1095. eva_fastrpc_driver_release_name(frpc_node);
  1096. mutex_unlock(&me->driver_name_lock);
  1097. kfree(frpc_node);
  1098. } else {
  1099. cvp_put_fastrpc_node(frpc_node);
  1100. }
  1101. }
  1102. void cvp_dsp_send_debug_mask(void)
  1103. {
  1104. struct cvp_dsp_cmd_msg cmd;
  1105. struct cvp_dsp_apps *me = &gfa_cv;
  1106. struct cvp_dsp_rsp_msg rsp;
  1107. int rc;
  1108. cmd.type = CPU2DSP_SET_DEBUG_LEVEL;
  1109. cmd.eva_dsp_debug_mask = me->debug_mask;
  1110. dprintk(CVP_DSP,
  1111. "%s: debug mask 0x%x\n",
  1112. __func__, cmd.eva_dsp_debug_mask);
  1113. rc = cvp_dsp_send_cmd_sync(&cmd, sizeof(struct cvp_dsp_cmd_msg), &rsp);
  1114. if (rc)
  1115. dprintk(CVP_ERR,
  1116. "%s: cvp_dsp_send_cmd failed rc = %d\n",
  1117. __func__, rc);
  1118. }
  1119. void cvp_dsp_send_hfi_queue(void)
  1120. {
  1121. struct msm_cvp_core *core;
  1122. struct iris_hfi_device *device;
  1123. struct cvp_dsp_apps *me = &gfa_cv;
  1124. struct cvp_dsp_rsp_msg rsp = {0};
  1125. uint64_t addr;
  1126. uint32_t size;
  1127. int rc;
  1128. core = list_first_entry(&cvp_driver->cores, struct msm_cvp_core, list);
  1129. if (core && core->device)
  1130. device = core->device->hfi_device_data;
  1131. else
  1132. return;
  1133. if (!device) {
  1134. dprintk(CVP_ERR, "%s: NULL device\n", __func__);
  1135. return;
  1136. }
  1137. dprintk(CVP_DSP, "Entering %s\n", __func__);
  1138. mutex_lock(&device->lock);
  1139. mutex_lock(&me->tx_lock);
  1140. if (!device->dsp_iface_q_table.align_virtual_addr) {
  1141. dprintk(CVP_ERR, "%s: DSP HFI queue released\n", __func__);
  1142. goto exit;
  1143. }
  1144. addr = (uint64_t)device->dsp_iface_q_table.mem_data.dma_handle;
  1145. size = device->dsp_iface_q_table.mem_data.size;
  1146. if (!addr || !size) {
  1147. dprintk(CVP_DSP, "%s: HFI queue is not ready\n", __func__);
  1148. goto exit;
  1149. }
  1150. if (me->state != DSP_PROBED && me->state != DSP_INACTIVE)
  1151. goto exit;
  1152. rc = cvp_hyp_assign_to_dsp(addr, size);
  1153. if (rc) {
  1154. dprintk(CVP_ERR, "%s: cvp_hyp_assign_to_dsp. rc=%d\n",
  1155. __func__, rc);
  1156. goto exit;
  1157. }
  1158. if (me->state == DSP_PROBED) {
  1159. cvp_dsp_init_hfi_queue_hdr(device);
  1160. dprintk(CVP_WARN,
  1161. "%s: Done init of HFI queue headers\n", __func__);
  1162. }
  1163. rc = cvp_dsp_send_cmd_hfi_queue((phys_addr_t *)addr, size, &rsp);
  1164. if (rc) {
  1165. dprintk(CVP_WARN, "%s: Send HFI Queue failed rc = %d\n",
  1166. __func__, rc);
  1167. goto exit;
  1168. }
  1169. if (rsp.ret == CPU2DSP_EUNSUPPORTED) {
  1170. dprintk(CVP_WARN, "%s unsupported cmd %d\n",
  1171. __func__, rsp.type);
  1172. goto exit;
  1173. }
  1174. if (rsp.ret == CPU2DSP_EFATAL || rsp.ret == CPU2DSP_EUNAVAILABLE) {
  1175. dprintk(CVP_ERR, "%s fatal error returned %d %d\n",
  1176. __func__, rsp.dsp_state, rsp.ret);
  1177. me->state = DSP_INVALID;
  1178. cvp_hyp_assign_from_dsp();
  1179. goto exit;
  1180. } else if (rsp.ret == CPU2DSP_EINVALSTATE) {
  1181. dprintk(CVP_ERR, "%s dsp invalid state %d\n",
  1182. __func__, rsp.dsp_state);
  1183. mutex_unlock(&me->tx_lock);
  1184. if (cvp_reinit_dsp()) {
  1185. dprintk(CVP_ERR, "%s reinit dsp fail\n", __func__);
  1186. mutex_unlock(&device->lock);
  1187. return;
  1188. }
  1189. mutex_lock(&me->tx_lock);
  1190. }
  1191. dprintk(CVP_DSP, "%s: dsp initialized\n", __func__);
  1192. me->state = DSP_READY;
  1193. exit:
  1194. mutex_unlock(&me->tx_lock);
  1195. mutex_unlock(&device->lock);
  1196. }
  1197. /* 32 or 64 bit CPU Side Ptr <-> 2 32 bit DSP Pointers. Dirty Fix. */
  1198. static void *ptr_dsp2cpu(uint32_t session_cpu_high, uint32_t session_cpu_low)
  1199. {
  1200. void *inst;
  1201. if ((session_cpu_high == 0) && (sizeof(void *) == BITPTRSIZE32)) {
  1202. inst = (void *)((uintptr_t)session_cpu_low);
  1203. } else if ((session_cpu_high != 0) && (sizeof(void *) == BITPTRSIZE64)) {
  1204. inst = (void *)((uintptr_t)(((uint64_t)session_cpu_high) << 32
  1205. | session_cpu_low));
  1206. } else {
  1207. dprintk(CVP_ERR,
  1208. "%s Invalid _cpu_high = 0x%x _cpu_low = 0x%x\n",
  1209. __func__, session_cpu_high, session_cpu_low);
  1210. inst = NULL;
  1211. }
  1212. return inst;
  1213. }
  1214. static void print_power(const struct eva_power_req *pwr_req)
  1215. {
  1216. if (pwr_req) {
  1217. dprintk(CVP_DSP, "Clock: Fdu %d Ica %d Od %d Mpu %d Fw %d",
  1218. pwr_req->clock_fdu, pwr_req->clock_ica,
  1219. pwr_req->clock_od, pwr_req->clock_mpu,
  1220. pwr_req->clock_fw);
  1221. dprintk(CVP_DSP, "OpClock: Fdu %d Ica %d Od %d Mpu %d Fw %d",
  1222. pwr_req->op_clock_fdu, pwr_req->op_clock_ica,
  1223. pwr_req->op_clock_od, pwr_req->op_clock_mpu,
  1224. pwr_req->op_clock_fw);
  1225. dprintk(CVP_DSP, "Actual Bw: Ddr %d, SysCache %d",
  1226. pwr_req->bw_ddr, pwr_req->bw_sys_cache);
  1227. dprintk(CVP_DSP, "OpBw: Ddr %d, SysCache %d",
  1228. pwr_req->op_bw_ddr, pwr_req->op_bw_sys_cache);
  1229. }
  1230. }
  1231. static void __dsp_cvp_sess_create(struct cvp_dsp_cmd_msg *cmd)
  1232. {
  1233. struct cvp_dsp_apps *me = &gfa_cv;
  1234. struct msm_cvp_inst *inst = NULL;
  1235. uint64_t inst_handle = 0;
  1236. int rc = 0;
  1237. struct cvp_dsp2cpu_cmd *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
  1238. struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
  1239. struct pid *pid_s = NULL;
  1240. struct task_struct *task = NULL;
  1241. struct cvp_hfi_device *hdev;
  1242. cmd->ret = 0;
  1243. dprintk(CVP_DSP,
  1244. "%s sess Type %d Mask %d Prio %d Sec %d pid 0x%x\n",
  1245. __func__, dsp2cpu_cmd->session_type,
  1246. dsp2cpu_cmd->kernel_mask,
  1247. dsp2cpu_cmd->session_prio,
  1248. dsp2cpu_cmd->is_secure,
  1249. dsp2cpu_cmd->pid);
  1250. pid_s = find_get_pid(dsp2cpu_cmd->pid);
  1251. if (pid_s == NULL) {
  1252. dprintk(CVP_WARN, "%s incorrect pid\n", __func__);
  1253. cmd->ret = -1;
  1254. return;
  1255. }
  1256. dprintk(CVP_DSP, "%s get pid_s 0x%x from pidA 0x%x\n", __func__,
  1257. pid_s, dsp2cpu_cmd->pid);
  1258. task = get_pid_task(pid_s, PIDTYPE_TGID);
  1259. if (!task) {
  1260. dprintk(CVP_WARN, "%s task doesn't exist\n", __func__);
  1261. cmd->ret = -1;
  1262. return;
  1263. }
  1264. rc = eva_fastrpc_driver_register(dsp2cpu_cmd->pid);
  1265. if (rc) {
  1266. dprintk(CVP_ERR, "%s Register fastrpc driver fail\n", __func__);
  1267. put_task_struct(task);
  1268. cmd->ret = -1;
  1269. return;
  1270. }
  1271. inst = msm_cvp_open(MSM_CORE_CVP, MSM_CVP_DSP, task);
  1272. if (!inst) {
  1273. dprintk(CVP_ERR, "%s Failed create instance\n", __func__);
  1274. goto fail_msm_cvp_open;
  1275. }
  1276. inst->process_id = dsp2cpu_cmd->pid;
  1277. inst->prop.kernel_mask = dsp2cpu_cmd->kernel_mask;
  1278. inst->prop.type = dsp2cpu_cmd->session_type;
  1279. inst->prop.priority = dsp2cpu_cmd->session_prio;
  1280. inst->prop.is_secure = dsp2cpu_cmd->is_secure;
  1281. inst->prop.dsp_mask = dsp2cpu_cmd->dsp_access_mask;
  1282. rc = msm_cvp_session_create(inst);
  1283. if (rc) {
  1284. dprintk(CVP_ERR, "Warning: send Session Create failed\n");
  1285. goto fail_session_create;
  1286. } else {
  1287. dprintk(CVP_DSP, "%s DSP Session Create done\n", __func__);
  1288. }
  1289. /* Get session id */
  1290. rc = msm_cvp_get_session_info(inst, &cmd->session_id);
  1291. if (rc) {
  1292. dprintk(CVP_ERR, "Warning: get session index failed %d\n", rc);
  1293. goto fail_get_session_info;
  1294. }
  1295. inst_handle = (uint64_t)inst;
  1296. cmd->session_cpu_high = (uint32_t)((inst_handle & HIGH32) >> 32);
  1297. cmd->session_cpu_low = (uint32_t)(inst_handle & LOW32);
  1298. frpc_node = cvp_get_fastrpc_node_with_handle(dsp2cpu_cmd->pid);
  1299. if (frpc_node) {
  1300. eva_fastrpc_driver_add_sess(frpc_node, inst);
  1301. cvp_put_fastrpc_node(frpc_node);
  1302. }
  1303. inst->task = task;
  1304. dprintk(CVP_DSP,
  1305. "%s CREATE_SESS id 0x%x, cpu_low 0x%x, cpu_high 0x%x\n",
  1306. __func__, cmd->session_id, cmd->session_cpu_low,
  1307. cmd->session_cpu_high);
  1308. spin_lock(&inst->core->resources.pm_qos.lock);
  1309. inst->core->resources.pm_qos.off_vote_cnt++;
  1310. spin_unlock(&inst->core->resources.pm_qos.lock);
  1311. hdev = inst->core->device;
  1312. call_hfi_op(hdev, pm_qos_update, hdev->hfi_device_data);
  1313. return;
  1314. fail_get_session_info:
  1315. fail_session_create:
  1316. msm_cvp_close(inst);
  1317. fail_msm_cvp_open:
  1318. /* unregister fastrpc driver */
  1319. eva_fastrpc_driver_unregister(dsp2cpu_cmd->pid, false);
  1320. put_task_struct(task);
  1321. cmd->ret = -1;
  1322. }
  1323. static void __dsp_cvp_sess_delete(struct cvp_dsp_cmd_msg *cmd)
  1324. {
  1325. struct cvp_dsp_apps *me = &gfa_cv;
  1326. struct msm_cvp_inst *inst;
  1327. int rc;
  1328. struct cvp_dsp2cpu_cmd *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
  1329. struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
  1330. struct task_struct *task = NULL;
  1331. struct cvp_hfi_device *hdev;
  1332. cmd->ret = 0;
  1333. dprintk(CVP_DSP,
  1334. "%s sess id 0x%x low 0x%x high 0x%x, pid 0x%x\n",
  1335. __func__, dsp2cpu_cmd->session_id,
  1336. dsp2cpu_cmd->session_cpu_low,
  1337. dsp2cpu_cmd->session_cpu_high,
  1338. dsp2cpu_cmd->pid);
  1339. frpc_node = cvp_get_fastrpc_node_with_handle(dsp2cpu_cmd->pid);
  1340. if (!frpc_node) {
  1341. dprintk(CVP_ERR, "%s pid 0x%x not registered with fastrpc\n",
  1342. __func__, dsp2cpu_cmd->pid);
  1343. cmd->ret = -1;
  1344. return;
  1345. }
  1346. cvp_put_fastrpc_node(frpc_node);
  1347. inst = (struct msm_cvp_inst *)ptr_dsp2cpu(
  1348. dsp2cpu_cmd->session_cpu_high,
  1349. dsp2cpu_cmd->session_cpu_low);
  1350. if (!inst || !is_cvp_inst_valid(inst)) {
  1351. dprintk(CVP_ERR, "%s incorrect session ID\n", __func__);
  1352. cmd->ret = -1;
  1353. goto dsp_fail_delete;
  1354. }
  1355. task = inst->task;
  1356. spin_lock(&inst->core->resources.pm_qos.lock);
  1357. if (inst->core->resources.pm_qos.off_vote_cnt > 0)
  1358. inst->core->resources.pm_qos.off_vote_cnt--;
  1359. else
  1360. dprintk(CVP_WARN, "%s Unexpected pm_qos off vote %d\n",
  1361. __func__,
  1362. inst->core->resources.pm_qos.off_vote_cnt);
  1363. spin_unlock(&inst->core->resources.pm_qos.lock);
  1364. hdev = inst->core->device;
  1365. call_hfi_op(hdev, pm_qos_update, hdev->hfi_device_data);
  1366. rc = msm_cvp_close(inst);
  1367. if (rc) {
  1368. dprintk(CVP_ERR, "Warning: Failed to close cvp instance\n");
  1369. cmd->ret = -1;
  1370. goto dsp_fail_delete;
  1371. }
  1372. /* unregister fastrpc driver */
  1373. eva_fastrpc_driver_unregister(dsp2cpu_cmd->pid, false);
  1374. if (task)
  1375. put_task_struct(task);
  1376. dprintk(CVP_DSP, "%s DSP2CPU_DETELE_SESSION Done, nr_maps %d\n",
  1377. __func__, atomic_read(&nr_maps));
  1378. dsp_fail_delete:
  1379. return;
  1380. }
  1381. static void __dsp_cvp_power_req(struct cvp_dsp_cmd_msg *cmd)
  1382. {
  1383. struct cvp_dsp_apps *me = &gfa_cv;
  1384. struct msm_cvp_inst *inst;
  1385. int rc;
  1386. struct cvp_dsp2cpu_cmd *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
  1387. cmd->ret = 0;
  1388. dprintk(CVP_DSP,
  1389. "%s sess id 0x%x, low 0x%x, high 0x%x\n",
  1390. __func__, dsp2cpu_cmd->session_id,
  1391. dsp2cpu_cmd->session_cpu_low,
  1392. dsp2cpu_cmd->session_cpu_high);
  1393. inst = (struct msm_cvp_inst *)ptr_dsp2cpu(
  1394. dsp2cpu_cmd->session_cpu_high,
  1395. dsp2cpu_cmd->session_cpu_low);
  1396. if (!inst) {
  1397. cmd->ret = -1;
  1398. goto dsp_fail_power_req;
  1399. }
  1400. print_power(&dsp2cpu_cmd->power_req);
  1401. inst->prop.cycles[HFI_HW_FDU] = dsp2cpu_cmd->power_req.clock_fdu;
  1402. inst->prop.cycles[HFI_HW_ICA] = dsp2cpu_cmd->power_req.clock_ica;
  1403. inst->prop.cycles[HFI_HW_OD] = dsp2cpu_cmd->power_req.clock_od;
  1404. inst->prop.cycles[HFI_HW_MPU] = dsp2cpu_cmd->power_req.clock_mpu;
  1405. inst->prop.fw_cycles = dsp2cpu_cmd->power_req.clock_fw;
  1406. inst->prop.ddr_bw = dsp2cpu_cmd->power_req.bw_ddr;
  1407. inst->prop.ddr_cache = dsp2cpu_cmd->power_req.bw_sys_cache;
  1408. inst->prop.op_cycles[HFI_HW_FDU] = dsp2cpu_cmd->power_req.op_clock_fdu;
  1409. inst->prop.op_cycles[HFI_HW_ICA] = dsp2cpu_cmd->power_req.op_clock_ica;
  1410. inst->prop.op_cycles[HFI_HW_OD] = dsp2cpu_cmd->power_req.op_clock_od;
  1411. inst->prop.op_cycles[HFI_HW_MPU] = dsp2cpu_cmd->power_req.op_clock_mpu;
  1412. inst->prop.fw_op_cycles = dsp2cpu_cmd->power_req.op_clock_fw;
  1413. inst->prop.ddr_op_bw = dsp2cpu_cmd->power_req.op_bw_ddr;
  1414. inst->prop.ddr_op_cache = dsp2cpu_cmd->power_req.op_bw_sys_cache;
  1415. rc = msm_cvp_update_power(inst);
  1416. if (rc) {
  1417. /*
  1418. *May need to define more error types
  1419. * Check UMD implementation
  1420. */
  1421. dprintk(CVP_ERR, "%s Failed update power\n", __func__);
  1422. cmd->ret = -1;
  1423. goto dsp_fail_power_req;
  1424. }
  1425. dprintk(CVP_DSP, "%s DSP2CPU_POWER_REQUEST Done\n", __func__);
  1426. dsp_fail_power_req:
  1427. return;
  1428. }
  1429. static void __dsp_cvp_buf_register(struct cvp_dsp_cmd_msg *cmd)
  1430. {
  1431. struct cvp_dsp_apps *me = &gfa_cv;
  1432. struct msm_cvp_inst *inst;
  1433. struct eva_kmd_arg *kmd;
  1434. struct eva_kmd_buffer *kmd_buf;
  1435. int rc;
  1436. struct cvp_dsp2cpu_cmd *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
  1437. cmd->ret = 0;
  1438. dprintk(CVP_DSP,
  1439. "%s sess id 0x%x, low 0x%x, high 0x%x, pid 0x%x\n",
  1440. __func__, dsp2cpu_cmd->session_id,
  1441. dsp2cpu_cmd->session_cpu_low,
  1442. dsp2cpu_cmd->session_cpu_high,
  1443. dsp2cpu_cmd->pid);
  1444. kmd = kzalloc(sizeof(*kmd), GFP_KERNEL);
  1445. if (!kmd) {
  1446. dprintk(CVP_ERR, "%s kzalloc failure\n", __func__);
  1447. cmd->ret = -1;
  1448. return;
  1449. }
  1450. inst = (struct msm_cvp_inst *)ptr_dsp2cpu(
  1451. dsp2cpu_cmd->session_cpu_high,
  1452. dsp2cpu_cmd->session_cpu_low);
  1453. kmd->type = EVA_KMD_REGISTER_BUFFER;
  1454. kmd_buf = (struct eva_kmd_buffer *)&(kmd->data.regbuf);
  1455. kmd_buf->type = EVA_KMD_BUFTYPE_INPUT;
  1456. kmd_buf->index = dsp2cpu_cmd->sbuf.index;
  1457. kmd_buf->fd = dsp2cpu_cmd->sbuf.fd;
  1458. kmd_buf->size = dsp2cpu_cmd->sbuf.size;
  1459. kmd_buf->offset = dsp2cpu_cmd->sbuf.offset;
  1460. kmd_buf->pixelformat = 0;
  1461. kmd_buf->flags = EVA_KMD_FLAG_UNSECURE;
  1462. rc = msm_cvp_register_buffer(inst, kmd_buf);
  1463. if (rc) {
  1464. dprintk(CVP_ERR, "%s Failed to register buffer\n", __func__);
  1465. cmd->ret = -1;
  1466. goto dsp_fail_buf_reg;
  1467. }
  1468. dprintk(CVP_DSP, "%s register buffer done\n", __func__);
  1469. cmd->sbuf.iova = kmd_buf->reserved[0];
  1470. cmd->sbuf.size = kmd_buf->size;
  1471. cmd->sbuf.fd = kmd_buf->fd;
  1472. cmd->sbuf.index = kmd_buf->index;
  1473. cmd->sbuf.offset = kmd_buf->offset;
  1474. dprintk(CVP_DSP, "%s: fd %d, iova 0x%x\n", __func__,
  1475. cmd->sbuf.fd, cmd->sbuf.iova);
  1476. dsp_fail_buf_reg:
  1477. kfree(kmd);
  1478. }
  1479. static void __dsp_cvp_buf_deregister(struct cvp_dsp_cmd_msg *cmd)
  1480. {
  1481. struct cvp_dsp_apps *me = &gfa_cv;
  1482. struct msm_cvp_inst *inst;
  1483. struct eva_kmd_arg *kmd;
  1484. struct eva_kmd_buffer *kmd_buf;
  1485. int rc;
  1486. struct cvp_dsp2cpu_cmd *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
  1487. cmd->ret = 0;
  1488. dprintk(CVP_DSP,
  1489. "%s : sess id 0x%x, low 0x%x, high 0x%x, pid 0x%x\n",
  1490. __func__, dsp2cpu_cmd->session_id,
  1491. dsp2cpu_cmd->session_cpu_low,
  1492. dsp2cpu_cmd->session_cpu_high,
  1493. dsp2cpu_cmd->pid);
  1494. kmd = kzalloc(sizeof(*kmd), GFP_KERNEL);
  1495. if (!kmd) {
  1496. dprintk(CVP_ERR, "%s kzalloc failure\n", __func__);
  1497. cmd->ret = -1;
  1498. return;
  1499. }
  1500. inst = (struct msm_cvp_inst *)ptr_dsp2cpu(
  1501. dsp2cpu_cmd->session_cpu_high,
  1502. dsp2cpu_cmd->session_cpu_low);
  1503. kmd->type = EVA_KMD_UNREGISTER_BUFFER;
  1504. kmd_buf = (struct eva_kmd_buffer *)&(kmd->data.regbuf);
  1505. kmd_buf->type = EVA_KMD_UNREGISTER_BUFFER;
  1506. kmd_buf->type = EVA_KMD_BUFTYPE_INPUT;
  1507. kmd_buf->index = dsp2cpu_cmd->sbuf.index;
  1508. kmd_buf->fd = dsp2cpu_cmd->sbuf.fd;
  1509. kmd_buf->size = dsp2cpu_cmd->sbuf.size;
  1510. kmd_buf->offset = dsp2cpu_cmd->sbuf.offset;
  1511. kmd_buf->pixelformat = 0;
  1512. kmd_buf->flags = EVA_KMD_FLAG_UNSECURE;
  1513. rc = msm_cvp_unregister_buffer(inst, kmd_buf);
  1514. if (rc) {
  1515. dprintk(CVP_ERR, "%s Failed to deregister buffer\n", __func__);
  1516. cmd->ret = -1;
  1517. goto fail_dsp_buf_dereg;
  1518. }
  1519. dprintk(CVP_DSP, "%s deregister buffer done\n", __func__);
  1520. fail_dsp_buf_dereg:
  1521. kfree(kmd);
  1522. }
  1523. static void __dsp_cvp_mem_alloc(struct cvp_dsp_cmd_msg *cmd)
  1524. {
  1525. struct cvp_dsp_apps *me = &gfa_cv;
  1526. struct msm_cvp_inst *inst;
  1527. int rc;
  1528. struct cvp_internal_buf *buf = NULL;
  1529. struct cvp_dsp2cpu_cmd *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
  1530. uint64_t v_dsp_addr = 0;
  1531. struct fastrpc_device *frpc_device = NULL;
  1532. struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
  1533. cmd->ret = 0;
  1534. dprintk(CVP_DSP,
  1535. "%s sess id 0x%x, low 0x%x, high 0x%x, pid 0x%x\n",
  1536. __func__, dsp2cpu_cmd->session_id,
  1537. dsp2cpu_cmd->session_cpu_low,
  1538. dsp2cpu_cmd->session_cpu_high,
  1539. dsp2cpu_cmd->pid);
  1540. frpc_node = cvp_get_fastrpc_node_with_handle(dsp2cpu_cmd->pid);
  1541. if (!frpc_node) {
  1542. dprintk(CVP_ERR, "%s Failed to find fastrpc node 0x%x\n",
  1543. __func__, dsp2cpu_cmd->pid);
  1544. goto fail_fastrpc_node;
  1545. }
  1546. frpc_device = frpc_node->cvp_fastrpc_device;
  1547. inst = (struct msm_cvp_inst *)ptr_dsp2cpu(
  1548. dsp2cpu_cmd->session_cpu_high,
  1549. dsp2cpu_cmd->session_cpu_low);
  1550. buf = cvp_kmem_cache_zalloc(&cvp_driver->buf_cache, GFP_KERNEL);
  1551. if (!buf)
  1552. goto fail_kzalloc_buf;
  1553. rc = cvp_allocate_dsp_bufs(inst, buf,
  1554. dsp2cpu_cmd->sbuf.size,
  1555. dsp2cpu_cmd->sbuf.type);
  1556. if (rc)
  1557. goto fail_allocate_dsp_buf;
  1558. rc = eva_fastrpc_dev_map_dma(frpc_device, buf,
  1559. dsp2cpu_cmd->sbuf.dsp_remote_map,
  1560. &v_dsp_addr);
  1561. if (rc) {
  1562. dprintk(CVP_ERR, "%s Failed to map buffer 0x%x\n", __func__,
  1563. rc);
  1564. goto fail_fastrpc_dev_map_dma;
  1565. }
  1566. mutex_lock(&inst->cvpdspbufs.lock);
  1567. list_add_tail(&buf->list, &inst->cvpdspbufs.list);
  1568. mutex_unlock(&inst->cvpdspbufs.lock);
  1569. dprintk(CVP_DSP, "%s allocate buffer done, addr 0x%llx\n",
  1570. __func__, v_dsp_addr);
  1571. cmd->sbuf.size = buf->smem->size;
  1572. cmd->sbuf.fd = buf->fd;
  1573. cmd->sbuf.offset = 0;
  1574. cmd->sbuf.iova = buf->smem->device_addr;
  1575. cmd->sbuf.v_dsp_addr = v_dsp_addr;
  1576. dprintk(CVP_DSP, "%s: size %d, iova 0x%x, v_dsp_addr 0x%llx\n",
  1577. __func__, cmd->sbuf.size, cmd->sbuf.iova,
  1578. cmd->sbuf.v_dsp_addr);
  1579. cvp_put_fastrpc_node(frpc_node);
  1580. return;
  1581. fail_fastrpc_dev_map_dma:
  1582. cvp_release_dsp_buffers(inst, buf);
  1583. fail_allocate_dsp_buf:
  1584. cvp_kmem_cache_free(&cvp_driver->buf_cache, buf);
  1585. fail_kzalloc_buf:
  1586. fail_fastrpc_node:
  1587. cmd->ret = -1;
  1588. cvp_put_fastrpc_node(frpc_node);
  1589. return;
  1590. }
  1591. static void __dsp_cvp_mem_free(struct cvp_dsp_cmd_msg *cmd)
  1592. {
  1593. struct cvp_dsp_apps *me = &gfa_cv;
  1594. struct msm_cvp_inst *inst;
  1595. int rc;
  1596. struct cvp_internal_buf *buf = NULL;
  1597. struct list_head *ptr = NULL, *next = NULL;
  1598. struct msm_cvp_list *buf_list = NULL;
  1599. struct cvp_dsp2cpu_cmd *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
  1600. struct fastrpc_device *frpc_device = NULL;
  1601. struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
  1602. cmd->ret = 0;
  1603. dprintk(CVP_DSP,
  1604. "%s sess id 0x%x, low 0x%x, high 0x%x, pid 0x%x\n",
  1605. __func__, dsp2cpu_cmd->session_id,
  1606. dsp2cpu_cmd->session_cpu_low,
  1607. dsp2cpu_cmd->session_cpu_high,
  1608. dsp2cpu_cmd->pid);
  1609. inst = (struct msm_cvp_inst *)ptr_dsp2cpu(
  1610. dsp2cpu_cmd->session_cpu_high,
  1611. dsp2cpu_cmd->session_cpu_low);
  1612. if (!inst) {
  1613. dprintk(CVP_ERR, "%s Failed to get inst\n",
  1614. __func__);
  1615. cmd->ret = -1;
  1616. return;
  1617. }
  1618. frpc_node = cvp_get_fastrpc_node_with_handle(dsp2cpu_cmd->pid);
  1619. if (!frpc_node) {
  1620. dprintk(CVP_ERR, "%s Failed to find fastrpc node 0x%x\n",
  1621. __func__, dsp2cpu_cmd->pid);
  1622. cmd->ret = -1;
  1623. return;
  1624. }
  1625. frpc_device = frpc_node->cvp_fastrpc_device;
  1626. buf_list = &inst->cvpdspbufs;
  1627. mutex_lock(&buf_list->lock);
  1628. list_for_each_safe(ptr, next, &buf_list->list) {
  1629. buf = list_entry(ptr, struct cvp_internal_buf, list);
  1630. if (!buf->smem) {
  1631. dprintk(CVP_DSP, "Empyt smem\n");
  1632. continue;
  1633. }
  1634. /* Verify with device addr */
  1635. if (buf->smem->device_addr == dsp2cpu_cmd->sbuf.iova) {
  1636. dprintk(CVP_DSP, "%s find device addr 0x%x\n",
  1637. __func__, buf->smem->device_addr);
  1638. dprintk(CVP_DSP, "fd in list 0x%x, fd from dsp 0x%x\n",
  1639. buf->fd, dsp2cpu_cmd->sbuf.fd);
  1640. rc = eva_fastrpc_dev_unmap_dma(frpc_device, buf);
  1641. if (rc) {
  1642. dprintk(CVP_ERR,
  1643. "%s Failed to unmap buffer 0x%x\n",
  1644. __func__, rc);
  1645. cmd->ret = -1;
  1646. goto fail_fastrpc_dev_unmap_dma;
  1647. }
  1648. rc = cvp_release_dsp_buffers(inst, buf);
  1649. if (rc) {
  1650. dprintk(CVP_ERR,
  1651. "%s Failed to free buffer 0x%x\n",
  1652. __func__, rc);
  1653. cmd->ret = -1;
  1654. goto fail_release_buf;
  1655. }
  1656. list_del(&buf->list);
  1657. cvp_kmem_cache_free(&cvp_driver->buf_cache, buf);
  1658. break;
  1659. }
  1660. }
  1661. fail_release_buf:
  1662. fail_fastrpc_dev_unmap_dma:
  1663. mutex_unlock(&buf_list->lock);
  1664. cvp_put_fastrpc_node(frpc_node);
  1665. }
  1666. static void __dsp_cvp_sess_start(struct cvp_dsp_cmd_msg *cmd)
  1667. {
  1668. struct cvp_dsp_apps *me = &gfa_cv;
  1669. struct msm_cvp_inst *inst;
  1670. int rc;
  1671. struct cvp_dsp2cpu_cmd *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
  1672. cmd->ret = 0;
  1673. dprintk(CVP_DSP,
  1674. "%s sess id 0x%x, low 0x%x, high 0x%x, pid 0x%x\n",
  1675. __func__, dsp2cpu_cmd->session_id,
  1676. dsp2cpu_cmd->session_cpu_low,
  1677. dsp2cpu_cmd->session_cpu_high,
  1678. dsp2cpu_cmd->pid);
  1679. inst = (struct msm_cvp_inst *)ptr_dsp2cpu(
  1680. dsp2cpu_cmd->session_cpu_high,
  1681. dsp2cpu_cmd->session_cpu_low);
  1682. rc = msm_cvp_session_start(inst, (struct eva_kmd_arg *)NULL);
  1683. if (rc) {
  1684. dprintk(CVP_ERR, "%s Failed to start session\n", __func__);
  1685. cmd->ret = -1;
  1686. return;
  1687. }
  1688. dprintk(CVP_DSP, "%s session started\n", __func__);
  1689. }
  1690. static void __dsp_cvp_sess_stop(struct cvp_dsp_cmd_msg *cmd)
  1691. {
  1692. struct cvp_dsp_apps *me = &gfa_cv;
  1693. struct msm_cvp_inst *inst;
  1694. int rc;
  1695. struct cvp_dsp2cpu_cmd *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
  1696. cmd->ret = 0;
  1697. dprintk(CVP_DSP,
  1698. "%s sess id 0x%x, low 0x%x, high 0x%x, pid 0x%x\n",
  1699. __func__, dsp2cpu_cmd->session_id,
  1700. dsp2cpu_cmd->session_cpu_low,
  1701. dsp2cpu_cmd->session_cpu_high,
  1702. dsp2cpu_cmd->pid);
  1703. inst = (struct msm_cvp_inst *)ptr_dsp2cpu(
  1704. dsp2cpu_cmd->session_cpu_high,
  1705. dsp2cpu_cmd->session_cpu_low);
  1706. rc = msm_cvp_session_stop(inst, (struct eva_kmd_arg *)NULL);
  1707. if (rc) {
  1708. dprintk(CVP_ERR, "%s Failed to stop session\n", __func__);
  1709. cmd->ret = -1;
  1710. return;
  1711. }
  1712. dprintk(CVP_DSP, "%s session stoppd\n", __func__);
  1713. }
  1714. static int cvp_dsp_thread(void *data)
  1715. {
  1716. int rc = 0, old_state;
  1717. struct cvp_dsp_apps *me = &gfa_cv;
  1718. struct cvp_dsp_cmd_msg cmd;
  1719. struct cvp_hfi_device *hdev;
  1720. struct msm_cvp_core *core;
  1721. core = list_first_entry(&cvp_driver->cores, struct msm_cvp_core, list);
  1722. if (!core) {
  1723. dprintk(CVP_ERR, "%s: Failed to find core\n", __func__);
  1724. rc = -EINVAL;
  1725. goto exit;
  1726. }
  1727. hdev = (struct cvp_hfi_device *)core->device;
  1728. if (!hdev) {
  1729. dprintk(CVP_ERR, "%s Invalid device handle\n", __func__);
  1730. rc = -EINVAL;
  1731. goto exit;
  1732. }
  1733. wait_dsp:
  1734. rc = wait_for_completion_interruptible(
  1735. &me->completions[CPU2DSP_MAX_CMD]);
  1736. if (me->state == DSP_INVALID)
  1737. goto exit;
  1738. if (me->state == DSP_UNINIT)
  1739. goto wait_dsp;
  1740. if (me->state == DSP_PROBED) {
  1741. cvp_dsp_send_hfi_queue();
  1742. goto wait_dsp;
  1743. }
  1744. cmd.type = me->pending_dsp2cpu_cmd.type;
  1745. if (rc == -ERESTARTSYS) {
  1746. dprintk(CVP_WARN, "%s received interrupt signal\n", __func__);
  1747. } else {
  1748. mutex_lock(&me->rx_lock);
  1749. if (me->state == DSP_UNINIT) {
  1750. /* DSP SSR may have happened */
  1751. mutex_unlock(&me->rx_lock);
  1752. goto wait_dsp;
  1753. }
  1754. switch (me->pending_dsp2cpu_cmd.type) {
  1755. case DSP2CPU_POWERON:
  1756. {
  1757. if (me->state == DSP_READY) {
  1758. cmd.ret = 0;
  1759. break;
  1760. }
  1761. mutex_lock(&me->tx_lock);
  1762. old_state = me->state;
  1763. me->state = DSP_READY;
  1764. rc = call_hfi_op(hdev, resume, hdev->hfi_device_data);
  1765. if (rc) {
  1766. dprintk(CVP_WARN, "%s Failed to resume cvp\n",
  1767. __func__);
  1768. me->state = old_state;
  1769. mutex_unlock(&me->tx_lock);
  1770. cmd.ret = 1;
  1771. break;
  1772. }
  1773. mutex_unlock(&me->tx_lock);
  1774. cmd.ret = 0;
  1775. break;
  1776. }
  1777. case DSP2CPU_POWEROFF:
  1778. {
  1779. me->state = DSP_SUSPEND;
  1780. cmd.ret = 0;
  1781. break;
  1782. }
  1783. case DSP2CPU_CREATE_SESSION:
  1784. {
  1785. __dsp_cvp_sess_create(&cmd);
  1786. break;
  1787. }
  1788. case DSP2CPU_DETELE_SESSION:
  1789. {
  1790. __dsp_cvp_sess_delete(&cmd);
  1791. break;
  1792. }
  1793. case DSP2CPU_POWER_REQUEST:
  1794. {
  1795. __dsp_cvp_power_req(&cmd);
  1796. break;
  1797. }
  1798. case DSP2CPU_REGISTER_BUFFER:
  1799. {
  1800. __dsp_cvp_buf_register(&cmd);
  1801. break;
  1802. }
  1803. case DSP2CPU_DEREGISTER_BUFFER:
  1804. {
  1805. __dsp_cvp_buf_deregister(&cmd);
  1806. break;
  1807. }
  1808. case DSP2CPU_MEM_ALLOC:
  1809. {
  1810. __dsp_cvp_mem_alloc(&cmd);
  1811. break;
  1812. }
  1813. case DSP2CPU_MEM_FREE:
  1814. {
  1815. __dsp_cvp_mem_free(&cmd);
  1816. break;
  1817. }
  1818. case DSP2CPU_START_SESSION:
  1819. {
  1820. __dsp_cvp_sess_start(&cmd);
  1821. break;
  1822. }
  1823. case DSP2CPU_STOP_SESSION:
  1824. {
  1825. __dsp_cvp_sess_stop(&cmd);
  1826. break;
  1827. }
  1828. default:
  1829. dprintk(CVP_ERR, "unrecognaized dsp cmds: %d\n",
  1830. me->pending_dsp2cpu_cmd.type);
  1831. break;
  1832. }
  1833. me->pending_dsp2cpu_cmd.type = CVP_INVALID_RPMSG_TYPE;
  1834. mutex_unlock(&me->rx_lock);
  1835. }
  1836. /* Responds to DSP */
  1837. rc = cvp_dsp_send_cmd(&cmd, sizeof(struct cvp_dsp_cmd_msg));
  1838. if (rc)
  1839. dprintk(CVP_ERR,
  1840. "%s: cvp_dsp_send_cmd failed rc = %d cmd type=%d\n",
  1841. __func__, rc, cmd.type);
  1842. goto wait_dsp;
  1843. exit:
  1844. dprintk(CVP_DBG, "dsp thread exit\n");
  1845. return rc;
  1846. }
  1847. int cvp_dsp_device_init(void)
  1848. {
  1849. struct cvp_dsp_apps *me = &gfa_cv;
  1850. char tname[16];
  1851. int rc;
  1852. int i;
  1853. char name[CVP_FASTRPC_DRIVER_NAME_SIZE] = "qcom,fastcv0\0";
  1854. add_va_node_to_list(CVP_DBG_DUMP, &gfa_cv, sizeof(struct cvp_dsp_apps),
  1855. "cvp_dsp_apps-gfa_cv", false);
  1856. mutex_init(&me->tx_lock);
  1857. mutex_init(&me->rx_lock);
  1858. me->state = DSP_INVALID;
  1859. me->hyp_assigned = false;
  1860. for (i = 0; i <= CPU2DSP_MAX_CMD; i++)
  1861. init_completion(&me->completions[i]);
  1862. me->pending_dsp2cpu_cmd.type = CVP_INVALID_RPMSG_TYPE;
  1863. me->pending_dsp2cpu_rsp.type = CVP_INVALID_RPMSG_TYPE;
  1864. INIT_MSM_CVP_LIST(&me->fastrpc_driver_list);
  1865. mutex_init(&me->driver_name_lock);
  1866. for (i = 0; i < MAX_FASTRPC_DRIVER_NUM; i++) {
  1867. me->cvp_fastrpc_name[i].status = DRIVER_NAME_AVAILABLE;
  1868. snprintf(me->cvp_fastrpc_name[i].name, sizeof(name), name);
  1869. name[11]++;
  1870. }
  1871. rc = register_rpmsg_driver(&cvp_dsp_rpmsg_client);
  1872. if (rc) {
  1873. dprintk(CVP_ERR,
  1874. "%s : register_rpmsg_driver failed rc = %d\n",
  1875. __func__, rc);
  1876. goto register_bail;
  1877. }
  1878. snprintf(tname, sizeof(tname), "cvp-dsp-thread");
  1879. me->state = DSP_UNINIT;
  1880. me->dsp_thread = kthread_run(cvp_dsp_thread, me, tname);
  1881. if (!me->dsp_thread) {
  1882. dprintk(CVP_ERR, "%s create %s fail", __func__, tname);
  1883. rc = -ECHILD;
  1884. me->state = DSP_INVALID;
  1885. goto register_bail;
  1886. }
  1887. return 0;
  1888. register_bail:
  1889. return rc;
  1890. }
  1891. void cvp_dsp_device_exit(void)
  1892. {
  1893. struct cvp_dsp_apps *me = &gfa_cv;
  1894. int i;
  1895. mutex_lock(&me->tx_lock);
  1896. me->state = DSP_INVALID;
  1897. mutex_unlock(&me->tx_lock);
  1898. DEINIT_MSM_CVP_LIST(&me->fastrpc_driver_list);
  1899. for (i = 0; i <= CPU2DSP_MAX_CMD; i++)
  1900. complete_all(&me->completions[i]);
  1901. mutex_destroy(&me->tx_lock);
  1902. mutex_destroy(&me->rx_lock);
  1903. mutex_destroy(&me->driver_name_lock);
  1904. unregister_rpmsg_driver(&cvp_dsp_rpmsg_client);
  1905. }