dpu_plane.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630
  1. /*
  2. * Copyright (C) 2014-2018 The Linux Foundation. All rights reserved.
  3. * Copyright (C) 2013 Red Hat
  4. * Author: Rob Clark <robdclark@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
  19. #include <linux/debugfs.h>
  20. #include <linux/dma-buf.h>
  21. #include <drm/drm_atomic_uapi.h>
  22. #include "msm_drv.h"
  23. #include "dpu_kms.h"
  24. #include "dpu_formats.h"
  25. #include "dpu_hw_sspp.h"
  26. #include "dpu_hw_catalog_format.h"
  27. #include "dpu_trace.h"
  28. #include "dpu_crtc.h"
  29. #include "dpu_vbif.h"
  30. #include "dpu_plane.h"
  31. #define DPU_DEBUG_PLANE(pl, fmt, ...) DPU_DEBUG("plane%d " fmt,\
  32. (pl) ? (pl)->base.base.id : -1, ##__VA_ARGS__)
  33. #define DPU_ERROR_PLANE(pl, fmt, ...) DPU_ERROR("plane%d " fmt,\
  34. (pl) ? (pl)->base.base.id : -1, ##__VA_ARGS__)
  35. #define DECIMATED_DIMENSION(dim, deci) (((dim) + ((1 << (deci)) - 1)) >> (deci))
  36. #define PHASE_STEP_SHIFT 21
  37. #define PHASE_STEP_UNIT_SCALE ((int) (1 << PHASE_STEP_SHIFT))
  38. #define PHASE_RESIDUAL 15
  39. #define SHARP_STRENGTH_DEFAULT 32
  40. #define SHARP_EDGE_THR_DEFAULT 112
  41. #define SHARP_SMOOTH_THR_DEFAULT 8
  42. #define SHARP_NOISE_THR_DEFAULT 2
  43. #define DPU_NAME_SIZE 12
  44. #define DPU_PLANE_COLOR_FILL_FLAG BIT(31)
  45. #define DPU_ZPOS_MAX 255
  46. /* multirect rect index */
  47. enum {
  48. R0,
  49. R1,
  50. R_MAX
  51. };
  52. #define DPU_QSEED3_DEFAULT_PRELOAD_H 0x4
  53. #define DPU_QSEED3_DEFAULT_PRELOAD_V 0x3
  54. #define DEFAULT_REFRESH_RATE 60
  55. /**
  56. * enum dpu_plane_qos - Different qos configurations for each pipe
  57. *
  58. * @DPU_PLANE_QOS_VBLANK_CTRL: Setup VBLANK qos for the pipe.
  59. * @DPU_PLANE_QOS_VBLANK_AMORTIZE: Enables Amortization within pipe.
  60. * this configuration is mutually exclusive from VBLANK_CTRL.
  61. * @DPU_PLANE_QOS_PANIC_CTRL: Setup panic for the pipe.
  62. */
  63. enum dpu_plane_qos {
  64. DPU_PLANE_QOS_VBLANK_CTRL = BIT(0),
  65. DPU_PLANE_QOS_VBLANK_AMORTIZE = BIT(1),
  66. DPU_PLANE_QOS_PANIC_CTRL = BIT(2),
  67. };
  68. /*
  69. * struct dpu_plane - local dpu plane structure
  70. * @aspace: address space pointer
  71. * @csc_ptr: Points to dpu_csc_cfg structure to use for current
  72. * @mplane_list: List of multirect planes of the same pipe
  73. * @catalog: Points to dpu catalog structure
  74. * @revalidate: force revalidation of all the plane properties
  75. */
  76. struct dpu_plane {
  77. struct drm_plane base;
  78. struct mutex lock;
  79. enum dpu_sspp pipe;
  80. uint32_t features; /* capabilities from catalog */
  81. uint32_t nformats;
  82. uint32_t formats[64];
  83. struct dpu_hw_pipe *pipe_hw;
  84. struct dpu_hw_pipe_cfg pipe_cfg;
  85. struct dpu_hw_pipe_qos_cfg pipe_qos_cfg;
  86. uint32_t color_fill;
  87. bool is_error;
  88. bool is_rt_pipe;
  89. bool is_virtual;
  90. struct list_head mplane_list;
  91. struct dpu_mdss_cfg *catalog;
  92. struct dpu_csc_cfg *csc_ptr;
  93. const struct dpu_sspp_sub_blks *pipe_sblk;
  94. char pipe_name[DPU_NAME_SIZE];
  95. /* debugfs related stuff */
  96. struct dentry *debugfs_root;
  97. struct dpu_debugfs_regset32 debugfs_src;
  98. struct dpu_debugfs_regset32 debugfs_scaler;
  99. struct dpu_debugfs_regset32 debugfs_csc;
  100. bool debugfs_default_scale;
  101. };
  102. #define to_dpu_plane(x) container_of(x, struct dpu_plane, base)
  103. static struct dpu_kms *_dpu_plane_get_kms(struct drm_plane *plane)
  104. {
  105. struct msm_drm_private *priv = plane->dev->dev_private;
  106. return to_dpu_kms(priv->kms);
  107. }
  108. /**
  109. * _dpu_plane_calc_fill_level - calculate fill level of the given source format
  110. * @plane: Pointer to drm plane
  111. * @fmt: Pointer to source buffer format
  112. * @src_wdith: width of source buffer
  113. * Return: fill level corresponding to the source buffer/format or 0 if error
  114. */
  115. static inline int _dpu_plane_calc_fill_level(struct drm_plane *plane,
  116. const struct dpu_format *fmt, u32 src_width)
  117. {
  118. struct dpu_plane *pdpu, *tmp;
  119. struct dpu_plane_state *pstate;
  120. u32 fixed_buff_size;
  121. u32 total_fl;
  122. if (!fmt || !plane->state || !src_width || !fmt->bpp) {
  123. DPU_ERROR("invalid arguments\n");
  124. return 0;
  125. }
  126. pdpu = to_dpu_plane(plane);
  127. pstate = to_dpu_plane_state(plane->state);
  128. fixed_buff_size = pdpu->pipe_sblk->common->pixel_ram_size;
  129. list_for_each_entry(tmp, &pdpu->mplane_list, mplane_list) {
  130. if (!tmp->base.state->visible)
  131. continue;
  132. DPU_DEBUG("plane%d/%d src_width:%d/%d\n",
  133. pdpu->base.base.id, tmp->base.base.id,
  134. src_width,
  135. drm_rect_width(&tmp->pipe_cfg.src_rect));
  136. src_width = max_t(u32, src_width,
  137. drm_rect_width(&tmp->pipe_cfg.src_rect));
  138. }
  139. if (fmt->fetch_planes == DPU_PLANE_PSEUDO_PLANAR) {
  140. if (fmt->chroma_sample == DPU_CHROMA_420) {
  141. /* NV12 */
  142. total_fl = (fixed_buff_size / 2) /
  143. ((src_width + 32) * fmt->bpp);
  144. } else {
  145. /* non NV12 */
  146. total_fl = (fixed_buff_size / 2) * 2 /
  147. ((src_width + 32) * fmt->bpp);
  148. }
  149. } else {
  150. if (pstate->multirect_mode == DPU_SSPP_MULTIRECT_PARALLEL) {
  151. total_fl = (fixed_buff_size / 2) * 2 /
  152. ((src_width + 32) * fmt->bpp);
  153. } else {
  154. total_fl = (fixed_buff_size) * 2 /
  155. ((src_width + 32) * fmt->bpp);
  156. }
  157. }
  158. DPU_DEBUG("plane%u: pnum:%d fmt: %4.4s w:%u fl:%u\n",
  159. plane->base.id, pdpu->pipe - SSPP_VIG0,
  160. (char *)&fmt->base.pixel_format,
  161. src_width, total_fl);
  162. return total_fl;
  163. }
  164. /**
  165. * _dpu_plane_get_qos_lut - get LUT mapping based on fill level
  166. * @tbl: Pointer to LUT table
  167. * @total_fl: fill level
  168. * Return: LUT setting corresponding to the fill level
  169. */
  170. static u64 _dpu_plane_get_qos_lut(const struct dpu_qos_lut_tbl *tbl,
  171. u32 total_fl)
  172. {
  173. int i;
  174. if (!tbl || !tbl->nentry || !tbl->entries)
  175. return 0;
  176. for (i = 0; i < tbl->nentry; i++)
  177. if (total_fl <= tbl->entries[i].fl)
  178. return tbl->entries[i].lut;
  179. /* if last fl is zero, use as default */
  180. if (!tbl->entries[i-1].fl)
  181. return tbl->entries[i-1].lut;
  182. return 0;
  183. }
  184. /**
  185. * _dpu_plane_set_qos_lut - set QoS LUT of the given plane
  186. * @plane: Pointer to drm plane
  187. * @fb: Pointer to framebuffer associated with the given plane
  188. */
  189. static void _dpu_plane_set_qos_lut(struct drm_plane *plane,
  190. struct drm_framebuffer *fb)
  191. {
  192. struct dpu_plane *pdpu = to_dpu_plane(plane);
  193. const struct dpu_format *fmt = NULL;
  194. u64 qos_lut;
  195. u32 total_fl = 0, lut_usage;
  196. if (!pdpu->is_rt_pipe) {
  197. lut_usage = DPU_QOS_LUT_USAGE_NRT;
  198. } else {
  199. fmt = dpu_get_dpu_format_ext(
  200. fb->format->format,
  201. fb->modifier);
  202. total_fl = _dpu_plane_calc_fill_level(plane, fmt,
  203. drm_rect_width(&pdpu->pipe_cfg.src_rect));
  204. if (fmt && DPU_FORMAT_IS_LINEAR(fmt))
  205. lut_usage = DPU_QOS_LUT_USAGE_LINEAR;
  206. else
  207. lut_usage = DPU_QOS_LUT_USAGE_MACROTILE;
  208. }
  209. qos_lut = _dpu_plane_get_qos_lut(
  210. &pdpu->catalog->perf.qos_lut_tbl[lut_usage], total_fl);
  211. pdpu->pipe_qos_cfg.creq_lut = qos_lut;
  212. trace_dpu_perf_set_qos_luts(pdpu->pipe - SSPP_VIG0,
  213. (fmt) ? fmt->base.pixel_format : 0,
  214. pdpu->is_rt_pipe, total_fl, qos_lut, lut_usage);
  215. DPU_DEBUG("plane%u: pnum:%d fmt: %4.4s rt:%d fl:%u lut:0x%llx\n",
  216. plane->base.id,
  217. pdpu->pipe - SSPP_VIG0,
  218. fmt ? (char *)&fmt->base.pixel_format : NULL,
  219. pdpu->is_rt_pipe, total_fl, qos_lut);
  220. pdpu->pipe_hw->ops.setup_creq_lut(pdpu->pipe_hw, &pdpu->pipe_qos_cfg);
  221. }
  222. /**
  223. * _dpu_plane_set_panic_lut - set danger/safe LUT of the given plane
  224. * @plane: Pointer to drm plane
  225. * @fb: Pointer to framebuffer associated with the given plane
  226. */
  227. static void _dpu_plane_set_danger_lut(struct drm_plane *plane,
  228. struct drm_framebuffer *fb)
  229. {
  230. struct dpu_plane *pdpu = to_dpu_plane(plane);
  231. const struct dpu_format *fmt = NULL;
  232. u32 danger_lut, safe_lut;
  233. if (!pdpu->is_rt_pipe) {
  234. danger_lut = pdpu->catalog->perf.danger_lut_tbl
  235. [DPU_QOS_LUT_USAGE_NRT];
  236. safe_lut = pdpu->catalog->perf.safe_lut_tbl
  237. [DPU_QOS_LUT_USAGE_NRT];
  238. } else {
  239. fmt = dpu_get_dpu_format_ext(
  240. fb->format->format,
  241. fb->modifier);
  242. if (fmt && DPU_FORMAT_IS_LINEAR(fmt)) {
  243. danger_lut = pdpu->catalog->perf.danger_lut_tbl
  244. [DPU_QOS_LUT_USAGE_LINEAR];
  245. safe_lut = pdpu->catalog->perf.safe_lut_tbl
  246. [DPU_QOS_LUT_USAGE_LINEAR];
  247. } else {
  248. danger_lut = pdpu->catalog->perf.danger_lut_tbl
  249. [DPU_QOS_LUT_USAGE_MACROTILE];
  250. safe_lut = pdpu->catalog->perf.safe_lut_tbl
  251. [DPU_QOS_LUT_USAGE_MACROTILE];
  252. }
  253. }
  254. pdpu->pipe_qos_cfg.danger_lut = danger_lut;
  255. pdpu->pipe_qos_cfg.safe_lut = safe_lut;
  256. trace_dpu_perf_set_danger_luts(pdpu->pipe - SSPP_VIG0,
  257. (fmt) ? fmt->base.pixel_format : 0,
  258. (fmt) ? fmt->fetch_mode : 0,
  259. pdpu->pipe_qos_cfg.danger_lut,
  260. pdpu->pipe_qos_cfg.safe_lut);
  261. DPU_DEBUG("plane%u: pnum:%d fmt: %4.4s mode:%d luts[0x%x, 0x%x]\n",
  262. plane->base.id,
  263. pdpu->pipe - SSPP_VIG0,
  264. fmt ? (char *)&fmt->base.pixel_format : NULL,
  265. fmt ? fmt->fetch_mode : -1,
  266. pdpu->pipe_qos_cfg.danger_lut,
  267. pdpu->pipe_qos_cfg.safe_lut);
  268. pdpu->pipe_hw->ops.setup_danger_safe_lut(pdpu->pipe_hw,
  269. &pdpu->pipe_qos_cfg);
  270. }
  271. /**
  272. * _dpu_plane_set_qos_ctrl - set QoS control of the given plane
  273. * @plane: Pointer to drm plane
  274. * @enable: true to enable QoS control
  275. * @flags: QoS control mode (enum dpu_plane_qos)
  276. */
  277. static void _dpu_plane_set_qos_ctrl(struct drm_plane *plane,
  278. bool enable, u32 flags)
  279. {
  280. struct dpu_plane *pdpu = to_dpu_plane(plane);
  281. if (flags & DPU_PLANE_QOS_VBLANK_CTRL) {
  282. pdpu->pipe_qos_cfg.creq_vblank = pdpu->pipe_sblk->creq_vblank;
  283. pdpu->pipe_qos_cfg.danger_vblank =
  284. pdpu->pipe_sblk->danger_vblank;
  285. pdpu->pipe_qos_cfg.vblank_en = enable;
  286. }
  287. if (flags & DPU_PLANE_QOS_VBLANK_AMORTIZE) {
  288. /* this feature overrules previous VBLANK_CTRL */
  289. pdpu->pipe_qos_cfg.vblank_en = false;
  290. pdpu->pipe_qos_cfg.creq_vblank = 0; /* clear vblank bits */
  291. }
  292. if (flags & DPU_PLANE_QOS_PANIC_CTRL)
  293. pdpu->pipe_qos_cfg.danger_safe_en = enable;
  294. if (!pdpu->is_rt_pipe) {
  295. pdpu->pipe_qos_cfg.vblank_en = false;
  296. pdpu->pipe_qos_cfg.danger_safe_en = false;
  297. }
  298. DPU_DEBUG("plane%u: pnum:%d ds:%d vb:%d pri[0x%x, 0x%x] is_rt:%d\n",
  299. plane->base.id,
  300. pdpu->pipe - SSPP_VIG0,
  301. pdpu->pipe_qos_cfg.danger_safe_en,
  302. pdpu->pipe_qos_cfg.vblank_en,
  303. pdpu->pipe_qos_cfg.creq_vblank,
  304. pdpu->pipe_qos_cfg.danger_vblank,
  305. pdpu->is_rt_pipe);
  306. pdpu->pipe_hw->ops.setup_qos_ctrl(pdpu->pipe_hw,
  307. &pdpu->pipe_qos_cfg);
  308. }
  309. static void dpu_plane_danger_signal_ctrl(struct drm_plane *plane, bool enable)
  310. {
  311. struct dpu_plane *pdpu = to_dpu_plane(plane);
  312. struct dpu_kms *dpu_kms = _dpu_plane_get_kms(plane);
  313. if (!pdpu->is_rt_pipe)
  314. return;
  315. pm_runtime_get_sync(&dpu_kms->pdev->dev);
  316. _dpu_plane_set_qos_ctrl(plane, enable, DPU_PLANE_QOS_PANIC_CTRL);
  317. pm_runtime_put_sync(&dpu_kms->pdev->dev);
  318. }
  319. /**
  320. * _dpu_plane_set_ot_limit - set OT limit for the given plane
  321. * @plane: Pointer to drm plane
  322. * @crtc: Pointer to drm crtc
  323. */
  324. static void _dpu_plane_set_ot_limit(struct drm_plane *plane,
  325. struct drm_crtc *crtc)
  326. {
  327. struct dpu_plane *pdpu = to_dpu_plane(plane);
  328. struct dpu_vbif_set_ot_params ot_params;
  329. struct dpu_kms *dpu_kms = _dpu_plane_get_kms(plane);
  330. memset(&ot_params, 0, sizeof(ot_params));
  331. ot_params.xin_id = pdpu->pipe_hw->cap->xin_id;
  332. ot_params.num = pdpu->pipe_hw->idx - SSPP_NONE;
  333. ot_params.width = drm_rect_width(&pdpu->pipe_cfg.src_rect);
  334. ot_params.height = drm_rect_height(&pdpu->pipe_cfg.src_rect);
  335. ot_params.is_wfd = !pdpu->is_rt_pipe;
  336. ot_params.frame_rate = crtc->mode.vrefresh;
  337. ot_params.vbif_idx = VBIF_RT;
  338. ot_params.clk_ctrl = pdpu->pipe_hw->cap->clk_ctrl;
  339. ot_params.rd = true;
  340. dpu_vbif_set_ot_limit(dpu_kms, &ot_params);
  341. }
  342. /**
  343. * _dpu_plane_set_vbif_qos - set vbif QoS for the given plane
  344. * @plane: Pointer to drm plane
  345. */
  346. static void _dpu_plane_set_qos_remap(struct drm_plane *plane)
  347. {
  348. struct dpu_plane *pdpu = to_dpu_plane(plane);
  349. struct dpu_vbif_set_qos_params qos_params;
  350. struct dpu_kms *dpu_kms = _dpu_plane_get_kms(plane);
  351. memset(&qos_params, 0, sizeof(qos_params));
  352. qos_params.vbif_idx = VBIF_RT;
  353. qos_params.clk_ctrl = pdpu->pipe_hw->cap->clk_ctrl;
  354. qos_params.xin_id = pdpu->pipe_hw->cap->xin_id;
  355. qos_params.num = pdpu->pipe_hw->idx - SSPP_VIG0;
  356. qos_params.is_rt = pdpu->is_rt_pipe;
  357. DPU_DEBUG("plane%d pipe:%d vbif:%d xin:%d rt:%d, clk_ctrl:%d\n",
  358. plane->base.id, qos_params.num,
  359. qos_params.vbif_idx,
  360. qos_params.xin_id, qos_params.is_rt,
  361. qos_params.clk_ctrl);
  362. dpu_vbif_set_qos_remap(dpu_kms, &qos_params);
  363. }
  364. /**
  365. * _dpu_plane_get_aspace: gets the address space
  366. */
  367. static inline struct msm_gem_address_space *_dpu_plane_get_aspace(
  368. struct dpu_plane *pdpu)
  369. {
  370. struct dpu_kms *kms = _dpu_plane_get_kms(&pdpu->base);
  371. return kms->base.aspace;
  372. }
  373. static inline void _dpu_plane_set_scanout(struct drm_plane *plane,
  374. struct dpu_plane_state *pstate,
  375. struct dpu_hw_pipe_cfg *pipe_cfg,
  376. struct drm_framebuffer *fb)
  377. {
  378. struct dpu_plane *pdpu = to_dpu_plane(plane);
  379. struct msm_gem_address_space *aspace = _dpu_plane_get_aspace(pdpu);
  380. int ret;
  381. ret = dpu_format_populate_layout(aspace, fb, &pipe_cfg->layout);
  382. if (ret == -EAGAIN)
  383. DPU_DEBUG_PLANE(pdpu, "not updating same src addrs\n");
  384. else if (ret)
  385. DPU_ERROR_PLANE(pdpu, "failed to get format layout, %d\n", ret);
  386. else if (pdpu->pipe_hw->ops.setup_sourceaddress) {
  387. trace_dpu_plane_set_scanout(pdpu->pipe_hw->idx,
  388. &pipe_cfg->layout,
  389. pstate->multirect_index);
  390. pdpu->pipe_hw->ops.setup_sourceaddress(pdpu->pipe_hw, pipe_cfg,
  391. pstate->multirect_index);
  392. }
  393. }
  394. static void _dpu_plane_setup_scaler3(struct dpu_plane *pdpu,
  395. struct dpu_plane_state *pstate,
  396. uint32_t src_w, uint32_t src_h, uint32_t dst_w, uint32_t dst_h,
  397. struct dpu_hw_scaler3_cfg *scale_cfg,
  398. const struct dpu_format *fmt,
  399. uint32_t chroma_subsmpl_h, uint32_t chroma_subsmpl_v)
  400. {
  401. uint32_t i;
  402. memset(scale_cfg, 0, sizeof(*scale_cfg));
  403. memset(&pstate->pixel_ext, 0, sizeof(struct dpu_hw_pixel_ext));
  404. scale_cfg->phase_step_x[DPU_SSPP_COMP_0] =
  405. mult_frac((1 << PHASE_STEP_SHIFT), src_w, dst_w);
  406. scale_cfg->phase_step_y[DPU_SSPP_COMP_0] =
  407. mult_frac((1 << PHASE_STEP_SHIFT), src_h, dst_h);
  408. scale_cfg->phase_step_y[DPU_SSPP_COMP_1_2] =
  409. scale_cfg->phase_step_y[DPU_SSPP_COMP_0] / chroma_subsmpl_v;
  410. scale_cfg->phase_step_x[DPU_SSPP_COMP_1_2] =
  411. scale_cfg->phase_step_x[DPU_SSPP_COMP_0] / chroma_subsmpl_h;
  412. scale_cfg->phase_step_x[DPU_SSPP_COMP_2] =
  413. scale_cfg->phase_step_x[DPU_SSPP_COMP_1_2];
  414. scale_cfg->phase_step_y[DPU_SSPP_COMP_2] =
  415. scale_cfg->phase_step_y[DPU_SSPP_COMP_1_2];
  416. scale_cfg->phase_step_x[DPU_SSPP_COMP_3] =
  417. scale_cfg->phase_step_x[DPU_SSPP_COMP_0];
  418. scale_cfg->phase_step_y[DPU_SSPP_COMP_3] =
  419. scale_cfg->phase_step_y[DPU_SSPP_COMP_0];
  420. for (i = 0; i < DPU_MAX_PLANES; i++) {
  421. scale_cfg->src_width[i] = src_w;
  422. scale_cfg->src_height[i] = src_h;
  423. if (i == DPU_SSPP_COMP_1_2 || i == DPU_SSPP_COMP_2) {
  424. scale_cfg->src_width[i] /= chroma_subsmpl_h;
  425. scale_cfg->src_height[i] /= chroma_subsmpl_v;
  426. }
  427. scale_cfg->preload_x[i] = DPU_QSEED3_DEFAULT_PRELOAD_H;
  428. scale_cfg->preload_y[i] = DPU_QSEED3_DEFAULT_PRELOAD_V;
  429. pstate->pixel_ext.num_ext_pxls_top[i] =
  430. scale_cfg->src_height[i];
  431. pstate->pixel_ext.num_ext_pxls_left[i] =
  432. scale_cfg->src_width[i];
  433. }
  434. if (!(DPU_FORMAT_IS_YUV(fmt)) && (src_h == dst_h)
  435. && (src_w == dst_w))
  436. return;
  437. scale_cfg->dst_width = dst_w;
  438. scale_cfg->dst_height = dst_h;
  439. scale_cfg->y_rgb_filter_cfg = DPU_SCALE_BIL;
  440. scale_cfg->uv_filter_cfg = DPU_SCALE_BIL;
  441. scale_cfg->alpha_filter_cfg = DPU_SCALE_ALPHA_BIL;
  442. scale_cfg->lut_flag = 0;
  443. scale_cfg->blend_cfg = 1;
  444. scale_cfg->enable = 1;
  445. }
  446. static inline void _dpu_plane_setup_csc(struct dpu_plane *pdpu)
  447. {
  448. static const struct dpu_csc_cfg dpu_csc_YUV2RGB_601L = {
  449. {
  450. /* S15.16 format */
  451. 0x00012A00, 0x00000000, 0x00019880,
  452. 0x00012A00, 0xFFFF9B80, 0xFFFF3000,
  453. 0x00012A00, 0x00020480, 0x00000000,
  454. },
  455. /* signed bias */
  456. { 0xfff0, 0xff80, 0xff80,},
  457. { 0x0, 0x0, 0x0,},
  458. /* unsigned clamp */
  459. { 0x10, 0xeb, 0x10, 0xf0, 0x10, 0xf0,},
  460. { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,},
  461. };
  462. static const struct dpu_csc_cfg dpu_csc10_YUV2RGB_601L = {
  463. {
  464. /* S15.16 format */
  465. 0x00012A00, 0x00000000, 0x00019880,
  466. 0x00012A00, 0xFFFF9B80, 0xFFFF3000,
  467. 0x00012A00, 0x00020480, 0x00000000,
  468. },
  469. /* signed bias */
  470. { 0xffc0, 0xfe00, 0xfe00,},
  471. { 0x0, 0x0, 0x0,},
  472. /* unsigned clamp */
  473. { 0x40, 0x3ac, 0x40, 0x3c0, 0x40, 0x3c0,},
  474. { 0x00, 0x3ff, 0x00, 0x3ff, 0x00, 0x3ff,},
  475. };
  476. if (!pdpu) {
  477. DPU_ERROR("invalid plane\n");
  478. return;
  479. }
  480. if (BIT(DPU_SSPP_CSC_10BIT) & pdpu->features)
  481. pdpu->csc_ptr = (struct dpu_csc_cfg *)&dpu_csc10_YUV2RGB_601L;
  482. else
  483. pdpu->csc_ptr = (struct dpu_csc_cfg *)&dpu_csc_YUV2RGB_601L;
  484. DPU_DEBUG_PLANE(pdpu, "using 0x%X 0x%X 0x%X...\n",
  485. pdpu->csc_ptr->csc_mv[0],
  486. pdpu->csc_ptr->csc_mv[1],
  487. pdpu->csc_ptr->csc_mv[2]);
  488. }
  489. static void _dpu_plane_setup_scaler(struct dpu_plane *pdpu,
  490. struct dpu_plane_state *pstate,
  491. const struct dpu_format *fmt, bool color_fill)
  492. {
  493. uint32_t chroma_subsmpl_h, chroma_subsmpl_v;
  494. /* don't chroma subsample if decimating */
  495. chroma_subsmpl_h =
  496. drm_format_horz_chroma_subsampling(fmt->base.pixel_format);
  497. chroma_subsmpl_v =
  498. drm_format_vert_chroma_subsampling(fmt->base.pixel_format);
  499. /* update scaler. calculate default config for QSEED3 */
  500. _dpu_plane_setup_scaler3(pdpu, pstate,
  501. drm_rect_width(&pdpu->pipe_cfg.src_rect),
  502. drm_rect_height(&pdpu->pipe_cfg.src_rect),
  503. drm_rect_width(&pdpu->pipe_cfg.dst_rect),
  504. drm_rect_height(&pdpu->pipe_cfg.dst_rect),
  505. &pstate->scaler3_cfg, fmt,
  506. chroma_subsmpl_h, chroma_subsmpl_v);
  507. }
  508. /**
  509. * _dpu_plane_color_fill - enables color fill on plane
  510. * @pdpu: Pointer to DPU plane object
  511. * @color: RGB fill color value, [23..16] Blue, [15..8] Green, [7..0] Red
  512. * @alpha: 8-bit fill alpha value, 255 selects 100% alpha
  513. * Returns: 0 on success
  514. */
  515. static int _dpu_plane_color_fill(struct dpu_plane *pdpu,
  516. uint32_t color, uint32_t alpha)
  517. {
  518. const struct dpu_format *fmt;
  519. const struct drm_plane *plane = &pdpu->base;
  520. struct dpu_plane_state *pstate = to_dpu_plane_state(plane->state);
  521. DPU_DEBUG_PLANE(pdpu, "\n");
  522. /*
  523. * select fill format to match user property expectation,
  524. * h/w only supports RGB variants
  525. */
  526. fmt = dpu_get_dpu_format(DRM_FORMAT_ABGR8888);
  527. /* update sspp */
  528. if (fmt && pdpu->pipe_hw->ops.setup_solidfill) {
  529. pdpu->pipe_hw->ops.setup_solidfill(pdpu->pipe_hw,
  530. (color & 0xFFFFFF) | ((alpha & 0xFF) << 24),
  531. pstate->multirect_index);
  532. /* override scaler/decimation if solid fill */
  533. pdpu->pipe_cfg.src_rect.x1 = 0;
  534. pdpu->pipe_cfg.src_rect.y1 = 0;
  535. pdpu->pipe_cfg.src_rect.x2 =
  536. drm_rect_width(&pdpu->pipe_cfg.dst_rect);
  537. pdpu->pipe_cfg.src_rect.y2 =
  538. drm_rect_height(&pdpu->pipe_cfg.dst_rect);
  539. _dpu_plane_setup_scaler(pdpu, pstate, fmt, true);
  540. if (pdpu->pipe_hw->ops.setup_format)
  541. pdpu->pipe_hw->ops.setup_format(pdpu->pipe_hw,
  542. fmt, DPU_SSPP_SOLID_FILL,
  543. pstate->multirect_index);
  544. if (pdpu->pipe_hw->ops.setup_rects)
  545. pdpu->pipe_hw->ops.setup_rects(pdpu->pipe_hw,
  546. &pdpu->pipe_cfg,
  547. pstate->multirect_index);
  548. if (pdpu->pipe_hw->ops.setup_pe)
  549. pdpu->pipe_hw->ops.setup_pe(pdpu->pipe_hw,
  550. &pstate->pixel_ext);
  551. if (pdpu->pipe_hw->ops.setup_scaler &&
  552. pstate->multirect_index != DPU_SSPP_RECT_1)
  553. pdpu->pipe_hw->ops.setup_scaler(pdpu->pipe_hw,
  554. &pdpu->pipe_cfg, &pstate->pixel_ext,
  555. &pstate->scaler3_cfg);
  556. }
  557. return 0;
  558. }
  559. void dpu_plane_clear_multirect(const struct drm_plane_state *drm_state)
  560. {
  561. struct dpu_plane_state *pstate = to_dpu_plane_state(drm_state);
  562. pstate->multirect_index = DPU_SSPP_RECT_SOLO;
  563. pstate->multirect_mode = DPU_SSPP_MULTIRECT_NONE;
  564. }
  565. int dpu_plane_validate_multirect_v2(struct dpu_multirect_plane_states *plane)
  566. {
  567. struct dpu_plane_state *pstate[R_MAX];
  568. const struct drm_plane_state *drm_state[R_MAX];
  569. struct drm_rect src[R_MAX], dst[R_MAX];
  570. struct dpu_plane *dpu_plane[R_MAX];
  571. const struct dpu_format *fmt[R_MAX];
  572. int i, buffer_lines;
  573. unsigned int max_tile_height = 1;
  574. bool parallel_fetch_qualified = true;
  575. bool has_tiled_rect = false;
  576. for (i = 0; i < R_MAX; i++) {
  577. const struct msm_format *msm_fmt;
  578. drm_state[i] = i ? plane->r1 : plane->r0;
  579. msm_fmt = msm_framebuffer_format(drm_state[i]->fb);
  580. fmt[i] = to_dpu_format(msm_fmt);
  581. if (DPU_FORMAT_IS_UBWC(fmt[i])) {
  582. has_tiled_rect = true;
  583. if (fmt[i]->tile_height > max_tile_height)
  584. max_tile_height = fmt[i]->tile_height;
  585. }
  586. }
  587. for (i = 0; i < R_MAX; i++) {
  588. int width_threshold;
  589. pstate[i] = to_dpu_plane_state(drm_state[i]);
  590. dpu_plane[i] = to_dpu_plane(drm_state[i]->plane);
  591. if (pstate[i] == NULL) {
  592. DPU_ERROR("DPU plane state of plane id %d is NULL\n",
  593. drm_state[i]->plane->base.id);
  594. return -EINVAL;
  595. }
  596. src[i].x1 = drm_state[i]->src_x >> 16;
  597. src[i].y1 = drm_state[i]->src_y >> 16;
  598. src[i].x2 = src[i].x1 + (drm_state[i]->src_w >> 16);
  599. src[i].y2 = src[i].y1 + (drm_state[i]->src_h >> 16);
  600. dst[i] = drm_plane_state_dest(drm_state[i]);
  601. if (drm_rect_calc_hscale(&src[i], &dst[i], 1, 1) != 1 ||
  602. drm_rect_calc_vscale(&src[i], &dst[i], 1, 1) != 1) {
  603. DPU_ERROR_PLANE(dpu_plane[i],
  604. "scaling is not supported in multirect mode\n");
  605. return -EINVAL;
  606. }
  607. if (DPU_FORMAT_IS_YUV(fmt[i])) {
  608. DPU_ERROR_PLANE(dpu_plane[i],
  609. "Unsupported format for multirect mode\n");
  610. return -EINVAL;
  611. }
  612. /**
  613. * SSPP PD_MEM is split half - one for each RECT.
  614. * Tiled formats need 5 lines of buffering while fetching
  615. * whereas linear formats need only 2 lines.
  616. * So we cannot support more than half of the supported SSPP
  617. * width for tiled formats.
  618. */
  619. width_threshold = dpu_plane[i]->pipe_sblk->common->maxlinewidth;
  620. if (has_tiled_rect)
  621. width_threshold /= 2;
  622. if (parallel_fetch_qualified &&
  623. drm_rect_width(&src[i]) > width_threshold)
  624. parallel_fetch_qualified = false;
  625. }
  626. /* Validate RECT's and set the mode */
  627. /* Prefer PARALLEL FETCH Mode over TIME_MX Mode */
  628. if (parallel_fetch_qualified) {
  629. pstate[R0]->multirect_mode = DPU_SSPP_MULTIRECT_PARALLEL;
  630. pstate[R1]->multirect_mode = DPU_SSPP_MULTIRECT_PARALLEL;
  631. goto done;
  632. }
  633. /* TIME_MX Mode */
  634. buffer_lines = 2 * max_tile_height;
  635. if (dst[R1].y1 >= dst[R0].y2 + buffer_lines ||
  636. dst[R0].y1 >= dst[R1].y2 + buffer_lines) {
  637. pstate[R0]->multirect_mode = DPU_SSPP_MULTIRECT_TIME_MX;
  638. pstate[R1]->multirect_mode = DPU_SSPP_MULTIRECT_TIME_MX;
  639. } else {
  640. DPU_ERROR(
  641. "No multirect mode possible for the planes (%d - %d)\n",
  642. drm_state[R0]->plane->base.id,
  643. drm_state[R1]->plane->base.id);
  644. return -EINVAL;
  645. }
  646. done:
  647. if (dpu_plane[R0]->is_virtual) {
  648. pstate[R0]->multirect_index = DPU_SSPP_RECT_1;
  649. pstate[R1]->multirect_index = DPU_SSPP_RECT_0;
  650. } else {
  651. pstate[R0]->multirect_index = DPU_SSPP_RECT_0;
  652. pstate[R1]->multirect_index = DPU_SSPP_RECT_1;
  653. };
  654. DPU_DEBUG_PLANE(dpu_plane[R0], "R0: %d - %d\n",
  655. pstate[R0]->multirect_mode, pstate[R0]->multirect_index);
  656. DPU_DEBUG_PLANE(dpu_plane[R1], "R1: %d - %d\n",
  657. pstate[R1]->multirect_mode, pstate[R1]->multirect_index);
  658. return 0;
  659. }
  660. /**
  661. * dpu_plane_get_ctl_flush - get control flush for the given plane
  662. * @plane: Pointer to drm plane structure
  663. * @ctl: Pointer to hardware control driver
  664. * @flush_sspp: Pointer to sspp flush control word
  665. */
  666. void dpu_plane_get_ctl_flush(struct drm_plane *plane, struct dpu_hw_ctl *ctl,
  667. u32 *flush_sspp)
  668. {
  669. *flush_sspp = ctl->ops.get_bitmask_sspp(ctl, dpu_plane_pipe(plane));
  670. }
  671. static int dpu_plane_prepare_fb(struct drm_plane *plane,
  672. struct drm_plane_state *new_state)
  673. {
  674. struct drm_framebuffer *fb = new_state->fb;
  675. struct dpu_plane *pdpu = to_dpu_plane(plane);
  676. struct dpu_plane_state *pstate = to_dpu_plane_state(new_state);
  677. struct dpu_hw_fmt_layout layout;
  678. struct drm_gem_object *obj;
  679. struct msm_gem_object *msm_obj;
  680. struct dma_fence *fence;
  681. struct msm_gem_address_space *aspace = _dpu_plane_get_aspace(pdpu);
  682. int ret;
  683. if (!new_state->fb)
  684. return 0;
  685. DPU_DEBUG_PLANE(pdpu, "FB[%u]\n", fb->base.id);
  686. /* cache aspace */
  687. pstate->aspace = aspace;
  688. /*
  689. * TODO: Need to sort out the msm_framebuffer_prepare() call below so
  690. * we can use msm_atomic_prepare_fb() instead of doing the
  691. * implicit fence and fb prepare by hand here.
  692. */
  693. obj = msm_framebuffer_bo(new_state->fb, 0);
  694. msm_obj = to_msm_bo(obj);
  695. fence = reservation_object_get_excl_rcu(msm_obj->resv);
  696. if (fence)
  697. drm_atomic_set_fence_for_plane(new_state, fence);
  698. if (pstate->aspace) {
  699. ret = msm_framebuffer_prepare(new_state->fb,
  700. pstate->aspace);
  701. if (ret) {
  702. DPU_ERROR("failed to prepare framebuffer\n");
  703. return ret;
  704. }
  705. }
  706. /* validate framebuffer layout before commit */
  707. ret = dpu_format_populate_layout(pstate->aspace,
  708. new_state->fb, &layout);
  709. if (ret) {
  710. DPU_ERROR_PLANE(pdpu, "failed to get format layout, %d\n", ret);
  711. return ret;
  712. }
  713. return 0;
  714. }
  715. static void dpu_plane_cleanup_fb(struct drm_plane *plane,
  716. struct drm_plane_state *old_state)
  717. {
  718. struct dpu_plane *pdpu = to_dpu_plane(plane);
  719. struct dpu_plane_state *old_pstate;
  720. if (!old_state || !old_state->fb)
  721. return;
  722. old_pstate = to_dpu_plane_state(old_state);
  723. DPU_DEBUG_PLANE(pdpu, "FB[%u]\n", old_state->fb->base.id);
  724. msm_framebuffer_cleanup(old_state->fb, old_pstate->aspace);
  725. }
  726. static bool dpu_plane_validate_src(struct drm_rect *src,
  727. struct drm_rect *fb_rect,
  728. uint32_t min_src_size)
  729. {
  730. /* Ensure fb size is supported */
  731. if (drm_rect_width(fb_rect) > MAX_IMG_WIDTH ||
  732. drm_rect_height(fb_rect) > MAX_IMG_HEIGHT)
  733. return false;
  734. /* Ensure src rect is above the minimum size */
  735. if (drm_rect_width(src) < min_src_size ||
  736. drm_rect_height(src) < min_src_size)
  737. return false;
  738. /* Ensure src is fully encapsulated in fb */
  739. return drm_rect_intersect(fb_rect, src) &&
  740. drm_rect_equals(fb_rect, src);
  741. }
  742. static int dpu_plane_atomic_check(struct drm_plane *plane,
  743. struct drm_plane_state *state)
  744. {
  745. int ret = 0, min_scale;
  746. struct dpu_plane *pdpu = to_dpu_plane(plane);
  747. const struct drm_crtc_state *crtc_state = NULL;
  748. const struct dpu_format *fmt;
  749. struct drm_rect src, dst, fb_rect = { 0 };
  750. uint32_t min_src_size, max_linewidth;
  751. if (state->crtc)
  752. crtc_state = drm_atomic_get_new_crtc_state(state->state,
  753. state->crtc);
  754. min_scale = FRAC_16_16(1, pdpu->pipe_sblk->maxdwnscale);
  755. ret = drm_atomic_helper_check_plane_state(state, crtc_state, min_scale,
  756. pdpu->pipe_sblk->maxupscale << 16,
  757. true, true);
  758. if (ret) {
  759. DPU_ERROR_PLANE(pdpu, "Check plane state failed (%d)\n", ret);
  760. return ret;
  761. }
  762. if (!state->visible)
  763. return 0;
  764. src.x1 = state->src_x >> 16;
  765. src.y1 = state->src_y >> 16;
  766. src.x2 = src.x1 + (state->src_w >> 16);
  767. src.y2 = src.y1 + (state->src_h >> 16);
  768. dst = drm_plane_state_dest(state);
  769. fb_rect.x2 = state->fb->width;
  770. fb_rect.y2 = state->fb->height;
  771. max_linewidth = pdpu->pipe_sblk->common->maxlinewidth;
  772. fmt = to_dpu_format(msm_framebuffer_format(state->fb));
  773. min_src_size = DPU_FORMAT_IS_YUV(fmt) ? 2 : 1;
  774. if (DPU_FORMAT_IS_YUV(fmt) &&
  775. (!(pdpu->features & DPU_SSPP_SCALER) ||
  776. !(pdpu->features & (BIT(DPU_SSPP_CSC)
  777. | BIT(DPU_SSPP_CSC_10BIT))))) {
  778. DPU_ERROR_PLANE(pdpu,
  779. "plane doesn't have scaler/csc for yuv\n");
  780. return -EINVAL;
  781. /* check src bounds */
  782. } else if (!dpu_plane_validate_src(&src, &fb_rect, min_src_size)) {
  783. DPU_ERROR_PLANE(pdpu, "invalid source " DRM_RECT_FMT "\n",
  784. DRM_RECT_ARG(&src));
  785. return -E2BIG;
  786. /* valid yuv image */
  787. } else if (DPU_FORMAT_IS_YUV(fmt) &&
  788. (src.x1 & 0x1 || src.y1 & 0x1 ||
  789. drm_rect_width(&src) & 0x1 ||
  790. drm_rect_height(&src) & 0x1)) {
  791. DPU_ERROR_PLANE(pdpu, "invalid yuv source " DRM_RECT_FMT "\n",
  792. DRM_RECT_ARG(&src));
  793. return -EINVAL;
  794. /* min dst support */
  795. } else if (drm_rect_width(&dst) < 0x1 || drm_rect_height(&dst) < 0x1) {
  796. DPU_ERROR_PLANE(pdpu, "invalid dest rect " DRM_RECT_FMT "\n",
  797. DRM_RECT_ARG(&dst));
  798. return -EINVAL;
  799. /* check decimated source width */
  800. } else if (drm_rect_width(&src) > max_linewidth) {
  801. DPU_ERROR_PLANE(pdpu, "invalid src " DRM_RECT_FMT " line:%u\n",
  802. DRM_RECT_ARG(&src), max_linewidth);
  803. return -E2BIG;
  804. }
  805. return 0;
  806. }
  807. void dpu_plane_flush(struct drm_plane *plane)
  808. {
  809. struct dpu_plane *pdpu;
  810. struct dpu_plane_state *pstate;
  811. if (!plane || !plane->state) {
  812. DPU_ERROR("invalid plane\n");
  813. return;
  814. }
  815. pdpu = to_dpu_plane(plane);
  816. pstate = to_dpu_plane_state(plane->state);
  817. /*
  818. * These updates have to be done immediately before the plane flush
  819. * timing, and may not be moved to the atomic_update/mode_set functions.
  820. */
  821. if (pdpu->is_error)
  822. /* force white frame with 100% alpha pipe output on error */
  823. _dpu_plane_color_fill(pdpu, 0xFFFFFF, 0xFF);
  824. else if (pdpu->color_fill & DPU_PLANE_COLOR_FILL_FLAG)
  825. /* force 100% alpha */
  826. _dpu_plane_color_fill(pdpu, pdpu->color_fill, 0xFF);
  827. else if (pdpu->pipe_hw && pdpu->csc_ptr && pdpu->pipe_hw->ops.setup_csc)
  828. pdpu->pipe_hw->ops.setup_csc(pdpu->pipe_hw, pdpu->csc_ptr);
  829. /* flag h/w flush complete */
  830. if (plane->state)
  831. pstate->pending = false;
  832. }
  833. /**
  834. * dpu_plane_set_error: enable/disable error condition
  835. * @plane: pointer to drm_plane structure
  836. */
  837. void dpu_plane_set_error(struct drm_plane *plane, bool error)
  838. {
  839. struct dpu_plane *pdpu;
  840. if (!plane)
  841. return;
  842. pdpu = to_dpu_plane(plane);
  843. pdpu->is_error = error;
  844. }
  845. static void dpu_plane_sspp_atomic_update(struct drm_plane *plane)
  846. {
  847. uint32_t src_flags;
  848. struct dpu_plane *pdpu = to_dpu_plane(plane);
  849. struct drm_plane_state *state = plane->state;
  850. struct dpu_plane_state *pstate = to_dpu_plane_state(state);
  851. struct drm_crtc *crtc = state->crtc;
  852. struct drm_framebuffer *fb = state->fb;
  853. const struct dpu_format *fmt =
  854. to_dpu_format(msm_framebuffer_format(fb));
  855. memset(&(pdpu->pipe_cfg), 0, sizeof(struct dpu_hw_pipe_cfg));
  856. _dpu_plane_set_scanout(plane, pstate, &pdpu->pipe_cfg, fb);
  857. pstate->pending = true;
  858. pdpu->is_rt_pipe = (dpu_crtc_get_client_type(crtc) != NRT_CLIENT);
  859. _dpu_plane_set_qos_ctrl(plane, false, DPU_PLANE_QOS_PANIC_CTRL);
  860. DPU_DEBUG_PLANE(pdpu, "FB[%u] " DRM_RECT_FP_FMT "->crtc%u " DRM_RECT_FMT
  861. ", %4.4s ubwc %d\n", fb->base.id, DRM_RECT_FP_ARG(&state->src),
  862. crtc->base.id, DRM_RECT_ARG(&state->dst),
  863. (char *)&fmt->base.pixel_format, DPU_FORMAT_IS_UBWC(fmt));
  864. pdpu->pipe_cfg.src_rect = state->src;
  865. /* state->src is 16.16, src_rect is not */
  866. pdpu->pipe_cfg.src_rect.x1 >>= 16;
  867. pdpu->pipe_cfg.src_rect.x2 >>= 16;
  868. pdpu->pipe_cfg.src_rect.y1 >>= 16;
  869. pdpu->pipe_cfg.src_rect.y2 >>= 16;
  870. pdpu->pipe_cfg.dst_rect = state->dst;
  871. _dpu_plane_setup_scaler(pdpu, pstate, fmt, false);
  872. /* override for color fill */
  873. if (pdpu->color_fill & DPU_PLANE_COLOR_FILL_FLAG) {
  874. /* skip remaining processing on color fill */
  875. return;
  876. }
  877. if (pdpu->pipe_hw->ops.setup_rects) {
  878. pdpu->pipe_hw->ops.setup_rects(pdpu->pipe_hw,
  879. &pdpu->pipe_cfg,
  880. pstate->multirect_index);
  881. }
  882. if (pdpu->pipe_hw->ops.setup_pe &&
  883. (pstate->multirect_index != DPU_SSPP_RECT_1))
  884. pdpu->pipe_hw->ops.setup_pe(pdpu->pipe_hw,
  885. &pstate->pixel_ext);
  886. /**
  887. * when programmed in multirect mode, scalar block will be
  888. * bypassed. Still we need to update alpha and bitwidth
  889. * ONLY for RECT0
  890. */
  891. if (pdpu->pipe_hw->ops.setup_scaler &&
  892. pstate->multirect_index != DPU_SSPP_RECT_1)
  893. pdpu->pipe_hw->ops.setup_scaler(pdpu->pipe_hw,
  894. &pdpu->pipe_cfg, &pstate->pixel_ext,
  895. &pstate->scaler3_cfg);
  896. if (pdpu->pipe_hw->ops.setup_multirect)
  897. pdpu->pipe_hw->ops.setup_multirect(
  898. pdpu->pipe_hw,
  899. pstate->multirect_index,
  900. pstate->multirect_mode);
  901. if (pdpu->pipe_hw->ops.setup_format) {
  902. src_flags = 0x0;
  903. /* update format */
  904. pdpu->pipe_hw->ops.setup_format(pdpu->pipe_hw, fmt, src_flags,
  905. pstate->multirect_index);
  906. if (pdpu->pipe_hw->ops.setup_cdp) {
  907. struct dpu_hw_pipe_cdp_cfg *cdp_cfg = &pstate->cdp_cfg;
  908. memset(cdp_cfg, 0, sizeof(struct dpu_hw_pipe_cdp_cfg));
  909. cdp_cfg->enable = pdpu->catalog->perf.cdp_cfg
  910. [DPU_PERF_CDP_USAGE_RT].rd_enable;
  911. cdp_cfg->ubwc_meta_enable =
  912. DPU_FORMAT_IS_UBWC(fmt);
  913. cdp_cfg->tile_amortize_enable =
  914. DPU_FORMAT_IS_UBWC(fmt) ||
  915. DPU_FORMAT_IS_TILE(fmt);
  916. cdp_cfg->preload_ahead = DPU_SSPP_CDP_PRELOAD_AHEAD_64;
  917. pdpu->pipe_hw->ops.setup_cdp(pdpu->pipe_hw, cdp_cfg);
  918. }
  919. /* update csc */
  920. if (DPU_FORMAT_IS_YUV(fmt))
  921. _dpu_plane_setup_csc(pdpu);
  922. else
  923. pdpu->csc_ptr = 0;
  924. }
  925. _dpu_plane_set_qos_lut(plane, fb);
  926. _dpu_plane_set_danger_lut(plane, fb);
  927. if (plane->type != DRM_PLANE_TYPE_CURSOR) {
  928. _dpu_plane_set_qos_ctrl(plane, true, DPU_PLANE_QOS_PANIC_CTRL);
  929. _dpu_plane_set_ot_limit(plane, crtc);
  930. }
  931. _dpu_plane_set_qos_remap(plane);
  932. }
  933. static void _dpu_plane_atomic_disable(struct drm_plane *plane)
  934. {
  935. struct dpu_plane *pdpu = to_dpu_plane(plane);
  936. struct drm_plane_state *state = plane->state;
  937. struct dpu_plane_state *pstate = to_dpu_plane_state(state);
  938. trace_dpu_plane_disable(DRMID(plane), is_dpu_plane_virtual(plane),
  939. pstate->multirect_mode);
  940. pstate->pending = true;
  941. if (is_dpu_plane_virtual(plane) &&
  942. pdpu->pipe_hw && pdpu->pipe_hw->ops.setup_multirect)
  943. pdpu->pipe_hw->ops.setup_multirect(pdpu->pipe_hw,
  944. DPU_SSPP_RECT_SOLO, DPU_SSPP_MULTIRECT_NONE);
  945. }
  946. static void dpu_plane_atomic_update(struct drm_plane *plane,
  947. struct drm_plane_state *old_state)
  948. {
  949. struct dpu_plane *pdpu = to_dpu_plane(plane);
  950. struct drm_plane_state *state = plane->state;
  951. pdpu->is_error = false;
  952. DPU_DEBUG_PLANE(pdpu, "\n");
  953. if (!state->visible) {
  954. _dpu_plane_atomic_disable(plane);
  955. } else {
  956. dpu_plane_sspp_atomic_update(plane);
  957. }
  958. }
  959. void dpu_plane_restore(struct drm_plane *plane)
  960. {
  961. struct dpu_plane *pdpu;
  962. if (!plane || !plane->state) {
  963. DPU_ERROR("invalid plane\n");
  964. return;
  965. }
  966. pdpu = to_dpu_plane(plane);
  967. DPU_DEBUG_PLANE(pdpu, "\n");
  968. /* last plane state is same as current state */
  969. dpu_plane_atomic_update(plane, plane->state);
  970. }
  971. static void dpu_plane_destroy(struct drm_plane *plane)
  972. {
  973. struct dpu_plane *pdpu = plane ? to_dpu_plane(plane) : NULL;
  974. DPU_DEBUG_PLANE(pdpu, "\n");
  975. if (pdpu) {
  976. _dpu_plane_set_qos_ctrl(plane, false, DPU_PLANE_QOS_PANIC_CTRL);
  977. mutex_destroy(&pdpu->lock);
  978. drm_plane_helper_disable(plane, NULL);
  979. /* this will destroy the states as well */
  980. drm_plane_cleanup(plane);
  981. dpu_hw_sspp_destroy(pdpu->pipe_hw);
  982. kfree(pdpu);
  983. }
  984. }
  985. static void dpu_plane_destroy_state(struct drm_plane *plane,
  986. struct drm_plane_state *state)
  987. {
  988. struct dpu_plane_state *pstate;
  989. if (!plane || !state) {
  990. DPU_ERROR("invalid arg(s), plane %d state %d\n",
  991. plane != 0, state != 0);
  992. return;
  993. }
  994. pstate = to_dpu_plane_state(state);
  995. __drm_atomic_helper_plane_destroy_state(state);
  996. kfree(pstate);
  997. }
  998. static struct drm_plane_state *
  999. dpu_plane_duplicate_state(struct drm_plane *plane)
  1000. {
  1001. struct dpu_plane *pdpu;
  1002. struct dpu_plane_state *pstate;
  1003. struct dpu_plane_state *old_state;
  1004. if (!plane) {
  1005. DPU_ERROR("invalid plane\n");
  1006. return NULL;
  1007. } else if (!plane->state) {
  1008. DPU_ERROR("invalid plane state\n");
  1009. return NULL;
  1010. }
  1011. old_state = to_dpu_plane_state(plane->state);
  1012. pdpu = to_dpu_plane(plane);
  1013. pstate = kmemdup(old_state, sizeof(*old_state), GFP_KERNEL);
  1014. if (!pstate) {
  1015. DPU_ERROR_PLANE(pdpu, "failed to allocate state\n");
  1016. return NULL;
  1017. }
  1018. DPU_DEBUG_PLANE(pdpu, "\n");
  1019. pstate->pending = false;
  1020. __drm_atomic_helper_plane_duplicate_state(plane, &pstate->base);
  1021. return &pstate->base;
  1022. }
  1023. static void dpu_plane_reset(struct drm_plane *plane)
  1024. {
  1025. struct dpu_plane *pdpu;
  1026. struct dpu_plane_state *pstate;
  1027. if (!plane) {
  1028. DPU_ERROR("invalid plane\n");
  1029. return;
  1030. }
  1031. pdpu = to_dpu_plane(plane);
  1032. DPU_DEBUG_PLANE(pdpu, "\n");
  1033. /* remove previous state, if present */
  1034. if (plane->state) {
  1035. dpu_plane_destroy_state(plane, plane->state);
  1036. plane->state = 0;
  1037. }
  1038. pstate = kzalloc(sizeof(*pstate), GFP_KERNEL);
  1039. if (!pstate) {
  1040. DPU_ERROR_PLANE(pdpu, "failed to allocate state\n");
  1041. return;
  1042. }
  1043. pstate->base.plane = plane;
  1044. plane->state = &pstate->base;
  1045. }
  1046. #ifdef CONFIG_DEBUG_FS
  1047. static ssize_t _dpu_plane_danger_read(struct file *file,
  1048. char __user *buff, size_t count, loff_t *ppos)
  1049. {
  1050. struct dpu_kms *kms = file->private_data;
  1051. struct dpu_mdss_cfg *cfg = kms->catalog;
  1052. int len = 0;
  1053. char buf[40] = {'\0'};
  1054. if (!cfg)
  1055. return -ENODEV;
  1056. if (*ppos)
  1057. return 0; /* the end */
  1058. len = snprintf(buf, sizeof(buf), "%d\n", !kms->has_danger_ctrl);
  1059. if (len < 0 || len >= sizeof(buf))
  1060. return 0;
  1061. if ((count < sizeof(buf)) || copy_to_user(buff, buf, len))
  1062. return -EFAULT;
  1063. *ppos += len; /* increase offset */
  1064. return len;
  1065. }
  1066. static void _dpu_plane_set_danger_state(struct dpu_kms *kms, bool enable)
  1067. {
  1068. struct drm_plane *plane;
  1069. drm_for_each_plane(plane, kms->dev) {
  1070. if (plane->fb && plane->state) {
  1071. dpu_plane_danger_signal_ctrl(plane, enable);
  1072. DPU_DEBUG("plane:%d img:%dx%d ",
  1073. plane->base.id, plane->fb->width,
  1074. plane->fb->height);
  1075. DPU_DEBUG("src[%d,%d,%d,%d] dst[%d,%d,%d,%d]\n",
  1076. plane->state->src_x >> 16,
  1077. plane->state->src_y >> 16,
  1078. plane->state->src_w >> 16,
  1079. plane->state->src_h >> 16,
  1080. plane->state->crtc_x, plane->state->crtc_y,
  1081. plane->state->crtc_w, plane->state->crtc_h);
  1082. } else {
  1083. DPU_DEBUG("Inactive plane:%d\n", plane->base.id);
  1084. }
  1085. }
  1086. }
  1087. static ssize_t _dpu_plane_danger_write(struct file *file,
  1088. const char __user *user_buf, size_t count, loff_t *ppos)
  1089. {
  1090. struct dpu_kms *kms = file->private_data;
  1091. struct dpu_mdss_cfg *cfg = kms->catalog;
  1092. int disable_panic;
  1093. char buf[10];
  1094. if (!cfg)
  1095. return -EFAULT;
  1096. if (count >= sizeof(buf))
  1097. return -EFAULT;
  1098. if (copy_from_user(buf, user_buf, count))
  1099. return -EFAULT;
  1100. buf[count] = 0; /* end of string */
  1101. if (kstrtoint(buf, 0, &disable_panic))
  1102. return -EFAULT;
  1103. if (disable_panic) {
  1104. /* Disable panic signal for all active pipes */
  1105. DPU_DEBUG("Disabling danger:\n");
  1106. _dpu_plane_set_danger_state(kms, false);
  1107. kms->has_danger_ctrl = false;
  1108. } else {
  1109. /* Enable panic signal for all active pipes */
  1110. DPU_DEBUG("Enabling danger:\n");
  1111. kms->has_danger_ctrl = true;
  1112. _dpu_plane_set_danger_state(kms, true);
  1113. }
  1114. return count;
  1115. }
  1116. static const struct file_operations dpu_plane_danger_enable = {
  1117. .open = simple_open,
  1118. .read = _dpu_plane_danger_read,
  1119. .write = _dpu_plane_danger_write,
  1120. };
  1121. static int _dpu_plane_init_debugfs(struct drm_plane *plane)
  1122. {
  1123. struct dpu_plane *pdpu;
  1124. struct dpu_kms *kms;
  1125. struct msm_drm_private *priv;
  1126. const struct dpu_sspp_sub_blks *sblk = 0;
  1127. const struct dpu_sspp_cfg *cfg = 0;
  1128. if (!plane || !plane->dev) {
  1129. DPU_ERROR("invalid arguments\n");
  1130. return -EINVAL;
  1131. }
  1132. priv = plane->dev->dev_private;
  1133. if (!priv || !priv->kms) {
  1134. DPU_ERROR("invalid KMS reference\n");
  1135. return -EINVAL;
  1136. }
  1137. kms = to_dpu_kms(priv->kms);
  1138. pdpu = to_dpu_plane(plane);
  1139. if (pdpu && pdpu->pipe_hw)
  1140. cfg = pdpu->pipe_hw->cap;
  1141. if (cfg)
  1142. sblk = cfg->sblk;
  1143. if (!sblk)
  1144. return 0;
  1145. /* create overall sub-directory for the pipe */
  1146. pdpu->debugfs_root =
  1147. debugfs_create_dir(pdpu->pipe_name,
  1148. plane->dev->primary->debugfs_root);
  1149. if (!pdpu->debugfs_root)
  1150. return -ENOMEM;
  1151. /* don't error check these */
  1152. debugfs_create_x32("features", 0600,
  1153. pdpu->debugfs_root, &pdpu->features);
  1154. /* add register dump support */
  1155. dpu_debugfs_setup_regset32(&pdpu->debugfs_src,
  1156. sblk->src_blk.base + cfg->base,
  1157. sblk->src_blk.len,
  1158. kms);
  1159. dpu_debugfs_create_regset32("src_blk", 0400,
  1160. pdpu->debugfs_root, &pdpu->debugfs_src);
  1161. if (cfg->features & BIT(DPU_SSPP_SCALER_QSEED3) ||
  1162. cfg->features & BIT(DPU_SSPP_SCALER_QSEED2)) {
  1163. dpu_debugfs_setup_regset32(&pdpu->debugfs_scaler,
  1164. sblk->scaler_blk.base + cfg->base,
  1165. sblk->scaler_blk.len,
  1166. kms);
  1167. dpu_debugfs_create_regset32("scaler_blk", 0400,
  1168. pdpu->debugfs_root,
  1169. &pdpu->debugfs_scaler);
  1170. debugfs_create_bool("default_scaling",
  1171. 0600,
  1172. pdpu->debugfs_root,
  1173. &pdpu->debugfs_default_scale);
  1174. }
  1175. if (cfg->features & BIT(DPU_SSPP_CSC) ||
  1176. cfg->features & BIT(DPU_SSPP_CSC_10BIT)) {
  1177. dpu_debugfs_setup_regset32(&pdpu->debugfs_csc,
  1178. sblk->csc_blk.base + cfg->base,
  1179. sblk->csc_blk.len,
  1180. kms);
  1181. dpu_debugfs_create_regset32("csc_blk", 0400,
  1182. pdpu->debugfs_root, &pdpu->debugfs_csc);
  1183. }
  1184. debugfs_create_u32("xin_id",
  1185. 0400,
  1186. pdpu->debugfs_root,
  1187. (u32 *) &cfg->xin_id);
  1188. debugfs_create_u32("clk_ctrl",
  1189. 0400,
  1190. pdpu->debugfs_root,
  1191. (u32 *) &cfg->clk_ctrl);
  1192. debugfs_create_x32("creq_vblank",
  1193. 0600,
  1194. pdpu->debugfs_root,
  1195. (u32 *) &sblk->creq_vblank);
  1196. debugfs_create_x32("danger_vblank",
  1197. 0600,
  1198. pdpu->debugfs_root,
  1199. (u32 *) &sblk->danger_vblank);
  1200. debugfs_create_file("disable_danger",
  1201. 0600,
  1202. pdpu->debugfs_root,
  1203. kms, &dpu_plane_danger_enable);
  1204. return 0;
  1205. }
  1206. static void _dpu_plane_destroy_debugfs(struct drm_plane *plane)
  1207. {
  1208. struct dpu_plane *pdpu;
  1209. if (!plane)
  1210. return;
  1211. pdpu = to_dpu_plane(plane);
  1212. debugfs_remove_recursive(pdpu->debugfs_root);
  1213. }
  1214. #else
  1215. static int _dpu_plane_init_debugfs(struct drm_plane *plane)
  1216. {
  1217. return 0;
  1218. }
  1219. static void _dpu_plane_destroy_debugfs(struct drm_plane *plane)
  1220. {
  1221. }
  1222. #endif
  1223. static int dpu_plane_late_register(struct drm_plane *plane)
  1224. {
  1225. return _dpu_plane_init_debugfs(plane);
  1226. }
  1227. static void dpu_plane_early_unregister(struct drm_plane *plane)
  1228. {
  1229. _dpu_plane_destroy_debugfs(plane);
  1230. }
  1231. static const struct drm_plane_funcs dpu_plane_funcs = {
  1232. .update_plane = drm_atomic_helper_update_plane,
  1233. .disable_plane = drm_atomic_helper_disable_plane,
  1234. .destroy = dpu_plane_destroy,
  1235. .reset = dpu_plane_reset,
  1236. .atomic_duplicate_state = dpu_plane_duplicate_state,
  1237. .atomic_destroy_state = dpu_plane_destroy_state,
  1238. .late_register = dpu_plane_late_register,
  1239. .early_unregister = dpu_plane_early_unregister,
  1240. };
  1241. static const struct drm_plane_helper_funcs dpu_plane_helper_funcs = {
  1242. .prepare_fb = dpu_plane_prepare_fb,
  1243. .cleanup_fb = dpu_plane_cleanup_fb,
  1244. .atomic_check = dpu_plane_atomic_check,
  1245. .atomic_update = dpu_plane_atomic_update,
  1246. };
  1247. enum dpu_sspp dpu_plane_pipe(struct drm_plane *plane)
  1248. {
  1249. return plane ? to_dpu_plane(plane)->pipe : SSPP_NONE;
  1250. }
  1251. bool is_dpu_plane_virtual(struct drm_plane *plane)
  1252. {
  1253. return plane ? to_dpu_plane(plane)->is_virtual : false;
  1254. }
  1255. /* initialize plane */
  1256. struct drm_plane *dpu_plane_init(struct drm_device *dev,
  1257. uint32_t pipe, enum drm_plane_type type,
  1258. unsigned long possible_crtcs, u32 master_plane_id)
  1259. {
  1260. struct drm_plane *plane = NULL, *master_plane = NULL;
  1261. const struct dpu_format_extended *format_list;
  1262. struct dpu_plane *pdpu;
  1263. struct msm_drm_private *priv = dev->dev_private;
  1264. struct dpu_kms *kms = to_dpu_kms(priv->kms);
  1265. int zpos_max = DPU_ZPOS_MAX;
  1266. int ret = -EINVAL;
  1267. /* create and zero local structure */
  1268. pdpu = kzalloc(sizeof(*pdpu), GFP_KERNEL);
  1269. if (!pdpu) {
  1270. DPU_ERROR("[%u]failed to allocate local plane struct\n", pipe);
  1271. ret = -ENOMEM;
  1272. goto exit;
  1273. }
  1274. /* cache local stuff for later */
  1275. plane = &pdpu->base;
  1276. pdpu->pipe = pipe;
  1277. pdpu->is_virtual = (master_plane_id != 0);
  1278. INIT_LIST_HEAD(&pdpu->mplane_list);
  1279. master_plane = drm_plane_find(dev, NULL, master_plane_id);
  1280. if (master_plane) {
  1281. struct dpu_plane *mpdpu = to_dpu_plane(master_plane);
  1282. list_add_tail(&pdpu->mplane_list, &mpdpu->mplane_list);
  1283. }
  1284. /* initialize underlying h/w driver */
  1285. pdpu->pipe_hw = dpu_hw_sspp_init(pipe, kms->mmio, kms->catalog,
  1286. master_plane_id != 0);
  1287. if (IS_ERR(pdpu->pipe_hw)) {
  1288. DPU_ERROR("[%u]SSPP init failed\n", pipe);
  1289. ret = PTR_ERR(pdpu->pipe_hw);
  1290. goto clean_plane;
  1291. } else if (!pdpu->pipe_hw->cap || !pdpu->pipe_hw->cap->sblk) {
  1292. DPU_ERROR("[%u]SSPP init returned invalid cfg\n", pipe);
  1293. goto clean_sspp;
  1294. }
  1295. /* cache features mask for later */
  1296. pdpu->features = pdpu->pipe_hw->cap->features;
  1297. pdpu->pipe_sblk = pdpu->pipe_hw->cap->sblk;
  1298. if (!pdpu->pipe_sblk) {
  1299. DPU_ERROR("[%u]invalid sblk\n", pipe);
  1300. goto clean_sspp;
  1301. }
  1302. if (!master_plane_id)
  1303. format_list = pdpu->pipe_sblk->format_list;
  1304. else
  1305. format_list = pdpu->pipe_sblk->virt_format_list;
  1306. pdpu->nformats = dpu_populate_formats(format_list,
  1307. pdpu->formats,
  1308. 0,
  1309. ARRAY_SIZE(pdpu->formats));
  1310. if (!pdpu->nformats) {
  1311. DPU_ERROR("[%u]no valid formats for plane\n", pipe);
  1312. goto clean_sspp;
  1313. }
  1314. ret = drm_universal_plane_init(dev, plane, 0xff, &dpu_plane_funcs,
  1315. pdpu->formats, pdpu->nformats,
  1316. NULL, type, NULL);
  1317. if (ret)
  1318. goto clean_sspp;
  1319. pdpu->catalog = kms->catalog;
  1320. if (kms->catalog->mixer_count &&
  1321. kms->catalog->mixer[0].sblk->maxblendstages) {
  1322. zpos_max = kms->catalog->mixer[0].sblk->maxblendstages - 1;
  1323. if (zpos_max > DPU_STAGE_MAX - DPU_STAGE_0 - 1)
  1324. zpos_max = DPU_STAGE_MAX - DPU_STAGE_0 - 1;
  1325. }
  1326. ret = drm_plane_create_zpos_property(plane, 0, 0, zpos_max);
  1327. if (ret)
  1328. DPU_ERROR("failed to install zpos property, rc = %d\n", ret);
  1329. /* success! finalize initialization */
  1330. drm_plane_helper_add(plane, &dpu_plane_helper_funcs);
  1331. /* save user friendly pipe name for later */
  1332. snprintf(pdpu->pipe_name, DPU_NAME_SIZE, "plane%u", plane->base.id);
  1333. mutex_init(&pdpu->lock);
  1334. DPU_DEBUG("%s created for pipe:%u id:%u virtual:%u\n", pdpu->pipe_name,
  1335. pipe, plane->base.id, master_plane_id);
  1336. return plane;
  1337. clean_sspp:
  1338. if (pdpu && pdpu->pipe_hw)
  1339. dpu_hw_sspp_destroy(pdpu->pipe_hw);
  1340. clean_plane:
  1341. kfree(pdpu);
  1342. exit:
  1343. return ERR_PTR(ret);
  1344. }