Commit 9876394f authored by Jani Nikula's avatar Jani Nikula
Browse files

drm/{i915,xe}: move framebuffer bo to parent interface



Add .framebuffer_init, .framebuffer_fini and .framebuffer_lookup to the
bo parent interface. While they're about framebuffers, they're
specifically about framebuffer objects, so the bo interface is a good
enough fit, and there's no need to add another interface struct.

Reviewed-by: default avatarSuraj Kandpal <suraj.kandpal@intel.com>
Link: https://patch.msgid.link/848d32a44bf844cba3d66e44ba9f20bea4a8352d.1773238670.git.jani.nikula@intel.com


Signed-off-by: default avatarJani Nikula <jani.nikula@intel.com>
parent a65c06a9
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -278,7 +278,6 @@ i915-y += \
	display/intel_drrs.o \
	display/intel_dsb.o \
	display/intel_fb.o \
	display/intel_fb_bo.o \
	display/intel_fb_pin.o \
	display/intel_fbc.o \
	display/intel_fdi.o \
+21 −0
Original line number Diff line number Diff line
@@ -64,3 +64,24 @@ void intel_bo_describe(struct seq_file *m, struct drm_gem_object *obj)
	if (display->parent->bo->describe)
		display->parent->bo->describe(m, obj);
}

int intel_bo_framebuffer_init(struct drm_gem_object *obj, struct drm_mode_fb_cmd2 *mode_cmd)
{
	struct intel_display *display = to_intel_display(obj->dev);

	return display->parent->bo->framebuffer_init(obj, mode_cmd);
}

void intel_bo_framebuffer_fini(struct drm_gem_object *obj)
{
	struct intel_display *display = to_intel_display(obj->dev);

	display->parent->bo->framebuffer_fini(obj);
}

struct drm_gem_object *intel_bo_framebuffer_lookup(struct intel_display *display,
						   struct drm_file *filp,
						   const struct drm_mode_fb_cmd2 *user_mode_cmd)
{
	return display->parent->bo->framebuffer_lookup(display->drm, filp, user_mode_cmd);
}
+9 −0
Original line number Diff line number Diff line
@@ -6,8 +6,11 @@

#include <linux/types.h>

