Merge tag 'io_uring-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / gpu / drm / i915 / gem / i915_gem_fence.c
blob8ab842c80f995a62bccf903d93403dd5ae2e957f
1 /*
2 * SPDX-License-Identifier: MIT
4 * Copyright © 2019 Intel Corporation
5 */
7 #include "i915_drv.h"
8 #include "i915_gem_object.h"
10 struct stub_fence {
11 struct dma_fence dma;
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);
20 switch (state) {
21 case FENCE_COMPLETE:
22 dma_fence_signal(&stub->dma);
23 break;
25 case FENCE_FREE:
26 dma_fence_put(&stub->dma);
27 break;
30 return NOTIFY_DONE;
33 static const char *stub_driver_name(struct dma_fence *fence)
35 return DRIVER_NAME;
38 static const char *stub_timeline_name(struct dma_fence *fence)
40 return "object";
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,
59 struct dma_fence *
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);
67 if (!stub)
68 return NULL;
70 i915_sw_fence_init(&stub->chain, stub_notify);
71 dma_fence_init(&stub->dma, &stub_fence_ops, &stub->chain.wait.lock,
72 0, 0);
74 if (i915_sw_fence_await_reservation(&stub->chain,
75 obj->base.resv, NULL, true,
76 i915_fence_timeout(to_i915(obj->base.dev)),
77 I915_FENCE_GFP) < 0)
78 goto err;
80 dma_resv_add_excl_fence(obj->base.resv, &stub->dma);
82 return &stub->dma;
84 err:
85 stub_release(&stub->dma);
86 return NULL;
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);