intel_sprite.c 41 KB

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