intel_sprite.c 32 KB

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