intel_sprite.c 48 KB

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