intel_sprite.c 33 KB

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