intel_sprite.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  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 <drm/drm_plane_helper.h>
  37. #include "intel_drv.h"
  38. #include <drm/i915_drm.h>
  39. #include "i915_drv.h"
  40. static bool
  41. format_is_yuv(uint32_t format)
  42. {
  43. switch (format) {
  44. case DRM_FORMAT_YUYV:
  45. case DRM_FORMAT_UYVY:
  46. case DRM_FORMAT_VYUY:
  47. case DRM_FORMAT_YVYU:
  48. return true;
  49. default:
  50. return false;
  51. }
  52. }
  53. static int usecs_to_scanlines(const struct drm_display_mode *mode, int usecs)
  54. {
  55. /* paranoia */
  56. if (!mode->crtc_htotal)
  57. return 1;
  58. return DIV_ROUND_UP(usecs * mode->crtc_clock, 1000 * mode->crtc_htotal);
  59. }
  60. /**
  61. * intel_pipe_update_start() - start update of a set of display registers
  62. * @crtc: the crtc of which the registers are going to be updated
  63. * @start_vbl_count: vblank counter return pointer used for error checking
  64. *
  65. * Mark the start of an update to pipe registers that should be updated
  66. * atomically regarding vblank. If the next vblank will happens within
  67. * the next 100 us, this function waits until the vblank passes.
  68. *
  69. * After a successful call to this function, interrupts will be disabled
  70. * until a subsequent call to intel_pipe_update_end(). That is done to
  71. * avoid random delays. The value written to @start_vbl_count should be
  72. * supplied to intel_pipe_update_end() for error checking.
  73. *
  74. * Return: true if the call was successful
  75. */
  76. bool intel_pipe_update_start(struct intel_crtc *crtc, uint32_t *start_vbl_count)
  77. {
  78. struct drm_device *dev = crtc->base.dev;
  79. const struct drm_display_mode *mode = &crtc->config->base.adjusted_mode;
  80. enum pipe pipe = crtc->pipe;
  81. long timeout = msecs_to_jiffies_timeout(1);
  82. int scanline, min, max, vblank_start;
  83. wait_queue_head_t *wq = drm_crtc_vblank_waitqueue(&crtc->base);
  84. DEFINE_WAIT(wait);
  85. vblank_start = mode->crtc_vblank_start;
  86. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  87. vblank_start = DIV_ROUND_UP(vblank_start, 2);
  88. /* FIXME needs to be calibrated sensibly */
  89. min = vblank_start - usecs_to_scanlines(mode, 100);
  90. max = vblank_start - 1;
  91. if (min <= 0 || max <= 0)
  92. return false;
  93. if (WARN_ON(drm_crtc_vblank_get(&crtc->base)))
  94. return false;
  95. local_irq_disable();
  96. trace_i915_pipe_update_start(crtc, min, max);
  97. for (;;) {
  98. /*
  99. * prepare_to_wait() has a memory barrier, which guarantees
  100. * other CPUs can see the task state update by the time we
  101. * read the scanline.
  102. */
  103. prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE);
  104. scanline = intel_get_crtc_scanline(crtc);
  105. if (scanline < min || scanline > max)
  106. break;
  107. if (timeout <= 0) {
  108. DRM_ERROR("Potential atomic update failure on pipe %c\n",
  109. pipe_name(crtc->pipe));
  110. break;
  111. }
  112. local_irq_enable();
  113. timeout = schedule_timeout(timeout);
  114. local_irq_disable();
  115. }
  116. finish_wait(wq, &wait);
  117. drm_crtc_vblank_put(&crtc->base);
  118. *start_vbl_count = dev->driver->get_vblank_counter(dev, pipe);
  119. trace_i915_pipe_update_vblank_evaded(crtc, min, max, *start_vbl_count);
  120. return true;
  121. }
  122. /**
  123. * intel_pipe_update_end() - end update of a set of display registers
  124. * @crtc: the crtc of which the registers were updated
  125. * @start_vbl_count: start vblank counter (used for error checking)
  126. *
  127. * Mark the end of an update started with intel_pipe_update_start(). This
  128. * re-enables interrupts and verifies the update was actually completed
  129. * before a vblank using the value of @start_vbl_count.
  130. */
  131. void intel_pipe_update_end(struct intel_crtc *crtc, u32 start_vbl_count)
  132. {
  133. struct drm_device *dev = crtc->base.dev;
  134. enum pipe pipe = crtc->pipe;
  135. u32 end_vbl_count = dev->driver->get_vblank_counter(dev, pipe);
  136. trace_i915_pipe_update_end(crtc, end_vbl_count);
  137. local_irq_enable();
  138. if (start_vbl_count != end_vbl_count)
  139. DRM_ERROR("Atomic update failure on pipe %c (start=%u end=%u)\n",
  140. pipe_name(pipe), start_vbl_count, end_vbl_count);
  141. }
  142. static void intel_update_primary_plane(struct intel_crtc *crtc)
  143. {
  144. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  145. int reg = DSPCNTR(crtc->plane);
  146. if (crtc->primary_enabled)
  147. I915_WRITE(reg, I915_READ(reg) | DISPLAY_PLANE_ENABLE);
  148. else
  149. I915_WRITE(reg, I915_READ(reg) & ~DISPLAY_PLANE_ENABLE);
  150. }
  151. static void
  152. skl_update_plane(struct drm_plane *drm_plane, struct drm_crtc *crtc,
  153. struct drm_framebuffer *fb,
  154. int crtc_x, int crtc_y,
  155. unsigned int crtc_w, unsigned int crtc_h,
  156. uint32_t x, uint32_t y,
  157. uint32_t src_w, uint32_t src_h)
  158. {
  159. struct drm_device *dev = drm_plane->dev;
  160. struct drm_i915_private *dev_priv = dev->dev_private;
  161. struct intel_plane *intel_plane = to_intel_plane(drm_plane);
  162. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  163. const int pipe = intel_plane->pipe;
  164. const int plane = intel_plane->plane + 1;
  165. u32 plane_ctl, stride_div;
  166. int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
  167. const struct drm_intel_sprite_colorkey *key = &intel_plane->ckey;
  168. unsigned long surf_addr;
  169. plane_ctl = PLANE_CTL_ENABLE |
  170. PLANE_CTL_PIPE_CSC_ENABLE;
  171. switch (fb->pixel_format) {
  172. case DRM_FORMAT_RGB565:
  173. plane_ctl |= PLANE_CTL_FORMAT_RGB_565;
  174. break;
  175. case DRM_FORMAT_XBGR8888:
  176. plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
  177. break;
  178. case DRM_FORMAT_XRGB8888:
  179. plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888;
  180. break;
  181. /*
  182. * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
  183. * to be already pre-multiplied. We need to add a knob (or a different
  184. * DRM_FORMAT) for user-space to configure that.
  185. */
  186. case DRM_FORMAT_ABGR8888:
  187. plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888 |
  188. PLANE_CTL_ORDER_RGBX |
  189. PLANE_CTL_ALPHA_SW_PREMULTIPLY;
  190. break;
  191. case DRM_FORMAT_ARGB8888:
  192. plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888 |
  193. PLANE_CTL_ALPHA_SW_PREMULTIPLY;
  194. break;
  195. case DRM_FORMAT_YUYV:
  196. plane_ctl |= PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
  197. break;
  198. case DRM_FORMAT_YVYU:
  199. plane_ctl |= PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
  200. break;
  201. case DRM_FORMAT_UYVY:
  202. plane_ctl |= PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
  203. break;
  204. case DRM_FORMAT_VYUY:
  205. plane_ctl |= PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
  206. break;
  207. default:
  208. BUG();
  209. }
  210. switch (fb->modifier[0]) {
  211. case DRM_FORMAT_MOD_NONE:
  212. break;
  213. case I915_FORMAT_MOD_X_TILED:
  214. plane_ctl |= PLANE_CTL_TILED_X;
  215. break;
  216. case I915_FORMAT_MOD_Y_TILED:
  217. plane_ctl |= PLANE_CTL_TILED_Y;
  218. break;
  219. case I915_FORMAT_MOD_Yf_TILED:
  220. plane_ctl |= PLANE_CTL_TILED_YF;
  221. break;
  222. default:
  223. MISSING_CASE(fb->modifier[0]);
  224. }
  225. if (drm_plane->state->rotation == BIT(DRM_ROTATE_180))
  226. plane_ctl |= PLANE_CTL_ROTATE_180;
  227. intel_update_sprite_watermarks(drm_plane, crtc, src_w, src_h,
  228. pixel_size, true,
  229. src_w != crtc_w || src_h != crtc_h);
  230. stride_div = intel_fb_stride_alignment(dev, fb->modifier[0],
  231. fb->pixel_format);
  232. /* Sizes are 0 based */
  233. src_w--;
  234. src_h--;
  235. crtc_w--;
  236. crtc_h--;
  237. if (key->flags) {
  238. I915_WRITE(PLANE_KEYVAL(pipe, plane), key->min_value);
  239. I915_WRITE(PLANE_KEYMAX(pipe, plane), key->max_value);
  240. I915_WRITE(PLANE_KEYMSK(pipe, plane), key->channel_mask);
  241. }
  242. if (key->flags & I915_SET_COLORKEY_DESTINATION)
  243. plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
  244. else if (key->flags & I915_SET_COLORKEY_SOURCE)
  245. plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
  246. surf_addr = intel_plane_obj_offset(intel_plane, obj);
  247. I915_WRITE(PLANE_OFFSET(pipe, plane), (y << 16) | x);
  248. I915_WRITE(PLANE_STRIDE(pipe, plane), fb->pitches[0] / stride_div);
  249. I915_WRITE(PLANE_POS(pipe, plane), (crtc_y << 16) | crtc_x);
  250. I915_WRITE(PLANE_SIZE(pipe, plane), (crtc_h << 16) | crtc_w);
  251. I915_WRITE(PLANE_CTL(pipe, plane), plane_ctl);
  252. I915_WRITE(PLANE_SURF(pipe, plane), surf_addr);
  253. POSTING_READ(PLANE_SURF(pipe, plane));
  254. }
  255. static void
  256. skl_disable_plane(struct drm_plane *drm_plane, struct drm_crtc *crtc)
  257. {
  258. struct drm_device *dev = drm_plane->dev;
  259. struct drm_i915_private *dev_priv = dev->dev_private;
  260. struct intel_plane *intel_plane = to_intel_plane(drm_plane);
  261. const int pipe = intel_plane->pipe;
  262. const int plane = intel_plane->plane + 1;
  263. I915_WRITE(PLANE_CTL(pipe, plane), 0);
  264. /* Activate double buffered register update */
  265. I915_WRITE(PLANE_SURF(pipe, plane), 0);
  266. POSTING_READ(PLANE_SURF(pipe, plane));
  267. intel_update_sprite_watermarks(drm_plane, crtc, 0, 0, 0, false, false);
  268. }
  269. static void
  270. chv_update_csc(struct intel_plane *intel_plane, uint32_t format)
  271. {
  272. struct drm_i915_private *dev_priv = intel_plane->base.dev->dev_private;
  273. int plane = intel_plane->plane;
  274. /* Seems RGB data bypasses the CSC always */
  275. if (!format_is_yuv(format))
  276. return;
  277. /*
  278. * BT.601 limited range YCbCr -> full range RGB
  279. *
  280. * |r| | 6537 4769 0| |cr |
  281. * |g| = |-3330 4769 -1605| x |y-64|
  282. * |b| | 0 4769 8263| |cb |
  283. *
  284. * Cb and Cr apparently come in as signed already, so no
  285. * need for any offset. For Y we need to remove the offset.
  286. */
  287. I915_WRITE(SPCSCYGOFF(plane), SPCSC_OOFF(0) | SPCSC_IOFF(-64));
  288. I915_WRITE(SPCSCCBOFF(plane), SPCSC_OOFF(0) | SPCSC_IOFF(0));
  289. I915_WRITE(SPCSCCROFF(plane), SPCSC_OOFF(0) | SPCSC_IOFF(0));
  290. I915_WRITE(SPCSCC01(plane), SPCSC_C1(4769) | SPCSC_C0(6537));
  291. I915_WRITE(SPCSCC23(plane), SPCSC_C1(-3330) | SPCSC_C0(0));
  292. I915_WRITE(SPCSCC45(plane), SPCSC_C1(-1605) | SPCSC_C0(4769));
  293. I915_WRITE(SPCSCC67(plane), SPCSC_C1(4769) | SPCSC_C0(0));
  294. I915_WRITE(SPCSCC8(plane), SPCSC_C0(8263));
  295. I915_WRITE(SPCSCYGICLAMP(plane), SPCSC_IMAX(940) | SPCSC_IMIN(64));
  296. I915_WRITE(SPCSCCBICLAMP(plane), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
  297. I915_WRITE(SPCSCCRICLAMP(plane), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
  298. I915_WRITE(SPCSCYGOCLAMP(plane), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
  299. I915_WRITE(SPCSCCBOCLAMP(plane), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
  300. I915_WRITE(SPCSCCROCLAMP(plane), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
  301. }
  302. static void
  303. vlv_update_plane(struct drm_plane *dplane, struct drm_crtc *crtc,
  304. struct drm_framebuffer *fb,
  305. int crtc_x, int crtc_y,
  306. unsigned int crtc_w, unsigned int crtc_h,
  307. uint32_t x, uint32_t y,
  308. uint32_t src_w, uint32_t src_h)
  309. {
  310. struct drm_device *dev = dplane->dev;
  311. struct drm_i915_private *dev_priv = dev->dev_private;
  312. struct intel_plane *intel_plane = to_intel_plane(dplane);
  313. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  314. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  315. int pipe = intel_plane->pipe;
  316. int plane = intel_plane->plane;
  317. u32 sprctl;
  318. unsigned long sprsurf_offset, linear_offset;
  319. int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
  320. const struct drm_intel_sprite_colorkey *key = &intel_plane->ckey;
  321. sprctl = SP_ENABLE;
  322. switch (fb->pixel_format) {
  323. case DRM_FORMAT_YUYV:
  324. sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
  325. break;
  326. case DRM_FORMAT_YVYU:
  327. sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
  328. break;
  329. case DRM_FORMAT_UYVY:
  330. sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
  331. break;
  332. case DRM_FORMAT_VYUY:
  333. sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
  334. break;
  335. case DRM_FORMAT_RGB565:
  336. sprctl |= SP_FORMAT_BGR565;
  337. break;
  338. case DRM_FORMAT_XRGB8888:
  339. sprctl |= SP_FORMAT_BGRX8888;
  340. break;
  341. case DRM_FORMAT_ARGB8888:
  342. sprctl |= SP_FORMAT_BGRA8888;
  343. break;
  344. case DRM_FORMAT_XBGR2101010:
  345. sprctl |= SP_FORMAT_RGBX1010102;
  346. break;
  347. case DRM_FORMAT_ABGR2101010:
  348. sprctl |= SP_FORMAT_RGBA1010102;
  349. break;
  350. case DRM_FORMAT_XBGR8888:
  351. sprctl |= SP_FORMAT_RGBX8888;
  352. break;
  353. case DRM_FORMAT_ABGR8888:
  354. sprctl |= SP_FORMAT_RGBA8888;
  355. break;
  356. default:
  357. /*
  358. * If we get here one of the upper layers failed to filter
  359. * out the unsupported plane formats
  360. */
  361. BUG();
  362. break;
  363. }
  364. /*
  365. * Enable gamma to match primary/cursor plane behaviour.
  366. * FIXME should be user controllable via propertiesa.
  367. */
  368. sprctl |= SP_GAMMA_ENABLE;
  369. if (obj->tiling_mode != I915_TILING_NONE)
  370. sprctl |= SP_TILED;
  371. intel_update_sprite_watermarks(dplane, crtc, src_w, src_h,
  372. pixel_size, true,
  373. src_w != crtc_w || src_h != crtc_h);
  374. /* Sizes are 0 based */
  375. src_w--;
  376. src_h--;
  377. crtc_w--;
  378. crtc_h--;
  379. linear_offset = y * fb->pitches[0] + x * pixel_size;
  380. sprsurf_offset = intel_gen4_compute_page_offset(&x, &y,
  381. obj->tiling_mode,
  382. pixel_size,
  383. fb->pitches[0]);
  384. linear_offset -= sprsurf_offset;
  385. if (dplane->state->rotation == BIT(DRM_ROTATE_180)) {
  386. sprctl |= SP_ROTATE_180;
  387. x += src_w;
  388. y += src_h;
  389. linear_offset += src_h * fb->pitches[0] + src_w * pixel_size;
  390. }
  391. intel_update_primary_plane(intel_crtc);
  392. if (key->flags) {
  393. I915_WRITE(SPKEYMINVAL(pipe, plane), key->min_value);
  394. I915_WRITE(SPKEYMAXVAL(pipe, plane), key->max_value);
  395. I915_WRITE(SPKEYMSK(pipe, plane), key->channel_mask);
  396. }
  397. if (key->flags & I915_SET_COLORKEY_SOURCE)
  398. sprctl |= SP_SOURCE_KEY;
  399. if (IS_CHERRYVIEW(dev) && pipe == PIPE_B)
  400. chv_update_csc(intel_plane, fb->pixel_format);
  401. I915_WRITE(SPSTRIDE(pipe, plane), fb->pitches[0]);
  402. I915_WRITE(SPPOS(pipe, plane), (crtc_y << 16) | crtc_x);
  403. if (obj->tiling_mode != I915_TILING_NONE)
  404. I915_WRITE(SPTILEOFF(pipe, plane), (y << 16) | x);
  405. else
  406. I915_WRITE(SPLINOFF(pipe, plane), linear_offset);
  407. I915_WRITE(SPCONSTALPHA(pipe, plane), 0);
  408. I915_WRITE(SPSIZE(pipe, plane), (crtc_h << 16) | crtc_w);
  409. I915_WRITE(SPCNTR(pipe, plane), sprctl);
  410. I915_WRITE(SPSURF(pipe, plane), i915_gem_obj_ggtt_offset(obj) +
  411. sprsurf_offset);
  412. intel_flush_primary_plane(dev_priv, intel_crtc->plane);
  413. }
  414. static void
  415. vlv_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc)
  416. {
  417. struct drm_device *dev = dplane->dev;
  418. struct drm_i915_private *dev_priv = dev->dev_private;
  419. struct intel_plane *intel_plane = to_intel_plane(dplane);
  420. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  421. int pipe = intel_plane->pipe;
  422. int plane = intel_plane->plane;
  423. intel_update_primary_plane(intel_crtc);
  424. I915_WRITE(SPCNTR(pipe, plane), 0);
  425. /* Activate double buffered register update */
  426. I915_WRITE(SPSURF(pipe, plane), 0);
  427. intel_flush_primary_plane(dev_priv, intel_crtc->plane);
  428. intel_update_sprite_watermarks(dplane, crtc, 0, 0, 0, false, false);
  429. }
  430. static void
  431. ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
  432. struct drm_framebuffer *fb,
  433. int crtc_x, int crtc_y,
  434. unsigned int crtc_w, unsigned int crtc_h,
  435. uint32_t x, uint32_t y,
  436. uint32_t src_w, uint32_t src_h)
  437. {
  438. struct drm_device *dev = plane->dev;
  439. struct drm_i915_private *dev_priv = dev->dev_private;
  440. struct intel_plane *intel_plane = to_intel_plane(plane);
  441. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  442. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  443. enum pipe pipe = intel_plane->pipe;
  444. u32 sprctl, sprscale = 0;
  445. unsigned long sprsurf_offset, linear_offset;
  446. int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
  447. const struct drm_intel_sprite_colorkey *key = &intel_plane->ckey;
  448. sprctl = SPRITE_ENABLE;
  449. switch (fb->pixel_format) {
  450. case DRM_FORMAT_XBGR8888:
  451. sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
  452. break;
  453. case DRM_FORMAT_XRGB8888:
  454. sprctl |= SPRITE_FORMAT_RGBX888;
  455. break;
  456. case DRM_FORMAT_YUYV:
  457. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
  458. break;
  459. case DRM_FORMAT_YVYU:
  460. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
  461. break;
  462. case DRM_FORMAT_UYVY:
  463. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
  464. break;
  465. case DRM_FORMAT_VYUY:
  466. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
  467. break;
  468. default:
  469. BUG();
  470. }
  471. /*
  472. * Enable gamma to match primary/cursor plane behaviour.
  473. * FIXME should be user controllable via propertiesa.
  474. */
  475. sprctl |= SPRITE_GAMMA_ENABLE;
  476. if (obj->tiling_mode != I915_TILING_NONE)
  477. sprctl |= SPRITE_TILED;
  478. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  479. sprctl &= ~SPRITE_TRICKLE_FEED_DISABLE;
  480. else
  481. sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
  482. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  483. sprctl |= SPRITE_PIPE_CSC_ENABLE;
  484. intel_update_sprite_watermarks(plane, crtc, src_w, src_h, pixel_size,
  485. true,
  486. src_w != crtc_w || src_h != crtc_h);
  487. /* Sizes are 0 based */
  488. src_w--;
  489. src_h--;
  490. crtc_w--;
  491. crtc_h--;
  492. if (crtc_w != src_w || crtc_h != src_h)
  493. sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
  494. linear_offset = y * fb->pitches[0] + x * pixel_size;
  495. sprsurf_offset =
  496. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  497. pixel_size, fb->pitches[0]);
  498. linear_offset -= sprsurf_offset;
  499. if (plane->state->rotation == BIT(DRM_ROTATE_180)) {
  500. sprctl |= SPRITE_ROTATE_180;
  501. /* HSW and BDW does this automagically in hardware */
  502. if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
  503. x += src_w;
  504. y += src_h;
  505. linear_offset += src_h * fb->pitches[0] +
  506. src_w * pixel_size;
  507. }
  508. }
  509. intel_update_primary_plane(intel_crtc);
  510. if (key->flags) {
  511. I915_WRITE(SPRKEYVAL(pipe), key->min_value);
  512. I915_WRITE(SPRKEYMAX(pipe), key->max_value);
  513. I915_WRITE(SPRKEYMSK(pipe), key->channel_mask);
  514. }
  515. if (key->flags & I915_SET_COLORKEY_DESTINATION)
  516. sprctl |= SPRITE_DEST_KEY;
  517. else if (key->flags & I915_SET_COLORKEY_SOURCE)
  518. sprctl |= SPRITE_SOURCE_KEY;
  519. I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]);
  520. I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
  521. /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
  522. * register */
  523. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  524. I915_WRITE(SPROFFSET(pipe), (y << 16) | x);
  525. else if (obj->tiling_mode != I915_TILING_NONE)
  526. I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x);
  527. else
  528. I915_WRITE(SPRLINOFF(pipe), linear_offset);
  529. I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
  530. if (intel_plane->can_scale)
  531. I915_WRITE(SPRSCALE(pipe), sprscale);
  532. I915_WRITE(SPRCTL(pipe), sprctl);
  533. I915_WRITE(SPRSURF(pipe),
  534. i915_gem_obj_ggtt_offset(obj) + sprsurf_offset);
  535. intel_flush_primary_plane(dev_priv, intel_crtc->plane);
  536. }
  537. static void
  538. ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
  539. {
  540. struct drm_device *dev = plane->dev;
  541. struct drm_i915_private *dev_priv = dev->dev_private;
  542. struct intel_plane *intel_plane = to_intel_plane(plane);
  543. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  544. int pipe = intel_plane->pipe;
  545. intel_update_primary_plane(intel_crtc);
  546. I915_WRITE(SPRCTL(pipe), I915_READ(SPRCTL(pipe)) & ~SPRITE_ENABLE);
  547. /* Can't leave the scaler enabled... */
  548. if (intel_plane->can_scale)
  549. I915_WRITE(SPRSCALE(pipe), 0);
  550. /* Activate double buffered register update */
  551. I915_WRITE(SPRSURF(pipe), 0);
  552. intel_flush_primary_plane(dev_priv, intel_crtc->plane);
  553. }
  554. static void
  555. ilk_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
  556. struct drm_framebuffer *fb,
  557. int crtc_x, int crtc_y,
  558. unsigned int crtc_w, unsigned int crtc_h,
  559. uint32_t x, uint32_t y,
  560. uint32_t src_w, uint32_t src_h)
  561. {
  562. struct drm_device *dev = plane->dev;
  563. struct drm_i915_private *dev_priv = dev->dev_private;
  564. struct intel_plane *intel_plane = to_intel_plane(plane);
  565. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  566. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  567. int pipe = intel_plane->pipe;
  568. unsigned long dvssurf_offset, linear_offset;
  569. u32 dvscntr, dvsscale;
  570. int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
  571. const struct drm_intel_sprite_colorkey *key = &intel_plane->ckey;
  572. dvscntr = DVS_ENABLE;
  573. switch (fb->pixel_format) {
  574. case DRM_FORMAT_XBGR8888:
  575. dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
  576. break;
  577. case DRM_FORMAT_XRGB8888:
  578. dvscntr |= DVS_FORMAT_RGBX888;
  579. break;
  580. case DRM_FORMAT_YUYV:
  581. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
  582. break;
  583. case DRM_FORMAT_YVYU:
  584. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
  585. break;
  586. case DRM_FORMAT_UYVY:
  587. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
  588. break;
  589. case DRM_FORMAT_VYUY:
  590. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
  591. break;
  592. default:
  593. BUG();
  594. }
  595. /*
  596. * Enable gamma to match primary/cursor plane behaviour.
  597. * FIXME should be user controllable via propertiesa.
  598. */
  599. dvscntr |= DVS_GAMMA_ENABLE;
  600. if (obj->tiling_mode != I915_TILING_NONE)
  601. dvscntr |= DVS_TILED;
  602. if (IS_GEN6(dev))
  603. dvscntr |= DVS_TRICKLE_FEED_DISABLE; /* must disable */
  604. intel_update_sprite_watermarks(plane, crtc, src_w, src_h,
  605. pixel_size, true,
  606. src_w != crtc_w || src_h != crtc_h);
  607. /* Sizes are 0 based */
  608. src_w--;
  609. src_h--;
  610. crtc_w--;
  611. crtc_h--;
  612. dvsscale = 0;
  613. if (crtc_w != src_w || crtc_h != src_h)
  614. dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
  615. linear_offset = y * fb->pitches[0] + x * pixel_size;
  616. dvssurf_offset =
  617. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  618. pixel_size, fb->pitches[0]);
  619. linear_offset -= dvssurf_offset;
  620. if (plane->state->rotation == BIT(DRM_ROTATE_180)) {
  621. dvscntr |= DVS_ROTATE_180;
  622. x += src_w;
  623. y += src_h;
  624. linear_offset += src_h * fb->pitches[0] + src_w * pixel_size;
  625. }
  626. intel_update_primary_plane(intel_crtc);
  627. if (key->flags) {
  628. I915_WRITE(DVSKEYVAL(pipe), key->min_value);
  629. I915_WRITE(DVSKEYMAX(pipe), key->max_value);
  630. I915_WRITE(DVSKEYMSK(pipe), key->channel_mask);
  631. }
  632. if (key->flags & I915_SET_COLORKEY_DESTINATION)
  633. dvscntr |= DVS_DEST_KEY;
  634. else if (key->flags & I915_SET_COLORKEY_SOURCE)
  635. dvscntr |= DVS_SOURCE_KEY;
  636. I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]);
  637. I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
  638. if (obj->tiling_mode != I915_TILING_NONE)
  639. I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x);
  640. else
  641. I915_WRITE(DVSLINOFF(pipe), linear_offset);
  642. I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
  643. I915_WRITE(DVSSCALE(pipe), dvsscale);
  644. I915_WRITE(DVSCNTR(pipe), dvscntr);
  645. I915_WRITE(DVSSURF(pipe),
  646. i915_gem_obj_ggtt_offset(obj) + dvssurf_offset);
  647. intel_flush_primary_plane(dev_priv, intel_crtc->plane);
  648. }
  649. static void
  650. ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
  651. {
  652. struct drm_device *dev = plane->dev;
  653. struct drm_i915_private *dev_priv = dev->dev_private;
  654. struct intel_plane *intel_plane = to_intel_plane(plane);
  655. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  656. int pipe = intel_plane->pipe;
  657. intel_update_primary_plane(intel_crtc);
  658. I915_WRITE(DVSCNTR(pipe), 0);
  659. /* Disable the scaler */
  660. I915_WRITE(DVSSCALE(pipe), 0);
  661. /* Flush double buffered register updates */
  662. I915_WRITE(DVSSURF(pipe), 0);
  663. intel_flush_primary_plane(dev_priv, intel_crtc->plane);
  664. }
  665. /**
  666. * intel_post_enable_primary - Perform operations after enabling primary plane
  667. * @crtc: the CRTC whose primary plane was just enabled
  668. *
  669. * Performs potentially sleeping operations that must be done after the primary
  670. * plane is enabled, such as updating FBC and IPS. Note that this may be
  671. * called due to an explicit primary plane update, or due to an implicit
  672. * re-enable that is caused when a sprite plane is updated to no longer
  673. * completely hide the primary plane.
  674. */
  675. void
  676. intel_post_enable_primary(struct drm_crtc *crtc)
  677. {
  678. struct drm_device *dev = crtc->dev;
  679. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  680. /*
  681. * BDW signals flip done immediately if the plane
  682. * is disabled, even if the plane enable is already
  683. * armed to occur at the next vblank :(
  684. */
  685. if (IS_BROADWELL(dev))
  686. intel_wait_for_vblank(dev, intel_crtc->pipe);
  687. /*
  688. * FIXME IPS should be fine as long as one plane is
  689. * enabled, but in practice it seems to have problems
  690. * when going from primary only to sprite only and vice
  691. * versa.
  692. */
  693. hsw_enable_ips(intel_crtc);
  694. mutex_lock(&dev->struct_mutex);
  695. intel_fbc_update(dev);
  696. mutex_unlock(&dev->struct_mutex);
  697. }
  698. /**
  699. * intel_pre_disable_primary - Perform operations before disabling primary plane
  700. * @crtc: the CRTC whose primary plane is to be disabled
  701. *
  702. * Performs potentially sleeping operations that must be done before the
  703. * primary plane is enabled, such as updating FBC and IPS. Note that this may
  704. * be called due to an explicit primary plane update, or due to an implicit
  705. * disable that is caused when a sprite plane completely hides the primary
  706. * plane.
  707. */
  708. void
  709. intel_pre_disable_primary(struct drm_crtc *crtc)
  710. {
  711. struct drm_device *dev = crtc->dev;
  712. struct drm_i915_private *dev_priv = dev->dev_private;
  713. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  714. mutex_lock(&dev->struct_mutex);
  715. if (dev_priv->fbc.crtc == intel_crtc)
  716. intel_fbc_disable(dev);
  717. mutex_unlock(&dev->struct_mutex);
  718. /*
  719. * FIXME IPS should be fine as long as one plane is
  720. * enabled, but in practice it seems to have problems
  721. * when going from primary only to sprite only and vice
  722. * versa.
  723. */
  724. hsw_disable_ips(intel_crtc);
  725. }
  726. static bool colorkey_enabled(struct intel_plane *intel_plane)
  727. {
  728. return intel_plane->ckey.flags != I915_SET_COLORKEY_NONE;
  729. }
  730. static int
  731. intel_check_sprite_plane(struct drm_plane *plane,
  732. struct intel_plane_state *state)
  733. {
  734. struct intel_crtc *intel_crtc = to_intel_crtc(state->base.crtc);
  735. struct intel_plane *intel_plane = to_intel_plane(plane);
  736. struct drm_framebuffer *fb = state->base.fb;
  737. int crtc_x, crtc_y;
  738. unsigned int crtc_w, crtc_h;
  739. uint32_t src_x, src_y, src_w, src_h;
  740. struct drm_rect *src = &state->src;
  741. struct drm_rect *dst = &state->dst;
  742. const struct drm_rect *clip = &state->clip;
  743. int hscale, vscale;
  744. int max_scale, min_scale;
  745. int pixel_size;
  746. intel_crtc = intel_crtc ? intel_crtc : to_intel_crtc(plane->crtc);
  747. if (!fb) {
  748. state->visible = false;
  749. goto finish;
  750. }
  751. /* Don't modify another pipe's plane */
  752. if (intel_plane->pipe != intel_crtc->pipe) {
  753. DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
  754. return -EINVAL;
  755. }
  756. /* FIXME check all gen limits */
  757. if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
  758. DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
  759. return -EINVAL;
  760. }
  761. /*
  762. * FIXME the following code does a bunch of fuzzy adjustments to the
  763. * coordinates and sizes. We probably need some way to decide whether
  764. * more strict checking should be done instead.
  765. */
  766. max_scale = intel_plane->max_downscale << 16;
  767. min_scale = intel_plane->can_scale ? 1 : (1 << 16);
  768. drm_rect_rotate(src, fb->width << 16, fb->height << 16,
  769. state->base.rotation);
  770. hscale = drm_rect_calc_hscale_relaxed(src, dst, min_scale, max_scale);
  771. BUG_ON(hscale < 0);
  772. vscale = drm_rect_calc_vscale_relaxed(src, dst, min_scale, max_scale);
  773. BUG_ON(vscale < 0);
  774. state->visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale);
  775. crtc_x = dst->x1;
  776. crtc_y = dst->y1;
  777. crtc_w = drm_rect_width(dst);
  778. crtc_h = drm_rect_height(dst);
  779. if (state->visible) {
  780. /* check again in case clipping clamped the results */
  781. hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale);
  782. if (hscale < 0) {
  783. DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
  784. drm_rect_debug_print(src, true);
  785. drm_rect_debug_print(dst, false);
  786. return hscale;
  787. }
  788. vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale);
  789. if (vscale < 0) {
  790. DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
  791. drm_rect_debug_print(src, true);
  792. drm_rect_debug_print(dst, false);
  793. return vscale;
  794. }
  795. /* Make the source viewport size an exact multiple of the scaling factors. */
  796. drm_rect_adjust_size(src,
  797. drm_rect_width(dst) * hscale - drm_rect_width(src),
  798. drm_rect_height(dst) * vscale - drm_rect_height(src));
  799. drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16,
  800. state->base.rotation);
  801. /* sanity check to make sure the src viewport wasn't enlarged */
  802. WARN_ON(src->x1 < (int) state->base.src_x ||
  803. src->y1 < (int) state->base.src_y ||
  804. src->x2 > (int) state->base.src_x + state->base.src_w ||
  805. src->y2 > (int) state->base.src_y + state->base.src_h);
  806. /*
  807. * Hardware doesn't handle subpixel coordinates.
  808. * Adjust to (macro)pixel boundary, but be careful not to
  809. * increase the source viewport size, because that could
  810. * push the downscaling factor out of bounds.
  811. */
  812. src_x = src->x1 >> 16;
  813. src_w = drm_rect_width(src) >> 16;
  814. src_y = src->y1 >> 16;
  815. src_h = drm_rect_height(src) >> 16;
  816. if (format_is_yuv(fb->pixel_format)) {
  817. src_x &= ~1;
  818. src_w &= ~1;
  819. /*
  820. * Must keep src and dst the
  821. * same if we can't scale.
  822. */
  823. if (!intel_plane->can_scale)
  824. crtc_w &= ~1;
  825. if (crtc_w == 0)
  826. state->visible = false;
  827. }
  828. }
  829. /* Check size restrictions when scaling */
  830. if (state->visible && (src_w != crtc_w || src_h != crtc_h)) {
  831. unsigned int width_bytes;
  832. WARN_ON(!intel_plane->can_scale);
  833. /* FIXME interlacing min height is 6 */
  834. if (crtc_w < 3 || crtc_h < 3)
  835. state->visible = false;
  836. if (src_w < 3 || src_h < 3)
  837. state->visible = false;
  838. pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
  839. width_bytes = ((src_x * pixel_size) & 63) +
  840. src_w * pixel_size;
  841. if (src_w > 2048 || src_h > 2048 ||
  842. width_bytes > 4096 || fb->pitches[0] > 4096) {
  843. DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
  844. return -EINVAL;
  845. }
  846. }
  847. if (state->visible) {
  848. src->x1 = src_x;
  849. src->x2 = src_x + src_w;
  850. src->y1 = src_y;
  851. src->y2 = src_y + src_h;
  852. }
  853. dst->x1 = crtc_x;
  854. dst->x2 = crtc_x + crtc_w;
  855. dst->y1 = crtc_y;
  856. dst->y2 = crtc_y + crtc_h;
  857. finish:
  858. /*
  859. * If the sprite is completely covering the primary plane,
  860. * we can disable the primary and save power.
  861. */
  862. state->hides_primary = fb != NULL && drm_rect_equals(dst, clip) &&
  863. !colorkey_enabled(intel_plane);
  864. WARN_ON(state->hides_primary && !state->visible && intel_crtc->active);
  865. if (intel_crtc->active) {
  866. if (intel_crtc->primary_enabled == state->hides_primary)
  867. intel_crtc->atomic.wait_for_flips = true;
  868. if (intel_crtc->primary_enabled && state->hides_primary)
  869. intel_crtc->atomic.pre_disable_primary = true;
  870. intel_crtc->atomic.fb_bits |=
  871. INTEL_FRONTBUFFER_SPRITE(intel_crtc->pipe);
  872. if (!intel_crtc->primary_enabled && !state->hides_primary)
  873. intel_crtc->atomic.post_enable_primary = true;
  874. if (intel_wm_need_update(plane, &state->base))
  875. intel_crtc->atomic.update_wm = true;
  876. if (!state->visible) {
  877. /*
  878. * Avoid underruns when disabling the sprite.
  879. * FIXME remove once watermark updates are done properly.
  880. */
  881. intel_crtc->atomic.wait_vblank = true;
  882. intel_crtc->atomic.update_sprite_watermarks |=
  883. (1 << drm_plane_index(plane));
  884. }
  885. }
  886. return 0;
  887. }
  888. static void
  889. intel_commit_sprite_plane(struct drm_plane *plane,
  890. struct intel_plane_state *state)
  891. {
  892. struct drm_crtc *crtc = state->base.crtc;
  893. struct intel_crtc *intel_crtc;
  894. struct intel_plane *intel_plane = to_intel_plane(plane);
  895. struct drm_framebuffer *fb = state->base.fb;
  896. int crtc_x, crtc_y;
  897. unsigned int crtc_w, crtc_h;
  898. uint32_t src_x, src_y, src_w, src_h;
  899. crtc = crtc ? crtc : plane->crtc;
  900. intel_crtc = to_intel_crtc(crtc);
  901. plane->fb = fb;
  902. if (intel_crtc->active) {
  903. intel_crtc->primary_enabled = !state->hides_primary;
  904. if (state->visible) {
  905. crtc_x = state->dst.x1;
  906. crtc_y = state->dst.y1;
  907. crtc_w = drm_rect_width(&state->dst);
  908. crtc_h = drm_rect_height(&state->dst);
  909. src_x = state->src.x1;
  910. src_y = state->src.y1;
  911. src_w = drm_rect_width(&state->src);
  912. src_h = drm_rect_height(&state->src);
  913. intel_plane->update_plane(plane, crtc, fb,
  914. crtc_x, crtc_y, crtc_w, crtc_h,
  915. src_x, src_y, src_w, src_h);
  916. } else {
  917. intel_plane->disable_plane(plane, crtc);
  918. }
  919. }
  920. }
  921. int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
  922. struct drm_file *file_priv)
  923. {
  924. struct drm_intel_sprite_colorkey *set = data;
  925. struct drm_plane *plane;
  926. struct intel_plane *intel_plane;
  927. int ret = 0;
  928. /* Make sure we don't try to enable both src & dest simultaneously */
  929. if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
  930. return -EINVAL;
  931. if (IS_VALLEYVIEW(dev) &&
  932. set->flags & I915_SET_COLORKEY_DESTINATION)
  933. return -EINVAL;
  934. drm_modeset_lock_all(dev);
  935. plane = drm_plane_find(dev, set->plane_id);
  936. if (!plane || plane->type != DRM_PLANE_TYPE_OVERLAY) {
  937. ret = -ENOENT;
  938. goto out_unlock;
  939. }
  940. intel_plane = to_intel_plane(plane);
  941. intel_plane->ckey = *set;
  942. /*
  943. * The only way this could fail would be due to
  944. * the current plane state being unsupportable already,
  945. * and we dont't consider that an error for the
  946. * colorkey ioctl. So just ignore any error.
  947. */
  948. intel_plane_restore(plane);
  949. out_unlock:
  950. drm_modeset_unlock_all(dev);
  951. return ret;
  952. }
  953. int intel_plane_restore(struct drm_plane *plane)
  954. {
  955. if (!plane->crtc || !plane->state->fb)
  956. return 0;
  957. return plane->funcs->update_plane(plane, plane->crtc, plane->state->fb,
  958. plane->state->crtc_x, plane->state->crtc_y,
  959. plane->state->crtc_w, plane->state->crtc_h,
  960. plane->state->src_x, plane->state->src_y,
  961. plane->state->src_w, plane->state->src_h);
  962. }
  963. static uint32_t ilk_plane_formats[] = {
  964. DRM_FORMAT_XRGB8888,
  965. DRM_FORMAT_YUYV,
  966. DRM_FORMAT_YVYU,
  967. DRM_FORMAT_UYVY,
  968. DRM_FORMAT_VYUY,
  969. };
  970. static uint32_t snb_plane_formats[] = {
  971. DRM_FORMAT_XBGR8888,
  972. DRM_FORMAT_XRGB8888,
  973. DRM_FORMAT_YUYV,
  974. DRM_FORMAT_YVYU,
  975. DRM_FORMAT_UYVY,
  976. DRM_FORMAT_VYUY,
  977. };
  978. static uint32_t vlv_plane_formats[] = {
  979. DRM_FORMAT_RGB565,
  980. DRM_FORMAT_ABGR8888,
  981. DRM_FORMAT_ARGB8888,
  982. DRM_FORMAT_XBGR8888,
  983. DRM_FORMAT_XRGB8888,
  984. DRM_FORMAT_XBGR2101010,
  985. DRM_FORMAT_ABGR2101010,
  986. DRM_FORMAT_YUYV,
  987. DRM_FORMAT_YVYU,
  988. DRM_FORMAT_UYVY,
  989. DRM_FORMAT_VYUY,
  990. };
  991. static uint32_t skl_plane_formats[] = {
  992. DRM_FORMAT_RGB565,
  993. DRM_FORMAT_ABGR8888,
  994. DRM_FORMAT_ARGB8888,
  995. DRM_FORMAT_XBGR8888,
  996. DRM_FORMAT_XRGB8888,
  997. DRM_FORMAT_YUYV,
  998. DRM_FORMAT_YVYU,
  999. DRM_FORMAT_UYVY,
  1000. DRM_FORMAT_VYUY,
  1001. };
  1002. int
  1003. intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
  1004. {
  1005. struct intel_plane *intel_plane;
  1006. struct intel_plane_state *state;
  1007. unsigned long possible_crtcs;
  1008. const uint32_t *plane_formats;
  1009. int num_plane_formats;
  1010. int ret;
  1011. if (INTEL_INFO(dev)->gen < 5)
  1012. return -ENODEV;
  1013. intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL);
  1014. if (!intel_plane)
  1015. return -ENOMEM;
  1016. state = intel_create_plane_state(&intel_plane->base);
  1017. if (!state) {
  1018. kfree(intel_plane);
  1019. return -ENOMEM;
  1020. }
  1021. intel_plane->base.state = &state->base;
  1022. switch (INTEL_INFO(dev)->gen) {
  1023. case 5:
  1024. case 6:
  1025. intel_plane->can_scale = true;
  1026. intel_plane->max_downscale = 16;
  1027. intel_plane->update_plane = ilk_update_plane;
  1028. intel_plane->disable_plane = ilk_disable_plane;
  1029. if (IS_GEN6(dev)) {
  1030. plane_formats = snb_plane_formats;
  1031. num_plane_formats = ARRAY_SIZE(snb_plane_formats);
  1032. } else {
  1033. plane_formats = ilk_plane_formats;
  1034. num_plane_formats = ARRAY_SIZE(ilk_plane_formats);
  1035. }
  1036. break;
  1037. case 7:
  1038. case 8:
  1039. if (IS_IVYBRIDGE(dev)) {
  1040. intel_plane->can_scale = true;
  1041. intel_plane->max_downscale = 2;
  1042. } else {
  1043. intel_plane->can_scale = false;
  1044. intel_plane->max_downscale = 1;
  1045. }
  1046. if (IS_VALLEYVIEW(dev)) {
  1047. intel_plane->update_plane = vlv_update_plane;
  1048. intel_plane->disable_plane = vlv_disable_plane;
  1049. plane_formats = vlv_plane_formats;
  1050. num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
  1051. } else {
  1052. intel_plane->update_plane = ivb_update_plane;
  1053. intel_plane->disable_plane = ivb_disable_plane;
  1054. plane_formats = snb_plane_formats;
  1055. num_plane_formats = ARRAY_SIZE(snb_plane_formats);
  1056. }
  1057. break;
  1058. case 9:
  1059. /*
  1060. * FIXME: Skylake planes can be scaled (with some restrictions),
  1061. * but this is for another time.
  1062. */
  1063. intel_plane->can_scale = false;
  1064. intel_plane->max_downscale = 1;
  1065. intel_plane->update_plane = skl_update_plane;
  1066. intel_plane->disable_plane = skl_disable_plane;
  1067. plane_formats = skl_plane_formats;
  1068. num_plane_formats = ARRAY_SIZE(skl_plane_formats);
  1069. break;
  1070. default:
  1071. kfree(intel_plane);
  1072. return -ENODEV;
  1073. }
  1074. intel_plane->pipe = pipe;
  1075. intel_plane->plane = plane;
  1076. intel_plane->check_plane = intel_check_sprite_plane;
  1077. intel_plane->commit_plane = intel_commit_sprite_plane;
  1078. possible_crtcs = (1 << pipe);
  1079. ret = drm_universal_plane_init(dev, &intel_plane->base, possible_crtcs,
  1080. &intel_plane_funcs,
  1081. plane_formats, num_plane_formats,
  1082. DRM_PLANE_TYPE_OVERLAY);
  1083. if (ret) {
  1084. kfree(intel_plane);
  1085. goto out;
  1086. }
  1087. if (!dev->mode_config.rotation_property)
  1088. dev->mode_config.rotation_property =
  1089. drm_mode_create_rotation_property(dev,
  1090. BIT(DRM_ROTATE_0) |
  1091. BIT(DRM_ROTATE_180));
  1092. if (dev->mode_config.rotation_property)
  1093. drm_object_attach_property(&intel_plane->base.base,
  1094. dev->mode_config.rotation_property,
  1095. state->base.rotation);
  1096. drm_plane_helper_add(&intel_plane->base, &intel_plane_helper_funcs);
  1097. out:
  1098. return ret;
  1099. }