From: Tvrtko Ursulin Date: Tue, 4 Oct 2016 08:29:28 +0000 (+0100) Subject: drm/i915: Use binary search when looking for shadowed registers X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=5a659383816aa548e7a1049d3dd5dd552966acac;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git drm/i915: Use binary search when looking for shadowed registers Simply replace the linear search with the kernel's binary search implementation. There is only six registers currently in that table so this may not be that interesting. It adds a function call so hopefully remains performance neutral for now. v2: No need for manual conversion to bool for return. (Joonas Lahtinen) Signed-off-by: Tvrtko Ursulin Reviewed-by: Joonas Lahtinen Reviewed-by: Chris Wilson --- diff --git a/drivers/gpu/drm/i915/intel_uncore.c b/drivers/gpu/drm/i915/intel_uncore.c index d7c9b6bc6e5e..8ac684598cec 100644 --- a/drivers/gpu/drm/i915/intel_uncore.c +++ b/drivers/gpu/drm/i915/intel_uncore.c @@ -691,14 +691,30 @@ static void intel_shadow_table_check(void) } } +static int mmio_reg_cmp(const void *key, const void *elt) +{ + u32 offset = (u32)(unsigned long)key; + i915_reg_t *reg = (i915_reg_t *)elt; + + if (offset < i915_mmio_reg_offset(*reg)) + return -1; + else if (offset > i915_mmio_reg_offset(*reg)) + return 1; + else + return 0; +} + static bool is_gen8_shadowed(u32 offset) { - int i; - for (i = 0; i < ARRAY_SIZE(gen8_shadowed_regs); i++) - if (offset == gen8_shadowed_regs[i].reg) - return true; + i915_reg_t *reg; - return false; + reg = bsearch((void *)(unsigned long)offset, + (const void *)gen8_shadowed_regs, + ARRAY_SIZE(gen8_shadowed_regs), + sizeof(i915_reg_t), + mmio_reg_cmp); + + return reg; } #define __gen8_reg_write_fw_domains(offset) \