intel_sprite.c 32 KB

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