xref: /OK3568_Linux_fs/external/drm-cursor/drm_common.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *  Copyright (c) 2021, Jeffy Chen <jeffy.chen@rock-chips.com>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  */
14 
15 #ifndef __DRM_COMMON_H_
16 #define __DRM_COMMON_H_
17 
18 #include <drm_fourcc.h>
19 
20 #include <stdio.h>
21 #include <stdint.h>
22 #include <sys/time.h>
23 
24 #define LIBDRM_CURSOR_VERSION "1.4.1~20230414"
25 
26 #define drm_private __attribute__((visibility("hidden")))
27 
28 #ifndef DRM_FORMAT_MOD_VENDOR_ARM
29 #define DRM_FORMAT_MOD_VENDOR_ARM 0x08
30 #endif
31 
32 #ifndef DRM_FORMAT_MOD_ARM_AFBC
33 #define DRM_FORMAT_MOD_ARM_AFBC(__afbc_mode) fourcc_mod_code(ARM, __afbc_mode)
34 #endif
35 
36 #ifndef AFBC_FORMAT_MOD_BLOCK_SIZE_16x16
37 #define AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 (1ULL)
38 #endif
39 
40 #ifndef AFBC_FORMAT_MOD_SPARSE
41 #define AFBC_FORMAT_MOD_SPARSE (((__u64)1) << 6)
42 #endif
43 
44 #define DRM_AFBC_MODIFIER \
45   (DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_SPARSE) | \
46    DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16))
47 
48 #define DRM_LOG(tag, ...) { \
49   struct timeval tv; gettimeofday(&tv, NULL); \
50   fprintf(g_log_fp ? g_log_fp : stderr, "[%05ld.%03ld] " tag ": %s(%d) ", \
51           tv.tv_sec % 100000, tv.tv_usec / 1000, __func__, __LINE__); \
52   fprintf(g_log_fp ? g_log_fp : stderr, __VA_ARGS__); \
53   fflush(g_log_fp ? g_log_fp : stderr); }
54 
55 #define DRM_DEBUG(...) \
56   if (g_drm_debug) DRM_LOG("DRM_DEBUG", __VA_ARGS__)
57 
58 #define DRM_INFO(...) DRM_LOG("DRM_INFO", __VA_ARGS__)
59 
60 #define DRM_ERROR(...) DRM_LOG("DRM_ERROR", __VA_ARGS__)
61 
62 drm_private extern int g_drm_debug;
63 drm_private extern FILE *g_log_fp;
64 
65 #endif
66