intel_sprite.c 35 KB

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