| .. | .. |
|---|
| 21 | 21 | */ |
|---|
| 22 | 22 | |
|---|
| 23 | 23 | #include <linux/dma-buf.h> |
|---|
| 24 | | -#include <linux/reservation.h> |
|---|
| 24 | +#include <linux/dma-resv.h> |
|---|
| 25 | + |
|---|
| 26 | +#include <drm/drm_file.h> |
|---|
| 25 | 27 | |
|---|
| 26 | 28 | #include "vgem_drv.h" |
|---|
| 27 | 29 | |
|---|
| .. | .. |
|---|
| 43 | 45 | return "unbound"; |
|---|
| 44 | 46 | } |
|---|
| 45 | 47 | |
|---|
| 46 | | -static bool vgem_fence_signaled(struct dma_fence *fence) |
|---|
| 47 | | -{ |
|---|
| 48 | | - return false; |
|---|
| 49 | | -} |
|---|
| 50 | | - |
|---|
| 51 | | -static bool vgem_fence_enable_signaling(struct dma_fence *fence) |
|---|
| 52 | | -{ |
|---|
| 53 | | - return true; |
|---|
| 54 | | -} |
|---|
| 55 | | - |
|---|
| 56 | 48 | static void vgem_fence_release(struct dma_fence *base) |
|---|
| 57 | 49 | { |
|---|
| 58 | 50 | struct vgem_fence *fence = container_of(base, typeof(*fence), base); |
|---|
| .. | .. |
|---|
| 63 | 55 | |
|---|
| 64 | 56 | static void vgem_fence_value_str(struct dma_fence *fence, char *str, int size) |
|---|
| 65 | 57 | { |
|---|
| 66 | | - snprintf(str, size, "%u", fence->seqno); |
|---|
| 58 | + snprintf(str, size, "%llu", fence->seqno); |
|---|
| 67 | 59 | } |
|---|
| 68 | 60 | |
|---|
| 69 | 61 | static void vgem_fence_timeline_value_str(struct dma_fence *fence, char *str, |
|---|
| 70 | 62 | int size) |
|---|
| 71 | 63 | { |
|---|
| 72 | | - snprintf(str, size, "%u", |
|---|
| 64 | + snprintf(str, size, "%llu", |
|---|
| 73 | 65 | dma_fence_is_signaled(fence) ? fence->seqno : 0); |
|---|
| 74 | 66 | } |
|---|
| 75 | 67 | |
|---|
| 76 | 68 | static const struct dma_fence_ops vgem_fence_ops = { |
|---|
| 77 | 69 | .get_driver_name = vgem_fence_get_driver_name, |
|---|
| 78 | 70 | .get_timeline_name = vgem_fence_get_timeline_name, |
|---|
| 79 | | - .enable_signaling = vgem_fence_enable_signaling, |
|---|
| 80 | | - .signaled = vgem_fence_signaled, |
|---|
| 81 | | - .wait = dma_fence_default_wait, |
|---|
| 82 | 71 | .release = vgem_fence_release, |
|---|
| 83 | 72 | |
|---|
| 84 | 73 | .fence_value_str = vgem_fence_value_str, |
|---|
| .. | .. |
|---|
| 113 | 102 | return &fence->base; |
|---|
| 114 | 103 | } |
|---|
| 115 | 104 | |
|---|
| 116 | | -static int attach_dmabuf(struct drm_device *dev, |
|---|
| 117 | | - struct drm_gem_object *obj) |
|---|
| 118 | | -{ |
|---|
| 119 | | - struct dma_buf *dmabuf; |
|---|
| 120 | | - |
|---|
| 121 | | - if (obj->dma_buf) |
|---|
| 122 | | - return 0; |
|---|
| 123 | | - |
|---|
| 124 | | - dmabuf = dev->driver->gem_prime_export(dev, obj, 0); |
|---|
| 125 | | - if (IS_ERR(dmabuf)) |
|---|
| 126 | | - return PTR_ERR(dmabuf); |
|---|
| 127 | | - |
|---|
| 128 | | - obj->dma_buf = dmabuf; |
|---|
| 129 | | - return 0; |
|---|
| 130 | | -} |
|---|
| 131 | | - |
|---|
| 132 | 105 | /* |
|---|
| 133 | 106 | * vgem_fence_attach_ioctl (DRM_IOCTL_VGEM_FENCE_ATTACH): |
|---|
| 134 | 107 | * |
|---|
| .. | .. |
|---|
| 155 | 128 | { |
|---|
| 156 | 129 | struct drm_vgem_fence_attach *arg = data; |
|---|
| 157 | 130 | struct vgem_file *vfile = file->driver_priv; |
|---|
| 158 | | - struct reservation_object *resv; |
|---|
| 131 | + struct dma_resv *resv; |
|---|
| 159 | 132 | struct drm_gem_object *obj; |
|---|
| 160 | 133 | struct dma_fence *fence; |
|---|
| 161 | 134 | int ret; |
|---|
| .. | .. |
|---|
| 170 | 143 | if (!obj) |
|---|
| 171 | 144 | return -ENOENT; |
|---|
| 172 | 145 | |
|---|
| 173 | | - ret = attach_dmabuf(dev, obj); |
|---|
| 174 | | - if (ret) |
|---|
| 175 | | - goto err; |
|---|
| 176 | | - |
|---|
| 177 | 146 | fence = vgem_fence_create(vfile, arg->flags); |
|---|
| 178 | 147 | if (!fence) { |
|---|
| 179 | 148 | ret = -ENOMEM; |
|---|
| .. | .. |
|---|
| 181 | 150 | } |
|---|
| 182 | 151 | |
|---|
| 183 | 152 | /* Check for a conflicting fence */ |
|---|
| 184 | | - resv = obj->dma_buf->resv; |
|---|
| 185 | | - if (!reservation_object_test_signaled_rcu(resv, |
|---|
| 153 | + resv = obj->resv; |
|---|
| 154 | + if (!dma_resv_test_signaled_rcu(resv, |
|---|
| 186 | 155 | arg->flags & VGEM_FENCE_WRITE)) { |
|---|
| 187 | 156 | ret = -EBUSY; |
|---|
| 188 | 157 | goto err_fence; |
|---|
| .. | .. |
|---|
| 190 | 159 | |
|---|
| 191 | 160 | /* Expose the fence via the dma-buf */ |
|---|
| 192 | 161 | ret = 0; |
|---|
| 193 | | - reservation_object_lock(resv, NULL); |
|---|
| 162 | + dma_resv_lock(resv, NULL); |
|---|
| 194 | 163 | if (arg->flags & VGEM_FENCE_WRITE) |
|---|
| 195 | | - reservation_object_add_excl_fence(resv, fence); |
|---|
| 196 | | - else if ((ret = reservation_object_reserve_shared(resv)) == 0) |
|---|
| 197 | | - reservation_object_add_shared_fence(resv, fence); |
|---|
| 198 | | - reservation_object_unlock(resv); |
|---|
| 164 | + dma_resv_add_excl_fence(resv, fence); |
|---|
| 165 | + else if ((ret = dma_resv_reserve_shared(resv, 1)) == 0) |
|---|
| 166 | + dma_resv_add_shared_fence(resv, fence); |
|---|
| 167 | + dma_resv_unlock(resv); |
|---|
| 199 | 168 | |
|---|
| 200 | 169 | /* Record the fence in our idr for later signaling */ |
|---|
| 201 | 170 | if (ret == 0) { |
|---|
| .. | .. |
|---|
| 213 | 182 | dma_fence_put(fence); |
|---|
| 214 | 183 | } |
|---|
| 215 | 184 | err: |
|---|
| 216 | | - drm_gem_object_put_unlocked(obj); |
|---|
| 185 | + drm_gem_object_put(obj); |
|---|
| 217 | 186 | return ret; |
|---|
| 218 | 187 | } |
|---|
| 219 | 188 | |
|---|