intel_sprite.c 39 KB

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