intel_sprite.c 32 KB

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