intel_sprite.c 33 KB

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