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