sde_vbif.c 20 KB

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