intel_sprite.c 31 KB

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