intel_sprite.c 32 KB

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