intel_sprite.c 34 KB

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