intel_sprite.c 31 KB

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