intel_sprite.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  1. /*
  2. * Copyright © 2011 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. *
  23. * Authors:
  24. * Jesse Barnes <jbarnes@virtuousgeek.org>
  25. *
  26. * New plane/sprite handling.
  27. *
  28. * The older chips had a separate interface for programming plane related
  29. * registers; newer ones are much simpler and we can use the new DRM plane
  30. * support.
  31. */
  32. #include <drm/drmP.h>
  33. #include <drm/drm_crtc.h>
  34. #include <drm/drm_fourcc.h>
  35. #include <drm/drm_rect.h>
  36. #include <drm/drm_atomic.h>
  37. #include <drm/drm_plane_helper.h>
  38. #include "intel_drv.h"
  39. #include "intel_frontbuffer.h"
  40. #include <drm/i915_drm.h>
  41. #include "i915_drv.h"
  42. static bool
  43. format_is_yuv(uint32_t format)
  44. {
  45. switch (format) {
  46. case DRM_FORMAT_YUYV:
  47. case DRM_FORMAT_UYVY:
  48. case DRM_FORMAT_VYUY:
  49. case DRM_FORMAT_YVYU:
  50. return true;
  51. default:
  52. return false;
  53. }
  54. }
  55. int intel_usecs_to_scanlines(const struct drm_display_mode *adjusted_mode,
  56. int usecs)
  57. {
  58. /* paranoia */
  59. if (!adjusted_mode->crtc_htotal)
  60. return 1;
  61. return DIV_ROUND_UP(usecs * adjusted_mode->crtc_clock,
  62. 1000 * adjusted_mode->crtc_htotal);
  63. }
  64. #define VBLANK_EVASION_TIME_US 100
  65. /**
  66. * intel_pipe_update_start() - start update of a set of display registers
  67. * @crtc: the crtc of which the registers are going to be updated
  68. * @start_vbl_count: vblank counter return pointer used for error checking
  69. *
  70. * Mark the start of an update to pipe registers that should be updated
  71. * atomically regarding vblank. If the next vblank will happens within
  72. * the next 100 us, this function waits until the vblank passes.
  73. *
  74. * After a successful call to this function, interrupts will be disabled
  75. * until a subsequent call to intel_pipe_update_end(). That is done to
  76. * avoid random delays. The value written to @start_vbl_count should be
  77. * supplied to intel_pipe_update_end() for error checking.
  78. */
  79. void intel_pipe_update_start(struct intel_crtc *crtc)
  80. {
  81. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  82. const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
  83. long timeout = msecs_to_jiffies_timeout(1);
  84. int scanline, min, max, vblank_start;
  85. wait_queue_head_t *wq = drm_crtc_vblank_waitqueue(&crtc->base);
  86. bool need_vlv_dsi_wa = (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
  87. intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DSI);
  88. DEFINE_WAIT(wait);
  89. vblank_start = adjusted_mode->crtc_vblank_start;
  90. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
  91. vblank_start = DIV_ROUND_UP(vblank_start, 2);
  92. /* FIXME needs to be calibrated sensibly */
  93. min = vblank_start - intel_usecs_to_scanlines(adjusted_mode,
  94. VBLANK_EVASION_TIME_US);
  95. max = vblank_start - 1;
  96. local_irq_disable();
  97. if (min <= 0 || max <= 0)
  98. return;
  99. if (WARN_ON(drm_crtc_vblank_get(&crtc->base)))
  100. return;
  101. crtc->debug.min_vbl = min;
  102. crtc->debug.max_vbl = max;
  103. trace_i915_pipe_update_start(crtc);
  104. for (;;) {
  105. /*
  106. * prepare_to_wait() has a memory barrier, which guarantees
  107. * other CPUs can see the task state update by the time we
  108. * read the scanline.
  109. */
  110. prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE);
  111. scanline = intel_get_crtc_scanline(crtc);
  112. if (scanline < min || scanline > max)
  113. break;
  114. if (timeout <= 0) {
  115. DRM_ERROR("Potential atomic update failure on pipe %c\n",
  116. pipe_name(crtc->pipe));
  117. break;
  118. }
  119. local_irq_enable();
  120. timeout = schedule_timeout(timeout);
  121. local_irq_disable();
  122. }
  123. finish_wait(wq, &wait);
  124. drm_crtc_vblank_put(&crtc->base);
  125. /*
  126. * On VLV/CHV DSI the scanline counter would appear to
  127. * increment approx. 1/3 of a scanline before start of vblank.
  128. * The registers still get latched at start of vblank however.
  129. * This means we must not write any registers on the first
  130. * line of vblank (since not the whole line is actually in
  131. * vblank). And unfortunately we can't use the interrupt to
  132. * wait here since it will fire too soon. We could use the
  133. * frame start interrupt instead since it will fire after the
  134. * critical scanline, but that would require more changes
  135. * in the interrupt code. So for now we'll just do the nasty
  136. * thing and poll for the bad scanline to pass us by.
  137. *
  138. * FIXME figure out if BXT+ DSI suffers from this as well
  139. */
  140. while (need_vlv_dsi_wa && scanline == vblank_start)
  141. scanline = intel_get_crtc_scanline(crtc);
  142. crtc->debug.scanline_start = scanline;
  143. crtc->debug.start_vbl_time = ktime_get();
  144. crtc->debug.start_vbl_count = intel_crtc_get_vblank_counter(crtc);
  145. trace_i915_pipe_update_vblank_evaded(crtc);
  146. }
  147. /**
  148. * intel_pipe_update_end() - end update of a set of display registers
  149. * @crtc: the crtc of which the registers were updated
  150. * @start_vbl_count: start vblank counter (used for error checking)
  151. *
  152. * Mark the end of an update started with intel_pipe_update_start(). This
  153. * re-enables interrupts and verifies the update was actually completed
  154. * before a vblank using the value of @start_vbl_count.
  155. */
  156. void intel_pipe_update_end(struct intel_crtc *crtc, struct intel_flip_work *work)
  157. {
  158. enum pipe pipe = crtc->pipe;
  159. int scanline_end = intel_get_crtc_scanline(crtc);
  160. u32 end_vbl_count = intel_crtc_get_vblank_counter(crtc);
  161. ktime_t end_vbl_time = ktime_get();
  162. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  163. if (work) {
  164. work->flip_queued_vblank = end_vbl_count;
  165. smp_mb__before_atomic();
  166. atomic_set(&work->pending, 1);
  167. }
  168. trace_i915_pipe_update_end(crtc, end_vbl_count, scanline_end);
  169. /* We're still in the vblank-evade critical section, this can't race.
  170. * Would be slightly nice to just grab the vblank count and arm the
  171. * event outside of the critical section - the spinlock might spin for a
  172. * while ... */
  173. if (crtc->base.state->event) {
  174. WARN_ON(drm_crtc_vblank_get(&crtc->base) != 0);
  175. spin_lock(&crtc->base.dev->event_lock);
  176. drm_crtc_arm_vblank_event(&crtc->base, crtc->base.state->event);
  177. spin_unlock(&crtc->base.dev->event_lock);
  178. crtc->base.state->event = NULL;
  179. }
  180. local_irq_enable();
  181. if (intel_vgpu_active(dev_priv))
  182. return;
  183. if (crtc->debug.start_vbl_count &&
  184. crtc->debug.start_vbl_count != end_vbl_count) {
  185. DRM_ERROR("Atomic update failure on pipe %c (start=%u end=%u) time %lld us, min %d, max %d, scanline start %d, end %d\n",
  186. pipe_name(pipe), crtc->debug.start_vbl_count,
  187. end_vbl_count,
  188. ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time),
  189. crtc->debug.min_vbl, crtc->debug.max_vbl,
  190. crtc->debug.scanline_start, scanline_end);
  191. }
  192. #ifdef CONFIG_DRM_I915_DEBUG_VBLANK_EVADE
  193. else if (ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time) >
  194. VBLANK_EVASION_TIME_US)
  195. DRM_WARN("Atomic update on pipe (%c) took %lld us, max time under evasion is %u us\n",
  196. pipe_name(pipe),
  197. ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time),
  198. VBLANK_EVASION_TIME_US);
  199. #endif
  200. }
  201. static void
  202. skl_update_plane(struct intel_plane *plane,
  203. const struct intel_crtc_state *crtc_state,
  204. const struct intel_plane_state *plane_state)
  205. {
  206. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  207. const struct drm_framebuffer *fb = plane_state->base.fb;
  208. enum plane_id plane_id = plane->id;
  209. enum pipe pipe = plane->pipe;
  210. u32 plane_ctl = plane_state->ctl;
  211. const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
  212. u32 surf_addr = plane_state->main.offset;
  213. unsigned int rotation = plane_state->base.rotation;
  214. u32 stride = skl_plane_stride(fb, 0, rotation);
  215. int crtc_x = plane_state->base.dst.x1;
  216. int crtc_y = plane_state->base.dst.y1;
  217. uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
  218. uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
  219. uint32_t x = plane_state->main.x;
  220. uint32_t y = plane_state->main.y;
  221. uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
  222. uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
  223. unsigned long irqflags;
  224. /* Sizes are 0 based */
  225. src_w--;
  226. src_h--;
  227. crtc_w--;
  228. crtc_h--;
  229. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  230. if (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) {
  231. I915_WRITE_FW(PLANE_COLOR_CTL(pipe, plane_id),
  232. PLANE_COLOR_PIPE_GAMMA_ENABLE |
  233. PLANE_COLOR_PIPE_CSC_ENABLE |
  234. PLANE_COLOR_PLANE_GAMMA_DISABLE);
  235. }
  236. if (key->flags) {
  237. I915_WRITE_FW(PLANE_KEYVAL(pipe, plane_id), key->min_value);
  238. I915_WRITE_FW(PLANE_KEYMAX(pipe, plane_id), key->max_value);
  239. I915_WRITE_FW(PLANE_KEYMSK(pipe, plane_id), key->channel_mask);
  240. }
  241. I915_WRITE_FW(PLANE_OFFSET(pipe, plane_id), (y << 16) | x);
  242. I915_WRITE_FW(PLANE_STRIDE(pipe, plane_id), stride);
  243. I915_WRITE_FW(PLANE_SIZE(pipe, plane_id), (src_h << 16) | src_w);
  244. /* program plane scaler */
  245. if (plane_state->scaler_id >= 0) {
  246. int scaler_id = plane_state->scaler_id;
  247. const struct intel_scaler *scaler;
  248. scaler = &crtc_state->scaler_state.scalers[scaler_id];
  249. I915_WRITE_FW(SKL_PS_CTRL(pipe, scaler_id),
  250. PS_SCALER_EN | PS_PLANE_SEL(plane_id) | scaler->mode);
  251. I915_WRITE_FW(SKL_PS_PWR_GATE(pipe, scaler_id), 0);
  252. I915_WRITE_FW(SKL_PS_WIN_POS(pipe, scaler_id), (crtc_x << 16) | crtc_y);
  253. I915_WRITE_FW(SKL_PS_WIN_SZ(pipe, scaler_id),
  254. ((crtc_w + 1) << 16)|(crtc_h + 1));
  255. I915_WRITE_FW(PLANE_POS(pipe, plane_id), 0);
  256. } else {
  257. I915_WRITE_FW(PLANE_POS(pipe, plane_id), (crtc_y << 16) | crtc_x);
  258. }
  259. I915_WRITE_FW(PLANE_CTL(pipe, plane_id), plane_ctl);
  260. I915_WRITE_FW(PLANE_SURF(pipe, plane_id),
  261. intel_plane_ggtt_offset(plane_state) + surf_addr);
  262. POSTING_READ_FW(PLANE_SURF(pipe, plane_id));
  263. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  264. }
  265. static void
  266. skl_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
  267. {
  268. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  269. enum plane_id plane_id = plane->id;
  270. enum pipe pipe = plane->pipe;
  271. unsigned long irqflags;
  272. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  273. I915_WRITE_FW(PLANE_CTL(pipe, plane_id), 0);
  274. I915_WRITE_FW(PLANE_SURF(pipe, plane_id), 0);
  275. POSTING_READ_FW(PLANE_SURF(pipe, plane_id));
  276. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  277. }
  278. static void
  279. chv_update_csc(struct intel_plane *plane, uint32_t format)
  280. {
  281. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  282. enum plane_id plane_id = plane->id;
  283. /* Seems RGB data bypasses the CSC always */
  284. if (!format_is_yuv(format))
  285. return;
  286. /*
  287. * BT.601 limited range YCbCr -> full range RGB
  288. *
  289. * |r| | 6537 4769 0| |cr |
  290. * |g| = |-3330 4769 -1605| x |y-64|
  291. * |b| | 0 4769 8263| |cb |
  292. *
  293. * Cb and Cr apparently come in as signed already, so no
  294. * need for any offset. For Y we need to remove the offset.
  295. */
  296. I915_WRITE_FW(SPCSCYGOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(-64));
  297. I915_WRITE_FW(SPCSCCBOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
  298. I915_WRITE_FW(SPCSCCROFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
  299. I915_WRITE_FW(SPCSCC01(plane_id), SPCSC_C1(4769) | SPCSC_C0(6537));
  300. I915_WRITE_FW(SPCSCC23(plane_id), SPCSC_C1(-3330) | SPCSC_C0(0));
  301. I915_WRITE_FW(SPCSCC45(plane_id), SPCSC_C1(-1605) | SPCSC_C0(4769));
  302. I915_WRITE_FW(SPCSCC67(plane_id), SPCSC_C1(4769) | SPCSC_C0(0));
  303. I915_WRITE_FW(SPCSCC8(plane_id), SPCSC_C0(8263));
  304. I915_WRITE_FW(SPCSCYGICLAMP(plane_id), SPCSC_IMAX(940) | SPCSC_IMIN(64));
  305. I915_WRITE_FW(SPCSCCBICLAMP(plane_id), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
  306. I915_WRITE_FW(SPCSCCRICLAMP(plane_id), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
  307. I915_WRITE_FW(SPCSCYGOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
  308. I915_WRITE_FW(SPCSCCBOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
  309. I915_WRITE_FW(SPCSCCROCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
  310. }
  311. static u32 vlv_sprite_ctl(const struct intel_crtc_state *crtc_state,
  312. const struct intel_plane_state *plane_state)
  313. {
  314. const struct drm_framebuffer *fb = plane_state->base.fb;
  315. unsigned int rotation = plane_state->base.rotation;
  316. const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
  317. u32 sprctl;
  318. sprctl = SP_ENABLE | SP_GAMMA_ENABLE;
  319. switch (fb->format->format) {
  320. case DRM_FORMAT_YUYV:
  321. sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
  322. break;
  323. case DRM_FORMAT_YVYU:
  324. sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
  325. break;
  326. case DRM_FORMAT_UYVY:
  327. sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
  328. break;
  329. case DRM_FORMAT_VYUY:
  330. sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
  331. break;
  332. case DRM_FORMAT_RGB565:
  333. sprctl |= SP_FORMAT_BGR565;
  334. break;
  335. case DRM_FORMAT_XRGB8888:
  336. sprctl |= SP_FORMAT_BGRX8888;
  337. break;
  338. case DRM_FORMAT_ARGB8888:
  339. sprctl |= SP_FORMAT_BGRA8888;
  340. break;
  341. case DRM_FORMAT_XBGR2101010:
  342. sprctl |= SP_FORMAT_RGBX1010102;
  343. break;
  344. case DRM_FORMAT_ABGR2101010:
  345. sprctl |= SP_FORMAT_RGBA1010102;
  346. break;
  347. case DRM_FORMAT_XBGR8888:
  348. sprctl |= SP_FORMAT_RGBX8888;
  349. break;
  350. case DRM_FORMAT_ABGR8888:
  351. sprctl |= SP_FORMAT_RGBA8888;
  352. break;
  353. default:
  354. MISSING_CASE(fb->format->format);
  355. return 0;
  356. }
  357. if (fb->modifier == I915_FORMAT_MOD_X_TILED)
  358. sprctl |= SP_TILED;
  359. if (rotation & DRM_MODE_ROTATE_180)
  360. sprctl |= SP_ROTATE_180;
  361. if (rotation & DRM_MODE_REFLECT_X)
  362. sprctl |= SP_MIRROR;
  363. if (key->flags & I915_SET_COLORKEY_SOURCE)
  364. sprctl |= SP_SOURCE_KEY;
  365. return sprctl;
  366. }
  367. static void
  368. vlv_update_plane(struct intel_plane *plane,
  369. const struct intel_crtc_state *crtc_state,
  370. const struct intel_plane_state *plane_state)
  371. {
  372. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  373. const struct drm_framebuffer *fb = plane_state->base.fb;
  374. enum pipe pipe = plane->pipe;
  375. enum plane_id plane_id = plane->id;
  376. u32 sprctl = plane_state->ctl;
  377. u32 sprsurf_offset = plane_state->main.offset;
  378. u32 linear_offset;
  379. const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
  380. int crtc_x = plane_state->base.dst.x1;
  381. int crtc_y = plane_state->base.dst.y1;
  382. uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
  383. uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
  384. uint32_t x = plane_state->main.x;
  385. uint32_t y = plane_state->main.y;
  386. unsigned long irqflags;
  387. /* Sizes are 0 based */
  388. crtc_w--;
  389. crtc_h--;
  390. linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
  391. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  392. if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B)
  393. chv_update_csc(plane, fb->format->format);
  394. if (key->flags) {
  395. I915_WRITE_FW(SPKEYMINVAL(pipe, plane_id), key->min_value);
  396. I915_WRITE_FW(SPKEYMAXVAL(pipe, plane_id), key->max_value);
  397. I915_WRITE_FW(SPKEYMSK(pipe, plane_id), key->channel_mask);
  398. }
  399. I915_WRITE_FW(SPSTRIDE(pipe, plane_id), fb->pitches[0]);
  400. I915_WRITE_FW(SPPOS(pipe, plane_id), (crtc_y << 16) | crtc_x);
  401. if (fb->modifier == I915_FORMAT_MOD_X_TILED)
  402. I915_WRITE_FW(SPTILEOFF(pipe, plane_id), (y << 16) | x);
  403. else
  404. I915_WRITE_FW(SPLINOFF(pipe, plane_id), linear_offset);
  405. I915_WRITE_FW(SPCONSTALPHA(pipe, plane_id), 0);
  406. I915_WRITE_FW(SPSIZE(pipe, plane_id), (crtc_h << 16) | crtc_w);
  407. I915_WRITE_FW(SPCNTR(pipe, plane_id), sprctl);
  408. I915_WRITE_FW(SPSURF(pipe, plane_id),
  409. intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
  410. POSTING_READ_FW(SPSURF(pipe, plane_id));
  411. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  412. }
  413. static void
  414. vlv_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
  415. {
  416. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  417. enum pipe pipe = plane->pipe;
  418. enum plane_id plane_id = plane->id;
  419. unsigned long irqflags;
  420. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  421. I915_WRITE_FW(SPCNTR(pipe, plane_id), 0);
  422. I915_WRITE_FW(SPSURF(pipe, plane_id), 0);
  423. POSTING_READ_FW(SPSURF(pipe, plane_id));
  424. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  425. }
  426. static u32 ivb_sprite_ctl(const struct intel_crtc_state *crtc_state,
  427. const struct intel_plane_state *plane_state)
  428. {
  429. struct drm_i915_private *dev_priv =
  430. to_i915(plane_state->base.plane->dev);
  431. const struct drm_framebuffer *fb = plane_state->base.fb;
  432. unsigned int rotation = plane_state->base.rotation;
  433. const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
  434. u32 sprctl;
  435. sprctl = SPRITE_ENABLE | SPRITE_GAMMA_ENABLE;
  436. if (IS_IVYBRIDGE(dev_priv))
  437. sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
  438. if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  439. sprctl |= SPRITE_PIPE_CSC_ENABLE;
  440. switch (fb->format->format) {
  441. case DRM_FORMAT_XBGR8888:
  442. sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
  443. break;
  444. case DRM_FORMAT_XRGB8888:
  445. sprctl |= SPRITE_FORMAT_RGBX888;
  446. break;
  447. case DRM_FORMAT_YUYV:
  448. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
  449. break;
  450. case DRM_FORMAT_YVYU:
  451. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
  452. break;
  453. case DRM_FORMAT_UYVY:
  454. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
  455. break;
  456. case DRM_FORMAT_VYUY:
  457. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
  458. break;
  459. default:
  460. MISSING_CASE(fb->format->format);
  461. return 0;
  462. }
  463. if (fb->modifier == I915_FORMAT_MOD_X_TILED)
  464. sprctl |= SPRITE_TILED;
  465. if (rotation & DRM_MODE_ROTATE_180)
  466. sprctl |= SPRITE_ROTATE_180;
  467. if (key->flags & I915_SET_COLORKEY_DESTINATION)
  468. sprctl |= SPRITE_DEST_KEY;
  469. else if (key->flags & I915_SET_COLORKEY_SOURCE)
  470. sprctl |= SPRITE_SOURCE_KEY;
  471. return sprctl;
  472. }
  473. static void
  474. ivb_update_plane(struct intel_plane *plane,
  475. const struct intel_crtc_state *crtc_state,
  476. const struct intel_plane_state *plane_state)
  477. {
  478. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  479. const struct drm_framebuffer *fb = plane_state->base.fb;
  480. enum pipe pipe = plane->pipe;
  481. u32 sprctl = plane_state->ctl, sprscale = 0;
  482. u32 sprsurf_offset = plane_state->main.offset;
  483. u32 linear_offset;
  484. const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
  485. int crtc_x = plane_state->base.dst.x1;
  486. int crtc_y = plane_state->base.dst.y1;
  487. uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
  488. uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
  489. uint32_t x = plane_state->main.x;
  490. uint32_t y = plane_state->main.y;
  491. uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
  492. uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
  493. unsigned long irqflags;
  494. /* Sizes are 0 based */
  495. src_w--;
  496. src_h--;
  497. crtc_w--;
  498. crtc_h--;
  499. if (crtc_w != src_w || crtc_h != src_h)
  500. sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
  501. linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
  502. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  503. if (key->flags) {
  504. I915_WRITE_FW(SPRKEYVAL(pipe), key->min_value);
  505. I915_WRITE_FW(SPRKEYMAX(pipe), key->max_value);
  506. I915_WRITE_FW(SPRKEYMSK(pipe), key->channel_mask);
  507. }
  508. I915_WRITE_FW(SPRSTRIDE(pipe), fb->pitches[0]);
  509. I915_WRITE_FW(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
  510. /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
  511. * register */
  512. if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  513. I915_WRITE_FW(SPROFFSET(pipe), (y << 16) | x);
  514. else if (fb->modifier == I915_FORMAT_MOD_X_TILED)
  515. I915_WRITE_FW(SPRTILEOFF(pipe), (y << 16) | x);
  516. else
  517. I915_WRITE_FW(SPRLINOFF(pipe), linear_offset);
  518. I915_WRITE_FW(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
  519. if (plane->can_scale)
  520. I915_WRITE_FW(SPRSCALE(pipe), sprscale);
  521. I915_WRITE_FW(SPRCTL(pipe), sprctl);
  522. I915_WRITE_FW(SPRSURF(pipe),
  523. intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
  524. POSTING_READ_FW(SPRSURF(pipe));
  525. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  526. }
  527. static void
  528. ivb_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
  529. {
  530. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  531. enum pipe pipe = plane->pipe;
  532. unsigned long irqflags;
  533. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  534. I915_WRITE_FW(SPRCTL(pipe), 0);
  535. /* Can't leave the scaler enabled... */
  536. if (plane->can_scale)
  537. I915_WRITE_FW(SPRSCALE(pipe), 0);
  538. I915_WRITE_FW(SPRSURF(pipe), 0);
  539. POSTING_READ_FW(SPRSURF(pipe));
  540. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  541. }
  542. static u32 g4x_sprite_ctl(const struct intel_crtc_state *crtc_state,
  543. const struct intel_plane_state *plane_state)
  544. {
  545. struct drm_i915_private *dev_priv =
  546. to_i915(plane_state->base.plane->dev);
  547. const struct drm_framebuffer *fb = plane_state->base.fb;
  548. unsigned int rotation = plane_state->base.rotation;
  549. const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
  550. u32 dvscntr;
  551. dvscntr = DVS_ENABLE | DVS_GAMMA_ENABLE;
  552. if (IS_GEN6(dev_priv))
  553. dvscntr |= DVS_TRICKLE_FEED_DISABLE;
  554. switch (fb->format->format) {
  555. case DRM_FORMAT_XBGR8888:
  556. dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
  557. break;
  558. case DRM_FORMAT_XRGB8888:
  559. dvscntr |= DVS_FORMAT_RGBX888;
  560. break;
  561. case DRM_FORMAT_YUYV:
  562. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
  563. break;
  564. case DRM_FORMAT_YVYU:
  565. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
  566. break;
  567. case DRM_FORMAT_UYVY:
  568. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
  569. break;
  570. case DRM_FORMAT_VYUY:
  571. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
  572. break;
  573. default:
  574. MISSING_CASE(fb->format->format);
  575. return 0;
  576. }
  577. if (fb->modifier == I915_FORMAT_MOD_X_TILED)
  578. dvscntr |= DVS_TILED;
  579. if (rotation & DRM_MODE_ROTATE_180)
  580. dvscntr |= DVS_ROTATE_180;
  581. if (key->flags & I915_SET_COLORKEY_DESTINATION)
  582. dvscntr |= DVS_DEST_KEY;
  583. else if (key->flags & I915_SET_COLORKEY_SOURCE)
  584. dvscntr |= DVS_SOURCE_KEY;
  585. return dvscntr;
  586. }
  587. static void
  588. g4x_update_plane(struct intel_plane *plane,
  589. const struct intel_crtc_state *crtc_state,
  590. const struct intel_plane_state *plane_state)
  591. {
  592. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  593. const struct drm_framebuffer *fb = plane_state->base.fb;
  594. enum pipe pipe = plane->pipe;
  595. u32 dvscntr = plane_state->ctl, dvsscale = 0;
  596. u32 dvssurf_offset = plane_state->main.offset;
  597. u32 linear_offset;
  598. const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
  599. int crtc_x = plane_state->base.dst.x1;
  600. int crtc_y = plane_state->base.dst.y1;
  601. uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
  602. uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
  603. uint32_t x = plane_state->main.x;
  604. uint32_t y = plane_state->main.y;
  605. uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
  606. uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
  607. unsigned long irqflags;
  608. /* Sizes are 0 based */
  609. src_w--;
  610. src_h--;
  611. crtc_w--;
  612. crtc_h--;
  613. if (crtc_w != src_w || crtc_h != src_h)
  614. dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
  615. linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
  616. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  617. if (key->flags) {
  618. I915_WRITE_FW(DVSKEYVAL(pipe), key->min_value);
  619. I915_WRITE_FW(DVSKEYMAX(pipe), key->max_value);
  620. I915_WRITE_FW(DVSKEYMSK(pipe), key->channel_mask);
  621. }
  622. I915_WRITE_FW(DVSSTRIDE(pipe), fb->pitches[0]);
  623. I915_WRITE_FW(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
  624. if (fb->modifier == I915_FORMAT_MOD_X_TILED)
  625. I915_WRITE_FW(DVSTILEOFF(pipe), (y << 16) | x);
  626. else
  627. I915_WRITE_FW(DVSLINOFF(pipe), linear_offset);
  628. I915_WRITE_FW(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
  629. I915_WRITE_FW(DVSSCALE(pipe), dvsscale);
  630. I915_WRITE_FW(DVSCNTR(pipe), dvscntr);
  631. I915_WRITE_FW(DVSSURF(pipe),
  632. intel_plane_ggtt_offset(plane_state) + dvssurf_offset);
  633. POSTING_READ_FW(DVSSURF(pipe));
  634. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  635. }
  636. static void
  637. g4x_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
  638. {
  639. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  640. enum pipe pipe = plane->pipe;
  641. unsigned long irqflags;
  642. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  643. I915_WRITE_FW(DVSCNTR(pipe), 0);
  644. /* Disable the scaler */
  645. I915_WRITE_FW(DVSSCALE(pipe), 0);
  646. I915_WRITE_FW(DVSSURF(pipe), 0);
  647. POSTING_READ_FW(DVSSURF(pipe));
  648. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  649. }
  650. static int
  651. intel_check_sprite_plane(struct intel_plane *plane,
  652. struct intel_crtc_state *crtc_state,
  653. struct intel_plane_state *state)
  654. {
  655. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  656. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  657. struct drm_framebuffer *fb = state->base.fb;
  658. int crtc_x, crtc_y;
  659. unsigned int crtc_w, crtc_h;
  660. uint32_t src_x, src_y, src_w, src_h;
  661. struct drm_rect *src = &state->base.src;
  662. struct drm_rect *dst = &state->base.dst;
  663. const struct drm_rect *clip = &state->clip;
  664. int hscale, vscale;
  665. int max_scale, min_scale;
  666. bool can_scale;
  667. int ret;
  668. *src = drm_plane_state_src(&state->base);
  669. *dst = drm_plane_state_dest(&state->base);
  670. if (!fb) {
  671. state->base.visible = false;
  672. return 0;
  673. }
  674. /* Don't modify another pipe's plane */
  675. if (plane->pipe != crtc->pipe) {
  676. DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
  677. return -EINVAL;
  678. }
  679. /* FIXME check all gen limits */
  680. if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
  681. DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
  682. return -EINVAL;
  683. }
  684. /* setup can_scale, min_scale, max_scale */
  685. if (INTEL_GEN(dev_priv) >= 9) {
  686. /* use scaler when colorkey is not required */
  687. if (state->ckey.flags == I915_SET_COLORKEY_NONE) {
  688. can_scale = 1;
  689. min_scale = 1;
  690. max_scale = skl_max_scale(crtc, crtc_state);
  691. } else {
  692. can_scale = 0;
  693. min_scale = DRM_PLANE_HELPER_NO_SCALING;
  694. max_scale = DRM_PLANE_HELPER_NO_SCALING;
  695. }
  696. } else {
  697. can_scale = plane->can_scale;
  698. max_scale = plane->max_downscale << 16;
  699. min_scale = plane->can_scale ? 1 : (1 << 16);
  700. }
  701. /*
  702. * FIXME the following code does a bunch of fuzzy adjustments to the
  703. * coordinates and sizes. We probably need some way to decide whether
  704. * more strict checking should be done instead.
  705. */
  706. drm_rect_rotate(src, fb->width << 16, fb->height << 16,
  707. state->base.rotation);
  708. hscale = drm_rect_calc_hscale_relaxed(src, dst, min_scale, max_scale);
  709. BUG_ON(hscale < 0);
  710. vscale = drm_rect_calc_vscale_relaxed(src, dst, min_scale, max_scale);
  711. BUG_ON(vscale < 0);
  712. state->base.visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale);
  713. crtc_x = dst->x1;
  714. crtc_y = dst->y1;
  715. crtc_w = drm_rect_width(dst);
  716. crtc_h = drm_rect_height(dst);
  717. if (state->base.visible) {
  718. /* check again in case clipping clamped the results */
  719. hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale);
  720. if (hscale < 0) {
  721. DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
  722. drm_rect_debug_print("src: ", src, true);
  723. drm_rect_debug_print("dst: ", dst, false);
  724. return hscale;
  725. }
  726. vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale);
  727. if (vscale < 0) {
  728. DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
  729. drm_rect_debug_print("src: ", src, true);
  730. drm_rect_debug_print("dst: ", dst, false);
  731. return vscale;
  732. }
  733. /* Make the source viewport size an exact multiple of the scaling factors. */
  734. drm_rect_adjust_size(src,
  735. drm_rect_width(dst) * hscale - drm_rect_width(src),
  736. drm_rect_height(dst) * vscale - drm_rect_height(src));
  737. drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16,
  738. state->base.rotation);
  739. /* sanity check to make sure the src viewport wasn't enlarged */
  740. WARN_ON(src->x1 < (int) state->base.src_x ||
  741. src->y1 < (int) state->base.src_y ||
  742. src->x2 > (int) state->base.src_x + state->base.src_w ||
  743. src->y2 > (int) state->base.src_y + state->base.src_h);
  744. /*
  745. * Hardware doesn't handle subpixel coordinates.
  746. * Adjust to (macro)pixel boundary, but be careful not to
  747. * increase the source viewport size, because that could
  748. * push the downscaling factor out of bounds.
  749. */
  750. src_x = src->x1 >> 16;
  751. src_w = drm_rect_width(src) >> 16;
  752. src_y = src->y1 >> 16;
  753. src_h = drm_rect_height(src) >> 16;
  754. if (format_is_yuv(fb->format->format)) {
  755. src_x &= ~1;
  756. src_w &= ~1;
  757. /*
  758. * Must keep src and dst the
  759. * same if we can't scale.
  760. */
  761. if (!can_scale)
  762. crtc_w &= ~1;
  763. if (crtc_w == 0)
  764. state->base.visible = false;
  765. }
  766. }
  767. /* Check size restrictions when scaling */
  768. if (state->base.visible && (src_w != crtc_w || src_h != crtc_h)) {
  769. unsigned int width_bytes;
  770. int cpp = fb->format->cpp[0];
  771. WARN_ON(!can_scale);
  772. /* FIXME interlacing min height is 6 */
  773. if (crtc_w < 3 || crtc_h < 3)
  774. state->base.visible = false;
  775. if (src_w < 3 || src_h < 3)
  776. state->base.visible = false;
  777. width_bytes = ((src_x * cpp) & 63) + src_w * cpp;
  778. if (INTEL_GEN(dev_priv) < 9 && (src_w > 2048 || src_h > 2048 ||
  779. width_bytes > 4096 || fb->pitches[0] > 4096)) {
  780. DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
  781. return -EINVAL;
  782. }
  783. }
  784. if (state->base.visible) {
  785. src->x1 = src_x << 16;
  786. src->x2 = (src_x + src_w) << 16;
  787. src->y1 = src_y << 16;
  788. src->y2 = (src_y + src_h) << 16;
  789. }
  790. dst->x1 = crtc_x;
  791. dst->x2 = crtc_x + crtc_w;
  792. dst->y1 = crtc_y;
  793. dst->y2 = crtc_y + crtc_h;
  794. if (INTEL_GEN(dev_priv) >= 9) {
  795. ret = skl_check_plane_surface(state);
  796. if (ret)
  797. return ret;
  798. state->ctl = skl_plane_ctl(crtc_state, state);
  799. } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  800. ret = i9xx_check_plane_surface(state);
  801. if (ret)
  802. return ret;
  803. state->ctl = vlv_sprite_ctl(crtc_state, state);
  804. } else if (INTEL_GEN(dev_priv) >= 7) {
  805. ret = i9xx_check_plane_surface(state);
  806. if (ret)
  807. return ret;
  808. state->ctl = ivb_sprite_ctl(crtc_state, state);
  809. } else {
  810. ret = i9xx_check_plane_surface(state);
  811. if (ret)
  812. return ret;
  813. state->ctl = g4x_sprite_ctl(crtc_state, state);
  814. }
  815. return 0;
  816. }
  817. int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
  818. struct drm_file *file_priv)
  819. {
  820. struct drm_i915_private *dev_priv = to_i915(dev);
  821. struct drm_intel_sprite_colorkey *set = data;
  822. struct drm_plane *plane;
  823. struct drm_plane_state *plane_state;
  824. struct drm_atomic_state *state;
  825. struct drm_modeset_acquire_ctx ctx;
  826. int ret = 0;
  827. /* Make sure we don't try to enable both src & dest simultaneously */
  828. if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
  829. return -EINVAL;
  830. if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
  831. set->flags & I915_SET_COLORKEY_DESTINATION)
  832. return -EINVAL;
  833. plane = drm_plane_find(dev, set->plane_id);
  834. if (!plane || plane->type != DRM_PLANE_TYPE_OVERLAY)
  835. return -ENOENT;
  836. drm_modeset_acquire_init(&ctx, 0);
  837. state = drm_atomic_state_alloc(plane->dev);
  838. if (!state) {
  839. ret = -ENOMEM;
  840. goto out;
  841. }
  842. state->acquire_ctx = &ctx;
  843. while (1) {
  844. plane_state = drm_atomic_get_plane_state(state, plane);
  845. ret = PTR_ERR_OR_ZERO(plane_state);
  846. if (!ret) {
  847. to_intel_plane_state(plane_state)->ckey = *set;
  848. ret = drm_atomic_commit(state);
  849. }
  850. if (ret != -EDEADLK)
  851. break;
  852. drm_atomic_state_clear(state);
  853. drm_modeset_backoff(&ctx);
  854. }
  855. drm_atomic_state_put(state);
  856. out:
  857. drm_modeset_drop_locks(&ctx);
  858. drm_modeset_acquire_fini(&ctx);
  859. return ret;
  860. }
  861. static const uint32_t g4x_plane_formats[] = {
  862. DRM_FORMAT_XRGB8888,
  863. DRM_FORMAT_YUYV,
  864. DRM_FORMAT_YVYU,
  865. DRM_FORMAT_UYVY,
  866. DRM_FORMAT_VYUY,
  867. };
  868. static const uint32_t snb_plane_formats[] = {
  869. DRM_FORMAT_XBGR8888,
  870. DRM_FORMAT_XRGB8888,
  871. DRM_FORMAT_YUYV,
  872. DRM_FORMAT_YVYU,
  873. DRM_FORMAT_UYVY,
  874. DRM_FORMAT_VYUY,
  875. };
  876. static const uint32_t vlv_plane_formats[] = {
  877. DRM_FORMAT_RGB565,
  878. DRM_FORMAT_ABGR8888,
  879. DRM_FORMAT_ARGB8888,
  880. DRM_FORMAT_XBGR8888,
  881. DRM_FORMAT_XRGB8888,
  882. DRM_FORMAT_XBGR2101010,
  883. DRM_FORMAT_ABGR2101010,
  884. DRM_FORMAT_YUYV,
  885. DRM_FORMAT_YVYU,
  886. DRM_FORMAT_UYVY,
  887. DRM_FORMAT_VYUY,
  888. };
  889. static uint32_t skl_plane_formats[] = {
  890. DRM_FORMAT_RGB565,
  891. DRM_FORMAT_ABGR8888,
  892. DRM_FORMAT_ARGB8888,
  893. DRM_FORMAT_XBGR8888,
  894. DRM_FORMAT_XRGB8888,
  895. DRM_FORMAT_YUYV,
  896. DRM_FORMAT_YVYU,
  897. DRM_FORMAT_UYVY,
  898. DRM_FORMAT_VYUY,
  899. };
  900. struct intel_plane *
  901. intel_sprite_plane_create(struct drm_i915_private *dev_priv,
  902. enum pipe pipe, int plane)
  903. {
  904. struct intel_plane *intel_plane = NULL;
  905. struct intel_plane_state *state = NULL;
  906. unsigned long possible_crtcs;
  907. const uint32_t *plane_formats;
  908. unsigned int supported_rotations;
  909. int num_plane_formats;
  910. int ret;
  911. intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL);
  912. if (!intel_plane) {
  913. ret = -ENOMEM;
  914. goto fail;
  915. }
  916. state = intel_create_plane_state(&intel_plane->base);
  917. if (!state) {
  918. ret = -ENOMEM;
  919. goto fail;
  920. }
  921. intel_plane->base.state = &state->base;
  922. if (INTEL_GEN(dev_priv) >= 9) {
  923. intel_plane->can_scale = true;
  924. state->scaler_id = -1;
  925. intel_plane->update_plane = skl_update_plane;
  926. intel_plane->disable_plane = skl_disable_plane;
  927. plane_formats = skl_plane_formats;
  928. num_plane_formats = ARRAY_SIZE(skl_plane_formats);
  929. } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  930. intel_plane->can_scale = false;
  931. intel_plane->max_downscale = 1;
  932. intel_plane->update_plane = vlv_update_plane;
  933. intel_plane->disable_plane = vlv_disable_plane;
  934. plane_formats = vlv_plane_formats;
  935. num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
  936. } else if (INTEL_GEN(dev_priv) >= 7) {
  937. if (IS_IVYBRIDGE(dev_priv)) {
  938. intel_plane->can_scale = true;
  939. intel_plane->max_downscale = 2;
  940. } else {
  941. intel_plane->can_scale = false;
  942. intel_plane->max_downscale = 1;
  943. }
  944. intel_plane->update_plane = ivb_update_plane;
  945. intel_plane->disable_plane = ivb_disable_plane;
  946. plane_formats = snb_plane_formats;
  947. num_plane_formats = ARRAY_SIZE(snb_plane_formats);
  948. } else {
  949. intel_plane->can_scale = true;
  950. intel_plane->max_downscale = 16;
  951. intel_plane->update_plane = g4x_update_plane;
  952. intel_plane->disable_plane = g4x_disable_plane;
  953. if (IS_GEN6(dev_priv)) {
  954. plane_formats = snb_plane_formats;
  955. num_plane_formats = ARRAY_SIZE(snb_plane_formats);
  956. } else {
  957. plane_formats = g4x_plane_formats;
  958. num_plane_formats = ARRAY_SIZE(g4x_plane_formats);
  959. }
  960. }
  961. if (INTEL_GEN(dev_priv) >= 9) {
  962. supported_rotations =
  963. DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
  964. DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270;
  965. } else if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
  966. supported_rotations =
  967. DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
  968. DRM_MODE_REFLECT_X;
  969. } else {
  970. supported_rotations =
  971. DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
  972. }
  973. intel_plane->pipe = pipe;
  974. intel_plane->plane = plane;
  975. intel_plane->id = PLANE_SPRITE0 + plane;
  976. intel_plane->frontbuffer_bit = INTEL_FRONTBUFFER_SPRITE(pipe, plane);
  977. intel_plane->check_plane = intel_check_sprite_plane;
  978. possible_crtcs = (1 << pipe);
  979. if (INTEL_GEN(dev_priv) >= 9)
  980. ret = drm_universal_plane_init(&dev_priv->drm, &intel_plane->base,
  981. possible_crtcs, &intel_plane_funcs,
  982. plane_formats, num_plane_formats,
  983. NULL, DRM_PLANE_TYPE_OVERLAY,
  984. "plane %d%c", plane + 2, pipe_name(pipe));
  985. else
  986. ret = drm_universal_plane_init(&dev_priv->drm, &intel_plane->base,
  987. possible_crtcs, &intel_plane_funcs,
  988. plane_formats, num_plane_formats,
  989. NULL, DRM_PLANE_TYPE_OVERLAY,
  990. "sprite %c", sprite_name(pipe, plane));
  991. if (ret)
  992. goto fail;
  993. drm_plane_create_rotation_property(&intel_plane->base,
  994. DRM_MODE_ROTATE_0,
  995. supported_rotations);
  996. drm_plane_helper_add(&intel_plane->base, &intel_plane_helper_funcs);
  997. return intel_plane;
  998. fail:
  999. kfree(state);
  1000. kfree(intel_plane);
  1001. return ERR_PTR(ret);
  1002. }