intel_sprite.c 33 KB

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