diff options
author | Daniel Vetter <daniel.vetter@ffwll.ch> | 2014-12-08 10:40:10 -0500 |
---|---|---|
committer | Daniel Vetter <daniel.vetter@ffwll.ch> | 2014-12-15 03:54:22 -0500 |
commit | 5f77eeb05c9ee1de03fbe695b41362aae401726a (patch) | |
tree | 0279a0d9b2b3ba2963121cdd1a4fac7a063384f0 /drivers/gpu | |
parent | 3f7531c3b37d232122d5b7c8564d4ea800adaa88 (diff) |
drm/i915: Use BUILD_BUG if possible in the i915 WARN_ON
Faster feedback to errors is always better. This is inspired by the
addition to WARN_ONs to mask/enable helpers for registers to make sure
callers have the arguments ordered correctly: Pretty much always the
arguments are static.
We use WARN_ON(1) a lot in default switch statements though where we
should always handle all cases. So add a new macro specifically for
that.
The idea to use __builtin_constant_p is from Chris Wilson.
v2: Use the ({}) gcc-ism to avoid the static inline, suggested by
Dave. My first attempt used __cond as the temp var, which is the same
used by BUILD_BUG_ON, but with inverted sense. Hilarity ensued, so
sprinkle i915 into the name.
Also use a temporary variable to only evaluate the condition once,
suggested by Damien.
v3: It's crazy but apparently 32bit gcc can't compile out the
BUILD_BUG_ON in a lot of cases and just falls over. I have no idea
why, but until clue grows just disable this nifty idea on 32bit
builds. Reported by 0-day builder.
v4: Got it all wrong, apparently its the gcc version. We need 4.9+.
Now reported by Imre.
v5: Chris suggested to add the case to MISSING_CASE for speedier
debug.
v6: Even some gcc 4.9 versions don't see through the maze, so give up
for now. Keep the skeleton and MISSING_CASE stuff though.
Cc: Imre Deak <imre.deak@intel.com>
Cc: Damien Lespiau <damien.lespiau@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Dave Gordon <david.s.gordon@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Diffstat (limited to 'drivers/gpu')
-rw-r--r-- | drivers/gpu/drm/i915/i915_debugfs.c | 2 | ||||
-rw-r--r-- | drivers/gpu/drm/i915/i915_drv.h | 14 | ||||
-rw-r--r-- | drivers/gpu/drm/i915/i915_gem_gtt.c | 6 | ||||
-rw-r--r-- | drivers/gpu/drm/i915/intel_display.c | 4 | ||||
-rw-r--r-- | drivers/gpu/drm/i915/intel_uncore.c | 4 |
5 files changed, 21 insertions, 9 deletions
diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c index 165a38f36009..479e0c119111 100644 --- a/drivers/gpu/drm/i915/i915_debugfs.c +++ b/drivers/gpu/drm/i915/i915_debugfs.c | |||
@@ -2347,7 +2347,7 @@ static const char *power_domain_str(enum intel_display_power_domain domain) | |||
2347 | case POWER_DOMAIN_INIT: | 2347 | case POWER_DOMAIN_INIT: |
2348 | return "INIT"; | 2348 | return "INIT"; |
2349 | default: | 2349 | default: |
2350 | WARN_ON(1); | 2350 | MISSING_CASE(domain); |
2351 | return "?"; | 2351 | return "?"; |
2352 | } | 2352 | } |
2353 | } | 2353 | } |
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index c74dc946cbf6..5f4cca3ef01c 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h | |||
@@ -58,7 +58,19 @@ | |||
58 | #define DRIVER_DATE "20141205" | 58 | #define DRIVER_DATE "20141205" |
59 | 59 | ||
60 | #undef WARN_ON | 60 | #undef WARN_ON |
61 | #define WARN_ON(x) WARN(x, "WARN_ON(" #x ")") | 61 | /* Many gcc seem to no see through this and fall over :( */ |
62 | #if 0 | ||
63 | #define WARN_ON(x) ({ \ | ||
64 | bool __i915_warn_cond = (x); \ | ||
65 | if (__builtin_constant_p(__i915_warn_cond)) \ | ||
66 | BUILD_BUG_ON(__i915_warn_cond); \ | ||
67 | WARN(__i915_warn_cond, "WARN_ON(" #x ")"); }) | ||
68 | #else | ||
69 | #define WARN_ON(x) WARN((x), "WARN_ON(" #x ")") | ||
70 | #endif | ||
71 | |||
72 | #define MISSING_CASE(x) WARN(1, "Missing switch case (%lu) in %s\n", \ | ||
73 | (long) (x), __func__); | ||
62 | 74 | ||
63 | enum pipe { | 75 | enum pipe { |
64 | INVALID_PIPE = -1, | 76 | INVALID_PIPE = -1, |
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c index ac03a382000b..ce4e46c443a1 100644 --- a/drivers/gpu/drm/i915/i915_gem_gtt.c +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c | |||
@@ -132,7 +132,7 @@ static gen6_gtt_pte_t snb_pte_encode(dma_addr_t addr, | |||
132 | pte |= GEN6_PTE_UNCACHED; | 132 | pte |= GEN6_PTE_UNCACHED; |
133 | break; | 133 | break; |
134 | default: | 134 | default: |
135 | WARN_ON(1); | 135 | MISSING_CASE(level); |
136 | } | 136 | } |
137 | 137 | ||
138 | return pte; | 138 | return pte; |
@@ -156,7 +156,7 @@ static gen6_gtt_pte_t ivb_pte_encode(dma_addr_t addr, | |||
156 | pte |= GEN6_PTE_UNCACHED; | 156 | pte |= GEN6_PTE_UNCACHED; |
157 | break; | 157 | break; |
158 | default: | 158 | default: |
159 | WARN_ON(1); | 159 | MISSING_CASE(level); |
160 | } | 160 | } |
161 | 161 | ||
162 | return pte; | 162 | return pte; |
@@ -1146,7 +1146,7 @@ int i915_ppgtt_init_hw(struct drm_device *dev) | |||
1146 | else if (INTEL_INFO(dev)->gen >= 8) | 1146 | else if (INTEL_INFO(dev)->gen >= 8) |
1147 | gen8_ppgtt_enable(dev); | 1147 | gen8_ppgtt_enable(dev); |
1148 | else | 1148 | else |
1149 | WARN_ON(1); | 1149 | MISSING_CASE(INTEL_INFO(dev)->gen); |
1150 | 1150 | ||
1151 | if (ppgtt) { | 1151 | if (ppgtt) { |
1152 | for_each_ring(ring, dev_priv, i) { | 1152 | for_each_ring(ring, dev_priv, i) { |
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c index 841af6c1f50b..878c4857ff49 100644 --- a/drivers/gpu/drm/i915/intel_display.c +++ b/drivers/gpu/drm/i915/intel_display.c | |||
@@ -4847,7 +4847,7 @@ static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) | |||
4847 | cmd = 0; | 4847 | cmd = 0; |
4848 | break; | 4848 | break; |
4849 | default: | 4849 | default: |
4850 | WARN_ON(1); | 4850 | MISSING_CASE(cdclk); |
4851 | return; | 4851 | return; |
4852 | } | 4852 | } |
4853 | 4853 | ||
@@ -8224,7 +8224,7 @@ static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base) | |||
8224 | cntl |= CURSOR_MODE_256_ARGB_AX; | 8224 | cntl |= CURSOR_MODE_256_ARGB_AX; |
8225 | break; | 8225 | break; |
8226 | default: | 8226 | default: |
8227 | WARN_ON(1); | 8227 | MISSING_CASE(intel_crtc->cursor_width); |
8228 | return; | 8228 | return; |
8229 | } | 8229 | } |
8230 | cntl |= pipe << 28; /* Connect to correct pipe */ | 8230 | cntl |= pipe << 28; /* Connect to correct pipe */ |
diff --git a/drivers/gpu/drm/i915/intel_uncore.c b/drivers/gpu/drm/i915/intel_uncore.c index 46de8d75b4bf..883d2febb705 100644 --- a/drivers/gpu/drm/i915/intel_uncore.c +++ b/drivers/gpu/drm/i915/intel_uncore.c | |||
@@ -1202,7 +1202,7 @@ void intel_uncore_init(struct drm_device *dev) | |||
1202 | 1202 | ||
1203 | switch (INTEL_INFO(dev)->gen) { | 1203 | switch (INTEL_INFO(dev)->gen) { |
1204 | default: | 1204 | default: |
1205 | WARN_ON(1); | 1205 | MISSING_CASE(INTEL_INFO(dev)->gen); |
1206 | return; | 1206 | return; |
1207 | case 9: | 1207 | case 9: |
1208 | ASSIGN_WRITE_MMIO_VFUNCS(gen9); | 1208 | ASSIGN_WRITE_MMIO_VFUNCS(gen9); |
@@ -1300,7 +1300,7 @@ int i915_reg_read_ioctl(struct drm_device *dev, | |||
1300 | reg->val = I915_READ8(reg->offset); | 1300 | reg->val = I915_READ8(reg->offset); |
1301 | break; | 1301 | break; |
1302 | default: | 1302 | default: |
1303 | WARN_ON(1); | 1303 | MISSING_CASE(entry->size); |
1304 | ret = -EINVAL; | 1304 | ret = -EINVAL; |
1305 | goto out; | 1305 | goto out; |
1306 | } | 1306 | } |