msm_cvp.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833
  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 = cvp_synx_ops(inst, CVP_INPUT_SYNX, fc, &synx_state);
  409. if (rc) {
  410. msm_cvp_unmap_frame(inst, pkt->client_data.kdata);
  411. goto exit;
  412. }
  413. rc = call_hfi_op(hdev, session_send, (void *)inst->session,
  414. (struct eva_kmd_hfi_packet *)pkt);
  415. if (rc) {
  416. dprintk(CVP_ERR, "%s %s: Failed in call_hfi_op %d, %x\n",
  417. current->comm, __func__, pkt->size, pkt->packet_type);
  418. synx_state = SYNX_STATE_SIGNALED_ERROR;
  419. goto exit;
  420. }
  421. timeout = msecs_to_jiffies(CVP_MAX_WAIT_TIME);
  422. rc = cvp_wait_process_message(inst, sq, &ktid, timeout,
  423. (struct eva_kmd_hfi_packet *)&hdr);
  424. /* Only FD support dcvs at certain FW */
  425. if (!msm_cvp_dcvs_disable &&
  426. hdr.packet_type == HFI_MSG_SESSION_CVP_FD) {
  427. if (hdr.size == sizeof(struct cvp_hfi_msg_session_hdr_ext)
  428. + sizeof(struct cvp_hfi_buf_type)) {
  429. struct cvp_hfi_msg_session_hdr_ext *fhdr =
  430. (struct cvp_hfi_msg_session_hdr_ext *)&hdr;
  431. struct msm_cvp_core *core = inst->core;
  432. dprintk(CVP_PWR, "busy cycle %d, total %d\n",
  433. fhdr->busy_cycles, fhdr->total_cycles);
  434. if (core && (core->dyn_clk.sum_fps[HFI_HW_FDU] ||
  435. core->dyn_clk.sum_fps[HFI_HW_MPU] ||
  436. core->dyn_clk.sum_fps[HFI_HW_OD] ||
  437. core->dyn_clk.sum_fps[HFI_HW_ICA])) {
  438. clock_check = true;
  439. }
  440. } else {
  441. dprintk(CVP_WARN, "dcvs is disabled, %d != %d + %d\n",
  442. hdr.size, sizeof(struct cvp_hfi_msg_session_hdr_ext),
  443. sizeof(struct cvp_hfi_buf_type));
  444. }
  445. }
  446. hfi_err = hdr.error_type;
  447. if (rc) {
  448. dprintk(CVP_ERR, "%s %s: cvp_wait_process_message rc %d\n",
  449. current->comm, __func__, rc);
  450. synx_state = SYNX_STATE_SIGNALED_ERROR;
  451. goto exit;
  452. }
  453. if (hfi_err == HFI_ERR_SESSION_FLUSHED) {
  454. dprintk(CVP_SYNX, "%s %s: cvp_wait_process_message flushed\n",
  455. current->comm, __func__);
  456. synx_state = SYNX_STATE_SIGNALED_CANCEL;
  457. } else if (hfi_err == HFI_ERR_SESSION_STREAM_CORRUPT) {
  458. dprintk(CVP_INFO, "%s %s: cvp_wait_process_msg non-fatal %d\n",
  459. current->comm, __func__, hfi_err);
  460. synx_state = SYNX_STATE_SIGNALED_SUCCESS;
  461. } else if (hfi_err != HFI_ERR_NONE) {
  462. dprintk(CVP_ERR, "%s %s: cvp_wait_process_message hfi err %d\n",
  463. current->comm, __func__, hfi_err);
  464. synx_state = SYNX_STATE_SIGNALED_CANCEL;
  465. }
  466. exit:
  467. rc = cvp_synx_ops(inst, CVP_OUTPUT_SYNX, fc, &synx_state);
  468. if (clock_check)
  469. cvp_check_clock(inst,
  470. (struct cvp_hfi_msg_session_hdr_ext *)&hdr);
  471. return rc;
  472. }
  473. static int cvp_alloc_fence_data(struct cvp_fence_command **f, u32 size)
  474. {
  475. struct cvp_fence_command *fcmd;
  476. int alloc_size = sizeof(struct cvp_hfi_msg_session_hdr_ext);
  477. fcmd = kzalloc(sizeof(struct cvp_fence_command), GFP_KERNEL);
  478. if (!fcmd)
  479. return -ENOMEM;
  480. alloc_size = (alloc_size >= size) ? alloc_size : size;
  481. fcmd->pkt = kzalloc(alloc_size, GFP_KERNEL);
  482. if (!fcmd->pkt) {
  483. kfree(fcmd);
  484. return -ENOMEM;
  485. }
  486. *f = fcmd;
  487. return 0;
  488. }
  489. static void cvp_free_fence_data(struct cvp_fence_command *f)
  490. {
  491. kfree(f->pkt);
  492. f->pkt = NULL;
  493. kfree(f);
  494. f = NULL;
  495. }
  496. static int cvp_fence_thread(void *data)
  497. {
  498. int rc = 0;
  499. struct msm_cvp_inst *inst;
  500. struct cvp_fence_queue *q;
  501. enum queue_state state;
  502. struct cvp_fence_command *f;
  503. struct cvp_hfi_cmd_session_hdr *pkt;
  504. u32 *synx;
  505. u64 ktid;
  506. dprintk(CVP_SYNX, "Enter %s\n", current->comm);
  507. inst = (struct msm_cvp_inst *)data;
  508. if (!inst || !inst->core || !inst->core->device) {
  509. dprintk(CVP_ERR, "%s invalid inst %pK\n", current->comm, inst);
  510. rc = -EINVAL;
  511. goto exit;
  512. }
  513. q = &inst->fence_cmd_queue;
  514. wait:
  515. dprintk(CVP_SYNX, "%s starts wait\n", current->comm);
  516. f = NULL;
  517. wait_event_interruptible(q->wq, cvp_fence_wait(q, &f, &state));
  518. if (state != QUEUE_START)
  519. goto exit;
  520. if (!f)
  521. goto wait;
  522. pkt = f->pkt;
  523. synx = (u32 *)f->synx;
  524. ktid = pkt->client_data.kdata & (FENCE_BIT - 1);
  525. dprintk(CVP_SYNX, "%s pkt type %d on ktid %llu frameID %llu\n",
  526. current->comm, pkt->packet_type, ktid, f->frame_id);
  527. rc = cvp_fence_proc(inst, f, pkt);
  528. mutex_lock(&q->lock);
  529. cvp_release_synx(inst, f);
  530. list_del_init(&f->list);
  531. state = q->state;
  532. mutex_unlock(&q->lock);
  533. dprintk(CVP_SYNX, "%s done with %d ktid %llu frameID %llu rc %d\n",
  534. current->comm, pkt->packet_type, ktid, f->frame_id, rc);
  535. cvp_free_fence_data(f);
  536. if (rc && state != QUEUE_START)
  537. goto exit;
  538. goto wait;
  539. exit:
  540. dprintk(CVP_SYNX, "%s exit\n", current->comm);
  541. cvp_put_inst(inst);
  542. do_exit(rc);
  543. return rc;
  544. }
  545. static int msm_cvp_session_process_hfi_fence(struct msm_cvp_inst *inst,
  546. struct eva_kmd_arg *arg)
  547. {
  548. int rc = 0;
  549. int idx;
  550. struct eva_kmd_hfi_fence_packet *fence_pkt;
  551. struct eva_kmd_hfi_synx_packet *synx_pkt;
  552. struct eva_kmd_fence_ctrl *kfc;
  553. struct cvp_hfi_cmd_session_hdr *pkt;
  554. unsigned int offset = 0, buf_num = 0, in_offset, in_buf_num;
  555. struct msm_cvp_inst *s;
  556. struct cvp_fence_command *f;
  557. struct cvp_fence_queue *q;
  558. u32 *fence;
  559. enum op_mode mode;
  560. if (!inst || !inst->core || !arg || !inst->core->device) {
  561. dprintk(CVP_ERR, "%s: invalid params\n", __func__);
  562. return -EINVAL;
  563. }
  564. s = cvp_get_inst_validate(inst->core, inst);
  565. if (!s)
  566. return -ECONNRESET;
  567. q = &inst->fence_cmd_queue;
  568. mutex_lock(&q->lock);
  569. mode = q->mode;
  570. mutex_unlock(&q->lock);
  571. if (mode == OP_DRAINING) {
  572. dprintk(CVP_SYNX, "%s: flush in progress\n", __func__);
  573. rc = -EBUSY;
  574. goto exit;
  575. }
  576. in_offset = arg->buf_offset;
  577. in_buf_num = arg->buf_num;
  578. fence_pkt = &arg->data.hfi_fence_pkt;
  579. pkt = (struct cvp_hfi_cmd_session_hdr *)&fence_pkt->pkt_data;
  580. idx = get_pkt_index((struct cvp_hal_session_cmd_pkt *)pkt);
  581. if (idx < 0 ||
  582. (pkt->size > MAX_HFI_FENCE_OFFSET * sizeof(unsigned int))) {
  583. dprintk(CVP_ERR, "%s incorrect packet %d %#x\n", __func__,
  584. pkt->size, pkt->packet_type);
  585. goto exit;
  586. }
  587. if (in_offset && in_buf_num) {
  588. offset = in_offset;
  589. buf_num = in_buf_num;
  590. }
  591. if (!is_buf_param_valid(buf_num, offset)) {
  592. dprintk(CVP_ERR, "Incorrect buf num and offset in cmd\n");
  593. goto exit;
  594. }
  595. rc = msm_cvp_map_frame(inst, (struct eva_kmd_hfi_packet *)pkt, offset,
  596. buf_num);
  597. if (rc)
  598. goto exit;
  599. rc = cvp_alloc_fence_data(&f, pkt->size);
  600. if (rc)
  601. goto exit;
  602. f->type = cvp_hfi_defs[idx].type;
  603. f->mode = OP_NORMAL;
  604. synx_pkt = &arg->data.hfi_synx_pkt;
  605. if (synx_pkt->fence_data[0] != 0xFEEDFACE) {
  606. dprintk(CVP_ERR, "%s deprecated synx path\n", __func__);
  607. cvp_free_fence_data(f);
  608. msm_cvp_unmap_frame(inst, pkt->client_data.kdata);
  609. goto exit;
  610. } else {
  611. kfc = &synx_pkt->fc;
  612. fence = (u32 *)&kfc->fences;
  613. f->frame_id = kfc->frame_id;
  614. f->signature = 0xFEEDFACE;
  615. f->num_fences = kfc->num_fences;
  616. f->output_index = kfc->output_index;
  617. }
  618. dprintk(CVP_SYNX, "%s: frameID %llu ktid %llu\n",
  619. __func__, f->frame_id, pkt->client_data.kdata);
  620. memcpy(f->pkt, pkt, pkt->size);
  621. f->pkt->client_data.kdata |= FENCE_BIT;
  622. rc = cvp_import_synx(inst, f, fence);
  623. if (rc) {
  624. kfree(f);
  625. goto exit;
  626. }
  627. mutex_lock(&q->lock);
  628. list_add_tail(&f->list, &inst->fence_cmd_queue.wait_list);
  629. mutex_unlock(&q->lock);
  630. wake_up(&inst->fence_cmd_queue.wq);
  631. exit:
  632. cvp_put_inst(s);
  633. return rc;
  634. }
  635. static inline int div_by_1dot5(unsigned int a)
  636. {
  637. unsigned long i = a << 1;
  638. return (unsigned int) i/3;
  639. }
  640. static inline int max_3(unsigned int a, unsigned int b, unsigned int c)
  641. {
  642. return (a >= b) ? ((a >= c) ? a : c) : ((b >= c) ? b : c);
  643. }
  644. static bool is_subblock_profile_existed(struct msm_cvp_inst *inst)
  645. {
  646. return (inst->prop.od_cycles ||
  647. inst->prop.mpu_cycles ||
  648. inst->prop.fdu_cycles ||
  649. inst->prop.ica_cycles);
  650. }
  651. static void aggregate_power_update(struct msm_cvp_core *core,
  652. struct cvp_power_level *nrt_pwr,
  653. struct cvp_power_level *rt_pwr,
  654. unsigned int max_clk_rate)
  655. {
  656. struct msm_cvp_inst *inst;
  657. int i;
  658. unsigned long fdu_sum[2] = {0}, od_sum[2] = {0}, mpu_sum[2] = {0};
  659. unsigned long ica_sum[2] = {0}, fw_sum[2] = {0};
  660. unsigned long op_fdu_max[2] = {0}, op_od_max[2] = {0};
  661. unsigned long op_mpu_max[2] = {0}, op_ica_max[2] = {0};
  662. unsigned long op_fw_max[2] = {0}, bw_sum[2] = {0}, op_bw_max[2] = {0};
  663. core->dyn_clk.sum_fps[HFI_HW_FDU] = 0;
  664. core->dyn_clk.sum_fps[HFI_HW_MPU] = 0;
  665. core->dyn_clk.sum_fps[HFI_HW_OD] = 0;
  666. core->dyn_clk.sum_fps[HFI_HW_ICA] = 0;
  667. list_for_each_entry(inst, &core->instances, list) {
  668. if (inst->state == MSM_CVP_CORE_INVALID ||
  669. inst->state == MSM_CVP_CORE_UNINIT ||
  670. !is_subblock_profile_existed(inst))
  671. continue;
  672. if (inst->prop.priority <= CVP_RT_PRIO_THRESHOLD) {
  673. /* Non-realtime session use index 0 */
  674. i = 0;
  675. } else {
  676. i = 1;
  677. }
  678. dprintk(CVP_PROF, "pwrUpdate fdu %u od %u mpu %u ica %u\n",
  679. inst->prop.fdu_cycles,
  680. inst->prop.od_cycles,
  681. inst->prop.mpu_cycles,
  682. inst->prop.ica_cycles);
  683. dprintk(CVP_PROF, "pwrUpdate fw %u fdu_o %u od_o %u mpu_o %u\n",
  684. inst->prop.fw_cycles,
  685. inst->prop.fdu_op_cycles,
  686. inst->prop.od_op_cycles,
  687. inst->prop.mpu_op_cycles);
  688. dprintk(CVP_PROF, "pwrUpdate ica_o %u fw_o %u bw %u bw_o %u\n",
  689. inst->prop.ica_op_cycles,
  690. inst->prop.fw_op_cycles,
  691. inst->prop.ddr_bw,
  692. inst->prop.ddr_op_bw);
  693. fdu_sum[i] += inst->prop.fdu_cycles;
  694. od_sum[i] += inst->prop.od_cycles;
  695. mpu_sum[i] += inst->prop.mpu_cycles;
  696. ica_sum[i] += inst->prop.ica_cycles;
  697. fw_sum[i] += inst->prop.fw_cycles;
  698. op_fdu_max[i] =
  699. (op_fdu_max[i] >= inst->prop.fdu_op_cycles) ?
  700. op_fdu_max[i] : inst->prop.fdu_op_cycles;
  701. op_od_max[i] =
  702. (op_od_max[i] >= inst->prop.od_op_cycles) ?
  703. op_od_max[i] : inst->prop.od_op_cycles;
  704. op_mpu_max[i] =
  705. (op_mpu_max[i] >= inst->prop.mpu_op_cycles) ?
  706. op_mpu_max[i] : inst->prop.mpu_op_cycles;
  707. op_ica_max[i] =
  708. (op_ica_max[i] >= inst->prop.ica_op_cycles) ?
  709. op_ica_max[i] : inst->prop.ica_op_cycles;
  710. op_fw_max[i] =
  711. (op_fw_max[i] >= inst->prop.fw_op_cycles) ?
  712. op_fw_max[i] : inst->prop.fw_op_cycles;
  713. bw_sum[i] += inst->prop.ddr_bw;
  714. op_bw_max[i] =
  715. (op_bw_max[i] >= inst->prop.ddr_op_bw) ?
  716. op_bw_max[i] : inst->prop.ddr_op_bw;
  717. dprintk(CVP_PWR, "%s:%d - fps fdu %d mpu %d od %d ica %d\n",
  718. __func__, __LINE__,
  719. inst->prop.fps[HFI_HW_FDU], inst->prop.fps[HFI_HW_MPU],
  720. inst->prop.fps[HFI_HW_OD], inst->prop.fps[HFI_HW_ICA]);
  721. core->dyn_clk.sum_fps[HFI_HW_FDU] += inst->prop.fps[HFI_HW_FDU];
  722. core->dyn_clk.sum_fps[HFI_HW_MPU] += inst->prop.fps[HFI_HW_MPU];
  723. core->dyn_clk.sum_fps[HFI_HW_OD] += inst->prop.fps[HFI_HW_OD];
  724. core->dyn_clk.sum_fps[HFI_HW_ICA] += inst->prop.fps[HFI_HW_ICA];
  725. dprintk(CVP_PWR, "%s:%d - sum_fps fdu %d mpu %d od %d ica %d\n",
  726. __func__, __LINE__,
  727. core->dyn_clk.sum_fps[HFI_HW_FDU],
  728. core->dyn_clk.sum_fps[HFI_HW_MPU],
  729. core->dyn_clk.sum_fps[HFI_HW_OD],
  730. core->dyn_clk.sum_fps[HFI_HW_ICA]);
  731. }
  732. for (i = 0; i < 2; i++) {
  733. fdu_sum[i] = max_3(fdu_sum[i], od_sum[i], mpu_sum[i]);
  734. fdu_sum[i] = max_3(fdu_sum[i], ica_sum[i], fw_sum[i]);
  735. op_fdu_max[i] = max_3(op_fdu_max[i], op_od_max[i],
  736. op_mpu_max[i]);
  737. op_fdu_max[i] = max_3(op_fdu_max[i],
  738. op_ica_max[i], op_fw_max[i]);
  739. op_fdu_max[i] =
  740. (op_fdu_max[i] > max_clk_rate) ?
  741. max_clk_rate : op_fdu_max[i];
  742. bw_sum[i] = (bw_sum[i] >= op_bw_max[i]) ?
  743. bw_sum[i] : op_bw_max[i];
  744. }
  745. nrt_pwr->core_sum += fdu_sum[0];
  746. nrt_pwr->op_core_sum = (nrt_pwr->op_core_sum >= op_fdu_max[0]) ?
  747. nrt_pwr->op_core_sum : op_fdu_max[0];
  748. nrt_pwr->bw_sum += bw_sum[0];
  749. rt_pwr->core_sum += fdu_sum[1];
  750. rt_pwr->op_core_sum = (rt_pwr->op_core_sum >= op_fdu_max[1]) ?
  751. rt_pwr->op_core_sum : op_fdu_max[1];
  752. rt_pwr->bw_sum += bw_sum[1];
  753. }
  754. /**
  755. * adjust_bw_freqs(): calculate CVP clock freq and bw required to sustain
  756. * required use case.
  757. * Bandwidth vote will be best-effort, not returning error if the request
  758. * b/w exceeds max limit.
  759. * Clock vote from non-realtime sessions will be best effort, not returning
  760. * error if the aggreated session clock request exceeds max limit.
  761. * Clock vote from realtime session will be hard request. If aggregated
  762. * session clock request exceeds max limit, the function will return
  763. * error.
  764. *
  765. * Ensure caller acquires clk_lock!
  766. */
  767. static int adjust_bw_freqs(void)
  768. {
  769. struct msm_cvp_core *core;
  770. struct iris_hfi_device *hdev;
  771. struct bus_info *bus;
  772. struct clock_set *clocks;
  773. struct clock_info *cl;
  774. struct allowed_clock_rates_table *tbl = NULL;
  775. unsigned int tbl_size;
  776. unsigned int cvp_min_rate, cvp_max_rate, max_bw, min_bw;
  777. struct cvp_power_level rt_pwr = {0}, nrt_pwr = {0};
  778. unsigned long tmp, core_sum, op_core_sum, bw_sum;
  779. int i, rc = 0;
  780. unsigned long ctrl_freq;
  781. core = list_first_entry(&cvp_driver->cores, struct msm_cvp_core, list);
  782. hdev = core->device->hfi_device_data;
  783. clocks = &core->resources.clock_set;
  784. cl = &clocks->clock_tbl[clocks->count - 1];
  785. tbl = core->resources.allowed_clks_tbl;
  786. tbl_size = core->resources.allowed_clks_tbl_size;
  787. cvp_min_rate = tbl[0].clock_rate;
  788. cvp_max_rate = tbl[tbl_size - 1].clock_rate;
  789. bus = &core->resources.bus_set.bus_tbl[1];
  790. max_bw = bus->range[1];
  791. min_bw = max_bw/10;
  792. aggregate_power_update(core, &nrt_pwr, &rt_pwr, cvp_max_rate);
  793. dprintk(CVP_PROF, "PwrUpdate nrt %u %u rt %u %u\n",
  794. nrt_pwr.core_sum, nrt_pwr.op_core_sum,
  795. rt_pwr.core_sum, rt_pwr.op_core_sum);
  796. if (rt_pwr.core_sum > cvp_max_rate) {
  797. dprintk(CVP_WARN, "%s clk vote out of range %lld\n",
  798. __func__, rt_pwr.core_sum);
  799. return -ENOTSUPP;
  800. }
  801. core_sum = rt_pwr.core_sum + nrt_pwr.core_sum;
  802. op_core_sum = (rt_pwr.op_core_sum >= nrt_pwr.op_core_sum) ?
  803. rt_pwr.op_core_sum : nrt_pwr.op_core_sum;
  804. core_sum = (core_sum >= op_core_sum) ?
  805. core_sum : op_core_sum;
  806. if (core_sum > cvp_max_rate) {
  807. core_sum = cvp_max_rate;
  808. } else if (core_sum <= cvp_min_rate) {
  809. core_sum = cvp_min_rate;
  810. } else {
  811. for (i = 1; i < tbl_size; i++)
  812. if (core_sum <= tbl[i].clock_rate)
  813. break;
  814. core_sum = tbl[i].clock_rate;
  815. }
  816. bw_sum = rt_pwr.bw_sum + nrt_pwr.bw_sum;
  817. bw_sum = bw_sum >> 10;
  818. bw_sum = (bw_sum > max_bw) ? max_bw : bw_sum;
  819. bw_sum = (bw_sum < min_bw) ? min_bw : bw_sum;
  820. dprintk(CVP_PROF, "%s %lld %lld\n", __func__,
  821. core_sum, bw_sum);
  822. if (!cl->has_scaling) {
  823. dprintk(CVP_ERR, "Cannot scale CVP clock\n");
  824. return -EINVAL;
  825. }
  826. tmp = core->curr_freq;
  827. core->curr_freq = core_sum;
  828. core->orig_core_sum = core_sum;
  829. rc = msm_cvp_set_clocks(core);
  830. if (rc) {
  831. dprintk(CVP_ERR,
  832. "Failed to set clock rate %u %s: %d %s\n",
  833. core_sum, cl->name, rc, __func__);
  834. core->curr_freq = tmp;
  835. return rc;
  836. }
  837. ctrl_freq = (core->curr_freq*3)>>1;
  838. core->dyn_clk.conf_freq = core->curr_freq;
  839. for (i = 0; i < HFI_MAX_HW_THREADS; ++i) {
  840. core->dyn_clk.hi_ctrl_lim[i] = core->dyn_clk.sum_fps[i] ?
  841. ctrl_freq/core->dyn_clk.sum_fps[i] : 0;
  842. core->dyn_clk.lo_ctrl_lim[i] =
  843. core->dyn_clk.hi_ctrl_lim[i];
  844. }
  845. hdev->clk_freq = core->curr_freq;
  846. rc = msm_cvp_set_bw(bus, bw_sum);
  847. return rc;
  848. }
  849. int msm_cvp_update_power(struct msm_cvp_inst *inst)
  850. {
  851. int rc = 0;
  852. struct msm_cvp_core *core;
  853. struct msm_cvp_inst *s;
  854. if (!inst) {
  855. dprintk(CVP_ERR, "%s: invalid params\n", __func__);
  856. return -EINVAL;
  857. }
  858. s = cvp_get_inst_validate(inst->core, inst);
  859. if (!s)
  860. return -ECONNRESET;
  861. core = inst->core;
  862. mutex_lock(&core->clk_lock);
  863. rc = adjust_bw_freqs();
  864. mutex_unlock(&core->clk_lock);
  865. cvp_put_inst(s);
  866. return rc;
  867. }
  868. int msm_cvp_session_delete(struct msm_cvp_inst *inst)
  869. {
  870. return 0;
  871. }
  872. int msm_cvp_session_create(struct msm_cvp_inst *inst)
  873. {
  874. int rc = 0;
  875. struct cvp_session_queue *sq;
  876. if (!inst || !inst->core)
  877. return -EINVAL;
  878. if (inst->state >= MSM_CVP_CLOSE_DONE)
  879. return -ECONNRESET;
  880. if (inst->state != MSM_CVP_CORE_INIT_DONE ||
  881. inst->state > MSM_CVP_OPEN_DONE) {
  882. dprintk(CVP_ERR,
  883. "%s Incorrect CVP state %d to create session\n",
  884. __func__, inst->state);
  885. return -EINVAL;
  886. }
  887. rc = msm_cvp_comm_try_state(inst, MSM_CVP_OPEN_DONE);
  888. if (rc) {
  889. dprintk(CVP_ERR,
  890. "Failed to move instance to open done state\n");
  891. goto fail_init;
  892. }
  893. rc = cvp_comm_set_arp_buffers(inst);
  894. if (rc) {
  895. dprintk(CVP_ERR,
  896. "Failed to set ARP buffers\n");
  897. goto fail_init;
  898. }
  899. cvp_sess_init_synx(inst);
  900. sq = &inst->session_queue;
  901. spin_lock(&sq->lock);
  902. sq->state = QUEUE_ACTIVE;
  903. spin_unlock(&sq->lock);
  904. fail_init:
  905. return rc;
  906. }
  907. static int session_state_check_init(struct msm_cvp_inst *inst)
  908. {
  909. mutex_lock(&inst->lock);
  910. if (inst->state == MSM_CVP_OPEN || inst->state == MSM_CVP_OPEN_DONE) {
  911. mutex_unlock(&inst->lock);
  912. return 0;
  913. }
  914. mutex_unlock(&inst->lock);
  915. return msm_cvp_session_create(inst);
  916. }
  917. static int cvp_fence_thread_start(struct msm_cvp_inst *inst)
  918. {
  919. u32 tnum = 0;
  920. u32 i = 0;
  921. int rc = 0;
  922. char tname[16];
  923. struct task_struct *thread;
  924. struct cvp_fence_queue *q;
  925. struct cvp_session_queue *sq;
  926. if (!inst->prop.fthread_nr)
  927. return 0;
  928. q = &inst->fence_cmd_queue;
  929. mutex_lock(&q->lock);
  930. q->state = QUEUE_START;
  931. mutex_unlock(&q->lock);
  932. for (i = 0; i < inst->prop.fthread_nr; ++i) {
  933. if (!cvp_get_inst_validate(inst->core, inst)) {
  934. rc = -ECONNRESET;
  935. goto exit;
  936. }
  937. snprintf(tname, sizeof(tname), "fthread_%d", tnum++);
  938. thread = kthread_run(cvp_fence_thread, inst, tname);
  939. if (!thread) {
  940. dprintk(CVP_ERR, "%s create %s fail", __func__, tname);
  941. rc = -ECHILD;
  942. goto exit;
  943. }
  944. }
  945. sq = &inst->session_queue_fence;
  946. spin_lock(&sq->lock);
  947. sq->state = QUEUE_START;
  948. spin_unlock(&sq->lock);
  949. exit:
  950. if (rc) {
  951. mutex_lock(&q->lock);
  952. q->state = QUEUE_STOP;
  953. mutex_unlock(&q->lock);
  954. wake_up_all(&q->wq);
  955. }
  956. return rc;
  957. }
  958. static int cvp_fence_thread_stop(struct msm_cvp_inst *inst)
  959. {
  960. struct cvp_fence_queue *q;
  961. struct cvp_session_queue *sq;
  962. if (!inst->prop.fthread_nr)
  963. return 0;
  964. q = &inst->fence_cmd_queue;
  965. mutex_lock(&q->lock);
  966. q->state = QUEUE_STOP;
  967. mutex_unlock(&q->lock);
  968. sq = &inst->session_queue_fence;
  969. spin_lock(&sq->lock);
  970. sq->state = QUEUE_STOP;
  971. spin_unlock(&sq->lock);
  972. wake_up_all(&q->wq);
  973. wake_up_all(&sq->wq);
  974. return 0;
  975. }
  976. static int msm_cvp_session_start(struct msm_cvp_inst *inst,
  977. struct eva_kmd_arg *arg)
  978. {
  979. struct cvp_session_queue *sq;
  980. struct cvp_hfi_device *hdev;
  981. sq = &inst->session_queue;
  982. spin_lock(&sq->lock);
  983. if (sq->msg_count) {
  984. dprintk(CVP_ERR, "session start failed queue not empty%d\n",
  985. sq->msg_count);
  986. spin_unlock(&sq->lock);
  987. return -EINVAL;
  988. }
  989. sq->state = QUEUE_START;
  990. spin_unlock(&sq->lock);
  991. if (inst->prop.type == HFI_SESSION_FD
  992. || inst->prop.type == HFI_SESSION_DMM) {
  993. spin_lock(&inst->core->resources.pm_qos.lock);
  994. inst->core->resources.pm_qos.off_vote_cnt++;
  995. spin_unlock(&inst->core->resources.pm_qos.lock);
  996. hdev = inst->core->device;
  997. call_hfi_op(hdev, pm_qos_update, hdev->hfi_device_data);
  998. }
  999. return cvp_fence_thread_start(inst);
  1000. }
  1001. static int msm_cvp_session_stop(struct msm_cvp_inst *inst,
  1002. struct eva_kmd_arg *arg)
  1003. {
  1004. struct cvp_session_queue *sq;
  1005. struct eva_kmd_session_control *sc = &arg->data.session_ctrl;
  1006. sq = &inst->session_queue;
  1007. spin_lock(&sq->lock);
  1008. if (sq->msg_count) {
  1009. dprintk(CVP_ERR, "session stop incorrect: queue not empty%d\n",
  1010. sq->msg_count);
  1011. sc->ctrl_data[0] = sq->msg_count;
  1012. spin_unlock(&sq->lock);
  1013. return -EUCLEAN;
  1014. }
  1015. sq->state = QUEUE_STOP;
  1016. pr_info(CVP_DBG_TAG "Stop session: %pK session_id = %d\n",
  1017. "sess", inst, hash32_ptr(inst->session));
  1018. spin_unlock(&sq->lock);
  1019. wake_up_all(&inst->session_queue.wq);
  1020. return cvp_fence_thread_stop(inst);
  1021. }
  1022. int msm_cvp_session_queue_stop(struct msm_cvp_inst *inst)
  1023. {
  1024. struct cvp_session_queue *sq;
  1025. sq = &inst->session_queue;
  1026. spin_lock(&sq->lock);
  1027. if (sq->state == QUEUE_STOP) {
  1028. spin_unlock(&sq->lock);
  1029. return 0;
  1030. }
  1031. sq->state = QUEUE_STOP;
  1032. dprintk(CVP_SESS, "Stop session queue: %pK session_id = %d\n",
  1033. inst, hash32_ptr(inst->session));
  1034. spin_unlock(&sq->lock);
  1035. wake_up_all(&inst->session_queue.wq);
  1036. return cvp_fence_thread_stop(inst);
  1037. }
  1038. static int msm_cvp_session_ctrl(struct msm_cvp_inst *inst,
  1039. struct eva_kmd_arg *arg)
  1040. {
  1041. struct eva_kmd_session_control *ctrl = &arg->data.session_ctrl;
  1042. int rc = 0;
  1043. unsigned int ctrl_type;
  1044. ctrl_type = ctrl->ctrl_type;
  1045. if (!inst && ctrl_type != SESSION_CREATE) {
  1046. dprintk(CVP_ERR, "%s invalid session\n", __func__);
  1047. return -EINVAL;
  1048. }
  1049. switch (ctrl_type) {
  1050. case SESSION_STOP:
  1051. rc = msm_cvp_session_stop(inst, arg);
  1052. break;
  1053. case SESSION_START:
  1054. rc = msm_cvp_session_start(inst, arg);
  1055. break;
  1056. case SESSION_CREATE:
  1057. rc = msm_cvp_session_create(inst);
  1058. break;
  1059. case SESSION_DELETE:
  1060. rc = msm_cvp_session_delete(inst);
  1061. break;
  1062. case SESSION_INFO:
  1063. default:
  1064. dprintk(CVP_ERR, "%s Unsupported session ctrl%d\n",
  1065. __func__, ctrl->ctrl_type);
  1066. rc = -EINVAL;
  1067. }
  1068. return rc;
  1069. }
  1070. static unsigned int msm_cvp_get_hw_aggregate_cycles(enum hw_block hwblk)
  1071. {
  1072. struct msm_cvp_core *core;
  1073. struct msm_cvp_inst *inst;
  1074. unsigned long cycles_sum = 0;
  1075. core = list_first_entry(&cvp_driver->cores, struct msm_cvp_core, list);
  1076. if (!core) {
  1077. dprintk(CVP_ERR, "%s: invalid core\n", __func__);
  1078. return -EINVAL;
  1079. }
  1080. mutex_lock(&core->clk_lock);
  1081. list_for_each_entry(inst, &core->instances, list) {
  1082. if (inst->state == MSM_CVP_CORE_INVALID ||
  1083. inst->state == MSM_CVP_CORE_UNINIT ||
  1084. !is_subblock_profile_existed(inst))
  1085. continue;
  1086. switch (hwblk) {
  1087. case CVP_FDU:
  1088. {
  1089. cycles_sum += inst->prop.fdu_cycles;
  1090. break;
  1091. }
  1092. case CVP_ICA:
  1093. {
  1094. cycles_sum += inst->prop.ica_cycles;
  1095. break;
  1096. }
  1097. case CVP_MPU:
  1098. {
  1099. cycles_sum += inst->prop.mpu_cycles;
  1100. break;
  1101. }
  1102. case CVP_OD:
  1103. {
  1104. cycles_sum += inst->prop.od_cycles;
  1105. break;
  1106. }
  1107. default:
  1108. dprintk(CVP_ERR, "unrecognized hw block %d\n",
  1109. hwblk);
  1110. break;
  1111. }
  1112. }
  1113. mutex_unlock(&core->clk_lock);
  1114. cycles_sum = cycles_sum&0xFFFFFFFF;
  1115. return (unsigned int)cycles_sum;
  1116. }
  1117. static int msm_cvp_get_sysprop(struct msm_cvp_inst *inst,
  1118. struct eva_kmd_arg *arg)
  1119. {
  1120. struct eva_kmd_sys_properties *props = &arg->data.sys_properties;
  1121. struct cvp_hfi_device *hdev;
  1122. struct iris_hfi_device *hfi;
  1123. struct cvp_session_prop *session_prop;
  1124. int i, rc = 0;
  1125. if (!inst || !inst->core || !inst->core->device) {
  1126. dprintk(CVP_ERR, "%s: invalid params\n", __func__);
  1127. return -EINVAL;
  1128. }
  1129. hdev = inst->core->device;
  1130. hfi = hdev->hfi_device_data;
  1131. if (props->prop_num > MAX_KMD_PROP_NUM_PER_PACKET) {
  1132. dprintk(CVP_ERR, "Too many properties %d to get\n",
  1133. props->prop_num);
  1134. return -E2BIG;
  1135. }
  1136. session_prop = &inst->prop;
  1137. for (i = 0; i < props->prop_num; i++) {
  1138. switch (props->prop_data[i].prop_type) {
  1139. case EVA_KMD_PROP_HFI_VERSION:
  1140. {
  1141. props->prop_data[i].data = hfi->version;
  1142. break;
  1143. }
  1144. case EVA_KMD_PROP_SESSION_DUMPOFFSET:
  1145. {
  1146. props->prop_data[i].data =
  1147. session_prop->dump_offset;
  1148. break;
  1149. }
  1150. case EVA_KMD_PROP_SESSION_DUMPSIZE:
  1151. {
  1152. props->prop_data[i].data =
  1153. session_prop->dump_size;
  1154. break;
  1155. }
  1156. case EVA_KMD_PROP_PWR_FDU:
  1157. {
  1158. props->prop_data[i].data =
  1159. msm_cvp_get_hw_aggregate_cycles(CVP_FDU);
  1160. break;
  1161. }
  1162. case EVA_KMD_PROP_PWR_ICA:
  1163. {
  1164. props->prop_data[i].data =
  1165. msm_cvp_get_hw_aggregate_cycles(CVP_ICA);
  1166. break;
  1167. }
  1168. case EVA_KMD_PROP_PWR_OD:
  1169. {
  1170. props->prop_data[i].data =
  1171. msm_cvp_get_hw_aggregate_cycles(CVP_OD);
  1172. break;
  1173. }
  1174. case EVA_KMD_PROP_PWR_MPU:
  1175. {
  1176. props->prop_data[i].data =
  1177. msm_cvp_get_hw_aggregate_cycles(CVP_MPU);
  1178. break;
  1179. }
  1180. default:
  1181. dprintk(CVP_ERR, "unrecognized sys property %d\n",
  1182. props->prop_data[i].prop_type);
  1183. rc = -EFAULT;
  1184. }
  1185. }
  1186. return rc;
  1187. }
  1188. static int msm_cvp_set_sysprop(struct msm_cvp_inst *inst,
  1189. struct eva_kmd_arg *arg)
  1190. {
  1191. struct eva_kmd_sys_properties *props = &arg->data.sys_properties;
  1192. struct eva_kmd_sys_property *prop_array;
  1193. struct cvp_session_prop *session_prop;
  1194. int i, rc = 0;
  1195. if (!inst) {
  1196. dprintk(CVP_ERR, "%s: invalid params\n", __func__);
  1197. return -EINVAL;
  1198. }
  1199. if (props->prop_num > MAX_KMD_PROP_NUM_PER_PACKET) {
  1200. dprintk(CVP_ERR, "Too many properties %d to set\n",
  1201. props->prop_num);
  1202. return -E2BIG;
  1203. }
  1204. prop_array = &arg->data.sys_properties.prop_data[0];
  1205. session_prop = &inst->prop;
  1206. for (i = 0; i < props->prop_num; i++) {
  1207. switch (prop_array[i].prop_type) {
  1208. case EVA_KMD_PROP_SESSION_TYPE:
  1209. session_prop->type = prop_array[i].data;
  1210. break;
  1211. case EVA_KMD_PROP_SESSION_KERNELMASK:
  1212. session_prop->kernel_mask = prop_array[i].data;
  1213. break;
  1214. case EVA_KMD_PROP_SESSION_PRIORITY:
  1215. session_prop->priority = prop_array[i].data;
  1216. break;
  1217. case EVA_KMD_PROP_SESSION_SECURITY:
  1218. session_prop->is_secure = prop_array[i].data;
  1219. break;
  1220. case EVA_KMD_PROP_SESSION_DSPMASK:
  1221. session_prop->dsp_mask = prop_array[i].data;
  1222. break;
  1223. case EVA_KMD_PROP_PWR_FDU:
  1224. session_prop->fdu_cycles = prop_array[i].data;
  1225. break;
  1226. case EVA_KMD_PROP_PWR_ICA:
  1227. session_prop->ica_cycles =
  1228. div_by_1dot5(prop_array[i].data);
  1229. break;
  1230. case EVA_KMD_PROP_PWR_OD:
  1231. session_prop->od_cycles = prop_array[i].data;
  1232. break;
  1233. case EVA_KMD_PROP_PWR_MPU:
  1234. session_prop->mpu_cycles = prop_array[i].data;
  1235. break;
  1236. case EVA_KMD_PROP_PWR_FW:
  1237. session_prop->fw_cycles =
  1238. div_by_1dot5(prop_array[i].data);
  1239. break;
  1240. case EVA_KMD_PROP_PWR_DDR:
  1241. session_prop->ddr_bw = prop_array[i].data;
  1242. break;
  1243. case EVA_KMD_PROP_PWR_SYSCACHE:
  1244. session_prop->ddr_cache = prop_array[i].data;
  1245. break;
  1246. case EVA_KMD_PROP_PWR_FDU_OP:
  1247. session_prop->fdu_op_cycles = prop_array[i].data;
  1248. break;
  1249. case EVA_KMD_PROP_PWR_ICA_OP:
  1250. session_prop->ica_op_cycles =
  1251. div_by_1dot5(prop_array[i].data);
  1252. break;
  1253. case EVA_KMD_PROP_PWR_OD_OP:
  1254. session_prop->od_op_cycles = prop_array[i].data;
  1255. break;
  1256. case EVA_KMD_PROP_PWR_MPU_OP:
  1257. session_prop->mpu_op_cycles = prop_array[i].data;
  1258. break;
  1259. case EVA_KMD_PROP_PWR_FW_OP:
  1260. session_prop->fw_op_cycles =
  1261. div_by_1dot5(prop_array[i].data);
  1262. break;
  1263. case EVA_KMD_PROP_PWR_DDR_OP:
  1264. session_prop->ddr_op_bw = prop_array[i].data;
  1265. break;
  1266. case EVA_KMD_PROP_PWR_SYSCACHE_OP:
  1267. session_prop->ddr_op_cache = prop_array[i].data;
  1268. break;
  1269. case EVA_KMD_PROP_PWR_FPS_FDU:
  1270. session_prop->fps[HFI_HW_FDU] = prop_array[i].data;
  1271. break;
  1272. case EVA_KMD_PROP_PWR_FPS_MPU:
  1273. session_prop->fps[HFI_HW_MPU] = prop_array[i].data;
  1274. break;
  1275. case EVA_KMD_PROP_PWR_FPS_OD:
  1276. session_prop->fps[HFI_HW_OD] = prop_array[i].data;
  1277. break;
  1278. case EVA_KMD_PROP_PWR_FPS_ICA:
  1279. session_prop->fps[HFI_HW_ICA] = prop_array[i].data;
  1280. break;
  1281. case EVA_KMD_PROP_SESSION_DUMPOFFSET:
  1282. session_prop->dump_offset = prop_array[i].data;
  1283. break;
  1284. case EVA_KMD_PROP_SESSION_DUMPSIZE:
  1285. session_prop->dump_size = prop_array[i].data;
  1286. break;
  1287. default:
  1288. dprintk(CVP_ERR,
  1289. "unrecognized sys property to set %d\n",
  1290. prop_array[i].prop_type);
  1291. rc = -EFAULT;
  1292. }
  1293. }
  1294. return rc;
  1295. }
  1296. static int cvp_drain_fence_sched_list(struct msm_cvp_inst *inst)
  1297. {
  1298. unsigned long wait_time;
  1299. struct cvp_fence_queue *q;
  1300. struct cvp_fence_command *f;
  1301. int rc = 0;
  1302. int count = 0, max_count = 0;
  1303. u64 ktid;
  1304. q = &inst->fence_cmd_queue;
  1305. mutex_lock(&q->lock);
  1306. list_for_each_entry(f, &q->sched_list, list) {
  1307. ktid = f->pkt->client_data.kdata & (FENCE_BIT - 1);
  1308. dprintk(CVP_SYNX, "%s: frame %llu %llu is in sched_list\n",
  1309. __func__, ktid, f->frame_id);
  1310. ++count;
  1311. }
  1312. mutex_unlock(&q->lock);
  1313. wait_time = count * CVP_MAX_WAIT_TIME * 1000;
  1314. dprintk(CVP_SYNX, "%s: wait %d us for %d fence command\n",
  1315. __func__, wait_time, count);
  1316. count = 0;
  1317. max_count = wait_time / 100;
  1318. retry:
  1319. mutex_lock(&q->lock);
  1320. if (list_empty(&q->sched_list)) {
  1321. mutex_unlock(&q->lock);
  1322. return rc;
  1323. }
  1324. mutex_unlock(&q->lock);
  1325. usleep_range(100, 200);
  1326. ++count;
  1327. if (count < max_count) {
  1328. goto retry;
  1329. } else {
  1330. rc = -ETIMEDOUT;
  1331. dprintk(CVP_ERR, "%s: timed out!\n", __func__);
  1332. }
  1333. return rc;
  1334. }
  1335. static void cvp_clean_fence_queue(struct msm_cvp_inst *inst, int synx_state)
  1336. {
  1337. struct cvp_fence_queue *q;
  1338. struct cvp_fence_command *f, *d;
  1339. u64 ktid;
  1340. q = &inst->fence_cmd_queue;
  1341. mutex_lock(&q->lock);
  1342. q->mode = OP_DRAINING;
  1343. list_for_each_entry_safe(f, d, &q->wait_list, list) {
  1344. ktid = f->pkt->client_data.kdata & (FENCE_BIT - 1);
  1345. dprintk(CVP_SYNX, "%s: (%#x) flush frame %llu %llu wait_list\n",
  1346. __func__, hash32_ptr(inst->session), ktid, f->frame_id);
  1347. list_del_init(&f->list);
  1348. msm_cvp_unmap_frame(inst, f->pkt->client_data.kdata);
  1349. cvp_cancel_synx(inst, CVP_OUTPUT_SYNX, f, synx_state);
  1350. cvp_release_synx(inst, f);
  1351. cvp_free_fence_data(f);
  1352. }
  1353. list_for_each_entry(f, &q->sched_list, list) {
  1354. ktid = f->pkt->client_data.kdata & (FENCE_BIT - 1);
  1355. dprintk(CVP_SYNX, "%s: (%#x)flush frame %llu %llu sched_list\n",
  1356. __func__, hash32_ptr(inst->session), ktid, f->frame_id);
  1357. cvp_cancel_synx(inst, CVP_INPUT_SYNX, f, synx_state);
  1358. }
  1359. mutex_unlock(&q->lock);
  1360. }
  1361. int cvp_clean_session_queues(struct msm_cvp_inst *inst)
  1362. {
  1363. struct cvp_fence_queue *q;
  1364. struct cvp_session_queue *sq;
  1365. u32 count = 0, max_retries = 100;
  1366. q = &inst->fence_cmd_queue;
  1367. mutex_lock(&q->lock);
  1368. if (q->state == QUEUE_START) {
  1369. mutex_unlock(&q->lock);
  1370. cvp_clean_fence_queue(inst, SYNX_STATE_SIGNALED_ERROR);
  1371. } else {
  1372. dprintk(CVP_WARN, "Incorrect fence cmd queue state %d\n",
  1373. q->state);
  1374. mutex_unlock(&q->lock);
  1375. }
  1376. cvp_fence_thread_stop(inst);
  1377. /* Waiting for all output synx sent */
  1378. retry:
  1379. mutex_lock(&q->lock);
  1380. if (list_empty(&q->sched_list)) {
  1381. mutex_unlock(&q->lock);
  1382. return 0;
  1383. }
  1384. mutex_unlock(&q->lock);
  1385. usleep_range(500, 1000);
  1386. if (++count > max_retries)
  1387. return -EBUSY;
  1388. goto retry;
  1389. sq = &inst->session_queue_fence;
  1390. spin_lock(&sq->lock);
  1391. sq->state = QUEUE_INVALID;
  1392. spin_unlock(&sq->lock);
  1393. }
  1394. static int cvp_flush_all(struct msm_cvp_inst *inst)
  1395. {
  1396. int rc = 0;
  1397. struct msm_cvp_inst *s;
  1398. struct cvp_fence_queue *q;
  1399. struct cvp_hfi_device *hdev;
  1400. if (!inst || !inst->core) {
  1401. dprintk(CVP_ERR, "%s: invalid params\n", __func__);
  1402. return -EINVAL;
  1403. }
  1404. s = cvp_get_inst_validate(inst->core, inst);
  1405. if (!s)
  1406. return -ECONNRESET;
  1407. dprintk(CVP_SESS, "session %llx (%#x)flush all starts\n",
  1408. inst, hash32_ptr(inst->session));
  1409. q = &inst->fence_cmd_queue;
  1410. hdev = inst->core->device;
  1411. cvp_clean_fence_queue(inst, SYNX_STATE_SIGNALED_CANCEL);
  1412. dprintk(CVP_SESS, "%s: (%#x) send flush to fw\n",
  1413. __func__, hash32_ptr(inst->session));
  1414. /* Send flush to FW */
  1415. rc = call_hfi_op(hdev, session_flush, (void *)inst->session);
  1416. if (rc) {
  1417. dprintk(CVP_WARN, "%s: continue flush without fw. rc %d\n",
  1418. __func__, rc);
  1419. goto exit;
  1420. }
  1421. /* Wait for FW response */
  1422. rc = wait_for_sess_signal_receipt(inst, HAL_SESSION_FLUSH_DONE);
  1423. if (rc)
  1424. dprintk(CVP_WARN, "%s: wait for signal failed, rc %d\n",
  1425. __func__, rc);
  1426. dprintk(CVP_SESS, "%s: (%#x) received flush from fw\n",
  1427. __func__, hash32_ptr(inst->session));
  1428. exit:
  1429. rc = cvp_drain_fence_sched_list(inst);
  1430. mutex_lock(&q->lock);
  1431. q->mode = OP_NORMAL;
  1432. mutex_unlock(&q->lock);
  1433. cvp_put_inst(s);
  1434. return rc;
  1435. }
  1436. int msm_cvp_handle_syscall(struct msm_cvp_inst *inst, struct eva_kmd_arg *arg)
  1437. {
  1438. int rc = 0;
  1439. if (!inst || !arg) {
  1440. dprintk(CVP_ERR, "%s: invalid args\n", __func__);
  1441. return -EINVAL;
  1442. }
  1443. dprintk(CVP_HFI, "%s: arg->type = %x", __func__, arg->type);
  1444. if (arg->type != EVA_KMD_SESSION_CONTROL &&
  1445. arg->type != EVA_KMD_SET_SYS_PROPERTY &&
  1446. arg->type != EVA_KMD_GET_SYS_PROPERTY) {
  1447. rc = session_state_check_init(inst);
  1448. if (rc) {
  1449. dprintk(CVP_ERR,
  1450. "Incorrect session state %d for command %#x",
  1451. inst->state, arg->type);
  1452. return rc;
  1453. }
  1454. }
  1455. switch (arg->type) {
  1456. case EVA_KMD_GET_SESSION_INFO:
  1457. {
  1458. struct eva_kmd_session_info *session =
  1459. (struct eva_kmd_session_info *)&arg->data.session;
  1460. rc = msm_cvp_get_session_info(inst, &session->session_id);
  1461. break;
  1462. }
  1463. case EVA_KMD_UPDATE_POWER:
  1464. {
  1465. rc = msm_cvp_update_power(inst);
  1466. break;
  1467. }
  1468. case EVA_KMD_REGISTER_BUFFER:
  1469. {
  1470. struct eva_kmd_buffer *buf =
  1471. (struct eva_kmd_buffer *)&arg->data.regbuf;
  1472. rc = msm_cvp_register_buffer(inst, buf);
  1473. break;
  1474. }
  1475. case EVA_KMD_UNREGISTER_BUFFER:
  1476. {
  1477. struct eva_kmd_buffer *buf =
  1478. (struct eva_kmd_buffer *)&arg->data.unregbuf;
  1479. rc = msm_cvp_unregister_buffer(inst, buf);
  1480. break;
  1481. }
  1482. case EVA_KMD_RECEIVE_MSG_PKT:
  1483. {
  1484. struct eva_kmd_hfi_packet *out_pkt =
  1485. (struct eva_kmd_hfi_packet *)&arg->data.hfi_pkt;
  1486. rc = msm_cvp_session_receive_hfi(inst, out_pkt);
  1487. break;
  1488. }
  1489. case EVA_KMD_SEND_CMD_PKT:
  1490. {
  1491. struct eva_kmd_hfi_packet *in_pkt =
  1492. (struct eva_kmd_hfi_packet *)&arg->data.hfi_pkt;
  1493. rc = msm_cvp_session_process_hfi(inst, in_pkt,
  1494. arg->buf_offset, arg->buf_num);
  1495. break;
  1496. }
  1497. case EVA_KMD_SEND_FENCE_CMD_PKT:
  1498. {
  1499. rc = msm_cvp_session_process_hfi_fence(inst, arg);
  1500. break;
  1501. }
  1502. case EVA_KMD_SESSION_CONTROL:
  1503. rc = msm_cvp_session_ctrl(inst, arg);
  1504. break;
  1505. case EVA_KMD_GET_SYS_PROPERTY:
  1506. rc = msm_cvp_get_sysprop(inst, arg);
  1507. break;
  1508. case EVA_KMD_SET_SYS_PROPERTY:
  1509. rc = msm_cvp_set_sysprop(inst, arg);
  1510. break;
  1511. case EVA_KMD_FLUSH_ALL:
  1512. rc = cvp_flush_all(inst);
  1513. break;
  1514. case EVA_KMD_FLUSH_FRAME:
  1515. dprintk(CVP_WARN, "EVA_KMD_FLUSH_FRAME IOCTL deprecated\n");
  1516. rc = 0;
  1517. break;
  1518. default:
  1519. dprintk(CVP_HFI, "%s: unknown arg type %#x\n",
  1520. __func__, arg->type);
  1521. rc = -ENOTSUPP;
  1522. break;
  1523. }
  1524. return rc;
  1525. }
  1526. int msm_cvp_session_deinit(struct msm_cvp_inst *inst)
  1527. {
  1528. int rc = 0;
  1529. struct cvp_hal_session *session;
  1530. if (!inst || !inst->core) {
  1531. dprintk(CVP_ERR, "%s: invalid params\n", __func__);
  1532. return -EINVAL;
  1533. }
  1534. dprintk(CVP_SESS, "%s: inst %pK (%#x)\n", __func__,
  1535. inst, hash32_ptr(inst->session));
  1536. session = (struct cvp_hal_session *)inst->session;
  1537. if (!session)
  1538. return rc;
  1539. rc = msm_cvp_comm_try_state(inst, MSM_CVP_CLOSE_DONE);
  1540. if (rc)
  1541. dprintk(CVP_ERR, "%s: close failed\n", __func__);
  1542. rc = msm_cvp_session_deinit_buffers(inst);
  1543. return rc;
  1544. }
  1545. int msm_cvp_session_init(struct msm_cvp_inst *inst)
  1546. {
  1547. int rc = 0;
  1548. if (!inst) {
  1549. dprintk(CVP_ERR, "%s: invalid params\n", __func__);
  1550. return -EINVAL;
  1551. }
  1552. dprintk(CVP_SESS, "%s: inst %pK (%#x)\n", __func__,
  1553. inst, hash32_ptr(inst->session));
  1554. /* set default frequency */
  1555. inst->clk_data.core_id = 0;
  1556. inst->clk_data.min_freq = 1000;
  1557. inst->clk_data.ddr_bw = 1000;
  1558. inst->clk_data.sys_cache_bw = 1000;
  1559. inst->prop.type = 1;
  1560. inst->prop.kernel_mask = 0xFFFFFFFF;
  1561. inst->prop.priority = 0;
  1562. inst->prop.is_secure = 0;
  1563. inst->prop.dsp_mask = 0;
  1564. inst->prop.fthread_nr = 3;
  1565. return rc;
  1566. }