intel_sprite.c 35 KB

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