[Intel-xe] [RFC PATCH v3 2/3] drm/xe: Introduce function pointers in xe_guc_pc.c with local structure

Francois Dugast francois.dugast at intel.com
Mon Mar 20 08:12:56 UTC 2023


This is similar to the previous commit which was for xe_gt.c.
A local structure of function pointers is used as a minimal
hardware abstraction layer to split between common and platform
specific code. This structure is initialized once with the
functions matching the platform, then it is used in the common
code with no need for switch or if/else to detect the platform.
For now only the functions init_fused_rp_values() and
update_rpe_value() are refactored.

Signed-off-by: Francois Dugast <francois.dugast at intel.com>
---
 drivers/gpu/drm/xe/xe_device_types.h |  1 +
 drivers/gpu/drm/xe/xe_guc_pc.c       | 51 +++++++++++++++++++++++-----
 2 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h
index 7d72fb3ff08d..f4b007bd0ee0 100644
--- a/drivers/gpu/drm/xe/xe_device_types.h
+++ b/drivers/gpu/drm/xe/xe_device_types.h
@@ -314,6 +314,7 @@ struct xe_device {
 	} params;
 #endif
 	const struct xe_gt_platform_funcs *gt_funcs;
+	const struct xe_guc_pc_platform_funcs *guc_pc_funcs;
 };
 
 /**
diff --git a/drivers/gpu/drm/xe/xe_guc_pc.c b/drivers/gpu/drm/xe/xe_guc_pc.c
index 5a8d827ba770..ef3ccf83ea3a 100644
--- a/drivers/gpu/drm/xe/xe_guc_pc.c
+++ b/drivers/gpu/drm/xe/xe_guc_pc.c
@@ -117,6 +117,26 @@ pc_to_maps(struct xe_guc_pc *pc)
 	return &pc->bo->vmap;
 }
 
+struct xe_guc_pc_platform_funcs {
+	void (*init_fused_rp_values)(struct xe_guc_pc *pc);
+	void (*update_rpe_value)(struct xe_guc_pc *pc);
+};
+
+static void mtl_init_fused_rp_values(struct xe_guc_pc *pc);
+static void tgl_init_fused_rp_values(struct xe_guc_pc *pc);
+static void mtl_update_rpe_value(struct xe_guc_pc *pc);
+static void tgl_update_rpe_value(struct xe_guc_pc *pc);
+
+static const struct xe_guc_pc_platform_funcs mtl_funcs = {
+	.init_fused_rp_values = mtl_init_fused_rp_values,
+	.update_rpe_value = mtl_update_rpe_value,
+};
+
+static const struct xe_guc_pc_platform_funcs tgl_funcs = {
+	.init_fused_rp_values = tgl_init_fused_rp_values,
+	.update_rpe_value = tgl_update_rpe_value,
+};
+
 #define slpc_shared_data_read(pc_, field_) \
 	xe_map_rd_field(pc_to_xe(pc_), pc_to_maps(pc_), 0, \
 			struct slpc_shared_data, field_)
@@ -348,10 +368,8 @@ static void pc_update_rp_values(struct xe_guc_pc *pc)
 	struct xe_gt *gt = pc_to_gt(pc);
 	struct xe_device *xe = gt_to_xe(gt);
 
-	if (xe->info.platform == XE_METEORLAKE)
-		mtl_update_rpe_value(pc);
-	else
-		tgl_update_rpe_value(pc);
+	if (xe->guc_pc_funcs->update_rpe_value)
+		xe->guc_pc_funcs->update_rpe_value(pc);
 
 	/*
 	 * RPe is decided at runtime by PCODE. In the rare case where that's
@@ -676,11 +694,10 @@ static void pc_init_fused_rp_values(struct xe_guc_pc *pc)
 	struct xe_gt *gt = pc_to_gt(pc);
 	struct xe_device *xe = gt_to_xe(gt);
 
-	if (xe->info.platform == XE_METEORLAKE)
-		mtl_init_fused_rp_values(pc);
-	else
-		tgl_init_fused_rp_values(pc);
+	if (xe->guc_pc_funcs->init_fused_rp_values)
+		xe->guc_pc_funcs->init_fused_rp_values(pc);
 }
+
 static int pc_adjust_freq_bounds(struct xe_guc_pc *pc)
 {
 	int ret;
@@ -893,6 +910,24 @@ int xe_guc_pc_init(struct xe_guc_pc *pc)
 	u32 size = PAGE_ALIGN(sizeof(struct slpc_shared_data));
 	int err;
 
+	switch (xe->info.platform) {
+	case XE_METEORLAKE:
+		xe->guc_pc_funcs = &mtl_funcs;
+		break;
+	case XE_PVC:
+	case XE_ROCKETLAKE:
+	case XE_DG1:
+	case XE_DG2:
+	case XE_ALDERLAKE_S:
+	case XE_ALDERLAKE_P:
+	case XE_TIGERLAKE:
+		xe->guc_pc_funcs = &tgl_funcs;
+		break;
+	default:
+		DRM_ERROR("Unsupported platform\n");
+		break;
+	}
+
 	mutex_init(&pc->freq_lock);
 
 	bo = xe_bo_create_pin_map(xe, gt, NULL, size,
-- 
2.25.1



More information about the Intel-xe mailing list