msm_cvp.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include "msm_cvp.h"
  6. #include "cvp_hfi.h"
  7. #include "cvp_core_hfi.h"
  8. #include "msm_cvp_buf.h"
  9. struct cvp_power_level {
  10. unsigned long core_sum;
  11. unsigned long op_core_sum;
  12. unsigned long bw_sum;
  13. };
  14. int msm_cvp_get_session_info(struct msm_cvp_inst *inst, u32 *session)
  15. {
  16. int rc = 0;
  17. struct msm_cvp_inst *s;
  18. if (!inst || !inst->core || !session) {
  19. dprintk(CVP_ERR, "%s: invalid params\n", __func__);
  20. return -EINVAL;
  21. }
  22. s = cvp_get_inst_validate(inst->core, inst);
  23. if (!s)
  24. return -ECONNRESET;
  25. *session = hash32_ptr(inst->session);
  26. dprintk(CVP_SESS, "%s: id 0x%x\n", __func__, *session);
  27. cvp_put_inst(s);
  28. return rc;
  29. }
  30. static bool cvp_msg_pending(struct cvp_session_queue *sq,
  31. struct cvp_session_msg **msg, u64 *ktid)
  32. {
  33. struct cvp_session_msg *mptr, *dummy;
  34. bool result = false;
  35. mptr = NULL;
  36. spin_lock(&sq->lock);
  37. if (sq->state == QUEUE_INIT || sq->state == QUEUE_INVALID) {
  38. /* The session is being deleted */
  39. spin_unlock(&sq->lock);
  40. *msg = NULL;
  41. return true;
  42. }
  43. result = list_empty(&sq->msgs);
  44. if (!result) {
  45. if (!ktid) {
  46. mptr =
  47. list_first_entry(&sq->msgs, struct cvp_session_msg,
  48. node);
  49. list_del_init(&mptr->node);
  50. sq->msg_count--;
  51. } else {
  52. result = true;
  53. list_for_each_entry_safe(mptr, dummy, &sq->msgs, node) {
  54. if (*ktid == mptr->pkt.client_data.kdata) {
  55. list_del_init(&mptr->node);
  56. sq->msg_count--;
  57. result = false;
  58. break;
  59. }
  60. }
  61. if (result)
  62. mptr = NULL;
  63. }
  64. }
  65. spin_unlock(&sq->lock);
  66. *msg = mptr;
  67. return !result;
  68. }
  69. static int cvp_wait_process_message(struct msm_cvp_inst *inst,
  70. struct cvp_session_queue *sq, u64 *ktid,
  71. unsigned long timeout,
  72. struct eva_kmd_hfi_packet *out)
  73. {
  74. struct cvp_session_msg *msg = NULL;
  75. struct cvp_hfi_msg_session_hdr *hdr;
  76. int rc = 0;
  77. if (wait_event_timeout(sq->wq,
  78. cvp_msg_pending(sq, &msg, ktid), timeout) == 0) {
  79. dprintk(CVP_WARN, "session queue wait timeout\n");
  80. rc = -ETIMEDOUT;
  81. goto exit;
  82. }
  83. if (msg == NULL) {
  84. dprintk(CVP_WARN, "%s: queue state %d, msg cnt %d\n", __func__,
  85. sq->state, sq->msg_count);
  86. if (inst->state >= MSM_CVP_CLOSE_DONE ||
  87. (sq->state != QUEUE_ACTIVE &&
  88. sq->state != QUEUE_START)) {
  89. rc = -ECONNRESET;
  90. goto exit;
  91. }
  92. msm_cvp_comm_kill_session(inst);
  93. goto exit;
  94. }
  95. if (!out) {
  96. kmem_cache_free(cvp_driver->msg_cache, msg);
  97. goto exit;
  98. }
  99. hdr = (struct cvp_hfi_msg_session_hdr *)&msg->pkt;
  100. memcpy(out, &msg->pkt, get_msg_size(hdr));
  101. if (hdr->client_data.kdata >= get_pkt_array_size())
  102. msm_cvp_unmap_frame(inst, hdr->client_data.kdata);
  103. kmem_cache_free(cvp_driver->msg_cache, msg);
  104. exit:
  105. return rc;
  106. }
  107. static int msm_cvp_session_receive_hfi(struct msm_cvp_inst *inst,
  108. struct eva_kmd_hfi_packet *out_pkt)
  109. {
  110. unsigned long wait_time;
  111. struct cvp_session_queue *sq;
  112. struct msm_cvp_inst *s;
  113. int rc = 0;
  114. if (!inst) {
  115. dprintk(CVP_ERR, "%s invalid session\n", __func__);
  116. return -EINVAL;
  117. }
  118. s = cvp_get_inst_validate(inst->core, inst);
  119. if (!s)
  120. return -ECONNRESET;
  121. wait_time = msecs_to_jiffies(CVP_MAX_WAIT_TIME);
  122. sq = &inst->session_queue;
  123. rc = cvp_wait_process_message(inst, sq, NULL, wait_time, out_pkt);
  124. cvp_put_inst(inst);
  125. return rc;
  126. }
  127. static int msm_cvp_session_process_hfi(
  128. struct msm_cvp_inst *inst,
  129. struct eva_kmd_hfi_packet *in_pkt,
  130. unsigned int in_offset,
  131. unsigned int in_buf_num)
  132. {
  133. int pkt_idx, pkt_type, rc = 0;
  134. struct cvp_hfi_device *hdev;
  135. unsigned int offset = 0, buf_num = 0, signal;
  136. struct cvp_session_queue *sq;
  137. struct msm_cvp_inst *s;
  138. bool is_config_pkt;
  139. enum buf_map_type map_type;
  140. struct cvp_hfi_cmd_session_hdr *cmd_hdr;
  141. if (!inst || !inst->core || !in_pkt) {
  142. dprintk(CVP_ERR, "%s: invalid params\n", __func__);
  143. return -EINVAL;
  144. }
  145. s = cvp_get_inst_validate(inst->core, inst);
  146. if (!s)
  147. return -ECONNRESET;
  148. hdev = inst->core->device;
  149. pkt_idx = get_pkt_index((struct cvp_hal_session_cmd_pkt *)in_pkt);
  150. if (pkt_idx < 0) {
  151. dprintk(CVP_ERR, "%s incorrect packet %d, %x\n", __func__,
  152. in_pkt->pkt_data[0],
  153. in_pkt->pkt_data[1]);
  154. goto exit;
  155. } else {
  156. signal = cvp_hfi_defs[pkt_idx].resp;
  157. is_config_pkt = cvp_hfi_defs[pkt_idx].is_config_pkt;
  158. }
  159. if (signal == HAL_NO_RESP) {
  160. /* Frame packets are not allowed before session starts*/
  161. sq = &inst->session_queue;
  162. spin_lock(&sq->lock);
  163. if ((sq->state != QUEUE_START && !is_config_pkt) ||
  164. (sq->state >= QUEUE_INVALID)) {
  165. /*
  166. * A init packet is allowed in case of
  167. * QUEUE_ACTIVE, QUEUE_START, QUEUE_STOP
  168. * A frame packet is only allowed in case of
  169. * QUEUE_START
  170. */
  171. spin_unlock(&sq->lock);
  172. dprintk(CVP_ERR, "%s: invalid queue state %d\n",
  173. __func__, sq->state);
  174. rc = -EINVAL;
  175. goto exit;
  176. }
  177. spin_unlock(&sq->lock);
  178. }
  179. if (in_offset && in_buf_num) {
  180. offset = in_offset;
  181. buf_num = in_buf_num;
  182. }
  183. if (!is_buf_param_valid(buf_num, offset)) {
  184. dprintk(CVP_ERR, "Incorrect buffer num and offset in cmd\n");
  185. return -EINVAL;
  186. }
  187. rc = msm_cvp_proc_oob(inst, in_pkt);
  188. if (rc) {
  189. dprintk(CVP_ERR, "%s: failed to process OOB buffer", __func__);
  190. goto exit;
  191. }
  192. pkt_type = in_pkt->pkt_data[1];
  193. map_type = cvp_find_map_type(pkt_type);
  194. cmd_hdr = (struct cvp_hfi_cmd_session_hdr *)in_pkt;
  195. /* The kdata will be overriden by transaction ID if the cmd has buf */
  196. cmd_hdr->client_data.kdata = pkt_idx;
  197. if (map_type == MAP_PERSIST)
  198. rc = msm_cvp_map_user_persist(inst, in_pkt, offset, buf_num);
  199. else if (map_type == UNMAP_PERSIST)
  200. rc = msm_cvp_mark_user_persist(inst, in_pkt, offset, buf_num);
  201. else
  202. rc = msm_cvp_map_frame(inst, in_pkt, offset, buf_num);
  203. if (rc)
  204. goto exit;
  205. rc = call_hfi_op(hdev, session_send, (void *)inst->session, in_pkt);
  206. if (rc) {
  207. dprintk(CVP_ERR,
  208. "%s: Failed in call_hfi_op %d, %x\n",
  209. __func__, in_pkt->pkt_data[0], in_pkt->pkt_data[1]);
  210. goto exit;
  211. }
  212. if (signal != HAL_NO_RESP)
  213. dprintk(CVP_ERR, "%s signal %d from UMD is not HAL_NO_RESP\n",
  214. __func__, signal);
  215. exit:
  216. cvp_put_inst(inst);
  217. return rc;
  218. }
  219. static bool cvp_fence_wait(struct cvp_fence_queue *q,
  220. struct cvp_fence_command **fence,
  221. enum queue_state *state)
  222. {
  223. struct cvp_fence_command *f;
  224. *fence = NULL;
  225. mutex_lock(&q->lock);
  226. *state = q->state;
  227. if (*state != QUEUE_START) {
  228. mutex_unlock(&q->lock);
  229. return true;
  230. }
  231. if (list_empty(&q->wait_list)) {
  232. mutex_unlock(&q->lock);
  233. return false;
  234. }
  235. f = list_first_entry(&q->wait_list, struct cvp_fence_command, list);
  236. list_del_init(&f->list);
  237. list_add_tail(&f->list, &q->sched_list);
  238. mutex_unlock(&q->lock);
  239. *fence = f;
  240. return true;
  241. }
  242. static int cvp_readjust_clock(struct msm_cvp_core *core,
  243. u32 avg_cycles, enum hfi_hw_thread i)
  244. {
  245. int rc = 0;
  246. struct allowed_clock_rates_table *tbl = NULL;
  247. unsigned int tbl_size = 0;
  248. unsigned int cvp_min_rate = 0, cvp_max_rate = 0;
  249. unsigned long tmp = core->curr_freq;
  250. unsigned long lo_freq = 0;
  251. u32 j;
  252. tbl = core->resources.allowed_clks_tbl;
  253. tbl_size = core->resources.allowed_clks_tbl_size;
  254. cvp_min_rate = tbl[0].clock_rate;
  255. cvp_max_rate = tbl[tbl_size - 1].clock_rate;
  256. if (!((avg_cycles > core->dyn_clk.hi_ctrl_lim[i] &&
  257. core->curr_freq != cvp_max_rate) ||
  258. (avg_cycles <= core->dyn_clk.lo_ctrl_lim[i] &&
  259. core->curr_freq != cvp_min_rate))) {
  260. return rc;
  261. }
  262. core->curr_freq = ((avg_cycles * core->dyn_clk.sum_fps[i]) << 1)/3;
  263. dprintk(CVP_PWR,
  264. "%s - cycles tot %u, avg %u. sum_fps %u, cur_freq %u\n",
  265. __func__,
  266. core->dyn_clk.cycle[i].total,
  267. avg_cycles,
  268. core->dyn_clk.sum_fps[i],
  269. core->curr_freq);
  270. if (core->curr_freq > cvp_max_rate) {
  271. core->curr_freq = cvp_max_rate;
  272. lo_freq = (tbl_size > 1) ?
  273. tbl[tbl_size - 2].clock_rate :
  274. cvp_min_rate;
  275. } else if (core->curr_freq <= cvp_min_rate) {
  276. core->curr_freq = cvp_min_rate;
  277. lo_freq = cvp_min_rate;
  278. } else {
  279. for (j = 1; j < tbl_size; j++)
  280. if (core->curr_freq <= tbl[j].clock_rate)
  281. break;
  282. core->curr_freq = tbl[j].clock_rate;
  283. lo_freq = tbl[j-1].clock_rate;
  284. }
  285. if (core->orig_core_sum > core->curr_freq) {
  286. dprintk(CVP_PWR,
  287. "%s - %d - Cancel readjust, core %u, freq %u\n",
  288. __func__, i, core->orig_core_sum, core->curr_freq);
  289. core->curr_freq = tmp;
  290. return rc;
  291. }
  292. dprintk(CVP_PWR,
  293. "%s:%d - %d - Readjust to %u\n",
  294. __func__, __LINE__, i, core->curr_freq);
  295. rc = msm_cvp_set_clocks(core);
  296. if (rc) {
  297. dprintk(CVP_ERR,
  298. "Failed to set clock rate %u: %d %s\n",
  299. core->curr_freq, rc, __func__);
  300. core->curr_freq = tmp;
  301. } else {
  302. lo_freq = (lo_freq < core->dyn_clk.conf_freq) ?
  303. core->dyn_clk.conf_freq : lo_freq;
  304. core->dyn_clk.hi_ctrl_lim[i] = core->dyn_clk.sum_fps[i] ?
  305. ((core->curr_freq*3)>>1)/core->dyn_clk.sum_fps[i] : 0;
  306. core->dyn_clk.lo_ctrl_lim[i] =
  307. core->dyn_clk.sum_fps[i] ?
  308. ((lo_freq*3)>>1)/core->dyn_clk.sum_fps[i] : 0;
  309. dprintk(CVP_PWR,
  310. "%s - Readjust clk to %u. New lim [%d] hi %u lo %u\n",
  311. __func__, core->curr_freq, i,
  312. core->dyn_clk.hi_ctrl_lim[i],
  313. core->dyn_clk.lo_ctrl_lim[i]);
  314. }
  315. return rc;
  316. }
  317. static int cvp_check_clock(struct msm_cvp_inst *inst,
  318. struct cvp_hfi_msg_session_hdr_ext *hdr)
  319. {
  320. int rc = 0;
  321. u32 i, j;
  322. u32 hw_cycles[HFI_MAX_HW_THREADS] = {0};
  323. u32 fw_cycles = 0;
  324. struct msm_cvp_core *core = inst->core;
  325. for (i = 0; i < HFI_MAX_HW_ACTIVATIONS_PER_FRAME; ++i)
  326. fw_cycles += hdr->fw_cycles[i];
  327. for (i = 0; i < HFI_MAX_HW_THREADS; ++i)
  328. for (j = 0; j < HFI_MAX_HW_ACTIVATIONS_PER_FRAME; ++j)
  329. hw_cycles[i] += hdr->hw_cycles[i][j];
  330. dprintk(CVP_PWR, "%s - cycles fw %u. FDU %d MPU %d ODU %d ICA %d\n",
  331. __func__, fw_cycles, hw_cycles[0],
  332. hw_cycles[1], hw_cycles[2], hw_cycles[3]);
  333. mutex_lock(&core->clk_lock);
  334. for (i = 0; i < HFI_MAX_HW_THREADS; ++i) {
  335. dprintk(CVP_PWR, "%s - %d: hw_cycles %u, tens_thresh %u\n",
  336. __func__, i, hw_cycles[i],
  337. core->dyn_clk.hi_ctrl_lim[i]);
  338. if (core->dyn_clk.hi_ctrl_lim[i]) {
  339. if (core->dyn_clk.cycle[i].size < CVP_CYCLE_STAT_SIZE)
  340. core->dyn_clk.cycle[i].size++;
  341. else
  342. core->dyn_clk.cycle[i].total -=
  343. core->dyn_clk.cycle[i].busy[
  344. core->dyn_clk.cycle[i].idx];
  345. if (hw_cycles[i]) {
  346. core->dyn_clk.cycle[i].busy[
  347. core->dyn_clk.cycle[i].idx]
  348. = hw_cycles[i] + fw_cycles;
  349. core->dyn_clk.cycle[i].total
  350. += hw_cycles[i] + fw_cycles;
  351. dprintk(CVP_PWR,
  352. "%s: busy (hw + fw) cycles = %u\n",
  353. __func__,
  354. core->dyn_clk.cycle[i].busy[
  355. core->dyn_clk.cycle[i].idx]);
  356. dprintk(CVP_PWR, "total cycles %u\n",
  357. core->dyn_clk.cycle[i].total);
  358. } else {
  359. core->dyn_clk.cycle[i].busy[
  360. core->dyn_clk.cycle[i].idx] =
  361. hdr->busy_cycles;
  362. core->dyn_clk.cycle[i].total +=
  363. hdr->busy_cycles;
  364. dprintk(CVP_PWR,
  365. "%s - busy cycles = %u total %u\n",
  366. __func__,
  367. core->dyn_clk.cycle[i].busy[
  368. core->dyn_clk.cycle[i].idx],
  369. core->dyn_clk.cycle[i].total);
  370. }
  371. core->dyn_clk.cycle[i].idx =
  372. (core->dyn_clk.cycle[i].idx ==
  373. CVP_CYCLE_STAT_SIZE-1) ?
  374. 0 : core->dyn_clk.cycle[i].idx+1;
  375. dprintk(CVP_PWR, "%s - %d: size %u, tens_thresh %u\n",
  376. __func__, i, core->dyn_clk.cycle[i].size,
  377. core->dyn_clk.hi_ctrl_lim[i]);
  378. if (core->dyn_clk.cycle[i].size == CVP_CYCLE_STAT_SIZE
  379. && core->dyn_clk.hi_ctrl_lim[i] != 0) {
  380. u32 avg_cycles =
  381. core->dyn_clk.cycle[i].total>>3;
  382. rc = cvp_readjust_clock(core,
  383. avg_cycles,
  384. i);
  385. }
  386. }
  387. }
  388. mutex_unlock(&core->clk_lock);
  389. return rc;
  390. }
  391. static int cvp_fence_proc(struct msm_cvp_inst *inst,
  392. struct cvp_fence_command *fc,
  393. struct cvp_hfi_cmd_session_hdr *pkt)
  394. {
  395. int rc = 0;
  396. unsigned long timeout;
  397. u64 ktid;
  398. int synx_state = SYNX_STATE_SIGNALED_SUCCESS;
  399. struct cvp_hfi_device *hdev;
  400. struct cvp_session_queue *sq;
  401. u32 hfi_err = HFI_ERR_NONE;
  402. struct cvp_hfi_msg_session_hdr_ext hdr;
  403. bool clock_check = false;
  404. dprintk(CVP_SYNX, "%s %s\n", current->comm, __func__);
  405. hdev = inst->core->device;
  406. sq = &inst->session_queue_fence;
  407. ktid = pkt->client_data.kdata;
  408. rc = inst->core->synx_ftbl->cvp_synx_ops(inst, CVP_INPUT_SYNX,
  409. fc, &synx_state);
  410. if (rc) {
  411. msm_cvp_unmap_frame(inst, pkt->client_data.kdata);
  412. goto exit;
  413. }
  414. rc = call_hfi_op(hdev, session_send, (void *)inst->session,
  415. (struct eva_kmd_hfi_packet *)pkt);
  416. if (rc) {
  417. dprintk(CVP_ERR, "%s %s: Failed in call_hfi_op %d, %x\n",
  418. current->comm, __func__, pkt->size, pkt->packet_type);
  419. synx_state = SYNX_STATE_SIGNALED_ERROR;
  420. goto exit;
  421. }
  422. timeout = msecs_to_jiffies(CVP_MAX_WAIT_TIME);
  423. rc = cvp_wait_process_message(inst, sq, &ktid, timeout,
  424. (struct eva_kmd_hfi_packet *)&hdr);
  425. /* Only FD support dcvs at certain FW */
  426. if (!msm_cvp_dcvs_disable &&
  427. hdr.packet_type == HFI_MSG_SESSION_CVP_FD) {
  428. if (hdr.size == sizeof(struct cvp_hfi_msg_session_hdr_ext)
  429. + sizeof(struct cvp_hfi_buf_type)) {
  430. struct cvp_hfi_msg_session_hdr_ext *fhdr =
  431. (struct cvp_hfi_msg_session_hdr_ext *)&hdr;
  432. struct msm_cvp_core *core = inst->core;
  433. dprintk(CVP_PWR, "busy cycle %d, total %d\n",
  434. fhdr->busy_cycles, fhdr->total_cycles);
  435. if (core && (core->dyn_clk.sum_fps[HFI_HW_FDU] ||
  436. core->dyn_clk.sum_fps[HFI_HW_MPU] ||
  437. core->dyn_clk.sum_fps[HFI_HW_OD] ||
  438. core->dyn_clk.sum_fps[HFI_HW_ICA])) {
  439. clock_check = true;
  440. }
  441. } else {
  442. dprintk(CVP_WARN, "dcvs is disabled, %d != %d + %d\n",
  443. hdr.size, sizeof(struct cvp_hfi_msg_session_hdr_ext),
  444. sizeof(struct cvp_hfi_buf_type));
  445. }
  446. }
  447. hfi_err = hdr.error_type;
  448. if (rc) {
  449. dprintk(CVP_ERR, "%s %s: cvp_wait_process_message rc %d\n",
  450. current->comm, __func__, rc);
  451. synx_state = SYNX_STATE_SIGNALED_ERROR;
  452. goto exit;
  453. }
  454. if (hfi_err == HFI_ERR_SESSION_FLUSHED) {
  455. dprintk(CVP_SYNX, "%s %s: cvp_wait_process_message flushed\n",
  456. current->comm, __func__);
  457. synx_state = SYNX_STATE_SIGNALED_CANCEL;
  458. } else if (hfi_err == HFI_ERR_SESSION_STREAM_CORRUPT) {
  459. dprintk(CVP_INFO, "%s %s: cvp_wait_process_msg non-fatal %d\n",
  460. current->comm, __func__, hfi_err);
  461. synx_state = SYNX_STATE_SIGNALED_SUCCESS;
  462. } else if (hfi_err != HFI_ERR_NONE) {
  463. dprintk(CVP_ERR, "%s %s: cvp_wait_process_message hfi err %d\n",
  464. current->comm, __func__, hfi_err);
  465. synx_state = SYNX_STATE_SIGNALED_CANCEL;
  466. }
  467. exit:
  468. rc = inst->core->synx_ftbl->cvp_synx_ops(inst, CVP_OUTPUT_SYNX,
  469. fc, &synx_state);
  470. if (clock_check)
  471. cvp_check_clock(inst,
  472. (struct cvp_hfi_msg_session_hdr_ext *)&hdr);
  473. return rc;
  474. }
  475. static int cvp_alloc_fence_data(struct cvp_fence_command **f, u32 size)
  476. {
  477. struct cvp_fence_command *fcmd;
  478. int alloc_size = sizeof(struct cvp_hfi_msg_session_hdr_ext);
  479. fcmd = kzalloc(sizeof(struct cvp_fence_command), GFP_KERNEL);
  480. if (!fcmd)
  481. return -ENOMEM;
  482. alloc_size = (alloc_size >= size) ? alloc_size : size;
  483. fcmd->pkt = kzalloc(alloc_size, GFP_KERNEL);
  484. if (!fcmd->pkt) {
  485. kfree(fcmd);
  486. return -ENOMEM;
  487. }
  488. *f = fcmd;
  489. return 0;
  490. }
  491. static void cvp_free_fence_data(struct cvp_fence_command *f)
  492. {
  493. kfree(f->pkt);
  494. f->pkt = NULL;
  495. kfree(f);
  496. f = NULL;
  497. }
  498. static int cvp_fence_thread(void *data)
  499. {
  500. int rc = 0;
  501. struct msm_cvp_inst *inst;
  502. struct cvp_fence_queue *q;
  503. enum queue_state state;
  504. struct cvp_fence_command *f;
  505. struct cvp_hfi_cmd_session_hdr *pkt;
  506. u32 *synx;
  507. u64 ktid;
  508. dprintk(CVP_SYNX, "Enter %s\n", current->comm);
  509. inst = (struct msm_cvp_inst *)data;
  510. if (!inst || !inst->core || !inst->core->device) {
  511. dprintk(CVP_ERR, "%s invalid inst %pK\n", current->comm, inst);
  512. rc = -EINVAL;
  513. goto exit;
  514. }
  515. q = &inst->fence_cmd_queue;
  516. wait:
  517. dprintk(CVP_SYNX, "%s starts wait\n", current->comm);
  518. f = NULL;
  519. wait_event_interruptible(q->wq, cvp_fence_wait(q, &f, &state));
  520. if (state != QUEUE_START)
  521. goto exit;
  522. if (!f)
  523. goto wait;
  524. pkt = f->pkt;
  525. synx = (u32 *)f->synx;
  526. ktid = pkt->client_data.kdata & (FENCE_BIT - 1);
  527. dprintk(CVP_SYNX, "%s pkt type %d on ktid %llu frameID %llu\n",
  528. current->comm, pkt->packet_type, ktid, f->frame_id);
  529. rc = cvp_fence_proc(inst, f, pkt);
  530. mutex_lock(&q->lock);
  531. inst->core->synx_ftbl->cvp_release_synx(inst, f);
  532. list_del_init(&f->list);
  533. state = q->state;
  534. mutex_unlock(&q->lock);
  535. dprintk(CVP_SYNX, "%s done with %d ktid %llu frameID %llu rc %d\n",
  536. current->comm, pkt->packet_type, ktid, f->frame_id, rc);
  537. cvp_free_fence_data(f);
  538. if (rc && state != QUEUE_START)
  539. goto exit;
  540. goto wait;
  541. exit:
  542. dprintk(CVP_SYNX, "%s exit\n", current->comm);
  543. cvp_put_inst(inst);
  544. do_exit(rc);
  545. return rc;
  546. }
  547. static int msm_cvp_session_process_hfi_fence(struct msm_cvp_inst *inst,
  548. struct eva_kmd_arg *arg)
  549. {
  550. int rc = 0;
  551. int idx;
  552. struct eva_kmd_hfi_fence_packet *fence_pkt;
  553. struct eva_kmd_hfi_synx_packet *synx_pkt;
  554. struct eva_kmd_fence_ctrl *kfc;
  555. struct cvp_hfi_cmd_session_hdr *pkt;
  556. unsigned int offset = 0, buf_num = 0, in_offset, in_buf_num;
  557. struct msm_cvp_inst *s;
  558. struct cvp_fence_command *f;
  559. struct cvp_fence_queue *q;
  560. u32 *fence;
  561. enum op_mode mode;
  562. if (!inst || !inst->core || !arg || !inst->core->device) {
  563. dprintk(CVP_ERR, "%s: invalid params\n", __func__);
  564. return -EINVAL;
  565. }
  566. s = cvp_get_inst_validate(inst->core, inst);
  567. if (!s)
  568. return -ECONNRESET;
  569. q = &inst->fence_cmd_queue;
  570. mutex_lock(&q->lock);
  571. mode = q->mode;
  572. mutex_unlock(&q->lock);
  573. if (mode == OP_DRAINING) {
  574. dprintk(CVP_SYNX, "%s: flush in progress\n", __func__);
  575. rc = -EBUSY;
  576. goto exit;
  577. }
  578. in_offset = arg->buf_offset;
  579. in_buf_num = arg->buf_num;
  580. fence_pkt = &arg->data.hfi_fence_pkt;
  581. pkt = (struct cvp_hfi_cmd_session_hdr *)&fence_pkt->pkt_data;
  582. idx = get_pkt_index((struct cvp_hal_session_cmd_pkt *)pkt);
  583. if (idx < 0 ||
  584. (pkt->size > MAX_HFI_FENCE_OFFSET * sizeof(unsigned int))) {
  585. dprintk(CVP_ERR, "%s incorrect packet %d %#x\n", __func__,
  586. pkt->size, pkt->packet_type);
  587. goto exit;
  588. }
  589. if (in_offset && in_buf_num) {
  590. offset = in_offset;
  591. buf_num = in_buf_num;
  592. }
  593. if (!is_buf_param_valid(buf_num, offset)) {
  594. dprintk(CVP_ERR, "Incorrect buf num and offset in cmd\n");
  595. goto exit;
  596. }
  597. rc = msm_cvp_map_frame(inst, (struct eva_kmd_hfi_packet *)pkt, offset,
  598. buf_num);
  599. if (rc)
  600. goto exit;
  601. rc = cvp_alloc_fence_data(&f, pkt->size);
  602. if (rc)
  603. goto exit;
  604. f->type = cvp_hfi_defs[idx].type;
  605. f->mode = OP_NORMAL;
  606. synx_pkt = &arg->data.hfi_synx_pkt;
  607. if (synx_pkt->fence_data[0] != 0xFEEDFACE) {
  608. dprintk(CVP_ERR, "%s deprecated synx path\n", __func__);
  609. cvp_free_fence_data(f);
  610. msm_cvp_unmap_frame(inst, pkt->client_data.kdata);
  611. goto exit;
  612. } else {
  613. kfc = &synx_pkt->fc;
  614. fence = (u32 *)&kfc->fences;
  615. f->frame_id = kfc->frame_id;
  616. f->signature = 0xFEEDFACE;
  617. f->num_fences = kfc->num_fences;
  618. f->output_index = kfc->output_index;
  619. }
  620. dprintk(CVP_SYNX, "%s: frameID %llu ktid %llu\n",
  621. __func__, f->frame_id, pkt->client_data.kdata);
  622. memcpy(f->pkt, pkt, pkt->size);
  623. f->pkt->client_data.kdata |= FENCE_BIT;
  624. rc = inst->core->synx_ftbl->cvp_import_synx(inst, f, fence);
  625. if (rc) {
  626. kfree(f);
  627. goto exit;
  628. }
  629. mutex_lock(&q->lock);
  630. list_add_tail(&f->list, &inst->fence_cmd_queue.wait_list);
  631. mutex_unlock(&q->lock);
  632. wake_up(&inst->fence_cmd_queue.wq);
  633. exit:
  634. cvp_put_inst(s);
  635. return rc;
  636. }
  637. static inline int div_by_1dot5(unsigned int a)
  638. {
  639. unsigned long i = a << 1;
  640. return (unsigned int) i/3;
  641. }
  642. static inline int max_3(unsigned int a, unsigned int b, unsigned int c)
  643. {
  644. return (a >= b) ? ((a >= c) ? a : c) : ((b >= c) ? b : c);
  645. }
  646. static bool is_subblock_profile_existed(struct msm_cvp_inst *inst)
  647. {
  648. return (inst->prop.od_cycles ||
  649. inst->prop.mpu_cycles ||
  650. inst->prop.fdu_cycles ||
  651. inst->prop.ica_cycles);
  652. }
  653. static void aggregate_power_update(struct msm_cvp_core *core,
  654. struct cvp_power_level *nrt_pwr,
  655. struct cvp_power_level *rt_pwr,
  656. unsigned int max_clk_rate)
  657. {
  658. struct msm_cvp_inst *inst;
  659. int i;
  660. unsigned long fdu_sum[2] = {0}, od_sum[2] = {0}, mpu_sum[2] = {0};
  661. unsigned long ica_sum[2] = {0}, fw_sum[2] = {0};
  662. unsigned long op_fdu_max[2] = {0}, op_od_max[2] = {0};
  663. unsigned long op_mpu_max[2] = {0}, op_ica_max[2] = {0};
  664. unsigned long op_fw_max[2] = {0}, bw_sum[2] = {0}, op_bw_max[2] = {0};
  665. core->dyn_clk.sum_fps[HFI_HW_FDU] = 0;
  666. core->dyn_clk.sum_fps[HFI_HW_MPU] = 0;
  667. core->dyn_clk.sum_fps[HFI_HW_OD] = 0;
  668. core->dyn_clk.sum_fps[HFI_HW_ICA] = 0;
  669. list_for_each_entry(inst, &core->instances, list) {
  670. if (inst->state == MSM_CVP_CORE_INVALID ||
  671. inst->state == MSM_CVP_CORE_UNINIT ||
  672. !is_subblock_profile_existed(inst))
  673. continue;
  674. if (inst->prop.priority <= CVP_RT_PRIO_THRESHOLD) {
  675. /* Non-realtime session use index 0 */
  676. i = 0;
  677. } else {
  678. i = 1;
  679. }
  680. dprintk(CVP_PROF, "pwrUpdate fdu %u od %u mpu %u ica %u\n",
  681. inst->prop.fdu_cycles,
  682. inst->prop.od_cycles,
  683. inst->prop.mpu_cycles,
  684. inst->prop.ica_cycles);
  685. dprintk(CVP_PROF, "pwrUpdate fw %u fdu_o %u od_o %u mpu_o %u\n",
  686. inst->prop.fw_cycles,
  687. inst->prop.fdu_op_cycles,
  688. inst->prop.od_op_cycles,
  689. inst->prop.mpu_op_cycles);
  690. dprintk(CVP_PROF, "pwrUpdate ica_o %u fw_o %u bw %u bw_o %u\n",
  691. inst->prop.ica_op_cycles,
  692. inst->prop.fw_op_cycles,
  693. inst->prop.ddr_bw,
  694. inst->prop.ddr_op_bw);
  695. fdu_sum[i] += inst->prop.fdu_cycles;
  696. od_sum[i] += inst->prop.od_cycles;
  697. mpu_sum[i] += inst->prop.mpu_cycles;
  698. ica_sum[i] += inst->prop.ica_cycles;
  699. fw_sum[i] += inst->prop.fw_cycles;
  700. op_fdu_max[i] =
  701. (op_fdu_max[i] >= inst->prop.fdu_op_cycles) ?
  702. op_fdu_max[i] : inst->prop.fdu_op_cycles;
  703. op_od_max[i] =
  704. (op_od_max[i] >= inst->prop.od_op_cycles) ?
  705. op_od_max[i] : inst->prop.od_op_cycles;
  706. op_mpu_max[i] =
  707. (op_mpu_max[i] >= inst->prop.mpu_op_cycles) ?
  708. op_mpu_max[i] : inst->prop.mpu_op_cycles;
  709. op_ica_max[i] =
  710. (op_ica_max[i] >= inst->prop.ica_op_cycles) ?
  711. op_ica_max[i] : inst->prop.ica_op_cycles;
  712. op_fw_max[i] =
  713. (op_fw_max[i] >= inst->prop.fw_op_cycles) ?
  714. op_fw_max[i] : inst->prop.fw_op_cycles;
  715. bw_sum[i] += inst->prop.ddr_bw;
  716. op_bw_max[i] =
  717. (op_bw_max[i] >= inst->prop.ddr_op_bw) ?
  718. op_bw_max[i] : inst->prop.ddr_op_bw;
  719. dprintk(CVP_PWR, "%s:%d - fps fdu %d mpu %d od %d ica %d\n",
  720. __func__, __LINE__,
  721. inst->prop.fps[HFI_HW_FDU], inst->prop.fps[HFI_HW_MPU],
  722. inst->prop.fps[HFI_HW_OD], inst->prop.fps[HFI_HW_ICA]);
  723. core->dyn_clk.sum_fps[HFI_HW_FDU] += inst->prop.fps[HFI_HW_FDU];
  724. core->dyn_clk.sum_fps[HFI_HW_MPU] += inst->prop.fps[HFI_HW_MPU];
  725. core->dyn_clk.sum_fps[HFI_HW_OD] += inst->prop.fps[HFI_HW_OD];
  726. core->dyn_clk.sum_fps[HFI_HW_ICA] += inst->prop.fps[HFI_HW_ICA];
  727. dprintk(CVP_PWR, "%s:%d - sum_fps fdu %d mpu %d od %d ica %d\n",
  728. __func__, __LINE__,
  729. core->dyn_clk.sum_fps[HFI_HW_FDU],
  730. core->dyn_clk.sum_fps[HFI_HW_MPU],
  731. core->dyn_clk.sum_fps[HFI_HW_OD],
  732. core->dyn_clk.sum_fps[HFI_HW_ICA]);
  733. }
  734. for (i = 0; i < 2; i++) {
  735. fdu_sum[i] = max_3(fdu_sum[i], od_sum[i], mpu_sum[i]);
  736. fdu_sum[i] = max_3(fdu_sum[i], ica_sum[i], fw_sum[i]);
  737. op_fdu_max[i] = max_3(op_fdu_max[i], op_od_max[i],
  738. op_mpu_max[i]);
  739. op_fdu_max[i] = max_3(op_fdu_max[i],
  740. op_ica_max[i], op_fw_max[i]);
  741. op_fdu_max[i] =
  742. (op_fdu_max[i] > max_clk_rate) ?
  743. max_clk_rate : op_fdu_max[i];
  744. bw_sum[i] = (bw_sum[i] >= op_bw_max[i]) ?
  745. bw_sum[i] : op_bw_max[i];
  746. }
  747. nrt_pwr->core_sum += fdu_sum[0];
  748. nrt_pwr->op_core_sum = (nrt_pwr->op_core_sum >= op_fdu_max[0]) ?
  749. nrt_pwr->op_core_sum : op_fdu_max[0];
  750. nrt_pwr->bw_sum += bw_sum[0];
  751. rt_pwr->core_sum += fdu_sum[1];
  752. rt_pwr->op_core_sum = (rt_pwr->op_core_sum >= op_fdu_max[1]) ?
  753. rt_pwr->op_core_sum : op_fdu_max[1];
  754. rt_pwr->bw_sum += bw_sum[1];
  755. }
  756. /**
  757. * adjust_bw_freqs(): calculate CVP clock freq and bw required to sustain
  758. * required use case.
  759. * Bandwidth vote will be best-effort, not returning error if the request
  760. * b/w exceeds max limit.
  761. * Clock vote from non-realtime sessions will be best effort, not returning
  762. * error if the aggreated session clock request exceeds max limit.
  763. * Clock vote from realtime session will be hard request. If aggregated
  764. * session clock request exceeds max limit, the function will return
  765. * error.
  766. *
  767. * Ensure caller acquires clk_lock!
  768. */
  769. static int adjust_bw_freqs(void)
  770. {
  771. struct msm_cvp_core *core;
  772. struct iris_hfi_device *hdev;
  773. struct bus_info *bus;
  774. struct clock_set *clocks;
  775. struct clock_info *cl;
  776. struct allowed_clock_rates_table *tbl = NULL;
  777. unsigned int tbl_size;
  778. unsigned int cvp_min_rate, cvp_max_rate, max_bw, min_bw;
  779. struct cvp_power_level rt_pwr = {0}, nrt_pwr = {0};
  780. unsigned long tmp, core_sum, op_core_sum, bw_sum;
  781. int i, rc = 0;
  782. unsigned long ctrl_freq;
  783. core = list_first_entry(&cvp_driver->cores, struct msm_cvp_core, list);
  784. hdev = core->device->hfi_device_data;
  785. clocks = &core->resources.clock_set;
  786. cl = &clocks->clock_tbl[clocks->count - 1];
  787. tbl = core->resources.allowed_clks_tbl;
  788. tbl_size = core->resources.allowed_clks_tbl_size;
  789. cvp_min_rate = tbl[0].clock_rate;
  790. cvp_max_rate = tbl[tbl_size - 1].clock_rate;
  791. bus = &core->resources.bus_set.bus_tbl[1];
  792. max_bw = bus->range[1];
  793. min_bw = max_bw/10;
  794. aggregate_power_update(core, &nrt_pwr, &rt_pwr, cvp_max_rate);
  795. dprintk(CVP_PROF, "PwrUpdate nrt %u %u rt %u %u\n",
  796. nrt_pwr.core_sum, nrt_pwr.op_core_sum,
  797. rt_pwr.core_sum, rt_pwr.op_core_sum);
  798. if (rt_pwr.core_sum > cvp_max_rate) {
  799. dprintk(CVP_WARN, "%s clk vote out of range %lld\n",
  800. __func__, rt_pwr.core_sum);
  801. return -ENOTSUPP;
  802. }
  803. core_sum = rt_pwr.core_sum + nrt_pwr.core_sum;
  804. op_core_sum = (rt_pwr.op_core_sum >= nrt_pwr.op_core_sum) ?
  805. rt_pwr.op_core_sum : nrt_pwr.op_core_sum;
  806. core_sum = (core_sum >= op_core_sum) ?
  807. core_sum : op_core_sum;
  808. if (core_sum > cvp_max_rate) {
  809. core_sum = cvp_max_rate;
  810. } else if (core_sum <= cvp_min_rate) {
  811. core_sum = cvp_min_rate;
  812. } else {
  813. for (i = 1; i < tbl_size; i++)
  814. if (core_sum <= tbl[i].clock_rate)
  815. break;
  816. core_sum = tbl[i].clock_rate;
  817. }
  818. bw_sum = rt_pwr.bw_sum + nrt_pwr.bw_sum;
  819. bw_sum = bw_sum >> 10;
  820. bw_sum = (bw_sum > max_bw) ? max_bw : bw_sum;
  821. bw_sum = (bw_sum < min_bw) ? min_bw : bw_sum;
  822. dprintk(CVP_PROF, "%s %lld %lld\n", __func__,
  823. core_sum, bw_sum);
  824. if (!cl->has_scaling) {
  825. dprintk(CVP_ERR, "Cannot scale CVP clock\n");
  826. return -EINVAL;
  827. }
  828. tmp = core->curr_freq;
  829. core->curr_freq = core_sum;
  830. core->orig_core_sum = core_sum;
  831. rc = msm_cvp_set_clocks(core);
  832. if (rc) {
  833. dprintk(CVP_ERR,
  834. "Failed to set clock rate %u %s: %d %s\n",
  835. core_sum, cl->name, rc, __func__);
  836. core->curr_freq = tmp;
  837. return rc;
  838. }
  839. ctrl_freq = (core->curr_freq*3)>>1;
  840. core->dyn_clk.conf_freq = core->curr_freq;
  841. for (i = 0; i < HFI_MAX_HW_THREADS; ++i) {
  842. core->dyn_clk.hi_ctrl_lim[i] = core->dyn_clk.sum_fps[i] ?
  843. ctrl_freq/core->dyn_clk.sum_fps[i] : 0;
  844. core->dyn_clk.lo_ctrl_lim[i] =
  845. core->dyn_clk.hi_ctrl_lim[i];
  846. }
  847. hdev->clk_freq = core->curr_freq;
  848. rc = msm_cvp_set_bw(bus, bw_sum);
  849. return rc;
  850. }
  851. int msm_cvp_update_power(struct msm_cvp_inst *inst)
  852. {
  853. int rc = 0;
  854. struct msm_cvp_core *core;
  855. struct msm_cvp_inst *s;
  856. if (!inst) {
  857. dprintk(CVP_ERR, "%s: invalid params\n", __func__);
  858. return -EINVAL;
  859. }
  860. s = cvp_get_inst_validate(inst->core, inst);
  861. if (!s)
  862. return -ECONNRESET;
  863. core = inst->core;
  864. mutex_lock(&core->clk_lock);
  865. rc = adjust_bw_freqs();
  866. mutex_unlock(&core->clk_lock);
  867. cvp_put_inst(s);
  868. return rc;
  869. }
  870. int msm_cvp_session_delete(struct msm_cvp_inst *inst)
  871. {
  872. return 0;
  873. }
  874. int msm_cvp_session_create(struct msm_cvp_inst *inst)
  875. {
  876. int rc = 0;
  877. struct cvp_session_queue *sq;
  878. if (!inst || !inst->core)
  879. return -EINVAL;
  880. if (inst->state >= MSM_CVP_CLOSE_DONE)
  881. return -ECONNRESET;
  882. if (inst->state != MSM_CVP_CORE_INIT_DONE ||
  883. inst->state > MSM_CVP_OPEN_DONE) {
  884. dprintk(CVP_ERR,
  885. "%s Incorrect CVP state %d to create session\n",
  886. __func__, inst->state);
  887. return -EINVAL;
  888. }
  889. rc = msm_cvp_comm_try_state(inst, MSM_CVP_OPEN_DONE);
  890. if (rc) {
  891. dprintk(CVP_ERR,
  892. "Failed to move instance to open done state\n");
  893. goto fail_init;
  894. }
  895. rc = cvp_comm_set_arp_buffers(inst);
  896. if (rc) {
  897. dprintk(CVP_ERR,
  898. "Failed to set ARP buffers\n");
  899. goto fail_init;
  900. }
  901. inst->core->synx_ftbl->cvp_sess_init_synx(inst);
  902. sq = &inst->session_queue;
  903. spin_lock(&sq->lock);
  904. sq->state = QUEUE_ACTIVE;
  905. spin_unlock(&sq->lock);
  906. fail_init:
  907. return rc;
  908. }
  909. static int session_state_check_init(struct msm_cvp_inst *inst)
  910. {
  911. mutex_lock(&inst->lock);
  912. if (inst->state == MSM_CVP_OPEN || inst->state == MSM_CVP_OPEN_DONE) {
  913. mutex_unlock(&inst->lock);
  914. return 0;
  915. }
  916. mutex_unlock(&inst->lock);
  917. return msm_cvp_session_create(inst);
  918. }
  919. static int cvp_fence_thread_start(struct msm_cvp_inst *inst)
  920. {
  921. u32 tnum = 0;
  922. u32 i = 0;
  923. int rc = 0;
  924. char tname[16];
  925. struct task_struct *thread;
  926. struct cvp_fence_queue *q;
  927. struct cvp_session_queue *sq;
  928. if (!inst->prop.fthread_nr)
  929. return 0;
  930. q = &inst->fence_cmd_queue;
  931. mutex_lock(&q->lock);
  932. q->state = QUEUE_START;
  933. mutex_unlock(&q->lock);
  934. for (i = 0; i < inst->prop.fthread_nr; ++i) {
  935. if (!cvp_get_inst_validate(inst->core, inst)) {
  936. rc = -ECONNRESET;
  937. goto exit;
  938. }
  939. snprintf(tname, sizeof(tname), "fthread_%d", tnum++);
  940. thread = kthread_run(cvp_fence_thread, inst, tname);
  941. if (!thread) {
  942. dprintk(CVP_ERR, "%s create %s fail", __func__, tname);
  943. rc = -ECHILD;
  944. goto exit;
  945. }
  946. }
  947. sq = &inst->session_queue_fence;
  948. spin_lock(&sq->lock);
  949. sq->state = QUEUE_START;
  950. spin_unlock(&sq->lock);
  951. exit:
  952. if (rc) {
  953. mutex_lock(&q->lock);
  954. q->state = QUEUE_STOP;
  955. mutex_unlock(&q->lock);
  956. wake_up_all(&q->wq);
  957. }
  958. return rc;
  959. }
  960. static int cvp_fence_thread_stop(struct msm_cvp_inst *inst)
  961. {
  962. struct cvp_fence_queue *q;
  963. struct cvp_session_queue *sq;
  964. if (!inst->prop.fthread_nr)
  965. return 0;
  966. q = &inst->fence_cmd_queue;
  967. mutex_lock(&q->lock);
  968. q->state = QUEUE_STOP;
  969. mutex_unlock(&q->lock);
  970. sq = &inst->session_queue_fence;
  971. spin_lock(&sq->lock);
  972. sq->state = QUEUE_STOP;
  973. spin_unlock(&sq->lock);
  974. wake_up_all(&q->wq);
  975. wake_up_all(&sq->wq);
  976. return 0;
  977. }
  978. static int msm_cvp_session_start(struct msm_cvp_inst *inst,
  979. struct eva_kmd_arg *arg)
  980. {
  981. struct cvp_session_queue *sq;
  982. struct cvp_hfi_device *hdev;
  983. sq = &inst->session_queue;
  984. spin_lock(&sq->lock);
  985. if (sq->msg_count) {
  986. dprintk(CVP_ERR, "session start failed queue not empty%d\n",
  987. sq->msg_count);
  988. spin_unlock(&sq->lock);
  989. return -EINVAL;
  990. }
  991. sq->state = QUEUE_START;
  992. spin_unlock(&sq->lock);
  993. if (inst->prop.type == HFI_SESSION_FD
  994. || inst->prop.type == HFI_SESSION_DMM) {
  995. spin_lock(&inst->core->resources.pm_qos.lock);
  996. inst->core->resources.pm_qos.off_vote_cnt++;
  997. spin_unlock(&inst->core->resources.pm_qos.lock);
  998. hdev = inst->core->device;
  999. call_hfi_op(hdev, pm_qos_update, hdev->hfi_device_data);
  1000. }
  1001. return cvp_fence_thread_start(inst);
  1002. }
  1003. static int msm_cvp_session_stop(struct msm_cvp_inst *inst,
  1004. struct eva_kmd_arg *arg)
  1005. {
  1006. struct cvp_session_queue *sq;
  1007. struct eva_kmd_session_control *sc = &arg->data.session_ctrl;
  1008. sq = &inst->session_queue;
  1009. spin_lock(&sq->lock);
  1010. if (sq->msg_count) {
  1011. dprintk(CVP_ERR, "session stop incorrect: queue not empty%d\n",
  1012. sq->msg_count);
  1013. sc->ctrl_data[0] = sq->msg_count;
  1014. spin_unlock(&sq->lock);
  1015. return -EUCLEAN;
  1016. }
  1017. sq->state = QUEUE_STOP;
  1018. pr_info(CVP_DBG_TAG "Stop session: %pK session_id = %d\n",
  1019. "sess", inst, hash32_ptr(inst->session));
  1020. spin_unlock(&sq->lock);
  1021. wake_up_all(&inst->session_queue.wq);
  1022. return cvp_fence_thread_stop(inst);
  1023. }
  1024. int msm_cvp_session_queue_stop(struct msm_cvp_inst *inst)
  1025. {
  1026. struct cvp_session_queue *sq;
  1027. sq = &inst->session_queue;
  1028. spin_lock(&sq->lock);
  1029. if (sq->state == QUEUE_STOP) {
  1030. spin_unlock(&sq->lock);
  1031. return 0;
  1032. }
  1033. sq->state = QUEUE_STOP;
  1034. dprintk(CVP_SESS, "Stop session queue: %pK session_id = %d\n",
  1035. inst, hash32_ptr(inst->session));
  1036. spin_unlock(&sq->lock);
  1037. wake_up_all(&inst->session_queue.wq);
  1038. return cvp_fence_thread_stop(inst);
  1039. }
  1040. static int msm_cvp_session_ctrl(struct msm_cvp_inst *inst,
  1041. struct eva_kmd_arg *arg)
  1042. {
  1043. struct eva_kmd_session_control *ctrl = &arg->data.session_ctrl;
  1044. int rc = 0;
  1045. unsigned int ctrl_type;
  1046. ctrl_type = ctrl->ctrl_type;
  1047. if (!inst && ctrl_type != SESSION_CREATE) {
  1048. dprintk(CVP_ERR, "%s invalid session\n", __func__);
  1049. return -EINVAL;
  1050. }
  1051. switch (ctrl_type) {
  1052. case SESSION_STOP:
  1053. rc = msm_cvp_session_stop(inst, arg);
  1054. break;
  1055. case SESSION_START:
  1056. rc = msm_cvp_session_start(inst, arg);
  1057. break;
  1058. case SESSION_CREATE:
  1059. rc = msm_cvp_session_create(inst);
  1060. break;
  1061. case SESSION_DELETE:
  1062. rc = msm_cvp_session_delete(inst);
  1063. break;
  1064. case SESSION_INFO:
  1065. default:
  1066. dprintk(CVP_ERR, "%s Unsupported session ctrl%d\n",
  1067. __func__, ctrl->ctrl_type);
  1068. rc = -EINVAL;
  1069. }
  1070. return rc;
  1071. }
  1072. static unsigned int msm_cvp_get_hw_aggregate_cycles(enum hw_block hwblk)
  1073. {
  1074. struct msm_cvp_core *core;
  1075. struct msm_cvp_inst *inst;
  1076. unsigned long cycles_sum = 0;
  1077. core = list_first_entry(&cvp_driver->cores, struct msm_cvp_core, list);
  1078. if (!core) {
  1079. dprintk(CVP_ERR, "%s: invalid core\n", __func__);
  1080. return -EINVAL;
  1081. }
  1082. mutex_lock(&core->clk_lock);
  1083. list_for_each_entry(inst, &core->instances, list) {
  1084. if (inst->state == MSM_CVP_CORE_INVALID ||
  1085. inst->state == MSM_CVP_CORE_UNINIT ||
  1086. !is_subblock_profile_existed(inst))
  1087. continue;
  1088. switch (hwblk) {
  1089. case CVP_FDU:
  1090. {
  1091. cycles_sum += inst->prop.fdu_cycles;
  1092. break;
  1093. }
  1094. case CVP_ICA:
  1095. {
  1096. cycles_sum += inst->prop.ica_cycles;
  1097. break;
  1098. }
  1099. case CVP_MPU:
  1100. {
  1101. cycles_sum += inst->prop.mpu_cycles;
  1102. break;
  1103. }
  1104. case CVP_OD:
  1105. {
  1106. cycles_sum += inst->prop.od_cycles;
  1107. break;
  1108. }
  1109. default:
  1110. dprintk(CVP_ERR, "unrecognized hw block %d\n",
  1111. hwblk);
  1112. break;
  1113. }
  1114. }
  1115. mutex_unlock(&core->clk_lock);
  1116. cycles_sum = cycles_sum&0xFFFFFFFF;
  1117. return (unsigned int)cycles_sum;
  1118. }
  1119. static int msm_cvp_get_sysprop(struct msm_cvp_inst *inst,
  1120. struct eva_kmd_arg *arg)
  1121. {
  1122. struct eva_kmd_sys_properties *props = &arg->data.sys_properties;
  1123. struct cvp_hfi_device *hdev;
  1124. struct iris_hfi_device *hfi;
  1125. struct cvp_session_prop *session_prop;
  1126. int i, rc = 0;
  1127. if (!inst || !inst->core || !inst->core->device) {
  1128. dprintk(CVP_ERR, "%s: invalid params\n", __func__);
  1129. return -EINVAL;
  1130. }
  1131. hdev = inst->core->device;
  1132. hfi = hdev->hfi_device_data;
  1133. if (props->prop_num > MAX_KMD_PROP_NUM_PER_PACKET) {
  1134. dprintk(CVP_ERR, "Too many properties %d to get\n",
  1135. props->prop_num);
  1136. return -E2BIG;
  1137. }
  1138. session_prop = &inst->prop;
  1139. for (i = 0; i < props->prop_num; i++) {
  1140. switch (props->prop_data[i].prop_type) {
  1141. case EVA_KMD_PROP_HFI_VERSION:
  1142. {
  1143. props->prop_data[i].data = hfi->version;
  1144. break;
  1145. }
  1146. case EVA_KMD_PROP_SESSION_DUMPOFFSET:
  1147. {
  1148. props->prop_data[i].data =
  1149. session_prop->dump_offset;
  1150. break;
  1151. }
  1152. case EVA_KMD_PROP_SESSION_DUMPSIZE:
  1153. {
  1154. props->prop_data[i].data =
  1155. session_prop->dump_size;
  1156. break;
  1157. }
  1158. case EVA_KMD_PROP_PWR_FDU:
  1159. {
  1160. props->prop_data[i].data =
  1161. msm_cvp_get_hw_aggregate_cycles(CVP_FDU);
  1162. break;
  1163. }
  1164. case EVA_KMD_PROP_PWR_ICA:
  1165. {
  1166. props->prop_data[i].data =
  1167. msm_cvp_get_hw_aggregate_cycles(CVP_ICA);
  1168. break;
  1169. }
  1170. case EVA_KMD_PROP_PWR_OD:
  1171. {
  1172. props->prop_data[i].data =
  1173. msm_cvp_get_hw_aggregate_cycles(CVP_OD);
  1174. break;
  1175. }
  1176. case EVA_KMD_PROP_PWR_MPU:
  1177. {
  1178. props->prop_data[i].data =
  1179. msm_cvp_get_hw_aggregate_cycles(CVP_MPU);
  1180. break;
  1181. }
  1182. default:
  1183. dprintk(CVP_ERR, "unrecognized sys property %d\n",
  1184. props->prop_data[i].prop_type);
  1185. rc = -EFAULT;
  1186. }
  1187. }
  1188. return rc;
  1189. }
  1190. static int msm_cvp_set_sysprop(struct msm_cvp_inst *inst,
  1191. struct eva_kmd_arg *arg)
  1192. {
  1193. struct eva_kmd_sys_properties *props = &arg->data.sys_properties;
  1194. struct eva_kmd_sys_property *prop_array;
  1195. struct cvp_session_prop *session_prop;
  1196. int i, rc = 0;
  1197. if (!inst) {
  1198. dprintk(CVP_ERR, "%s: invalid params\n", __func__);
  1199. return -EINVAL;
  1200. }
  1201. if (props->prop_num > MAX_KMD_PROP_NUM_PER_PACKET) {
  1202. dprintk(CVP_ERR, "Too many properties %d to set\n",
  1203. props->prop_num);
  1204. return -E2BIG;
  1205. }
  1206. prop_array = &arg->data.sys_properties.prop_data[0];
  1207. session_prop = &inst->prop;
  1208. for (i = 0; i < props->prop_num; i++) {
  1209. switch (prop_array[i].prop_type) {
  1210. case EVA_KMD_PROP_SESSION_TYPE:
  1211. session_prop->type = prop_array[i].data;
  1212. break;
  1213. case EVA_KMD_PROP_SESSION_KERNELMASK:
  1214. session_prop->kernel_mask = prop_array[i].data;
  1215. break;
  1216. case EVA_KMD_PROP_SESSION_PRIORITY:
  1217. session_prop->priority = prop_array[i].data;
  1218. break;
  1219. case EVA_KMD_PROP_SESSION_SECURITY:
  1220. session_prop->is_secure = prop_array[i].data;
  1221. break;
  1222. case EVA_KMD_PROP_SESSION_DSPMASK:
  1223. session_prop->dsp_mask = prop_array[i].data;
  1224. break;
  1225. case EVA_KMD_PROP_PWR_FDU:
  1226. session_prop->fdu_cycles = prop_array[i].data;
  1227. break;
  1228. case EVA_KMD_PROP_PWR_ICA:
  1229. session_prop->ica_cycles =
  1230. div_by_1dot5(prop_array[i].data);
  1231. break;
  1232. case EVA_KMD_PROP_PWR_OD:
  1233. session_prop->od_cycles = prop_array[i].data;
  1234. break;
  1235. case EVA_KMD_PROP_PWR_MPU:
  1236. session_prop->mpu_cycles = prop_array[i].data;
  1237. break;
  1238. case EVA_KMD_PROP_PWR_FW:
  1239. session_prop->fw_cycles =
  1240. div_by_1dot5(prop_array[i].data);
  1241. break;
  1242. case EVA_KMD_PROP_PWR_DDR:
  1243. session_prop->ddr_bw = prop_array[i].data;
  1244. break;
  1245. case EVA_KMD_PROP_PWR_SYSCACHE:
  1246. session_prop->ddr_cache = prop_array[i].data;
  1247. break;
  1248. case EVA_KMD_PROP_PWR_FDU_OP:
  1249. session_prop->fdu_op_cycles = prop_array[i].data;
  1250. break;
  1251. case EVA_KMD_PROP_PWR_ICA_OP:
  1252. session_prop->ica_op_cycles =
  1253. div_by_1dot5(prop_array[i].data);
  1254. break;
  1255. case EVA_KMD_PROP_PWR_OD_OP:
  1256. session_prop->od_op_cycles = prop_array[i].data;
  1257. break;
  1258. case EVA_KMD_PROP_PWR_MPU_OP:
  1259. session_prop->mpu_op_cycles = prop_array[i].data;
  1260. break;
  1261. case EVA_KMD_PROP_PWR_FW_OP:
  1262. session_prop->fw_op_cycles =
  1263. div_by_1dot5(prop_array[i].data);
  1264. break;
  1265. case EVA_KMD_PROP_PWR_DDR_OP:
  1266. session_prop->ddr_op_bw = prop_array[i].data;
  1267. break;
  1268. case EVA_KMD_PROP_PWR_SYSCACHE_OP:
  1269. session_prop->ddr_op_cache = prop_array[i].data;
  1270. break;
  1271. case EVA_KMD_PROP_PWR_FPS_FDU:
  1272. session_prop->fps[HFI_HW_FDU] = prop_array[i].data;
  1273. break;
  1274. case EVA_KMD_PROP_PWR_FPS_MPU:
  1275. session_prop->fps[HFI_HW_MPU] = prop_array[i].data;
  1276. break;
  1277. case EVA_KMD_PROP_PWR_FPS_OD:
  1278. session_prop->fps[HFI_HW_OD] = prop_array[i].data;
  1279. break;
  1280. case EVA_KMD_PROP_PWR_FPS_ICA:
  1281. session_prop->fps[HFI_HW_ICA] = prop_array[i].data;
  1282. break;
  1283. case EVA_KMD_PROP_SESSION_DUMPOFFSET:
  1284. session_prop->dump_offset = prop_array[i].data;
  1285. break;
  1286. case EVA_KMD_PROP_SESSION_DUMPSIZE:
  1287. session_prop->dump_size = prop_array[i].data;
  1288. break;
  1289. default:
  1290. dprintk(CVP_ERR,
  1291. "unrecognized sys property to set %d\n",
  1292. prop_array[i].prop_type);
  1293. rc = -EFAULT;
  1294. }
  1295. }
  1296. return rc;
  1297. }
  1298. static int cvp_drain_fence_sched_list(struct msm_cvp_inst *inst)
  1299. {
  1300. unsigned long wait_time;
  1301. struct cvp_fence_queue *q;
  1302. struct cvp_fence_command *f;
  1303. int rc = 0;
  1304. int count = 0, max_count = 0;
  1305. u64 ktid;
  1306. q = &inst->fence_cmd_queue;
  1307. mutex_lock(&q->lock);
  1308. list_for_each_entry(f, &q->sched_list, list) {
  1309. ktid = f->pkt->client_data.kdata & (FENCE_BIT - 1);
  1310. dprintk(CVP_SYNX, "%s: frame %llu %llu is in sched_list\n",
  1311. __func__, ktid, f->frame_id);
  1312. ++count;
  1313. }
  1314. mutex_unlock(&q->lock);
  1315. wait_time = count * CVP_MAX_WAIT_TIME * 1000;
  1316. dprintk(CVP_SYNX, "%s: wait %d us for %d fence command\n",
  1317. __func__, wait_time, count);
  1318. count = 0;
  1319. max_count = wait_time / 100;
  1320. retry:
  1321. mutex_lock(&q->lock);
  1322. if (list_empty(&q->sched_list)) {
  1323. mutex_unlock(&q->lock);
  1324. return rc;
  1325. }
  1326. mutex_unlock(&q->lock);
  1327. usleep_range(100, 200);
  1328. ++count;
  1329. if (count < max_count) {
  1330. goto retry;
  1331. } else {
  1332. rc = -ETIMEDOUT;
  1333. dprintk(CVP_ERR, "%s: timed out!\n", __func__);
  1334. }
  1335. return rc;
  1336. }
  1337. static void cvp_clean_fence_queue(struct msm_cvp_inst *inst, int synx_state)
  1338. {
  1339. struct cvp_fence_queue *q;
  1340. struct cvp_fence_command *f, *d;
  1341. u64 ktid;
  1342. q = &inst->fence_cmd_queue;
  1343. mutex_lock(&q->lock);
  1344. q->mode = OP_DRAINING;
  1345. list_for_each_entry_safe(f, d, &q->wait_list, list) {
  1346. ktid = f->pkt->client_data.kdata & (FENCE_BIT - 1);
  1347. dprintk(CVP_SYNX, "%s: (%#x) flush frame %llu %llu wait_list\n",
  1348. __func__, hash32_ptr(inst->session), ktid, f->frame_id);
  1349. list_del_init(&f->list);
  1350. msm_cvp_unmap_frame(inst, f->pkt->client_data.kdata);
  1351. inst->core->synx_ftbl->cvp_cancel_synx(inst, CVP_OUTPUT_SYNX,
  1352. f, synx_state);
  1353. inst->core->synx_ftbl->cvp_release_synx(inst, f);
  1354. cvp_free_fence_data(f);
  1355. }
  1356. list_for_each_entry(f, &q->sched_list, list) {
  1357. ktid = f->pkt->client_data.kdata & (FENCE_BIT - 1);
  1358. dprintk(CVP_SYNX, "%s: (%#x)flush frame %llu %llu sched_list\n",
  1359. __func__, hash32_ptr(inst->session), ktid, f->frame_id);
  1360. inst->core->synx_ftbl->cvp_cancel_synx(inst, CVP_INPUT_SYNX,
  1361. f, synx_state);
  1362. }
  1363. mutex_unlock(&q->lock);
  1364. }
  1365. int cvp_clean_session_queues(struct msm_cvp_inst *inst)
  1366. {
  1367. struct cvp_fence_queue *q;
  1368. struct cvp_session_queue *sq;
  1369. u32 count = 0, max_retries = 100;
  1370. q = &inst->fence_cmd_queue;
  1371. mutex_lock(&q->lock);
  1372. if (q->state == QUEUE_START) {
  1373. mutex_unlock(&q->lock);
  1374. cvp_clean_fence_queue(inst, SYNX_STATE_SIGNALED_ERROR);
  1375. } else {
  1376. dprintk(CVP_WARN, "Incorrect fence cmd queue state %d\n",
  1377. q->state);
  1378. mutex_unlock(&q->lock);
  1379. }
  1380. cvp_fence_thread_stop(inst);
  1381. /* Waiting for all output synx sent */
  1382. retry:
  1383. mutex_lock(&q->lock);
  1384. if (list_empty(&q->sched_list)) {
  1385. mutex_unlock(&q->lock);
  1386. return 0;
  1387. }
  1388. mutex_unlock(&q->lock);
  1389. usleep_range(500, 1000);
  1390. if (++count > max_retries)
  1391. return -EBUSY;
  1392. goto retry;
  1393. sq = &inst->session_queue_fence;
  1394. spin_lock(&sq->lock);
  1395. sq->state = QUEUE_INVALID;
  1396. spin_unlock(&sq->lock);
  1397. }
  1398. static int cvp_flush_all(struct msm_cvp_inst *inst)
  1399. {
  1400. int rc = 0;
  1401. struct msm_cvp_inst *s;
  1402. struct cvp_fence_queue *q;
  1403. struct cvp_hfi_device *hdev;
  1404. if (!inst || !inst->core) {
  1405. dprintk(CVP_ERR, "%s: invalid params\n", __func__);
  1406. return -EINVAL;
  1407. }
  1408. s = cvp_get_inst_validate(inst->core, inst);
  1409. if (!s)
  1410. return -ECONNRESET;
  1411. dprintk(CVP_SESS, "session %llx (%#x)flush all starts\n",
  1412. inst, hash32_ptr(inst->session));
  1413. q = &inst->fence_cmd_queue;
  1414. hdev = inst->core->device;
  1415. cvp_clean_fence_queue(inst, SYNX_STATE_SIGNALED_CANCEL);
  1416. dprintk(CVP_SESS, "%s: (%#x) send flush to fw\n",
  1417. __func__, hash32_ptr(inst->session));
  1418. /* Send flush to FW */
  1419. rc = call_hfi_op(hdev, session_flush, (void *)inst->session);
  1420. if (rc) {
  1421. dprintk(CVP_WARN, "%s: continue flush without fw. rc %d\n",
  1422. __func__, rc);
  1423. goto exit;
  1424. }
  1425. /* Wait for FW response */
  1426. rc = wait_for_sess_signal_receipt(inst, HAL_SESSION_FLUSH_DONE);
  1427. if (rc)
  1428. dprintk(CVP_WARN, "%s: wait for signal failed, rc %d\n",
  1429. __func__, rc);
  1430. dprintk(CVP_SESS, "%s: (%#x) received flush from fw\n",
  1431. __func__, hash32_ptr(inst->session));
  1432. exit:
  1433. rc = cvp_drain_fence_sched_list(inst);
  1434. mutex_lock(&q->lock);
  1435. q->mode = OP_NORMAL;
  1436. mutex_unlock(&q->lock);
  1437. cvp_put_inst(s);
  1438. return rc;
  1439. }
  1440. int msm_cvp_handle_syscall(struct msm_cvp_inst *inst, struct eva_kmd_arg *arg)
  1441. {
  1442. int rc = 0;
  1443. if (!inst || !arg) {
  1444. dprintk(CVP_ERR, "%s: invalid args\n", __func__);
  1445. return -EINVAL;
  1446. }
  1447. dprintk(CVP_HFI, "%s: arg->type = %x", __func__, arg->type);
  1448. if (arg->type != EVA_KMD_SESSION_CONTROL &&
  1449. arg->type != EVA_KMD_SET_SYS_PROPERTY &&
  1450. arg->type != EVA_KMD_GET_SYS_PROPERTY) {
  1451. rc = session_state_check_init(inst);
  1452. if (rc) {
  1453. dprintk(CVP_ERR,
  1454. "Incorrect session state %d for command %#x",
  1455. inst->state, arg->type);
  1456. return rc;
  1457. }
  1458. }
  1459. switch (arg->type) {
  1460. case EVA_KMD_GET_SESSION_INFO:
  1461. {
  1462. struct eva_kmd_session_info *session =
  1463. (struct eva_kmd_session_info *)&arg->data.session;
  1464. rc = msm_cvp_get_session_info(inst, &session->session_id);
  1465. break;
  1466. }
  1467. case EVA_KMD_UPDATE_POWER:
  1468. {
  1469. rc = msm_cvp_update_power(inst);
  1470. break;
  1471. }
  1472. case EVA_KMD_REGISTER_BUFFER:
  1473. {
  1474. struct eva_kmd_buffer *buf =
  1475. (struct eva_kmd_buffer *)&arg->data.regbuf;
  1476. rc = msm_cvp_register_buffer(inst, buf);
  1477. break;
  1478. }
  1479. case EVA_KMD_UNREGISTER_BUFFER:
  1480. {
  1481. struct eva_kmd_buffer *buf =
  1482. (struct eva_kmd_buffer *)&arg->data.unregbuf;
  1483. rc = msm_cvp_unregister_buffer(inst, buf);
  1484. break;
  1485. }
  1486. case EVA_KMD_RECEIVE_MSG_PKT:
  1487. {
  1488. struct eva_kmd_hfi_packet *out_pkt =
  1489. (struct eva_kmd_hfi_packet *)&arg->data.hfi_pkt;
  1490. rc = msm_cvp_session_receive_hfi(inst, out_pkt);
  1491. break;
  1492. }
  1493. case EVA_KMD_SEND_CMD_PKT:
  1494. {
  1495. struct eva_kmd_hfi_packet *in_pkt =
  1496. (struct eva_kmd_hfi_packet *)&arg->data.hfi_pkt;
  1497. rc = msm_cvp_session_process_hfi(inst, in_pkt,
  1498. arg->buf_offset, arg->buf_num);
  1499. break;
  1500. }
  1501. case EVA_KMD_SEND_FENCE_CMD_PKT:
  1502. {
  1503. rc = msm_cvp_session_process_hfi_fence(inst, arg);
  1504. break;
  1505. }
  1506. case EVA_KMD_SESSION_CONTROL:
  1507. rc = msm_cvp_session_ctrl(inst, arg);
  1508. break;
  1509. case EVA_KMD_GET_SYS_PROPERTY:
  1510. rc = msm_cvp_get_sysprop(inst, arg);
  1511. break;
  1512. case EVA_KMD_SET_SYS_PROPERTY:
  1513. rc = msm_cvp_set_sysprop(inst, arg);
  1514. break;
  1515. case EVA_KMD_FLUSH_ALL:
  1516. rc = cvp_flush_all(inst);
  1517. break;
  1518. case EVA_KMD_FLUSH_FRAME:
  1519. dprintk(CVP_WARN, "EVA_KMD_FLUSH_FRAME IOCTL deprecated\n");
  1520. rc = 0;
  1521. break;
  1522. default:
  1523. dprintk(CVP_HFI, "%s: unknown arg type %#x\n",
  1524. __func__, arg->type);
  1525. rc = -ENOTSUPP;
  1526. break;
  1527. }
  1528. return rc;
  1529. }
  1530. int msm_cvp_session_deinit(struct msm_cvp_inst *inst)
  1531. {
  1532. int rc = 0;
  1533. struct cvp_hal_session *session;
  1534. if (!inst || !inst->core) {
  1535. dprintk(CVP_ERR, "%s: invalid params\n", __func__);
  1536. return -EINVAL;
  1537. }
  1538. dprintk(CVP_SESS, "%s: inst %pK (%#x)\n", __func__,
  1539. inst, hash32_ptr(inst->session));
  1540. session = (struct cvp_hal_session *)inst->session;
  1541. if (!session)
  1542. return rc;
  1543. rc = msm_cvp_comm_try_state(inst, MSM_CVP_CLOSE_DONE);
  1544. if (rc)
  1545. dprintk(CVP_ERR, "%s: close failed\n", __func__);
  1546. rc = msm_cvp_session_deinit_buffers(inst);
  1547. return rc;
  1548. }
  1549. int msm_cvp_session_init(struct msm_cvp_inst *inst)
  1550. {
  1551. int rc = 0;
  1552. if (!inst) {
  1553. dprintk(CVP_ERR, "%s: invalid params\n", __func__);
  1554. return -EINVAL;
  1555. }
  1556. dprintk(CVP_SESS, "%s: inst %pK (%#x)\n", __func__,
  1557. inst, hash32_ptr(inst->session));
  1558. /* set default frequency */
  1559. inst->clk_data.core_id = 0;
  1560. inst->clk_data.min_freq = 1000;
  1561. inst->clk_data.ddr_bw = 1000;
  1562. inst->clk_data.sys_cache_bw = 1000;
  1563. inst->prop.type = 1;
  1564. inst->prop.kernel_mask = 0xFFFFFFFF;
  1565. inst->prop.priority = 0;
  1566. inst->prop.is_secure = 0;
  1567. inst->prop.dsp_mask = 0;
  1568. inst->prop.fthread_nr = 3;
  1569. return rc;
  1570. }