intel_sprite.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  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 drm_plane *drm_plane,
  203. const struct intel_crtc_state *crtc_state,
  204. const struct intel_plane_state *plane_state)
  205. {
  206. struct drm_device *dev = drm_plane->dev;
  207. struct drm_i915_private *dev_priv = to_i915(dev);
  208. struct intel_plane *intel_plane = to_intel_plane(drm_plane);
  209. struct drm_framebuffer *fb = plane_state->base.fb;
  210. enum plane_id plane_id = intel_plane->id;
  211. enum pipe pipe = intel_plane->pipe;
  212. u32 plane_ctl = plane_state->ctl;
  213. const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
  214. u32 surf_addr = plane_state->main.offset;
  215. unsigned int rotation = plane_state->base.rotation;
  216. u32 stride = skl_plane_stride(fb, 0, rotation);
  217. int crtc_x = plane_state->base.dst.x1;
  218. int crtc_y = plane_state->base.dst.y1;
  219. uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
  220. uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
  221. uint32_t x = plane_state->main.x;
  222. uint32_t y = plane_state->main.y;
  223. uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
  224. uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
  225. unsigned long irqflags;
  226. /* Sizes are 0 based */
  227. src_w--;
  228. src_h--;
  229. crtc_w--;
  230. crtc_h--;
  231. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  232. if (IS_GEMINILAKE(dev_priv)) {
  233. I915_WRITE_FW(PLANE_COLOR_CTL(pipe, plane_id),
  234. PLANE_COLOR_PIPE_GAMMA_ENABLE |
  235. PLANE_COLOR_PIPE_CSC_ENABLE |
  236. PLANE_COLOR_PLANE_GAMMA_DISABLE);
  237. }
  238. if (key->flags) {
  239. I915_WRITE_FW(PLANE_KEYVAL(pipe, plane_id), key->min_value);
  240. I915_WRITE_FW(PLANE_KEYMAX(pipe, plane_id), key->max_value);
  241. I915_WRITE_FW(PLANE_KEYMSK(pipe, plane_id), key->channel_mask);
  242. }
  243. I915_WRITE_FW(PLANE_OFFSET(pipe, plane_id), (y << 16) | x);
  244. I915_WRITE_FW(PLANE_STRIDE(pipe, plane_id), stride);
  245. I915_WRITE_FW(PLANE_SIZE(pipe, plane_id), (src_h << 16) | src_w);
  246. /* program plane scaler */
  247. if (plane_state->scaler_id >= 0) {
  248. int scaler_id = plane_state->scaler_id;
  249. const struct intel_scaler *scaler;
  250. scaler = &crtc_state->scaler_state.scalers[scaler_id];
  251. I915_WRITE_FW(SKL_PS_CTRL(pipe, scaler_id),
  252. PS_SCALER_EN | PS_PLANE_SEL(plane_id) | scaler->mode);
  253. I915_WRITE_FW(SKL_PS_PWR_GATE(pipe, scaler_id), 0);
  254. I915_WRITE_FW(SKL_PS_WIN_POS(pipe, scaler_id), (crtc_x << 16) | crtc_y);
  255. I915_WRITE_FW(SKL_PS_WIN_SZ(pipe, scaler_id),
  256. ((crtc_w + 1) << 16)|(crtc_h + 1));
  257. I915_WRITE_FW(PLANE_POS(pipe, plane_id), 0);
  258. } else {
  259. I915_WRITE_FW(PLANE_POS(pipe, plane_id), (crtc_y << 16) | crtc_x);
  260. }
  261. I915_WRITE_FW(PLANE_CTL(pipe, plane_id), plane_ctl);
  262. I915_WRITE_FW(PLANE_SURF(pipe, plane_id),
  263. intel_plane_ggtt_offset(plane_state) + surf_addr);
  264. POSTING_READ_FW(PLANE_SURF(pipe, plane_id));
  265. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  266. }
  267. static void
  268. skl_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc)
  269. {
  270. struct drm_device *dev = dplane->dev;
  271. struct drm_i915_private *dev_priv = to_i915(dev);
  272. struct intel_plane *intel_plane = to_intel_plane(dplane);
  273. enum plane_id plane_id = intel_plane->id;
  274. enum pipe pipe = intel_plane->pipe;
  275. unsigned long irqflags;
  276. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  277. I915_WRITE_FW(PLANE_CTL(pipe, plane_id), 0);
  278. I915_WRITE_FW(PLANE_SURF(pipe, plane_id), 0);
  279. POSTING_READ_FW(PLANE_SURF(pipe, plane_id));
  280. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  281. }
  282. static void
  283. chv_update_csc(struct intel_plane *intel_plane, uint32_t format)
  284. {
  285. struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
  286. enum plane_id plane_id = intel_plane->id;
  287. /* Seems RGB data bypasses the CSC always */
  288. if (!format_is_yuv(format))
  289. return;
  290. /*
  291. * BT.601 limited range YCbCr -> full range RGB
  292. *
  293. * |r| | 6537 4769 0| |cr |
  294. * |g| = |-3330 4769 -1605| x |y-64|
  295. * |b| | 0 4769 8263| |cb |
  296. *
  297. * Cb and Cr apparently come in as signed already, so no
  298. * need for any offset. For Y we need to remove the offset.
  299. */
  300. I915_WRITE_FW(SPCSCYGOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(-64));
  301. I915_WRITE_FW(SPCSCCBOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
  302. I915_WRITE_FW(SPCSCCROFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
  303. I915_WRITE_FW(SPCSCC01(plane_id), SPCSC_C1(4769) | SPCSC_C0(6537));
  304. I915_WRITE_FW(SPCSCC23(plane_id), SPCSC_C1(-3330) | SPCSC_C0(0));
  305. I915_WRITE_FW(SPCSCC45(plane_id), SPCSC_C1(-1605) | SPCSC_C0(4769));
  306. I915_WRITE_FW(SPCSCC67(plane_id), SPCSC_C1(4769) | SPCSC_C0(0));
  307. I915_WRITE_FW(SPCSCC8(plane_id), SPCSC_C0(8263));
  308. I915_WRITE_FW(SPCSCYGICLAMP(plane_id), SPCSC_IMAX(940) | SPCSC_IMIN(64));
  309. I915_WRITE_FW(SPCSCCBICLAMP(plane_id), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
  310. I915_WRITE_FW(SPCSCCRICLAMP(plane_id), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
  311. I915_WRITE_FW(SPCSCYGOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
  312. I915_WRITE_FW(SPCSCCBOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
  313. I915_WRITE_FW(SPCSCCROCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
  314. }
  315. static u32 vlv_sprite_ctl(const struct intel_crtc_state *crtc_state,
  316. const struct intel_plane_state *plane_state)
  317. {
  318. const struct drm_framebuffer *fb = plane_state->base.fb;
  319. unsigned int rotation = plane_state->base.rotation;
  320. const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
  321. u32 sprctl;
  322. sprctl = SP_ENABLE | SP_GAMMA_ENABLE;
  323. switch (fb->format->format) {
  324. case DRM_FORMAT_YUYV:
  325. sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
  326. break;
  327. case DRM_FORMAT_YVYU:
  328. sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
  329. break;
  330. case DRM_FORMAT_UYVY:
  331. sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
  332. break;
  333. case DRM_FORMAT_VYUY:
  334. sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
  335. break;
  336. case DRM_FORMAT_RGB565:
  337. sprctl |= SP_FORMAT_BGR565;
  338. break;
  339. case DRM_FORMAT_XRGB8888:
  340. sprctl |= SP_FORMAT_BGRX8888;
  341. break;
  342. case DRM_FORMAT_ARGB8888:
  343. sprctl |= SP_FORMAT_BGRA8888;
  344. break;
  345. case DRM_FORMAT_XBGR2101010:
  346. sprctl |= SP_FORMAT_RGBX1010102;
  347. break;
  348. case DRM_FORMAT_ABGR2101010:
  349. sprctl |= SP_FORMAT_RGBA1010102;
  350. break;
  351. case DRM_FORMAT_XBGR8888:
  352. sprctl |= SP_FORMAT_RGBX8888;
  353. break;
  354. case DRM_FORMAT_ABGR8888:
  355. sprctl |= SP_FORMAT_RGBA8888;
  356. break;
  357. default:
  358. MISSING_CASE(fb->format->format);
  359. return 0;
  360. }
  361. if (fb->modifier == I915_FORMAT_MOD_X_TILED)
  362. sprctl |= SP_TILED;
  363. if (rotation & DRM_ROTATE_180)
  364. sprctl |= SP_ROTATE_180;
  365. if (rotation & DRM_REFLECT_X)
  366. sprctl |= SP_MIRROR;
  367. if (key->flags & I915_SET_COLORKEY_SOURCE)
  368. sprctl |= SP_SOURCE_KEY;
  369. return sprctl;
  370. }
  371. static void
  372. vlv_update_plane(struct drm_plane *dplane,
  373. const struct intel_crtc_state *crtc_state,
  374. const struct intel_plane_state *plane_state)
  375. {
  376. struct drm_device *dev = dplane->dev;
  377. struct drm_i915_private *dev_priv = to_i915(dev);
  378. struct intel_plane *intel_plane = to_intel_plane(dplane);
  379. struct drm_framebuffer *fb = plane_state->base.fb;
  380. enum pipe pipe = intel_plane->pipe;
  381. enum plane_id plane_id = intel_plane->id;
  382. u32 sprctl = plane_state->ctl;
  383. u32 sprsurf_offset = plane_state->main.offset;
  384. u32 linear_offset;
  385. const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
  386. int crtc_x = plane_state->base.dst.x1;
  387. int crtc_y = plane_state->base.dst.y1;
  388. uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
  389. uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
  390. uint32_t x = plane_state->main.x;
  391. uint32_t y = plane_state->main.y;
  392. unsigned long irqflags;
  393. /* Sizes are 0 based */
  394. crtc_w--;
  395. crtc_h--;
  396. linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
  397. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  398. if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B)
  399. chv_update_csc(intel_plane, fb->format->format);
  400. if (key->flags) {
  401. I915_WRITE_FW(SPKEYMINVAL(pipe, plane_id), key->min_value);
  402. I915_WRITE_FW(SPKEYMAXVAL(pipe, plane_id), key->max_value);
  403. I915_WRITE_FW(SPKEYMSK(pipe, plane_id), key->channel_mask);
  404. }
  405. I915_WRITE_FW(SPSTRIDE(pipe, plane_id), fb->pitches[0]);
  406. I915_WRITE_FW(SPPOS(pipe, plane_id), (crtc_y << 16) | crtc_x);
  407. if (fb->modifier == I915_FORMAT_MOD_X_TILED)
  408. I915_WRITE_FW(SPTILEOFF(pipe, plane_id), (y << 16) | x);
  409. else
  410. I915_WRITE_FW(SPLINOFF(pipe, plane_id), linear_offset);
  411. I915_WRITE_FW(SPCONSTALPHA(pipe, plane_id), 0);
  412. I915_WRITE_FW(SPSIZE(pipe, plane_id), (crtc_h << 16) | crtc_w);
  413. I915_WRITE_FW(SPCNTR(pipe, plane_id), sprctl);
  414. I915_WRITE_FW(SPSURF(pipe, plane_id),
  415. intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
  416. POSTING_READ_FW(SPSURF(pipe, plane_id));
  417. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  418. }
  419. static void
  420. vlv_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc)
  421. {
  422. struct drm_device *dev = dplane->dev;
  423. struct drm_i915_private *dev_priv = to_i915(dev);
  424. struct intel_plane *intel_plane = to_intel_plane(dplane);
  425. enum pipe pipe = intel_plane->pipe;
  426. enum plane_id plane_id = intel_plane->id;
  427. unsigned long irqflags;
  428. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  429. I915_WRITE_FW(SPCNTR(pipe, plane_id), 0);
  430. I915_WRITE_FW(SPSURF(pipe, plane_id), 0);
  431. POSTING_READ_FW(SPSURF(pipe, plane_id));
  432. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  433. }
  434. static u32 ivb_sprite_ctl(const struct intel_crtc_state *crtc_state,
  435. const struct intel_plane_state *plane_state)
  436. {
  437. struct drm_i915_private *dev_priv =
  438. to_i915(plane_state->base.plane->dev);
  439. const struct drm_framebuffer *fb = plane_state->base.fb;
  440. unsigned int rotation = plane_state->base.rotation;
  441. const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
  442. u32 sprctl;
  443. sprctl = SPRITE_ENABLE | SPRITE_GAMMA_ENABLE;
  444. if (IS_IVYBRIDGE(dev_priv))
  445. sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
  446. if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  447. sprctl |= SPRITE_PIPE_CSC_ENABLE;
  448. switch (fb->format->format) {
  449. case DRM_FORMAT_XBGR8888:
  450. sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
  451. break;
  452. case DRM_FORMAT_XRGB8888:
  453. sprctl |= SPRITE_FORMAT_RGBX888;
  454. break;
  455. case DRM_FORMAT_YUYV:
  456. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
  457. break;
  458. case DRM_FORMAT_YVYU:
  459. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
  460. break;
  461. case DRM_FORMAT_UYVY:
  462. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
  463. break;
  464. case DRM_FORMAT_VYUY:
  465. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
  466. break;
  467. default:
  468. MISSING_CASE(fb->format->format);
  469. return 0;
  470. }
  471. if (fb->modifier == I915_FORMAT_MOD_X_TILED)
  472. sprctl |= SPRITE_TILED;
  473. if (rotation & DRM_ROTATE_180)
  474. sprctl |= SPRITE_ROTATE_180;
  475. if (key->flags & I915_SET_COLORKEY_DESTINATION)
  476. sprctl |= SPRITE_DEST_KEY;
  477. else if (key->flags & I915_SET_COLORKEY_SOURCE)
  478. sprctl |= SPRITE_SOURCE_KEY;
  479. return sprctl;
  480. }
  481. static void
  482. ivb_update_plane(struct drm_plane *plane,
  483. const struct intel_crtc_state *crtc_state,
  484. const struct intel_plane_state *plane_state)
  485. {
  486. struct drm_device *dev = plane->dev;
  487. struct drm_i915_private *dev_priv = to_i915(dev);
  488. struct intel_plane *intel_plane = to_intel_plane(plane);
  489. struct drm_framebuffer *fb = plane_state->base.fb;
  490. enum pipe pipe = intel_plane->pipe;
  491. u32 sprctl = plane_state->ctl, sprscale = 0;
  492. u32 sprsurf_offset = plane_state->main.offset;
  493. u32 linear_offset;
  494. const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
  495. int crtc_x = plane_state->base.dst.x1;
  496. int crtc_y = plane_state->base.dst.y1;
  497. uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
  498. uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
  499. uint32_t x = plane_state->main.x;
  500. uint32_t y = plane_state->main.y;
  501. uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
  502. uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
  503. unsigned long irqflags;
  504. /* Sizes are 0 based */
  505. src_w--;
  506. src_h--;
  507. crtc_w--;
  508. crtc_h--;
  509. if (crtc_w != src_w || crtc_h != src_h)
  510. sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
  511. linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
  512. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  513. if (key->flags) {
  514. I915_WRITE_FW(SPRKEYVAL(pipe), key->min_value);
  515. I915_WRITE_FW(SPRKEYMAX(pipe), key->max_value);
  516. I915_WRITE_FW(SPRKEYMSK(pipe), key->channel_mask);
  517. }
  518. I915_WRITE_FW(SPRSTRIDE(pipe), fb->pitches[0]);
  519. I915_WRITE_FW(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
  520. /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
  521. * register */
  522. if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  523. I915_WRITE_FW(SPROFFSET(pipe), (y << 16) | x);
  524. else if (fb->modifier == I915_FORMAT_MOD_X_TILED)
  525. I915_WRITE_FW(SPRTILEOFF(pipe), (y << 16) | x);
  526. else
  527. I915_WRITE_FW(SPRLINOFF(pipe), linear_offset);
  528. I915_WRITE_FW(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
  529. if (intel_plane->can_scale)
  530. I915_WRITE_FW(SPRSCALE(pipe), sprscale);
  531. I915_WRITE_FW(SPRCTL(pipe), sprctl);
  532. I915_WRITE_FW(SPRSURF(pipe),
  533. intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
  534. POSTING_READ_FW(SPRSURF(pipe));
  535. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  536. }
  537. static void
  538. ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
  539. {
  540. struct drm_device *dev = plane->dev;
  541. struct drm_i915_private *dev_priv = to_i915(dev);
  542. struct intel_plane *intel_plane = to_intel_plane(plane);
  543. int pipe = intel_plane->pipe;
  544. unsigned long irqflags;
  545. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  546. I915_WRITE_FW(SPRCTL(pipe), 0);
  547. /* Can't leave the scaler enabled... */
  548. if (intel_plane->can_scale)
  549. I915_WRITE_FW(SPRSCALE(pipe), 0);
  550. I915_WRITE_FW(SPRSURF(pipe), 0);
  551. POSTING_READ_FW(SPRSURF(pipe));
  552. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  553. }
  554. static u32 ilk_sprite_ctl(const struct intel_crtc_state *crtc_state,
  555. const struct intel_plane_state *plane_state)
  556. {
  557. struct drm_i915_private *dev_priv =
  558. to_i915(plane_state->base.plane->dev);
  559. const struct drm_framebuffer *fb = plane_state->base.fb;
  560. unsigned int rotation = plane_state->base.rotation;
  561. const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
  562. u32 dvscntr;
  563. dvscntr = DVS_ENABLE | DVS_GAMMA_ENABLE;
  564. if (IS_GEN6(dev_priv))
  565. dvscntr |= DVS_TRICKLE_FEED_DISABLE;
  566. switch (fb->format->format) {
  567. case DRM_FORMAT_XBGR8888:
  568. dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
  569. break;
  570. case DRM_FORMAT_XRGB8888:
  571. dvscntr |= DVS_FORMAT_RGBX888;
  572. break;
  573. case DRM_FORMAT_YUYV:
  574. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
  575. break;
  576. case DRM_FORMAT_YVYU:
  577. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
  578. break;
  579. case DRM_FORMAT_UYVY:
  580. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
  581. break;
  582. case DRM_FORMAT_VYUY:
  583. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
  584. break;
  585. default:
  586. MISSING_CASE(fb->format->format);
  587. return 0;
  588. }
  589. if (fb->modifier == I915_FORMAT_MOD_X_TILED)
  590. dvscntr |= DVS_TILED;
  591. if (rotation & DRM_ROTATE_180)
  592. dvscntr |= DVS_ROTATE_180;
  593. if (key->flags & I915_SET_COLORKEY_DESTINATION)
  594. dvscntr |= DVS_DEST_KEY;
  595. else if (key->flags & I915_SET_COLORKEY_SOURCE)
  596. dvscntr |= DVS_SOURCE_KEY;
  597. return dvscntr;
  598. }
  599. static void
  600. ilk_update_plane(struct drm_plane *plane,
  601. const struct intel_crtc_state *crtc_state,
  602. const struct intel_plane_state *plane_state)
  603. {
  604. struct drm_device *dev = plane->dev;
  605. struct drm_i915_private *dev_priv = to_i915(dev);
  606. struct intel_plane *intel_plane = to_intel_plane(plane);
  607. struct drm_framebuffer *fb = plane_state->base.fb;
  608. int pipe = intel_plane->pipe;
  609. u32 dvscntr = plane_state->ctl, dvsscale = 0;
  610. u32 dvssurf_offset = plane_state->main.offset;
  611. u32 linear_offset;
  612. const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
  613. int crtc_x = plane_state->base.dst.x1;
  614. int crtc_y = plane_state->base.dst.y1;
  615. uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
  616. uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
  617. uint32_t x = plane_state->main.x;
  618. uint32_t y = plane_state->main.y;
  619. uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
  620. uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
  621. unsigned long irqflags;
  622. /* Sizes are 0 based */
  623. src_w--;
  624. src_h--;
  625. crtc_w--;
  626. crtc_h--;
  627. if (crtc_w != src_w || crtc_h != src_h)
  628. dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
  629. linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
  630. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  631. if (key->flags) {
  632. I915_WRITE_FW(DVSKEYVAL(pipe), key->min_value);
  633. I915_WRITE_FW(DVSKEYMAX(pipe), key->max_value);
  634. I915_WRITE_FW(DVSKEYMSK(pipe), key->channel_mask);
  635. }
  636. I915_WRITE_FW(DVSSTRIDE(pipe), fb->pitches[0]);
  637. I915_WRITE_FW(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
  638. if (fb->modifier == I915_FORMAT_MOD_X_TILED)
  639. I915_WRITE_FW(DVSTILEOFF(pipe), (y << 16) | x);
  640. else
  641. I915_WRITE_FW(DVSLINOFF(pipe), linear_offset);
  642. I915_WRITE_FW(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
  643. I915_WRITE_FW(DVSSCALE(pipe), dvsscale);
  644. I915_WRITE_FW(DVSCNTR(pipe), dvscntr);
  645. I915_WRITE_FW(DVSSURF(pipe),
  646. intel_plane_ggtt_offset(plane_state) + dvssurf_offset);
  647. POSTING_READ_FW(DVSSURF(pipe));
  648. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  649. }
  650. static void
  651. ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
  652. {
  653. struct drm_device *dev = plane->dev;
  654. struct drm_i915_private *dev_priv = to_i915(dev);
  655. struct intel_plane *intel_plane = to_intel_plane(plane);
  656. int pipe = intel_plane->pipe;
  657. unsigned long irqflags;
  658. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  659. I915_WRITE_FW(DVSCNTR(pipe), 0);
  660. /* Disable the scaler */
  661. I915_WRITE_FW(DVSSCALE(pipe), 0);
  662. I915_WRITE_FW(DVSSURF(pipe), 0);
  663. POSTING_READ_FW(DVSSURF(pipe));
  664. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  665. }
  666. static int
  667. intel_check_sprite_plane(struct drm_plane *plane,
  668. struct intel_crtc_state *crtc_state,
  669. struct intel_plane_state *state)
  670. {
  671. struct drm_i915_private *dev_priv = to_i915(plane->dev);
  672. struct drm_crtc *crtc = state->base.crtc;
  673. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  674. struct intel_plane *intel_plane = to_intel_plane(plane);
  675. struct drm_framebuffer *fb = state->base.fb;
  676. int crtc_x, crtc_y;
  677. unsigned int crtc_w, crtc_h;
  678. uint32_t src_x, src_y, src_w, src_h;
  679. struct drm_rect *src = &state->base.src;
  680. struct drm_rect *dst = &state->base.dst;
  681. const struct drm_rect *clip = &state->clip;
  682. int hscale, vscale;
  683. int max_scale, min_scale;
  684. bool can_scale;
  685. int ret;
  686. *src = drm_plane_state_src(&state->base);
  687. *dst = drm_plane_state_dest(&state->base);
  688. if (!fb) {
  689. state->base.visible = false;
  690. return 0;
  691. }
  692. /* Don't modify another pipe's plane */
  693. if (intel_plane->pipe != intel_crtc->pipe) {
  694. DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
  695. return -EINVAL;
  696. }
  697. /* FIXME check all gen limits */
  698. if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
  699. DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
  700. return -EINVAL;
  701. }
  702. /* setup can_scale, min_scale, max_scale */
  703. if (INTEL_GEN(dev_priv) >= 9) {
  704. /* use scaler when colorkey is not required */
  705. if (state->ckey.flags == I915_SET_COLORKEY_NONE) {
  706. can_scale = 1;
  707. min_scale = 1;
  708. max_scale = skl_max_scale(intel_crtc, crtc_state);
  709. } else {
  710. can_scale = 0;
  711. min_scale = DRM_PLANE_HELPER_NO_SCALING;
  712. max_scale = DRM_PLANE_HELPER_NO_SCALING;
  713. }
  714. } else {
  715. can_scale = intel_plane->can_scale;
  716. max_scale = intel_plane->max_downscale << 16;
  717. min_scale = intel_plane->can_scale ? 1 : (1 << 16);
  718. }
  719. /*
  720. * FIXME the following code does a bunch of fuzzy adjustments to the
  721. * coordinates and sizes. We probably need some way to decide whether
  722. * more strict checking should be done instead.
  723. */
  724. drm_rect_rotate(src, fb->width << 16, fb->height << 16,
  725. state->base.rotation);
  726. hscale = drm_rect_calc_hscale_relaxed(src, dst, min_scale, max_scale);
  727. BUG_ON(hscale < 0);
  728. vscale = drm_rect_calc_vscale_relaxed(src, dst, min_scale, max_scale);
  729. BUG_ON(vscale < 0);
  730. state->base.visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale);
  731. crtc_x = dst->x1;
  732. crtc_y = dst->y1;
  733. crtc_w = drm_rect_width(dst);
  734. crtc_h = drm_rect_height(dst);
  735. if (state->base.visible) {
  736. /* check again in case clipping clamped the results */
  737. hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale);
  738. if (hscale < 0) {
  739. DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
  740. drm_rect_debug_print("src: ", src, true);
  741. drm_rect_debug_print("dst: ", dst, false);
  742. return hscale;
  743. }
  744. vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale);
  745. if (vscale < 0) {
  746. DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
  747. drm_rect_debug_print("src: ", src, true);
  748. drm_rect_debug_print("dst: ", dst, false);
  749. return vscale;
  750. }
  751. /* Make the source viewport size an exact multiple of the scaling factors. */
  752. drm_rect_adjust_size(src,
  753. drm_rect_width(dst) * hscale - drm_rect_width(src),
  754. drm_rect_height(dst) * vscale - drm_rect_height(src));
  755. drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16,
  756. state->base.rotation);
  757. /* sanity check to make sure the src viewport wasn't enlarged */
  758. WARN_ON(src->x1 < (int) state->base.src_x ||
  759. src->y1 < (int) state->base.src_y ||
  760. src->x2 > (int) state->base.src_x + state->base.src_w ||
  761. src->y2 > (int) state->base.src_y + state->base.src_h);
  762. /*
  763. * Hardware doesn't handle subpixel coordinates.
  764. * Adjust to (macro)pixel boundary, but be careful not to
  765. * increase the source viewport size, because that could
  766. * push the downscaling factor out of bounds.
  767. */
  768. src_x = src->x1 >> 16;
  769. src_w = drm_rect_width(src) >> 16;
  770. src_y = src->y1 >> 16;
  771. src_h = drm_rect_height(src) >> 16;
  772. if (format_is_yuv(fb->format->format)) {
  773. src_x &= ~1;
  774. src_w &= ~1;
  775. /*
  776. * Must keep src and dst the
  777. * same if we can't scale.
  778. */
  779. if (!can_scale)
  780. crtc_w &= ~1;
  781. if (crtc_w == 0)
  782. state->base.visible = false;
  783. }
  784. }
  785. /* Check size restrictions when scaling */
  786. if (state->base.visible && (src_w != crtc_w || src_h != crtc_h)) {
  787. unsigned int width_bytes;
  788. int cpp = fb->format->cpp[0];
  789. WARN_ON(!can_scale);
  790. /* FIXME interlacing min height is 6 */
  791. if (crtc_w < 3 || crtc_h < 3)
  792. state->base.visible = false;
  793. if (src_w < 3 || src_h < 3)
  794. state->base.visible = false;
  795. width_bytes = ((src_x * cpp) & 63) + src_w * cpp;
  796. if (INTEL_GEN(dev_priv) < 9 && (src_w > 2048 || src_h > 2048 ||
  797. width_bytes > 4096 || fb->pitches[0] > 4096)) {
  798. DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
  799. return -EINVAL;
  800. }
  801. }
  802. if (state->base.visible) {
  803. src->x1 = src_x << 16;
  804. src->x2 = (src_x + src_w) << 16;
  805. src->y1 = src_y << 16;
  806. src->y2 = (src_y + src_h) << 16;
  807. }
  808. dst->x1 = crtc_x;
  809. dst->x2 = crtc_x + crtc_w;
  810. dst->y1 = crtc_y;
  811. dst->y2 = crtc_y + crtc_h;
  812. if (INTEL_GEN(dev_priv) >= 9) {
  813. ret = skl_check_plane_surface(state);
  814. if (ret)
  815. return ret;
  816. state->ctl = skl_plane_ctl(crtc_state, state);
  817. } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  818. ret = i9xx_check_plane_surface(state);
  819. if (ret)
  820. return ret;
  821. state->ctl = vlv_sprite_ctl(crtc_state, state);
  822. } else if (INTEL_GEN(dev_priv) >= 7) {
  823. ret = i9xx_check_plane_surface(state);
  824. if (ret)
  825. return ret;
  826. state->ctl = ivb_sprite_ctl(crtc_state, state);
  827. } else {
  828. ret = i9xx_check_plane_surface(state);
  829. if (ret)
  830. return ret;
  831. state->ctl = ilk_sprite_ctl(crtc_state, state);
  832. }
  833. return 0;
  834. }
  835. int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
  836. struct drm_file *file_priv)
  837. {
  838. struct drm_i915_private *dev_priv = to_i915(dev);
  839. struct drm_intel_sprite_colorkey *set = data;
  840. struct drm_plane *plane;
  841. struct drm_plane_state *plane_state;
  842. struct drm_atomic_state *state;
  843. struct drm_modeset_acquire_ctx ctx;
  844. int ret = 0;
  845. /* Make sure we don't try to enable both src & dest simultaneously */
  846. if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
  847. return -EINVAL;
  848. if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
  849. set->flags & I915_SET_COLORKEY_DESTINATION)
  850. return -EINVAL;
  851. plane = drm_plane_find(dev, set->plane_id);
  852. if (!plane || plane->type != DRM_PLANE_TYPE_OVERLAY)
  853. return -ENOENT;
  854. drm_modeset_acquire_init(&ctx, 0);
  855. state = drm_atomic_state_alloc(plane->dev);
  856. if (!state) {
  857. ret = -ENOMEM;
  858. goto out;
  859. }
  860. state->acquire_ctx = &ctx;
  861. while (1) {
  862. plane_state = drm_atomic_get_plane_state(state, plane);
  863. ret = PTR_ERR_OR_ZERO(plane_state);
  864. if (!ret) {
  865. to_intel_plane_state(plane_state)->ckey = *set;
  866. ret = drm_atomic_commit(state);
  867. }
  868. if (ret != -EDEADLK)
  869. break;
  870. drm_atomic_state_clear(state);
  871. drm_modeset_backoff(&ctx);
  872. }
  873. drm_atomic_state_put(state);
  874. out:
  875. drm_modeset_drop_locks(&ctx);
  876. drm_modeset_acquire_fini(&ctx);
  877. return ret;
  878. }
  879. static const uint32_t ilk_plane_formats[] = {
  880. DRM_FORMAT_XRGB8888,
  881. DRM_FORMAT_YUYV,
  882. DRM_FORMAT_YVYU,
  883. DRM_FORMAT_UYVY,
  884. DRM_FORMAT_VYUY,
  885. };
  886. static const uint32_t snb_plane_formats[] = {
  887. DRM_FORMAT_XBGR8888,
  888. DRM_FORMAT_XRGB8888,
  889. DRM_FORMAT_YUYV,
  890. DRM_FORMAT_YVYU,
  891. DRM_FORMAT_UYVY,
  892. DRM_FORMAT_VYUY,
  893. };
  894. static const uint32_t vlv_plane_formats[] = {
  895. DRM_FORMAT_RGB565,
  896. DRM_FORMAT_ABGR8888,
  897. DRM_FORMAT_ARGB8888,
  898. DRM_FORMAT_XBGR8888,
  899. DRM_FORMAT_XRGB8888,
  900. DRM_FORMAT_XBGR2101010,
  901. DRM_FORMAT_ABGR2101010,
  902. DRM_FORMAT_YUYV,
  903. DRM_FORMAT_YVYU,
  904. DRM_FORMAT_UYVY,
  905. DRM_FORMAT_VYUY,
  906. };
  907. static uint32_t skl_plane_formats[] = {
  908. DRM_FORMAT_RGB565,
  909. DRM_FORMAT_ABGR8888,
  910. DRM_FORMAT_ARGB8888,
  911. DRM_FORMAT_XBGR8888,
  912. DRM_FORMAT_XRGB8888,
  913. DRM_FORMAT_YUYV,
  914. DRM_FORMAT_YVYU,
  915. DRM_FORMAT_UYVY,
  916. DRM_FORMAT_VYUY,
  917. };
  918. struct intel_plane *
  919. intel_sprite_plane_create(struct drm_i915_private *dev_priv,
  920. enum pipe pipe, int plane)
  921. {
  922. struct intel_plane *intel_plane = NULL;
  923. struct intel_plane_state *state = NULL;
  924. unsigned long possible_crtcs;
  925. const uint32_t *plane_formats;
  926. unsigned int supported_rotations;
  927. int num_plane_formats;
  928. int ret;
  929. intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL);
  930. if (!intel_plane) {
  931. ret = -ENOMEM;
  932. goto fail;
  933. }
  934. state = intel_create_plane_state(&intel_plane->base);
  935. if (!state) {
  936. ret = -ENOMEM;
  937. goto fail;
  938. }
  939. intel_plane->base.state = &state->base;
  940. if (INTEL_GEN(dev_priv) >= 9) {
  941. intel_plane->can_scale = true;
  942. state->scaler_id = -1;
  943. intel_plane->update_plane = skl_update_plane;
  944. intel_plane->disable_plane = skl_disable_plane;
  945. plane_formats = skl_plane_formats;
  946. num_plane_formats = ARRAY_SIZE(skl_plane_formats);
  947. } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  948. intel_plane->can_scale = false;
  949. intel_plane->max_downscale = 1;
  950. intel_plane->update_plane = vlv_update_plane;
  951. intel_plane->disable_plane = vlv_disable_plane;
  952. plane_formats = vlv_plane_formats;
  953. num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
  954. } else if (INTEL_GEN(dev_priv) >= 7) {
  955. if (IS_IVYBRIDGE(dev_priv)) {
  956. intel_plane->can_scale = true;
  957. intel_plane->max_downscale = 2;
  958. } else {
  959. intel_plane->can_scale = false;
  960. intel_plane->max_downscale = 1;
  961. }
  962. intel_plane->update_plane = ivb_update_plane;
  963. intel_plane->disable_plane = ivb_disable_plane;
  964. plane_formats = snb_plane_formats;
  965. num_plane_formats = ARRAY_SIZE(snb_plane_formats);
  966. } else {
  967. intel_plane->can_scale = true;
  968. intel_plane->max_downscale = 16;
  969. intel_plane->update_plane = ilk_update_plane;
  970. intel_plane->disable_plane = ilk_disable_plane;
  971. if (IS_GEN6(dev_priv)) {
  972. plane_formats = snb_plane_formats;
  973. num_plane_formats = ARRAY_SIZE(snb_plane_formats);
  974. } else {
  975. plane_formats = ilk_plane_formats;
  976. num_plane_formats = ARRAY_SIZE(ilk_plane_formats);
  977. }
  978. }
  979. if (INTEL_GEN(dev_priv) >= 9) {
  980. supported_rotations =
  981. DRM_ROTATE_0 | DRM_ROTATE_90 |
  982. DRM_ROTATE_180 | DRM_ROTATE_270;
  983. } else if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
  984. supported_rotations =
  985. DRM_ROTATE_0 | DRM_ROTATE_180 |
  986. DRM_REFLECT_X;
  987. } else {
  988. supported_rotations =
  989. DRM_ROTATE_0 | DRM_ROTATE_180;
  990. }
  991. intel_plane->pipe = pipe;
  992. intel_plane->plane = plane;
  993. intel_plane->id = PLANE_SPRITE0 + plane;
  994. intel_plane->frontbuffer_bit = INTEL_FRONTBUFFER_SPRITE(pipe, plane);
  995. intel_plane->check_plane = intel_check_sprite_plane;
  996. possible_crtcs = (1 << pipe);
  997. if (INTEL_GEN(dev_priv) >= 9)
  998. ret = drm_universal_plane_init(&dev_priv->drm, &intel_plane->base,
  999. possible_crtcs, &intel_plane_funcs,
  1000. plane_formats, num_plane_formats,
  1001. DRM_PLANE_TYPE_OVERLAY,
  1002. "plane %d%c", plane + 2, pipe_name(pipe));
  1003. else
  1004. ret = drm_universal_plane_init(&dev_priv->drm, &intel_plane->base,
  1005. possible_crtcs, &intel_plane_funcs,
  1006. plane_formats, num_plane_formats,
  1007. DRM_PLANE_TYPE_OVERLAY,
  1008. "sprite %c", sprite_name(pipe, plane));
  1009. if (ret)
  1010. goto fail;
  1011. drm_plane_create_rotation_property(&intel_plane->base,
  1012. DRM_ROTATE_0,
  1013. supported_rotations);
  1014. drm_plane_helper_add(&intel_plane->base, &intel_plane_helper_funcs);
  1015. return intel_plane;
  1016. fail:
  1017. kfree(state);
  1018. kfree(intel_plane);
  1019. return ERR_PTR(ret);
  1020. }