drm/i915: Allow optimized platform checks
authorTvrtko Ursulin <tvrtko.ursulin@intel.com>
Wed, 27 Sep 2017 16:41:38 +0000 (17:41 +0100)
committerTvrtko Ursulin <tvrtko.ursulin@intel.com>
Thu, 28 Sep 2017 11:47:19 +0000 (12:47 +0100)
If we store the platform as a bitmask, and convert the
IS_PLATFORM macro to use it, we allow the compiler to
merge the IS_PLATFORM(a) || IS_PLATFORM(b) || ... checks
into a single conditional.

As a secondary benefit this saves almost 1k of text:

    text           data     bss     dec     hex filename
-1460254          60014    3656 1523924  1740d4 drivers/gpu/drm/i915/i915.ko
+1459260          60026    3656 1522942  173cfe drivers/gpu/drm/i915/i915.ko

v2: Removed the infamous -1.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Jani Nikula <jani.nikula@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Acked-by: Jani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20170927164138.15474-1-tvrtko.ursulin@linux.intel.com
drivers/gpu/drm/i915/i915_drv.c
drivers/gpu/drm/i915/i915_drv.h

index 7056bb299dc6f6e921e5177bf4114ee94ccb3ee5..59ac9199b35dc6b93eb28edfb7d9f4794b904816 100644 (file)
@@ -870,6 +870,10 @@ static int i915_driver_init_early(struct drm_i915_private *dev_priv,
        memcpy(device_info, match_info, sizeof(*device_info));
        device_info->device_id = dev_priv->drm.pdev->device;
 
+       BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
+                    sizeof(device_info->platform_mask) * BITS_PER_BYTE);
+       device_info->platform_mask = BIT(device_info->platform);
+
        BUG_ON(device_info->gen > sizeof(device_info->gen_mask) * BITS_PER_BYTE);
        device_info->gen_mask = BIT(device_info->gen - 1);
 
index 4e2fcdd4ce9ef9463fae75ff8a6218e76d8a894d..59fd4bceec7bfbb15d321db6f8abb48267f4ba42 100644 (file)
@@ -861,6 +861,7 @@ struct intel_device_info {
        u8 ring_mask; /* Rings supported by the HW */
 
        enum intel_platform platform;
+       u32 platform_mask;
 
        u32 display_mmio_offset;
 
@@ -2913,7 +2914,7 @@ intel_info(const struct drm_i915_private *dev_priv)
 #define IS_REVID(p, since, until) \
        (INTEL_REVID(p) >= (since) && INTEL_REVID(p) <= (until))
 
-#define IS_PLATFORM(dev_priv, p) ((dev_priv)->info.platform == (p))
+#define IS_PLATFORM(dev_priv, p) ((dev_priv)->info.platform_mask & BIT(p))
 
 #define IS_I830(dev_priv)      IS_PLATFORM(dev_priv, INTEL_I830)
 #define IS_I845G(dev_priv)     IS_PLATFORM(dev_priv, INTEL_I845G)