Skip to content

Commit 922044c

Browse files
vsyrjaladanvet
authored andcommitted
drm/i915: Avoid div by zero when pixel clock is large
Make sure the line_time_us isn't zero in the gmch watermarks code as that would cause a div by zero. This can be triggered by specifying a very fast pixel clock for the mode. At some point we should probably just switch over to using the same math we use on PCH platforms which avoids such intermediate rounded results. Also we should verify the user provided mode much more rigorously. At the moment we accept pretty much anything. Note that "very fast mode" here means above 74.25 GHz. Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> [danvet: Add Ville's clarification of what "very fast" means.] Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
1 parent 77961eb commit 922044c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/gpu/drm/i915/intel_pm.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ static bool g4x_compute_wm0(struct drm_device *dev,
11341134
*plane_wm = display->max_wm;
11351135

11361136
/* Use the large buffer method to calculate cursor watermark */
1137-
line_time_us = ((htotal * 1000) / clock);
1137+
line_time_us = max(htotal * 1000 / clock, 1);
11381138
line_count = (cursor_latency_ns / line_time_us + 1000) / 1000;
11391139
entries = line_count * 64 * pixel_size;
11401140
tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8;
@@ -1210,7 +1210,7 @@ static bool g4x_compute_srwm(struct drm_device *dev,
12101210
hdisplay = to_intel_crtc(crtc)->config.pipe_src_w;
12111211
pixel_size = crtc->fb->bits_per_pixel / 8;
12121212

1213-
line_time_us = (htotal * 1000) / clock;
1213+
line_time_us = max(htotal * 1000 / clock, 1);
12141214
line_count = (latency_ns / line_time_us + 1000) / 1000;
12151215
line_size = hdisplay * pixel_size;
12161216

@@ -1443,7 +1443,7 @@ static void i965_update_wm(struct drm_crtc *unused_crtc)
14431443
unsigned long line_time_us;
14441444
int entries;
14451445

1446-
line_time_us = ((htotal * 1000) / clock);
1446+
line_time_us = max(htotal * 1000 / clock, 1);
14471447

14481448
/* Use ns/us then divide to preserve precision */
14491449
entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
@@ -1569,7 +1569,7 @@ static void i9xx_update_wm(struct drm_crtc *unused_crtc)
15691569
unsigned long line_time_us;
15701570
int entries;
15711571

1572-
line_time_us = (htotal * 1000) / clock;
1572+
line_time_us = max(htotal * 1000 / clock, 1);
15731573

15741574
/* Use ns/us then divide to preserve precision */
15751575
entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *

0 commit comments

Comments
 (0)