intel_sprite.c 32 KB

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