blob: cba2b12112c42a13c9129e48dbdac6a3059f9e88 [file] [log] [blame]
Ao Xu6747bbd2020-09-28 20:02:09 +08001/*
2 * Copyright (C) 2020 Amlogic, Inc. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 */
wenlong.zhange389b372021-12-16 16:42:08 +08009#include <poll.h>
10#include <sys/ioctl.h>
11#include "dma-buf.h"
Ao Xu6747bbd2020-09-28 20:02:09 +080012#include "meson_drm_util.h"
13
14struct drm_display *drm_kms_init(void);
15
16struct drm_display *drm_display_init(void)
17{
18 return drm_kms_init();
19}
20
21void drm_destroy_display(struct drm_display *disp)
22{
23 disp->destroy_display(disp);
24}
25
26void drm_display_register_done_cb(struct drm_display *disp, void *func, void *priv)
27{
28 disp->display_done_callback = func;
29 disp->priv = priv;
30}
31
32void drm_display_register_res_cb(struct drm_display *disp, void *func, void *priv)
33{
34 disp->resolution_change_callback = func;
35 disp->reso_priv = priv;
36}
37
wenlong.zhang4c011d42022-06-09 10:59:38 +080038int drm_set_alloc_only_flag(struct drm_display *disp, int flag)
39{
40 disp->alloc_only = flag;
41}
42
Ao Xu6747bbd2020-09-28 20:02:09 +080043int drm_alloc_bufs(struct drm_display *disp, int num, struct drm_buf_metadata *info)
44{
45 int ret;
46 ret = disp->alloc_bufs(disp, num, info);
47
48 return ret;
49}
50
51int drm_free_bufs(struct drm_display *disp)
52{
53 int ret;
54 ret = disp->free_bufs(disp);
55
56 return ret;
57}
58
59struct drm_buf *drm_alloc_buf(struct drm_display *disp, struct drm_buf_metadata *info)
60{
61 struct drm_buf *buf = NULL;
62
63 buf = disp->alloc_buf(disp, info);
64
65 return buf;
66}
67
Ao Xu70554242020-10-15 15:19:48 +080068struct drm_buf *drm_import_buf(struct drm_display *disp, struct drm_buf_import *info)
69{
70 struct drm_buf *buf = NULL;
71
72 buf = disp->import_buf(disp, info);
73
74 return buf;
75}
76
Ao Xu6747bbd2020-09-28 20:02:09 +080077int drm_free_buf(struct drm_buf *buf)
78{
79 int ret;
80 struct drm_display *disp = buf->disp;
81 ret = disp->free_buf(buf);
82
83 return ret;
84}
85
86int drm_post_buf(struct drm_display *disp, struct drm_buf *buf)
87{
88 return disp->post_buf(disp, buf);
89}
wenlong.zhange389b372021-12-16 16:42:08 +080090
91int drm_waitvideoFence( int dmabuffd )
92{
93 struct dma_buf_export_sync_file dma_fence;
94 int rc = -1;
95
96 if (dmabuffd <= 0)
97 return;
98
99 memset (&dma_fence, 0, sizeof(dma_fence));
100 dma_fence.flags |= DMA_BUF_SYNC_READ;
101 rc = ioctl(dmabuffd, DMA_BUF_IOCTL_EXPORT_SYNC_FILE, &dma_fence);
102 if (!rc && dma_fence.fd >= 0 )
103 {
104 struct pollfd pfd;
105
106 pfd.fd= dma_fence.fd;
107 pfd.events= POLLIN;
108 pfd.revents= 0;
109
110 for ( ; ; ) {
111 rc= poll( &pfd, 1, 3000);
112 if ( (rc == -1) && ((errno == EINTR) || (errno == EAGAIN)) )
113 {
114 continue;
115 }
116 else if ( rc <= 0 )
117 {
118 if ( rc == 0 ) errno= ETIME;
119 fprintf(stderr, "wait out video fence failed: fd %d errno %d\n", dma_fence.fd, errno);
120 }
121 else if(pfd.revents & (POLLNVAL | POLLERR)) {
122 fprintf(stderr, "waiting on video fence fd %d, revents error\n", dma_fence.fd);
123 }
124 break;
125 }
126 close( dma_fence.fd );
127 dma_fence.fd= -1;
128 }
129
130 return rc;
131}