2 * SPDX-License-Identifier: MIT
4 * Copyright © 2019 Intel Corporation
8 #include "i915_gem_object.h"
12 struct i915_sw_fence chain
;
15 static int __i915_sw_fence_call
16 stub_notify(struct i915_sw_fence
*fence
, enum i915_sw_fence_notify state
)
18 struct stub_fence
*stub
= container_of(fence
, typeof(*stub
), chain
);
22 dma_fence_signal(&stub
->dma
);
26 dma_fence_put(&stub
->dma
);
33 static const char *stub_driver_name(struct dma_fence
*fence
)
38 static const char *stub_timeline_name(struct dma_fence
*fence
)
43 static void stub_release(struct dma_fence
*fence
)
45 struct stub_fence
*stub
= container_of(fence
, typeof(*stub
), dma
);
47 i915_sw_fence_fini(&stub
->chain
);
49 BUILD_BUG_ON(offsetof(typeof(*stub
), dma
));
50 dma_fence_free(&stub
->dma
);
53 static const struct dma_fence_ops stub_fence_ops
= {
54 .get_driver_name
= stub_driver_name
,
55 .get_timeline_name
= stub_timeline_name
,
56 .release
= stub_release
,
60 i915_gem_object_lock_fence(struct drm_i915_gem_object
*obj
)
62 struct stub_fence
*stub
;
64 assert_object_held(obj
);
66 stub
= kmalloc(sizeof(*stub
), GFP_KERNEL
);
70 i915_sw_fence_init(&stub
->chain
, stub_notify
);
71 dma_fence_init(&stub
->dma
, &stub_fence_ops
, &stub
->chain
.wait
.lock
,
74 if (i915_sw_fence_await_reservation(&stub
->chain
,
75 obj
->base
.resv
, NULL
, true,
76 i915_fence_timeout(to_i915(obj
->base
.dev
)),
80 dma_resv_add_excl_fence(obj
->base
.resv
, &stub
->dma
);
85 stub_release(&stub
->dma
);
89 void i915_gem_object_unlock_fence(struct drm_i915_gem_object
*obj
,
90 struct dma_fence
*fence
)
92 struct stub_fence
*stub
= container_of(fence
, typeof(*stub
), dma
);
94 i915_sw_fence_commit(&stub
->chain
);