intel_sprite.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157
  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. u32 plane_ctl;
  183. const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
  184. u32 surf_addr = plane_state->main.offset;
  185. unsigned int rotation = plane_state->base.rotation;
  186. u32 stride = skl_plane_stride(fb, 0, rotation);
  187. int crtc_x = plane_state->base.dst.x1;
  188. int crtc_y = plane_state->base.dst.y1;
  189. uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
  190. uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
  191. uint32_t x = plane_state->main.x;
  192. uint32_t y = plane_state->main.y;
  193. uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
  194. uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
  195. plane_ctl = PLANE_CTL_ENABLE |
  196. PLANE_CTL_PIPE_GAMMA_ENABLE |
  197. PLANE_CTL_PIPE_CSC_ENABLE;
  198. plane_ctl |= skl_plane_ctl_format(fb->pixel_format);
  199. plane_ctl |= skl_plane_ctl_tiling(fb->modifier[0]);
  200. plane_ctl |= skl_plane_ctl_rotation(rotation);
  201. if (wm->dirty_pipes & drm_crtc_mask(crtc))
  202. skl_write_plane_wm(intel_crtc, wm, plane);
  203. if (key->flags) {
  204. I915_WRITE(PLANE_KEYVAL(pipe, plane), key->min_value);
  205. I915_WRITE(PLANE_KEYMAX(pipe, plane), key->max_value);
  206. I915_WRITE(PLANE_KEYMSK(pipe, plane), key->channel_mask);
  207. }
  208. if (key->flags & I915_SET_COLORKEY_DESTINATION)
  209. plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
  210. else if (key->flags & I915_SET_COLORKEY_SOURCE)
  211. plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
  212. /* Sizes are 0 based */
  213. src_w--;
  214. src_h--;
  215. crtc_w--;
  216. crtc_h--;
  217. I915_WRITE(PLANE_OFFSET(pipe, plane), (y << 16) | x);
  218. I915_WRITE(PLANE_STRIDE(pipe, plane), stride);
  219. I915_WRITE(PLANE_SIZE(pipe, plane), (src_h << 16) | src_w);
  220. /* program plane scaler */
  221. if (plane_state->scaler_id >= 0) {
  222. int scaler_id = plane_state->scaler_id;
  223. const struct intel_scaler *scaler;
  224. DRM_DEBUG_KMS("plane = %d PS_PLANE_SEL(plane) = 0x%x\n", plane,
  225. PS_PLANE_SEL(plane));
  226. scaler = &crtc_state->scaler_state.scalers[scaler_id];
  227. I915_WRITE(SKL_PS_CTRL(pipe, scaler_id),
  228. PS_SCALER_EN | PS_PLANE_SEL(plane) | scaler->mode);
  229. I915_WRITE(SKL_PS_PWR_GATE(pipe, scaler_id), 0);
  230. I915_WRITE(SKL_PS_WIN_POS(pipe, scaler_id), (crtc_x << 16) | crtc_y);
  231. I915_WRITE(SKL_PS_WIN_SZ(pipe, scaler_id),
  232. ((crtc_w + 1) << 16)|(crtc_h + 1));
  233. I915_WRITE(PLANE_POS(pipe, plane), 0);
  234. } else {
  235. I915_WRITE(PLANE_POS(pipe, plane), (crtc_y << 16) | crtc_x);
  236. }
  237. I915_WRITE(PLANE_CTL(pipe, plane), plane_ctl);
  238. I915_WRITE(PLANE_SURF(pipe, plane),
  239. intel_fb_gtt_offset(fb, rotation) + surf_addr);
  240. POSTING_READ(PLANE_SURF(pipe, plane));
  241. }
  242. static void
  243. skl_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc)
  244. {
  245. struct drm_device *dev = dplane->dev;
  246. struct drm_i915_private *dev_priv = to_i915(dev);
  247. struct intel_plane *intel_plane = to_intel_plane(dplane);
  248. const int pipe = intel_plane->pipe;
  249. const int plane = intel_plane->plane + 1;
  250. /*
  251. * We only populate skl_results on watermark updates, and if the
  252. * plane's visiblity isn't actually changing neither is its watermarks.
  253. */
  254. if (!dplane->state->visible)
  255. skl_write_plane_wm(to_intel_crtc(crtc),
  256. &dev_priv->wm.skl_results, plane);
  257. I915_WRITE(PLANE_CTL(pipe, plane), 0);
  258. I915_WRITE(PLANE_SURF(pipe, plane), 0);
  259. POSTING_READ(PLANE_SURF(pipe, plane));
  260. }
  261. static void
  262. chv_update_csc(struct intel_plane *intel_plane, uint32_t format)
  263. {
  264. struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
  265. int plane = intel_plane->plane;
  266. /* Seems RGB data bypasses the CSC always */
  267. if (!format_is_yuv(format))
  268. return;
  269. /*
  270. * BT.601 limited range YCbCr -> full range RGB
  271. *
  272. * |r| | 6537 4769 0| |cr |
  273. * |g| = |-3330 4769 -1605| x |y-64|
  274. * |b| | 0 4769 8263| |cb |
  275. *
  276. * Cb and Cr apparently come in as signed already, so no
  277. * need for any offset. For Y we need to remove the offset.
  278. */
  279. I915_WRITE(SPCSCYGOFF(plane), SPCSC_OOFF(0) | SPCSC_IOFF(-64));
  280. I915_WRITE(SPCSCCBOFF(plane), SPCSC_OOFF(0) | SPCSC_IOFF(0));
  281. I915_WRITE(SPCSCCROFF(plane), SPCSC_OOFF(0) | SPCSC_IOFF(0));
  282. I915_WRITE(SPCSCC01(plane), SPCSC_C1(4769) | SPCSC_C0(6537));
  283. I915_WRITE(SPCSCC23(plane), SPCSC_C1(-3330) | SPCSC_C0(0));
  284. I915_WRITE(SPCSCC45(plane), SPCSC_C1(-1605) | SPCSC_C0(4769));
  285. I915_WRITE(SPCSCC67(plane), SPCSC_C1(4769) | SPCSC_C0(0));
  286. I915_WRITE(SPCSCC8(plane), SPCSC_C0(8263));
  287. I915_WRITE(SPCSCYGICLAMP(plane), SPCSC_IMAX(940) | SPCSC_IMIN(64));
  288. I915_WRITE(SPCSCCBICLAMP(plane), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
  289. I915_WRITE(SPCSCCRICLAMP(plane), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
  290. I915_WRITE(SPCSCYGOCLAMP(plane), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
  291. I915_WRITE(SPCSCCBOCLAMP(plane), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
  292. I915_WRITE(SPCSCCROCLAMP(plane), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
  293. }
  294. static void
  295. vlv_update_plane(struct drm_plane *dplane,
  296. const struct intel_crtc_state *crtc_state,
  297. const struct intel_plane_state *plane_state)
  298. {
  299. struct drm_device *dev = dplane->dev;
  300. struct drm_i915_private *dev_priv = to_i915(dev);
  301. struct intel_plane *intel_plane = to_intel_plane(dplane);
  302. struct drm_framebuffer *fb = plane_state->base.fb;
  303. int pipe = intel_plane->pipe;
  304. int plane = intel_plane->plane;
  305. u32 sprctl;
  306. u32 sprsurf_offset, linear_offset;
  307. unsigned int rotation = plane_state->base.rotation;
  308. const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
  309. int crtc_x = plane_state->base.dst.x1;
  310. int crtc_y = plane_state->base.dst.y1;
  311. uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
  312. uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
  313. uint32_t x = plane_state->base.src.x1 >> 16;
  314. uint32_t y = plane_state->base.src.y1 >> 16;
  315. uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
  316. uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
  317. sprctl = SP_ENABLE;
  318. switch (fb->pixel_format) {
  319. case DRM_FORMAT_YUYV:
  320. sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
  321. break;
  322. case DRM_FORMAT_YVYU:
  323. sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
  324. break;
  325. case DRM_FORMAT_UYVY:
  326. sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
  327. break;
  328. case DRM_FORMAT_VYUY:
  329. sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
  330. break;
  331. case DRM_FORMAT_RGB565:
  332. sprctl |= SP_FORMAT_BGR565;
  333. break;
  334. case DRM_FORMAT_XRGB8888:
  335. sprctl |= SP_FORMAT_BGRX8888;
  336. break;
  337. case DRM_FORMAT_ARGB8888:
  338. sprctl |= SP_FORMAT_BGRA8888;
  339. break;
  340. case DRM_FORMAT_XBGR2101010:
  341. sprctl |= SP_FORMAT_RGBX1010102;
  342. break;
  343. case DRM_FORMAT_ABGR2101010:
  344. sprctl |= SP_FORMAT_RGBA1010102;
  345. break;
  346. case DRM_FORMAT_XBGR8888:
  347. sprctl |= SP_FORMAT_RGBX8888;
  348. break;
  349. case DRM_FORMAT_ABGR8888:
  350. sprctl |= SP_FORMAT_RGBA8888;
  351. break;
  352. default:
  353. /*
  354. * If we get here one of the upper layers failed to filter
  355. * out the unsupported plane formats
  356. */
  357. BUG();
  358. break;
  359. }
  360. /*
  361. * Enable gamma to match primary/cursor plane behaviour.
  362. * FIXME should be user controllable via propertiesa.
  363. */
  364. sprctl |= SP_GAMMA_ENABLE;
  365. if (fb->modifier[0] == I915_FORMAT_MOD_X_TILED)
  366. sprctl |= SP_TILED;
  367. /* Sizes are 0 based */
  368. src_w--;
  369. src_h--;
  370. crtc_w--;
  371. crtc_h--;
  372. intel_add_fb_offsets(&x, &y, plane_state, 0);
  373. sprsurf_offset = intel_compute_tile_offset(&x, &y, plane_state, 0);
  374. if (rotation == DRM_ROTATE_180) {
  375. sprctl |= SP_ROTATE_180;
  376. x += src_w;
  377. y += src_h;
  378. }
  379. linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
  380. if (key->flags) {
  381. I915_WRITE(SPKEYMINVAL(pipe, plane), key->min_value);
  382. I915_WRITE(SPKEYMAXVAL(pipe, plane), key->max_value);
  383. I915_WRITE(SPKEYMSK(pipe, plane), key->channel_mask);
  384. }
  385. if (key->flags & I915_SET_COLORKEY_SOURCE)
  386. sprctl |= SP_SOURCE_KEY;
  387. if (IS_CHERRYVIEW(dev) && pipe == PIPE_B)
  388. chv_update_csc(intel_plane, fb->pixel_format);
  389. I915_WRITE(SPSTRIDE(pipe, plane), fb->pitches[0]);
  390. I915_WRITE(SPPOS(pipe, plane), (crtc_y << 16) | crtc_x);
  391. if (fb->modifier[0] == I915_FORMAT_MOD_X_TILED)
  392. I915_WRITE(SPTILEOFF(pipe, plane), (y << 16) | x);
  393. else
  394. I915_WRITE(SPLINOFF(pipe, plane), linear_offset);
  395. I915_WRITE(SPCONSTALPHA(pipe, plane), 0);
  396. I915_WRITE(SPSIZE(pipe, plane), (crtc_h << 16) | crtc_w);
  397. I915_WRITE(SPCNTR(pipe, plane), sprctl);
  398. I915_WRITE(SPSURF(pipe, plane),
  399. intel_fb_gtt_offset(fb, rotation) + sprsurf_offset);
  400. POSTING_READ(SPSURF(pipe, plane));
  401. }
  402. static void
  403. vlv_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc)
  404. {
  405. struct drm_device *dev = dplane->dev;
  406. struct drm_i915_private *dev_priv = to_i915(dev);
  407. struct intel_plane *intel_plane = to_intel_plane(dplane);
  408. int pipe = intel_plane->pipe;
  409. int plane = intel_plane->plane;
  410. I915_WRITE(SPCNTR(pipe, plane), 0);
  411. I915_WRITE(SPSURF(pipe, plane), 0);
  412. POSTING_READ(SPSURF(pipe, plane));
  413. }
  414. static void
  415. ivb_update_plane(struct drm_plane *plane,
  416. const struct intel_crtc_state *crtc_state,
  417. const struct intel_plane_state *plane_state)
  418. {
  419. struct drm_device *dev = plane->dev;
  420. struct drm_i915_private *dev_priv = to_i915(dev);
  421. struct intel_plane *intel_plane = to_intel_plane(plane);
  422. struct drm_framebuffer *fb = plane_state->base.fb;
  423. enum pipe pipe = intel_plane->pipe;
  424. u32 sprctl, sprscale = 0;
  425. u32 sprsurf_offset, linear_offset;
  426. unsigned int rotation = plane_state->base.rotation;
  427. const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
  428. int crtc_x = plane_state->base.dst.x1;
  429. int crtc_y = plane_state->base.dst.y1;
  430. uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
  431. uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
  432. uint32_t x = plane_state->base.src.x1 >> 16;
  433. uint32_t y = plane_state->base.src.y1 >> 16;
  434. uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
  435. uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
  436. sprctl = SPRITE_ENABLE;
  437. switch (fb->pixel_format) {
  438. case DRM_FORMAT_XBGR8888:
  439. sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
  440. break;
  441. case DRM_FORMAT_XRGB8888:
  442. sprctl |= SPRITE_FORMAT_RGBX888;
  443. break;
  444. case DRM_FORMAT_YUYV:
  445. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
  446. break;
  447. case DRM_FORMAT_YVYU:
  448. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
  449. break;
  450. case DRM_FORMAT_UYVY:
  451. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
  452. break;
  453. case DRM_FORMAT_VYUY:
  454. sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
  455. break;
  456. default:
  457. BUG();
  458. }
  459. /*
  460. * Enable gamma to match primary/cursor plane behaviour.
  461. * FIXME should be user controllable via propertiesa.
  462. */
  463. sprctl |= SPRITE_GAMMA_ENABLE;
  464. if (fb->modifier[0] == I915_FORMAT_MOD_X_TILED)
  465. sprctl |= SPRITE_TILED;
  466. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  467. sprctl &= ~SPRITE_TRICKLE_FEED_DISABLE;
  468. else
  469. sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
  470. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  471. sprctl |= SPRITE_PIPE_CSC_ENABLE;
  472. /* Sizes are 0 based */
  473. src_w--;
  474. src_h--;
  475. crtc_w--;
  476. crtc_h--;
  477. if (crtc_w != src_w || crtc_h != src_h)
  478. sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
  479. intel_add_fb_offsets(&x, &y, plane_state, 0);
  480. sprsurf_offset = intel_compute_tile_offset(&x, &y, plane_state, 0);
  481. if (rotation == DRM_ROTATE_180) {
  482. sprctl |= SPRITE_ROTATE_180;
  483. /* HSW and BDW does this automagically in hardware */
  484. if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
  485. x += src_w;
  486. y += src_h;
  487. }
  488. }
  489. linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
  490. if (key->flags) {
  491. I915_WRITE(SPRKEYVAL(pipe), key->min_value);
  492. I915_WRITE(SPRKEYMAX(pipe), key->max_value);
  493. I915_WRITE(SPRKEYMSK(pipe), key->channel_mask);
  494. }
  495. if (key->flags & I915_SET_COLORKEY_DESTINATION)
  496. sprctl |= SPRITE_DEST_KEY;
  497. else if (key->flags & I915_SET_COLORKEY_SOURCE)
  498. sprctl |= SPRITE_SOURCE_KEY;
  499. I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]);
  500. I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
  501. /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
  502. * register */
  503. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  504. I915_WRITE(SPROFFSET(pipe), (y << 16) | x);
  505. else if (fb->modifier[0] == I915_FORMAT_MOD_X_TILED)
  506. I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x);
  507. else
  508. I915_WRITE(SPRLINOFF(pipe), linear_offset);
  509. I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
  510. if (intel_plane->can_scale)
  511. I915_WRITE(SPRSCALE(pipe), sprscale);
  512. I915_WRITE(SPRCTL(pipe), sprctl);
  513. I915_WRITE(SPRSURF(pipe),
  514. intel_fb_gtt_offset(fb, rotation) + sprsurf_offset);
  515. POSTING_READ(SPRSURF(pipe));
  516. }
  517. static void
  518. ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
  519. {
  520. struct drm_device *dev = plane->dev;
  521. struct drm_i915_private *dev_priv = to_i915(dev);
  522. struct intel_plane *intel_plane = to_intel_plane(plane);
  523. int pipe = intel_plane->pipe;
  524. I915_WRITE(SPRCTL(pipe), 0);
  525. /* Can't leave the scaler enabled... */
  526. if (intel_plane->can_scale)
  527. I915_WRITE(SPRSCALE(pipe), 0);
  528. I915_WRITE(SPRSURF(pipe), 0);
  529. POSTING_READ(SPRSURF(pipe));
  530. }
  531. static void
  532. ilk_update_plane(struct drm_plane *plane,
  533. const struct intel_crtc_state *crtc_state,
  534. const struct intel_plane_state *plane_state)
  535. {
  536. struct drm_device *dev = plane->dev;
  537. struct drm_i915_private *dev_priv = to_i915(dev);
  538. struct intel_plane *intel_plane = to_intel_plane(plane);
  539. struct drm_framebuffer *fb = plane_state->base.fb;
  540. int pipe = intel_plane->pipe;
  541. u32 dvscntr, dvsscale;
  542. u32 dvssurf_offset, linear_offset;
  543. unsigned int rotation = plane_state->base.rotation;
  544. const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
  545. int crtc_x = plane_state->base.dst.x1;
  546. int crtc_y = plane_state->base.dst.y1;
  547. uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
  548. uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
  549. uint32_t x = plane_state->base.src.x1 >> 16;
  550. uint32_t y = plane_state->base.src.y1 >> 16;
  551. uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
  552. uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
  553. dvscntr = DVS_ENABLE;
  554. switch (fb->pixel_format) {
  555. case DRM_FORMAT_XBGR8888:
  556. dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
  557. break;
  558. case DRM_FORMAT_XRGB8888:
  559. dvscntr |= DVS_FORMAT_RGBX888;
  560. break;
  561. case DRM_FORMAT_YUYV:
  562. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
  563. break;
  564. case DRM_FORMAT_YVYU:
  565. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
  566. break;
  567. case DRM_FORMAT_UYVY:
  568. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
  569. break;
  570. case DRM_FORMAT_VYUY:
  571. dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
  572. break;
  573. default:
  574. BUG();
  575. }
  576. /*
  577. * Enable gamma to match primary/cursor plane behaviour.
  578. * FIXME should be user controllable via propertiesa.
  579. */
  580. dvscntr |= DVS_GAMMA_ENABLE;
  581. if (fb->modifier[0] == I915_FORMAT_MOD_X_TILED)
  582. dvscntr |= DVS_TILED;
  583. if (IS_GEN6(dev))
  584. dvscntr |= DVS_TRICKLE_FEED_DISABLE; /* must disable */
  585. /* Sizes are 0 based */
  586. src_w--;
  587. src_h--;
  588. crtc_w--;
  589. crtc_h--;
  590. dvsscale = 0;
  591. if (crtc_w != src_w || crtc_h != src_h)
  592. dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
  593. intel_add_fb_offsets(&x, &y, plane_state, 0);
  594. dvssurf_offset = intel_compute_tile_offset(&x, &y, plane_state, 0);
  595. if (rotation == DRM_ROTATE_180) {
  596. dvscntr |= DVS_ROTATE_180;
  597. x += src_w;
  598. y += src_h;
  599. }
  600. linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
  601. if (key->flags) {
  602. I915_WRITE(DVSKEYVAL(pipe), key->min_value);
  603. I915_WRITE(DVSKEYMAX(pipe), key->max_value);
  604. I915_WRITE(DVSKEYMSK(pipe), key->channel_mask);
  605. }
  606. if (key->flags & I915_SET_COLORKEY_DESTINATION)
  607. dvscntr |= DVS_DEST_KEY;
  608. else if (key->flags & I915_SET_COLORKEY_SOURCE)
  609. dvscntr |= DVS_SOURCE_KEY;
  610. I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]);
  611. I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
  612. if (fb->modifier[0] == I915_FORMAT_MOD_X_TILED)
  613. I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x);
  614. else
  615. I915_WRITE(DVSLINOFF(pipe), linear_offset);
  616. I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
  617. I915_WRITE(DVSSCALE(pipe), dvsscale);
  618. I915_WRITE(DVSCNTR(pipe), dvscntr);
  619. I915_WRITE(DVSSURF(pipe),
  620. intel_fb_gtt_offset(fb, rotation) + dvssurf_offset);
  621. POSTING_READ(DVSSURF(pipe));
  622. }
  623. static void
  624. ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
  625. {
  626. struct drm_device *dev = plane->dev;
  627. struct drm_i915_private *dev_priv = to_i915(dev);
  628. struct intel_plane *intel_plane = to_intel_plane(plane);
  629. int pipe = intel_plane->pipe;
  630. I915_WRITE(DVSCNTR(pipe), 0);
  631. /* Disable the scaler */
  632. I915_WRITE(DVSSCALE(pipe), 0);
  633. I915_WRITE(DVSSURF(pipe), 0);
  634. POSTING_READ(DVSSURF(pipe));
  635. }
  636. static int
  637. intel_check_sprite_plane(struct drm_plane *plane,
  638. struct intel_crtc_state *crtc_state,
  639. struct intel_plane_state *state)
  640. {
  641. struct drm_device *dev = plane->dev;
  642. struct drm_crtc *crtc = state->base.crtc;
  643. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  644. struct intel_plane *intel_plane = to_intel_plane(plane);
  645. struct drm_framebuffer *fb = state->base.fb;
  646. int crtc_x, crtc_y;
  647. unsigned int crtc_w, crtc_h;
  648. uint32_t src_x, src_y, src_w, src_h;
  649. struct drm_rect *src = &state->base.src;
  650. struct drm_rect *dst = &state->base.dst;
  651. const struct drm_rect *clip = &state->clip;
  652. int hscale, vscale;
  653. int max_scale, min_scale;
  654. bool can_scale;
  655. int ret;
  656. src->x1 = state->base.src_x;
  657. src->y1 = state->base.src_y;
  658. src->x2 = state->base.src_x + state->base.src_w;
  659. src->y2 = state->base.src_y + state->base.src_h;
  660. dst->x1 = state->base.crtc_x;
  661. dst->y1 = state->base.crtc_y;
  662. dst->x2 = state->base.crtc_x + state->base.crtc_w;
  663. dst->y2 = state->base.crtc_y + state->base.crtc_h;
  664. if (!fb) {
  665. state->base.visible = false;
  666. return 0;
  667. }
  668. /* Don't modify another pipe's plane */
  669. if (intel_plane->pipe != intel_crtc->pipe) {
  670. DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
  671. return -EINVAL;
  672. }
  673. /* FIXME check all gen limits */
  674. if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
  675. DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
  676. return -EINVAL;
  677. }
  678. /* setup can_scale, min_scale, max_scale */
  679. if (INTEL_INFO(dev)->gen >= 9) {
  680. /* use scaler when colorkey is not required */
  681. if (state->ckey.flags == I915_SET_COLORKEY_NONE) {
  682. can_scale = 1;
  683. min_scale = 1;
  684. max_scale = skl_max_scale(intel_crtc, crtc_state);
  685. } else {
  686. can_scale = 0;
  687. min_scale = DRM_PLANE_HELPER_NO_SCALING;
  688. max_scale = DRM_PLANE_HELPER_NO_SCALING;
  689. }
  690. } else {
  691. can_scale = intel_plane->can_scale;
  692. max_scale = intel_plane->max_downscale << 16;
  693. min_scale = intel_plane->can_scale ? 1 : (1 << 16);
  694. }
  695. /*
  696. * FIXME the following code does a bunch of fuzzy adjustments to the
  697. * coordinates and sizes. We probably need some way to decide whether
  698. * more strict checking should be done instead.
  699. */
  700. drm_rect_rotate(src, fb->width << 16, fb->height << 16,
  701. state->base.rotation);
  702. hscale = drm_rect_calc_hscale_relaxed(src, dst, min_scale, max_scale);
  703. BUG_ON(hscale < 0);
  704. vscale = drm_rect_calc_vscale_relaxed(src, dst, min_scale, max_scale);
  705. BUG_ON(vscale < 0);
  706. state->base.visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale);
  707. crtc_x = dst->x1;
  708. crtc_y = dst->y1;
  709. crtc_w = drm_rect_width(dst);
  710. crtc_h = drm_rect_height(dst);
  711. if (state->base.visible) {
  712. /* check again in case clipping clamped the results */
  713. hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale);
  714. if (hscale < 0) {
  715. DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
  716. drm_rect_debug_print("src: ", src, true);
  717. drm_rect_debug_print("dst: ", dst, false);
  718. return hscale;
  719. }
  720. vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale);
  721. if (vscale < 0) {
  722. DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
  723. drm_rect_debug_print("src: ", src, true);
  724. drm_rect_debug_print("dst: ", dst, false);
  725. return vscale;
  726. }
  727. /* Make the source viewport size an exact multiple of the scaling factors. */
  728. drm_rect_adjust_size(src,
  729. drm_rect_width(dst) * hscale - drm_rect_width(src),
  730. drm_rect_height(dst) * vscale - drm_rect_height(src));
  731. drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16,
  732. state->base.rotation);
  733. /* sanity check to make sure the src viewport wasn't enlarged */
  734. WARN_ON(src->x1 < (int) state->base.src_x ||
  735. src->y1 < (int) state->base.src_y ||
  736. src->x2 > (int) state->base.src_x + state->base.src_w ||
  737. src->y2 > (int) state->base.src_y + state->base.src_h);
  738. /*
  739. * Hardware doesn't handle subpixel coordinates.
  740. * Adjust to (macro)pixel boundary, but be careful not to
  741. * increase the source viewport size, because that could
  742. * push the downscaling factor out of bounds.
  743. */
  744. src_x = src->x1 >> 16;
  745. src_w = drm_rect_width(src) >> 16;
  746. src_y = src->y1 >> 16;
  747. src_h = drm_rect_height(src) >> 16;
  748. if (format_is_yuv(fb->pixel_format)) {
  749. src_x &= ~1;
  750. src_w &= ~1;
  751. /*
  752. * Must keep src and dst the
  753. * same if we can't scale.
  754. */
  755. if (!can_scale)
  756. crtc_w &= ~1;
  757. if (crtc_w == 0)
  758. state->base.visible = false;
  759. }
  760. }
  761. /* Check size restrictions when scaling */
  762. if (state->base.visible && (src_w != crtc_w || src_h != crtc_h)) {
  763. unsigned int width_bytes;
  764. int cpp = drm_format_plane_cpp(fb->pixel_format, 0);
  765. WARN_ON(!can_scale);
  766. /* FIXME interlacing min height is 6 */
  767. if (crtc_w < 3 || crtc_h < 3)
  768. state->base.visible = false;
  769. if (src_w < 3 || src_h < 3)
  770. state->base.visible = false;
  771. width_bytes = ((src_x * cpp) & 63) + src_w * cpp;
  772. if (INTEL_INFO(dev)->gen < 9 && (src_w > 2048 || src_h > 2048 ||
  773. width_bytes > 4096 || fb->pitches[0] > 4096)) {
  774. DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
  775. return -EINVAL;
  776. }
  777. }
  778. if (state->base.visible) {
  779. src->x1 = src_x << 16;
  780. src->x2 = (src_x + src_w) << 16;
  781. src->y1 = src_y << 16;
  782. src->y2 = (src_y + src_h) << 16;
  783. }
  784. dst->x1 = crtc_x;
  785. dst->x2 = crtc_x + crtc_w;
  786. dst->y1 = crtc_y;
  787. dst->y2 = crtc_y + crtc_h;
  788. if (INTEL_GEN(dev) >= 9) {
  789. ret = skl_check_plane_surface(state);
  790. if (ret)
  791. return ret;
  792. }
  793. return 0;
  794. }
  795. int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
  796. struct drm_file *file_priv)
  797. {
  798. struct drm_intel_sprite_colorkey *set = data;
  799. struct drm_plane *plane;
  800. struct drm_plane_state *plane_state;
  801. struct drm_atomic_state *state;
  802. struct drm_modeset_acquire_ctx ctx;
  803. int ret = 0;
  804. /* Make sure we don't try to enable both src & dest simultaneously */
  805. if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
  806. return -EINVAL;
  807. if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
  808. set->flags & I915_SET_COLORKEY_DESTINATION)
  809. return -EINVAL;
  810. plane = drm_plane_find(dev, set->plane_id);
  811. if (!plane || plane->type != DRM_PLANE_TYPE_OVERLAY)
  812. return -ENOENT;
  813. drm_modeset_acquire_init(&ctx, 0);
  814. state = drm_atomic_state_alloc(plane->dev);
  815. if (!state) {
  816. ret = -ENOMEM;
  817. goto out;
  818. }
  819. state->acquire_ctx = &ctx;
  820. while (1) {
  821. plane_state = drm_atomic_get_plane_state(state, plane);
  822. ret = PTR_ERR_OR_ZERO(plane_state);
  823. if (!ret) {
  824. to_intel_plane_state(plane_state)->ckey = *set;
  825. ret = drm_atomic_commit(state);
  826. }
  827. if (ret != -EDEADLK)
  828. break;
  829. drm_atomic_state_clear(state);
  830. drm_modeset_backoff(&ctx);
  831. }
  832. if (ret)
  833. drm_atomic_state_free(state);
  834. out:
  835. drm_modeset_drop_locks(&ctx);
  836. drm_modeset_acquire_fini(&ctx);
  837. return ret;
  838. }
  839. static const uint32_t ilk_plane_formats[] = {
  840. DRM_FORMAT_XRGB8888,
  841. DRM_FORMAT_YUYV,
  842. DRM_FORMAT_YVYU,
  843. DRM_FORMAT_UYVY,
  844. DRM_FORMAT_VYUY,
  845. };
  846. static const uint32_t snb_plane_formats[] = {
  847. DRM_FORMAT_XBGR8888,
  848. DRM_FORMAT_XRGB8888,
  849. DRM_FORMAT_YUYV,
  850. DRM_FORMAT_YVYU,
  851. DRM_FORMAT_UYVY,
  852. DRM_FORMAT_VYUY,
  853. };
  854. static const uint32_t vlv_plane_formats[] = {
  855. DRM_FORMAT_RGB565,
  856. DRM_FORMAT_ABGR8888,
  857. DRM_FORMAT_ARGB8888,
  858. DRM_FORMAT_XBGR8888,
  859. DRM_FORMAT_XRGB8888,
  860. DRM_FORMAT_XBGR2101010,
  861. DRM_FORMAT_ABGR2101010,
  862. DRM_FORMAT_YUYV,
  863. DRM_FORMAT_YVYU,
  864. DRM_FORMAT_UYVY,
  865. DRM_FORMAT_VYUY,
  866. };
  867. static uint32_t skl_plane_formats[] = {
  868. DRM_FORMAT_RGB565,
  869. DRM_FORMAT_ABGR8888,
  870. DRM_FORMAT_ARGB8888,
  871. DRM_FORMAT_XBGR8888,
  872. DRM_FORMAT_XRGB8888,
  873. DRM_FORMAT_YUYV,
  874. DRM_FORMAT_YVYU,
  875. DRM_FORMAT_UYVY,
  876. DRM_FORMAT_VYUY,
  877. };
  878. int
  879. intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
  880. {
  881. struct intel_plane *intel_plane = NULL;
  882. struct intel_plane_state *state = NULL;
  883. unsigned long possible_crtcs;
  884. const uint32_t *plane_formats;
  885. int num_plane_formats;
  886. int ret;
  887. if (INTEL_INFO(dev)->gen < 5)
  888. return -ENODEV;
  889. intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL);
  890. if (!intel_plane) {
  891. ret = -ENOMEM;
  892. goto fail;
  893. }
  894. state = intel_create_plane_state(&intel_plane->base);
  895. if (!state) {
  896. ret = -ENOMEM;
  897. goto fail;
  898. }
  899. intel_plane->base.state = &state->base;
  900. switch (INTEL_INFO(dev)->gen) {
  901. case 5:
  902. case 6:
  903. intel_plane->can_scale = true;
  904. intel_plane->max_downscale = 16;
  905. intel_plane->update_plane = ilk_update_plane;
  906. intel_plane->disable_plane = ilk_disable_plane;
  907. if (IS_GEN6(dev)) {
  908. plane_formats = snb_plane_formats;
  909. num_plane_formats = ARRAY_SIZE(snb_plane_formats);
  910. } else {
  911. plane_formats = ilk_plane_formats;
  912. num_plane_formats = ARRAY_SIZE(ilk_plane_formats);
  913. }
  914. break;
  915. case 7:
  916. case 8:
  917. if (IS_IVYBRIDGE(dev)) {
  918. intel_plane->can_scale = true;
  919. intel_plane->max_downscale = 2;
  920. } else {
  921. intel_plane->can_scale = false;
  922. intel_plane->max_downscale = 1;
  923. }
  924. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  925. intel_plane->update_plane = vlv_update_plane;
  926. intel_plane->disable_plane = vlv_disable_plane;
  927. plane_formats = vlv_plane_formats;
  928. num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
  929. } else {
  930. intel_plane->update_plane = ivb_update_plane;
  931. intel_plane->disable_plane = ivb_disable_plane;
  932. plane_formats = snb_plane_formats;
  933. num_plane_formats = ARRAY_SIZE(snb_plane_formats);
  934. }
  935. break;
  936. case 9:
  937. intel_plane->can_scale = true;
  938. intel_plane->update_plane = skl_update_plane;
  939. intel_plane->disable_plane = skl_disable_plane;
  940. state->scaler_id = -1;
  941. plane_formats = skl_plane_formats;
  942. num_plane_formats = ARRAY_SIZE(skl_plane_formats);
  943. break;
  944. default:
  945. MISSING_CASE(INTEL_INFO(dev)->gen);
  946. ret = -ENODEV;
  947. goto fail;
  948. }
  949. intel_plane->pipe = pipe;
  950. intel_plane->plane = plane;
  951. intel_plane->frontbuffer_bit = INTEL_FRONTBUFFER_SPRITE(pipe, plane);
  952. intel_plane->check_plane = intel_check_sprite_plane;
  953. possible_crtcs = (1 << pipe);
  954. if (INTEL_INFO(dev)->gen >= 9)
  955. ret = drm_universal_plane_init(dev, &intel_plane->base, possible_crtcs,
  956. &intel_plane_funcs,
  957. plane_formats, num_plane_formats,
  958. DRM_PLANE_TYPE_OVERLAY,
  959. "plane %d%c", plane + 2, pipe_name(pipe));
  960. else
  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. "sprite %c", sprite_name(pipe, plane));
  966. if (ret)
  967. goto fail;
  968. intel_create_rotation_property(dev, intel_plane);
  969. drm_plane_helper_add(&intel_plane->base, &intel_plane_helper_funcs);
  970. return 0;
  971. fail:
  972. kfree(state);
  973. kfree(intel_plane);
  974. return ret;
  975. }