blob: cd4caa0f14cbb036782ca243f82d9b75e2d34521 [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 */
9
10#ifndef _MESON_DRM_UTIL_H_
11#define _MESON_DRM_UTIL_H_
12
13#include <stdio.h>
14#include <stdint.h>
15#include <stdlib.h>
16#include <string.h>
17#include <errno.h>
18#include <unistd.h>
19
20#include <xf86drmMode.h>
21#include "meson_drmif.h"
22
23struct drm_buf {
24 uint32_t fourcc;
25 uint32_t width;
26 uint32_t height;
27 uint32_t flags;
28 uint32_t size;
29 int bpp;
30 int nbo;
31 struct meson_bo *bos[4];
32 uint32_t pitches[4];
33 uint32_t offsets[4];
34 uint32_t fb_id;
35 int fd[4];
36 int fence_fd;
37
38 uint32_t src_x, src_y, src_w, src_h;
Ao Xu70554242020-10-15 15:19:48 +080039 int crtc_x, crtc_y;
40 uint32_t crtc_w, crtc_h;
Ao Xu6747bbd2020-09-28 20:02:09 +080041 uint32_t zpos;
42
43 struct drm_display *disp;
44 int commit_to_video;
wenlong.zhangcf8a5462023-04-10 03:25:19 +000045 int disable_plane;
mingyang.hefecc9982024-12-18 19:47:59 +080046 uint32_t rotation;
Ao Xu6747bbd2020-09-28 20:02:09 +080047};
48
49struct drm_buf_metadata {
50 uint32_t fourcc;
51 uint32_t width;
52 uint32_t height;
53 uint32_t flags;
54};
55
Ao Xu70554242020-10-15 15:19:48 +080056struct drm_buf_import {
57 uint32_t fourcc;
58 uint32_t width;
59 uint32_t height;
60 uint32_t flags;
61 int fd[4];
62};
63
Ao Xu6747bbd2020-09-28 20:02:09 +080064struct drm_display {
65 int drm_fd;
66 uint32_t width, height;
67 uint32_t vrefresh;
68 struct meson_device *dev;
69
70 size_t nbuf;
71 struct drm_buf *bufs;
wenlong.zhang7d32ed92023-04-12 06:08:17 +000072 int alloc_only;
73 int freeze;
Ao Xu6747bbd2020-09-28 20:02:09 +080074
75 void (*destroy_display)(struct drm_display *disp);
76 int (*alloc_bufs)(struct drm_display *disp, int num, struct drm_buf_metadata *info);
77 int (*free_bufs)(struct drm_display *disp);
78
79 struct drm_buf *(*alloc_buf)(struct drm_display *disp, struct drm_buf_metadata *info);
Ao Xu70554242020-10-15 15:19:48 +080080 struct drm_buf *(*import_buf)(struct drm_display *disp, struct drm_buf_import *info);
Ao Xu6747bbd2020-09-28 20:02:09 +080081 int (*free_buf)(struct drm_buf *buf);
82 int (*post_buf)(struct drm_display *disp, struct drm_buf *buf);
mingyang.he2ba112a2024-03-25 07:56:58 +000083 int (*set_plane)(struct drm_display *disp, struct drm_buf *buf);
Ao Xu6747bbd2020-09-28 20:02:09 +080084
85 void (*display_done_callback)(void *priv);
86 void *priv;
87
88 void (*resolution_change_callback)(void *priv);
89 void *reso_priv;
90};
91
92struct drm_display *drm_display_init(void);
93void drm_destroy_display(struct drm_display *disp);
94void drm_display_register_done_cb(struct drm_display *disp, void *func, void *priv);
95void drm_display_register_res_cb(struct drm_display *disp, void *func, void *priv);
wenlong.zhang4c011d42022-06-09 10:59:38 +080096/*for non-root process, the renderD128 can used to do some ioctl, except display related ioctl*/
97int drm_set_alloc_only_flag(struct drm_display *disp, int flag);
Ao Xu6747bbd2020-09-28 20:02:09 +080098
99int drm_alloc_bufs(struct drm_display *disp, int num, struct drm_buf_metadata *info);
100int drm_free_bufs(struct drm_display *disp);
101
102struct drm_buf *drm_alloc_buf(struct drm_display *disp, struct drm_buf_metadata *info);
Ao Xu70554242020-10-15 15:19:48 +0800103struct drm_buf *drm_import_buf(struct drm_display *disp, struct drm_buf_import *info);
Ao Xu6747bbd2020-09-28 20:02:09 +0800104int drm_free_buf(struct drm_buf *buf);
105int drm_post_buf(struct drm_display *disp, struct drm_buf *buf);
106
sky zhouf05ca462020-10-29 18:07:40 +0800107int drmModeAsyncAtomicCommit(int fd, drmModeAtomicReqPtr req,
108 uint32_t flags, void *user_data);
109
wenlong.zhange389b372021-12-16 16:42:08 +0800110int drm_waitvideoFence( int dmabuffd);
111
Ao Xu6747bbd2020-09-28 20:02:09 +0800112#endif