intel_sprite.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125
  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;
  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. rotation = plane_state->base.rotation;
  189. plane_ctl |= skl_plane_ctl_rotation(rotation);
  190. stride_div = intel_fb_stride_alignment(dev_priv, fb->modifier[0],
  191. fb->pixel_format);
  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. int cpp = drm_format_plane_cpp(fb->pixel_format, 0);
  209. /* stride: Surface height in tiles */
  210. tile_height = intel_tile_height(dev_priv, fb->modifier[0], cpp);
  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 (plane_state->scaler_id >= 0) {
  227. uint32_t ps_ctrl = 0;
  228. int scaler_id = plane_state->scaler_id;
  229. DRM_DEBUG_KMS("plane = %d PS_PLANE_SEL(plane) = 0x%x\n", plane,
  230. PS_PLANE_SEL(plane));
  231. ps_ctrl = PS_SCALER_EN | PS_PLANE_SEL(plane) | scaler->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. }
  257. static void
  258. chv_update_csc(struct intel_plane *intel_plane, uint32_t format)
  259. {
  260. struct drm_i915_private *dev_priv = intel_plane->base.dev->dev_private;
  261. int plane = intel_plane->plane;
  262. /* Seems RGB data bypasses the CSC always */
  263. if (!format_is_yuv(format))
  264. return;
  265. /*
  266. * BT.601 limited range YCbCr -> full range RGB
  267. *
  268. * |r| | 6537 4769 0| |cr |
  269. * |g| = |-3330 4769 -1605| x |y-64|
  270. * |b| | 0 4769 8263| |cb |
  271. *
  272. * Cb and Cr apparently come in as signed already, so no
  273. * need for any offset. For Y we need to remove the offset.
  274. */
  275. I915_WRITE(SPCSCYGOFF(plane), SPCSC_OOFF(0) | SPCSC_IOFF(-64));
  276. I915_WRITE(SPCSCCBOFF(plane), SPCSC_OOFF(0) | SPCSC_IOFF(0));
  277. I915_WRITE(SPCSCCROFF(plane), SPCSC_OOFF(0) | SPCSC_IOFF(0));
  278. I915_WRITE(SPCSCC01(plane), SPCSC_C1(4769) | SPCSC_C0(6537));
  279. I915_WRITE(SPCSCC23(plane), SPCSC_C1(-3330) | SPCSC_C0(0));
  280. I915_WRITE(SPCSCC45(plane), SPCSC_C1(-1605) | SPCSC_C0(4769));
  281. I915_WRITE(SPCSCC67(plane), SPCSC_C1(4769) | SPCSC_C0(0));
  282. I915_WRITE(SPCSCC8(plane), SPCSC_C0(8263));
  283. I915_WRITE(SPCSCYGICLAMP(plane), SPCSC_IMAX(940) | SPCSC_IMIN(64));
  284. I915_WRITE(SPCSCCBICLAMP(plane), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
  285. I915_WRITE(SPCSCCRICLAMP(plane), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
  286. I915_WRITE(SPCSCYGOCLAMP(plane), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
  287. I915_WRITE(SPCSCCBOCLAMP(plane), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
  288. I915_WRITE(SPCSCCROCLAMP(plane), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
  289. }
  290. static void
  291. vlv_update_plane(struct drm_plane *dplane,
  292. const struct intel_crtc_state *crtc_state,
  293. const struct intel_plane_state *plane_state)
  294. {
  295. struct drm_device *dev = dplane->dev;
  296. struct drm_i915_private *dev_priv = dev->dev_private;
  297. struct intel_plane *intel_plane = to_intel_plane(dplane);
  298. struct drm_framebuffer *fb = plane_state->base.fb;
  299. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  300. int pipe = intel_plane->pipe;
  301. int plane = intel_plane->plane;
  302. u32 sprctl;
  303. u32 sprsurf_offset, linear_offset;
  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(dev_priv, &x, &y,
  371. fb->modifier[0], cpp,
  372. fb->pitches[0]);
  373. linear_offset -= sprsurf_offset;
  374. if (plane_state->base.rotation == BIT(DRM_ROTATE_180)) {
  375. sprctl |= SP_ROTATE_180;
  376. x += src_w;
  377. y += src_h;
  378. linear_offset += src_h * fb->pitches[0] + src_w * cpp;
  379. }
  380. if (key->flags) {
  381. I915_WRITE(SPKEYMINVAL(pipe, plane), key->min_value);
  382. I915_WRITE(SPKEYMAXVAL(pipe, plane), key->max_value);
  383. I915_WRITE(SPKEYMSK(pipe, plane), key->channel_mask);
  384. }
  385. if (key->flags & I915_SET_COLORKEY_SOURCE)
  386. sprctl |= SP_SOURCE_KEY;
  387. if (IS_CHERRYVIEW(dev) && pipe == PIPE_B)
  388. chv_update_csc(intel_plane, fb->pixel_format);
  389. I915_WRITE(SPSTRIDE(pipe, plane), fb->pitches[0]);
  390. I915_WRITE(SPPOS(pipe, plane), (crtc_y << 16) | crtc_x);
  391. if (obj->tiling_mode != I915_TILING_NONE)
  392. I915_WRITE(SPTILEOFF(pipe, plane), (y << 16) | x);
  393. else
  394. I915_WRITE(SPLINOFF(pipe, plane), linear_offset);
  395. I915_WRITE(SPCONSTALPHA(pipe, plane), 0);
  396. I915_WRITE(SPSIZE(pipe, plane), (crtc_h << 16) | crtc_w);
  397. I915_WRITE(SPCNTR(pipe, plane), sprctl);
  398. I915_WRITE(SPSURF(pipe, plane), i915_gem_obj_ggtt_offset(obj) +
  399. sprsurf_offset);
  400. POSTING_READ(SPSURF(pipe, plane));
  401. }
  402. static void
  403. vlv_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc)
  404. {
  405. struct drm_device *dev = dplane->dev;
  406. struct drm_i915_private *dev_priv = dev->dev_private;
  407. struct intel_plane *intel_plane = to_intel_plane(dplane);
  408. int pipe = intel_plane->pipe;
  409. int plane = intel_plane->plane;
  410. I915_WRITE(SPCNTR(pipe, plane), 0);
  411. I915_WRITE(SPSURF(pipe, plane), 0);
  412. POSTING_READ(SPSURF(pipe, plane));
  413. }
  414. static void
  415. ivb_update_plane(struct drm_plane *plane,
  416. const struct intel_crtc_state *crtc_state,
  417. const struct intel_plane_state *plane_state)
  418. {
  419. struct drm_device *dev = plane->dev;
  420. struct drm_i915_private *dev_priv = dev->dev_private;
  421. struct intel_plane *intel_plane = to_intel_plane(plane);
  422. struct drm_framebuffer *fb = plane_state->base.fb;
  423. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  424. enum pipe pipe = intel_plane->pipe;
  425. u32 sprctl, sprscale = 0;
  426. u32 sprsurf_offset, linear_offset;
  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(dev_priv, &x, &y,
  482. fb->modifier[0], cpp,
  483. fb->pitches[0]);
  484. linear_offset -= sprsurf_offset;
  485. if (plane_state->base.rotation == BIT(DRM_ROTATE_180)) {
  486. sprctl |= SPRITE_ROTATE_180;
  487. /* HSW and BDW does this automagically in hardware */
  488. if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
  489. x += src_w;
  490. y += src_h;
  491. linear_offset += src_h * fb->pitches[0] + src_w * cpp;
  492. }
  493. }
  494. if (key->flags) {
  495. I915_WRITE(SPRKEYVAL(pipe), key->min_value);
  496. I915_WRITE(SPRKEYMAX(pipe), key->max_value);
  497. I915_WRITE(SPRKEYMSK(pipe), key->channel_mask);
  498. }
  499. if (key->flags & I915_SET_COLORKEY_DESTINATION)
  500. sprctl |= SPRITE_DEST_KEY;
  501. else if (key->flags & I915_SET_COLORKEY_SOURCE)
  502. sprctl |= SPRITE_SOURCE_KEY;
  503. I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]);
  504. I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
  505. /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
  506. * register */
  507. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  508. I915_WRITE(SPROFFSET(pipe), (y << 16) | x);
  509. else if (obj->tiling_mode != I915_TILING_NONE)
  510. I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x);
  511. else
  512. I915_WRITE(SPRLINOFF(pipe), linear_offset);
  513. I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
  514. if (intel_plane->can_scale)
  515. I915_WRITE(SPRSCALE(pipe), sprscale);
  516. I915_WRITE(SPRCTL(pipe), sprctl);
  517. I915_WRITE(SPRSURF(pipe),
  518. i915_gem_obj_ggtt_offset(obj) + sprsurf_offset);
  519. POSTING_READ(SPRSURF(pipe));
  520. }
  521. static void
  522. ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
  523. {
  524. struct drm_device *dev = plane->dev;
  525. struct drm_i915_private *dev_priv = dev->dev_private;
  526. struct intel_plane *intel_plane = to_intel_plane(plane);
  527. int pipe = intel_plane->pipe;
  528. I915_WRITE(SPRCTL(pipe), 0);
  529. /* Can't leave the scaler enabled... */
  530. if (intel_plane->can_scale)
  531. I915_WRITE(SPRSCALE(pipe), 0);
  532. I915_WRITE(SPRSURF(pipe), 0);
  533. POSTING_READ(SPRSURF(pipe));
  534. }
  535. static void
  536. ilk_update_plane(struct drm_plane *plane,
  537. const struct intel_crtc_state *crtc_state,
  538. const struct intel_plane_state *plane_state)
  539. {
  540. struct drm_device *dev = plane->dev;
  541. struct drm_i915_private *dev_priv = dev->dev_private;
  542. struct intel_plane *intel_plane = to_intel_plane(plane);
  543. struct drm_framebuffer *fb = plane_state->base.fb;
  544. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  545. int pipe = intel_plane->pipe;
  546. u32 dvscntr, dvsscale;
  547. u32 dvssurf_offset, linear_offset;
  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(dev_priv, &x, &y,
  600. fb->modifier[0], cpp,
  601. fb->pitches[0]);
  602. linear_offset -= dvssurf_offset;
  603. if (plane_state->base.rotation == BIT(DRM_ROTATE_180)) {
  604. dvscntr |= DVS_ROTATE_180;
  605. x += src_w;
  606. y += src_h;
  607. linear_offset += src_h * fb->pitches[0] + src_w * cpp;
  608. }
  609. if (key->flags) {
  610. I915_WRITE(DVSKEYVAL(pipe), key->min_value);
  611. I915_WRITE(DVSKEYMAX(pipe), key->max_value);
  612. I915_WRITE(DVSKEYMSK(pipe), key->channel_mask);
  613. }
  614. if (key->flags & I915_SET_COLORKEY_DESTINATION)
  615. dvscntr |= DVS_DEST_KEY;
  616. else if (key->flags & I915_SET_COLORKEY_SOURCE)
  617. dvscntr |= DVS_SOURCE_KEY;
  618. I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]);
  619. I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
  620. if (obj->tiling_mode != I915_TILING_NONE)
  621. I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x);
  622. else
  623. I915_WRITE(DVSLINOFF(pipe), linear_offset);
  624. I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
  625. I915_WRITE(DVSSCALE(pipe), dvsscale);
  626. I915_WRITE(DVSCNTR(pipe), dvscntr);
  627. I915_WRITE(DVSSURF(pipe),
  628. i915_gem_obj_ggtt_offset(obj) + dvssurf_offset);
  629. POSTING_READ(DVSSURF(pipe));
  630. }
  631. static void
  632. ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
  633. {
  634. struct drm_device *dev = plane->dev;
  635. struct drm_i915_private *dev_priv = dev->dev_private;
  636. struct intel_plane *intel_plane = to_intel_plane(plane);
  637. int pipe = intel_plane->pipe;
  638. I915_WRITE(DVSCNTR(pipe), 0);
  639. /* Disable the scaler */
  640. I915_WRITE(DVSSCALE(pipe), 0);
  641. I915_WRITE(DVSSURF(pipe), 0);
  642. POSTING_READ(DVSSURF(pipe));
  643. }
  644. static int
  645. intel_check_sprite_plane(struct drm_plane *plane,
  646. struct intel_crtc_state *crtc_state,
  647. struct intel_plane_state *state)
  648. {
  649. struct drm_device *dev = plane->dev;
  650. struct drm_crtc *crtc = state->base.crtc;
  651. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  652. struct intel_plane *intel_plane = to_intel_plane(plane);
  653. struct drm_framebuffer *fb = state->base.fb;
  654. int crtc_x, crtc_y;
  655. unsigned int crtc_w, crtc_h;
  656. uint32_t src_x, src_y, src_w, src_h;
  657. struct drm_rect *src = &state->src;
  658. struct drm_rect *dst = &state->dst;
  659. const struct drm_rect *clip = &state->clip;
  660. int hscale, vscale;
  661. int max_scale, min_scale;
  662. bool can_scale;
  663. if (!fb) {
  664. state->visible = false;
  665. return 0;
  666. }
  667. /* Don't modify another pipe's plane */
  668. if (intel_plane->pipe != intel_crtc->pipe) {
  669. DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
  670. return -EINVAL;
  671. }
  672. /* FIXME check all gen limits */
  673. if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
  674. DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
  675. return -EINVAL;
  676. }
  677. /* setup can_scale, min_scale, max_scale */
  678. if (INTEL_INFO(dev)->gen >= 9) {
  679. /* use scaler when colorkey is not required */
  680. if (state->ckey.flags == I915_SET_COLORKEY_NONE) {
  681. can_scale = 1;
  682. min_scale = 1;
  683. max_scale = skl_max_scale(intel_crtc, crtc_state);
  684. } else {
  685. can_scale = 0;
  686. min_scale = DRM_PLANE_HELPER_NO_SCALING;
  687. max_scale = DRM_PLANE_HELPER_NO_SCALING;
  688. }
  689. } else {
  690. can_scale = intel_plane->can_scale;
  691. max_scale = intel_plane->max_downscale << 16;
  692. min_scale = intel_plane->can_scale ? 1 : (1 << 16);
  693. }
  694. /*
  695. * FIXME the following code does a bunch of fuzzy adjustments to the
  696. * coordinates and sizes. We probably need some way to decide whether
  697. * more strict checking should be done instead.
  698. */
  699. drm_rect_rotate(src, fb->width << 16, fb->height << 16,
  700. state->base.rotation);
  701. hscale = drm_rect_calc_hscale_relaxed(src, dst, min_scale, max_scale);
  702. BUG_ON(hscale < 0);
  703. vscale = drm_rect_calc_vscale_relaxed(src, dst, min_scale, max_scale);
  704. BUG_ON(vscale < 0);
  705. state->visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale);
  706. crtc_x = dst->x1;
  707. crtc_y = dst->y1;
  708. crtc_w = drm_rect_width(dst);
  709. crtc_h = drm_rect_height(dst);
  710. if (state->visible) {
  711. /* check again in case clipping clamped the results */
  712. hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale);
  713. if (hscale < 0) {
  714. DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
  715. drm_rect_debug_print("src: ", src, true);
  716. drm_rect_debug_print("dst: ", dst, false);
  717. return hscale;
  718. }
  719. vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale);
  720. if (vscale < 0) {
  721. DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
  722. drm_rect_debug_print("src: ", src, true);
  723. drm_rect_debug_print("dst: ", dst, false);
  724. return vscale;
  725. }
  726. /* Make the source viewport size an exact multiple of the scaling factors. */
  727. drm_rect_adjust_size(src,
  728. drm_rect_width(dst) * hscale - drm_rect_width(src),
  729. drm_rect_height(dst) * vscale - drm_rect_height(src));
  730. drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16,
  731. state->base.rotation);
  732. /* sanity check to make sure the src viewport wasn't enlarged */
  733. WARN_ON(src->x1 < (int) state->base.src_x ||
  734. src->y1 < (int) state->base.src_y ||
  735. src->x2 > (int) state->base.src_x + state->base.src_w ||
  736. src->y2 > (int) state->base.src_y + state->base.src_h);
  737. /*
  738. * Hardware doesn't handle subpixel coordinates.
  739. * Adjust to (macro)pixel boundary, but be careful not to
  740. * increase the source viewport size, because that could
  741. * push the downscaling factor out of bounds.
  742. */
  743. src_x = src->x1 >> 16;
  744. src_w = drm_rect_width(src) >> 16;
  745. src_y = src->y1 >> 16;
  746. src_h = drm_rect_height(src) >> 16;
  747. if (format_is_yuv(fb->pixel_format)) {
  748. src_x &= ~1;
  749. src_w &= ~1;
  750. /*
  751. * Must keep src and dst the
  752. * same if we can't scale.
  753. */
  754. if (!can_scale)
  755. crtc_w &= ~1;
  756. if (crtc_w == 0)
  757. state->visible = false;
  758. }
  759. }
  760. /* Check size restrictions when scaling */
  761. if (state->visible && (src_w != crtc_w || src_h != crtc_h)) {
  762. unsigned int width_bytes;
  763. int cpp = drm_format_plane_cpp(fb->pixel_format, 0);
  764. WARN_ON(!can_scale);
  765. /* FIXME interlacing min height is 6 */
  766. if (crtc_w < 3 || crtc_h < 3)
  767. state->visible = false;
  768. if (src_w < 3 || src_h < 3)
  769. state->visible = false;
  770. width_bytes = ((src_x * cpp) & 63) + src_w * cpp;
  771. if (INTEL_INFO(dev)->gen < 9 && (src_w > 2048 || src_h > 2048 ||
  772. width_bytes > 4096 || fb->pitches[0] > 4096)) {
  773. DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
  774. return -EINVAL;
  775. }
  776. }
  777. if (state->visible) {
  778. src->x1 = src_x << 16;
  779. src->x2 = (src_x + src_w) << 16;
  780. src->y1 = src_y << 16;
  781. src->y2 = (src_y + src_h) << 16;
  782. }
  783. dst->x1 = crtc_x;
  784. dst->x2 = crtc_x + crtc_w;
  785. dst->y1 = crtc_y;
  786. dst->y2 = crtc_y + crtc_h;
  787. return 0;
  788. }
  789. int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
  790. struct drm_file *file_priv)
  791. {
  792. struct drm_intel_sprite_colorkey *set = data;
  793. struct drm_plane *plane;
  794. struct drm_plane_state *plane_state;
  795. struct drm_atomic_state *state;
  796. struct drm_modeset_acquire_ctx ctx;
  797. int ret = 0;
  798. /* Make sure we don't try to enable both src & dest simultaneously */
  799. if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
  800. return -EINVAL;
  801. if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
  802. set->flags & I915_SET_COLORKEY_DESTINATION)
  803. return -EINVAL;
  804. plane = drm_plane_find(dev, set->plane_id);
  805. if (!plane || plane->type != DRM_PLANE_TYPE_OVERLAY)
  806. return -ENOENT;
  807. drm_modeset_acquire_init(&ctx, 0);
  808. state = drm_atomic_state_alloc(plane->dev);
  809. if (!state) {
  810. ret = -ENOMEM;
  811. goto out;
  812. }
  813. state->acquire_ctx = &ctx;
  814. while (1) {
  815. plane_state = drm_atomic_get_plane_state(state, plane);
  816. ret = PTR_ERR_OR_ZERO(plane_state);
  817. if (!ret) {
  818. to_intel_plane_state(plane_state)->ckey = *set;
  819. ret = drm_atomic_commit(state);
  820. }
  821. if (ret != -EDEADLK)
  822. break;
  823. drm_atomic_state_clear(state);
  824. drm_modeset_backoff(&ctx);
  825. }
  826. if (ret)
  827. drm_atomic_state_free(state);
  828. out:
  829. drm_modeset_drop_locks(&ctx);
  830. drm_modeset_acquire_fini(&ctx);
  831. return ret;
  832. }
  833. static const uint32_t ilk_plane_formats[] = {
  834. DRM_FORMAT_XRGB8888,
  835. DRM_FORMAT_YUYV,
  836. DRM_FORMAT_YVYU,
  837. DRM_FORMAT_UYVY,
  838. DRM_FORMAT_VYUY,
  839. };
  840. static const uint32_t snb_plane_formats[] = {
  841. DRM_FORMAT_XBGR8888,
  842. DRM_FORMAT_XRGB8888,
  843. DRM_FORMAT_YUYV,
  844. DRM_FORMAT_YVYU,
  845. DRM_FORMAT_UYVY,
  846. DRM_FORMAT_VYUY,
  847. };
  848. static const uint32_t vlv_plane_formats[] = {
  849. DRM_FORMAT_RGB565,
  850. DRM_FORMAT_ABGR8888,
  851. DRM_FORMAT_ARGB8888,
  852. DRM_FORMAT_XBGR8888,
  853. DRM_FORMAT_XRGB8888,
  854. DRM_FORMAT_XBGR2101010,
  855. DRM_FORMAT_ABGR2101010,
  856. DRM_FORMAT_YUYV,
  857. DRM_FORMAT_YVYU,
  858. DRM_FORMAT_UYVY,
  859. DRM_FORMAT_VYUY,
  860. };
  861. static uint32_t skl_plane_formats[] = {
  862. DRM_FORMAT_RGB565,
  863. DRM_FORMAT_ABGR8888,
  864. DRM_FORMAT_ARGB8888,
  865. DRM_FORMAT_XBGR8888,
  866. DRM_FORMAT_XRGB8888,
  867. DRM_FORMAT_YUYV,
  868. DRM_FORMAT_YVYU,
  869. DRM_FORMAT_UYVY,
  870. DRM_FORMAT_VYUY,
  871. };
  872. int
  873. intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
  874. {
  875. struct intel_plane *intel_plane;
  876. struct intel_plane_state *state;
  877. unsigned long possible_crtcs;
  878. const uint32_t *plane_formats;
  879. int num_plane_formats;
  880. int ret;
  881. if (INTEL_INFO(dev)->gen < 5)
  882. return -ENODEV;
  883. intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL);
  884. if (!intel_plane)
  885. return -ENOMEM;
  886. state = intel_create_plane_state(&intel_plane->base);
  887. if (!state) {
  888. kfree(intel_plane);
  889. return -ENOMEM;
  890. }
  891. intel_plane->base.state = &state->base;
  892. switch (INTEL_INFO(dev)->gen) {
  893. case 5:
  894. case 6:
  895. intel_plane->can_scale = true;
  896. intel_plane->max_downscale = 16;
  897. intel_plane->update_plane = ilk_update_plane;
  898. intel_plane->disable_plane = ilk_disable_plane;
  899. if (IS_GEN6(dev)) {
  900. plane_formats = snb_plane_formats;
  901. num_plane_formats = ARRAY_SIZE(snb_plane_formats);
  902. } else {
  903. plane_formats = ilk_plane_formats;
  904. num_plane_formats = ARRAY_SIZE(ilk_plane_formats);
  905. }
  906. break;
  907. case 7:
  908. case 8:
  909. if (IS_IVYBRIDGE(dev)) {
  910. intel_plane->can_scale = true;
  911. intel_plane->max_downscale = 2;
  912. } else {
  913. intel_plane->can_scale = false;
  914. intel_plane->max_downscale = 1;
  915. }
  916. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  917. intel_plane->update_plane = vlv_update_plane;
  918. intel_plane->disable_plane = vlv_disable_plane;
  919. plane_formats = vlv_plane_formats;
  920. num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
  921. } else {
  922. intel_plane->update_plane = ivb_update_plane;
  923. intel_plane->disable_plane = ivb_disable_plane;
  924. plane_formats = snb_plane_formats;
  925. num_plane_formats = ARRAY_SIZE(snb_plane_formats);
  926. }
  927. break;
  928. case 9:
  929. intel_plane->can_scale = true;
  930. intel_plane->update_plane = skl_update_plane;
  931. intel_plane->disable_plane = skl_disable_plane;
  932. state->scaler_id = -1;
  933. plane_formats = skl_plane_formats;
  934. num_plane_formats = ARRAY_SIZE(skl_plane_formats);
  935. break;
  936. default:
  937. kfree(intel_plane);
  938. return -ENODEV;
  939. }
  940. intel_plane->pipe = pipe;
  941. intel_plane->plane = plane;
  942. intel_plane->frontbuffer_bit = INTEL_FRONTBUFFER_SPRITE(pipe, plane);
  943. intel_plane->check_plane = intel_check_sprite_plane;
  944. possible_crtcs = (1 << pipe);
  945. ret = drm_universal_plane_init(dev, &intel_plane->base, possible_crtcs,
  946. &intel_plane_funcs,
  947. plane_formats, num_plane_formats,
  948. DRM_PLANE_TYPE_OVERLAY, NULL);
  949. if (ret) {
  950. kfree(intel_plane);
  951. goto out;
  952. }
  953. intel_create_rotation_property(dev, intel_plane);
  954. drm_plane_helper_add(&intel_plane->base, &intel_plane_helper_funcs);
  955. out:
  956. return ret;
  957. }