intel_sprite.c 19 KB

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