[Intel-xe] [RFC PATCH 3/4] drm/xe: Add function pointers for platform specific code
Francois Dugast
francois.dugast at intel.com
Fri Mar 3 14:50:14 UTC 2023
A new structure xe_platform_funcs holds pointers to platform
specific functions in separate files which contain the actual
implementation. It is initialized at probe time with the structure
that matches the platform.
Signed-off-by: Francois Dugast <francois.dugast at intel.com>
---
drivers/gpu/drm/xe/xe_device.c | 17 +++++++++++++++++
drivers/gpu/drm/xe/xe_device_types.h | 2 ++
drivers/gpu/drm/xe/xe_gt.c | 20 ++++++--------------
drivers/gpu/drm/xe/xe_platform.h | 19 ++++++++++++++++---
drivers/gpu/drm/xe/xe_platform_mtl.c | 13 ++++++++++++-
drivers/gpu/drm/xe/xe_platform_pvc.c | 13 ++++++++++++-
drivers/gpu/drm/xe/xe_platform_tgl.c | 13 ++++++++++++-
7 files changed, 77 insertions(+), 20 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
index 45e3c740fda2..f1f7a50d92c7 100644
--- a/drivers/gpu/drm/xe/xe_device.c
+++ b/drivers/gpu/drm/xe/xe_device.c
@@ -24,6 +24,7 @@
#include "xe_mmio.h"
#include "xe_module.h"
#include "xe_pcode.h"
+#include "xe_platform.h"
#include "xe_pm.h"
#include "xe_query.h"
#include "xe_ttm_stolen_mgr.h"
@@ -261,6 +262,22 @@ int xe_device_probe(struct xe_device *xe)
int err;
u8 id;
+ switch (xe->info.platform) {
+ case XE_TIGERLAKE:
+ tgl_set_funcs(xe);
+ break;
+ case XE_PVC:
+ pvc_set_funcs(xe);
+ break;
+ case XE_METEORLAKE:
+ mtl_set_funcs(xe);
+ break;
+ default:
+ DRM_ERROR("Unsupported platform\n");
+ unsupported_platform_set_funcs(xe);
+ break;
+ }
+
xe->info.mem_region_mask = 1;
err = xe_display_init_nommio(xe);
if (err)
diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h
index 9743987fc883..151c6e574cb0 100644
--- a/drivers/gpu/drm/xe/xe_device_types.h
+++ b/drivers/gpu/drm/xe/xe_device_types.h
@@ -308,6 +308,8 @@ struct xe_device {
const char *vbt_firmware;
u32 lvds_channel_mode;
} params;
+
+ const struct xe_platform_funcs *platform_funcs;
};
/**
diff --git a/drivers/gpu/drm/xe/xe_gt.c b/drivers/gpu/drm/xe/xe_gt.c
index 0eceb5789d15..7a777dcc41f9 100644
--- a/drivers/gpu/drm/xe/xe_gt.c
+++ b/drivers/gpu/drm/xe/xe_gt.c
@@ -94,18 +94,6 @@ int xe_gt_alloc(struct xe_device *xe, struct xe_gt *gt)
return 0;
}
-static void setup_private_ppat(struct xe_gt *gt)
-{
- struct xe_device *xe = gt_to_xe(gt);
-
- if (xe->info.platform == XE_METEORLAKE)
- mtl_setup_private_ppat(gt);
- else if (xe->info.platform == XE_PVC)
- pvc_setup_private_ppat(gt);
- else
- tgl_setup_private_ppat(gt);
-}
-
static int gt_ttm_mgr_init(struct xe_gt *gt)
{
struct xe_device *xe = gt_to_xe(gt);
@@ -378,13 +366,15 @@ int xe_gt_init_noalloc(struct xe_gt *gt)
static int gt_fw_domain_init(struct xe_gt *gt)
{
int err, i;
+ struct xe_device *xe = gt_to_xe(gt);
xe_device_mem_access_get(gt_to_xe(gt));
err = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
if (err)
goto err_hw_fence_irq;
- setup_private_ppat(gt);
+ if (xe->platform_funcs->setup_private_ppat)
+ xe->platform_funcs->setup_private_ppat(gt);
if (!xe_gt_is_media_type(gt)) {
err = xe_ggtt_init(gt, gt->mem.ggtt);
@@ -567,8 +557,10 @@ static int do_gt_restart(struct xe_gt *gt)
struct xe_hw_engine *hwe;
enum xe_hw_engine_id id;
int err;
+ struct xe_device *xe = gt_to_xe(gt);
- setup_private_ppat(gt);
+ if (xe->platform_funcs->setup_private_ppat)
+ xe->platform_funcs->setup_private_ppat(gt);
xe_gt_mcr_set_implicit_defaults(gt);
xe_reg_sr_apply_mmio(>->reg_sr, gt);
diff --git a/drivers/gpu/drm/xe/xe_platform.h b/drivers/gpu/drm/xe/xe_platform.h
index d00377e807db..f2bf48fac3f4 100644
--- a/drivers/gpu/drm/xe/xe_platform.h
+++ b/drivers/gpu/drm/xe/xe_platform.h
@@ -6,8 +6,21 @@
#ifndef _XE_PLATFORM_H_
#define _XE_PLATFORM_H_
-void tgl_setup_private_ppat(struct xe_gt *gt);
-void pvc_setup_private_ppat(struct xe_gt *gt);
-void mtl_setup_private_ppat(struct xe_gt *gt);
+#include "xe_device_types.h"
+
+struct xe_platform_funcs {
+ void (*setup_private_ppat)(struct xe_gt *gt);
+};
+
+static const struct xe_platform_funcs empty_funcs;
+
+static inline void unsupported_platform_set_funcs(struct xe_device *xe)
+{
+ xe->platform_funcs = &empty_funcs;
+}
+
+void mtl_set_funcs(struct xe_device *xe);
+void pvc_set_funcs(struct xe_device *xe);
+void tgl_set_funcs(struct xe_device *xe);
#endif /* _XE_PLATFORM_H_ */
diff --git a/drivers/gpu/drm/xe/xe_platform_mtl.c b/drivers/gpu/drm/xe/xe_platform_mtl.c
index acc244a6a257..f1990bf69ca5 100644
--- a/drivers/gpu/drm/xe/xe_platform_mtl.c
+++ b/drivers/gpu/drm/xe/xe_platform_mtl.c
@@ -4,10 +4,12 @@
*/
#include "regs/xe_gt_regs.h"
+#include "xe_gt.h"
#include "xe_gt_ppat.h"
#include "xe_mmio.h"
+#include "xe_platform.h"
-void mtl_setup_private_ppat(struct xe_gt *gt)
+static void mtl_setup_private_ppat(struct xe_gt *gt)
{
xe_mmio_write32(gt, GEN12_PAT_INDEX(0).reg, MTL_PPAT_0_WB);
xe_mmio_write32(gt, GEN12_PAT_INDEX(1).reg,
@@ -19,3 +21,12 @@ void mtl_setup_private_ppat(struct xe_gt *gt)
xe_mmio_write32(gt, GEN12_PAT_INDEX(4).reg,
MTL_PPAT_0_WB | MTL_3_COH_2W);
}
+
+static const struct xe_platform_funcs mtl_funcs = {
+ .setup_private_ppat = mtl_setup_private_ppat,
+};
+
+void mtl_set_funcs(struct xe_device *xe)
+{
+ xe->platform_funcs = &mtl_funcs;
+}
diff --git a/drivers/gpu/drm/xe/xe_platform_pvc.c b/drivers/gpu/drm/xe/xe_platform_pvc.c
index fcee1426f395..32167fbbabb1 100644
--- a/drivers/gpu/drm/xe/xe_platform_pvc.c
+++ b/drivers/gpu/drm/xe/xe_platform_pvc.c
@@ -4,10 +4,12 @@
*/
#include "regs/xe_gt_regs.h"
+#include "xe_gt.h"
#include "xe_gt_ppat.h"
#include "xe_mmio.h"
+#include "xe_platform.h"
-void pvc_setup_private_ppat(struct xe_gt *gt)
+static void pvc_setup_private_ppat(struct xe_gt *gt)
{
xe_mmio_write32(gt, GEN12_PAT_INDEX(0).reg, GEN8_PPAT_UC);
xe_mmio_write32(gt, GEN12_PAT_INDEX(1).reg, GEN8_PPAT_WC);
@@ -22,3 +24,12 @@ void pvc_setup_private_ppat(struct xe_gt *gt)
xe_mmio_write32(gt, GEN12_PAT_INDEX(7).reg,
GEN12_PPAT_CLOS(2) | GEN8_PPAT_WB);
}
+
+static const struct xe_platform_funcs pvc_funcs = {
+ .setup_private_ppat = pvc_setup_private_ppat,
+};
+
+void pvc_set_funcs(struct xe_device *xe)
+{
+ xe->platform_funcs = &pvc_funcs;
+}
diff --git a/drivers/gpu/drm/xe/xe_platform_tgl.c b/drivers/gpu/drm/xe/xe_platform_tgl.c
index 7b909a1a90f4..616c20b97844 100644
--- a/drivers/gpu/drm/xe/xe_platform_tgl.c
+++ b/drivers/gpu/drm/xe/xe_platform_tgl.c
@@ -4,10 +4,12 @@
*/
#include "regs/xe_gt_regs.h"
+#include "xe_gt.h"
#include "xe_gt_ppat.h"
#include "xe_mmio.h"
+#include "xe_platform.h"
-void tgl_setup_private_ppat(struct xe_gt *gt)
+static void tgl_setup_private_ppat(struct xe_gt *gt)
{
/* TGL doesn't support LLC or AGE settings */
xe_mmio_write32(gt, GEN12_PAT_INDEX(0).reg, GEN8_PPAT_WB);
@@ -19,3 +21,12 @@ void tgl_setup_private_ppat(struct xe_gt *gt)
xe_mmio_write32(gt, GEN12_PAT_INDEX(6).reg, GEN8_PPAT_WB);
xe_mmio_write32(gt, GEN12_PAT_INDEX(7).reg, GEN8_PPAT_WB);
}
+
+static const struct xe_platform_funcs tgl_funcs = {
+ .setup_private_ppat = tgl_setup_private_ppat,
+};
+
+void tgl_set_funcs(struct xe_device *xe)
+{
+ xe->platform_funcs = &tgl_funcs;
+}
--
2.25.1
More information about the Intel-xe
mailing list