struct drm_file;
struct drm_gem_object;
struct drm_mode_fb_cmd2;
struct drm_scanout_buffer;
struct intel_display;
struct intel_framebuffer;
struct seq_file;
struct vm_area_struct;
@@ -22,4 +25,10 @@ int intel_bo_read_from_page(struct drm_gem_object *obj, u64 offset, void *dst, i

void intel_bo_describe(struct seq_file *m, struct drm_gem_object *obj);

void intel_bo_framebuffer_fini(struct drm_gem_object *obj);
int intel_bo_framebuffer_init(struct drm_gem_object *obj, struct drm_mode_fb_cmd2 *mode_cmd);
struct drm_gem_object *intel_bo_framebuffer_lookup(struct intel_display *display,
						   struct drm_file *filp,
						   const struct drm_mode_fb_cmd2 *user_mode_cmd);

#endif /* __INTEL_BO__ */
+6 −6
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
#include "intel_display_types.h"
#include "intel_display_utils.h"
#include "intel_fb.h"
#include "intel_fb_bo.h"
#include "intel_frontbuffer.h"
#include "intel_parent.h"
#include "intel_plane.h"
@@ -2111,7 +2110,7 @@ static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
	if (intel_fb_uses_dpt(fb))
		intel_parent_dpt_destroy(display, intel_fb->dpt);

	intel_fb_bo_framebuffer_fini(intel_fb_bo(fb));
	intel_bo_framebuffer_fini(intel_fb_bo(fb));

	intel_parent_frontbuffer_put(display, intel_fb->frontbuffer);

@@ -2222,7 +2221,7 @@ int intel_framebuffer_init(struct intel_framebuffer *intel_fb,

	/*
	 * intel_parent_frontbuffer_get() must be done before
	 * intel_fb_bo_framebuffer_init() to avoid set_tiling vs. addfb race.
	 * intel_bo_framebuffer_init() to avoid set_tiling vs. addfb race.
	 */
	intel_fb->frontbuffer = intel_parent_frontbuffer_get(display, obj);
	if (!intel_fb->frontbuffer) {
@@ -2230,7 +2229,7 @@ int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
		goto err_free_panic;
	}

	ret = intel_fb_bo_framebuffer_init(obj, mode_cmd);
	ret = intel_bo_framebuffer_init(obj, mode_cmd);
	if (ret)
		goto err_frontbuffer_put;

@@ -2333,7 +2332,7 @@ int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
	if (intel_fb_uses_dpt(fb))
		intel_parent_dpt_destroy(display, intel_fb->dpt);
err_bo_framebuffer_fini:
	intel_fb_bo_framebuffer_fini(obj);
	intel_bo_framebuffer_fini(obj);
err_frontbuffer_put:
	intel_parent_frontbuffer_put(display, intel_fb->frontbuffer);
err_free_panic:
@@ -2348,11 +2347,12 @@ intel_user_framebuffer_create(struct drm_device *dev,
			      const struct drm_format_info *info,
			      const struct drm_mode_fb_cmd2 *user_mode_cmd)
{
	struct intel_display *display = to_intel_display(dev);
	struct drm_framebuffer *fb;
	struct drm_gem_object *obj;
	struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;

	obj = intel_fb_bo_lookup_valid_bo(dev, filp, &mode_cmd);
	obj = intel_bo_framebuffer_lookup(display, filp, &mode_cmd);
	if (IS_ERR(obj))
		return ERR_CAST(obj);

+0 −99
Original line number Diff line number Diff line
/* SPDX-License-Identifier: MIT */
/*
 * Copyright © 2021 Intel Corporation
 */

#include <drm/drm_framebuffer.h>
#include <drm/drm_print.h>

#include "gem/i915_gem_object.h"

#include "i915_drv.h"
#include "intel_fb.h"
#include "intel_fb_bo.h"

void intel_fb_bo_framebuffer_fini(struct drm_gem_object *obj)
{
	/* Nothing to do for i915 */
}

int intel_fb_bo_framebuffer_init(struct drm_gem_object *_obj,
				 struct drm_mode_fb_cmd2 *mode_cmd)
{
	struct drm_i915_gem_object *obj = to_intel_bo(_obj);
	struct drm_i915_private *i915 = to_i915(obj->base.dev);
	unsigned int tiling, stride;

	i915_gem_object_lock(obj, NULL);
	tiling = i915_gem_object_get_tiling(obj);
	stride = i915_gem_object_get_stride(obj);
	i915_gem_object_unlock(obj);

	if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
		/*
		 * If there's a fence, enforce that
		 * the fb modifier and tiling mode match.
		 */
		if (tiling != I915_TILING_NONE &&
		    tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
			drm_dbg_kms(&i915->drm,
				    "tiling_mode doesn't match fb modifier\n");
			return -EINVAL;
		}
	} else {
		if (tiling == I915_TILING_X) {
			mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
		} else if (tiling == I915_TILING_Y) {
			drm_dbg_kms(&i915->drm,
				    "No Y tiling for legacy addfb\n");
			return -EINVAL;
		}
	}

	/*
	 * gen2/3 display engine uses the fence if present,
	 * so the tiling mode must match the fb modifier exactly.
	 */
	if (GRAPHICS_VER(i915) < 4 &&
	    tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
		drm_dbg_kms(&i915->drm,
			    "tiling_mode must match fb modifier exactly on gen2/3\n");
		return -EINVAL;
	}

	/*
	 * If there's a fence, enforce that
	 * the fb pitch and fence stride match.
	 */
	if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
		drm_dbg_kms(&i915->drm,
			    "pitch (%d) must match tiling stride (%d)\n",
			    mode_cmd->pitches[0], stride);
		return -EINVAL;
	}

	return 0;
}

struct drm_gem_object *
intel_fb_bo_lookup_valid_bo(struct drm_device *drm,
			    struct drm_file *filp,
			    const struct drm_mode_fb_cmd2 *mode_cmd)
{
	struct drm_i915_private *i915 = to_i915(drm);
	struct drm_i915_gem_object *obj;

	obj = i915_gem_object_lookup(filp, mode_cmd->handles[0]);
	if (!obj)
		return ERR_PTR(-ENOENT);

	/* object is backed with LMEM for discrete */
	if (HAS_LMEM(i915) && !i915_gem_object_can_migrate(obj, INTEL_REGION_LMEM_0)) {
		/* object is "remote", not in local memory */
		i915_gem_object_put(obj);
		drm_dbg_kms(&i915->drm, "framebuffer must reside in local memory\n");
		return ERR_PTR(-EREMOTE);
	}

	return intel_bo_to_drm_bo(obj);
}
Loading