intel_sprite.c 33 KB

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