]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/xe/rtp: Extract rule_match_item()
authorGustavo Sousa <gustavo.sousa@intel.com>
Fri, 22 May 2026 08:45:20 +0000 (05:45 -0300)
committerGustavo Sousa <gustavo.sousa@intel.com>
Fri, 22 May 2026 13:52:29 +0000 (10:52 -0300)
The current logic in rule_matches() mixes individual rule matching
with the logic necessary for handling OR operations.  Let's simplify
rule_matches() to focus on the latter by extracting individual rule
matching into a separate function called rule_match_item().

Reviewed-by: Matt Roper <matthew.d.roper@intel.com>
Link: https://patch.msgid.link/20260522-rtp-rule-parser-v3-5-0c51039899f4@intel.com
Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
drivers/gpu/drm/xe/xe_rtp.c

index df72b456ab162fca43cf4726b6a95f001bfed464..c49f80f398afab3d405e0bc8688d086f63d5b47f 100644 (file)
@@ -30,6 +30,96 @@ static bool has_samedia(const struct xe_device *xe)
        return xe->info.media_verx100 >= 1300;
 }
 
+static bool rule_match_item(const struct xe_device *xe,
+                           struct xe_gt *gt,
+                           struct xe_hw_engine *hwe,
+                           const struct xe_rtp_rule *r)
+{
+       switch (r->match_type) {
+       case XE_RTP_MATCH_PLATFORM:
+               return xe->info.platform == r->platform;
+       case XE_RTP_MATCH_SUBPLATFORM:
+               return xe->info.platform == r->platform &&
+                       xe->info.subplatform == r->subplatform;
+       case XE_RTP_MATCH_PLATFORM_STEP:
+               if (drm_WARN_ON(&xe->drm, xe->info.step.platform == STEP_NONE))
+                       return false;
+
+               return xe->info.step.platform >= r->step_start &&
+                       xe->info.step.platform < r->step_end;
+       case XE_RTP_MATCH_GRAPHICS_VERSION:
+               if (drm_WARN_ON(&xe->drm, !gt))
+                       return false;
+
+               return xe->info.graphics_verx100 == r->ver_start &&
+                       (!has_samedia(xe) || !xe_gt_is_media_type(gt));
+       case XE_RTP_MATCH_GRAPHICS_VERSION_RANGE:
+               if (drm_WARN_ON(&xe->drm, !gt))
+                       return false;
+
+               return xe->info.graphics_verx100 >= r->ver_start &&
+                       xe->info.graphics_verx100 <= r->ver_end &&
+                       (!has_samedia(xe) || !xe_gt_is_media_type(gt));
+       case XE_RTP_MATCH_GRAPHICS_VERSION_ANY_GT:
+               if (drm_WARN_ON(&xe->drm, !gt))
+                       return false;
+
+               return xe->info.graphics_verx100 == r->ver_start;
+       case XE_RTP_MATCH_GRAPHICS_STEP:
+               if (drm_WARN_ON(&xe->drm, !gt))
+                       return false;
+
+               return xe->info.step.graphics >= r->step_start &&
+                       xe->info.step.graphics < r->step_end &&
+                       (!has_samedia(xe) || !xe_gt_is_media_type(gt));
+       case XE_RTP_MATCH_MEDIA_VERSION:
+               if (drm_WARN_ON(&xe->drm, !gt))
+                       return false;
+
+               return xe->info.media_verx100 == r->ver_start &&
+                       (!has_samedia(xe) || xe_gt_is_media_type(gt));
+       case XE_RTP_MATCH_MEDIA_VERSION_RANGE:
+               if (drm_WARN_ON(&xe->drm, !gt))
+                       return false;
+
+               return xe->info.media_verx100 >= r->ver_start &&
+                       xe->info.media_verx100 <= r->ver_end &&
+                       (!has_samedia(xe) || xe_gt_is_media_type(gt));
+       case XE_RTP_MATCH_MEDIA_STEP:
+               if (drm_WARN_ON(&xe->drm, !gt))
+                       return false;
+
+               return xe->info.step.media >= r->step_start &&
+                       xe->info.step.media < r->step_end &&
+                       (!has_samedia(xe) || xe_gt_is_media_type(gt));
+       case XE_RTP_MATCH_MEDIA_VERSION_ANY_GT:
+               if (drm_WARN_ON(&xe->drm, !gt))
+                       return false;
+
+               return xe->info.media_verx100 == r->ver_start;
+       case XE_RTP_MATCH_INTEGRATED:
+               return !xe->info.is_dgfx;
+       case XE_RTP_MATCH_DISCRETE:
+               return xe->info.is_dgfx;
+       case XE_RTP_MATCH_ENGINE_CLASS:
+               if (drm_WARN_ON(&xe->drm, !hwe))
+                       return false;
+
+               return hwe->class == r->engine_class;
+       case XE_RTP_MATCH_NOT_ENGINE_CLASS:
+               if (drm_WARN_ON(&xe->drm, !hwe))
+                       return false;
+
+               return hwe->class != r->engine_class;
+       case XE_RTP_MATCH_FUNC:
+               return r->match_func(xe, gt, hwe);
+       default:
+               drm_warn(&xe->drm, "Invalid RTP match %u\n",
+                        r->match_type);
+               return false;
+       }
+}
+
 static bool rule_matches_with_err(const struct xe_device *xe,
                                  struct xe_gt *gt,
                                  struct xe_hw_engine *hwe,
@@ -39,14 +129,12 @@ static bool rule_matches_with_err(const struct xe_device *xe,
 {
        const struct xe_rtp_rule *r;
        unsigned int i, rcount = 0;
-       bool match;
 
        if (err)
                *err = 0;
 
        for (r = rules, i = 0; i < n_rules; r = &rules[++i]) {
-               switch (r->match_type) {
-               case XE_RTP_MATCH_OR:
+               if (r->match_type == XE_RTP_MATCH_OR) {
                        if (drm_WARN_ON(&xe->drm, !rcount)) {
                                if (err)
                                        *err = -EINVAL;
@@ -59,128 +147,11 @@ static bool rule_matches_with_err(const struct xe_device *xe,
                         * rules and return true.
                         */
                        return true;
-               case XE_RTP_MATCH_PLATFORM:
-                       match = xe->info.platform == r->platform;
-                       break;
-               case XE_RTP_MATCH_SUBPLATFORM:
-                       match = xe->info.platform == r->platform &&
-                               xe->info.subplatform == r->subplatform;
-                       break;
-               case XE_RTP_MATCH_PLATFORM_STEP:
-                       if (drm_WARN_ON(&xe->drm, xe->info.step.platform == STEP_NONE)) {
-                               match = false;
-                               break;
-                       }
-
-                       match = xe->info.step.platform >= r->step_start &&
-                               xe->info.step.platform < r->step_end;
-                       break;
-               case XE_RTP_MATCH_GRAPHICS_VERSION:
-                       if (drm_WARN_ON(&xe->drm, !gt)) {
-                               match = false;
-                               break;
-                       }
-
-                       match = xe->info.graphics_verx100 == r->ver_start &&
-                               (!has_samedia(xe) || !xe_gt_is_media_type(gt));
-                       break;
-               case XE_RTP_MATCH_GRAPHICS_VERSION_RANGE:
-                       if (drm_WARN_ON(&xe->drm, !gt)) {
-                               match = false;
-                               break;
-                       }
-
-                       match = xe->info.graphics_verx100 >= r->ver_start &&
-                               xe->info.graphics_verx100 <= r->ver_end &&
-                               (!has_samedia(xe) || !xe_gt_is_media_type(gt));
-                       break;
-               case XE_RTP_MATCH_GRAPHICS_VERSION_ANY_GT:
-                       if (drm_WARN_ON(&xe->drm, !gt)) {
-                               match = false;
-                               break;
-                       }
-
-                       match = xe->info.graphics_verx100 == r->ver_start;
-                       break;
-               case XE_RTP_MATCH_GRAPHICS_STEP:
-                       if (drm_WARN_ON(&xe->drm, !gt)) {
-                               match = false;
-                               break;
-                       }
-
-                       match = xe->info.step.graphics >= r->step_start &&
-                               xe->info.step.graphics < r->step_end &&
-                               (!has_samedia(xe) || !xe_gt_is_media_type(gt));
-                       break;
-               case XE_RTP_MATCH_MEDIA_VERSION:
-                       if (drm_WARN_ON(&xe->drm, !gt)) {
-                               match = false;
-                               break;
-                       }
-
-                       match = xe->info.media_verx100 == r->ver_start &&
-                               (!has_samedia(xe) || xe_gt_is_media_type(gt));
-                       break;
-               case XE_RTP_MATCH_MEDIA_VERSION_RANGE:
-                       if (drm_WARN_ON(&xe->drm, !gt)) {
-                               match = false;
-                               break;
-                       }
-
-                       match = xe->info.media_verx100 >= r->ver_start &&
-                               xe->info.media_verx100 <= r->ver_end &&
-                               (!has_samedia(xe) || xe_gt_is_media_type(gt));
-                       break;
-               case XE_RTP_MATCH_MEDIA_STEP:
-                       if (drm_WARN_ON(&xe->drm, !gt)) {
-                               match = false;
-                               break;
-                       }
-
-                       match = xe->info.step.media >= r->step_start &&
-                               xe->info.step.media < r->step_end &&
-                               (!has_samedia(xe) || xe_gt_is_media_type(gt));
-                       break;
-               case XE_RTP_MATCH_MEDIA_VERSION_ANY_GT:
-                       if (drm_WARN_ON(&xe->drm, !gt)) {
-                               match = false;
-                               break;
-                       }
-
-                       match = xe->info.media_verx100 == r->ver_start;
-                       break;
-               case XE_RTP_MATCH_INTEGRATED:
-                       match = !xe->info.is_dgfx;
-                       break;
-               case XE_RTP_MATCH_DISCRETE:
-                       match = xe->info.is_dgfx;
-                       break;
-               case XE_RTP_MATCH_ENGINE_CLASS:
-                       if (drm_WARN_ON(&xe->drm, !hwe)) {
-                               match = false;
-                               break;
-                       }
-
-                       match = hwe->class == r->engine_class;
-                       break;
-               case XE_RTP_MATCH_NOT_ENGINE_CLASS:
-                       if (drm_WARN_ON(&xe->drm, !hwe)) {
-                               match = false;
-                               break;
-                       }
-
-                       match = hwe->class != r->engine_class;
-                       break;
-               case XE_RTP_MATCH_FUNC:
-                       match = r->match_func(xe, gt, hwe);
-                       break;
-               default:
-                       drm_warn(&xe->drm, "Invalid RTP match %u\n",
-                                r->match_type);
-                       match = false;
                }
 
-               if (!match) {
+               if (rule_match_item(xe, gt, hwe, r)) {
+                       rcount++;
+               } else {
                        /*
                         * Advance rules until we find XE_RTP_MATCH_OR to check
                         * if there's another set of conditions to check
@@ -192,8 +163,6 @@ static bool rule_matches_with_err(const struct xe_device *xe,
                                return false;
 
                        rcount = 0;
-               } else {
-                       rcount++;
                }
        }