intel_sprite.c 34 KB

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