intel_sprite.c 33 KB

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