intel_sprite.c 33 KB

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