sde_vbif.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
  7. #include <linux/debugfs.h>
  8. #include "sde_vbif.h"
  9. #include "sde_hw_vbif.h"
  10. #include "sde_trace.h"
  11. #include "sde_rotator_vbif.h"
  12. #define MAX_XIN_CLIENT 16
  13. #define VBIF_CLK_CLIENT(x) sde_kms->vbif_clk_clients[x]
  14. #define VBIF_CLK_CLIENT_NAME(x) sde_clk_ctrl_type_s[x]
  15. int sde_vbif_clk_register(struct sde_kms *sde_kms, struct sde_vbif_clk_client *client)
  16. {
  17. enum sde_clk_ctrl_type clk_ctrl;
  18. if (!sde_kms || !client)
  19. return -EINVAL;
  20. clk_ctrl = client->clk_ctrl;
  21. if (!SDE_CLK_CTRL_VALID(clk_ctrl))
  22. return -EINVAL;
  23. VBIF_CLK_CLIENT(clk_ctrl).hw = client->hw;
  24. VBIF_CLK_CLIENT(clk_ctrl).clk_ctrl = clk_ctrl;
  25. memcpy(&VBIF_CLK_CLIENT(clk_ctrl).ops, &client->ops, sizeof(struct sde_vbif_clk_ops));
  26. SDE_DEBUG("registering hw:%pK clk_ctrl:%s\n", client->hw, VBIF_CLK_CLIENT_NAME(clk_ctrl));
  27. return 0;
  28. }
  29. /**
  30. * _sde_vbif_setup_clk_supported - check if VBIF setup_clk_force_ctrl API is supported
  31. * @sde_kms: Pointer to sde_kms object
  32. * @clk_ctrl: clock to be controlled
  33. * @return: true if client is supported, otherwise false
  34. */
  35. static bool _sde_vbif_setup_clk_supported(struct sde_kms *sde_kms, enum sde_clk_ctrl_type clk_ctrl)
  36. {
  37. bool supported = false;
  38. bool has_split_vbif = test_bit(SDE_FEATURE_VBIF_CLK_SPLIT, sde_kms->catalog->features);
  39. if ((has_split_vbif && VBIF_CLK_CLIENT(clk_ctrl).ops.setup_clk_force_ctrl) ||
  40. (!has_split_vbif && sde_kms->hw_mdp->ops.setup_clk_force_ctrl))
  41. supported = true;
  42. SDE_DEBUG("split_vbif:%d type:%s supported:%d\n", has_split_vbif,
  43. VBIF_CLK_CLIENT_NAME(clk_ctrl), supported);
  44. return supported;
  45. }
  46. /**
  47. * _sde_vbif_get_clk_supported - check if VBIF get_clk_ctrl_status API is supported
  48. * @sde_kms: Pointer to sde_kms object
  49. * @clk_ctrl: clock to be controlled
  50. * @return: true if client is supported, otherwise false
  51. */
  52. static bool _sde_vbif_get_clk_supported(struct sde_kms *sde_kms, enum sde_clk_ctrl_type clk_ctrl)
  53. {
  54. bool supported = false;
  55. bool has_split_vbif = test_bit(SDE_FEATURE_VBIF_CLK_SPLIT, sde_kms->catalog->features);
  56. if ((has_split_vbif && VBIF_CLK_CLIENT(clk_ctrl).ops.get_clk_ctrl_status) ||
  57. (!has_split_vbif && sde_kms->hw_mdp->ops.get_clk_ctrl_status))
  58. supported = true;
  59. SDE_DEBUG("split_vbif:%d type:%s supported:%d\n", has_split_vbif,
  60. VBIF_CLK_CLIENT_NAME(clk_ctrl), supported);
  61. return supported;
  62. }
  63. /**
  64. * _sde_vbif_setup_clk_force_ctrl - set clock force control
  65. * @sde_kms: Pointer to sde_kms object
  66. * @clk_ctrl: clock to be controlled
  67. * @enable: force on enable
  68. * @return: if the clock is forced-on by this function
  69. */
  70. static int _sde_vbif_setup_clk_force_ctrl(struct sde_kms *sde_kms, enum sde_clk_ctrl_type clk_ctrl,
  71. bool enable)
  72. {
  73. int rc = 0;
  74. struct sde_hw_blk_reg_map *hw = VBIF_CLK_CLIENT(clk_ctrl).hw;
  75. bool has_split_vbif = test_bit(SDE_FEATURE_VBIF_CLK_SPLIT, sde_kms->catalog->features);
  76. if (has_split_vbif)
  77. rc = VBIF_CLK_CLIENT(clk_ctrl).ops.setup_clk_force_ctrl(hw, clk_ctrl, enable);
  78. else
  79. rc = sde_kms->hw_mdp->ops.setup_clk_force_ctrl(sde_kms->hw_mdp, clk_ctrl, enable);
  80. SDE_DEBUG("split_vbif:%d type:%s en:%d rc:%d\n", has_split_vbif,
  81. VBIF_CLK_CLIENT_NAME(clk_ctrl), enable, rc);
  82. return rc;
  83. }
  84. /**
  85. * _sde_vbif_get_clk_ctrl_status - get clock control status
  86. * @sde_kms: Pointer to sde_kms object
  87. * @clk_ctrl: clock to be controlled
  88. * @status: returns true if clock is on
  89. * @return: 0 if success, otherwise return error code
  90. */
  91. static int _sde_vbif_get_clk_ctrl_status(struct sde_kms *sde_kms, enum sde_clk_ctrl_type clk_ctrl,
  92. bool *status)
  93. {
  94. int rc = 0;
  95. struct sde_hw_blk_reg_map *hw = VBIF_CLK_CLIENT(clk_ctrl).hw;
  96. bool has_split_vbif = test_bit(SDE_FEATURE_VBIF_CLK_SPLIT, sde_kms->catalog->features);
  97. if (has_split_vbif)
  98. rc = VBIF_CLK_CLIENT(clk_ctrl).ops.get_clk_ctrl_status(hw, clk_ctrl, status);
  99. else
  100. rc = sde_kms->hw_mdp->ops.get_clk_ctrl_status(sde_kms->hw_mdp, clk_ctrl, status);
  101. SDE_DEBUG("split_vbif:%d type:%s status:%d rc:%d\n", has_split_vbif,
  102. VBIF_CLK_CLIENT_NAME(clk_ctrl), *status, rc);
  103. return rc;
  104. }
  105. /**
  106. * _sde_vbif_wait_for_xin_halt - wait for the xin to halt
  107. * @vbif: Pointer to hardware vbif driver
  108. * @xin_id: Client interface identifier
  109. * @return: 0 if success; error code otherwise
  110. */
  111. static int _sde_vbif_wait_for_xin_halt(struct sde_hw_vbif *vbif, u32 xin_id)
  112. {
  113. ktime_t timeout;
  114. bool status;
  115. int rc;
  116. if (!vbif || !vbif->cap || !vbif->ops.get_xin_halt_status) {
  117. SDE_ERROR("invalid arguments vbif %d\n", !vbif);
  118. return -EINVAL;
  119. }
  120. timeout = ktime_add_us(ktime_get(), vbif->cap->xin_halt_timeout);
  121. for (;;) {
  122. status = vbif->ops.get_xin_halt_status(vbif, xin_id);
  123. if (status)
  124. break;
  125. if (ktime_compare_safe(ktime_get(), timeout) > 0) {
  126. status = vbif->ops.get_xin_halt_status(vbif, xin_id);
  127. break;
  128. }
  129. usleep_range(501, 1000);
  130. }
  131. if (!status) {
  132. rc = -ETIMEDOUT;
  133. SDE_ERROR("VBIF %d client %d not halting. TIMEDOUT.\n",
  134. vbif->idx - VBIF_0, xin_id);
  135. } else {
  136. rc = 0;
  137. SDE_DEBUG("VBIF %d client %d is halted\n",
  138. vbif->idx - VBIF_0, xin_id);
  139. }
  140. return rc;
  141. }
  142. static int _sde_vbif_wait_for_axi_halt(struct sde_hw_vbif *vbif)
  143. {
  144. int rc;
  145. if (!vbif || !vbif->cap || !vbif->ops.get_axi_halt_status) {
  146. SDE_ERROR("invalid arguments vbif %d\n", !vbif);
  147. return -EINVAL;
  148. }
  149. rc = vbif->ops.get_axi_halt_status(vbif);
  150. if (rc)
  151. SDE_ERROR("VBIF %d AXI port(s) not halting. TIMEDOUT.\n",
  152. vbif->idx - VBIF_0);
  153. else
  154. SDE_DEBUG("VBIF %d AXI port(s) halted\n",
  155. vbif->idx - VBIF_0);
  156. return rc;
  157. }
  158. int sde_vbif_halt_plane_xin(struct sde_kms *sde_kms, u32 xin_id, u32 clk_ctrl)
  159. {
  160. struct sde_hw_vbif *vbif = NULL;
  161. struct sde_hw_mdp *mdp;
  162. bool forced_on = false;
  163. bool status;
  164. int rc = 0;
  165. if (!sde_kms) {
  166. SDE_ERROR("invalid argument\n");
  167. return -EINVAL;
  168. }
  169. if (!sde_kms_is_vbif_operation_allowed(sde_kms)) {
  170. SDE_DEBUG("vbif operations not permitted\n");
  171. return 0;
  172. }
  173. vbif = sde_kms->hw_vbif[VBIF_RT];
  174. mdp = sde_kms->hw_mdp;
  175. if (!vbif || !mdp || !vbif->ops.get_xin_halt_status ||
  176. !vbif->ops.set_xin_halt ||
  177. !_sde_vbif_setup_clk_supported(sde_kms, clk_ctrl)) {
  178. SDE_ERROR("invalid vbif or mdp arguments\n");
  179. return -EINVAL;
  180. }
  181. mutex_lock(&vbif->mutex);
  182. SDE_EVT32_VERBOSE(vbif->idx, xin_id);
  183. /*
  184. * If status is 0, then make sure client clock is not gated
  185. * while halting by forcing it ON only if it was not previously
  186. * forced on. If status is 1 then its already halted.
  187. */
  188. status = vbif->ops.get_xin_halt_status(vbif, xin_id);
  189. if (status) {
  190. mutex_unlock(&vbif->mutex);
  191. return 0;
  192. }
  193. forced_on = _sde_vbif_setup_clk_force_ctrl(sde_kms, clk_ctrl, true);
  194. /* send halt request for unused plane's xin client */
  195. vbif->ops.set_xin_halt(vbif, xin_id, true);
  196. rc = _sde_vbif_wait_for_xin_halt(vbif, xin_id);
  197. if (rc) {
  198. SDE_ERROR(
  199. "wait failed for pipe halt:xin_id %u, clk_ctrl %u, rc %u\n",
  200. xin_id, clk_ctrl, rc);
  201. SDE_EVT32(xin_id, clk_ctrl, rc, SDE_EVTLOG_ERROR);
  202. }
  203. /* open xin client to enable transactions */
  204. vbif->ops.set_xin_halt(vbif, xin_id, false);
  205. if (forced_on)
  206. _sde_vbif_setup_clk_force_ctrl(sde_kms, clk_ctrl, false);
  207. mutex_unlock(&vbif->mutex);
  208. return rc;
  209. }
  210. /**
  211. * _sde_vbif_apply_dynamic_ot_limit - determine OT based on usecase parameters
  212. * @vbif: Pointer to hardware vbif driver
  213. * @ot_lim: Pointer to OT limit to be modified
  214. * @params: Pointer to usecase parameters
  215. */
  216. static void _sde_vbif_apply_dynamic_ot_limit(struct sde_hw_vbif *vbif,
  217. u32 *ot_lim, struct sde_vbif_set_ot_params *params)
  218. {
  219. u64 pps;
  220. const struct sde_vbif_dynamic_ot_tbl *tbl;
  221. u32 i;
  222. if (!vbif || !(vbif->cap->features & BIT(SDE_VBIF_QOS_OTLIM)))
  223. return;
  224. /* Dynamic OT setting done only for WFD */
  225. if (!params->is_wfd)
  226. return;
  227. pps = params->frame_rate;
  228. pps *= params->width;
  229. pps *= params->height;
  230. tbl = params->rd ? &vbif->cap->dynamic_ot_rd_tbl :
  231. &vbif->cap->dynamic_ot_wr_tbl;
  232. for (i = 0; i < tbl->count; i++) {
  233. if (pps <= tbl->cfg[i].pps) {
  234. *ot_lim = tbl->cfg[i].ot_limit;
  235. break;
  236. }
  237. }
  238. SDE_DEBUG("vbif:%d xin:%d w:%d h:%d fps:%d pps:%llu ot:%u\n",
  239. vbif->idx - VBIF_0, params->xin_id,
  240. params->width, params->height, params->frame_rate,
  241. pps, *ot_lim);
  242. }
  243. /**
  244. * _sde_vbif_get_ot_limit - get OT based on usecase & configuration parameters
  245. * @vbif: Pointer to hardware vbif driver
  246. * @params: Pointer to usecase parameters
  247. * @return: OT limit
  248. */
  249. static u32 _sde_vbif_get_ot_limit(struct sde_hw_vbif *vbif,
  250. struct sde_vbif_set_ot_params *params)
  251. {
  252. u32 ot_lim = 0;
  253. u32 val;
  254. if (!vbif || !vbif->cap) {
  255. SDE_ERROR("invalid arguments vbif %d\n", !vbif);
  256. return -EINVAL;
  257. }
  258. if (vbif->cap->default_ot_wr_limit && !params->rd)
  259. ot_lim = vbif->cap->default_ot_wr_limit;
  260. else if (vbif->cap->default_ot_rd_limit && params->rd)
  261. ot_lim = vbif->cap->default_ot_rd_limit;
  262. /*
  263. * If default ot is not set from dt/catalog,
  264. * then do not configure it.
  265. */
  266. if (ot_lim == 0)
  267. goto exit;
  268. /* Modify the limits if the target and the use case requires it */
  269. _sde_vbif_apply_dynamic_ot_limit(vbif, &ot_lim, params);
  270. if (vbif && vbif->ops.get_limit_conf) {
  271. val = vbif->ops.get_limit_conf(vbif,
  272. params->xin_id, params->rd);
  273. if (val == ot_lim)
  274. ot_lim = 0;
  275. }
  276. exit:
  277. SDE_DEBUG("vbif:%d xin:%d ot_lim:%d\n",
  278. vbif->idx - VBIF_0, params->xin_id, ot_lim);
  279. return ot_lim;
  280. }
  281. /**
  282. * sde_vbif_set_ot_limit - set OT based on usecase & configuration parameters
  283. * @vbif: Pointer to hardware vbif driver
  284. * @params: Pointer to usecase parameters
  285. *
  286. * Note this function would block waiting for bus halt.
  287. */
  288. void sde_vbif_set_ot_limit(struct sde_kms *sde_kms,
  289. struct sde_vbif_set_ot_params *params)
  290. {
  291. struct sde_hw_vbif *vbif = NULL;
  292. struct sde_hw_mdp *mdp;
  293. bool forced_on = false;
  294. u32 ot_lim;
  295. int ret, i;
  296. if (!sde_kms) {
  297. SDE_ERROR("invalid arguments\n");
  298. return;
  299. }
  300. if (!sde_kms_is_vbif_operation_allowed(sde_kms)) {
  301. SDE_DEBUG("vbif operations not permitted\n");
  302. return;
  303. }
  304. mdp = sde_kms->hw_mdp;
  305. for (i = 0; i < ARRAY_SIZE(sde_kms->hw_vbif); i++) {
  306. if (sde_kms->hw_vbif[i] &&
  307. sde_kms->hw_vbif[i]->idx == params->vbif_idx) {
  308. vbif = sde_kms->hw_vbif[i];
  309. break;
  310. }
  311. }
  312. if (!vbif || !mdp) {
  313. SDE_DEBUG("invalid arguments vbif %d mdp %d\n",
  314. vbif != NULL, mdp != NULL);
  315. return;
  316. }
  317. if (!_sde_vbif_setup_clk_supported(sde_kms, params->clk_ctrl) ||
  318. !vbif->ops.set_limit_conf ||
  319. !vbif->ops.set_xin_halt)
  320. return;
  321. mutex_lock(&vbif->mutex);
  322. SDE_EVT32_VERBOSE(vbif->idx, params->xin_id);
  323. /* set write_gather_en for all write clients */
  324. if (vbif->ops.set_write_gather_en && !params->rd)
  325. vbif->ops.set_write_gather_en(vbif, params->xin_id);
  326. ot_lim = _sde_vbif_get_ot_limit(vbif, params) & 0xFF;
  327. if (ot_lim == 0)
  328. goto exit;
  329. trace_sde_perf_set_ot(params->num, params->xin_id, ot_lim,
  330. params->vbif_idx);
  331. forced_on = _sde_vbif_setup_clk_force_ctrl(sde_kms, params->clk_ctrl, true);
  332. vbif->ops.set_limit_conf(vbif, params->xin_id, params->rd, ot_lim);
  333. vbif->ops.set_xin_halt(vbif, params->xin_id, true);
  334. ret = _sde_vbif_wait_for_xin_halt(vbif, params->xin_id);
  335. if (ret)
  336. SDE_EVT32(vbif->idx, params->xin_id);
  337. vbif->ops.set_xin_halt(vbif, params->xin_id, false);
  338. if (forced_on)
  339. _sde_vbif_setup_clk_force_ctrl(sde_kms, params->clk_ctrl, false);
  340. exit:
  341. mutex_unlock(&vbif->mutex);
  342. }
  343. void mdp_vbif_lock(struct platform_device *parent_pdev, bool enable)
  344. {
  345. struct drm_device *ddev;
  346. struct sde_kms *sde_kms;
  347. struct sde_hw_vbif *vbif = NULL;
  348. int i;
  349. ddev = platform_get_drvdata(parent_pdev);
  350. if (!ddev || !ddev_to_msm_kms(ddev)) {
  351. SDE_ERROR("invalid drm device\n");
  352. return;
  353. }
  354. sde_kms = to_sde_kms(ddev_to_msm_kms(ddev));
  355. for (i = 0; i < ARRAY_SIZE(sde_kms->hw_vbif); i++) {
  356. if (sde_kms->hw_vbif[i] &&
  357. sde_kms->hw_vbif[i]->idx == VBIF_RT) {
  358. vbif = sde_kms->hw_vbif[i];
  359. break;
  360. }
  361. }
  362. if (!vbif) {
  363. SDE_DEBUG("invalid vbif structure\n");
  364. return;
  365. }
  366. if (enable)
  367. mutex_lock(&vbif->mutex);
  368. else
  369. mutex_unlock(&vbif->mutex);
  370. }
  371. bool sde_vbif_set_xin_halt(struct sde_kms *sde_kms,
  372. struct sde_vbif_set_xin_halt_params *params)
  373. {
  374. struct sde_hw_vbif *vbif = NULL;
  375. struct sde_hw_mdp *mdp;
  376. bool forced_on = false;
  377. int ret, i;
  378. if (!sde_kms || !params) {
  379. SDE_ERROR("invalid arguments\n");
  380. return false;
  381. }
  382. if (!sde_kms_is_vbif_operation_allowed(sde_kms)) {
  383. SDE_DEBUG("vbif operations not permitted\n");
  384. return true;
  385. }
  386. mdp = sde_kms->hw_mdp;
  387. for (i = 0; i < ARRAY_SIZE(sde_kms->hw_vbif); i++) {
  388. if (sde_kms->hw_vbif[i] &&
  389. sde_kms->hw_vbif[i]->idx == params->vbif_idx) {
  390. vbif = sde_kms->hw_vbif[i];
  391. break;
  392. }
  393. }
  394. if (!vbif || !mdp) {
  395. SDE_DEBUG("invalid arguments vbif %d mdp %d\n",
  396. vbif != NULL, mdp != NULL);
  397. return false;
  398. }
  399. if (!_sde_vbif_setup_clk_supported(sde_kms, params->clk_ctrl) ||
  400. !vbif->ops.set_xin_halt)
  401. return false;
  402. mutex_lock(&vbif->mutex);
  403. SDE_EVT32_VERBOSE(vbif->idx, params->xin_id);
  404. if (params->enable) {
  405. forced_on = _sde_vbif_setup_clk_force_ctrl(sde_kms, params->clk_ctrl, true);
  406. vbif->ops.set_xin_halt(vbif, params->xin_id, true);
  407. ret = _sde_vbif_wait_for_xin_halt(vbif, params->xin_id);
  408. if (ret)
  409. SDE_EVT32(vbif->idx, params->xin_id, SDE_EVTLOG_ERROR);
  410. } else {
  411. vbif->ops.set_xin_halt(vbif, params->xin_id, false);
  412. if (params->forced_on)
  413. _sde_vbif_setup_clk_force_ctrl(sde_kms, params->clk_ctrl, false);
  414. }
  415. mutex_unlock(&vbif->mutex);
  416. return forced_on;
  417. }
  418. bool sde_vbif_get_xin_status(struct sde_kms *sde_kms,
  419. struct sde_vbif_get_xin_status_params *params)
  420. {
  421. struct sde_hw_vbif *vbif = NULL;
  422. struct sde_hw_mdp *mdp;
  423. int i, rc;
  424. bool status;
  425. if (!sde_kms || !params) {
  426. SDE_ERROR("invalid arguments\n");
  427. return false;
  428. }
  429. if (!sde_kms_is_vbif_operation_allowed(sde_kms)) {
  430. SDE_DEBUG("vbif operations not permitted\n");
  431. return true;
  432. }
  433. mdp = sde_kms->hw_mdp;
  434. for (i = 0; i < ARRAY_SIZE(sde_kms->hw_vbif); i++) {
  435. if (sde_kms->hw_vbif[i] &&
  436. sde_kms->hw_vbif[i]->idx == params->vbif_idx) {
  437. vbif = sde_kms->hw_vbif[i];
  438. break;
  439. }
  440. }
  441. if (!vbif || !mdp) {
  442. SDE_DEBUG("invalid arguments vbif:%d mdp:%d vbif idx:%d\n",
  443. vbif != NULL, mdp != NULL, params->vbif_idx);
  444. return false;
  445. }
  446. if (!_sde_vbif_get_clk_supported(sde_kms, params->clk_ctrl) ||
  447. !vbif->ops.get_xin_halt_status)
  448. return false;
  449. mutex_lock(&vbif->mutex);
  450. SDE_EVT32_VERBOSE(vbif->idx, params->xin_id);
  451. status = vbif->ops.get_xin_halt_status(vbif, params->xin_id);
  452. if (status) {
  453. rc = _sde_vbif_get_clk_ctrl_status(sde_kms, params->clk_ctrl, &status);
  454. if (rc)
  455. status = false;
  456. }
  457. mutex_unlock(&vbif->mutex);
  458. return status;
  459. }
  460. void sde_vbif_set_qos_remap(struct sde_kms *sde_kms,
  461. struct sde_vbif_set_qos_params *params)
  462. {
  463. struct sde_hw_vbif *vbif = NULL;
  464. struct sde_hw_mdp *mdp;
  465. bool forced_on = false;
  466. const struct sde_vbif_qos_tbl *qos_tbl;
  467. int i;
  468. u32 nlvl;
  469. if (!sde_kms || !params || !sde_kms->hw_mdp) {
  470. SDE_ERROR("invalid arguments\n");
  471. return;
  472. }
  473. if (!sde_kms_is_vbif_operation_allowed(sde_kms)) {
  474. SDE_DEBUG("vbif operations not permitted\n");
  475. return;
  476. }
  477. mdp = sde_kms->hw_mdp;
  478. for (i = 0; i < ARRAY_SIZE(sde_kms->hw_vbif); i++) {
  479. if (sde_kms->hw_vbif[i] &&
  480. sde_kms->hw_vbif[i]->idx == params->vbif_idx) {
  481. vbif = sde_kms->hw_vbif[i];
  482. break;
  483. }
  484. }
  485. if (!vbif || !vbif->cap) {
  486. SDE_ERROR("invalid vbif %d\n", params->vbif_idx);
  487. return;
  488. }
  489. if (!vbif->ops.set_qos_remap || !_sde_vbif_setup_clk_supported(sde_kms, params->clk_ctrl)) {
  490. SDE_DEBUG("qos remap not supported\n");
  491. return;
  492. }
  493. if (params->client_type > VBIF_MAX_CLIENT) {
  494. SDE_ERROR("invalid client type:%d\n", params->client_type);
  495. return;
  496. }
  497. qos_tbl = &vbif->cap->qos_tbl[params->client_type];
  498. if (!qos_tbl->count || !qos_tbl->priority_lvl) {
  499. SDE_DEBUG("qos tbl not defined\n");
  500. return;
  501. }
  502. mutex_lock(&vbif->mutex);
  503. forced_on = _sde_vbif_setup_clk_force_ctrl(sde_kms, params->clk_ctrl, true);
  504. nlvl = qos_tbl->count / 2;
  505. for (i = 0; i < nlvl; i++) {
  506. SDE_DEBUG("vbif:%d xin:%d rp_remap:%d/%d, lv_remap:%d/%d\n",
  507. params->vbif_idx, params->xin_id, i, qos_tbl->priority_lvl[i],
  508. i + nlvl, qos_tbl->priority_lvl[i + nlvl]);
  509. vbif->ops.set_qos_remap(vbif, params->xin_id, i,
  510. qos_tbl->priority_lvl[i], qos_tbl->priority_lvl[i + nlvl]);
  511. }
  512. if (forced_on)
  513. _sde_vbif_setup_clk_force_ctrl(sde_kms, params->clk_ctrl, false);
  514. mutex_unlock(&vbif->mutex);
  515. }
  516. void sde_vbif_clear_errors(struct sde_kms *sde_kms)
  517. {
  518. struct sde_hw_vbif *vbif;
  519. u32 i, pnd, src;
  520. if (!sde_kms) {
  521. SDE_ERROR("invalid argument\n");
  522. return;
  523. }
  524. if (!sde_kms_is_vbif_operation_allowed(sde_kms)) {
  525. SDE_DEBUG("vbif operations not permitted\n");
  526. return;
  527. }
  528. for (i = 0; i < ARRAY_SIZE(sde_kms->hw_vbif); i++) {
  529. vbif = sde_kms->hw_vbif[i];
  530. if (vbif && vbif->ops.clear_errors) {
  531. mutex_lock(&vbif->mutex);
  532. vbif->ops.clear_errors(vbif, &pnd, &src);
  533. if (pnd || src) {
  534. SDE_EVT32(i, pnd, src);
  535. SDE_DEBUG("VBIF %d: pnd 0x%X, src 0x%X\n",
  536. vbif->idx - VBIF_0, pnd, src);
  537. }
  538. mutex_unlock(&vbif->mutex);
  539. }
  540. }
  541. }
  542. void sde_vbif_init_memtypes(struct sde_kms *sde_kms)
  543. {
  544. struct sde_hw_vbif *vbif;
  545. int i, j;
  546. if (!sde_kms) {
  547. SDE_ERROR("invalid argument\n");
  548. return;
  549. }
  550. if (!sde_kms_is_vbif_operation_allowed(sde_kms)) {
  551. SDE_DEBUG("vbif operations not permitted\n");
  552. return;
  553. }
  554. for (i = 0; i < ARRAY_SIZE(sde_kms->hw_vbif); i++) {
  555. vbif = sde_kms->hw_vbif[i];
  556. if (vbif && vbif->cap && vbif->ops.set_mem_type) {
  557. mutex_lock(&vbif->mutex);
  558. for (j = 0; j < vbif->cap->memtype_count; j++)
  559. vbif->ops.set_mem_type(
  560. vbif, j, vbif->cap->memtype[j]);
  561. mutex_unlock(&vbif->mutex);
  562. }
  563. }
  564. }
  565. void sde_vbif_axi_halt_request(struct sde_kms *sde_kms)
  566. {
  567. struct sde_hw_vbif *vbif;
  568. int i;
  569. if (!sde_kms) {
  570. SDE_ERROR("invalid argument\n");
  571. return;
  572. }
  573. if (!sde_kms_is_vbif_operation_allowed(sde_kms)) {
  574. SDE_DEBUG("vbif operations not permitted\n");
  575. return;
  576. }
  577. for (i = 0; i < ARRAY_SIZE(sde_kms->hw_vbif); i++) {
  578. vbif = sde_kms->hw_vbif[i];
  579. if (vbif && vbif->cap && vbif->ops.set_axi_halt) {
  580. mutex_lock(&vbif->mutex);
  581. vbif->ops.set_axi_halt(vbif);
  582. _sde_vbif_wait_for_axi_halt(vbif);
  583. mutex_unlock(&vbif->mutex);
  584. }
  585. }
  586. }
  587. int sde_vbif_halt_xin_mask(struct sde_kms *sde_kms, u32 xin_id_mask,
  588. bool halt)
  589. {
  590. struct sde_hw_vbif *vbif;
  591. int i = 0, status, rc;
  592. if (!sde_kms) {
  593. SDE_ERROR("invalid argument\n");
  594. return -EINVAL;
  595. }
  596. vbif = sde_kms->hw_vbif[VBIF_RT];
  597. if (!vbif->ops.get_xin_halt_status || !vbif->ops.set_xin_halt)
  598. return 0;
  599. SDE_EVT32(xin_id_mask, halt);
  600. for (i = 0; i < MAX_XIN_CLIENT; i++) {
  601. if (xin_id_mask & BIT(i)) {
  602. /* unhalt the xin-clients */
  603. if (!halt) {
  604. vbif->ops.set_xin_halt(vbif, i, false);
  605. continue;
  606. }
  607. status = vbif->ops.get_xin_halt_status(vbif, i);
  608. if (status)
  609. continue;
  610. /* halt xin-clients and wait for ack */
  611. vbif->ops.set_xin_halt(vbif, i, true);
  612. rc = _sde_vbif_wait_for_xin_halt(vbif, i);
  613. if (rc) {
  614. SDE_ERROR("xin_halt failed for xin:%d, rc:%d\n",
  615. i, rc);
  616. SDE_EVT32(xin_id_mask, i, rc, SDE_EVTLOG_ERROR);
  617. return rc;
  618. }
  619. }
  620. }
  621. return 0;
  622. }
  623. #if IS_ENABLED(CONFIG_DEBUG_FS)
  624. void sde_debugfs_vbif_destroy(struct sde_kms *sde_kms)
  625. {
  626. debugfs_remove_recursive(sde_kms->debugfs_vbif);
  627. sde_kms->debugfs_vbif = NULL;
  628. }
  629. int sde_debugfs_vbif_init(struct sde_kms *sde_kms, struct dentry *debugfs_root)
  630. {
  631. char vbif_name[32];
  632. struct dentry *debugfs_vbif;
  633. int i, j;
  634. sde_kms->debugfs_vbif = debugfs_create_dir("vbif", debugfs_root);
  635. if (!sde_kms->debugfs_vbif) {
  636. SDE_ERROR("failed to create vbif debugfs\n");
  637. return -EINVAL;
  638. }
  639. for (i = 0; i < sde_kms->catalog->vbif_count; i++) {
  640. struct sde_vbif_cfg *vbif = &sde_kms->catalog->vbif[i];
  641. snprintf(vbif_name, sizeof(vbif_name), "%d", vbif->id);
  642. debugfs_vbif = debugfs_create_dir(vbif_name,
  643. sde_kms->debugfs_vbif);
  644. debugfs_create_u32("features", 0400, debugfs_vbif,
  645. (u32 *)&vbif->features);
  646. debugfs_create_u32("xin_halt_timeout", 0400, debugfs_vbif,
  647. (u32 *)&vbif->xin_halt_timeout);
  648. debugfs_create_u32("default_rd_ot_limit", 0400, debugfs_vbif,
  649. (u32 *)&vbif->default_ot_rd_limit);
  650. debugfs_create_u32("default_wr_ot_limit", 0400, debugfs_vbif,
  651. (u32 *)&vbif->default_ot_wr_limit);
  652. for (j = 0; j < vbif->dynamic_ot_rd_tbl.count; j++) {
  653. struct sde_vbif_dynamic_ot_cfg *cfg =
  654. &vbif->dynamic_ot_rd_tbl.cfg[j];
  655. snprintf(vbif_name, sizeof(vbif_name),
  656. "dynamic_ot_rd_%d_pps", j);
  657. debugfs_create_u64(vbif_name, 0400, debugfs_vbif,
  658. (u64 *)&cfg->pps);
  659. snprintf(vbif_name, sizeof(vbif_name),
  660. "dynamic_ot_rd_%d_ot_limit", j);
  661. debugfs_create_u32(vbif_name, 0400, debugfs_vbif,
  662. (u32 *)&cfg->ot_limit);
  663. }
  664. for (j = 0; j < vbif->dynamic_ot_wr_tbl.count; j++) {
  665. struct sde_vbif_dynamic_ot_cfg *cfg =
  666. &vbif->dynamic_ot_wr_tbl.cfg[j];
  667. snprintf(vbif_name, sizeof(vbif_name),
  668. "dynamic_ot_wr_%d_pps", j);
  669. debugfs_create_u64(vbif_name, 0400, debugfs_vbif,
  670. (u64 *)&cfg->pps);
  671. snprintf(vbif_name, sizeof(vbif_name),
  672. "dynamic_ot_wr_%d_ot_limit", j);
  673. debugfs_create_u32(vbif_name, 0400, debugfs_vbif,
  674. (u32 *)&cfg->ot_limit);
  675. }
  676. }
  677. return 0;
  678. }
  679. #endif /* CONFIG_DEBUG_FS */