Rev 6937 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6937 | Rev 7144 | ||
---|---|---|---|
Line 41... | Line 41... | ||
41 | #include "intel_drv.h" |
41 | #include "intel_drv.h" |
42 | #include "i915_drv.h" |
42 | #include "i915_drv.h" |
Line 43... | Line 43... | ||
43 | 43 | ||
44 | static inline bool fbc_supported(struct drm_i915_private *dev_priv) |
44 | static inline bool fbc_supported(struct drm_i915_private *dev_priv) |
45 | { |
45 | { |
46 | return dev_priv->fbc.activate != NULL; |
46 | return HAS_FBC(dev_priv); |
Line 47... | Line 47... | ||
47 | } |
47 | } |
48 | 48 | ||
49 | static inline bool fbc_on_pipe_a_only(struct drm_i915_private *dev_priv) |
49 | static inline bool fbc_on_pipe_a_only(struct drm_i915_private *dev_priv) |
Line 54... | Line 54... | ||
54 | static inline bool fbc_on_plane_a_only(struct drm_i915_private *dev_priv) |
54 | static inline bool fbc_on_plane_a_only(struct drm_i915_private *dev_priv) |
55 | { |
55 | { |
56 | return INTEL_INFO(dev_priv)->gen < 4; |
56 | return INTEL_INFO(dev_priv)->gen < 4; |
57 | } |
57 | } |
Line -... | Line 58... | ||
- | 58 | ||
- | 59 | static inline bool no_fbc_on_multiple_pipes(struct drm_i915_private *dev_priv) |
|
- | 60 | { |
|
- | 61 | return INTEL_INFO(dev_priv)->gen <= 3; |
|
- | 62 | } |
|
58 | 63 | ||
59 | /* |
64 | /* |
60 | * In some platforms where the CRTC's x:0/y:0 coordinates doesn't match the |
65 | * In some platforms where the CRTC's x:0/y:0 coordinates doesn't match the |
61 | * frontbuffer's x:0/y:0 coordinates we lie to the hardware about the plane's |
66 | * frontbuffer's x:0/y:0 coordinates we lie to the hardware about the plane's |
62 | * origin so the x and y offsets can actually fit the registers. As a |
67 | * origin so the x and y offsets can actually fit the registers. As a |
Line 72... | Line 77... | ||
72 | /* |
77 | /* |
73 | * For SKL+, the plane source size used by the hardware is based on the value we |
78 | * For SKL+, the plane source size used by the hardware is based on the value we |
74 | * write to the PLANE_SIZE register. For BDW-, the hardware looks at the value |
79 | * write to the PLANE_SIZE register. For BDW-, the hardware looks at the value |
75 | * we wrote to PIPESRC. |
80 | * we wrote to PIPESRC. |
76 | */ |
81 | */ |
77 | static void intel_fbc_get_plane_source_size(struct intel_crtc *crtc, |
82 | static void intel_fbc_get_plane_source_size(struct intel_fbc_state_cache *cache, |
78 | int *width, int *height) |
83 | int *width, int *height) |
79 | { |
84 | { |
80 | struct intel_plane_state *plane_state = |
- | |
81 | to_intel_plane_state(crtc->base.primary->state); |
- | |
82 | int w, h; |
85 | int w, h; |
Line 83... | Line 86... | ||
83 | 86 | ||
84 | if (intel_rotation_90_or_270(plane_state->base.rotation)) { |
87 | if (intel_rotation_90_or_270(cache->plane.rotation)) { |
85 | w = drm_rect_height(&plane_state->src) >> 16; |
88 | w = cache->plane.src_h; |
86 | h = drm_rect_width(&plane_state->src) >> 16; |
89 | h = cache->plane.src_w; |
87 | } else { |
90 | } else { |
88 | w = drm_rect_width(&plane_state->src) >> 16; |
91 | w = cache->plane.src_w; |
89 | h = drm_rect_height(&plane_state->src) >> 16; |
92 | h = cache->plane.src_h; |
Line 90... | Line 93... | ||
90 | } |
93 | } |
91 | 94 | ||
92 | if (width) |
95 | if (width) |
93 | *width = w; |
96 | *width = w; |
94 | if (height) |
97 | if (height) |
Line 95... | Line 98... | ||
95 | *height = h; |
98 | *height = h; |
96 | } |
99 | } |
97 | 100 | ||
98 | static int intel_fbc_calculate_cfb_size(struct intel_crtc *crtc, |
- | |
99 | struct drm_framebuffer *fb) |
101 | static int intel_fbc_calculate_cfb_size(struct drm_i915_private *dev_priv, |
Line 100... | Line 102... | ||
100 | { |
102 | struct intel_fbc_state_cache *cache) |
101 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
103 | { |
102 | int lines; |
104 | int lines; |
Line 103... | Line 105... | ||
103 | 105 | ||
104 | intel_fbc_get_plane_source_size(crtc, NULL, &lines); |
106 | intel_fbc_get_plane_source_size(cache, NULL, &lines); |
105 | if (INTEL_INFO(dev_priv)->gen >= 7) |
107 | if (INTEL_INFO(dev_priv)->gen >= 7) |
Line 106... | Line 108... | ||
106 | lines = min(lines, 2048); |
108 | lines = min(lines, 2048); |
107 | 109 | ||
108 | /* Hardware needs the full buffer stride, not just the active area. */ |
110 | /* Hardware needs the full buffer stride, not just the active area. */ |
Line 109... | Line -... | ||
109 | return lines * fb->pitches[0]; |
- | |
110 | } |
- | |
111 | 111 | return lines * cache->fb.stride; |
|
112 | static void i8xx_fbc_deactivate(struct drm_i915_private *dev_priv) |
112 | } |
113 | { |
113 | |
114 | u32 fbc_ctl; |
114 | static void i8xx_fbc_deactivate(struct drm_i915_private *dev_priv) |
Line 128... | Line 128... | ||
128 | DRM_DEBUG_KMS("FBC idle timed out\n"); |
128 | DRM_DEBUG_KMS("FBC idle timed out\n"); |
129 | return; |
129 | return; |
130 | } |
130 | } |
131 | } |
131 | } |
Line 132... | Line 132... | ||
132 | 132 | ||
133 | static void i8xx_fbc_activate(struct intel_crtc *crtc) |
133 | static void i8xx_fbc_activate(struct drm_i915_private *dev_priv) |
134 | { |
- | |
135 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
- | |
136 | struct drm_framebuffer *fb = crtc->base.primary->fb; |
134 | { |
137 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
135 | struct intel_fbc_reg_params *params = &dev_priv->fbc.params; |
138 | int cfb_pitch; |
136 | int cfb_pitch; |
139 | int i; |
137 | int i; |
Line 140... | Line -... | ||
140 | u32 fbc_ctl; |
- | |
141 | - | ||
142 | dev_priv->fbc.active = true; |
138 | u32 fbc_ctl; |
143 | 139 | ||
144 | /* Note: fbc.threshold == 1 for i8xx */ |
140 | /* Note: fbc.threshold == 1 for i8xx */ |
145 | cfb_pitch = intel_fbc_calculate_cfb_size(crtc, fb) / FBC_LL_SIZE; |
141 | cfb_pitch = params->cfb_size / FBC_LL_SIZE; |
Line 146... | Line 142... | ||
146 | if (fb->pitches[0] < cfb_pitch) |
142 | if (params->fb.stride < cfb_pitch) |
147 | cfb_pitch = fb->pitches[0]; |
143 | cfb_pitch = params->fb.stride; |
148 | 144 | ||
149 | /* FBC_CTL wants 32B or 64B units */ |
145 | /* FBC_CTL wants 32B or 64B units */ |
Line 159... | Line 155... | ||
159 | if (IS_GEN4(dev_priv)) { |
155 | if (IS_GEN4(dev_priv)) { |
160 | u32 fbc_ctl2; |
156 | u32 fbc_ctl2; |
Line 161... | Line 157... | ||
161 | 157 | ||
162 | /* Set it up... */ |
158 | /* Set it up... */ |
163 | fbc_ctl2 = FBC_CTL_FENCE_DBL | FBC_CTL_IDLE_IMM | FBC_CTL_CPU_FENCE; |
159 | fbc_ctl2 = FBC_CTL_FENCE_DBL | FBC_CTL_IDLE_IMM | FBC_CTL_CPU_FENCE; |
164 | fbc_ctl2 |= FBC_CTL_PLANE(crtc->plane); |
160 | fbc_ctl2 |= FBC_CTL_PLANE(params->crtc.plane); |
165 | I915_WRITE(FBC_CONTROL2, fbc_ctl2); |
161 | I915_WRITE(FBC_CONTROL2, fbc_ctl2); |
166 | I915_WRITE(FBC_FENCE_OFF, get_crtc_fence_y_offset(crtc)); |
162 | I915_WRITE(FBC_FENCE_OFF, params->crtc.fence_y_offset); |
Line 167... | Line 163... | ||
167 | } |
163 | } |
168 | 164 | ||
169 | /* enable it... */ |
165 | /* enable it... */ |
170 | fbc_ctl = I915_READ(FBC_CONTROL); |
166 | fbc_ctl = I915_READ(FBC_CONTROL); |
171 | fbc_ctl &= 0x3fff << FBC_CTL_INTERVAL_SHIFT; |
167 | fbc_ctl &= 0x3fff << FBC_CTL_INTERVAL_SHIFT; |
172 | fbc_ctl |= FBC_CTL_EN | FBC_CTL_PERIODIC; |
168 | fbc_ctl |= FBC_CTL_EN | FBC_CTL_PERIODIC; |
173 | if (IS_I945GM(dev_priv)) |
169 | if (IS_I945GM(dev_priv)) |
174 | fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */ |
170 | fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */ |
175 | fbc_ctl |= (cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT; |
171 | fbc_ctl |= (cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT; |
176 | fbc_ctl |= obj->fence_reg; |
172 | fbc_ctl |= params->fb.fence_reg; |
Line 177... | Line 173... | ||
177 | I915_WRITE(FBC_CONTROL, fbc_ctl); |
173 | I915_WRITE(FBC_CONTROL, fbc_ctl); |
178 | } |
174 | } |
179 | 175 | ||
180 | static bool i8xx_fbc_is_active(struct drm_i915_private *dev_priv) |
176 | static bool i8xx_fbc_is_active(struct drm_i915_private *dev_priv) |
Line 181... | Line 177... | ||
181 | { |
177 | { |
182 | return I915_READ(FBC_CONTROL) & FBC_CTL_EN; |
178 | return I915_READ(FBC_CONTROL) & FBC_CTL_EN; |
183 | } |
- | |
184 | - | ||
185 | static void g4x_fbc_activate(struct intel_crtc *crtc) |
179 | } |
186 | { |
180 | |
Line 187... | Line -... | ||
187 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
- | |
188 | struct drm_framebuffer *fb = crtc->base.primary->fb; |
- | |
189 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
181 | static void g4x_fbc_activate(struct drm_i915_private *dev_priv) |
190 | u32 dpfc_ctl; |
182 | { |
191 | 183 | struct intel_fbc_reg_params *params = &dev_priv->fbc.params; |
|
192 | dev_priv->fbc.active = true; |
184 | u32 dpfc_ctl; |
193 | 185 | ||
194 | dpfc_ctl = DPFC_CTL_PLANE(crtc->plane) | DPFC_SR_EN; |
186 | dpfc_ctl = DPFC_CTL_PLANE(params->crtc.plane) | DPFC_SR_EN; |
Line 195... | Line 187... | ||
195 | if (drm_format_plane_cpp(fb->pixel_format, 0) == 2) |
187 | if (drm_format_plane_cpp(params->fb.pixel_format, 0) == 2) |
Line 196... | Line 188... | ||
196 | dpfc_ctl |= DPFC_CTL_LIMIT_2X; |
188 | dpfc_ctl |= DPFC_CTL_LIMIT_2X; |
197 | else |
189 | else |
198 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
190 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
Line 199... | Line 191... | ||
199 | dpfc_ctl |= DPFC_CTL_FENCE_EN | obj->fence_reg; |
191 | dpfc_ctl |= DPFC_CTL_FENCE_EN | params->fb.fence_reg; |
200 | 192 | ||
201 | I915_WRITE(DPFC_FENCE_YOFF, get_crtc_fence_y_offset(crtc)); |
193 | I915_WRITE(DPFC_FENCE_YOFF, params->crtc.fence_y_offset); |
Line 202... | Line -... | ||
202 | - | ||
203 | /* enable it... */ |
- | |
204 | I915_WRITE(DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
194 | |
205 | } |
195 | /* enable it... */ |
206 | 196 | I915_WRITE(DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
|
207 | static void g4x_fbc_deactivate(struct drm_i915_private *dev_priv) |
197 | } |
208 | { |
198 | |
Line 228... | Line 218... | ||
228 | { |
218 | { |
229 | I915_WRITE(MSG_FBC_REND_STATE, FBC_REND_NUKE); |
219 | I915_WRITE(MSG_FBC_REND_STATE, FBC_REND_NUKE); |
230 | POSTING_READ(MSG_FBC_REND_STATE); |
220 | POSTING_READ(MSG_FBC_REND_STATE); |
231 | } |
221 | } |
Line 232... | Line 222... | ||
232 | 222 | ||
233 | static void ilk_fbc_activate(struct intel_crtc *crtc) |
223 | static void ilk_fbc_activate(struct drm_i915_private *dev_priv) |
234 | { |
- | |
235 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
- | |
236 | struct drm_framebuffer *fb = crtc->base.primary->fb; |
224 | { |
237 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
225 | struct intel_fbc_reg_params *params = &dev_priv->fbc.params; |
238 | u32 dpfc_ctl; |
226 | u32 dpfc_ctl; |
239 | int threshold = dev_priv->fbc.threshold; |
- | |
240 | unsigned int y_offset; |
- | |
241 | - | ||
Line 242... | Line 227... | ||
242 | dev_priv->fbc.active = true; |
227 | int threshold = dev_priv->fbc.threshold; |
243 | 228 | ||
244 | dpfc_ctl = DPFC_CTL_PLANE(crtc->plane); |
229 | dpfc_ctl = DPFC_CTL_PLANE(params->crtc.plane); |
Line 245... | Line 230... | ||
245 | if (drm_format_plane_cpp(fb->pixel_format, 0) == 2) |
230 | if (drm_format_plane_cpp(params->fb.pixel_format, 0) == 2) |
246 | threshold++; |
231 | threshold++; |
247 | 232 | ||
Line 257... | Line 242... | ||
257 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
242 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
258 | break; |
243 | break; |
259 | } |
244 | } |
260 | dpfc_ctl |= DPFC_CTL_FENCE_EN; |
245 | dpfc_ctl |= DPFC_CTL_FENCE_EN; |
261 | if (IS_GEN5(dev_priv)) |
246 | if (IS_GEN5(dev_priv)) |
262 | dpfc_ctl |= obj->fence_reg; |
247 | dpfc_ctl |= params->fb.fence_reg; |
Line 263... | Line -... | ||
263 | - | ||
264 | y_offset = get_crtc_fence_y_offset(crtc); |
248 | |
265 | I915_WRITE(ILK_DPFC_FENCE_YOFF, y_offset); |
249 | I915_WRITE(ILK_DPFC_FENCE_YOFF, params->crtc.fence_y_offset); |
266 | I915_WRITE(ILK_FBC_RT_BASE, i915_gem_obj_ggtt_offset(obj) | ILK_FBC_RT_VALID); |
250 | I915_WRITE(ILK_FBC_RT_BASE, params->fb.ggtt_offset | ILK_FBC_RT_VALID); |
267 | /* enable it... */ |
251 | /* enable it... */ |
Line 268... | Line 252... | ||
268 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
252 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
269 | 253 | ||
270 | if (IS_GEN6(dev_priv)) { |
254 | if (IS_GEN6(dev_priv)) { |
271 | I915_WRITE(SNB_DPFC_CTL_SA, |
255 | I915_WRITE(SNB_DPFC_CTL_SA, |
272 | SNB_CPU_FENCE_ENABLE | obj->fence_reg); |
256 | SNB_CPU_FENCE_ENABLE | params->fb.fence_reg); |
Line 273... | Line 257... | ||
273 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, y_offset); |
257 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, params->crtc.fence_y_offset); |
274 | } |
258 | } |
Line 275... | Line 259... | ||
275 | 259 | ||
276 | intel_fbc_recompress(dev_priv); |
260 | intel_fbc_recompress(dev_priv); |
277 | } |
261 | } |
Line 278... | Line -... | ||
278 | - | ||
279 | static void ilk_fbc_deactivate(struct drm_i915_private *dev_priv) |
- | |
280 | { |
262 | |
281 | u32 dpfc_ctl; |
263 | static void ilk_fbc_deactivate(struct drm_i915_private *dev_priv) |
282 | 264 | { |
|
283 | dev_priv->fbc.active = false; |
265 | u32 dpfc_ctl; |
284 | 266 | ||
Line 293... | Line 275... | ||
293 | static bool ilk_fbc_is_active(struct drm_i915_private *dev_priv) |
275 | static bool ilk_fbc_is_active(struct drm_i915_private *dev_priv) |
294 | { |
276 | { |
295 | return I915_READ(ILK_DPFC_CONTROL) & DPFC_CTL_EN; |
277 | return I915_READ(ILK_DPFC_CONTROL) & DPFC_CTL_EN; |
296 | } |
278 | } |
Line 297... | Line 279... | ||
297 | 279 | ||
298 | static void gen7_fbc_activate(struct intel_crtc *crtc) |
280 | static void gen7_fbc_activate(struct drm_i915_private *dev_priv) |
299 | { |
- | |
300 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
- | |
301 | struct drm_framebuffer *fb = crtc->base.primary->fb; |
281 | { |
302 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
282 | struct intel_fbc_reg_params *params = &dev_priv->fbc.params; |
303 | u32 dpfc_ctl; |
283 | u32 dpfc_ctl; |
Line 304... | Line -... | ||
304 | int threshold = dev_priv->fbc.threshold; |
- | |
305 | - | ||
306 | dev_priv->fbc.active = true; |
284 | int threshold = dev_priv->fbc.threshold; |
307 | 285 | ||
308 | dpfc_ctl = 0; |
286 | dpfc_ctl = 0; |
Line 309... | Line 287... | ||
309 | if (IS_IVYBRIDGE(dev_priv)) |
287 | if (IS_IVYBRIDGE(dev_priv)) |
310 | dpfc_ctl |= IVB_DPFC_CTL_PLANE(crtc->plane); |
288 | dpfc_ctl |= IVB_DPFC_CTL_PLANE(params->crtc.plane); |
Line 311... | Line 289... | ||
311 | 289 | ||
312 | if (drm_format_plane_cpp(fb->pixel_format, 0) == 2) |
290 | if (drm_format_plane_cpp(params->fb.pixel_format, 0) == 2) |
313 | threshold++; |
291 | threshold++; |
Line 335... | Line 313... | ||
335 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
313 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
336 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
314 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
337 | ILK_FBCQ_DIS); |
315 | ILK_FBCQ_DIS); |
338 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
316 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
339 | /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */ |
317 | /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */ |
340 | I915_WRITE(CHICKEN_PIPESL_1(crtc->pipe), |
318 | I915_WRITE(CHICKEN_PIPESL_1(params->crtc.pipe), |
341 | I915_READ(CHICKEN_PIPESL_1(crtc->pipe)) | |
319 | I915_READ(CHICKEN_PIPESL_1(params->crtc.pipe)) | |
342 | HSW_FBCQ_DIS); |
320 | HSW_FBCQ_DIS); |
343 | } |
321 | } |
Line 344... | Line 322... | ||
344 | 322 | ||
Line 345... | Line 323... | ||
345 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
323 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
346 | 324 | ||
347 | I915_WRITE(SNB_DPFC_CTL_SA, |
325 | I915_WRITE(SNB_DPFC_CTL_SA, |
Line 348... | Line 326... | ||
348 | SNB_CPU_FENCE_ENABLE | obj->fence_reg); |
326 | SNB_CPU_FENCE_ENABLE | params->fb.fence_reg); |
349 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, get_crtc_fence_y_offset(crtc)); |
327 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, params->crtc.fence_y_offset); |
Line -... | Line 328... | ||
- | 328 | ||
- | 329 | intel_fbc_recompress(dev_priv); |
|
- | 330 | } |
|
- | 331 | ||
- | 332 | static bool intel_fbc_hw_is_active(struct drm_i915_private *dev_priv) |
|
- | 333 | { |
|
- | 334 | if (INTEL_INFO(dev_priv)->gen >= 5) |
|
- | 335 | return ilk_fbc_is_active(dev_priv); |
|
- | 336 | else if (IS_GM45(dev_priv)) |
|
- | 337 | return g4x_fbc_is_active(dev_priv); |
|
- | 338 | else |
|
- | 339 | return i8xx_fbc_is_active(dev_priv); |
|
- | 340 | } |
|
- | 341 | ||
- | 342 | static void intel_fbc_hw_activate(struct drm_i915_private *dev_priv) |
|
- | 343 | { |
|
- | 344 | struct intel_fbc *fbc = &dev_priv->fbc; |
|
- | 345 | ||
- | 346 | fbc->active = true; |
|
- | 347 | ||
- | 348 | if (INTEL_INFO(dev_priv)->gen >= 7) |
|
- | 349 | gen7_fbc_activate(dev_priv); |
|
- | 350 | else if (INTEL_INFO(dev_priv)->gen >= 5) |
|
- | 351 | ilk_fbc_activate(dev_priv); |
|
- | 352 | else if (IS_GM45(dev_priv)) |
|
- | 353 | g4x_fbc_activate(dev_priv); |
|
- | 354 | else |
|
- | 355 | i8xx_fbc_activate(dev_priv); |
|
- | 356 | } |
|
- | 357 | ||
- | 358 | static void intel_fbc_hw_deactivate(struct drm_i915_private *dev_priv) |
|
- | 359 | { |
|
- | 360 | struct intel_fbc *fbc = &dev_priv->fbc; |
|
- | 361 | ||
- | 362 | fbc->active = false; |
|
- | 363 | ||
- | 364 | if (INTEL_INFO(dev_priv)->gen >= 5) |
|
- | 365 | ilk_fbc_deactivate(dev_priv); |
|
- | 366 | else if (IS_GM45(dev_priv)) |
|
- | 367 | g4x_fbc_deactivate(dev_priv); |
|
350 | 368 | else |
|
351 | intel_fbc_recompress(dev_priv); |
369 | i8xx_fbc_deactivate(dev_priv); |
352 | } |
370 | } |
353 | 371 | ||
354 | /** |
372 | /** |
Line 362... | Line 380... | ||
362 | bool intel_fbc_is_active(struct drm_i915_private *dev_priv) |
380 | bool intel_fbc_is_active(struct drm_i915_private *dev_priv) |
363 | { |
381 | { |
364 | return dev_priv->fbc.active; |
382 | return dev_priv->fbc.active; |
365 | } |
383 | } |
Line 366... | Line -... | ||
366 | - | ||
367 | static void intel_fbc_activate(const struct drm_framebuffer *fb) |
- | |
368 | { |
- | |
369 | struct drm_i915_private *dev_priv = fb->dev->dev_private; |
- | |
370 | struct intel_crtc *crtc = dev_priv->fbc.crtc; |
- | |
371 | - | ||
372 | dev_priv->fbc.activate(crtc); |
- | |
373 | - | ||
374 | dev_priv->fbc.fb_id = fb->base.id; |
- | |
375 | dev_priv->fbc.y = crtc->base.y; |
- | |
376 | } |
- | |
377 | 384 | ||
378 | static void intel_fbc_work_fn(struct work_struct *__work) |
385 | static void intel_fbc_work_fn(struct work_struct *__work) |
379 | { |
386 | { |
380 | struct drm_i915_private *dev_priv = |
387 | struct drm_i915_private *dev_priv = |
- | 388 | container_of(__work, struct drm_i915_private, fbc.work.work); |
|
381 | container_of(__work, struct drm_i915_private, fbc.work.work); |
389 | struct intel_fbc *fbc = &dev_priv->fbc; |
382 | struct intel_fbc_work *work = &dev_priv->fbc.work; |
390 | struct intel_fbc_work *work = &fbc->work; |
- | 391 | struct intel_crtc *crtc = fbc->crtc; |
|
- | 392 | struct drm_vblank_crtc *vblank = &dev_priv->dev->vblank[crtc->pipe]; |
|
- | 393 | ||
- | 394 | if (drm_crtc_vblank_get(&crtc->base)) { |
|
- | 395 | DRM_ERROR("vblank not available for FBC on pipe %c\n", |
|
- | 396 | pipe_name(crtc->pipe)); |
|
- | 397 | ||
383 | struct intel_crtc *crtc = dev_priv->fbc.crtc; |
398 | mutex_lock(&fbc->lock); |
- | 399 | work->scheduled = false; |
|
- | 400 | mutex_unlock(&fbc->lock); |
|
- | 401 | return; |
|
Line 384... | Line 402... | ||
384 | int delay_ms = 50; |
402 | } |
385 | 403 | ||
386 | retry: |
404 | retry: |
387 | /* Delay the actual enabling to let pageflipping cease and the |
405 | /* Delay the actual enabling to let pageflipping cease and the |
388 | * display to settle before starting the compression. Note that |
406 | * display to settle before starting the compression. Note that |
389 | * this delay also serves a second purpose: it allows for a |
407 | * this delay also serves a second purpose: it allows for a |
390 | * vblank to pass after disabling the FBC before we attempt |
408 | * vblank to pass after disabling the FBC before we attempt |
391 | * to modify the control registers. |
- | |
392 | * |
- | |
393 | * A more complicated solution would involve tracking vblanks |
- | |
394 | * following the termination of the page-flipping sequence |
- | |
395 | * and indeed performing the enable as a co-routine and not |
- | |
396 | * waiting synchronously upon the vblank. |
409 | * to modify the control registers. |
- | 410 | * |
|
- | 411 | * WaFbcWaitForVBlankBeforeEnable:ilk,snb |
|
- | 412 | * |
|
- | 413 | * It is also worth mentioning that since work->scheduled_vblank can be |
|
- | 414 | * updated multiple times by the other threads, hitting the timeout is |
|
397 | * |
415 | * not an error condition. We'll just end up hitting the "goto retry" |
- | 416 | * case below. |
|
398 | * WaFbcWaitForVBlankBeforeEnable:ilk,snb |
417 | */ |
- | 418 | wait_event_timeout(vblank->queue, |
|
Line 399... | Line 419... | ||
399 | */ |
419 | drm_crtc_vblank_count(&crtc->base) != work->scheduled_vblank, |
Line 400... | Line 420... | ||
400 | wait_remaining_ms_from_jiffies(work->enable_jiffies, delay_ms); |
420 | msecs_to_jiffies(50)); |
401 | 421 | ||
402 | mutex_lock(&dev_priv->fbc.lock); |
422 | mutex_lock(&fbc->lock); |
Line 403... | Line 423... | ||
403 | 423 | ||
404 | /* Were we cancelled? */ |
424 | /* Were we cancelled? */ |
405 | if (!work->scheduled) |
- | |
406 | goto out; |
425 | if (!work->scheduled) |
407 | 426 | goto out; |
|
408 | /* Were we delayed again while this function was sleeping? */ |
427 | |
Line 409... | Line -... | ||
409 | if (time_after(work->enable_jiffies + msecs_to_jiffies(delay_ms), |
- | |
410 | jiffies)) { |
428 | /* Were we delayed again while this function was sleeping? */ |
Line 411... | Line 429... | ||
411 | mutex_unlock(&dev_priv->fbc.lock); |
429 | if (drm_crtc_vblank_count(&crtc->base) == work->scheduled_vblank) { |
Line 412... | Line 430... | ||
412 | goto retry; |
430 | mutex_unlock(&fbc->lock); |
413 | } |
431 | goto retry; |
414 | - | ||
415 | if (crtc->base.primary->fb == work->fb) |
- | |
416 | intel_fbc_activate(work->fb); |
- | |
417 | - | ||
418 | work->scheduled = false; |
- | |
419 | 432 | } |
|
420 | out: |
433 | |
Line 421... | Line 434... | ||
421 | mutex_unlock(&dev_priv->fbc.lock); |
434 | intel_fbc_hw_activate(dev_priv); |
422 | } |
435 | |
423 | 436 | work->scheduled = false; |
|
424 | static void intel_fbc_cancel_work(struct drm_i915_private *dev_priv) |
437 | |
425 | { |
- | |
426 | WARN_ON(!mutex_is_locked(&dev_priv->fbc.lock)); |
438 | out: |
Line 427... | Line -... | ||
427 | dev_priv->fbc.work.scheduled = false; |
- | |
428 | } |
- | |
429 | - | ||
430 | static void intel_fbc_schedule_activation(struct intel_crtc *crtc) |
- | |
431 | { |
- | |
432 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
- | |
433 | struct intel_fbc_work *work = &dev_priv->fbc.work; |
- | |
434 | - | ||
435 | WARN_ON(!mutex_is_locked(&dev_priv->fbc.lock)); |
- | |
436 | - | ||
437 | /* It is useless to call intel_fbc_cancel_work() in this function since |
- | |
438 | * we're not releasing fbc.lock, so it won't have an opportunity to grab |
- | |
439 | * it to discover that it was cancelled. So we just update the expected |
- | |
440 | * jiffy count. */ |
439 | mutex_unlock(&fbc->lock); |
441 | work->fb = crtc->base.primary->fb; |
- | |
442 | work->scheduled = true; |
- | |
443 | work->enable_jiffies = jiffies; |
- | |
444 | - | ||
445 | schedule_work(&work->work); |
- | |
446 | } |
- | |
447 | - | ||
448 | static void __intel_fbc_deactivate(struct drm_i915_private *dev_priv) |
- | |
449 | { |
- | |
450 | WARN_ON(!mutex_is_locked(&dev_priv->fbc.lock)); |
- | |
451 | - | ||
452 | intel_fbc_cancel_work(dev_priv); |
- | |
453 | - | ||
454 | if (dev_priv->fbc.active) |
- | |
455 | dev_priv->fbc.deactivate(dev_priv); |
- | |
456 | } |
- | |
Line -... | Line 440... | ||
- | 440 | drm_crtc_vblank_put(&crtc->base); |
|
- | 441 | } |
|
457 | 442 | ||
458 | /* |
443 | static void intel_fbc_schedule_activation(struct intel_crtc *crtc) |
459 | * intel_fbc_deactivate - deactivate FBC if it's associated with crtc |
- | |
460 | * @crtc: the CRTC |
- | |
461 | * |
- | |
462 | * This function deactivates FBC if it's associated with the provided CRTC. |
- | |
463 | */ |
- | |
464 | void intel_fbc_deactivate(struct intel_crtc *crtc) |
444 | { |
Line 465... | Line 445... | ||
465 | { |
445 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
- | 446 | struct intel_fbc *fbc = &dev_priv->fbc; |
|
- | 447 | struct intel_fbc_work *work = &fbc->work; |
|
- | 448 | ||
466 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
449 | WARN_ON(!mutex_is_locked(&fbc->lock)); |
467 | - | ||
468 | if (!fbc_supported(dev_priv)) |
450 | |
469 | return; |
451 | if (drm_crtc_vblank_get(&crtc->base)) { |
Line 470... | Line 452... | ||
470 | 452 | DRM_ERROR("vblank not available for FBC on pipe %c\n", |
|
471 | mutex_lock(&dev_priv->fbc.lock); |
- | |
472 | if (dev_priv->fbc.crtc == crtc) |
453 | pipe_name(crtc->pipe)); |
Line 473... | Line 454... | ||
473 | __intel_fbc_deactivate(dev_priv); |
454 | return; |
474 | mutex_unlock(&dev_priv->fbc.lock); |
455 | } |
475 | } |
456 | |
Line 476... | Line 457... | ||
476 | 457 | /* It is useless to call intel_fbc_cancel_work() or cancel_work() in |
|
477 | static void set_no_fbc_reason(struct drm_i915_private *dev_priv, |
- | |
Line -... | Line 458... | ||
- | 458 | * this function since we're not releasing fbc.lock, so it won't have an |
|
478 | const char *reason) |
459 | * opportunity to grab it to discover that it was cancelled. So we just |
- | 460 | * update the expected jiffy count. */ |
|
479 | { |
461 | work->scheduled = true; |
Line 480... | Line 462... | ||
480 | if (dev_priv->fbc.no_fbc_reason == reason) |
462 | work->scheduled_vblank = drm_crtc_vblank_count(&crtc->base); |
- | 463 | drm_crtc_vblank_put(&crtc->base); |
|
481 | return; |
464 | |
Line 482... | Line 465... | ||
482 | 465 | schedule_work(&work->work); |
|
483 | dev_priv->fbc.no_fbc_reason = reason; |
466 | } |
484 | DRM_DEBUG_KMS("Disabling FBC: %s\n", reason); |
467 | |
485 | } |
- | |
486 | - | ||
487 | static bool crtc_can_fbc(struct intel_crtc *crtc) |
468 | static void intel_fbc_deactivate(struct drm_i915_private *dev_priv) |
488 | { |
- | |
489 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
- | |
490 | - | ||
491 | if (fbc_on_pipe_a_only(dev_priv) && crtc->pipe != PIPE_A) |
- | |
492 | return false; |
- | |
493 | 469 | { |
|
494 | if (fbc_on_plane_a_only(dev_priv) && crtc->plane != PLANE_A) |
- | |
495 | return false; |
470 | struct intel_fbc *fbc = &dev_priv->fbc; |
496 | - | ||
497 | return true; |
- | |
Line -... | Line 471... | ||
- | 471 | ||
498 | } |
472 | WARN_ON(!mutex_is_locked(&fbc->lock)); |
499 | 473 | ||
Line 500... | Line -... | ||
500 | static bool crtc_is_valid(struct intel_crtc *crtc) |
- | |
501 | { |
474 | /* Calling cancel_work() here won't help due to the fact that the work |
Line 502... | Line -... | ||
502 | if (!intel_crtc_active(&crtc->base)) |
- | |
503 | return false; |
475 | * function grabs fbc->lock. Just set scheduled to false so the work |
504 | 476 | * function can know it was cancelled. */ |
|
505 | if (!to_intel_plane_state(crtc->base.primary->state)->visible) |
477 | fbc->work.scheduled = false; |
- | 478 | ||
Line 506... | Line 479... | ||
506 | return false; |
479 | if (fbc->active) |
507 | 480 | intel_fbc_hw_deactivate(dev_priv); |
|
Line 508... | Line 481... | ||
508 | return true; |
481 | } |
509 | } |
482 | |
510 | 483 | static bool multiple_pipes_ok(struct intel_crtc *crtc) |
|
Line 579... | Line 552... | ||
579 | } |
552 | } |
Line 580... | Line 553... | ||
580 | 553 | ||
581 | static int intel_fbc_alloc_cfb(struct intel_crtc *crtc) |
554 | static int intel_fbc_alloc_cfb(struct intel_crtc *crtc) |
582 | { |
555 | { |
583 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
556 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
584 | struct drm_framebuffer *fb = crtc->base.primary->state->fb; |
557 | struct intel_fbc *fbc = &dev_priv->fbc; |
585 | struct drm_mm_node *uninitialized_var(compressed_llb); |
558 | struct drm_mm_node *uninitialized_var(compressed_llb); |
Line 586... | Line 559... | ||
586 | int size, fb_cpp, ret; |
559 | int size, fb_cpp, ret; |
Line 587... | Line 560... | ||
587 | 560 | ||
588 | WARN_ON(drm_mm_node_allocated(&dev_priv->fbc.compressed_fb)); |
561 | WARN_ON(drm_mm_node_allocated(&fbc->compressed_fb)); |
Line 589... | Line 562... | ||
589 | 562 | ||
590 | size = intel_fbc_calculate_cfb_size(crtc, fb); |
563 | size = intel_fbc_calculate_cfb_size(dev_priv, &fbc->state_cache); |
591 | fb_cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
564 | fb_cpp = drm_format_plane_cpp(fbc->state_cache.fb.pixel_format, 0); |
592 | 565 | ||
593 | ret = find_compression_threshold(dev_priv, &dev_priv->fbc.compressed_fb, |
566 | ret = find_compression_threshold(dev_priv, &fbc->compressed_fb, |
594 | size, fb_cpp); |
567 | size, fb_cpp); |
Line 595... | Line 568... | ||
595 | if (!ret) |
568 | if (!ret) |
Line 596... | Line 569... | ||
596 | goto err_llb; |
569 | goto err_llb; |
Line 597... | Line 570... | ||
597 | else if (ret > 1) { |
570 | else if (ret > 1) { |
598 | DRM_INFO("Reducing the compressed framebuffer size. This may lead to less power savings than a non-reduced-size. Try to increase stolen memory size if available in BIOS.\n"); |
571 | DRM_INFO("Reducing the compressed framebuffer size. This may lead to less power savings than a non-reduced-size. Try to increase stolen memory size if available in BIOS.\n"); |
599 | 572 | ||
600 | } |
573 | } |
601 | 574 | ||
602 | dev_priv->fbc.threshold = ret; |
575 | fbc->threshold = ret; |
603 | 576 | ||
604 | if (INTEL_INFO(dev_priv)->gen >= 5) |
577 | if (INTEL_INFO(dev_priv)->gen >= 5) |
Line 605... | Line 578... | ||
605 | I915_WRITE(ILK_DPFC_CB_BASE, dev_priv->fbc.compressed_fb.start); |
578 | I915_WRITE(ILK_DPFC_CB_BASE, fbc->compressed_fb.start); |
606 | else if (IS_GM45(dev_priv)) { |
579 | else if (IS_GM45(dev_priv)) { |
607 | I915_WRITE(DPFC_CB_BASE, dev_priv->fbc.compressed_fb.start); |
580 | I915_WRITE(DPFC_CB_BASE, fbc->compressed_fb.start); |
608 | } else { |
581 | } else { |
Line 609... | Line 582... | ||
609 | compressed_llb = kzalloc(sizeof(*compressed_llb), GFP_KERNEL); |
582 | compressed_llb = kzalloc(sizeof(*compressed_llb), GFP_KERNEL); |
Line 610... | Line 583... | ||
610 | if (!compressed_llb) |
583 | if (!compressed_llb) |
611 | goto err_fb; |
584 | goto err_fb; |
612 | 585 | ||
613 | ret = i915_gem_stolen_insert_node(dev_priv, compressed_llb, |
586 | ret = i915_gem_stolen_insert_node(dev_priv, compressed_llb, |
614 | 4096, 4096); |
587 | 4096, 4096); |
Line 615... | Line 588... | ||
615 | if (ret) |
588 | if (ret) |
616 | goto err_fb; |
- | |
617 | 589 | goto err_fb; |
|
Line 618... | Line 590... | ||
618 | dev_priv->fbc.compressed_llb = compressed_llb; |
590 | |
Line 619... | Line 591... | ||
619 | 591 | fbc->compressed_llb = compressed_llb; |
|
620 | I915_WRITE(FBC_CFB_BASE, |
592 | |
621 | dev_priv->mm.stolen_base + dev_priv->fbc.compressed_fb.start); |
593 | I915_WRITE(FBC_CFB_BASE, |
622 | I915_WRITE(FBC_LL_BASE, |
594 | dev_priv->mm.stolen_base + fbc->compressed_fb.start); |
623 | dev_priv->mm.stolen_base + compressed_llb->start); |
595 | I915_WRITE(FBC_LL_BASE, |
624 | } |
596 | dev_priv->mm.stolen_base + compressed_llb->start); |
625 | 597 | } |
|
Line 626... | Line 598... | ||
626 | DRM_DEBUG_KMS("reserved %llu bytes of contiguous stolen space for FBC, threshold: %d\n", |
598 | |
627 | dev_priv->fbc.compressed_fb.size, |
599 | DRM_DEBUG_KMS("reserved %llu bytes of contiguous stolen space for FBC, threshold: %d\n", |
- | 600 | fbc->compressed_fb.size, fbc->threshold); |
|
- | 601 | ||
628 | dev_priv->fbc.threshold); |
602 | return 0; |
629 | 603 | ||
630 | return 0; |
- | |
631 | 604 | err_fb: |
|
632 | err_fb: |
605 | kfree(compressed_llb); |
633 | kfree(compressed_llb); |
606 | i915_gem_stolen_remove_node(dev_priv, &fbc->compressed_fb); |
634 | i915_gem_stolen_remove_node(dev_priv, &dev_priv->fbc.compressed_fb); |
- | |
635 | err_llb: |
607 | err_llb: |
636 | pr_info_once("drm: not enough stolen space for compressed buffer (need %d more bytes), disabling. Hint: you may be able to increase stolen memory size in the BIOS to avoid this.\n", size); |
608 | pr_info_once("drm: not enough stolen space for compressed buffer (need %d more bytes), disabling. Hint: you may be able to increase stolen memory size in the BIOS to avoid this.\n", size); |
637 | return -ENOSPC; |
609 | return -ENOSPC; |
Line 638... | Line 610... | ||
638 | } |
610 | } |
639 | 611 | ||
- | 612 | static void __intel_fbc_cleanup_cfb(struct drm_i915_private *dev_priv) |
|
- | 613 | { |
|
640 | static void __intel_fbc_cleanup_cfb(struct drm_i915_private *dev_priv) |
614 | struct intel_fbc *fbc = &dev_priv->fbc; |
641 | { |
615 | |
Line 642... | Line 616... | ||
642 | if (drm_mm_node_allocated(&dev_priv->fbc.compressed_fb)) |
616 | if (drm_mm_node_allocated(&fbc->compressed_fb)) |
643 | i915_gem_stolen_remove_node(dev_priv, |
617 | i915_gem_stolen_remove_node(dev_priv, &fbc->compressed_fb); |
644 | &dev_priv->fbc.compressed_fb); |
618 | |
645 | 619 | if (fbc->compressed_llb) { |
|
Line 646... | Line 620... | ||
646 | if (dev_priv->fbc.compressed_llb) { |
620 | i915_gem_stolen_remove_node(dev_priv, fbc->compressed_llb); |
647 | i915_gem_stolen_remove_node(dev_priv, |
621 | kfree(fbc->compressed_llb); |
648 | dev_priv->fbc.compressed_llb); |
622 | } |
Line 679... | Line 653... | ||
679 | return false; |
653 | return false; |
Line 680... | Line 654... | ||
680 | 654 | ||
681 | return true; |
655 | return true; |
Line 682... | Line 656... | ||
682 | } |
656 | } |
- | 657 | ||
683 | 658 | static bool pixel_format_is_valid(struct drm_i915_private *dev_priv, |
|
684 | static bool pixel_format_is_valid(struct drm_framebuffer *fb) |
- | |
685 | { |
- | |
686 | struct drm_device *dev = fb->dev; |
- | |
687 | struct drm_i915_private *dev_priv = dev->dev_private; |
659 | uint32_t pixel_format) |
688 | 660 | { |
|
689 | switch (fb->pixel_format) { |
661 | switch (pixel_format) { |
690 | case DRM_FORMAT_XRGB8888: |
662 | case DRM_FORMAT_XRGB8888: |
691 | case DRM_FORMAT_XBGR8888: |
663 | case DRM_FORMAT_XBGR8888: |
692 | return true; |
664 | return true; |
693 | case DRM_FORMAT_XRGB1555: |
665 | case DRM_FORMAT_XRGB1555: |
694 | case DRM_FORMAT_RGB565: |
666 | case DRM_FORMAT_RGB565: |
695 | /* 16bpp not supported on gen2 */ |
667 | /* 16bpp not supported on gen2 */ |
696 | if (IS_GEN2(dev)) |
668 | if (IS_GEN2(dev_priv)) |
697 | return false; |
669 | return false; |
698 | /* WaFbcOnly1to1Ratio:ctg */ |
670 | /* WaFbcOnly1to1Ratio:ctg */ |
699 | if (IS_G4X(dev_priv)) |
671 | if (IS_G4X(dev_priv)) |
Line 711... | Line 683... | ||
711 | * variables instead of just looking at the pipe/plane size. |
683 | * variables instead of just looking at the pipe/plane size. |
712 | */ |
684 | */ |
713 | static bool intel_fbc_hw_tracking_covers_screen(struct intel_crtc *crtc) |
685 | static bool intel_fbc_hw_tracking_covers_screen(struct intel_crtc *crtc) |
714 | { |
686 | { |
715 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
687 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
- | 688 | struct intel_fbc *fbc = &dev_priv->fbc; |
|
716 | unsigned int effective_w, effective_h, max_w, max_h; |
689 | unsigned int effective_w, effective_h, max_w, max_h; |
Line 717... | Line 690... | ||
717 | 690 | ||
718 | if (INTEL_INFO(dev_priv)->gen >= 8 || IS_HASWELL(dev_priv)) { |
691 | if (INTEL_INFO(dev_priv)->gen >= 8 || IS_HASWELL(dev_priv)) { |
719 | max_w = 4096; |
692 | max_w = 4096; |
Line 724... | Line 697... | ||
724 | } else { |
697 | } else { |
725 | max_w = 2048; |
698 | max_w = 2048; |
726 | max_h = 1536; |
699 | max_h = 1536; |
727 | } |
700 | } |
Line 728... | Line 701... | ||
728 | 701 | ||
- | 702 | intel_fbc_get_plane_source_size(&fbc->state_cache, &effective_w, |
|
729 | intel_fbc_get_plane_source_size(crtc, &effective_w, &effective_h); |
703 | &effective_h); |
730 | effective_w += crtc->adjusted_x; |
704 | effective_w += crtc->adjusted_x; |
Line 731... | Line 705... | ||
731 | effective_h += crtc->adjusted_y; |
705 | effective_h += crtc->adjusted_y; |
732 | 706 | ||
Line 733... | Line -... | ||
733 | return effective_w <= max_w && effective_h <= max_h; |
- | |
734 | } |
- | |
735 | - | ||
736 | /** |
- | |
737 | * __intel_fbc_update - activate/deactivate FBC as needed, unlocked |
- | |
738 | * @crtc: the CRTC that triggered the update |
- | |
739 | * |
- | |
740 | * This function completely reevaluates the status of FBC, then activates, |
707 | return effective_w <= max_w && effective_h <= max_h; |
741 | * deactivates or maintains it on the same state. |
708 | } |
742 | */ |
709 | |
- | 710 | static void intel_fbc_update_state_cache(struct intel_crtc *crtc) |
|
- | 711 | { |
|
- | 712 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
|
- | 713 | struct intel_fbc *fbc = &dev_priv->fbc; |
|
- | 714 | struct intel_fbc_state_cache *cache = &fbc->state_cache; |
|
- | 715 | struct intel_crtc_state *crtc_state = |
|
743 | static void __intel_fbc_update(struct intel_crtc *crtc) |
716 | to_intel_crtc_state(crtc->base.state); |
744 | { |
717 | struct intel_plane_state *plane_state = |
745 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
- | |
Line 746... | Line 718... | ||
746 | struct drm_framebuffer *fb; |
718 | to_intel_plane_state(crtc->base.primary->state); |
- | 719 | struct drm_framebuffer *fb = plane_state->base.fb; |
|
Line -... | Line 720... | ||
- | 720 | struct drm_i915_gem_object *obj; |
|
747 | struct drm_i915_gem_object *obj; |
721 | |
748 | const struct drm_display_mode *adjusted_mode; |
722 | WARN_ON(!drm_modeset_is_locked(&crtc->base.mutex)); |
749 | 723 | WARN_ON(!drm_modeset_is_locked(&crtc->base.primary->mutex)); |
|
750 | WARN_ON(!mutex_is_locked(&dev_priv->fbc.lock)); |
724 | |
- | 725 | cache->crtc.mode_flags = crtc_state->base.adjusted_mode.flags; |
|
- | 726 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
|
- | 727 | cache->crtc.hsw_bdw_pixel_rate = |
|
- | 728 | ilk_pipe_pixel_rate(crtc_state); |
|
Line 751... | Line 729... | ||
751 | 729 | ||
752 | if (!multiple_pipes_ok(dev_priv)) { |
730 | cache->plane.rotation = plane_state->base.rotation; |
Line 753... | Line 731... | ||
753 | set_no_fbc_reason(dev_priv, "more than one pipe active"); |
731 | cache->plane.src_w = drm_rect_width(&plane_state->src) >> 16; |
- | 732 | cache->plane.src_h = drm_rect_height(&plane_state->src) >> 16; |
|
754 | goto out_disable; |
733 | cache->plane.visible = plane_state->visible; |
755 | } |
734 | |
- | 735 | if (!cache->plane.visible) |
|
- | 736 | return; |
|
- | 737 | ||
- | 738 | obj = intel_fb_obj(fb); |
|
- | 739 | ||
- | 740 | /* FIXME: We lack the proper locking here, so only run this on the |
|
756 | 741 | * platforms that need. */ |
|
Line -... | Line 742... | ||
- | 742 | if (INTEL_INFO(dev_priv)->gen >= 5 && INTEL_INFO(dev_priv)->gen < 7) |
|
- | 743 | cache->fb.ilk_ggtt_offset = i915_gem_obj_ggtt_offset(obj); |
|
757 | if (!dev_priv->fbc.enabled || dev_priv->fbc.crtc != crtc) |
744 | cache->fb.pixel_format = fb->pixel_format; |
758 | return; |
745 | cache->fb.stride = fb->pitches[0]; |
759 | 746 | cache->fb.fence_reg = obj->fence_reg; |
|
Line -... | Line 747... | ||
- | 747 | cache->fb.tiling_mode = obj->tiling_mode; |
|
- | 748 | } |
|
- | 749 | ||
- | 750 | static bool intel_fbc_can_activate(struct intel_crtc *crtc) |
|
- | 751 | { |
|
760 | if (!crtc_is_valid(crtc)) { |
752 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
761 | set_no_fbc_reason(dev_priv, "no output"); |
753 | struct intel_fbc *fbc = &dev_priv->fbc; |
762 | goto out_disable; |
754 | struct intel_fbc_state_cache *cache = &fbc->state_cache; |
763 | } |
755 | |
764 | 756 | if (!cache->plane.visible) { |
|
Line 765... | Line 757... | ||
765 | fb = crtc->base.primary->fb; |
757 | fbc->no_fbc_reason = "primary plane not visible"; |
766 | obj = intel_fb_obj(fb); |
758 | return false; |
767 | adjusted_mode = &crtc->config->base.adjusted_mode; |
759 | } |
768 | 760 | ||
Line 769... | Line 761... | ||
769 | if ((adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) || |
761 | if ((cache->crtc.mode_flags & DRM_MODE_FLAG_INTERLACE) || |
770 | (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)) { |
762 | (cache->crtc.mode_flags & DRM_MODE_FLAG_DBLSCAN)) { |
771 | set_no_fbc_reason(dev_priv, "incompatible mode"); |
763 | fbc->no_fbc_reason = "incompatible mode"; |
772 | goto out_disable; |
764 | return false; |
773 | } |
765 | } |
774 | 766 | ||
775 | if (!intel_fbc_hw_tracking_covers_screen(crtc)) { |
767 | if (!intel_fbc_hw_tracking_covers_screen(crtc)) { |
776 | set_no_fbc_reason(dev_priv, "mode too large for compression"); |
768 | fbc->no_fbc_reason = "mode too large for compression"; |
777 | goto out_disable; |
769 | return false; |
778 | } |
770 | } |
779 | 771 | ||
780 | /* The use of a CPU fence is mandatory in order to detect writes |
772 | /* The use of a CPU fence is mandatory in order to detect writes |
781 | * by the CPU to the scanout and trigger updates to the FBC. |
773 | * by the CPU to the scanout and trigger updates to the FBC. |
Line 782... | Line 774... | ||
782 | */ |
774 | */ |
783 | if (obj->tiling_mode != I915_TILING_X || |
775 | if (cache->fb.tiling_mode != I915_TILING_X || |
784 | obj->fence_reg == I915_FENCE_REG_NONE) { |
776 | cache->fb.fence_reg == I915_FENCE_REG_NONE) { |
785 | set_no_fbc_reason(dev_priv, "framebuffer not tiled or fenced"); |
777 | fbc->no_fbc_reason = "framebuffer not tiled or fenced"; |
Line 786... | Line 778... | ||
786 | goto out_disable; |
778 | return false; |
787 | } |
779 | } |
788 | if (INTEL_INFO(dev_priv)->gen <= 4 && !IS_G4X(dev_priv) && |
780 | if (INTEL_INFO(dev_priv)->gen <= 4 && !IS_G4X(dev_priv) && |
789 | crtc->base.primary->state->rotation != BIT(DRM_ROTATE_0)) { |
781 | cache->plane.rotation != BIT(DRM_ROTATE_0)) { |
Line 790... | Line 782... | ||
790 | set_no_fbc_reason(dev_priv, "rotation unsupported"); |
782 | fbc->no_fbc_reason = "rotation unsupported"; |
791 | goto out_disable; |
783 | return false; |
792 | } |
- | |
793 | 784 | } |
|
794 | if (!stride_is_valid(dev_priv, fb->pitches[0])) { |
785 | |
795 | set_no_fbc_reason(dev_priv, "framebuffer stride not supported"); |
786 | if (!stride_is_valid(dev_priv, cache->fb.stride)) { |
796 | goto out_disable; |
787 | fbc->no_fbc_reason = "framebuffer stride not supported"; |
Line 797... | Line 788... | ||
797 | } |
788 | return false; |
798 | 789 | } |
|
799 | if (!pixel_format_is_valid(fb)) { |
790 | |
Line 817... | Line 808... | ||
817 | * disable FBC. Notice that it would be possible to disable FBC, wait |
808 | * disable FBC. Notice that it would be possible to disable FBC, wait |
818 | * for a frame, free the stolen node, then try to reenable FBC in case |
809 | * for a frame, free the stolen node, then try to reenable FBC in case |
819 | * we didn't get any invalidate/deactivate calls, but this would require |
810 | * we didn't get any invalidate/deactivate calls, but this would require |
820 | * a lot of tracking just for a specific case. If we conclude it's an |
811 | * a lot of tracking just for a specific case. If we conclude it's an |
821 | * important case, we can implement it later. */ |
812 | * important case, we can implement it later. */ |
822 | if (intel_fbc_calculate_cfb_size(crtc, fb) > |
813 | if (intel_fbc_calculate_cfb_size(dev_priv, &fbc->state_cache) > |
823 | dev_priv->fbc.compressed_fb.size * dev_priv->fbc.threshold) { |
814 | fbc->compressed_fb.size * fbc->threshold) { |
824 | set_no_fbc_reason(dev_priv, "CFB requirements changed"); |
815 | fbc->no_fbc_reason = "CFB requirements changed"; |
- | 816 | return false; |
|
- | 817 | } |
|
- | 818 | ||
- | 819 | return true; |
|
- | 820 | } |
|
- | 821 | ||
- | 822 | static bool intel_fbc_can_choose(struct intel_crtc *crtc) |
|
- | 823 | { |
|
- | 824 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
|
- | 825 | struct intel_fbc *fbc = &dev_priv->fbc; |
|
- | 826 | bool enable_by_default = IS_BROADWELL(dev_priv); |
|
- | 827 | ||
- | 828 | if (intel_vgpu_active(dev_priv->dev)) { |
|
- | 829 | fbc->no_fbc_reason = "VGPU is active"; |
|
- | 830 | return false; |
|
- | 831 | } |
|
- | 832 | ||
- | 833 | if (i915.enable_fbc < 0 && !enable_by_default) { |
|
- | 834 | fbc->no_fbc_reason = "disabled per chip default"; |
|
- | 835 | return false; |
|
- | 836 | } |
|
- | 837 | ||
- | 838 | if (!i915.enable_fbc) { |
|
- | 839 | fbc->no_fbc_reason = "disabled per module param"; |
|
- | 840 | return false; |
|
- | 841 | } |
|
- | 842 | ||
- | 843 | if (fbc_on_pipe_a_only(dev_priv) && crtc->pipe != PIPE_A) { |
|
- | 844 | fbc->no_fbc_reason = "no enabled pipes can have FBC"; |
|
- | 845 | return false; |
|
- | 846 | } |
|
- | 847 | ||
- | 848 | if (fbc_on_plane_a_only(dev_priv) && crtc->plane != PLANE_A) { |
|
- | 849 | fbc->no_fbc_reason = "no enabled planes can have FBC"; |
|
- | 850 | return false; |
|
- | 851 | } |
|
- | 852 | ||
- | 853 | return true; |
|
- | 854 | } |
|
- | 855 | ||
- | 856 | static void intel_fbc_get_reg_params(struct intel_crtc *crtc, |
|
- | 857 | struct intel_fbc_reg_params *params) |
|
- | 858 | { |
|
- | 859 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
|
- | 860 | struct intel_fbc *fbc = &dev_priv->fbc; |
|
- | 861 | struct intel_fbc_state_cache *cache = &fbc->state_cache; |
|
- | 862 | ||
- | 863 | /* Since all our fields are integer types, use memset here so the |
|
- | 864 | * comparison function can rely on memcmp because the padding will be |
|
- | 865 | * zero. */ |
|
- | 866 | memset(params, 0, sizeof(*params)); |
|
- | 867 | ||
- | 868 | params->crtc.pipe = crtc->pipe; |
|
- | 869 | params->crtc.plane = crtc->plane; |
|
- | 870 | params->crtc.fence_y_offset = get_crtc_fence_y_offset(crtc); |
|
- | 871 | ||
- | 872 | params->fb.pixel_format = cache->fb.pixel_format; |
|
- | 873 | params->fb.stride = cache->fb.stride; |
|
- | 874 | params->fb.fence_reg = cache->fb.fence_reg; |
|
- | 875 | ||
- | 876 | params->cfb_size = intel_fbc_calculate_cfb_size(dev_priv, cache); |
|
- | 877 | ||
- | 878 | params->fb.ggtt_offset = cache->fb.ilk_ggtt_offset; |
|
- | 879 | } |
|
- | 880 | ||
- | 881 | static bool intel_fbc_reg_params_equal(struct intel_fbc_reg_params *params1, |
|
- | 882 | struct intel_fbc_reg_params *params2) |
|
- | 883 | { |
|
- | 884 | /* We can use this since intel_fbc_get_reg_params() does a memset. */ |
|
- | 885 | return memcmp(params1, params2, sizeof(*params1)) == 0; |
|
- | 886 | } |
|
- | 887 | ||
- | 888 | void intel_fbc_pre_update(struct intel_crtc *crtc) |
|
- | 889 | { |
|
- | 890 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
|
- | 891 | struct intel_fbc *fbc = &dev_priv->fbc; |
|
- | 892 | ||
- | 893 | if (!fbc_supported(dev_priv)) |
|
- | 894 | return; |
|
- | 895 | ||
- | 896 | mutex_lock(&fbc->lock); |
|
- | 897 | ||
- | 898 | if (!multiple_pipes_ok(crtc)) { |
|
- | 899 | fbc->no_fbc_reason = "more than one pipe active"; |
|
825 | goto out_disable; |
900 | goto deactivate; |
- | 901 | } |
|
- | 902 | ||
- | 903 | if (!fbc->enabled || fbc->crtc != crtc) |
|
- | 904 | goto unlock; |
|
- | 905 | ||
- | 906 | intel_fbc_update_state_cache(crtc); |
|
- | 907 | ||
- | 908 | deactivate: |
|
- | 909 | intel_fbc_deactivate(dev_priv); |
|
- | 910 | unlock: |
|
- | 911 | mutex_unlock(&fbc->lock); |
|
826 | } |
912 | } |
Line -... | Line 913... | ||
- | 913 | ||
- | 914 | static void __intel_fbc_post_update(struct intel_crtc *crtc) |
|
- | 915 | { |
|
- | 916 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
|
- | 917 | struct intel_fbc *fbc = &dev_priv->fbc; |
|
- | 918 | struct intel_fbc_reg_params old_params; |
|
- | 919 | ||
- | 920 | WARN_ON(!mutex_is_locked(&fbc->lock)); |
|
- | 921 | ||
- | 922 | if (!fbc->enabled || fbc->crtc != crtc) |
|
- | 923 | return; |
|
- | 924 | ||
- | 925 | if (!intel_fbc_can_activate(crtc)) { |
|
- | 926 | WARN_ON(fbc->active); |
|
- | 927 | return; |
|
- | 928 | } |
|
- | 929 | ||
- | 930 | old_params = fbc->params; |
|
- | 931 | intel_fbc_get_reg_params(crtc, &fbc->params); |
|
827 | 932 | ||
828 | /* If the scanout has not changed, don't modify the FBC settings. |
933 | /* If the scanout has not changed, don't modify the FBC settings. |
829 | * Note that we make the fundamental assumption that the fb->obj |
934 | * Note that we make the fundamental assumption that the fb->obj |
830 | * cannot be unpinned (and have its GTT offset and fence revoked) |
935 | * cannot be unpinned (and have its GTT offset and fence revoked) |
831 | * without first being decoupled from the scanout and FBC disabled. |
936 | * without first being decoupled from the scanout and FBC disabled. |
832 | */ |
937 | */ |
833 | if (dev_priv->fbc.crtc == crtc && |
938 | if (fbc->active && |
834 | dev_priv->fbc.fb_id == fb->base.id && |
- | |
835 | dev_priv->fbc.y == crtc->base.y && |
- | |
836 | dev_priv->fbc.active) |
939 | intel_fbc_reg_params_equal(&old_params, &fbc->params)) |
Line 837... | Line -... | ||
837 | return; |
- | |
838 | - | ||
839 | if (intel_fbc_is_active(dev_priv)) { |
- | |
840 | /* We update FBC along two paths, after changing fb/crtc |
- | |
841 | * configuration (modeswitching) and after page-flipping |
- | |
842 | * finishes. For the latter, we know that not only did |
- | |
843 | * we disable the FBC at the start of the page-flip |
- | |
844 | * sequence, but also more than one vblank has passed. |
- | |
845 | * |
- | |
846 | * For the former case of modeswitching, it is possible |
- | |
847 | * to switch between two FBC valid configurations |
- | |
848 | * instantaneously so we do need to disable the FBC |
- | |
849 | * before we can modify its control registers. We also |
- | |
850 | * have to wait for the next vblank for that to take |
- | |
851 | * effect. However, since we delay enabling FBC we can |
- | |
852 | * assume that a vblank has passed since disabling and |
- | |
853 | * that we can safely alter the registers in the deferred |
- | |
854 | * callback. |
- | |
855 | * |
- | |
856 | * In the scenario that we go from a valid to invalid |
- | |
857 | * and then back to valid FBC configuration we have |
- | |
858 | * no strict enforcement that a vblank occurred since |
- | |
859 | * disabling the FBC. However, along all current pipe |
- | |
860 | * disabling paths we do need to wait for a vblank at |
- | |
861 | * some point. And we wait before enabling FBC anyway. |
- | |
862 | */ |
940 | return; |
863 | DRM_DEBUG_KMS("deactivating FBC for update\n"); |
- | |
864 | __intel_fbc_deactivate(dev_priv); |
- | |
865 | } |
941 | |
866 | 942 | intel_fbc_deactivate(dev_priv); |
|
867 | intel_fbc_schedule_activation(crtc); |
- | |
868 | dev_priv->fbc.no_fbc_reason = "FBC enabled (not necessarily active)"; |
- | |
869 | return; |
- | |
870 | - | ||
871 | out_disable: |
- | |
872 | /* Multiple disables should be harmless */ |
- | |
873 | if (intel_fbc_is_active(dev_priv)) { |
- | |
874 | DRM_DEBUG_KMS("unsupported config, deactivating FBC\n"); |
- | |
875 | __intel_fbc_deactivate(dev_priv); |
943 | intel_fbc_schedule_activation(crtc); |
Line 876... | Line -... | ||
876 | } |
- | |
877 | } |
- | |
878 | - | ||
879 | /* |
- | |
880 | * intel_fbc_update - activate/deactivate FBC as needed |
- | |
881 | * @crtc: the CRTC that triggered the update |
- | |
882 | * |
944 | fbc->no_fbc_reason = "FBC enabled (active or scheduled)"; |
883 | * This function reevaluates the overall state and activates or deactivates FBC. |
945 | } |
884 | */ |
946 | |
- | 947 | void intel_fbc_post_update(struct intel_crtc *crtc) |
|
Line 885... | Line 948... | ||
885 | void intel_fbc_update(struct intel_crtc *crtc) |
948 | { |
886 | { |
949 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
Line 887... | Line 950... | ||
887 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
950 | struct intel_fbc *fbc = &dev_priv->fbc; |
888 | 951 | ||
889 | if (!fbc_supported(dev_priv)) |
952 | if (!fbc_supported(dev_priv)) |
- | 953 | return; |
|
- | 954 | ||
- | 955 | mutex_lock(&fbc->lock); |
|
- | 956 | __intel_fbc_post_update(crtc); |
|
- | 957 | mutex_unlock(&fbc->lock); |
|
- | 958 | } |
|
- | 959 | ||
- | 960 | static unsigned int intel_fbc_get_frontbuffer_bit(struct intel_fbc *fbc) |
|
890 | return; |
961 | { |
Line 891... | Line 962... | ||
891 | 962 | if (fbc->enabled) |
|
892 | mutex_lock(&dev_priv->fbc.lock); |
963 | return to_intel_plane(fbc->crtc->base.primary)->frontbuffer_bit; |
893 | __intel_fbc_update(crtc); |
964 | else |
894 | mutex_unlock(&dev_priv->fbc.lock); |
965 | return fbc->possible_framebuffer_bits; |
895 | } |
966 | } |
Line 896... | Line 967... | ||
896 | 967 | ||
897 | void intel_fbc_invalidate(struct drm_i915_private *dev_priv, |
968 | void intel_fbc_invalidate(struct drm_i915_private *dev_priv, |
Line 898... | Line 969... | ||
898 | unsigned int frontbuffer_bits, |
969 | unsigned int frontbuffer_bits, |
899 | enum fb_op_origin origin) |
970 | enum fb_op_origin origin) |
Line 900... | Line 971... | ||
900 | { |
971 | { |
Line 901... | Line -... | ||
901 | unsigned int fbc_bits; |
- | |
902 | - | ||
903 | if (!fbc_supported(dev_priv)) |
- | |
904 | return; |
- | |
905 | - | ||
906 | if (origin == ORIGIN_GTT) |
972 | struct intel_fbc *fbc = &dev_priv->fbc; |
Line 907... | Line 973... | ||
907 | return; |
973 | |
908 | 974 | if (!fbc_supported(dev_priv)) |
|
Line 909... | Line 975... | ||
909 | mutex_lock(&dev_priv->fbc.lock); |
975 | return; |
910 | 976 | ||
Line 911... | Line 977... | ||
911 | if (dev_priv->fbc.enabled) |
977 | if (origin == ORIGIN_GTT || origin == ORIGIN_FLIP) |
912 | fbc_bits = INTEL_FRONTBUFFER_PRIMARY(dev_priv->fbc.crtc->pipe); |
978 | return; |
913 | else |
979 | |
- | 980 | mutex_lock(&fbc->lock); |
|
- | 981 | ||
914 | fbc_bits = dev_priv->fbc.possible_framebuffer_bits; |
982 | fbc->busy_bits |= intel_fbc_get_frontbuffer_bit(fbc) & frontbuffer_bits; |
915 | 983 | ||
Line 916... | Line 984... | ||
916 | dev_priv->fbc.busy_bits |= (fbc_bits & frontbuffer_bits); |
984 | if (fbc->enabled && fbc->busy_bits) |
917 | 985 | intel_fbc_deactivate(dev_priv); |
|
Line 918... | Line 986... | ||
918 | if (dev_priv->fbc.busy_bits) |
986 | |
Line 919... | Line 987... | ||
919 | __intel_fbc_deactivate(dev_priv); |
987 | mutex_unlock(&fbc->lock); |
Line 920... | Line 988... | ||
920 | 988 | } |
|
921 | mutex_unlock(&dev_priv->fbc.lock); |
989 | |
- | 990 | void intel_fbc_flush(struct drm_i915_private *dev_priv, |
|
922 | } |
991 | unsigned int frontbuffer_bits, enum fb_op_origin origin) |
923 | 992 | { |
|
924 | void intel_fbc_flush(struct drm_i915_private *dev_priv, |
993 | struct intel_fbc *fbc = &dev_priv->fbc; |
- | 994 | ||
- | 995 | if (!fbc_supported(dev_priv)) |
|
- | 996 | return; |
|
- | 997 | ||
- | 998 | if (origin == ORIGIN_GTT || origin == ORIGIN_FLIP) |
|
- | 999 | return; |
|
- | 1000 | ||
- | 1001 | mutex_lock(&fbc->lock); |
|
- | 1002 | ||
- | 1003 | fbc->busy_bits &= ~frontbuffer_bits; |
|
- | 1004 | ||
- | 1005 | if (!fbc->busy_bits && fbc->enabled && |
|
- | 1006 | (frontbuffer_bits & intel_fbc_get_frontbuffer_bit(fbc))) { |
|
- | 1007 | if (fbc->active) |
|
- | 1008 | intel_fbc_recompress(dev_priv); |
|
- | 1009 | else |
|
- | 1010 | __intel_fbc_post_update(fbc->crtc); |
|
- | 1011 | } |
|
- | 1012 | ||
- | 1013 | mutex_unlock(&fbc->lock); |
|
925 | unsigned int frontbuffer_bits, enum fb_op_origin origin) |
1014 | } |
- | 1015 | ||
- | 1016 | /** |
|
- | 1017 | * intel_fbc_choose_crtc - select a CRTC to enable FBC on |
|
- | 1018 | * @dev_priv: i915 device instance |
|
- | 1019 | * @state: the atomic state structure |
|
- | 1020 | * |
|
- | 1021 | * This function looks at the proposed state for CRTCs and planes, then chooses |
|
- | 1022 | * which pipe is going to have FBC by setting intel_crtc_state->enable_fbc to |
|
- | 1023 | * true. |
|
- | 1024 | * |
|
- | 1025 | * Later, intel_fbc_enable is going to look for state->enable_fbc and then maybe |
|
- | 1026 | * enable FBC for the chosen CRTC. If it does, it will set dev_priv->fbc.crtc. |
|
- | 1027 | */ |
|
- | 1028 | void intel_fbc_choose_crtc(struct drm_i915_private *dev_priv, |
|
- | 1029 | struct drm_atomic_state *state) |
|
- | 1030 | { |
|
- | 1031 | struct intel_fbc *fbc = &dev_priv->fbc; |
|
- | 1032 | struct drm_crtc *crtc; |
|
- | 1033 | struct drm_crtc_state *crtc_state; |
|
- | 1034 | struct drm_plane *plane; |
|
- | 1035 | struct drm_plane_state *plane_state; |
|
- | 1036 | bool fbc_crtc_present = false; |
|
- | 1037 | int i, j; |
|
- | 1038 | ||
- | 1039 | mutex_lock(&fbc->lock); |
|
- | 1040 | ||
- | 1041 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
|
- | 1042 | if (fbc->crtc == to_intel_crtc(crtc)) { |
|
- | 1043 | fbc_crtc_present = true; |
|
- | 1044 | break; |
|
- | 1045 | } |
|
- | 1046 | } |
|
- | 1047 | /* This atomic commit doesn't involve the CRTC currently tied to FBC. */ |
|
- | 1048 | if (!fbc_crtc_present && fbc->crtc != NULL) |
|
- | 1049 | goto out; |
|
- | 1050 | ||
- | 1051 | /* Simply choose the first CRTC that is compatible and has a visible |
|
- | 1052 | * plane. We could go for fancier schemes such as checking the plane |
|
- | 1053 | * size, but this would just affect the few platforms that don't tie FBC |
|
- | 1054 | * to pipe or plane A. */ |
|
- | 1055 | for_each_plane_in_state(state, plane, plane_state, i) { |
|
- | 1056 | struct intel_plane_state *intel_plane_state = |
|
926 | { |
1057 | to_intel_plane_state(plane_state); |
927 | if (!fbc_supported(dev_priv)) |
1058 | |
Line -... | Line 1059... | ||
- | 1059 | if (!intel_plane_state->visible) |
|
928 | return; |
1060 | continue; |
929 | 1061 | ||
Line 930... | Line 1062... | ||
930 | if (origin == ORIGIN_GTT) |
1062 | for_each_crtc_in_state(state, crtc, crtc_state, j) { |
931 | return; |
1063 | struct intel_crtc_state *intel_crtc_state = |
932 | 1064 | to_intel_crtc_state(crtc_state); |
|
933 | mutex_lock(&dev_priv->fbc.lock); |
1065 | |
934 | 1066 | if (plane_state->crtc != crtc) |
|
935 | dev_priv->fbc.busy_bits &= ~frontbuffer_bits; |
1067 | continue; |
- | 1068 | ||
- | 1069 | if (!intel_fbc_can_choose(to_intel_crtc(crtc))) |
|
936 | 1070 | break; |
|
937 | if (!dev_priv->fbc.busy_bits && dev_priv->fbc.enabled) { |
1071 | |
938 | if (origin != ORIGIN_FLIP && dev_priv->fbc.active) { |
1072 | intel_crtc_state->enable_fbc = true; |
939 | intel_fbc_recompress(dev_priv); |
1073 | goto out; |
- | 1074 | } |
|
Line 940... | Line 1075... | ||
940 | } else { |
1075 | } |
941 | __intel_fbc_deactivate(dev_priv); |
1076 | |
Line 942... | Line 1077... | ||
942 | __intel_fbc_update(dev_priv->fbc.crtc); |
1077 | out: |
943 | } |
- | |
944 | } |
- | |
945 | - | ||
946 | mutex_unlock(&dev_priv->fbc.lock); |
- | |
947 | } |
- | |
948 | - | ||
949 | /** |
- | |
950 | * intel_fbc_enable: tries to enable FBC on the CRTC |
- | |
Line -... | Line 1078... | ||
- | 1078 | mutex_unlock(&fbc->lock); |
|
- | 1079 | } |
|
951 | * @crtc: the CRTC |
1080 | |
952 | * |
1081 | /** |
953 | * This function checks if it's possible to enable FBC on the following CRTC, |
1082 | * intel_fbc_enable: tries to enable FBC on the CRTC |
954 | * then enables it. Notice that it doesn't activate FBC. |
1083 | * @crtc: the CRTC |
955 | */ |
- | |
956 | void intel_fbc_enable(struct intel_crtc *crtc) |
- | |
957 | { |
- | |
958 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
1084 | * |
959 | 1085 | * This function checks if the given CRTC was chosen for FBC, then enables it if |
|
Line 960... | Line 1086... | ||
960 | if (!fbc_supported(dev_priv)) |
1086 | * possible. Notice that it doesn't activate FBC. It is valid to call |
961 | return; |
- | |
962 | 1087 | * intel_fbc_enable multiple times for the same pipe without an |
|
963 | mutex_lock(&dev_priv->fbc.lock); |
- | |
Line 964... | Line 1088... | ||
964 | 1088 | * intel_fbc_disable in the middle, as long as it is deactivated. |
|
965 | if (dev_priv->fbc.enabled) { |
1089 | */ |
966 | WARN_ON(dev_priv->fbc.crtc == crtc); |
- | |
967 | goto out; |
- | |
Line -... | Line 1090... | ||
- | 1090 | void intel_fbc_enable(struct intel_crtc *crtc) |
|
968 | } |
1091 | { |
969 | 1092 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
|
970 | WARN_ON(dev_priv->fbc.active); |
1093 | struct intel_fbc *fbc = &dev_priv->fbc; |
971 | WARN_ON(dev_priv->fbc.crtc != NULL); |
1094 | |
Line 972... | Line 1095... | ||
972 | 1095 | if (!fbc_supported(dev_priv)) |
|
973 | if (intel_vgpu_active(dev_priv->dev)) { |
1096 | return; |
Line 974... | Line 1097... | ||
974 | set_no_fbc_reason(dev_priv, "VGPU is active"); |
1097 | |
975 | goto out; |
1098 | mutex_lock(&fbc->lock); |
976 | } |
1099 | |
977 | 1100 | if (fbc->enabled) { |
|
978 | if (i915.enable_fbc < 0) { |
1101 | WARN_ON(fbc->crtc == NULL); |
Line 979... | Line 1102... | ||
979 | set_no_fbc_reason(dev_priv, "disabled per chip default"); |
1102 | if (fbc->crtc == crtc) { |
980 | goto out; |
1103 | WARN_ON(!crtc->config->enable_fbc); |
981 | } |
1104 | WARN_ON(fbc->active); |
Line 1011... | Line 1134... | ||
1011 | * This is the low level function that actually disables FBC. Callers should |
1134 | * This is the low level function that actually disables FBC. Callers should |
1012 | * grab the FBC lock. |
1135 | * grab the FBC lock. |
1013 | */ |
1136 | */ |
1014 | static void __intel_fbc_disable(struct drm_i915_private *dev_priv) |
1137 | static void __intel_fbc_disable(struct drm_i915_private *dev_priv) |
1015 | { |
1138 | { |
1016 | struct intel_crtc *crtc = dev_priv->fbc.crtc; |
1139 | struct intel_fbc *fbc = &dev_priv->fbc; |
- | 1140 | struct intel_crtc *crtc = fbc->crtc; |
|
Line 1017... | Line 1141... | ||
1017 | 1141 | ||
1018 | WARN_ON(!mutex_is_locked(&dev_priv->fbc.lock)); |
1142 | WARN_ON(!mutex_is_locked(&fbc->lock)); |
1019 | WARN_ON(!dev_priv->fbc.enabled); |
1143 | WARN_ON(!fbc->enabled); |
1020 | WARN_ON(dev_priv->fbc.active); |
1144 | WARN_ON(fbc->active); |
Line 1021... | Line 1145... | ||
1021 | assert_pipe_disabled(dev_priv, crtc->pipe); |
1145 | WARN_ON(crtc->active); |
Line 1022... | Line 1146... | ||
1022 | 1146 | ||
Line 1023... | Line 1147... | ||
1023 | DRM_DEBUG_KMS("Disabling FBC on pipe %c\n", pipe_name(crtc->pipe)); |
1147 | DRM_DEBUG_KMS("Disabling FBC on pipe %c\n", pipe_name(crtc->pipe)); |
1024 | 1148 | ||
1025 | __intel_fbc_cleanup_cfb(dev_priv); |
1149 | __intel_fbc_cleanup_cfb(dev_priv); |
Line 1026... | Line 1150... | ||
1026 | 1150 | ||
1027 | dev_priv->fbc.enabled = false; |
1151 | fbc->enabled = false; |
1028 | dev_priv->fbc.crtc = NULL; |
1152 | fbc->crtc = NULL; |
1029 | } |
1153 | } |
1030 | 1154 | ||
1031 | /** |
1155 | /** |
1032 | * intel_fbc_disable_crtc - disable FBC if it's associated with crtc |
1156 | * intel_fbc_disable - disable FBC if it's associated with crtc |
1033 | * @crtc: the CRTC |
1157 | * @crtc: the CRTC |
1034 | * |
1158 | * |
- | 1159 | * This function disables FBC if it's associated with the provided CRTC. |
|
Line 1035... | Line 1160... | ||
1035 | * This function disables FBC if it's associated with the provided CRTC. |
1160 | */ |
1036 | */ |
1161 | void intel_fbc_disable(struct intel_crtc *crtc) |
Line 1037... | Line 1162... | ||
1037 | void intel_fbc_disable_crtc(struct intel_crtc *crtc) |
1162 | { |
1038 | { |
1163 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
1039 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
1164 | struct intel_fbc *fbc = &dev_priv->fbc; |
1040 | 1165 | ||
1041 | if (!fbc_supported(dev_priv)) |
1166 | if (!fbc_supported(dev_priv)) |
1042 | return; |
1167 | return; |
1043 | 1168 | ||
- | 1169 | mutex_lock(&fbc->lock); |
|
- | 1170 | if (fbc->crtc == crtc) { |
|
1044 | mutex_lock(&dev_priv->fbc.lock); |
1171 | WARN_ON(!fbc->enabled); |
Line 1045... | Line 1172... | ||
1045 | if (dev_priv->fbc.crtc == crtc) { |
1172 | WARN_ON(fbc->active); |
1046 | WARN_ON(!dev_priv->fbc.enabled); |
1173 | __intel_fbc_disable(dev_priv); |
1047 | WARN_ON(dev_priv->fbc.active); |
1174 | } |
1048 | __intel_fbc_disable(dev_priv); |
1175 | mutex_unlock(&fbc->lock); |
1049 | } |
1176 | |
1050 | mutex_unlock(&dev_priv->fbc.lock); |
1177 | cancel_work_sync(&fbc->work.work); |
1051 | } |
1178 | } |
1052 | 1179 | ||
- | 1180 | /** |
|
- | 1181 | * intel_fbc_global_disable - globally disable FBC |
|
1053 | /** |
1182 | * @dev_priv: i915 device instance |
1054 | * intel_fbc_disable - globally disable FBC |
1183 | * |
Line 1055... | Line 1184... | ||
1055 | * @dev_priv: i915 device instance |
1184 | * This function disables FBC regardless of which CRTC is associated with it. |
1056 | * |
1185 | */ |
1057 | * This function disables FBC regardless of which CRTC is associated with it. |
1186 | void intel_fbc_global_disable(struct drm_i915_private *dev_priv) |
1058 | */ |
1187 | { |
- | 1188 | struct intel_fbc *fbc = &dev_priv->fbc; |
|
- | 1189 | ||
- | 1190 | if (!fbc_supported(dev_priv)) |
|
- | 1191 | return; |
|
- | 1192 | ||
- | 1193 | mutex_lock(&fbc->lock); |
|
- | 1194 | if (fbc->enabled) |
|
- | 1195 | __intel_fbc_disable(dev_priv); |
|
- | 1196 | mutex_unlock(&fbc->lock); |
|
- | 1197 | ||
- | 1198 | cancel_work_sync(&fbc->work.work); |
|
- | 1199 | } |
|
- | 1200 | ||
- | 1201 | /** |
|
- | 1202 | * intel_fbc_init_pipe_state - initialize FBC's CRTC visibility tracking |
|
- | 1203 | * @dev_priv: i915 device instance |
|
- | 1204 | * |
|
- | 1205 | * The FBC code needs to track CRTC visibility since the older platforms can't |
|
- | 1206 | * have FBC enabled while multiple pipes are used. This function does the |
|
- | 1207 | * initial setup at driver load to make sure FBC is matching the real hardware. |
|
- | 1208 | */ |
|
- | 1209 | void intel_fbc_init_pipe_state(struct drm_i915_private *dev_priv) |
|
- | 1210 | { |
|
- | 1211 | struct intel_crtc *crtc; |
|
1059 | void intel_fbc_disable(struct drm_i915_private *dev_priv) |
1212 | |
Line 1060... | Line 1213... | ||
1060 | { |
1213 | /* Don't even bother tracking anything if we don't need. */ |
1061 | if (!fbc_supported(dev_priv)) |
1214 | if (!no_fbc_on_multiple_pipes(dev_priv)) |
1062 | return; |
1215 | return; |
1063 | 1216 | ||
1064 | mutex_lock(&dev_priv->fbc.lock); |
1217 | for_each_intel_crtc(dev_priv->dev, crtc) |
1065 | if (dev_priv->fbc.enabled) |
1218 | if (intel_crtc_active(&crtc->base) && |
1066 | __intel_fbc_disable(dev_priv); |
1219 | to_intel_plane_state(crtc->base.primary->state)->visible) |
1067 | mutex_unlock(&dev_priv->fbc.lock); |
1220 | dev_priv->fbc.visible_pipes_mask |= (1 << crtc->pipe); |
- | 1221 | } |
|
1068 | } |
1222 | |
Line 1069... | Line 1223... | ||
1069 | 1223 | /** |
|
1070 | /** |
1224 | * intel_fbc_init - Initialize FBC |
1071 | * intel_fbc_init - Initialize FBC |
1225 | * @dev_priv: the i915 device |
1072 | * @dev_priv: the i915 device |
1226 | * |
1073 | * |
1227 | * This function might be called during PM init process. |
Line 1074... | Line 1228... | ||
1074 | * This function might be called during PM init process. |
1228 | */ |
1075 | */ |
1229 | void intel_fbc_init(struct drm_i915_private *dev_priv) |
1076 | void intel_fbc_init(struct drm_i915_private *dev_priv) |
1230 | { |
1077 | { |
1231 | struct intel_fbc *fbc = &dev_priv->fbc; |
Line 1078... | Line 1232... | ||
1078 | enum pipe pipe; |
1232 | enum pipe pipe; |
1079 | 1233 | ||
1080 | INIT_WORK(&dev_priv->fbc.work.work, intel_fbc_work_fn); |
1234 | INIT_WORK(&fbc->work.work, intel_fbc_work_fn); |
Line 1081... | Line 1235... | ||
1081 | mutex_init(&dev_priv->fbc.lock); |
1235 | mutex_init(&fbc->lock); |
1082 | dev_priv->fbc.enabled = false; |
1236 | fbc->enabled = false; |
1083 | dev_priv->fbc.active = false; |
1237 | fbc->active = false; |
Line 1084... | Line -... | ||
1084 | dev_priv->fbc.work.scheduled = false; |
- | |
1085 | - | ||
1086 | if (!HAS_FBC(dev_priv)) { |
- | |
1087 | dev_priv->fbc.no_fbc_reason = "unsupported by this chipset"; |
- | |
1088 | return; |
- | |
1089 | } |
- | |
1090 | - | ||
1091 | for_each_pipe(dev_priv, pipe) { |
- | |
1092 | dev_priv->fbc.possible_framebuffer_bits |= |
- | |
1093 | INTEL_FRONTBUFFER_PRIMARY(pipe); |
- | |
1094 | - | ||
1095 | if (fbc_on_pipe_a_only(dev_priv)) |
- | |
1096 | break; |
- | |
1097 | } |
- | |
1098 | - | ||
1099 | if (INTEL_INFO(dev_priv)->gen >= 7) { |
- | |
1100 | dev_priv->fbc.is_active = ilk_fbc_is_active; |
- | |
1101 | dev_priv->fbc.activate = gen7_fbc_activate; |
1238 | fbc->work.scheduled = false; |
- | 1239 | ||
1102 | dev_priv->fbc.deactivate = ilk_fbc_deactivate; |
1240 | if (!HAS_FBC(dev_priv)) { |
1103 | } else if (INTEL_INFO(dev_priv)->gen >= 5) { |
- | |
Line 1104... | Line 1241... | ||
1104 | dev_priv->fbc.is_active = ilk_fbc_is_active; |
1241 | fbc->no_fbc_reason = "unsupported by this chipset"; |
1105 | dev_priv->fbc.activate = ilk_fbc_activate; |
1242 | return; |
1106 | dev_priv->fbc.deactivate = ilk_fbc_deactivate; |
1243 | } |
1107 | } else if (IS_GM45(dev_priv)) { |
1244 | |
1108 | dev_priv->fbc.is_active = g4x_fbc_is_active; |
1245 | for_each_pipe(dev_priv, pipe) { |
1109 | dev_priv->fbc.activate = g4x_fbc_activate; |
1246 | fbc->possible_framebuffer_bits |= |