blob: abe39adc41c27709b1dd4ee47ff30b9293d4f5a0 [file] [log] [blame]
limin.tian79bf2b12023-02-24 10:28:26 +00001 /*
2 * Copyright (c) 2019 Amlogic, Inc. All rights reserved.
Ao Xu6747bbd2020-09-28 20:02:09 +08003 *
limin.tian79bf2b12023-02-24 10:28:26 +00004 * This source code is subject to the terms and conditions defined in the
5 * file 'LICENSE' which is part of this source code package.
6 *
7 * Description:
Ao Xu6747bbd2020-09-28 20:02:09 +08008 */
limin.tian79bf2b12023-02-24 10:28:26 +00009
wenlong.zhange389b372021-12-16 16:42:08 +080010#include <poll.h>
11#include <sys/ioctl.h>
12#include "dma-buf.h"
Ao Xu6747bbd2020-09-28 20:02:09 +080013#include "meson_drm_util.h"
14
15struct drm_display *drm_kms_init(void);
16
17struct drm_display *drm_display_init(void)
18{
19 return drm_kms_init();
20}
21
22void drm_destroy_display(struct drm_display *disp)
23{
24 disp->destroy_display(disp);
25}
26
27void drm_display_register_done_cb(struct drm_display *disp, void *func, void *priv)
28{
29 disp->display_done_callback = func;
30 disp->priv = priv;
31}
32
33void drm_display_register_res_cb(struct drm_display *disp, void *func, void *priv)
34{
35 disp->resolution_change_callback = func;
36 disp->reso_priv = priv;
37}
38
wenlong.zhang4c011d42022-06-09 10:59:38 +080039int drm_set_alloc_only_flag(struct drm_display *disp, int flag)
40{
41 disp->alloc_only = flag;
42}
43
Ao Xu6747bbd2020-09-28 20:02:09 +080044int drm_alloc_bufs(struct drm_display *disp, int num, struct drm_buf_metadata *info)
45{
46 int ret;
47 ret = disp->alloc_bufs(disp, num, info);
48
49 return ret;
50}
51
52int drm_free_bufs(struct drm_display *disp)
53{
54 int ret;
55 ret = disp->free_bufs(disp);
56
57 return ret;
58}
59
60struct drm_buf *drm_alloc_buf(struct drm_display *disp, struct drm_buf_metadata *info)
61{
62 struct drm_buf *buf = NULL;
63
64 buf = disp->alloc_buf(disp, info);
65
66 return buf;
67}
68
Ao Xu70554242020-10-15 15:19:48 +080069struct drm_buf *drm_import_buf(struct drm_display *disp, struct drm_buf_import *info)
70{
71 struct drm_buf *buf = NULL;
72
73 buf = disp->import_buf(disp, info);
74
75 return buf;
76}
77
Ao Xu6747bbd2020-09-28 20:02:09 +080078int drm_free_buf(struct drm_buf *buf)
79{
80 int ret;
81 struct drm_display *disp = buf->disp;
82 ret = disp->free_buf(buf);
83
84 return ret;
85}
86
87int drm_post_buf(struct drm_display *disp, struct drm_buf *buf)
88{
89 return disp->post_buf(disp, buf);
90}
wenlong.zhange389b372021-12-16 16:42:08 +080091
92int drm_waitvideoFence( int dmabuffd )
93{
94 struct dma_buf_export_sync_file dma_fence;
95 int rc = -1;
96
97 if (dmabuffd <= 0)
98 return;
99
100 memset (&dma_fence, 0, sizeof(dma_fence));
101 dma_fence.flags |= DMA_BUF_SYNC_READ;
102 rc = ioctl(dmabuffd, DMA_BUF_IOCTL_EXPORT_SYNC_FILE, &dma_fence);
103 if (!rc && dma_fence.fd >= 0 )
104 {
105 struct pollfd pfd;
106
107 pfd.fd= dma_fence.fd;
108 pfd.events= POLLIN;
109 pfd.revents= 0;
110
111 for ( ; ; ) {
112 rc= poll( &pfd, 1, 3000);
113 if ( (rc == -1) && ((errno == EINTR) || (errno == EAGAIN)) )
114 {
115 continue;
116 }
117 else if ( rc <= 0 )
118 {
119 if ( rc == 0 ) errno= ETIME;
120 fprintf(stderr, "wait out video fence failed: fd %d errno %d\n", dma_fence.fd, errno);
121 }
122 else if(pfd.revents & (POLLNVAL | POLLERR)) {
123 fprintf(stderr, "waiting on video fence fd %d, revents error\n", dma_fence.fd);
124 }
125 break;
126 }
127 close( dma_fence.fd );
128 dma_fence.fd= -1;
129 }
130
131 return rc;
132}