]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/xe/pat: Extract gt_pta_entry()
authorGustavo Sousa <gustavo.sousa@intel.com>
Tue, 3 Mar 2026 20:46:17 +0000 (17:46 -0300)
committerGustavo Sousa <gustavo.sousa@intel.com>
Wed, 11 Mar 2026 18:05:05 +0000 (15:05 -0300)
Avoid code duplication by extracting the logic for selection of the
correct PAT_PTA entry for a GT into function gt_pta_entry() and using
that function whenever necessary.

Reviewed-by: Dnyaneshwar Bhadane <dnyaneshwar.bhadane@intel.com>
Link: https://patch.msgid.link/20260303-pat-gt_pta_entry-v1-1-0dee8e1e7bd9@intel.com
Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
drivers/gpu/drm/xe/xe_pat.c

index f840d9a587402c9ff0d63ddd756b2ec745e622d5..34c9031e1e74b6c6b21f36e8319828b8c6a28c3b 100644 (file)
@@ -311,10 +311,25 @@ u16 xe_pat_index_get_l3_policy(struct xe_device *xe, u16 pat_index)
        return REG_FIELD_GET(XE2_L3_POLICY, xe->pat.table[pat_index].value);
 }
 
+static const struct xe_pat_table_entry *gt_pta_entry(struct xe_gt *gt)
+{
+       struct xe_device *xe = gt_to_xe(gt);
+
+       if (xe_gt_is_main_type(gt))
+               return xe->pat.pat_primary_pta;
+
+       if (xe_gt_is_media_type(gt))
+               return xe->pat.pat_media_pta;
+
+       xe_assert(xe, false);
+       return NULL;
+}
+
 static void program_pat(struct xe_gt *gt, const struct xe_pat_table_entry table[],
                        int n_entries)
 {
        struct xe_device *xe = gt_to_xe(gt);
+       const struct xe_pat_table_entry *pta_entry = gt_pta_entry(gt);
 
        for (int i = 0; i < n_entries; i++) {
                struct xe_reg reg = XE_REG(_PAT_INDEX(i));
@@ -324,16 +339,16 @@ static void program_pat(struct xe_gt *gt, const struct xe_pat_table_entry table[
 
        if (xe->pat.pat_ats)
                xe_mmio_write32(&gt->mmio, XE_REG(_PAT_ATS), xe->pat.pat_ats->value);
-       if (xe->pat.pat_primary_pta && xe_gt_is_main_type(gt))
-               xe_mmio_write32(&gt->mmio, XE_REG(_PAT_PTA), xe->pat.pat_primary_pta->value);
-       if (xe->pat.pat_media_pta && xe_gt_is_media_type(gt))
-               xe_mmio_write32(&gt->mmio, XE_REG(_PAT_PTA), xe->pat.pat_media_pta->value);
+
+       if (pta_entry)
+               xe_mmio_write32(&gt->mmio, XE_REG(_PAT_PTA), pta_entry->value);
 }
 
 static void program_pat_mcr(struct xe_gt *gt, const struct xe_pat_table_entry table[],
                            int n_entries)
 {
        struct xe_device *xe = gt_to_xe(gt);
+       const struct xe_pat_table_entry *pta_entry = gt_pta_entry(gt);
 
        for (int i = 0; i < n_entries; i++) {
                struct xe_reg_mcr reg_mcr = XE_REG_MCR(_PAT_INDEX(i));
@@ -343,10 +358,9 @@ static void program_pat_mcr(struct xe_gt *gt, const struct xe_pat_table_entry ta
 
        if (xe->pat.pat_ats)
                xe_gt_mcr_multicast_write(gt, XE_REG_MCR(_PAT_ATS), xe->pat.pat_ats->value);
-       if (xe->pat.pat_primary_pta && xe_gt_is_main_type(gt))
-               xe_gt_mcr_multicast_write(gt, XE_REG_MCR(_PAT_PTA), xe->pat.pat_primary_pta->value);
-       if (xe->pat.pat_media_pta && xe_gt_is_media_type(gt))
-               xe_gt_mcr_multicast_write(gt, XE_REG_MCR(_PAT_PTA), xe->pat.pat_media_pta->value);
+
+       if (pta_entry)
+               xe_gt_mcr_multicast_write(gt, XE_REG_MCR(_PAT_PTA), pta_entry->value);
 }
 
 static int xelp_dump(struct xe_gt *gt, struct drm_printer *p)
@@ -677,8 +691,7 @@ int xe_pat_dump(struct xe_gt *gt, struct drm_printer *p)
 int xe_pat_dump_sw_config(struct xe_gt *gt, struct drm_printer *p)
 {
        struct xe_device *xe = gt_to_xe(gt);
-       const struct xe_pat_table_entry *pta_entry = xe_gt_is_main_type(gt) ?
-               xe->pat.pat_primary_pta : xe->pat.pat_media_pta;
+       const struct xe_pat_table_entry *pta_entry = gt_pta_entry(gt);
        char label[PAT_LABEL_LEN];
 
        if (!xe->pat.table || !xe->pat.n_entries)