intel_sprite.c 37 KB

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