msm_cvp_dsp.c 56 KB

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