2
* Copyright (c) 2018-2019 Lima Project
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sub license,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
11
* The above copyright notice and this permission notice (including the
12
* next paragraph) shall be included in all copies or substantial portions
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
* DEALINGS IN THE SOFTWARE.
28
#include "util/os_file.h"
29
#include <util/u_memory.h>
30
#include <util/u_inlines.h>
32
#include "drm-uapi/lima_drm.h"
34
#include "lima_screen.h"
35
#include "lima_context.h"
36
#include "lima_fence.h"
39
struct pipe_fence_handle {
40
struct pipe_reference reference;
45
lima_create_fence_fd(struct pipe_context *pctx,
46
struct pipe_fence_handle **fence,
47
int fd, enum pipe_fd_type type)
49
assert(type == PIPE_FD_TYPE_NATIVE_SYNC);
50
*fence = lima_fence_create(os_dupfd_cloexec(fd));
54
lima_fence_server_sync(struct pipe_context *pctx,
55
struct pipe_fence_handle *fence)
57
struct lima_context *ctx = lima_context(pctx);
59
sync_accumulate("lima", &ctx->in_sync_fd, fence->fd);
62
void lima_fence_context_init(struct lima_context *ctx)
64
ctx->base.create_fence_fd = lima_create_fence_fd;
65
ctx->base.fence_server_sync = lima_fence_server_sync;
68
struct pipe_fence_handle *
69
lima_fence_create(int fd)
71
struct pipe_fence_handle *fence;
73
fence = CALLOC_STRUCT(pipe_fence_handle);
77
pipe_reference_init(&fence->reference, 1);
84
lima_fence_get_fd(struct pipe_screen *pscreen,
85
struct pipe_fence_handle *fence)
87
return os_dupfd_cloexec(fence->fd);
91
lima_fence_destroy(struct pipe_fence_handle *fence)
99
lima_fence_reference(struct pipe_screen *pscreen,
100
struct pipe_fence_handle **ptr,
101
struct pipe_fence_handle *fence)
103
if (pipe_reference(&(*ptr)->reference, &fence->reference))
104
lima_fence_destroy(*ptr);
109
lima_fence_finish(struct pipe_screen *pscreen, struct pipe_context *pctx,
110
struct pipe_fence_handle *fence, uint64_t timeout)
112
return !sync_wait(fence->fd, timeout / 1000000);
116
lima_fence_screen_init(struct lima_screen *screen)
118
screen->base.fence_reference = lima_fence_reference;
119
screen->base.fence_finish = lima_fence_finish;
120
screen->base.fence_get_fd = lima_fence_get_fd;