Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/xe/pat: Extract gt_pta_entry()
@ 2026-03-03 20:46 Gustavo Sousa
  2026-03-03 21:10 ` ✓ CI.KUnit: success for " Patchwork
                   ` (7 more replies)
  0 siblings, 8 replies; 12+ messages in thread
From: Gustavo Sousa @ 2026-03-03 20:46 UTC (permalink / raw)
  To: intel-xe; +Cc: Gustavo Sousa

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.

Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
---
 drivers/gpu/drm/xe/xe_pat.c | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_pat.c b/drivers/gpu/drm/xe/xe_pat.c
index f840d9a58740..34c9031e1e74 100644
--- a/drivers/gpu/drm/xe/xe_pat.c
+++ b/drivers/gpu/drm/xe/xe_pat.c
@@ -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)

---
base-commit: cfc20c776480fda8c1b0517b187bb71ec0781cd4
change-id: 20260303-pat-gt_pta_entry-a342fb34cbf8

Best regards,
--  
Gustavo Sousa <gustavo.sousa@intel.com>


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-03-11 18:49 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-03 20:46 [PATCH] drm/xe/pat: Extract gt_pta_entry() Gustavo Sousa
2026-03-03 21:10 ` ✓ CI.KUnit: success for " Patchwork
2026-03-03 22:04 ` ✗ Xe.CI.BAT: failure " Patchwork
2026-03-04  8:49 ` ✗ Xe.CI.FULL: " Patchwork
2026-03-04  8:55 ` [PATCH] " Bhadane, Dnyaneshwar
2026-03-11 18:48   ` Gustavo Sousa
2026-03-05  9:45 ` ✗ Xe.CI.BAT: failure for " Patchwork
2026-03-06  7:58 ` ✓ CI.KUnit: success for drm/xe/pat: Extract gt_pta_entry() (rev2) Patchwork
2026-03-06  8:59 ` ✗ Xe.CI.BAT: failure " Patchwork
2026-03-11 15:14   ` Gustavo Sousa
2026-03-07  8:30 ` ✗ Xe.CI.FULL: " Patchwork
2026-03-11 18:01   ` Gustavo Sousa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox