[Intel-gfx] [RFC 1/3] drm/i915: rough ideas for further separating display code from the rest
Jani Nikula
jani.nikula at intel.com
Tue Sep 26 17:15:41 UTC 2023
Long term goal: Separate display code from struct drm_i915_private and
i915_drv.h, and everything in them.
First step, draft some ideas how we could use struct intel_display as
the main device structure for display, while struct drm_device remains
in struct drm_i915_private (or, in the case of xe, in struct xe_device).
To get at struct drm_device * given a struct intel_display *, simply
store a backpointer.
To get at struct intel_display * given a struct drm_device *, require
storing a struct intel_display * right after struct drm_device in
memory. It's slightly hackish, but devm_drm_dev_alloc() facilitates
defining the enclosing struct as we wish.
Signed-off-by: Jani Nikula <jani.nikula at intel.com>
---
.../gpu/drm/i915/display/intel_display_core.h | 16 ++++++++++++++++
.../gpu/drm/i915/display/intel_display_device.c | 13 +++++++++++++
drivers/gpu/drm/i915/i915_drv.h | 11 ++++++++++-
3 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/i915/display/intel_display_core.h b/drivers/gpu/drm/i915/display/intel_display_core.h
index 53e5c33e08c3..a5463a9b5f54 100644
--- a/drivers/gpu/drm/i915/display/intel_display_core.h
+++ b/drivers/gpu/drm/i915/display/intel_display_core.h
@@ -14,6 +14,7 @@
#include <linux/workqueue.h>
#include <drm/drm_connector.h>
+#include <drm/drm_device.h>
#include <drm/drm_modeset_lock.h>
#include "intel_cdclk.h"
@@ -267,6 +268,9 @@ struct intel_wm {
};
struct intel_display {
+ /* drm device backpointer */
+ struct drm_device *drm;
+
/* Display functions */
struct {
/* Top level crtc-ish functions */
@@ -521,4 +525,16 @@ struct intel_display {
struct intel_wm wm;
};
+/* FIXME: could be placed somewhere else to avoid drm/drm_device.h include */
+static inline struct intel_display *to_intel_display(const struct drm_device *drm)
+{
+ /*
+ * Assume there's a pointer to struct intel_display in memory right
+ * after struct drm_device.
+ */
+ struct intel_display **p = (struct intel_display **)(drm + 1);
+
+ return *p;
+}
+
#endif /* __INTEL_DISPLAY_CORE_H__ */
diff --git a/drivers/gpu/drm/i915/display/intel_display_device.c b/drivers/gpu/drm/i915/display/intel_display_device.c
index a6a18eae7ae8..b90da136ac65 100644
--- a/drivers/gpu/drm/i915/display/intel_display_device.c
+++ b/drivers/gpu/drm/i915/display/intel_display_device.c
@@ -921,6 +921,19 @@ void intel_display_device_probe(struct drm_i915_private *i915)
const struct intel_display_device_info *info;
u16 ver, rel, step;
+ /*
+ * These are here for now to do them as early as possible. i915 has just
+ * been allocated, drm isn't even initialized yet, but we have the
+ * pointer.
+ *
+ * Later on, the display probe would allocate struct intel_display
+ * itself, and return the pointer to the caller, for whom struct
+ * intel_display would be an opaque type, a cookie to be passed on to
+ * display functions.
+ */
+ i915->__intel_display_private = &i915->display;
+ i915->display.drm = &i915->drm;
+
if (HAS_GMD_ID(i915))
info = probe_gmdid_display(i915, &ver, &rel, &step);
else
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 511eba3bbdba..10770fb5f429 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -193,7 +193,16 @@ struct i915_selftest_stash {
};
struct drm_i915_private {
- struct drm_device drm;
+ struct {
+ struct drm_device drm;
+
+ /*
+ * Display private data. Do *not* access directly. Must be
+ * placed right after drm_device to facilitate getting to it
+ * given a drm device pointer.
+ */
+ struct intel_display *__intel_display_private;
+ } __packed;
struct intel_display display;
--
2.39.2
More information about the Intel-gfx
mailing list