Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/{i915,xe}: driver agnostic drm to display pointer chase

The display driver needs to get from the struct drm_device pointer to
the struct intel_display pointer. Currently, this depends on knowledge
of the struct drm_i915_private and struct xe_device definitions, but
we'd like to hide those definitions from display.

Require the struct drm_device and struct intel_display * members within
struct drm_i915_private and struct xe_device to be placed next to each
other, to be able to figure out the display pointer without knowledge of
the structures.

Use a generic dummy device structure to define the relative offsets of
the drm and display members, and add static assertions to ensure this
holds for both i915 and xe. Use the dummy structure to do the pointer
chase from struct drm_device * to struct intel_display *.

This requires moving the display member in struct xe_device after the
drm member.

Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Ville Syrjala <ville.syrjala@linux.intel.com>
Suggested-by: Simona Vetter <simona.vetter@ffwll.ch>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Link: https://lore.kernel.org/r/20250926111032.1188876-1-jani.nikula@intel.com
Signed-off-by: Jani Nikula <jani.nikula@intel.com>

+69 -9
+13 -7
drivers/gpu/drm/i915/display/intel_display_conversion.c
··· 1 1 // SPDX-License-Identifier: MIT 2 2 /* Copyright © 2024 Intel Corporation */ 3 3 4 - #include "i915_drv.h" 5 - #include "intel_display_conversion.h" 4 + #include <drm/intel/display_member.h> 6 5 7 - static struct intel_display *__i915_to_display(struct drm_i915_private *i915) 8 - { 9 - return i915->display; 10 - } 6 + #include "intel_display_conversion.h" 11 7 12 8 struct intel_display *__drm_to_display(struct drm_device *drm) 13 9 { 14 - return __i915_to_display(to_i915(drm)); 10 + /* 11 + * Note: This relies on both struct drm_i915_private and struct 12 + * xe_device having the struct drm_device and struct intel_display * 13 + * members at the same relative offsets, as defined by struct 14 + * __intel_generic_device. 15 + * 16 + * See also INTEL_DISPLAY_MEMBER_STATIC_ASSERT(). 17 + */ 18 + struct __intel_generic_device *d = container_of(drm, struct __intel_generic_device, drm); 19 + 20 + return d->display; 15 21 }
+4
drivers/gpu/drm/i915/i915_driver.c
··· 46 46 #include <drm/drm_ioctl.h> 47 47 #include <drm/drm_managed.h> 48 48 #include <drm/drm_probe_helper.h> 49 + #include <drm/intel/display_member.h> 49 50 50 51 #include "display/i9xx_display_sr.h" 51 52 #include "display/intel_bw.h" ··· 737 736 drm_info(&dev_priv->drm, 738 737 "DRM_I915_DEBUG_RUNTIME_PM enabled\n"); 739 738 } 739 + 740 + /* Ensure drm and display members are placed properly. */ 741 + INTEL_DISPLAY_MEMBER_STATIC_ASSERT(struct drm_i915_private, drm, display); 740 742 741 743 static struct drm_i915_private * 742 744 i915_driver_create(struct pci_dev *pdev, const struct pci_device_id *ent)
+1
drivers/gpu/drm/i915/i915_drv.h
··· 174 174 struct drm_i915_private { 175 175 struct drm_device drm; 176 176 177 + /* display device data, must be placed after drm device member */ 177 178 struct intel_display *display; 178 179 179 180 /* FIXME: Device release actions should all be moved to drmm_ */
+4
drivers/gpu/drm/xe/display/xe_display.c
··· 13 13 #include <drm/drm_drv.h> 14 14 #include <drm/drm_managed.h> 15 15 #include <drm/drm_probe_helper.h> 16 + #include <drm/intel/display_member.h> 16 17 #include <uapi/drm/xe_drm.h> 17 18 18 19 #include "soc/intel_dram.h" ··· 35 34 #include "intel_opregion.h" 36 35 #include "skl_watermark.h" 37 36 #include "xe_module.h" 37 + 38 + /* Ensure drm and display members are placed properly. */ 39 + INTEL_DISPLAY_MEMBER_STATIC_ASSERT(struct xe_device, drm, display); 38 40 39 41 /* Xe device functions */ 40 42
+5 -2
drivers/gpu/drm/xe/xe_device_types.h
··· 217 217 /** @drm: drm device */ 218 218 struct drm_device drm; 219 219 220 + #if IS_ENABLED(CONFIG_DRM_XE_DISPLAY) 221 + /** @display: display device data, must be placed after drm device member */ 222 + struct intel_display *display; 223 + #endif 224 + 220 225 /** @devcoredump: device coredump */ 221 226 struct xe_devcoredump devcoredump; 222 227 ··· 622 617 * drm_i915_private during build. After cleanup these should go away, 623 618 * migrating to the right sub-structs 624 619 */ 625 - struct intel_display *display; 626 - 627 620 const struct dram_info *dram_info; 628 621 629 622 /*
+42
include/drm/intel/display_member.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* Copyright © 2025 Intel Corporation */ 3 + 4 + #ifndef __DRM_INTEL_DISPLAY_H__ 5 + #define __DRM_INTEL_DISPLAY_H__ 6 + 7 + #include <linux/build_bug.h> 8 + #include <linux/stddef.h> 9 + #include <linux/stringify.h> 10 + 11 + #include <drm/drm_device.h> 12 + 13 + struct intel_display; 14 + 15 + /* 16 + * A dummy device struct to define the relative offsets of drm and display 17 + * members. With the members identically placed in struct drm_i915_private and 18 + * struct xe_device, this allows figuring out the struct intel_display pointer 19 + * without the definition of either driver specific structure. 20 + */ 21 + struct __intel_generic_device { 22 + struct drm_device drm; 23 + struct intel_display *display; 24 + }; 25 + 26 + /** 27 + * INTEL_DISPLAY_MEMBER_STATIC_ASSERT() - ensure correct placing of drm and display members 28 + * @type: The struct to check 29 + * @drm_member: Name of the struct drm_device member 30 + * @display_member: Name of the struct intel_display * member. 31 + * 32 + * Use this static assert macro to ensure the struct drm_i915_private and struct 33 + * xe_device struct drm_device and struct intel_display * members are at the 34 + * same relative offsets. 35 + */ 36 + #define INTEL_DISPLAY_MEMBER_STATIC_ASSERT(type, drm_member, display_member) \ 37 + static_assert( \ 38 + offsetof(struct __intel_generic_device, display) - offsetof(struct __intel_generic_device, drm) == \ 39 + offsetof(type, display_member) - offsetof(type, drm_member), \ 40 + __stringify(type) " " __stringify(drm_member) " and " __stringify(display_member) " members at invalid offsets") 41 + 42 + #endif