Loading...
1// SPDX-License-Identifier: GPL-2.0 OR MIT
2/* Copyright 2017-2019 Qiang Yu <yuq825@gmail.com> */
3
4#include <linux/mm.h>
5#include <linux/sync_file.h>
6#include <linux/pfn_t.h>
7
8#include <drm/drm_file.h>
9#include <drm/drm_syncobj.h>
10#include <drm/drm_utils.h>
11
12#include <drm/lima_drm.h>
13
14#include "lima_drv.h"
15#include "lima_gem.h"
16#include "lima_gem_prime.h"
17#include "lima_vm.h"
18#include "lima_object.h"
19
20int lima_gem_create_handle(struct drm_device *dev, struct drm_file *file,
21 u32 size, u32 flags, u32 *handle)
22{
23 int err;
24 struct lima_bo *bo;
25 struct lima_device *ldev = to_lima_dev(dev);
26
27 bo = lima_bo_create(ldev, size, flags, NULL);
28 if (IS_ERR(bo))
29 return PTR_ERR(bo);
30
31 err = drm_gem_handle_create(file, &bo->gem, handle);
32
33 /* drop reference from allocate - handle holds it now */
34 drm_gem_object_put_unlocked(&bo->gem);
35
36 return err;
37}
38
39void lima_gem_free_object(struct drm_gem_object *obj)
40{
41 struct lima_bo *bo = to_lima_bo(obj);
42
43 if (!list_empty(&bo->va))
44 dev_err(obj->dev->dev, "lima gem free bo still has va\n");
45
46 lima_bo_destroy(bo);
47}
48
49int lima_gem_object_open(struct drm_gem_object *obj, struct drm_file *file)
50{
51 struct lima_bo *bo = to_lima_bo(obj);
52 struct lima_drm_priv *priv = to_lima_drm_priv(file);
53 struct lima_vm *vm = priv->vm;
54
55 return lima_vm_bo_add(vm, bo, true);
56}
57
58void lima_gem_object_close(struct drm_gem_object *obj, struct drm_file *file)
59{
60 struct lima_bo *bo = to_lima_bo(obj);
61 struct lima_drm_priv *priv = to_lima_drm_priv(file);
62 struct lima_vm *vm = priv->vm;
63
64 lima_vm_bo_del(vm, bo);
65}
66
67int lima_gem_get_info(struct drm_file *file, u32 handle, u32 *va, u64 *offset)
68{
69 struct drm_gem_object *obj;
70 struct lima_bo *bo;
71 struct lima_drm_priv *priv = to_lima_drm_priv(file);
72 struct lima_vm *vm = priv->vm;
73 int err;
74
75 obj = drm_gem_object_lookup(file, handle);
76 if (!obj)
77 return -ENOENT;
78
79 bo = to_lima_bo(obj);
80
81 *va = lima_vm_get_va(vm, bo);
82
83 err = drm_gem_create_mmap_offset(obj);
84 if (!err)
85 *offset = drm_vma_node_offset_addr(&obj->vma_node);
86
87 drm_gem_object_put_unlocked(obj);
88 return err;
89}
90
91static vm_fault_t lima_gem_fault(struct vm_fault *vmf)
92{
93 struct vm_area_struct *vma = vmf->vma;
94 struct drm_gem_object *obj = vma->vm_private_data;
95 struct lima_bo *bo = to_lima_bo(obj);
96 pfn_t pfn;
97 pgoff_t pgoff;
98
99 /* We don't use vmf->pgoff since that has the fake offset: */
100 pgoff = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
101 pfn = __pfn_to_pfn_t(page_to_pfn(bo->pages[pgoff]), PFN_DEV);
102
103 return vmf_insert_mixed(vma, vmf->address, pfn);
104}
105
106const struct vm_operations_struct lima_gem_vm_ops = {
107 .fault = lima_gem_fault,
108 .open = drm_gem_vm_open,
109 .close = drm_gem_vm_close,
110};
111
112void lima_set_vma_flags(struct vm_area_struct *vma)
113{
114 pgprot_t prot = vm_get_page_prot(vma->vm_flags);
115
116 vma->vm_flags |= VM_MIXEDMAP;
117 vma->vm_flags &= ~VM_PFNMAP;
118 vma->vm_page_prot = pgprot_writecombine(prot);
119}
120
121int lima_gem_mmap(struct file *filp, struct vm_area_struct *vma)
122{
123 int ret;
124
125 ret = drm_gem_mmap(filp, vma);
126 if (ret)
127 return ret;
128
129 lima_set_vma_flags(vma);
130 return 0;
131}
132
133static int lima_gem_sync_bo(struct lima_sched_task *task, struct lima_bo *bo,
134 bool write, bool explicit)
135{
136 int err = 0;
137
138 if (!write) {
139 err = dma_resv_reserve_shared(bo->gem.resv, 1);
140 if (err)
141 return err;
142 }
143
144 /* explicit sync use user passed dep fence */
145 if (explicit)
146 return 0;
147
148 return drm_gem_fence_array_add_implicit(&task->deps, &bo->gem, write);
149}
150
151static int lima_gem_lock_bos(struct lima_bo **bos, u32 nr_bos,
152 struct ww_acquire_ctx *ctx)
153{
154 int i, ret = 0, contended, slow_locked = -1;
155
156 ww_acquire_init(ctx, &reservation_ww_class);
157
158retry:
159 for (i = 0; i < nr_bos; i++) {
160 if (i == slow_locked) {
161 slow_locked = -1;
162 continue;
163 }
164
165 ret = ww_mutex_lock_interruptible(&bos[i]->gem.resv->lock, ctx);
166 if (ret < 0) {
167 contended = i;
168 goto err;
169 }
170 }
171
172 ww_acquire_done(ctx);
173 return 0;
174
175err:
176 for (i--; i >= 0; i--)
177 ww_mutex_unlock(&bos[i]->gem.resv->lock);
178
179 if (slow_locked >= 0)
180 ww_mutex_unlock(&bos[slow_locked]->gem.resv->lock);
181
182 if (ret == -EDEADLK) {
183 /* we lost out in a seqno race, lock and retry.. */
184 ret = ww_mutex_lock_slow_interruptible(
185 &bos[contended]->gem.resv->lock, ctx);
186 if (!ret) {
187 slow_locked = contended;
188 goto retry;
189 }
190 }
191 ww_acquire_fini(ctx);
192
193 return ret;
194}
195
196static void lima_gem_unlock_bos(struct lima_bo **bos, u32 nr_bos,
197 struct ww_acquire_ctx *ctx)
198{
199 int i;
200
201 for (i = 0; i < nr_bos; i++)
202 ww_mutex_unlock(&bos[i]->gem.resv->lock);
203 ww_acquire_fini(ctx);
204}
205
206static int lima_gem_add_deps(struct drm_file *file, struct lima_submit *submit)
207{
208 int i, err;
209
210 for (i = 0; i < ARRAY_SIZE(submit->in_sync); i++) {
211 struct dma_fence *fence = NULL;
212
213 if (!submit->in_sync[i])
214 continue;
215
216 err = drm_syncobj_find_fence(file, submit->in_sync[i],
217 0, 0, &fence);
218 if (err)
219 return err;
220
221 err = drm_gem_fence_array_add(&submit->task->deps, fence);
222 if (err) {
223 dma_fence_put(fence);
224 return err;
225 }
226 }
227
228 return 0;
229}
230
231int lima_gem_submit(struct drm_file *file, struct lima_submit *submit)
232{
233 int i, err = 0;
234 struct ww_acquire_ctx ctx;
235 struct lima_drm_priv *priv = to_lima_drm_priv(file);
236 struct lima_vm *vm = priv->vm;
237 struct drm_syncobj *out_sync = NULL;
238 struct dma_fence *fence;
239 struct lima_bo **bos = submit->lbos;
240
241 if (submit->out_sync) {
242 out_sync = drm_syncobj_find(file, submit->out_sync);
243 if (!out_sync)
244 return -ENOENT;
245 }
246
247 for (i = 0; i < submit->nr_bos; i++) {
248 struct drm_gem_object *obj;
249 struct lima_bo *bo;
250
251 obj = drm_gem_object_lookup(file, submit->bos[i].handle);
252 if (!obj) {
253 err = -ENOENT;
254 goto err_out0;
255 }
256
257 bo = to_lima_bo(obj);
258
259 /* increase refcnt of gpu va map to prevent unmapped when executing,
260 * will be decreased when task done
261 */
262 err = lima_vm_bo_add(vm, bo, false);
263 if (err) {
264 drm_gem_object_put_unlocked(obj);
265 goto err_out0;
266 }
267
268 bos[i] = bo;
269 }
270
271 err = lima_gem_lock_bos(bos, submit->nr_bos, &ctx);
272 if (err)
273 goto err_out0;
274
275 err = lima_sched_task_init(
276 submit->task, submit->ctx->context + submit->pipe,
277 bos, submit->nr_bos, vm);
278 if (err)
279 goto err_out1;
280
281 err = lima_gem_add_deps(file, submit);
282 if (err)
283 goto err_out2;
284
285 for (i = 0; i < submit->nr_bos; i++) {
286 err = lima_gem_sync_bo(
287 submit->task, bos[i],
288 submit->bos[i].flags & LIMA_SUBMIT_BO_WRITE,
289 submit->flags & LIMA_SUBMIT_FLAG_EXPLICIT_FENCE);
290 if (err)
291 goto err_out2;
292 }
293
294 fence = lima_sched_context_queue_task(
295 submit->ctx->context + submit->pipe, submit->task);
296
297 for (i = 0; i < submit->nr_bos; i++) {
298 if (submit->bos[i].flags & LIMA_SUBMIT_BO_WRITE)
299 dma_resv_add_excl_fence(bos[i]->gem.resv, fence);
300 else
301 dma_resv_add_shared_fence(bos[i]->gem.resv, fence);
302 }
303
304 lima_gem_unlock_bos(bos, submit->nr_bos, &ctx);
305
306 for (i = 0; i < submit->nr_bos; i++)
307 drm_gem_object_put_unlocked(&bos[i]->gem);
308
309 if (out_sync) {
310 drm_syncobj_replace_fence(out_sync, fence);
311 drm_syncobj_put(out_sync);
312 }
313
314 dma_fence_put(fence);
315
316 return 0;
317
318err_out2:
319 lima_sched_task_fini(submit->task);
320err_out1:
321 lima_gem_unlock_bos(bos, submit->nr_bos, &ctx);
322err_out0:
323 for (i = 0; i < submit->nr_bos; i++) {
324 if (!bos[i])
325 break;
326 lima_vm_bo_del(vm, bos[i]);
327 drm_gem_object_put_unlocked(&bos[i]->gem);
328 }
329 if (out_sync)
330 drm_syncobj_put(out_sync);
331 return err;
332}
333
334int lima_gem_wait(struct drm_file *file, u32 handle, u32 op, s64 timeout_ns)
335{
336 bool write = op & LIMA_GEM_WAIT_WRITE;
337 long ret, timeout;
338
339 if (!op)
340 return 0;
341
342 timeout = drm_timeout_abs_to_jiffies(timeout_ns);
343
344 ret = drm_gem_dma_resv_wait(file, handle, write, timeout);
345 if (ret == -ETIME)
346 ret = timeout ? -ETIMEDOUT : -EBUSY;
347
348 return ret;
349}
1// SPDX-License-Identifier: GPL-2.0 OR MIT
2/* Copyright 2017-2019 Qiang Yu <yuq825@gmail.com> */
3
4#include <linux/mm.h>
5#include <linux/iosys-map.h>
6#include <linux/sync_file.h>
7#include <linux/pagemap.h>
8#include <linux/shmem_fs.h>
9#include <linux/dma-mapping.h>
10
11#include <drm/drm_file.h>
12#include <drm/drm_syncobj.h>
13#include <drm/drm_utils.h>
14
15#include <drm/lima_drm.h>
16
17#include "lima_drv.h"
18#include "lima_gem.h"
19#include "lima_vm.h"
20
21int lima_heap_alloc(struct lima_bo *bo, struct lima_vm *vm)
22{
23 struct page **pages;
24 struct address_space *mapping = bo->base.base.filp->f_mapping;
25 struct device *dev = bo->base.base.dev->dev;
26 size_t old_size = bo->heap_size;
27 size_t new_size = bo->heap_size ? bo->heap_size * 2 :
28 (lima_heap_init_nr_pages << PAGE_SHIFT);
29 struct sg_table sgt;
30 int i, ret;
31
32 if (bo->heap_size >= bo->base.base.size)
33 return -ENOSPC;
34
35 new_size = min(new_size, bo->base.base.size);
36
37 dma_resv_lock(bo->base.base.resv, NULL);
38
39 if (bo->base.pages) {
40 pages = bo->base.pages;
41 } else {
42 pages = kvmalloc_array(bo->base.base.size >> PAGE_SHIFT,
43 sizeof(*pages), GFP_KERNEL | __GFP_ZERO);
44 if (!pages) {
45 dma_resv_unlock(bo->base.base.resv);
46 return -ENOMEM;
47 }
48
49 bo->base.pages = pages;
50 bo->base.pages_use_count = 1;
51
52 mapping_set_unevictable(mapping);
53 }
54
55 for (i = old_size >> PAGE_SHIFT; i < new_size >> PAGE_SHIFT; i++) {
56 struct page *page = shmem_read_mapping_page(mapping, i);
57
58 if (IS_ERR(page)) {
59 dma_resv_unlock(bo->base.base.resv);
60 return PTR_ERR(page);
61 }
62 pages[i] = page;
63 }
64
65 dma_resv_unlock(bo->base.base.resv);
66
67 ret = sg_alloc_table_from_pages(&sgt, pages, i, 0,
68 new_size, GFP_KERNEL);
69 if (ret)
70 return ret;
71
72 if (bo->base.sgt) {
73 dma_unmap_sgtable(dev, bo->base.sgt, DMA_BIDIRECTIONAL, 0);
74 sg_free_table(bo->base.sgt);
75 } else {
76 bo->base.sgt = kmalloc(sizeof(*bo->base.sgt), GFP_KERNEL);
77 if (!bo->base.sgt) {
78 ret = -ENOMEM;
79 goto err_out0;
80 }
81 }
82
83 ret = dma_map_sgtable(dev, &sgt, DMA_BIDIRECTIONAL, 0);
84 if (ret)
85 goto err_out1;
86
87 *bo->base.sgt = sgt;
88
89 if (vm) {
90 ret = lima_vm_map_bo(vm, bo, old_size >> PAGE_SHIFT);
91 if (ret)
92 goto err_out2;
93 }
94
95 bo->heap_size = new_size;
96 return 0;
97
98err_out2:
99 dma_unmap_sgtable(dev, &sgt, DMA_BIDIRECTIONAL, 0);
100err_out1:
101 kfree(bo->base.sgt);
102 bo->base.sgt = NULL;
103err_out0:
104 sg_free_table(&sgt);
105 return ret;
106}
107
108int lima_gem_create_handle(struct drm_device *dev, struct drm_file *file,
109 u32 size, u32 flags, u32 *handle)
110{
111 int err;
112 gfp_t mask;
113 struct drm_gem_shmem_object *shmem;
114 struct drm_gem_object *obj;
115 struct lima_bo *bo;
116 bool is_heap = flags & LIMA_BO_FLAG_HEAP;
117
118 shmem = drm_gem_shmem_create(dev, size);
119 if (IS_ERR(shmem))
120 return PTR_ERR(shmem);
121
122 obj = &shmem->base;
123
124 /* Mali Utgard GPU can only support 32bit address space */
125 mask = mapping_gfp_mask(obj->filp->f_mapping);
126 mask &= ~__GFP_HIGHMEM;
127 mask |= __GFP_DMA32;
128 mapping_set_gfp_mask(obj->filp->f_mapping, mask);
129
130 if (is_heap) {
131 bo = to_lima_bo(obj);
132 err = lima_heap_alloc(bo, NULL);
133 if (err)
134 goto out;
135 } else {
136 struct sg_table *sgt = drm_gem_shmem_get_pages_sgt(shmem);
137
138 if (IS_ERR(sgt)) {
139 err = PTR_ERR(sgt);
140 goto out;
141 }
142 }
143
144 err = drm_gem_handle_create(file, obj, handle);
145
146out:
147 /* drop reference from allocate - handle holds it now */
148 drm_gem_object_put(obj);
149
150 return err;
151}
152
153static void lima_gem_free_object(struct drm_gem_object *obj)
154{
155 struct lima_bo *bo = to_lima_bo(obj);
156
157 if (!list_empty(&bo->va))
158 dev_err(obj->dev->dev, "lima gem free bo still has va\n");
159
160 drm_gem_shmem_free(&bo->base);
161}
162
163static int lima_gem_object_open(struct drm_gem_object *obj, struct drm_file *file)
164{
165 struct lima_bo *bo = to_lima_bo(obj);
166 struct lima_drm_priv *priv = to_lima_drm_priv(file);
167 struct lima_vm *vm = priv->vm;
168
169 return lima_vm_bo_add(vm, bo, true);
170}
171
172static void lima_gem_object_close(struct drm_gem_object *obj, struct drm_file *file)
173{
174 struct lima_bo *bo = to_lima_bo(obj);
175 struct lima_drm_priv *priv = to_lima_drm_priv(file);
176 struct lima_vm *vm = priv->vm;
177
178 lima_vm_bo_del(vm, bo);
179}
180
181static int lima_gem_pin(struct drm_gem_object *obj)
182{
183 struct lima_bo *bo = to_lima_bo(obj);
184
185 if (bo->heap_size)
186 return -EINVAL;
187
188 return drm_gem_shmem_pin(&bo->base);
189}
190
191static int lima_gem_vmap(struct drm_gem_object *obj, struct iosys_map *map)
192{
193 struct lima_bo *bo = to_lima_bo(obj);
194
195 if (bo->heap_size)
196 return -EINVAL;
197
198 return drm_gem_shmem_vmap(&bo->base, map);
199}
200
201static int lima_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
202{
203 struct lima_bo *bo = to_lima_bo(obj);
204
205 if (bo->heap_size)
206 return -EINVAL;
207
208 return drm_gem_shmem_mmap(&bo->base, vma);
209}
210
211static const struct drm_gem_object_funcs lima_gem_funcs = {
212 .free = lima_gem_free_object,
213 .open = lima_gem_object_open,
214 .close = lima_gem_object_close,
215 .print_info = drm_gem_shmem_object_print_info,
216 .pin = lima_gem_pin,
217 .unpin = drm_gem_shmem_object_unpin,
218 .get_sg_table = drm_gem_shmem_object_get_sg_table,
219 .vmap = lima_gem_vmap,
220 .vunmap = drm_gem_shmem_object_vunmap,
221 .mmap = lima_gem_mmap,
222 .vm_ops = &drm_gem_shmem_vm_ops,
223};
224
225struct drm_gem_object *lima_gem_create_object(struct drm_device *dev, size_t size)
226{
227 struct lima_bo *bo;
228
229 bo = kzalloc(sizeof(*bo), GFP_KERNEL);
230 if (!bo)
231 return ERR_PTR(-ENOMEM);
232
233 mutex_init(&bo->lock);
234 INIT_LIST_HEAD(&bo->va);
235 bo->base.map_wc = true;
236 bo->base.base.funcs = &lima_gem_funcs;
237
238 return &bo->base.base;
239}
240
241int lima_gem_get_info(struct drm_file *file, u32 handle, u32 *va, u64 *offset)
242{
243 struct drm_gem_object *obj;
244 struct lima_bo *bo;
245 struct lima_drm_priv *priv = to_lima_drm_priv(file);
246 struct lima_vm *vm = priv->vm;
247
248 obj = drm_gem_object_lookup(file, handle);
249 if (!obj)
250 return -ENOENT;
251
252 bo = to_lima_bo(obj);
253
254 *va = lima_vm_get_va(vm, bo);
255
256 *offset = drm_vma_node_offset_addr(&obj->vma_node);
257
258 drm_gem_object_put(obj);
259 return 0;
260}
261
262static int lima_gem_sync_bo(struct lima_sched_task *task, struct lima_bo *bo,
263 bool write, bool explicit)
264{
265 int err;
266
267 err = dma_resv_reserve_fences(lima_bo_resv(bo), 1);
268 if (err)
269 return err;
270
271 /* explicit sync use user passed dep fence */
272 if (explicit)
273 return 0;
274
275 return drm_sched_job_add_implicit_dependencies(&task->base,
276 &bo->base.base,
277 write);
278}
279
280static int lima_gem_add_deps(struct drm_file *file, struct lima_submit *submit)
281{
282 int i, err;
283
284 for (i = 0; i < ARRAY_SIZE(submit->in_sync); i++) {
285 if (!submit->in_sync[i])
286 continue;
287
288 err = drm_sched_job_add_syncobj_dependency(&submit->task->base, file,
289 submit->in_sync[i], 0);
290 if (err)
291 return err;
292 }
293
294 return 0;
295}
296
297int lima_gem_submit(struct drm_file *file, struct lima_submit *submit)
298{
299 int i, err = 0;
300 struct ww_acquire_ctx ctx;
301 struct lima_drm_priv *priv = to_lima_drm_priv(file);
302 struct lima_vm *vm = priv->vm;
303 struct drm_syncobj *out_sync = NULL;
304 struct dma_fence *fence;
305 struct lima_bo **bos = submit->lbos;
306
307 if (submit->out_sync) {
308 out_sync = drm_syncobj_find(file, submit->out_sync);
309 if (!out_sync)
310 return -ENOENT;
311 }
312
313 for (i = 0; i < submit->nr_bos; i++) {
314 struct drm_gem_object *obj;
315 struct lima_bo *bo;
316
317 obj = drm_gem_object_lookup(file, submit->bos[i].handle);
318 if (!obj) {
319 err = -ENOENT;
320 goto err_out0;
321 }
322
323 bo = to_lima_bo(obj);
324
325 /* increase refcnt of gpu va map to prevent unmapped when executing,
326 * will be decreased when task done
327 */
328 err = lima_vm_bo_add(vm, bo, false);
329 if (err) {
330 drm_gem_object_put(obj);
331 goto err_out0;
332 }
333
334 bos[i] = bo;
335 }
336
337 err = drm_gem_lock_reservations((struct drm_gem_object **)bos,
338 submit->nr_bos, &ctx);
339 if (err)
340 goto err_out0;
341
342 err = lima_sched_task_init(
343 submit->task, submit->ctx->context + submit->pipe,
344 bos, submit->nr_bos, vm);
345 if (err)
346 goto err_out1;
347
348 err = lima_gem_add_deps(file, submit);
349 if (err)
350 goto err_out2;
351
352 for (i = 0; i < submit->nr_bos; i++) {
353 err = lima_gem_sync_bo(
354 submit->task, bos[i],
355 submit->bos[i].flags & LIMA_SUBMIT_BO_WRITE,
356 submit->flags & LIMA_SUBMIT_FLAG_EXPLICIT_FENCE);
357 if (err)
358 goto err_out2;
359 }
360
361 fence = lima_sched_context_queue_task(submit->task);
362
363 for (i = 0; i < submit->nr_bos; i++) {
364 dma_resv_add_fence(lima_bo_resv(bos[i]), fence,
365 submit->bos[i].flags & LIMA_SUBMIT_BO_WRITE ?
366 DMA_RESV_USAGE_WRITE : DMA_RESV_USAGE_READ);
367 }
368
369 drm_gem_unlock_reservations((struct drm_gem_object **)bos,
370 submit->nr_bos, &ctx);
371
372 for (i = 0; i < submit->nr_bos; i++)
373 drm_gem_object_put(&bos[i]->base.base);
374
375 if (out_sync) {
376 drm_syncobj_replace_fence(out_sync, fence);
377 drm_syncobj_put(out_sync);
378 }
379
380 dma_fence_put(fence);
381
382 return 0;
383
384err_out2:
385 lima_sched_task_fini(submit->task);
386err_out1:
387 drm_gem_unlock_reservations((struct drm_gem_object **)bos,
388 submit->nr_bos, &ctx);
389err_out0:
390 for (i = 0; i < submit->nr_bos; i++) {
391 if (!bos[i])
392 break;
393 lima_vm_bo_del(vm, bos[i]);
394 drm_gem_object_put(&bos[i]->base.base);
395 }
396 if (out_sync)
397 drm_syncobj_put(out_sync);
398 return err;
399}
400
401int lima_gem_wait(struct drm_file *file, u32 handle, u32 op, s64 timeout_ns)
402{
403 bool write = op & LIMA_GEM_WAIT_WRITE;
404 long ret, timeout;
405
406 if (!op)
407 return 0;
408
409 timeout = drm_timeout_abs_to_jiffies(timeout_ns);
410
411 ret = drm_gem_dma_resv_wait(file, handle, write, timeout);
412 if (ret == -ETIME)
413 ret = timeout ? -ETIMEDOUT : -EBUSY;
414
415 return ret;
416}