intel_sprite.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  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 "drmP.h"
  33. #include "drm_crtc.h"
  34. #include "drm_fourcc.h"
  35. #include "intel_drv.h"
  36. #include "i915_drm.h"
  37. #include "i915_drv.h"
  38. static void
  39. ivb_update_plane(struct drm_plane *plane, struct drm_framebuffer *fb,
  40. struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
  41. unsigned int crtc_w, unsigned int crtc_h,
  42. uint32_t x, uint32_t y,
  43. uint32_t src_w, uint32_t src_h)
  44. {
  45. struct drm_device *dev = plane->dev;
  46. struct drm_i915_private *dev_priv = dev->dev_private;
  47. struct intel_plane *intel_plane = to_intel_plane(plane);
  48. int pipe = intel_plane->pipe;
  49. u32 sprctl, sprscale = 0;
  50. int pixel_size;
  51. sprctl = I915_READ(SPRCTL(pipe));
  52. /* Mask out pixel format bits in case we change it */
  53. sprctl &= ~SPRITE_PIXFORMAT_MASK;
  54. sprctl &= ~SPRITE_RGB_ORDER_RGBX;
  55. sprctl &= ~SPRITE_YUV_BYTE_ORDER_MASK;
  56. switch (fb->pixel_format) {
  57. case DRM_FORMAT_XBGR8888:
  58. sprctl |= SPRITE_FORMAT_RGBX888;
  59. pixel_size = 4;
  60. break;
  61. case DRM_FORMAT_XRGB8888:
  62. sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
  63. pixel_size = 4;
  64. break;
  65. case DRM_FORMAT_YUYV:
  66. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
  67. pixel_size = 2;
  68. break;
  69. case DRM_FORMAT_YVYU:
  70. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
  71. pixel_size = 2;
  72. break;
  73. case DRM_FORMAT_UYVY:
  74. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
  75. pixel_size = 2;
  76. break;
  77. case DRM_FORMAT_VYUY:
  78. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
  79. pixel_size = 2;
  80. break;
  81. default:
  82. DRM_DEBUG_DRIVER("bad pixel format, assuming RGBX888\n");
  83. sprctl |= DVS_FORMAT_RGBX888;
  84. pixel_size = 4;
  85. break;
  86. }
  87. if (obj->tiling_mode != I915_TILING_NONE)
  88. sprctl |= SPRITE_TILED;
  89. /* must disable */
  90. sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
  91. sprctl |= SPRITE_ENABLE;
  92. sprctl |= SPRITE_DEST_KEY;
  93. /* Sizes are 0 based */
  94. src_w--;
  95. src_h--;
  96. crtc_w--;
  97. crtc_h--;
  98. intel_update_sprite_watermarks(dev, pipe, crtc_w, pixel_size);
  99. /*
  100. * IVB workaround: must disable low power watermarks for at least
  101. * one frame before enabling scaling. LP watermarks can be re-enabled
  102. * when scaling is disabled.
  103. */
  104. if (crtc_w != src_w || crtc_h != src_h) {
  105. dev_priv->sprite_scaling_enabled = true;
  106. sandybridge_update_wm(dev);
  107. intel_wait_for_vblank(dev, pipe);
  108. sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
  109. } else {
  110. dev_priv->sprite_scaling_enabled = false;
  111. /* potentially re-enable LP watermarks */
  112. sandybridge_update_wm(dev);
  113. }
  114. I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]);
  115. I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
  116. if (obj->tiling_mode != I915_TILING_NONE) {
  117. I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x);
  118. } else {
  119. unsigned long offset;
  120. offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  121. I915_WRITE(SPRLINOFF(pipe), offset);
  122. }
  123. I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
  124. I915_WRITE(SPRSCALE(pipe), sprscale);
  125. I915_WRITE(SPRCTL(pipe), sprctl);
  126. I915_WRITE(SPRSURF(pipe), obj->gtt_offset);
  127. POSTING_READ(SPRSURF(pipe));
  128. }
  129. static void
  130. ivb_disable_plane(struct drm_plane *plane)
  131. {
  132. struct drm_device *dev = plane->dev;
  133. struct drm_i915_private *dev_priv = dev->dev_private;
  134. struct intel_plane *intel_plane = to_intel_plane(plane);
  135. int pipe = intel_plane->pipe;
  136. I915_WRITE(SPRCTL(pipe), I915_READ(SPRCTL(pipe)) & ~SPRITE_ENABLE);
  137. /* Can't leave the scaler enabled... */
  138. I915_WRITE(SPRSCALE(pipe), 0);
  139. /* Activate double buffered register update */
  140. I915_WRITE(SPRSURF(pipe), 0);
  141. POSTING_READ(SPRSURF(pipe));
  142. }
  143. static int
  144. ivb_update_colorkey(struct drm_plane *plane,
  145. struct drm_intel_sprite_colorkey *key)
  146. {
  147. struct drm_device *dev = plane->dev;
  148. struct drm_i915_private *dev_priv = dev->dev_private;
  149. struct intel_plane *intel_plane;
  150. u32 sprctl;
  151. int ret = 0;
  152. intel_plane = to_intel_plane(plane);
  153. I915_WRITE(SPRKEYVAL(intel_plane->pipe), key->min_value);
  154. I915_WRITE(SPRKEYMAX(intel_plane->pipe), key->max_value);
  155. I915_WRITE(SPRKEYMSK(intel_plane->pipe), key->channel_mask);
  156. sprctl = I915_READ(SPRCTL(intel_plane->pipe));
  157. sprctl &= ~(SPRITE_SOURCE_KEY | SPRITE_DEST_KEY);
  158. if (key->flags & I915_SET_COLORKEY_DESTINATION)
  159. sprctl |= SPRITE_DEST_KEY;
  160. else if (key->flags & I915_SET_COLORKEY_SOURCE)
  161. sprctl |= SPRITE_SOURCE_KEY;
  162. I915_WRITE(SPRCTL(intel_plane->pipe), sprctl);
  163. POSTING_READ(SPRKEYMSK(intel_plane->pipe));
  164. return ret;
  165. }
  166. static void
  167. ivb_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
  168. {
  169. struct drm_device *dev = plane->dev;
  170. struct drm_i915_private *dev_priv = dev->dev_private;
  171. struct intel_plane *intel_plane;
  172. u32 sprctl;
  173. intel_plane = to_intel_plane(plane);
  174. key->min_value = I915_READ(SPRKEYVAL(intel_plane->pipe));
  175. key->max_value = I915_READ(SPRKEYMAX(intel_plane->pipe));
  176. key->channel_mask = I915_READ(SPRKEYMSK(intel_plane->pipe));
  177. key->flags = 0;
  178. sprctl = I915_READ(SPRCTL(intel_plane->pipe));
  179. if (sprctl & SPRITE_DEST_KEY)
  180. key->flags = I915_SET_COLORKEY_DESTINATION;
  181. else if (sprctl & SPRITE_SOURCE_KEY)
  182. key->flags = I915_SET_COLORKEY_SOURCE;
  183. else
  184. key->flags = I915_SET_COLORKEY_NONE;
  185. }
  186. static void
  187. snb_update_plane(struct drm_plane *plane, struct drm_framebuffer *fb,
  188. struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
  189. unsigned int crtc_w, unsigned int crtc_h,
  190. uint32_t x, uint32_t y,
  191. uint32_t src_w, uint32_t src_h)
  192. {
  193. struct drm_device *dev = plane->dev;
  194. struct drm_i915_private *dev_priv = dev->dev_private;
  195. struct intel_plane *intel_plane = to_intel_plane(plane);
  196. int pipe = intel_plane->pipe, pixel_size;
  197. u32 dvscntr, dvsscale = 0;
  198. dvscntr = I915_READ(DVSCNTR(pipe));
  199. /* Mask out pixel format bits in case we change it */
  200. dvscntr &= ~DVS_PIXFORMAT_MASK;
  201. dvscntr &= ~DVS_RGB_ORDER_XBGR;
  202. dvscntr &= ~DVS_YUV_BYTE_ORDER_MASK;
  203. switch (fb->pixel_format) {
  204. case DRM_FORMAT_XBGR8888:
  205. dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
  206. pixel_size = 4;
  207. break;
  208. case DRM_FORMAT_XRGB8888:
  209. dvscntr |= DVS_FORMAT_RGBX888;
  210. pixel_size = 4;
  211. break;
  212. case DRM_FORMAT_YUYV:
  213. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
  214. pixel_size = 2;
  215. break;
  216. case DRM_FORMAT_YVYU:
  217. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
  218. pixel_size = 2;
  219. break;
  220. case DRM_FORMAT_UYVY:
  221. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
  222. pixel_size = 2;
  223. break;
  224. case DRM_FORMAT_VYUY:
  225. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
  226. pixel_size = 2;
  227. break;
  228. default:
  229. DRM_DEBUG_DRIVER("bad pixel format, assuming RGBX888\n");
  230. dvscntr |= DVS_FORMAT_RGBX888;
  231. pixel_size = 4;
  232. break;
  233. }
  234. if (obj->tiling_mode != I915_TILING_NONE)
  235. dvscntr |= DVS_TILED;
  236. /* must disable */
  237. dvscntr |= DVS_TRICKLE_FEED_DISABLE;
  238. dvscntr |= DVS_ENABLE;
  239. /* Sizes are 0 based */
  240. src_w--;
  241. src_h--;
  242. crtc_w--;
  243. crtc_h--;
  244. intel_update_sprite_watermarks(dev, pipe, crtc_w, pixel_size);
  245. if (crtc_w != src_w || crtc_h != src_h)
  246. dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
  247. I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]);
  248. I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
  249. if (obj->tiling_mode != I915_TILING_NONE) {
  250. I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x);
  251. } else {
  252. unsigned long offset;
  253. offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  254. I915_WRITE(DVSLINOFF(pipe), offset);
  255. }
  256. I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
  257. I915_WRITE(DVSSCALE(pipe), dvsscale);
  258. I915_WRITE(DVSCNTR(pipe), dvscntr);
  259. I915_WRITE(DVSSURF(pipe), obj->gtt_offset);
  260. POSTING_READ(DVSSURF(pipe));
  261. }
  262. static void
  263. snb_disable_plane(struct drm_plane *plane)
  264. {
  265. struct drm_device *dev = plane->dev;
  266. struct drm_i915_private *dev_priv = dev->dev_private;
  267. struct intel_plane *intel_plane = to_intel_plane(plane);
  268. int pipe = intel_plane->pipe;
  269. I915_WRITE(DVSCNTR(pipe), I915_READ(DVSCNTR(pipe)) & ~DVS_ENABLE);
  270. /* Disable the scaler */
  271. I915_WRITE(DVSSCALE(pipe), 0);
  272. /* Flush double buffered register updates */
  273. I915_WRITE(DVSSURF(pipe), 0);
  274. POSTING_READ(DVSSURF(pipe));
  275. }
  276. static void
  277. intel_enable_primary(struct drm_crtc *crtc)
  278. {
  279. struct drm_device *dev = crtc->dev;
  280. struct drm_i915_private *dev_priv = dev->dev_private;
  281. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  282. int reg = DSPCNTR(intel_crtc->plane);
  283. I915_WRITE(reg, I915_READ(reg) | DISPLAY_PLANE_ENABLE);
  284. }
  285. static void
  286. intel_disable_primary(struct drm_crtc *crtc)
  287. {
  288. struct drm_device *dev = crtc->dev;
  289. struct drm_i915_private *dev_priv = dev->dev_private;
  290. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  291. int reg = DSPCNTR(intel_crtc->plane);
  292. I915_WRITE(reg, I915_READ(reg) & ~DISPLAY_PLANE_ENABLE);
  293. }
  294. static int
  295. snb_update_colorkey(struct drm_plane *plane,
  296. struct drm_intel_sprite_colorkey *key)
  297. {
  298. struct drm_device *dev = plane->dev;
  299. struct drm_i915_private *dev_priv = dev->dev_private;
  300. struct intel_plane *intel_plane;
  301. u32 dvscntr;
  302. int ret = 0;
  303. intel_plane = to_intel_plane(plane);
  304. I915_WRITE(DVSKEYVAL(intel_plane->pipe), key->min_value);
  305. I915_WRITE(DVSKEYMAX(intel_plane->pipe), key->max_value);
  306. I915_WRITE(DVSKEYMSK(intel_plane->pipe), key->channel_mask);
  307. dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
  308. dvscntr &= ~(DVS_SOURCE_KEY | DVS_DEST_KEY);
  309. if (key->flags & I915_SET_COLORKEY_DESTINATION)
  310. dvscntr |= DVS_DEST_KEY;
  311. else if (key->flags & I915_SET_COLORKEY_SOURCE)
  312. dvscntr |= DVS_SOURCE_KEY;
  313. I915_WRITE(DVSCNTR(intel_plane->pipe), dvscntr);
  314. POSTING_READ(DVSKEYMSK(intel_plane->pipe));
  315. return ret;
  316. }
  317. static void
  318. snb_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
  319. {
  320. struct drm_device *dev = plane->dev;
  321. struct drm_i915_private *dev_priv = dev->dev_private;
  322. struct intel_plane *intel_plane;
  323. u32 dvscntr;
  324. intel_plane = to_intel_plane(plane);
  325. key->min_value = I915_READ(DVSKEYVAL(intel_plane->pipe));
  326. key->max_value = I915_READ(DVSKEYMAX(intel_plane->pipe));
  327. key->channel_mask = I915_READ(DVSKEYMSK(intel_plane->pipe));
  328. key->flags = 0;
  329. dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
  330. if (dvscntr & DVS_DEST_KEY)
  331. key->flags = I915_SET_COLORKEY_DESTINATION;
  332. else if (dvscntr & DVS_SOURCE_KEY)
  333. key->flags = I915_SET_COLORKEY_SOURCE;
  334. else
  335. key->flags = I915_SET_COLORKEY_NONE;
  336. }
  337. static int
  338. intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
  339. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  340. unsigned int crtc_w, unsigned int crtc_h,
  341. uint32_t src_x, uint32_t src_y,
  342. uint32_t src_w, uint32_t src_h)
  343. {
  344. struct drm_device *dev = plane->dev;
  345. struct drm_i915_private *dev_priv = dev->dev_private;
  346. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  347. struct intel_plane *intel_plane = to_intel_plane(plane);
  348. struct intel_framebuffer *intel_fb;
  349. struct drm_i915_gem_object *obj, *old_obj;
  350. int pipe = intel_plane->pipe;
  351. int ret = 0;
  352. int x = src_x >> 16, y = src_y >> 16;
  353. int primary_w = crtc->mode.hdisplay, primary_h = crtc->mode.vdisplay;
  354. bool disable_primary = false;
  355. intel_fb = to_intel_framebuffer(fb);
  356. obj = intel_fb->obj;
  357. old_obj = intel_plane->obj;
  358. /* Pipe must be running... */
  359. if (!(I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE))
  360. return -EINVAL;
  361. if (crtc_x >= primary_w || crtc_y >= primary_h)
  362. return -EINVAL;
  363. /* Don't modify another pipe's plane */
  364. if (intel_plane->pipe != intel_crtc->pipe)
  365. return -EINVAL;
  366. /*
  367. * Clamp the width & height into the visible area. Note we don't
  368. * try to scale the source if part of the visible region is offscreen.
  369. * The caller must handle that by adjusting source offset and size.
  370. */
  371. if ((crtc_x < 0) && ((crtc_x + crtc_w) > 0)) {
  372. crtc_w += crtc_x;
  373. crtc_x = 0;
  374. }
  375. if ((crtc_x + crtc_w) <= 0) /* Nothing to display */
  376. goto out;
  377. if ((crtc_x + crtc_w) > primary_w)
  378. crtc_w = primary_w - crtc_x;
  379. if ((crtc_y < 0) && ((crtc_y + crtc_h) > 0)) {
  380. crtc_h += crtc_y;
  381. crtc_y = 0;
  382. }
  383. if ((crtc_y + crtc_h) <= 0) /* Nothing to display */
  384. goto out;
  385. if (crtc_y + crtc_h > primary_h)
  386. crtc_h = primary_h - crtc_y;
  387. if (!crtc_w || !crtc_h) /* Again, nothing to display */
  388. goto out;
  389. /*
  390. * We can take a larger source and scale it down, but
  391. * only so much... 16x is the max on SNB.
  392. */
  393. if (((src_w * src_h) / (crtc_w * crtc_h)) > intel_plane->max_downscale)
  394. return -EINVAL;
  395. /*
  396. * If the sprite is completely covering the primary plane,
  397. * we can disable the primary and save power.
  398. */
  399. if ((crtc_x == 0) && (crtc_y == 0) &&
  400. (crtc_w == primary_w) && (crtc_h == primary_h))
  401. disable_primary = true;
  402. mutex_lock(&dev->struct_mutex);
  403. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  404. if (ret)
  405. goto out_unlock;
  406. intel_plane->obj = obj;
  407. /*
  408. * Be sure to re-enable the primary before the sprite is no longer
  409. * covering it fully.
  410. */
  411. if (!disable_primary && intel_plane->primary_disabled) {
  412. intel_enable_primary(crtc);
  413. intel_plane->primary_disabled = false;
  414. }
  415. intel_plane->update_plane(plane, fb, obj, crtc_x, crtc_y,
  416. crtc_w, crtc_h, x, y, src_w, src_h);
  417. if (disable_primary) {
  418. intel_disable_primary(crtc);
  419. intel_plane->primary_disabled = true;
  420. }
  421. /* Unpin old obj after new one is active to avoid ugliness */
  422. if (old_obj) {
  423. /*
  424. * It's fairly common to simply update the position of
  425. * an existing object. In that case, we don't need to
  426. * wait for vblank to avoid ugliness, we only need to
  427. * do the pin & ref bookkeeping.
  428. */
  429. if (old_obj != obj) {
  430. mutex_unlock(&dev->struct_mutex);
  431. intel_wait_for_vblank(dev, to_intel_crtc(crtc)->pipe);
  432. mutex_lock(&dev->struct_mutex);
  433. }
  434. i915_gem_object_unpin(old_obj);
  435. }
  436. out_unlock:
  437. mutex_unlock(&dev->struct_mutex);
  438. out:
  439. return ret;
  440. }
  441. static int
  442. intel_disable_plane(struct drm_plane *plane)
  443. {
  444. struct drm_device *dev = plane->dev;
  445. struct intel_plane *intel_plane = to_intel_plane(plane);
  446. int ret = 0;
  447. if (intel_plane->primary_disabled) {
  448. intel_enable_primary(plane->crtc);
  449. intel_plane->primary_disabled = false;
  450. }
  451. intel_plane->disable_plane(plane);
  452. if (!intel_plane->obj)
  453. goto out;
  454. mutex_lock(&dev->struct_mutex);
  455. i915_gem_object_unpin(intel_plane->obj);
  456. intel_plane->obj = NULL;
  457. mutex_unlock(&dev->struct_mutex);
  458. out:
  459. return ret;
  460. }
  461. static void intel_destroy_plane(struct drm_plane *plane)
  462. {
  463. struct intel_plane *intel_plane = to_intel_plane(plane);
  464. intel_disable_plane(plane);
  465. drm_plane_cleanup(plane);
  466. kfree(intel_plane);
  467. }
  468. int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
  469. struct drm_file *file_priv)
  470. {
  471. struct drm_intel_sprite_colorkey *set = data;
  472. struct drm_i915_private *dev_priv = dev->dev_private;
  473. struct drm_mode_object *obj;
  474. struct drm_plane *plane;
  475. struct intel_plane *intel_plane;
  476. int ret = 0;
  477. if (!dev_priv)
  478. return -EINVAL;
  479. /* Make sure we don't try to enable both src & dest simultaneously */
  480. if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
  481. return -EINVAL;
  482. mutex_lock(&dev->mode_config.mutex);
  483. obj = drm_mode_object_find(dev, set->plane_id, DRM_MODE_OBJECT_PLANE);
  484. if (!obj) {
  485. ret = -EINVAL;
  486. goto out_unlock;
  487. }
  488. plane = obj_to_plane(obj);
  489. intel_plane = to_intel_plane(plane);
  490. ret = intel_plane->update_colorkey(plane, set);
  491. out_unlock:
  492. mutex_unlock(&dev->mode_config.mutex);
  493. return ret;
  494. }
  495. int intel_sprite_get_colorkey(struct drm_device *dev, void *data,
  496. struct drm_file *file_priv)
  497. {
  498. struct drm_intel_sprite_colorkey *get = data;
  499. struct drm_i915_private *dev_priv = dev->dev_private;
  500. struct drm_mode_object *obj;
  501. struct drm_plane *plane;
  502. struct intel_plane *intel_plane;
  503. int ret = 0;
  504. if (!dev_priv)
  505. return -EINVAL;
  506. mutex_lock(&dev->mode_config.mutex);
  507. obj = drm_mode_object_find(dev, get->plane_id, DRM_MODE_OBJECT_PLANE);
  508. if (!obj) {
  509. ret = -EINVAL;
  510. goto out_unlock;
  511. }
  512. plane = obj_to_plane(obj);
  513. intel_plane = to_intel_plane(plane);
  514. intel_plane->get_colorkey(plane, get);
  515. out_unlock:
  516. mutex_unlock(&dev->mode_config.mutex);
  517. return ret;
  518. }
  519. static const struct drm_plane_funcs intel_plane_funcs = {
  520. .update_plane = intel_update_plane,
  521. .disable_plane = intel_disable_plane,
  522. .destroy = intel_destroy_plane,
  523. };
  524. static uint32_t snb_plane_formats[] = {
  525. DRM_FORMAT_XBGR8888,
  526. DRM_FORMAT_XRGB8888,
  527. DRM_FORMAT_YUYV,
  528. DRM_FORMAT_YVYU,
  529. DRM_FORMAT_UYVY,
  530. DRM_FORMAT_VYUY,
  531. };
  532. int
  533. intel_plane_init(struct drm_device *dev, enum pipe pipe)
  534. {
  535. struct intel_plane *intel_plane;
  536. unsigned long possible_crtcs;
  537. int ret;
  538. if (!(IS_GEN6(dev) || IS_GEN7(dev)))
  539. return -ENODEV;
  540. intel_plane = kzalloc(sizeof(struct intel_plane), GFP_KERNEL);
  541. if (!intel_plane)
  542. return -ENOMEM;
  543. if (IS_GEN6(dev)) {
  544. intel_plane->max_downscale = 16;
  545. intel_plane->update_plane = snb_update_plane;
  546. intel_plane->disable_plane = snb_disable_plane;
  547. intel_plane->update_colorkey = snb_update_colorkey;
  548. intel_plane->get_colorkey = snb_get_colorkey;
  549. } else if (IS_GEN7(dev)) {
  550. intel_plane->max_downscale = 2;
  551. intel_plane->update_plane = ivb_update_plane;
  552. intel_plane->disable_plane = ivb_disable_plane;
  553. intel_plane->update_colorkey = ivb_update_colorkey;
  554. intel_plane->get_colorkey = ivb_get_colorkey;
  555. }
  556. intel_plane->pipe = pipe;
  557. possible_crtcs = (1 << pipe);
  558. ret = drm_plane_init(dev, &intel_plane->base, possible_crtcs,
  559. &intel_plane_funcs, snb_plane_formats,
  560. ARRAY_SIZE(snb_plane_formats), false);
  561. if (ret)
  562. kfree(intel_plane);
  563. return ret;
  564. }