intel_sprite.c 18 KB

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