blob: ef382a9b0edb6687e2771bbb2427537094453e9c [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
38int drm_alloc_bufs(struct drm_display *disp, int num, struct drm_buf_metadata *info)
39{
40 int ret;
41 ret = disp->alloc_bufs(disp, num, info);
42
43 return ret;
44}
45
46int drm_free_bufs(struct drm_display *disp)
47{
48 int ret;
49 ret = disp->free_bufs(disp);
50
51 return ret;
52}
53
54struct drm_buf *drm_alloc_buf(struct drm_display *disp, struct drm_buf_metadata *info)
55{
56 struct drm_buf *buf = NULL;
57
58 buf = disp->alloc_buf(disp, info);
59
60 return buf;
61}
62
Ao Xu70554242020-10-15 15:19:48 +080063struct drm_buf *drm_import_buf(struct drm_display *disp, struct drm_buf_import *info)
64{
65 struct drm_buf *buf = NULL;
66
67 buf = disp->import_buf(disp, info);
68
69 return buf;
70}
71
Ao Xu6747bbd2020-09-28 20:02:09 +080072int drm_free_buf(struct drm_buf *buf)
73{
74 int ret;
75 struct drm_display *disp = buf->disp;
76 ret = disp->free_buf(buf);
77
78 return ret;
79}
80
81int drm_post_buf(struct drm_display *disp, struct drm_buf *buf)
82{
83 return disp->post_buf(disp, buf);
84}
wenlong.zhange389b372021-12-16 16:42:08 +080085
86int drm_waitvideoFence( int dmabuffd )
87{
88 struct dma_buf_export_sync_file dma_fence;
89 int rc = -1;
90
91 if (dmabuffd <= 0)
92 return;
93
94 memset (&dma_fence, 0, sizeof(dma_fence));
95 dma_fence.flags |= DMA_BUF_SYNC_READ;
96 rc = ioctl(dmabuffd, DMA_BUF_IOCTL_EXPORT_SYNC_FILE, &dma_fence);
97 if (!rc && dma_fence.fd >= 0 )
98 {
99 struct pollfd pfd;
100
101 pfd.fd= dma_fence.fd;
102 pfd.events= POLLIN;
103 pfd.revents= 0;
104
105 for ( ; ; ) {
106 rc= poll( &pfd, 1, 3000);
107 if ( (rc == -1) && ((errno == EINTR) || (errno == EAGAIN)) )
108 {
109 continue;
110 }
111 else if ( rc <= 0 )
112 {
113 if ( rc == 0 ) errno= ETIME;
114 fprintf(stderr, "wait out video fence failed: fd %d errno %d\n", dma_fence.fd, errno);
115 }
116 else if(pfd.revents & (POLLNVAL | POLLERR)) {
117 fprintf(stderr, "waiting on video fence fd %d, revents error\n", dma_fence.fd);
118 }
119 break;
120 }
121 close( dma_fence.fd );
122 dma_fence.fd= -1;
123 }
124
125 return rc;
126}