Ao Xu | 6747bbd | 2020-09-28 20:02:09 +0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 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 | |
| 23 | struct 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 Xu | 7055424 | 2020-10-15 15:19:48 +0800 | [diff] [blame] | 39 | int crtc_x, crtc_y; |
| 40 | uint32_t crtc_w, crtc_h; |
Ao Xu | 6747bbd | 2020-09-28 20:02:09 +0800 | [diff] [blame] | 41 | uint32_t zpos; |
| 42 | |
| 43 | struct drm_display *disp; |
| 44 | int commit_to_video; |
| 45 | }; |
| 46 | |
| 47 | struct drm_buf_metadata { |
| 48 | uint32_t fourcc; |
| 49 | uint32_t width; |
| 50 | uint32_t height; |
| 51 | uint32_t flags; |
| 52 | }; |
| 53 | |
Ao Xu | 7055424 | 2020-10-15 15:19:48 +0800 | [diff] [blame] | 54 | struct drm_buf_import { |
| 55 | uint32_t fourcc; |
| 56 | uint32_t width; |
| 57 | uint32_t height; |
| 58 | uint32_t flags; |
| 59 | int fd[4]; |
| 60 | }; |
| 61 | |
Ao Xu | 6747bbd | 2020-09-28 20:02:09 +0800 | [diff] [blame] | 62 | struct drm_display { |
| 63 | int drm_fd; |
| 64 | uint32_t width, height; |
| 65 | uint32_t vrefresh; |
| 66 | struct meson_device *dev; |
| 67 | |
| 68 | size_t nbuf; |
| 69 | struct drm_buf *bufs; |
| 70 | |
| 71 | void (*destroy_display)(struct drm_display *disp); |
| 72 | int (*alloc_bufs)(struct drm_display *disp, int num, struct drm_buf_metadata *info); |
| 73 | int (*free_bufs)(struct drm_display *disp); |
| 74 | |
| 75 | struct drm_buf *(*alloc_buf)(struct drm_display *disp, struct drm_buf_metadata *info); |
Ao Xu | 7055424 | 2020-10-15 15:19:48 +0800 | [diff] [blame] | 76 | struct drm_buf *(*import_buf)(struct drm_display *disp, struct drm_buf_import *info); |
Ao Xu | 6747bbd | 2020-09-28 20:02:09 +0800 | [diff] [blame] | 77 | int (*free_buf)(struct drm_buf *buf); |
| 78 | int (*post_buf)(struct drm_display *disp, struct drm_buf *buf); |
| 79 | |
| 80 | void (*display_done_callback)(void *priv); |
| 81 | void *priv; |
| 82 | |
| 83 | void (*resolution_change_callback)(void *priv); |
| 84 | void *reso_priv; |
| 85 | }; |
| 86 | |
| 87 | struct drm_display *drm_display_init(void); |
| 88 | void drm_destroy_display(struct drm_display *disp); |
| 89 | void drm_display_register_done_cb(struct drm_display *disp, void *func, void *priv); |
| 90 | void drm_display_register_res_cb(struct drm_display *disp, void *func, void *priv); |
| 91 | |
| 92 | int drm_alloc_bufs(struct drm_display *disp, int num, struct drm_buf_metadata *info); |
| 93 | int drm_free_bufs(struct drm_display *disp); |
| 94 | |
| 95 | struct drm_buf *drm_alloc_buf(struct drm_display *disp, struct drm_buf_metadata *info); |
Ao Xu | 7055424 | 2020-10-15 15:19:48 +0800 | [diff] [blame] | 96 | struct drm_buf *drm_import_buf(struct drm_display *disp, struct drm_buf_import *info); |
Ao Xu | 6747bbd | 2020-09-28 20:02:09 +0800 | [diff] [blame] | 97 | int drm_free_buf(struct drm_buf *buf); |
| 98 | int drm_post_buf(struct drm_display *disp, struct drm_buf *buf); |
| 99 | |
sky zhou | f05ca46 | 2020-10-29 18:07:40 +0800 | [diff] [blame^] | 100 | int drmModeAsyncAtomicCommit(int fd, drmModeAtomicReqPtr req, |
| 101 | uint32_t flags, void *user_data); |
| 102 | |
Ao Xu | 6747bbd | 2020-09-28 20:02:09 +0800 | [diff] [blame] | 103 | #endif |