Files
linux/drivers/gpu/drm/i915/display/intel_display_conversion.c
Jani Nikula 97825e1c6d 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>
2025-09-29 12:55:50 +03:00

22 lines
622 B
C

// SPDX-License-Identifier: MIT
/* Copyright © 2024 Intel Corporation */
#include <drm/intel/display_member.h>
#include "intel_display_conversion.h"
struct intel_display *__drm_to_display(struct drm_device *drm)
{
/*
* Note: This relies on both struct drm_i915_private and struct
* xe_device having the struct drm_device and struct intel_display *
* members at the same relative offsets, as defined by struct
* __intel_generic_device.
*
* See also INTEL_DISPLAY_MEMBER_STATIC_ASSERT().
*/
struct __intel_generic_device *d = container_of(drm, struct __intel_generic_device, drm);
return d->display;
}