Linux Audio

Check our new training course

Loading...
v6.13.7
 1/* SPDX-License-Identifier: MIT */
 2/*
 3 * Copyright © 2021 Intel Corporation
 4 */
 5
 6#include <drm/drm_modeset_helper.h>
 7#include <drm/ttm/ttm_bo.h>
 8
 
 9#include "intel_display_types.h"
10#include "intel_fb.h"
11#include "intel_fb_bo.h"
12#include "xe_bo.h"
13
14void intel_fb_bo_framebuffer_fini(struct drm_gem_object *obj)
15{
16	struct xe_bo *bo = gem_to_xe_bo(obj);
17
18	if (bo->flags & XE_BO_FLAG_PINNED) {
19		/* Unpin our kernel fb first */
20		xe_bo_lock(bo, false);
21		xe_bo_unpin(bo);
22		xe_bo_unlock(bo);
23	}
24	xe_bo_put(bo);
25}
26
27int intel_fb_bo_framebuffer_init(struct intel_framebuffer *intel_fb,
28				 struct drm_gem_object *obj,
29				 struct drm_mode_fb_cmd2 *mode_cmd)
30{
31	struct xe_bo *bo = gem_to_xe_bo(obj);
32	struct xe_device *xe = to_xe_device(bo->ttm.base.dev);
33	int ret;
34
35	/*
36	 * Some modifiers require physical alignment of 64KiB VRAM pages;
37	 * require that the BO in those cases is created correctly.
38	 */
39	if (XE_IOCTL_DBG(xe, intel_fb_needs_64k_phys(mode_cmd->modifier[0]) &&
40			     !(bo->flags & XE_BO_FLAG_NEEDS_64K)))
41		return -EINVAL;
42
43	xe_bo_get(bo);
44
45	ret = ttm_bo_reserve(&bo->ttm, true, false, NULL);
46	if (ret)
47		goto err;
48
49	if (!(bo->flags & XE_BO_FLAG_SCANOUT)) {
50		/*
51		 * XE_BO_FLAG_SCANOUT should ideally be set at creation, or is
52		 * automatically set when creating FB. We cannot change caching
53		 * mode when the boect is VM_BINDed, so we can only set
54		 * coherency with display when unbound.
55		 */
56		if (XE_IOCTL_DBG(xe, !list_empty(&bo->ttm.base.gpuva.list))) {
57			ttm_bo_unreserve(&bo->ttm);
58			ret = -EINVAL;
59			goto err;
60		}
61		bo->flags |= XE_BO_FLAG_SCANOUT;
62	}
63	ttm_bo_unreserve(&bo->ttm);
64	return 0;
65
66err:
67	xe_bo_put(bo);
68	return ret;
69}
70
71struct drm_gem_object *intel_fb_bo_lookup_valid_bo(struct drm_i915_private *i915,
72						   struct drm_file *filp,
73						   const struct drm_mode_fb_cmd2 *mode_cmd)
74{
75	struct xe_bo *bo;
76	struct drm_gem_object *gem = drm_gem_object_lookup(filp, mode_cmd->handles[0]);
77
78	if (!gem)
79		return ERR_PTR(-ENOENT);
80
81	bo = gem_to_xe_bo(gem);
82	/* Require vram placement or dma-buf import */
83	if (IS_DGFX(i915) &&
84	    !xe_bo_can_migrate(bo, XE_PL_VRAM0) &&
85	    bo->ttm.type != ttm_bo_type_sg) {
86		drm_gem_object_put(gem);
87		return ERR_PTR(-EREMOTE);
88	}
89
90	return gem;
91}
v6.9.4
 1/* SPDX-License-Identifier: MIT */
 2/*
 3 * Copyright © 2021 Intel Corporation
 4 */
 5
 6#include <drm/drm_modeset_helper.h>
 
 7
 8#include "i915_drv.h"
 9#include "intel_display_types.h"
 
10#include "intel_fb_bo.h"
 
11
12void intel_fb_bo_framebuffer_fini(struct xe_bo *bo)
13{
14	if (bo->flags & XE_BO_CREATE_PINNED_BIT) {
 
 
15		/* Unpin our kernel fb first */
16		xe_bo_lock(bo, false);
17		xe_bo_unpin(bo);
18		xe_bo_unlock(bo);
19	}
20	xe_bo_put(bo);
21}
22
23int intel_fb_bo_framebuffer_init(struct intel_framebuffer *intel_fb,
24				 struct xe_bo *bo,
25				 struct drm_mode_fb_cmd2 *mode_cmd)
26{
27	struct drm_i915_private *i915 = to_i915(bo->ttm.base.dev);
 
28	int ret;
29
 
 
 
 
 
 
 
 
30	xe_bo_get(bo);
31
32	ret = ttm_bo_reserve(&bo->ttm, true, false, NULL);
33	if (ret)
34		goto err;
35
36	if (!(bo->flags & XE_BO_SCANOUT_BIT)) {
37		/*
38		 * XE_BO_SCANOUT_BIT should ideally be set at creation, or is
39		 * automatically set when creating FB. We cannot change caching
40		 * mode when the boect is VM_BINDed, so we can only set
41		 * coherency with display when unbound.
42		 */
43		if (XE_IOCTL_DBG(i915, !list_empty(&bo->ttm.base.gpuva.list))) {
44			ttm_bo_unreserve(&bo->ttm);
45			ret = -EINVAL;
46			goto err;
47		}
48		bo->flags |= XE_BO_SCANOUT_BIT;
49	}
50	ttm_bo_unreserve(&bo->ttm);
51	return 0;
52
53err:
54	xe_bo_put(bo);
55	return ret;
56}
57
58struct xe_bo *intel_fb_bo_lookup_valid_bo(struct drm_i915_private *i915,
59					  struct drm_file *filp,
60					  const struct drm_mode_fb_cmd2 *mode_cmd)
61{
62	struct drm_i915_gem_object *bo;
63	struct drm_gem_object *gem = drm_gem_object_lookup(filp, mode_cmd->handles[0]);
64
65	if (!gem)
66		return ERR_PTR(-ENOENT);
67
68	bo = gem_to_xe_bo(gem);
69	/* Require vram placement or dma-buf import */
70	if (IS_DGFX(i915) &&
71	    !xe_bo_can_migrate(gem_to_xe_bo(gem), XE_PL_VRAM0) &&
72	    bo->ttm.type != ttm_bo_type_sg) {
73		drm_gem_object_put(gem);
74		return ERR_PTR(-EREMOTE);
75	}
76
77	return bo;
78}