intel_sprite.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  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 "intel_drv.h"
  37. #include <drm/i915_drm.h>
  38. #include "i915_drv.h"
  39. static void
  40. vlv_update_plane(struct drm_plane *dplane, struct drm_crtc *crtc,
  41. struct drm_framebuffer *fb,
  42. struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
  43. unsigned int crtc_w, unsigned int crtc_h,
  44. uint32_t x, uint32_t y,
  45. uint32_t src_w, uint32_t src_h)
  46. {
  47. struct drm_device *dev = dplane->dev;
  48. struct drm_i915_private *dev_priv = dev->dev_private;
  49. struct intel_plane *intel_plane = to_intel_plane(dplane);
  50. int pipe = intel_plane->pipe;
  51. int plane = intel_plane->plane;
  52. u32 sprctl;
  53. unsigned long sprsurf_offset, linear_offset;
  54. int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
  55. sprctl = I915_READ(SPCNTR(pipe, plane));
  56. /* Mask out pixel format bits in case we change it */
  57. sprctl &= ~SP_PIXFORMAT_MASK;
  58. sprctl &= ~SP_YUV_BYTE_ORDER_MASK;
  59. sprctl &= ~SP_TILED;
  60. switch (fb->pixel_format) {
  61. case DRM_FORMAT_YUYV:
  62. sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
  63. break;
  64. case DRM_FORMAT_YVYU:
  65. sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
  66. break;
  67. case DRM_FORMAT_UYVY:
  68. sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
  69. break;
  70. case DRM_FORMAT_VYUY:
  71. sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
  72. break;
  73. case DRM_FORMAT_RGB565:
  74. sprctl |= SP_FORMAT_BGR565;
  75. break;
  76. case DRM_FORMAT_XRGB8888:
  77. sprctl |= SP_FORMAT_BGRX8888;
  78. break;
  79. case DRM_FORMAT_ARGB8888:
  80. sprctl |= SP_FORMAT_BGRA8888;
  81. break;
  82. case DRM_FORMAT_XBGR2101010:
  83. sprctl |= SP_FORMAT_RGBX1010102;
  84. break;
  85. case DRM_FORMAT_ABGR2101010:
  86. sprctl |= SP_FORMAT_RGBA1010102;
  87. break;
  88. case DRM_FORMAT_XBGR8888:
  89. sprctl |= SP_FORMAT_RGBX8888;
  90. break;
  91. case DRM_FORMAT_ABGR8888:
  92. sprctl |= SP_FORMAT_RGBA8888;
  93. break;
  94. default:
  95. /*
  96. * If we get here one of the upper layers failed to filter
  97. * out the unsupported plane formats
  98. */
  99. BUG();
  100. break;
  101. }
  102. /*
  103. * Enable gamma to match primary/cursor plane behaviour.
  104. * FIXME should be user controllable via propertiesa.
  105. */
  106. sprctl |= SP_GAMMA_ENABLE;
  107. if (obj->tiling_mode != I915_TILING_NONE)
  108. sprctl |= SP_TILED;
  109. sprctl |= SP_ENABLE;
  110. intel_update_sprite_watermarks(dplane, crtc, src_w, pixel_size, true,
  111. src_w != crtc_w || src_h != crtc_h);
  112. /* Sizes are 0 based */
  113. src_w--;
  114. src_h--;
  115. crtc_w--;
  116. crtc_h--;
  117. I915_WRITE(SPSTRIDE(pipe, plane), fb->pitches[0]);
  118. I915_WRITE(SPPOS(pipe, plane), (crtc_y << 16) | crtc_x);
  119. linear_offset = y * fb->pitches[0] + x * pixel_size;
  120. sprsurf_offset = intel_gen4_compute_page_offset(&x, &y,
  121. obj->tiling_mode,
  122. pixel_size,
  123. fb->pitches[0]);
  124. linear_offset -= sprsurf_offset;
  125. if (obj->tiling_mode != I915_TILING_NONE)
  126. I915_WRITE(SPTILEOFF(pipe, plane), (y << 16) | x);
  127. else
  128. I915_WRITE(SPLINOFF(pipe, plane), linear_offset);
  129. I915_WRITE(SPSIZE(pipe, plane), (crtc_h << 16) | crtc_w);
  130. I915_WRITE(SPCNTR(pipe, plane), sprctl);
  131. I915_WRITE(SPSURF(pipe, plane), i915_gem_obj_ggtt_offset(obj) +
  132. sprsurf_offset);
  133. POSTING_READ(SPSURF(pipe, plane));
  134. }
  135. static void
  136. vlv_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc)
  137. {
  138. struct drm_device *dev = dplane->dev;
  139. struct drm_i915_private *dev_priv = dev->dev_private;
  140. struct intel_plane *intel_plane = to_intel_plane(dplane);
  141. int pipe = intel_plane->pipe;
  142. int plane = intel_plane->plane;
  143. I915_WRITE(SPCNTR(pipe, plane), I915_READ(SPCNTR(pipe, plane)) &
  144. ~SP_ENABLE);
  145. /* Activate double buffered register update */
  146. I915_WRITE(SPSURF(pipe, plane), 0);
  147. POSTING_READ(SPSURF(pipe, plane));
  148. intel_update_sprite_watermarks(dplane, crtc, 0, 0, false, false);
  149. }
  150. static int
  151. vlv_update_colorkey(struct drm_plane *dplane,
  152. struct drm_intel_sprite_colorkey *key)
  153. {
  154. struct drm_device *dev = dplane->dev;
  155. struct drm_i915_private *dev_priv = dev->dev_private;
  156. struct intel_plane *intel_plane = to_intel_plane(dplane);
  157. int pipe = intel_plane->pipe;
  158. int plane = intel_plane->plane;
  159. u32 sprctl;
  160. if (key->flags & I915_SET_COLORKEY_DESTINATION)
  161. return -EINVAL;
  162. I915_WRITE(SPKEYMINVAL(pipe, plane), key->min_value);
  163. I915_WRITE(SPKEYMAXVAL(pipe, plane), key->max_value);
  164. I915_WRITE(SPKEYMSK(pipe, plane), key->channel_mask);
  165. sprctl = I915_READ(SPCNTR(pipe, plane));
  166. sprctl &= ~SP_SOURCE_KEY;
  167. if (key->flags & I915_SET_COLORKEY_SOURCE)
  168. sprctl |= SP_SOURCE_KEY;
  169. I915_WRITE(SPCNTR(pipe, plane), sprctl);
  170. POSTING_READ(SPKEYMSK(pipe, plane));
  171. return 0;
  172. }
  173. static void
  174. vlv_get_colorkey(struct drm_plane *dplane,
  175. struct drm_intel_sprite_colorkey *key)
  176. {
  177. struct drm_device *dev = dplane->dev;
  178. struct drm_i915_private *dev_priv = dev->dev_private;
  179. struct intel_plane *intel_plane = to_intel_plane(dplane);
  180. int pipe = intel_plane->pipe;
  181. int plane = intel_plane->plane;
  182. u32 sprctl;
  183. key->min_value = I915_READ(SPKEYMINVAL(pipe, plane));
  184. key->max_value = I915_READ(SPKEYMAXVAL(pipe, plane));
  185. key->channel_mask = I915_READ(SPKEYMSK(pipe, plane));
  186. sprctl = I915_READ(SPCNTR(pipe, plane));
  187. if (sprctl & SP_SOURCE_KEY)
  188. key->flags = I915_SET_COLORKEY_SOURCE;
  189. else
  190. key->flags = I915_SET_COLORKEY_NONE;
  191. }
  192. static void
  193. ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
  194. struct drm_framebuffer *fb,
  195. struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
  196. unsigned int crtc_w, unsigned int crtc_h,
  197. uint32_t x, uint32_t y,
  198. uint32_t src_w, uint32_t src_h)
  199. {
  200. struct drm_device *dev = plane->dev;
  201. struct drm_i915_private *dev_priv = dev->dev_private;
  202. struct intel_plane *intel_plane = to_intel_plane(plane);
  203. int pipe = intel_plane->pipe;
  204. u32 sprctl, sprscale = 0;
  205. unsigned long sprsurf_offset, linear_offset;
  206. int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
  207. sprctl = I915_READ(SPRCTL(pipe));
  208. /* Mask out pixel format bits in case we change it */
  209. sprctl &= ~SPRITE_PIXFORMAT_MASK;
  210. sprctl &= ~SPRITE_RGB_ORDER_RGBX;
  211. sprctl &= ~SPRITE_YUV_BYTE_ORDER_MASK;
  212. sprctl &= ~SPRITE_TILED;
  213. switch (fb->pixel_format) {
  214. case DRM_FORMAT_XBGR8888:
  215. sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
  216. break;
  217. case DRM_FORMAT_XRGB8888:
  218. sprctl |= SPRITE_FORMAT_RGBX888;
  219. break;
  220. case DRM_FORMAT_YUYV:
  221. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
  222. break;
  223. case DRM_FORMAT_YVYU:
  224. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
  225. break;
  226. case DRM_FORMAT_UYVY:
  227. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
  228. break;
  229. case DRM_FORMAT_VYUY:
  230. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
  231. break;
  232. default:
  233. BUG();
  234. }
  235. /*
  236. * Enable gamma to match primary/cursor plane behaviour.
  237. * FIXME should be user controllable via propertiesa.
  238. */
  239. sprctl |= SPRITE_GAMMA_ENABLE;
  240. if (obj->tiling_mode != I915_TILING_NONE)
  241. sprctl |= SPRITE_TILED;
  242. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  243. sprctl &= ~SPRITE_TRICKLE_FEED_DISABLE;
  244. else
  245. sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
  246. sprctl |= SPRITE_ENABLE;
  247. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  248. sprctl |= SPRITE_PIPE_CSC_ENABLE;
  249. intel_update_sprite_watermarks(plane, crtc, src_w, pixel_size, true,
  250. src_w != crtc_w || src_h != crtc_h);
  251. /* Sizes are 0 based */
  252. src_w--;
  253. src_h--;
  254. crtc_w--;
  255. crtc_h--;
  256. if (crtc_w != src_w || crtc_h != src_h)
  257. sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
  258. I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]);
  259. I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
  260. linear_offset = y * fb->pitches[0] + x * pixel_size;
  261. sprsurf_offset =
  262. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  263. pixel_size, fb->pitches[0]);
  264. linear_offset -= sprsurf_offset;
  265. /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
  266. * register */
  267. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  268. I915_WRITE(SPROFFSET(pipe), (y << 16) | x);
  269. else if (obj->tiling_mode != I915_TILING_NONE)
  270. I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x);
  271. else
  272. I915_WRITE(SPRLINOFF(pipe), linear_offset);
  273. I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
  274. if (intel_plane->can_scale)
  275. I915_WRITE(SPRSCALE(pipe), sprscale);
  276. I915_WRITE(SPRCTL(pipe), sprctl);
  277. I915_WRITE(SPRSURF(pipe),
  278. i915_gem_obj_ggtt_offset(obj) + sprsurf_offset);
  279. POSTING_READ(SPRSURF(pipe));
  280. }
  281. static void
  282. ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
  283. {
  284. struct drm_device *dev = plane->dev;
  285. struct drm_i915_private *dev_priv = dev->dev_private;
  286. struct intel_plane *intel_plane = to_intel_plane(plane);
  287. int pipe = intel_plane->pipe;
  288. I915_WRITE(SPRCTL(pipe), I915_READ(SPRCTL(pipe)) & ~SPRITE_ENABLE);
  289. /* Can't leave the scaler enabled... */
  290. if (intel_plane->can_scale)
  291. I915_WRITE(SPRSCALE(pipe), 0);
  292. /* Activate double buffered register update */
  293. I915_WRITE(SPRSURF(pipe), 0);
  294. POSTING_READ(SPRSURF(pipe));
  295. /*
  296. * Avoid underruns when disabling the sprite.
  297. * FIXME remove once watermark updates are done properly.
  298. */
  299. intel_wait_for_vblank(dev, pipe);
  300. intel_update_sprite_watermarks(plane, crtc, 0, 0, false, false);
  301. }
  302. static int
  303. ivb_update_colorkey(struct drm_plane *plane,
  304. struct drm_intel_sprite_colorkey *key)
  305. {
  306. struct drm_device *dev = plane->dev;
  307. struct drm_i915_private *dev_priv = dev->dev_private;
  308. struct intel_plane *intel_plane;
  309. u32 sprctl;
  310. int ret = 0;
  311. intel_plane = to_intel_plane(plane);
  312. I915_WRITE(SPRKEYVAL(intel_plane->pipe), key->min_value);
  313. I915_WRITE(SPRKEYMAX(intel_plane->pipe), key->max_value);
  314. I915_WRITE(SPRKEYMSK(intel_plane->pipe), key->channel_mask);
  315. sprctl = I915_READ(SPRCTL(intel_plane->pipe));
  316. sprctl &= ~(SPRITE_SOURCE_KEY | SPRITE_DEST_KEY);
  317. if (key->flags & I915_SET_COLORKEY_DESTINATION)
  318. sprctl |= SPRITE_DEST_KEY;
  319. else if (key->flags & I915_SET_COLORKEY_SOURCE)
  320. sprctl |= SPRITE_SOURCE_KEY;
  321. I915_WRITE(SPRCTL(intel_plane->pipe), sprctl);
  322. POSTING_READ(SPRKEYMSK(intel_plane->pipe));
  323. return ret;
  324. }
  325. static void
  326. ivb_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
  327. {
  328. struct drm_device *dev = plane->dev;
  329. struct drm_i915_private *dev_priv = dev->dev_private;
  330. struct intel_plane *intel_plane;
  331. u32 sprctl;
  332. intel_plane = to_intel_plane(plane);
  333. key->min_value = I915_READ(SPRKEYVAL(intel_plane->pipe));
  334. key->max_value = I915_READ(SPRKEYMAX(intel_plane->pipe));
  335. key->channel_mask = I915_READ(SPRKEYMSK(intel_plane->pipe));
  336. key->flags = 0;
  337. sprctl = I915_READ(SPRCTL(intel_plane->pipe));
  338. if (sprctl & SPRITE_DEST_KEY)
  339. key->flags = I915_SET_COLORKEY_DESTINATION;
  340. else if (sprctl & SPRITE_SOURCE_KEY)
  341. key->flags = I915_SET_COLORKEY_SOURCE;
  342. else
  343. key->flags = I915_SET_COLORKEY_NONE;
  344. }
  345. static void
  346. ilk_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
  347. struct drm_framebuffer *fb,
  348. struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
  349. unsigned int crtc_w, unsigned int crtc_h,
  350. uint32_t x, uint32_t y,
  351. uint32_t src_w, uint32_t src_h)
  352. {
  353. struct drm_device *dev = plane->dev;
  354. struct drm_i915_private *dev_priv = dev->dev_private;
  355. struct intel_plane *intel_plane = to_intel_plane(plane);
  356. int pipe = intel_plane->pipe;
  357. unsigned long dvssurf_offset, linear_offset;
  358. u32 dvscntr, dvsscale;
  359. int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
  360. dvscntr = I915_READ(DVSCNTR(pipe));
  361. /* Mask out pixel format bits in case we change it */
  362. dvscntr &= ~DVS_PIXFORMAT_MASK;
  363. dvscntr &= ~DVS_RGB_ORDER_XBGR;
  364. dvscntr &= ~DVS_YUV_BYTE_ORDER_MASK;
  365. dvscntr &= ~DVS_TILED;
  366. switch (fb->pixel_format) {
  367. case DRM_FORMAT_XBGR8888:
  368. dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
  369. break;
  370. case DRM_FORMAT_XRGB8888:
  371. dvscntr |= DVS_FORMAT_RGBX888;
  372. break;
  373. case DRM_FORMAT_YUYV:
  374. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
  375. break;
  376. case DRM_FORMAT_YVYU:
  377. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
  378. break;
  379. case DRM_FORMAT_UYVY:
  380. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
  381. break;
  382. case DRM_FORMAT_VYUY:
  383. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
  384. break;
  385. default:
  386. BUG();
  387. }
  388. /*
  389. * Enable gamma to match primary/cursor plane behaviour.
  390. * FIXME should be user controllable via propertiesa.
  391. */
  392. dvscntr |= DVS_GAMMA_ENABLE;
  393. if (obj->tiling_mode != I915_TILING_NONE)
  394. dvscntr |= DVS_TILED;
  395. if (IS_GEN6(dev))
  396. dvscntr |= DVS_TRICKLE_FEED_DISABLE; /* must disable */
  397. dvscntr |= DVS_ENABLE;
  398. intel_update_sprite_watermarks(plane, crtc, src_w, pixel_size, true,
  399. src_w != crtc_w || src_h != crtc_h);
  400. /* Sizes are 0 based */
  401. src_w--;
  402. src_h--;
  403. crtc_w--;
  404. crtc_h--;
  405. dvsscale = 0;
  406. if (crtc_w != src_w || crtc_h != src_h)
  407. dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
  408. I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]);
  409. I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
  410. linear_offset = y * fb->pitches[0] + x * pixel_size;
  411. dvssurf_offset =
  412. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  413. pixel_size, fb->pitches[0]);
  414. linear_offset -= dvssurf_offset;
  415. if (obj->tiling_mode != I915_TILING_NONE)
  416. I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x);
  417. else
  418. I915_WRITE(DVSLINOFF(pipe), linear_offset);
  419. I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
  420. I915_WRITE(DVSSCALE(pipe), dvsscale);
  421. I915_WRITE(DVSCNTR(pipe), dvscntr);
  422. I915_WRITE(DVSSURF(pipe),
  423. i915_gem_obj_ggtt_offset(obj) + dvssurf_offset);
  424. POSTING_READ(DVSSURF(pipe));
  425. }
  426. static void
  427. ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
  428. {
  429. struct drm_device *dev = plane->dev;
  430. struct drm_i915_private *dev_priv = dev->dev_private;
  431. struct intel_plane *intel_plane = to_intel_plane(plane);
  432. int pipe = intel_plane->pipe;
  433. I915_WRITE(DVSCNTR(pipe), I915_READ(DVSCNTR(pipe)) & ~DVS_ENABLE);
  434. /* Disable the scaler */
  435. I915_WRITE(DVSSCALE(pipe), 0);
  436. /* Flush double buffered register updates */
  437. I915_WRITE(DVSSURF(pipe), 0);
  438. POSTING_READ(DVSSURF(pipe));
  439. /*
  440. * Avoid underruns when disabling the sprite.
  441. * FIXME remove once watermark updates are done properly.
  442. */
  443. intel_wait_for_vblank(dev, pipe);
  444. intel_update_sprite_watermarks(plane, crtc, 0, 0, false, false);
  445. }
  446. static void
  447. intel_enable_primary(struct drm_crtc *crtc)
  448. {
  449. struct drm_device *dev = crtc->dev;
  450. struct drm_i915_private *dev_priv = dev->dev_private;
  451. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  452. int reg = DSPCNTR(intel_crtc->plane);
  453. if (intel_crtc->primary_enabled)
  454. return;
  455. intel_crtc->primary_enabled = true;
  456. I915_WRITE(reg, I915_READ(reg) | DISPLAY_PLANE_ENABLE);
  457. intel_flush_primary_plane(dev_priv, intel_crtc->plane);
  458. /*
  459. * FIXME IPS should be fine as long as one plane is
  460. * enabled, but in practice it seems to have problems
  461. * when going from primary only to sprite only and vice
  462. * versa.
  463. */
  464. if (intel_crtc->config.ips_enabled) {
  465. intel_wait_for_vblank(dev, intel_crtc->pipe);
  466. hsw_enable_ips(intel_crtc);
  467. }
  468. mutex_lock(&dev->struct_mutex);
  469. intel_update_fbc(dev);
  470. mutex_unlock(&dev->struct_mutex);
  471. }
  472. static void
  473. intel_disable_primary(struct drm_crtc *crtc)
  474. {
  475. struct drm_device *dev = crtc->dev;
  476. struct drm_i915_private *dev_priv = dev->dev_private;
  477. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  478. int reg = DSPCNTR(intel_crtc->plane);
  479. if (!intel_crtc->primary_enabled)
  480. return;
  481. intel_crtc->primary_enabled = false;
  482. mutex_lock(&dev->struct_mutex);
  483. if (dev_priv->fbc.plane == intel_crtc->plane)
  484. intel_disable_fbc(dev);
  485. mutex_unlock(&dev->struct_mutex);
  486. /*
  487. * FIXME IPS should be fine as long as one plane is
  488. * enabled, but in practice it seems to have problems
  489. * when going from primary only to sprite only and vice
  490. * versa.
  491. */
  492. hsw_disable_ips(intel_crtc);
  493. I915_WRITE(reg, I915_READ(reg) & ~DISPLAY_PLANE_ENABLE);
  494. intel_flush_primary_plane(dev_priv, intel_crtc->plane);
  495. }
  496. static int
  497. ilk_update_colorkey(struct drm_plane *plane,
  498. struct drm_intel_sprite_colorkey *key)
  499. {
  500. struct drm_device *dev = plane->dev;
  501. struct drm_i915_private *dev_priv = dev->dev_private;
  502. struct intel_plane *intel_plane;
  503. u32 dvscntr;
  504. int ret = 0;
  505. intel_plane = to_intel_plane(plane);
  506. I915_WRITE(DVSKEYVAL(intel_plane->pipe), key->min_value);
  507. I915_WRITE(DVSKEYMAX(intel_plane->pipe), key->max_value);
  508. I915_WRITE(DVSKEYMSK(intel_plane->pipe), key->channel_mask);
  509. dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
  510. dvscntr &= ~(DVS_SOURCE_KEY | DVS_DEST_KEY);
  511. if (key->flags & I915_SET_COLORKEY_DESTINATION)
  512. dvscntr |= DVS_DEST_KEY;
  513. else if (key->flags & I915_SET_COLORKEY_SOURCE)
  514. dvscntr |= DVS_SOURCE_KEY;
  515. I915_WRITE(DVSCNTR(intel_plane->pipe), dvscntr);
  516. POSTING_READ(DVSKEYMSK(intel_plane->pipe));
  517. return ret;
  518. }
  519. static void
  520. ilk_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
  521. {
  522. struct drm_device *dev = plane->dev;
  523. struct drm_i915_private *dev_priv = dev->dev_private;
  524. struct intel_plane *intel_plane;
  525. u32 dvscntr;
  526. intel_plane = to_intel_plane(plane);
  527. key->min_value = I915_READ(DVSKEYVAL(intel_plane->pipe));
  528. key->max_value = I915_READ(DVSKEYMAX(intel_plane->pipe));
  529. key->channel_mask = I915_READ(DVSKEYMSK(intel_plane->pipe));
  530. key->flags = 0;
  531. dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
  532. if (dvscntr & DVS_DEST_KEY)
  533. key->flags = I915_SET_COLORKEY_DESTINATION;
  534. else if (dvscntr & DVS_SOURCE_KEY)
  535. key->flags = I915_SET_COLORKEY_SOURCE;
  536. else
  537. key->flags = I915_SET_COLORKEY_NONE;
  538. }
  539. static bool
  540. format_is_yuv(uint32_t format)
  541. {
  542. switch (format) {
  543. case DRM_FORMAT_YUYV:
  544. case DRM_FORMAT_UYVY:
  545. case DRM_FORMAT_VYUY:
  546. case DRM_FORMAT_YVYU:
  547. return true;
  548. default:
  549. return false;
  550. }
  551. }
  552. static bool colorkey_enabled(struct intel_plane *intel_plane)
  553. {
  554. struct drm_intel_sprite_colorkey key;
  555. intel_plane->get_colorkey(&intel_plane->base, &key);
  556. return key.flags != I915_SET_COLORKEY_NONE;
  557. }
  558. static int
  559. intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
  560. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  561. unsigned int crtc_w, unsigned int crtc_h,
  562. uint32_t src_x, uint32_t src_y,
  563. uint32_t src_w, uint32_t src_h)
  564. {
  565. struct drm_device *dev = plane->dev;
  566. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  567. struct intel_plane *intel_plane = to_intel_plane(plane);
  568. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  569. struct drm_i915_gem_object *obj = intel_fb->obj;
  570. struct drm_i915_gem_object *old_obj = intel_plane->obj;
  571. int ret;
  572. bool disable_primary = false;
  573. bool visible;
  574. int hscale, vscale;
  575. int max_scale, min_scale;
  576. int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
  577. struct drm_rect src = {
  578. /* sample coordinates in 16.16 fixed point */
  579. .x1 = src_x,
  580. .x2 = src_x + src_w,
  581. .y1 = src_y,
  582. .y2 = src_y + src_h,
  583. };
  584. struct drm_rect dst = {
  585. /* integer pixels */
  586. .x1 = crtc_x,
  587. .x2 = crtc_x + crtc_w,
  588. .y1 = crtc_y,
  589. .y2 = crtc_y + crtc_h,
  590. };
  591. const struct drm_rect clip = {
  592. .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0,
  593. .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0,
  594. };
  595. const struct {
  596. int crtc_x, crtc_y;
  597. unsigned int crtc_w, crtc_h;
  598. uint32_t src_x, src_y, src_w, src_h;
  599. } orig = {
  600. .crtc_x = crtc_x,
  601. .crtc_y = crtc_y,
  602. .crtc_w = crtc_w,
  603. .crtc_h = crtc_h,
  604. .src_x = src_x,
  605. .src_y = src_y,
  606. .src_w = src_w,
  607. .src_h = src_h,
  608. };
  609. /* Don't modify another pipe's plane */
  610. if (intel_plane->pipe != intel_crtc->pipe) {
  611. DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
  612. return -EINVAL;
  613. }
  614. /* FIXME check all gen limits */
  615. if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
  616. DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
  617. return -EINVAL;
  618. }
  619. /* Sprite planes can be linear or x-tiled surfaces */
  620. switch (obj->tiling_mode) {
  621. case I915_TILING_NONE:
  622. case I915_TILING_X:
  623. break;
  624. default:
  625. DRM_DEBUG_KMS("Unsupported tiling mode\n");
  626. return -EINVAL;
  627. }
  628. /*
  629. * FIXME the following code does a bunch of fuzzy adjustments to the
  630. * coordinates and sizes. We probably need some way to decide whether
  631. * more strict checking should be done instead.
  632. */
  633. max_scale = intel_plane->max_downscale << 16;
  634. min_scale = intel_plane->can_scale ? 1 : (1 << 16);
  635. hscale = drm_rect_calc_hscale_relaxed(&src, &dst, min_scale, max_scale);
  636. BUG_ON(hscale < 0);
  637. vscale = drm_rect_calc_vscale_relaxed(&src, &dst, min_scale, max_scale);
  638. BUG_ON(vscale < 0);
  639. visible = drm_rect_clip_scaled(&src, &dst, &clip, hscale, vscale);
  640. crtc_x = dst.x1;
  641. crtc_y = dst.y1;
  642. crtc_w = drm_rect_width(&dst);
  643. crtc_h = drm_rect_height(&dst);
  644. if (visible) {
  645. /* check again in case clipping clamped the results */
  646. hscale = drm_rect_calc_hscale(&src, &dst, min_scale, max_scale);
  647. if (hscale < 0) {
  648. DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
  649. drm_rect_debug_print(&src, true);
  650. drm_rect_debug_print(&dst, false);
  651. return hscale;
  652. }
  653. vscale = drm_rect_calc_vscale(&src, &dst, min_scale, max_scale);
  654. if (vscale < 0) {
  655. DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
  656. drm_rect_debug_print(&src, true);
  657. drm_rect_debug_print(&dst, false);
  658. return vscale;
  659. }
  660. /* Make the source viewport size an exact multiple of the scaling factors. */
  661. drm_rect_adjust_size(&src,
  662. drm_rect_width(&dst) * hscale - drm_rect_width(&src),
  663. drm_rect_height(&dst) * vscale - drm_rect_height(&src));
  664. /* sanity check to make sure the src viewport wasn't enlarged */
  665. WARN_ON(src.x1 < (int) src_x ||
  666. src.y1 < (int) src_y ||
  667. src.x2 > (int) (src_x + src_w) ||
  668. src.y2 > (int) (src_y + src_h));
  669. /*
  670. * Hardware doesn't handle subpixel coordinates.
  671. * Adjust to (macro)pixel boundary, but be careful not to
  672. * increase the source viewport size, because that could
  673. * push the downscaling factor out of bounds.
  674. */
  675. src_x = src.x1 >> 16;
  676. src_w = drm_rect_width(&src) >> 16;
  677. src_y = src.y1 >> 16;
  678. src_h = drm_rect_height(&src) >> 16;
  679. if (format_is_yuv(fb->pixel_format)) {
  680. src_x &= ~1;
  681. src_w &= ~1;
  682. /*
  683. * Must keep src and dst the
  684. * same if we can't scale.
  685. */
  686. if (!intel_plane->can_scale)
  687. crtc_w &= ~1;
  688. if (crtc_w == 0)
  689. visible = false;
  690. }
  691. }
  692. /* Check size restrictions when scaling */
  693. if (visible && (src_w != crtc_w || src_h != crtc_h)) {
  694. unsigned int width_bytes;
  695. WARN_ON(!intel_plane->can_scale);
  696. /* FIXME interlacing min height is 6 */
  697. if (crtc_w < 3 || crtc_h < 3)
  698. visible = false;
  699. if (src_w < 3 || src_h < 3)
  700. visible = false;
  701. width_bytes = ((src_x * pixel_size) & 63) + src_w * pixel_size;
  702. if (src_w > 2048 || src_h > 2048 ||
  703. width_bytes > 4096 || fb->pitches[0] > 4096) {
  704. DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
  705. return -EINVAL;
  706. }
  707. }
  708. dst.x1 = crtc_x;
  709. dst.x2 = crtc_x + crtc_w;
  710. dst.y1 = crtc_y;
  711. dst.y2 = crtc_y + crtc_h;
  712. /*
  713. * If the sprite is completely covering the primary plane,
  714. * we can disable the primary and save power.
  715. */
  716. disable_primary = drm_rect_equals(&dst, &clip) && !colorkey_enabled(intel_plane);
  717. WARN_ON(disable_primary && !visible && intel_crtc->active);
  718. mutex_lock(&dev->struct_mutex);
  719. /* Note that this will apply the VT-d workaround for scanouts,
  720. * which is more restrictive than required for sprites. (The
  721. * primary plane requires 256KiB alignment with 64 PTE padding,
  722. * the sprite planes only require 128KiB alignment and 32 PTE padding.
  723. */
  724. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  725. mutex_unlock(&dev->struct_mutex);
  726. if (ret)
  727. return ret;
  728. intel_plane->crtc_x = orig.crtc_x;
  729. intel_plane->crtc_y = orig.crtc_y;
  730. intel_plane->crtc_w = orig.crtc_w;
  731. intel_plane->crtc_h = orig.crtc_h;
  732. intel_plane->src_x = orig.src_x;
  733. intel_plane->src_y = orig.src_y;
  734. intel_plane->src_w = orig.src_w;
  735. intel_plane->src_h = orig.src_h;
  736. intel_plane->obj = obj;
  737. if (intel_crtc->active) {
  738. /*
  739. * Be sure to re-enable the primary before the sprite is no longer
  740. * covering it fully.
  741. */
  742. if (!disable_primary)
  743. intel_enable_primary(crtc);
  744. if (visible)
  745. intel_plane->update_plane(plane, crtc, fb, obj,
  746. crtc_x, crtc_y, crtc_w, crtc_h,
  747. src_x, src_y, src_w, src_h);
  748. else
  749. intel_plane->disable_plane(plane, crtc);
  750. if (disable_primary)
  751. intel_disable_primary(crtc);
  752. }
  753. /* Unpin old obj after new one is active to avoid ugliness */
  754. if (old_obj) {
  755. /*
  756. * It's fairly common to simply update the position of
  757. * an existing object. In that case, we don't need to
  758. * wait for vblank to avoid ugliness, we only need to
  759. * do the pin & ref bookkeeping.
  760. */
  761. if (old_obj != obj && intel_crtc->active)
  762. intel_wait_for_vblank(dev, intel_crtc->pipe);
  763. mutex_lock(&dev->struct_mutex);
  764. intel_unpin_fb_obj(old_obj);
  765. mutex_unlock(&dev->struct_mutex);
  766. }
  767. return 0;
  768. }
  769. static int
  770. intel_disable_plane(struct drm_plane *plane)
  771. {
  772. struct drm_device *dev = plane->dev;
  773. struct intel_plane *intel_plane = to_intel_plane(plane);
  774. struct intel_crtc *intel_crtc;
  775. if (!plane->fb)
  776. return 0;
  777. if (WARN_ON(!plane->crtc))
  778. return -EINVAL;
  779. intel_crtc = to_intel_crtc(plane->crtc);
  780. if (intel_crtc->active) {
  781. intel_enable_primary(plane->crtc);
  782. intel_plane->disable_plane(plane, plane->crtc);
  783. }
  784. if (intel_plane->obj) {
  785. if (intel_crtc->active)
  786. intel_wait_for_vblank(dev, intel_plane->pipe);
  787. mutex_lock(&dev->struct_mutex);
  788. intel_unpin_fb_obj(intel_plane->obj);
  789. mutex_unlock(&dev->struct_mutex);
  790. intel_plane->obj = NULL;
  791. }
  792. return 0;
  793. }
  794. static void intel_destroy_plane(struct drm_plane *plane)
  795. {
  796. struct intel_plane *intel_plane = to_intel_plane(plane);
  797. intel_disable_plane(plane);
  798. drm_plane_cleanup(plane);
  799. kfree(intel_plane);
  800. }
  801. int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
  802. struct drm_file *file_priv)
  803. {
  804. struct drm_intel_sprite_colorkey *set = data;
  805. struct drm_mode_object *obj;
  806. struct drm_plane *plane;
  807. struct intel_plane *intel_plane;
  808. int ret = 0;
  809. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  810. return -ENODEV;
  811. /* Make sure we don't try to enable both src & dest simultaneously */
  812. if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
  813. return -EINVAL;
  814. drm_modeset_lock_all(dev);
  815. obj = drm_mode_object_find(dev, set->plane_id, DRM_MODE_OBJECT_PLANE);
  816. if (!obj) {
  817. ret = -ENOENT;
  818. goto out_unlock;
  819. }
  820. plane = obj_to_plane(obj);
  821. intel_plane = to_intel_plane(plane);
  822. ret = intel_plane->update_colorkey(plane, set);
  823. out_unlock:
  824. drm_modeset_unlock_all(dev);
  825. return ret;
  826. }
  827. int intel_sprite_get_colorkey(struct drm_device *dev, void *data,
  828. struct drm_file *file_priv)
  829. {
  830. struct drm_intel_sprite_colorkey *get = data;
  831. struct drm_mode_object *obj;
  832. struct drm_plane *plane;
  833. struct intel_plane *intel_plane;
  834. int ret = 0;
  835. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  836. return -ENODEV;
  837. drm_modeset_lock_all(dev);
  838. obj = drm_mode_object_find(dev, get->plane_id, DRM_MODE_OBJECT_PLANE);
  839. if (!obj) {
  840. ret = -ENOENT;
  841. goto out_unlock;
  842. }
  843. plane = obj_to_plane(obj);
  844. intel_plane = to_intel_plane(plane);
  845. intel_plane->get_colorkey(plane, get);
  846. out_unlock:
  847. drm_modeset_unlock_all(dev);
  848. return ret;
  849. }
  850. void intel_plane_restore(struct drm_plane *plane)
  851. {
  852. struct intel_plane *intel_plane = to_intel_plane(plane);
  853. if (!plane->crtc || !plane->fb)
  854. return;
  855. intel_update_plane(plane, plane->crtc, plane->fb,
  856. intel_plane->crtc_x, intel_plane->crtc_y,
  857. intel_plane->crtc_w, intel_plane->crtc_h,
  858. intel_plane->src_x, intel_plane->src_y,
  859. intel_plane->src_w, intel_plane->src_h);
  860. }
  861. void intel_plane_disable(struct drm_plane *plane)
  862. {
  863. if (!plane->crtc || !plane->fb)
  864. return;
  865. intel_disable_plane(plane);
  866. }
  867. static const struct drm_plane_funcs intel_plane_funcs = {
  868. .update_plane = intel_update_plane,
  869. .disable_plane = intel_disable_plane,
  870. .destroy = intel_destroy_plane,
  871. };
  872. static uint32_t ilk_plane_formats[] = {
  873. DRM_FORMAT_XRGB8888,
  874. DRM_FORMAT_YUYV,
  875. DRM_FORMAT_YVYU,
  876. DRM_FORMAT_UYVY,
  877. DRM_FORMAT_VYUY,
  878. };
  879. static uint32_t snb_plane_formats[] = {
  880. DRM_FORMAT_XBGR8888,
  881. DRM_FORMAT_XRGB8888,
  882. DRM_FORMAT_YUYV,
  883. DRM_FORMAT_YVYU,
  884. DRM_FORMAT_UYVY,
  885. DRM_FORMAT_VYUY,
  886. };
  887. static uint32_t vlv_plane_formats[] = {
  888. DRM_FORMAT_RGB565,
  889. DRM_FORMAT_ABGR8888,
  890. DRM_FORMAT_ARGB8888,
  891. DRM_FORMAT_XBGR8888,
  892. DRM_FORMAT_XRGB8888,
  893. DRM_FORMAT_XBGR2101010,
  894. DRM_FORMAT_ABGR2101010,
  895. DRM_FORMAT_YUYV,
  896. DRM_FORMAT_YVYU,
  897. DRM_FORMAT_UYVY,
  898. DRM_FORMAT_VYUY,
  899. };
  900. int
  901. intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
  902. {
  903. struct intel_plane *intel_plane;
  904. unsigned long possible_crtcs;
  905. const uint32_t *plane_formats;
  906. int num_plane_formats;
  907. int ret;
  908. if (INTEL_INFO(dev)->gen < 5)
  909. return -ENODEV;
  910. intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL);
  911. if (!intel_plane)
  912. return -ENOMEM;
  913. switch (INTEL_INFO(dev)->gen) {
  914. case 5:
  915. case 6:
  916. intel_plane->can_scale = true;
  917. intel_plane->max_downscale = 16;
  918. intel_plane->update_plane = ilk_update_plane;
  919. intel_plane->disable_plane = ilk_disable_plane;
  920. intel_plane->update_colorkey = ilk_update_colorkey;
  921. intel_plane->get_colorkey = ilk_get_colorkey;
  922. if (IS_GEN6(dev)) {
  923. plane_formats = snb_plane_formats;
  924. num_plane_formats = ARRAY_SIZE(snb_plane_formats);
  925. } else {
  926. plane_formats = ilk_plane_formats;
  927. num_plane_formats = ARRAY_SIZE(ilk_plane_formats);
  928. }
  929. break;
  930. case 7:
  931. case 8:
  932. if (IS_IVYBRIDGE(dev)) {
  933. intel_plane->can_scale = true;
  934. intel_plane->max_downscale = 2;
  935. } else {
  936. intel_plane->can_scale = false;
  937. intel_plane->max_downscale = 1;
  938. }
  939. if (IS_VALLEYVIEW(dev)) {
  940. intel_plane->update_plane = vlv_update_plane;
  941. intel_plane->disable_plane = vlv_disable_plane;
  942. intel_plane->update_colorkey = vlv_update_colorkey;
  943. intel_plane->get_colorkey = vlv_get_colorkey;
  944. plane_formats = vlv_plane_formats;
  945. num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
  946. } else {
  947. intel_plane->update_plane = ivb_update_plane;
  948. intel_plane->disable_plane = ivb_disable_plane;
  949. intel_plane->update_colorkey = ivb_update_colorkey;
  950. intel_plane->get_colorkey = ivb_get_colorkey;
  951. plane_formats = snb_plane_formats;
  952. num_plane_formats = ARRAY_SIZE(snb_plane_formats);
  953. }
  954. break;
  955. default:
  956. kfree(intel_plane);
  957. return -ENODEV;
  958. }
  959. intel_plane->pipe = pipe;
  960. intel_plane->plane = plane;
  961. possible_crtcs = (1 << pipe);
  962. ret = drm_plane_init(dev, &intel_plane->base, possible_crtcs,
  963. &intel_plane_funcs,
  964. plane_formats, num_plane_formats,
  965. false);
  966. if (ret)
  967. kfree(intel_plane);
  968. return ret;
  969. }