1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright 2011 Intel Corporation
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a
5*4882a593Smuzhiyun * copy of this software and associated documentation files (the "Software"),
6*4882a593Smuzhiyun * to deal in the Software without restriction, including without limitation
7*4882a593Smuzhiyun * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*4882a593Smuzhiyun * and/or sell copies of the Software, and to permit persons to whom the
9*4882a593Smuzhiyun * Software is furnished to do so, subject to the following conditions:
10*4882a593Smuzhiyun *
11*4882a593Smuzhiyun * The above copyright notice and this permission notice (including the next
12*4882a593Smuzhiyun * paragraph) shall be included in all copies or substantial portions of the
13*4882a593Smuzhiyun * Software.
14*4882a593Smuzhiyun *
15*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*4882a593Smuzhiyun * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18*4882a593Smuzhiyun * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19*4882a593Smuzhiyun * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20*4882a593Smuzhiyun * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21*4882a593Smuzhiyun * OTHER DEALINGS IN THE SOFTWARE.
22*4882a593Smuzhiyun */
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun #ifndef DRM_FOURCC_H
25*4882a593Smuzhiyun #define DRM_FOURCC_H
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun #include "drm.h"
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun #if defined(__cplusplus)
30*4882a593Smuzhiyun extern "C" {
31*4882a593Smuzhiyun #endif
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun /**
34*4882a593Smuzhiyun * DOC: overview
35*4882a593Smuzhiyun *
36*4882a593Smuzhiyun * In the DRM subsystem, framebuffer pixel formats are described using the
37*4882a593Smuzhiyun * fourcc codes defined in `include/uapi/drm/drm_fourcc.h`. In addition to the
38*4882a593Smuzhiyun * fourcc code, a Format Modifier may optionally be provided, in order to
39*4882a593Smuzhiyun * further describe the buffer's format - for example tiling or compression.
40*4882a593Smuzhiyun *
41*4882a593Smuzhiyun * Format Modifiers
42*4882a593Smuzhiyun * ----------------
43*4882a593Smuzhiyun *
44*4882a593Smuzhiyun * Format modifiers are used in conjunction with a fourcc code, forming a
45*4882a593Smuzhiyun * unique fourcc:modifier pair. This format:modifier pair must fully define the
46*4882a593Smuzhiyun * format and data layout of the buffer, and should be the only way to describe
47*4882a593Smuzhiyun * that particular buffer.
48*4882a593Smuzhiyun *
49*4882a593Smuzhiyun * Having multiple fourcc:modifier pairs which describe the same layout should
50*4882a593Smuzhiyun * be avoided, as such aliases run the risk of different drivers exposing
51*4882a593Smuzhiyun * different names for the same data format, forcing userspace to understand
52*4882a593Smuzhiyun * that they are aliases.
53*4882a593Smuzhiyun *
54*4882a593Smuzhiyun * Format modifiers may change any property of the buffer, including the number
55*4882a593Smuzhiyun * of planes and/or the required allocation size. Format modifiers are
56*4882a593Smuzhiyun * vendor-namespaced, and as such the relationship between a fourcc code and a
57*4882a593Smuzhiyun * modifier is specific to the modifer being used. For example, some modifiers
58*4882a593Smuzhiyun * may preserve meaning - such as number of planes - from the fourcc code,
59*4882a593Smuzhiyun * whereas others may not.
60*4882a593Smuzhiyun *
61*4882a593Smuzhiyun * Vendors should document their modifier usage in as much detail as
62*4882a593Smuzhiyun * possible, to ensure maximum compatibility across devices, drivers and
63*4882a593Smuzhiyun * applications.
64*4882a593Smuzhiyun *
65*4882a593Smuzhiyun * The authoritative list of format modifier codes is found in
66*4882a593Smuzhiyun * `include/uapi/drm/drm_fourcc.h`
67*4882a593Smuzhiyun */
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun #define fourcc_code(a, b, c, d) ((__u32)(a) | ((__u32)(b) << 8) | \
70*4882a593Smuzhiyun ((__u32)(c) << 16) | ((__u32)(d) << 24))
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun #define DRM_FORMAT_BIG_ENDIAN (1U<<31) /* format is big endian instead of little endian */
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun /* Reserve 0 for the invalid format specifier */
75*4882a593Smuzhiyun #define DRM_FORMAT_INVALID 0
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun /* color index */
78*4882a593Smuzhiyun #define DRM_FORMAT_C8 fourcc_code('C', '8', ' ', ' ') /* [7:0] C */
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun /* 8 bpp Red */
81*4882a593Smuzhiyun #define DRM_FORMAT_R8 fourcc_code('R', '8', ' ', ' ') /* [7:0] R */
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun /* 16 bpp Red */
84*4882a593Smuzhiyun #define DRM_FORMAT_R16 fourcc_code('R', '1', '6', ' ') /* [15:0] R little endian */
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun /* 16 bpp RG */
87*4882a593Smuzhiyun #define DRM_FORMAT_RG88 fourcc_code('R', 'G', '8', '8') /* [15:0] R:G 8:8 little endian */
88*4882a593Smuzhiyun #define DRM_FORMAT_GR88 fourcc_code('G', 'R', '8', '8') /* [15:0] G:R 8:8 little endian */
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun /* 32 bpp RG */
91*4882a593Smuzhiyun #define DRM_FORMAT_RG1616 fourcc_code('R', 'G', '3', '2') /* [31:0] R:G 16:16 little endian */
92*4882a593Smuzhiyun #define DRM_FORMAT_GR1616 fourcc_code('G', 'R', '3', '2') /* [31:0] G:R 16:16 little endian */
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun /* 8 bpp RGB */
95*4882a593Smuzhiyun #define DRM_FORMAT_RGB332 fourcc_code('R', 'G', 'B', '8') /* [7:0] R:G:B 3:3:2 */
96*4882a593Smuzhiyun #define DRM_FORMAT_BGR233 fourcc_code('B', 'G', 'R', '8') /* [7:0] B:G:R 2:3:3 */
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun /* 16 bpp RGB */
99*4882a593Smuzhiyun #define DRM_FORMAT_XRGB4444 fourcc_code('X', 'R', '1', '2') /* [15:0] x:R:G:B 4:4:4:4 little endian */
100*4882a593Smuzhiyun #define DRM_FORMAT_XBGR4444 fourcc_code('X', 'B', '1', '2') /* [15:0] x:B:G:R 4:4:4:4 little endian */
101*4882a593Smuzhiyun #define DRM_FORMAT_RGBX4444 fourcc_code('R', 'X', '1', '2') /* [15:0] R:G:B:x 4:4:4:4 little endian */
102*4882a593Smuzhiyun #define DRM_FORMAT_BGRX4444 fourcc_code('B', 'X', '1', '2') /* [15:0] B:G:R:x 4:4:4:4 little endian */
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun #define DRM_FORMAT_ARGB4444 fourcc_code('A', 'R', '1', '2') /* [15:0] A:R:G:B 4:4:4:4 little endian */
105*4882a593Smuzhiyun #define DRM_FORMAT_ABGR4444 fourcc_code('A', 'B', '1', '2') /* [15:0] A:B:G:R 4:4:4:4 little endian */
106*4882a593Smuzhiyun #define DRM_FORMAT_RGBA4444 fourcc_code('R', 'A', '1', '2') /* [15:0] R:G:B:A 4:4:4:4 little endian */
107*4882a593Smuzhiyun #define DRM_FORMAT_BGRA4444 fourcc_code('B', 'A', '1', '2') /* [15:0] B:G:R:A 4:4:4:4 little endian */
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun #define DRM_FORMAT_XRGB1555 fourcc_code('X', 'R', '1', '5') /* [15:0] x:R:G:B 1:5:5:5 little endian */
110*4882a593Smuzhiyun #define DRM_FORMAT_XBGR1555 fourcc_code('X', 'B', '1', '5') /* [15:0] x:B:G:R 1:5:5:5 little endian */
111*4882a593Smuzhiyun #define DRM_FORMAT_RGBX5551 fourcc_code('R', 'X', '1', '5') /* [15:0] R:G:B:x 5:5:5:1 little endian */
112*4882a593Smuzhiyun #define DRM_FORMAT_BGRX5551 fourcc_code('B', 'X', '1', '5') /* [15:0] B:G:R:x 5:5:5:1 little endian */
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun #define DRM_FORMAT_ARGB1555 fourcc_code('A', 'R', '1', '5') /* [15:0] A:R:G:B 1:5:5:5 little endian */
115*4882a593Smuzhiyun #define DRM_FORMAT_ABGR1555 fourcc_code('A', 'B', '1', '5') /* [15:0] A:B:G:R 1:5:5:5 little endian */
116*4882a593Smuzhiyun #define DRM_FORMAT_RGBA5551 fourcc_code('R', 'A', '1', '5') /* [15:0] R:G:B:A 5:5:5:1 little endian */
117*4882a593Smuzhiyun #define DRM_FORMAT_BGRA5551 fourcc_code('B', 'A', '1', '5') /* [15:0] B:G:R:A 5:5:5:1 little endian */
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun #define DRM_FORMAT_RGB565 fourcc_code('R', 'G', '1', '6') /* [15:0] R:G:B 5:6:5 little endian */
120*4882a593Smuzhiyun #define DRM_FORMAT_BGR565 fourcc_code('B', 'G', '1', '6') /* [15:0] B:G:R 5:6:5 little endian */
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun /* 24 bpp RGB */
123*4882a593Smuzhiyun #define DRM_FORMAT_RGB888 fourcc_code('R', 'G', '2', '4') /* [23:0] R:G:B little endian */
124*4882a593Smuzhiyun #define DRM_FORMAT_BGR888 fourcc_code('B', 'G', '2', '4') /* [23:0] B:G:R little endian */
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun /* 32 bpp RGB */
127*4882a593Smuzhiyun #define DRM_FORMAT_XRGB8888 fourcc_code('X', 'R', '2', '4') /* [31:0] x:R:G:B 8:8:8:8 little endian */
128*4882a593Smuzhiyun #define DRM_FORMAT_XBGR8888 fourcc_code('X', 'B', '2', '4') /* [31:0] x:B:G:R 8:8:8:8 little endian */
129*4882a593Smuzhiyun #define DRM_FORMAT_RGBX8888 fourcc_code('R', 'X', '2', '4') /* [31:0] R:G:B:x 8:8:8:8 little endian */
130*4882a593Smuzhiyun #define DRM_FORMAT_BGRX8888 fourcc_code('B', 'X', '2', '4') /* [31:0] B:G:R:x 8:8:8:8 little endian */
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun #define DRM_FORMAT_ARGB8888 fourcc_code('A', 'R', '2', '4') /* [31:0] A:R:G:B 8:8:8:8 little endian */
133*4882a593Smuzhiyun #define DRM_FORMAT_ABGR8888 fourcc_code('A', 'B', '2', '4') /* [31:0] A:B:G:R 8:8:8:8 little endian */
134*4882a593Smuzhiyun #define DRM_FORMAT_RGBA8888 fourcc_code('R', 'A', '2', '4') /* [31:0] R:G:B:A 8:8:8:8 little endian */
135*4882a593Smuzhiyun #define DRM_FORMAT_BGRA8888 fourcc_code('B', 'A', '2', '4') /* [31:0] B:G:R:A 8:8:8:8 little endian */
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun #define DRM_FORMAT_XRGB2101010 fourcc_code('X', 'R', '3', '0') /* [31:0] x:R:G:B 2:10:10:10 little endian */
138*4882a593Smuzhiyun #define DRM_FORMAT_XBGR2101010 fourcc_code('X', 'B', '3', '0') /* [31:0] x:B:G:R 2:10:10:10 little endian */
139*4882a593Smuzhiyun #define DRM_FORMAT_RGBX1010102 fourcc_code('R', 'X', '3', '0') /* [31:0] R:G:B:x 10:10:10:2 little endian */
140*4882a593Smuzhiyun #define DRM_FORMAT_BGRX1010102 fourcc_code('B', 'X', '3', '0') /* [31:0] B:G:R:x 10:10:10:2 little endian */
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun #define DRM_FORMAT_ARGB2101010 fourcc_code('A', 'R', '3', '0') /* [31:0] A:R:G:B 2:10:10:10 little endian */
143*4882a593Smuzhiyun #define DRM_FORMAT_ABGR2101010 fourcc_code('A', 'B', '3', '0') /* [31:0] A:B:G:R 2:10:10:10 little endian */
144*4882a593Smuzhiyun #define DRM_FORMAT_RGBA1010102 fourcc_code('R', 'A', '3', '0') /* [31:0] R:G:B:A 10:10:10:2 little endian */
145*4882a593Smuzhiyun #define DRM_FORMAT_BGRA1010102 fourcc_code('B', 'A', '3', '0') /* [31:0] B:G:R:A 10:10:10:2 little endian */
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun /*
148*4882a593Smuzhiyun * Floating point 64bpp RGB
149*4882a593Smuzhiyun * IEEE 754-2008 binary16 half-precision float
150*4882a593Smuzhiyun * [15:0] sign:exponent:mantissa 1:5:10
151*4882a593Smuzhiyun */
152*4882a593Smuzhiyun #define DRM_FORMAT_XRGB16161616F fourcc_code('X', 'R', '4', 'H') /* [63:0] x:R:G:B 16:16:16:16 little endian */
153*4882a593Smuzhiyun #define DRM_FORMAT_XBGR16161616F fourcc_code('X', 'B', '4', 'H') /* [63:0] x:B:G:R 16:16:16:16 little endian */
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun #define DRM_FORMAT_ARGB16161616F fourcc_code('A', 'R', '4', 'H') /* [63:0] A:R:G:B 16:16:16:16 little endian */
156*4882a593Smuzhiyun #define DRM_FORMAT_ABGR16161616F fourcc_code('A', 'B', '4', 'H') /* [63:0] A:B:G:R 16:16:16:16 little endian */
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun /* packed YCbCr */
159*4882a593Smuzhiyun #define DRM_FORMAT_YUYV fourcc_code('Y', 'U', 'Y', 'V') /* [31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian */
160*4882a593Smuzhiyun #define DRM_FORMAT_YVYU fourcc_code('Y', 'V', 'Y', 'U') /* [31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian */
161*4882a593Smuzhiyun #define DRM_FORMAT_UYVY fourcc_code('U', 'Y', 'V', 'Y') /* [31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian */
162*4882a593Smuzhiyun #define DRM_FORMAT_VYUY fourcc_code('V', 'Y', 'U', 'Y') /* [31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian */
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun #define DRM_FORMAT_AYUV fourcc_code('A', 'Y', 'U', 'V') /* [31:0] A:Y:Cb:Cr 8:8:8:8 little endian */
165*4882a593Smuzhiyun #define DRM_FORMAT_XYUV8888 fourcc_code('X', 'Y', 'U', 'V') /* [31:0] X:Y:Cb:Cr 8:8:8:8 little endian */
166*4882a593Smuzhiyun #define DRM_FORMAT_VUY888 fourcc_code('V', 'U', '2', '4') /* [23:0] Cr:Cb:Y 8:8:8 little endian */
167*4882a593Smuzhiyun #define DRM_FORMAT_VUY101010 fourcc_code('V', 'U', '3', '0') /* Y followed by U then V, 10:10:10. Non-linear modifier only */
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun /*
170*4882a593Smuzhiyun * packed Y2xx indicate for each component, xx valid data occupy msb
171*4882a593Smuzhiyun * 16-xx padding occupy lsb
172*4882a593Smuzhiyun */
173*4882a593Smuzhiyun #define DRM_FORMAT_Y210 fourcc_code('Y', '2', '1', '0') /* [63:0] Cr0:0:Y1:0:Cb0:0:Y0:0 10:6:10:6:10:6:10:6 little endian per 2 Y pixels */
174*4882a593Smuzhiyun #define DRM_FORMAT_Y212 fourcc_code('Y', '2', '1', '2') /* [63:0] Cr0:0:Y1:0:Cb0:0:Y0:0 12:4:12:4:12:4:12:4 little endian per 2 Y pixels */
175*4882a593Smuzhiyun #define DRM_FORMAT_Y216 fourcc_code('Y', '2', '1', '6') /* [63:0] Cr0:Y1:Cb0:Y0 16:16:16:16 little endian per 2 Y pixels */
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun /*
178*4882a593Smuzhiyun * packed Y4xx indicate for each component, xx valid data occupy msb
179*4882a593Smuzhiyun * 16-xx padding occupy lsb except Y410
180*4882a593Smuzhiyun */
181*4882a593Smuzhiyun #define DRM_FORMAT_Y410 fourcc_code('Y', '4', '1', '0') /* [31:0] A:Cr:Y:Cb 2:10:10:10 little endian */
182*4882a593Smuzhiyun #define DRM_FORMAT_Y412 fourcc_code('Y', '4', '1', '2') /* [63:0] A:0:Cr:0:Y:0:Cb:0 12:4:12:4:12:4:12:4 little endian */
183*4882a593Smuzhiyun #define DRM_FORMAT_Y416 fourcc_code('Y', '4', '1', '6') /* [63:0] A:Cr:Y:Cb 16:16:16:16 little endian */
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun #define DRM_FORMAT_XVYU2101010 fourcc_code('X', 'V', '3', '0') /* [31:0] X:Cr:Y:Cb 2:10:10:10 little endian */
186*4882a593Smuzhiyun #define DRM_FORMAT_XVYU12_16161616 fourcc_code('X', 'V', '3', '6') /* [63:0] X:0:Cr:0:Y:0:Cb:0 12:4:12:4:12:4:12:4 little endian */
187*4882a593Smuzhiyun #define DRM_FORMAT_XVYU16161616 fourcc_code('X', 'V', '4', '8') /* [63:0] X:Cr:Y:Cb 16:16:16:16 little endian */
188*4882a593Smuzhiyun
189*4882a593Smuzhiyun /*
190*4882a593Smuzhiyun * packed YCbCr420 2x2 tiled formats
191*4882a593Smuzhiyun * first 64 bits will contain Y,Cb,Cr components for a 2x2 tile
192*4882a593Smuzhiyun */
193*4882a593Smuzhiyun /* [63:0] A3:A2:Y3:0:Cr0:0:Y2:0:A1:A0:Y1:0:Cb0:0:Y0:0 1:1:8:2:8:2:8:2:1:1:8:2:8:2:8:2 little endian */
194*4882a593Smuzhiyun #define DRM_FORMAT_Y0L0 fourcc_code('Y', '0', 'L', '0')
195*4882a593Smuzhiyun /* [63:0] X3:X2:Y3:0:Cr0:0:Y2:0:X1:X0:Y1:0:Cb0:0:Y0:0 1:1:8:2:8:2:8:2:1:1:8:2:8:2:8:2 little endian */
196*4882a593Smuzhiyun #define DRM_FORMAT_X0L0 fourcc_code('X', '0', 'L', '0')
197*4882a593Smuzhiyun
198*4882a593Smuzhiyun /* [63:0] A3:A2:Y3:Cr0:Y2:A1:A0:Y1:Cb0:Y0 1:1:10:10:10:1:1:10:10:10 little endian */
199*4882a593Smuzhiyun #define DRM_FORMAT_Y0L2 fourcc_code('Y', '0', 'L', '2')
200*4882a593Smuzhiyun /* [63:0] X3:X2:Y3:Cr0:Y2:X1:X0:Y1:Cb0:Y0 1:1:10:10:10:1:1:10:10:10 little endian */
201*4882a593Smuzhiyun #define DRM_FORMAT_X0L2 fourcc_code('X', '0', 'L', '2')
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun /*
204*4882a593Smuzhiyun * 1-plane YUV 4:2:0
205*4882a593Smuzhiyun * In these formats, the component ordering is specified (Y, followed by U
206*4882a593Smuzhiyun * then V), but the exact Linear layout is undefined.
207*4882a593Smuzhiyun * These formats can only be used with a non-Linear modifier.
208*4882a593Smuzhiyun */
209*4882a593Smuzhiyun #define DRM_FORMAT_YUV420_8BIT fourcc_code('Y', 'U', '0', '8')
210*4882a593Smuzhiyun #define DRM_FORMAT_YUV420_10BIT fourcc_code('Y', 'U', '1', '0')
211*4882a593Smuzhiyun
212*4882a593Smuzhiyun /*
213*4882a593Smuzhiyun * 2 plane RGB + A
214*4882a593Smuzhiyun * index 0 = RGB plane, same format as the corresponding non _A8 format has
215*4882a593Smuzhiyun * index 1 = A plane, [7:0] A
216*4882a593Smuzhiyun */
217*4882a593Smuzhiyun #define DRM_FORMAT_XRGB8888_A8 fourcc_code('X', 'R', 'A', '8')
218*4882a593Smuzhiyun #define DRM_FORMAT_XBGR8888_A8 fourcc_code('X', 'B', 'A', '8')
219*4882a593Smuzhiyun #define DRM_FORMAT_RGBX8888_A8 fourcc_code('R', 'X', 'A', '8')
220*4882a593Smuzhiyun #define DRM_FORMAT_BGRX8888_A8 fourcc_code('B', 'X', 'A', '8')
221*4882a593Smuzhiyun #define DRM_FORMAT_RGB888_A8 fourcc_code('R', '8', 'A', '8')
222*4882a593Smuzhiyun #define DRM_FORMAT_BGR888_A8 fourcc_code('B', '8', 'A', '8')
223*4882a593Smuzhiyun #define DRM_FORMAT_RGB565_A8 fourcc_code('R', '5', 'A', '8')
224*4882a593Smuzhiyun #define DRM_FORMAT_BGR565_A8 fourcc_code('B', '5', 'A', '8')
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun /*
227*4882a593Smuzhiyun * 2 plane YCbCr
228*4882a593Smuzhiyun * index 0 = Y plane, [7:0] Y
229*4882a593Smuzhiyun * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
230*4882a593Smuzhiyun * or
231*4882a593Smuzhiyun * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
232*4882a593Smuzhiyun */
233*4882a593Smuzhiyun #define DRM_FORMAT_NV12 fourcc_code('N', 'V', '1', '2') /* 2x2 subsampled Cr:Cb plane */
234*4882a593Smuzhiyun #define DRM_FORMAT_NV21 fourcc_code('N', 'V', '2', '1') /* 2x2 subsampled Cb:Cr plane */
235*4882a593Smuzhiyun #define DRM_FORMAT_NV16 fourcc_code('N', 'V', '1', '6') /* 2x1 subsampled Cr:Cb plane */
236*4882a593Smuzhiyun #define DRM_FORMAT_NV61 fourcc_code('N', 'V', '6', '1') /* 2x1 subsampled Cb:Cr plane */
237*4882a593Smuzhiyun #define DRM_FORMAT_NV24 fourcc_code('N', 'V', '2', '4') /* non-subsampled Cr:Cb plane */
238*4882a593Smuzhiyun #define DRM_FORMAT_NV42 fourcc_code('N', 'V', '4', '2') /* non-subsampled Cb:Cr plane */
239*4882a593Smuzhiyun /*
240*4882a593Smuzhiyun * 2 plane YCbCr
241*4882a593Smuzhiyun * index 0 = Y plane, [39:0] Y3:Y2:Y1:Y0 little endian
242*4882a593Smuzhiyun * index 1 = Cr:Cb plane, [39:0] Cr1:Cb1:Cr0:Cb0 little endian
243*4882a593Smuzhiyun */
244*4882a593Smuzhiyun #define DRM_FORMAT_NV15 fourcc_code('N', 'V', '1', '5') /* 2x2 subsampled Cr:Cb plane */
245*4882a593Smuzhiyun #define DRM_FORMAT_NV20 fourcc_code('N', 'V', '2', '0') /* 2x1 subsampled Cr:Cb plane */
246*4882a593Smuzhiyun #define DRM_FORMAT_NV30 fourcc_code('N', 'V', '3', '0') /* non-subsampled Cr:Cb plane */
247*4882a593Smuzhiyun
248*4882a593Smuzhiyun /*
249*4882a593Smuzhiyun * 2 plane YCbCr MSB aligned
250*4882a593Smuzhiyun * index 0 = Y plane, [15:0] Y:x [10:6] little endian
251*4882a593Smuzhiyun * index 1 = Cr:Cb plane, [31:0] Cr:x:Cb:x [10:6:10:6] little endian
252*4882a593Smuzhiyun */
253*4882a593Smuzhiyun #define DRM_FORMAT_P210 fourcc_code('P', '2', '1', '0') /* 2x1 subsampled Cr:Cb plane, 10 bit per channel */
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun /*
256*4882a593Smuzhiyun * 2 plane YCbCr MSB aligned
257*4882a593Smuzhiyun * index 0 = Y plane, [15:0] Y:x [10:6] little endian
258*4882a593Smuzhiyun * index 1 = Cr:Cb plane, [31:0] Cr:x:Cb:x [10:6:10:6] little endian
259*4882a593Smuzhiyun */
260*4882a593Smuzhiyun #define DRM_FORMAT_P010 fourcc_code('P', '0', '1', '0') /* 2x2 subsampled Cr:Cb plane 10 bits per channel */
261*4882a593Smuzhiyun
262*4882a593Smuzhiyun /*
263*4882a593Smuzhiyun * 2 plane YCbCr MSB aligned
264*4882a593Smuzhiyun * index 0 = Y plane, [15:0] Y:x [12:4] little endian
265*4882a593Smuzhiyun * index 1 = Cr:Cb plane, [31:0] Cr:x:Cb:x [12:4:12:4] little endian
266*4882a593Smuzhiyun */
267*4882a593Smuzhiyun #define DRM_FORMAT_P012 fourcc_code('P', '0', '1', '2') /* 2x2 subsampled Cr:Cb plane 12 bits per channel */
268*4882a593Smuzhiyun
269*4882a593Smuzhiyun /*
270*4882a593Smuzhiyun * 2 plane YCbCr MSB aligned
271*4882a593Smuzhiyun * index 0 = Y plane, [15:0] Y little endian
272*4882a593Smuzhiyun * index 1 = Cr:Cb plane, [31:0] Cr:Cb [16:16] little endian
273*4882a593Smuzhiyun */
274*4882a593Smuzhiyun #define DRM_FORMAT_P016 fourcc_code('P', '0', '1', '6') /* 2x2 subsampled Cr:Cb plane 16 bits per channel */
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun /* 3 plane non-subsampled (444) YCbCr
277*4882a593Smuzhiyun * 16 bits per component, but only 10 bits are used and 6 bits are padded
278*4882a593Smuzhiyun * index 0: Y plane, [15:0] Y:x [10:6] little endian
279*4882a593Smuzhiyun * index 1: Cb plane, [15:0] Cb:x [10:6] little endian
280*4882a593Smuzhiyun * index 2: Cr plane, [15:0] Cr:x [10:6] little endian
281*4882a593Smuzhiyun */
282*4882a593Smuzhiyun #define DRM_FORMAT_Q410 fourcc_code('Q', '4', '1', '0')
283*4882a593Smuzhiyun
284*4882a593Smuzhiyun /* 3 plane non-subsampled (444) YCrCb
285*4882a593Smuzhiyun * 16 bits per component, but only 10 bits are used and 6 bits are padded
286*4882a593Smuzhiyun * index 0: Y plane, [15:0] Y:x [10:6] little endian
287*4882a593Smuzhiyun * index 1: Cr plane, [15:0] Cr:x [10:6] little endian
288*4882a593Smuzhiyun * index 2: Cb plane, [15:0] Cb:x [10:6] little endian
289*4882a593Smuzhiyun */
290*4882a593Smuzhiyun #define DRM_FORMAT_Q401 fourcc_code('Q', '4', '0', '1')
291*4882a593Smuzhiyun
292*4882a593Smuzhiyun /*
293*4882a593Smuzhiyun * 3 plane YCbCr
294*4882a593Smuzhiyun * index 0: Y plane, [7:0] Y
295*4882a593Smuzhiyun * index 1: Cb plane, [7:0] Cb
296*4882a593Smuzhiyun * index 2: Cr plane, [7:0] Cr
297*4882a593Smuzhiyun * or
298*4882a593Smuzhiyun * index 1: Cr plane, [7:0] Cr
299*4882a593Smuzhiyun * index 2: Cb plane, [7:0] Cb
300*4882a593Smuzhiyun */
301*4882a593Smuzhiyun #define DRM_FORMAT_YUV410 fourcc_code('Y', 'U', 'V', '9') /* 4x4 subsampled Cb (1) and Cr (2) planes */
302*4882a593Smuzhiyun #define DRM_FORMAT_YVU410 fourcc_code('Y', 'V', 'U', '9') /* 4x4 subsampled Cr (1) and Cb (2) planes */
303*4882a593Smuzhiyun #define DRM_FORMAT_YUV411 fourcc_code('Y', 'U', '1', '1') /* 4x1 subsampled Cb (1) and Cr (2) planes */
304*4882a593Smuzhiyun #define DRM_FORMAT_YVU411 fourcc_code('Y', 'V', '1', '1') /* 4x1 subsampled Cr (1) and Cb (2) planes */
305*4882a593Smuzhiyun #define DRM_FORMAT_YUV420 fourcc_code('Y', 'U', '1', '2') /* 2x2 subsampled Cb (1) and Cr (2) planes */
306*4882a593Smuzhiyun #define DRM_FORMAT_YVU420 fourcc_code('Y', 'V', '1', '2') /* 2x2 subsampled Cr (1) and Cb (2) planes */
307*4882a593Smuzhiyun #define DRM_FORMAT_YUV422 fourcc_code('Y', 'U', '1', '6') /* 2x1 subsampled Cb (1) and Cr (2) planes */
308*4882a593Smuzhiyun #define DRM_FORMAT_YVU422 fourcc_code('Y', 'V', '1', '6') /* 2x1 subsampled Cr (1) and Cb (2) planes */
309*4882a593Smuzhiyun #define DRM_FORMAT_YUV444 fourcc_code('Y', 'U', '2', '4') /* non-subsampled Cb (1) and Cr (2) planes */
310*4882a593Smuzhiyun #define DRM_FORMAT_YVU444 fourcc_code('Y', 'V', '2', '4') /* non-subsampled Cr (1) and Cb (2) planes */
311*4882a593Smuzhiyun
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun /*
314*4882a593Smuzhiyun * Format Modifiers:
315*4882a593Smuzhiyun *
316*4882a593Smuzhiyun * Format modifiers describe, typically, a re-ordering or modification
317*4882a593Smuzhiyun * of the data in a plane of an FB. This can be used to express tiled/
318*4882a593Smuzhiyun * swizzled formats, or compression, or a combination of the two.
319*4882a593Smuzhiyun *
320*4882a593Smuzhiyun * The upper 8 bits of the format modifier are a vendor-id as assigned
321*4882a593Smuzhiyun * below. The lower 56 bits are assigned as vendor sees fit.
322*4882a593Smuzhiyun */
323*4882a593Smuzhiyun
324*4882a593Smuzhiyun /* Vendor Ids: */
325*4882a593Smuzhiyun #define DRM_FORMAT_MOD_NONE 0
326*4882a593Smuzhiyun #define DRM_FORMAT_MOD_VENDOR_NONE 0
327*4882a593Smuzhiyun #define DRM_FORMAT_MOD_VENDOR_INTEL 0x01
328*4882a593Smuzhiyun #define DRM_FORMAT_MOD_VENDOR_AMD 0x02
329*4882a593Smuzhiyun #define DRM_FORMAT_MOD_VENDOR_NVIDIA 0x03
330*4882a593Smuzhiyun #define DRM_FORMAT_MOD_VENDOR_SAMSUNG 0x04
331*4882a593Smuzhiyun #define DRM_FORMAT_MOD_VENDOR_QCOM 0x05
332*4882a593Smuzhiyun #define DRM_FORMAT_MOD_VENDOR_VIVANTE 0x06
333*4882a593Smuzhiyun #define DRM_FORMAT_MOD_VENDOR_BROADCOM 0x07
334*4882a593Smuzhiyun #define DRM_FORMAT_MOD_VENDOR_ARM 0x08
335*4882a593Smuzhiyun #define DRM_FORMAT_MOD_VENDOR_ALLWINNER 0x09
336*4882a593Smuzhiyun #define DRM_FORMAT_MOD_VENDOR_AMLOGIC 0x0a
337*4882a593Smuzhiyun #define DRM_FORMAT_MOD_VENDOR_ROCKCHIP 0x0b
338*4882a593Smuzhiyun
339*4882a593Smuzhiyun /* add more to the end as needed */
340*4882a593Smuzhiyun
341*4882a593Smuzhiyun #define DRM_FORMAT_RESERVED ((1ULL << 56) - 1)
342*4882a593Smuzhiyun
343*4882a593Smuzhiyun #define fourcc_mod_code(vendor, val) \
344*4882a593Smuzhiyun ((((__u64)DRM_FORMAT_MOD_VENDOR_## vendor) << 56) | ((val) & 0x00ffffffffffffffULL))
345*4882a593Smuzhiyun
346*4882a593Smuzhiyun /*
347*4882a593Smuzhiyun * Format Modifier tokens:
348*4882a593Smuzhiyun *
349*4882a593Smuzhiyun * When adding a new token please document the layout with a code comment,
350*4882a593Smuzhiyun * similar to the fourcc codes above. drm_fourcc.h is considered the
351*4882a593Smuzhiyun * authoritative source for all of these.
352*4882a593Smuzhiyun *
353*4882a593Smuzhiyun * Generic modifier names:
354*4882a593Smuzhiyun *
355*4882a593Smuzhiyun * DRM_FORMAT_MOD_GENERIC_* definitions are used to provide vendor-neutral names
356*4882a593Smuzhiyun * for layouts which are common across multiple vendors. To preserve
357*4882a593Smuzhiyun * compatibility, in cases where a vendor-specific definition already exists and
358*4882a593Smuzhiyun * a generic name for it is desired, the common name is a purely symbolic alias
359*4882a593Smuzhiyun * and must use the same numerical value as the original definition.
360*4882a593Smuzhiyun *
361*4882a593Smuzhiyun * Note that generic names should only be used for modifiers which describe
362*4882a593Smuzhiyun * generic layouts (such as pixel re-ordering), which may have
363*4882a593Smuzhiyun * independently-developed support across multiple vendors.
364*4882a593Smuzhiyun *
365*4882a593Smuzhiyun * In future cases where a generic layout is identified before merging with a
366*4882a593Smuzhiyun * vendor-specific modifier, a new 'GENERIC' vendor or modifier using vendor
367*4882a593Smuzhiyun * 'NONE' could be considered. This should only be for obvious, exceptional
368*4882a593Smuzhiyun * cases to avoid polluting the 'GENERIC' namespace with modifiers which only
369*4882a593Smuzhiyun * apply to a single vendor.
370*4882a593Smuzhiyun *
371*4882a593Smuzhiyun * Generic names should not be used for cases where multiple hardware vendors
372*4882a593Smuzhiyun * have implementations of the same standardised compression scheme (such as
373*4882a593Smuzhiyun * AFBC). In those cases, all implementations should use the same format
374*4882a593Smuzhiyun * modifier(s), reflecting the vendor of the standard.
375*4882a593Smuzhiyun */
376*4882a593Smuzhiyun
377*4882a593Smuzhiyun #define DRM_FORMAT_MOD_GENERIC_16_16_TILE DRM_FORMAT_MOD_SAMSUNG_16_16_TILE
378*4882a593Smuzhiyun
379*4882a593Smuzhiyun /*
380*4882a593Smuzhiyun * Invalid Modifier
381*4882a593Smuzhiyun *
382*4882a593Smuzhiyun * This modifier can be used as a sentinel to terminate the format modifiers
383*4882a593Smuzhiyun * list, or to initialize a variable with an invalid modifier. It might also be
384*4882a593Smuzhiyun * used to report an error back to userspace for certain APIs.
385*4882a593Smuzhiyun */
386*4882a593Smuzhiyun #define DRM_FORMAT_MOD_INVALID fourcc_mod_code(NONE, DRM_FORMAT_RESERVED)
387*4882a593Smuzhiyun
388*4882a593Smuzhiyun /*
389*4882a593Smuzhiyun * Linear Layout
390*4882a593Smuzhiyun *
391*4882a593Smuzhiyun * Just plain linear layout. Note that this is different from no specifying any
392*4882a593Smuzhiyun * modifier (e.g. not setting DRM_MODE_FB_MODIFIERS in the DRM_ADDFB2 ioctl),
393*4882a593Smuzhiyun * which tells the driver to also take driver-internal information into account
394*4882a593Smuzhiyun * and so might actually result in a tiled framebuffer.
395*4882a593Smuzhiyun */
396*4882a593Smuzhiyun #define DRM_FORMAT_MOD_LINEAR fourcc_mod_code(NONE, 0)
397*4882a593Smuzhiyun
398*4882a593Smuzhiyun /* Intel framebuffer modifiers */
399*4882a593Smuzhiyun
400*4882a593Smuzhiyun /*
401*4882a593Smuzhiyun * Intel X-tiling layout
402*4882a593Smuzhiyun *
403*4882a593Smuzhiyun * This is a tiled layout using 4Kb tiles (except on gen2 where the tiles 2Kb)
404*4882a593Smuzhiyun * in row-major layout. Within the tile bytes are laid out row-major, with
405*4882a593Smuzhiyun * a platform-dependent stride. On top of that the memory can apply
406*4882a593Smuzhiyun * platform-depending swizzling of some higher address bits into bit6.
407*4882a593Smuzhiyun *
408*4882a593Smuzhiyun * Note that this layout is only accurate on intel gen 8+ or valleyview chipsets.
409*4882a593Smuzhiyun * On earlier platforms the is highly platforms specific and not useful for
410*4882a593Smuzhiyun * cross-driver sharing. It exists since on a given platform it does uniquely
411*4882a593Smuzhiyun * identify the layout in a simple way for i915-specific userspace, which
412*4882a593Smuzhiyun * facilitated conversion of userspace to modifiers. Additionally the exact
413*4882a593Smuzhiyun * format on some really old platforms is not known.
414*4882a593Smuzhiyun */
415*4882a593Smuzhiyun #define I915_FORMAT_MOD_X_TILED fourcc_mod_code(INTEL, 1)
416*4882a593Smuzhiyun
417*4882a593Smuzhiyun /*
418*4882a593Smuzhiyun * Intel Y-tiling layout
419*4882a593Smuzhiyun *
420*4882a593Smuzhiyun * This is a tiled layout using 4Kb tiles (except on gen2 where the tiles 2Kb)
421*4882a593Smuzhiyun * in row-major layout. Within the tile bytes are laid out in OWORD (16 bytes)
422*4882a593Smuzhiyun * chunks column-major, with a platform-dependent height. On top of that the
423*4882a593Smuzhiyun * memory can apply platform-depending swizzling of some higher address bits
424*4882a593Smuzhiyun * into bit6.
425*4882a593Smuzhiyun *
426*4882a593Smuzhiyun * Note that this layout is only accurate on intel gen 8+ or valleyview chipsets.
427*4882a593Smuzhiyun * On earlier platforms the is highly platforms specific and not useful for
428*4882a593Smuzhiyun * cross-driver sharing. It exists since on a given platform it does uniquely
429*4882a593Smuzhiyun * identify the layout in a simple way for i915-specific userspace, which
430*4882a593Smuzhiyun * facilitated conversion of userspace to modifiers. Additionally the exact
431*4882a593Smuzhiyun * format on some really old platforms is not known.
432*4882a593Smuzhiyun */
433*4882a593Smuzhiyun #define I915_FORMAT_MOD_Y_TILED fourcc_mod_code(INTEL, 2)
434*4882a593Smuzhiyun
435*4882a593Smuzhiyun /*
436*4882a593Smuzhiyun * Intel Yf-tiling layout
437*4882a593Smuzhiyun *
438*4882a593Smuzhiyun * This is a tiled layout using 4Kb tiles in row-major layout.
439*4882a593Smuzhiyun * Within the tile pixels are laid out in 16 256 byte units / sub-tiles which
440*4882a593Smuzhiyun * are arranged in four groups (two wide, two high) with column-major layout.
441*4882a593Smuzhiyun * Each group therefore consits out of four 256 byte units, which are also laid
442*4882a593Smuzhiyun * out as 2x2 column-major.
443*4882a593Smuzhiyun * 256 byte units are made out of four 64 byte blocks of pixels, producing
444*4882a593Smuzhiyun * either a square block or a 2:1 unit.
445*4882a593Smuzhiyun * 64 byte blocks of pixels contain four pixel rows of 16 bytes, where the width
446*4882a593Smuzhiyun * in pixel depends on the pixel depth.
447*4882a593Smuzhiyun */
448*4882a593Smuzhiyun #define I915_FORMAT_MOD_Yf_TILED fourcc_mod_code(INTEL, 3)
449*4882a593Smuzhiyun
450*4882a593Smuzhiyun /*
451*4882a593Smuzhiyun * Intel color control surface (CCS) for render compression
452*4882a593Smuzhiyun *
453*4882a593Smuzhiyun * The framebuffer format must be one of the 8:8:8:8 RGB formats.
454*4882a593Smuzhiyun * The main surface will be plane index 0 and must be Y/Yf-tiled,
455*4882a593Smuzhiyun * the CCS will be plane index 1.
456*4882a593Smuzhiyun *
457*4882a593Smuzhiyun * Each CCS tile matches a 1024x512 pixel area of the main surface.
458*4882a593Smuzhiyun * To match certain aspects of the 3D hardware the CCS is
459*4882a593Smuzhiyun * considered to be made up of normal 128Bx32 Y tiles, Thus
460*4882a593Smuzhiyun * the CCS pitch must be specified in multiples of 128 bytes.
461*4882a593Smuzhiyun *
462*4882a593Smuzhiyun * In reality the CCS tile appears to be a 64Bx64 Y tile, composed
463*4882a593Smuzhiyun * of QWORD (8 bytes) chunks instead of OWORD (16 bytes) chunks.
464*4882a593Smuzhiyun * But that fact is not relevant unless the memory is accessed
465*4882a593Smuzhiyun * directly.
466*4882a593Smuzhiyun */
467*4882a593Smuzhiyun #define I915_FORMAT_MOD_Y_TILED_CCS fourcc_mod_code(INTEL, 4)
468*4882a593Smuzhiyun #define I915_FORMAT_MOD_Yf_TILED_CCS fourcc_mod_code(INTEL, 5)
469*4882a593Smuzhiyun
470*4882a593Smuzhiyun /*
471*4882a593Smuzhiyun * Intel color control surfaces (CCS) for Gen-12 render compression.
472*4882a593Smuzhiyun *
473*4882a593Smuzhiyun * The main surface is Y-tiled and at plane index 0, the CCS is linear and
474*4882a593Smuzhiyun * at index 1. A 64B CCS cache line corresponds to an area of 4x1 tiles in
475*4882a593Smuzhiyun * main surface. In other words, 4 bits in CCS map to a main surface cache
476*4882a593Smuzhiyun * line pair. The main surface pitch is required to be a multiple of four
477*4882a593Smuzhiyun * Y-tile widths.
478*4882a593Smuzhiyun */
479*4882a593Smuzhiyun #define I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS fourcc_mod_code(INTEL, 6)
480*4882a593Smuzhiyun
481*4882a593Smuzhiyun /*
482*4882a593Smuzhiyun * Intel color control surfaces (CCS) for Gen-12 media compression
483*4882a593Smuzhiyun *
484*4882a593Smuzhiyun * The main surface is Y-tiled and at plane index 0, the CCS is linear and
485*4882a593Smuzhiyun * at index 1. A 64B CCS cache line corresponds to an area of 4x1 tiles in
486*4882a593Smuzhiyun * main surface. In other words, 4 bits in CCS map to a main surface cache
487*4882a593Smuzhiyun * line pair. The main surface pitch is required to be a multiple of four
488*4882a593Smuzhiyun * Y-tile widths. For semi-planar formats like NV12, CCS planes follow the
489*4882a593Smuzhiyun * Y and UV planes i.e., planes 0 and 1 are used for Y and UV surfaces,
490*4882a593Smuzhiyun * planes 2 and 3 for the respective CCS.
491*4882a593Smuzhiyun */
492*4882a593Smuzhiyun #define I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS fourcc_mod_code(INTEL, 7)
493*4882a593Smuzhiyun
494*4882a593Smuzhiyun /*
495*4882a593Smuzhiyun * Tiled, NV12MT, grouped in 64 (pixels) x 32 (lines) -sized macroblocks
496*4882a593Smuzhiyun *
497*4882a593Smuzhiyun * Macroblocks are laid in a Z-shape, and each pixel data is following the
498*4882a593Smuzhiyun * standard NV12 style.
499*4882a593Smuzhiyun * As for NV12, an image is the result of two frame buffers: one for Y,
500*4882a593Smuzhiyun * one for the interleaved Cb/Cr components (1/2 the height of the Y buffer).
501*4882a593Smuzhiyun * Alignment requirements are (for each buffer):
502*4882a593Smuzhiyun * - multiple of 128 pixels for the width
503*4882a593Smuzhiyun * - multiple of 32 pixels for the height
504*4882a593Smuzhiyun *
505*4882a593Smuzhiyun * For more information: see https://linuxtv.org/downloads/v4l-dvb-apis/re32.html
506*4882a593Smuzhiyun */
507*4882a593Smuzhiyun #define DRM_FORMAT_MOD_SAMSUNG_64_32_TILE fourcc_mod_code(SAMSUNG, 1)
508*4882a593Smuzhiyun
509*4882a593Smuzhiyun /*
510*4882a593Smuzhiyun * Tiled, 16 (pixels) x 16 (lines) - sized macroblocks
511*4882a593Smuzhiyun *
512*4882a593Smuzhiyun * This is a simple tiled layout using tiles of 16x16 pixels in a row-major
513*4882a593Smuzhiyun * layout. For YCbCr formats Cb/Cr components are taken in such a way that
514*4882a593Smuzhiyun * they correspond to their 16x16 luma block.
515*4882a593Smuzhiyun */
516*4882a593Smuzhiyun #define DRM_FORMAT_MOD_SAMSUNG_16_16_TILE fourcc_mod_code(SAMSUNG, 2)
517*4882a593Smuzhiyun
518*4882a593Smuzhiyun /*
519*4882a593Smuzhiyun * Qualcomm Compressed Format
520*4882a593Smuzhiyun *
521*4882a593Smuzhiyun * Refers to a compressed variant of the base format that is compressed.
522*4882a593Smuzhiyun * Implementation may be platform and base-format specific.
523*4882a593Smuzhiyun *
524*4882a593Smuzhiyun * Each macrotile consists of m x n (mostly 4 x 4) tiles.
525*4882a593Smuzhiyun * Pixel data pitch/stride is aligned with macrotile width.
526*4882a593Smuzhiyun * Pixel data height is aligned with macrotile height.
527*4882a593Smuzhiyun * Entire pixel data buffer is aligned with 4k(bytes).
528*4882a593Smuzhiyun */
529*4882a593Smuzhiyun #define DRM_FORMAT_MOD_QCOM_COMPRESSED fourcc_mod_code(QCOM, 1)
530*4882a593Smuzhiyun
531*4882a593Smuzhiyun /* Vivante framebuffer modifiers */
532*4882a593Smuzhiyun
533*4882a593Smuzhiyun /*
534*4882a593Smuzhiyun * Vivante 4x4 tiling layout
535*4882a593Smuzhiyun *
536*4882a593Smuzhiyun * This is a simple tiled layout using tiles of 4x4 pixels in a row-major
537*4882a593Smuzhiyun * layout.
538*4882a593Smuzhiyun */
539*4882a593Smuzhiyun #define DRM_FORMAT_MOD_VIVANTE_TILED fourcc_mod_code(VIVANTE, 1)
540*4882a593Smuzhiyun
541*4882a593Smuzhiyun /*
542*4882a593Smuzhiyun * Vivante 64x64 super-tiling layout
543*4882a593Smuzhiyun *
544*4882a593Smuzhiyun * This is a tiled layout using 64x64 pixel super-tiles, where each super-tile
545*4882a593Smuzhiyun * contains 8x4 groups of 2x4 tiles of 4x4 pixels (like above) each, all in row-
546*4882a593Smuzhiyun * major layout.
547*4882a593Smuzhiyun *
548*4882a593Smuzhiyun * For more information: see
549*4882a593Smuzhiyun * https://github.com/etnaviv/etna_viv/blob/master/doc/hardware.md#texture-tiling
550*4882a593Smuzhiyun */
551*4882a593Smuzhiyun #define DRM_FORMAT_MOD_VIVANTE_SUPER_TILED fourcc_mod_code(VIVANTE, 2)
552*4882a593Smuzhiyun
553*4882a593Smuzhiyun /*
554*4882a593Smuzhiyun * Vivante 4x4 tiling layout for dual-pipe
555*4882a593Smuzhiyun *
556*4882a593Smuzhiyun * Same as the 4x4 tiling layout, except every second 4x4 pixel tile starts at a
557*4882a593Smuzhiyun * different base address. Offsets from the base addresses are therefore halved
558*4882a593Smuzhiyun * compared to the non-split tiled layout.
559*4882a593Smuzhiyun */
560*4882a593Smuzhiyun #define DRM_FORMAT_MOD_VIVANTE_SPLIT_TILED fourcc_mod_code(VIVANTE, 3)
561*4882a593Smuzhiyun
562*4882a593Smuzhiyun /*
563*4882a593Smuzhiyun * Vivante 64x64 super-tiling layout for dual-pipe
564*4882a593Smuzhiyun *
565*4882a593Smuzhiyun * Same as the 64x64 super-tiling layout, except every second 4x4 pixel tile
566*4882a593Smuzhiyun * starts at a different base address. Offsets from the base addresses are
567*4882a593Smuzhiyun * therefore halved compared to the non-split super-tiled layout.
568*4882a593Smuzhiyun */
569*4882a593Smuzhiyun #define DRM_FORMAT_MOD_VIVANTE_SPLIT_SUPER_TILED fourcc_mod_code(VIVANTE, 4)
570*4882a593Smuzhiyun
571*4882a593Smuzhiyun /* NVIDIA frame buffer modifiers */
572*4882a593Smuzhiyun
573*4882a593Smuzhiyun /*
574*4882a593Smuzhiyun * Tegra Tiled Layout, used by Tegra 2, 3 and 4.
575*4882a593Smuzhiyun *
576*4882a593Smuzhiyun * Pixels are arranged in simple tiles of 16 x 16 bytes.
577*4882a593Smuzhiyun */
578*4882a593Smuzhiyun #define DRM_FORMAT_MOD_NVIDIA_TEGRA_TILED fourcc_mod_code(NVIDIA, 1)
579*4882a593Smuzhiyun
580*4882a593Smuzhiyun /*
581*4882a593Smuzhiyun * Generalized Block Linear layout, used by desktop GPUs starting with NV50/G80,
582*4882a593Smuzhiyun * and Tegra GPUs starting with Tegra K1.
583*4882a593Smuzhiyun *
584*4882a593Smuzhiyun * Pixels are arranged in Groups of Bytes (GOBs). GOB size and layout varies
585*4882a593Smuzhiyun * based on the architecture generation. GOBs themselves are then arranged in
586*4882a593Smuzhiyun * 3D blocks, with the block dimensions (in terms of GOBs) always being a power
587*4882a593Smuzhiyun * of two, and hence expressible as their log2 equivalent (E.g., "2" represents
588*4882a593Smuzhiyun * a block depth or height of "4").
589*4882a593Smuzhiyun *
590*4882a593Smuzhiyun * Chapter 20 "Pixel Memory Formats" of the Tegra X1 TRM describes this format
591*4882a593Smuzhiyun * in full detail.
592*4882a593Smuzhiyun *
593*4882a593Smuzhiyun * Macro
594*4882a593Smuzhiyun * Bits Param Description
595*4882a593Smuzhiyun * ---- ----- -----------------------------------------------------------------
596*4882a593Smuzhiyun *
597*4882a593Smuzhiyun * 3:0 h log2(height) of each block, in GOBs. Placed here for
598*4882a593Smuzhiyun * compatibility with the existing
599*4882a593Smuzhiyun * DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK()-based modifiers.
600*4882a593Smuzhiyun *
601*4882a593Smuzhiyun * 4:4 - Must be 1, to indicate block-linear layout. Necessary for
602*4882a593Smuzhiyun * compatibility with the existing
603*4882a593Smuzhiyun * DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK()-based modifiers.
604*4882a593Smuzhiyun *
605*4882a593Smuzhiyun * 8:5 - Reserved (To support 3D-surfaces with variable log2(depth) block
606*4882a593Smuzhiyun * size). Must be zero.
607*4882a593Smuzhiyun *
608*4882a593Smuzhiyun * Note there is no log2(width) parameter. Some portions of the
609*4882a593Smuzhiyun * hardware support a block width of two gobs, but it is impractical
610*4882a593Smuzhiyun * to use due to lack of support elsewhere, and has no known
611*4882a593Smuzhiyun * benefits.
612*4882a593Smuzhiyun *
613*4882a593Smuzhiyun * 11:9 - Reserved (To support 2D-array textures with variable array stride
614*4882a593Smuzhiyun * in blocks, specified via log2(tile width in blocks)). Must be
615*4882a593Smuzhiyun * zero.
616*4882a593Smuzhiyun *
617*4882a593Smuzhiyun * 19:12 k Page Kind. This value directly maps to a field in the page
618*4882a593Smuzhiyun * tables of all GPUs >= NV50. It affects the exact layout of bits
619*4882a593Smuzhiyun * in memory and can be derived from the tuple
620*4882a593Smuzhiyun *
621*4882a593Smuzhiyun * (format, GPU model, compression type, samples per pixel)
622*4882a593Smuzhiyun *
623*4882a593Smuzhiyun * Where compression type is defined below. If GPU model were
624*4882a593Smuzhiyun * implied by the format modifier, format, or memory buffer, page
625*4882a593Smuzhiyun * kind would not need to be included in the modifier itself, but
626*4882a593Smuzhiyun * since the modifier should define the layout of the associated
627*4882a593Smuzhiyun * memory buffer independent from any device or other context, it
628*4882a593Smuzhiyun * must be included here.
629*4882a593Smuzhiyun *
630*4882a593Smuzhiyun * 21:20 g GOB Height and Page Kind Generation. The height of a GOB changed
631*4882a593Smuzhiyun * starting with Fermi GPUs. Additionally, the mapping between page
632*4882a593Smuzhiyun * kind and bit layout has changed at various points.
633*4882a593Smuzhiyun *
634*4882a593Smuzhiyun * 0 = Gob Height 8, Fermi - Volta, Tegra K1+ Page Kind mapping
635*4882a593Smuzhiyun * 1 = Gob Height 4, G80 - GT2XX Page Kind mapping
636*4882a593Smuzhiyun * 2 = Gob Height 8, Turing+ Page Kind mapping
637*4882a593Smuzhiyun * 3 = Reserved for future use.
638*4882a593Smuzhiyun *
639*4882a593Smuzhiyun * 22:22 s Sector layout. On Tegra GPUs prior to Xavier, there is a further
640*4882a593Smuzhiyun * bit remapping step that occurs at an even lower level than the
641*4882a593Smuzhiyun * page kind and block linear swizzles. This causes the layout of
642*4882a593Smuzhiyun * surfaces mapped in those SOC's GPUs to be incompatible with the
643*4882a593Smuzhiyun * equivalent mapping on other GPUs in the same system.
644*4882a593Smuzhiyun *
645*4882a593Smuzhiyun * 0 = Tegra K1 - Tegra Parker/TX2 Layout.
646*4882a593Smuzhiyun * 1 = Desktop GPU and Tegra Xavier+ Layout
647*4882a593Smuzhiyun *
648*4882a593Smuzhiyun * 25:23 c Lossless Framebuffer Compression type.
649*4882a593Smuzhiyun *
650*4882a593Smuzhiyun * 0 = none
651*4882a593Smuzhiyun * 1 = ROP/3D, layout 1, exact compression format implied by Page
652*4882a593Smuzhiyun * Kind field
653*4882a593Smuzhiyun * 2 = ROP/3D, layout 2, exact compression format implied by Page
654*4882a593Smuzhiyun * Kind field
655*4882a593Smuzhiyun * 3 = CDE horizontal
656*4882a593Smuzhiyun * 4 = CDE vertical
657*4882a593Smuzhiyun * 5 = Reserved for future use
658*4882a593Smuzhiyun * 6 = Reserved for future use
659*4882a593Smuzhiyun * 7 = Reserved for future use
660*4882a593Smuzhiyun *
661*4882a593Smuzhiyun * 55:25 - Reserved for future use. Must be zero.
662*4882a593Smuzhiyun */
663*4882a593Smuzhiyun #define DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(c, s, g, k, h) \
664*4882a593Smuzhiyun fourcc_mod_code(NVIDIA, (0x10 | \
665*4882a593Smuzhiyun ((h) & 0xf) | \
666*4882a593Smuzhiyun (((k) & 0xff) << 12) | \
667*4882a593Smuzhiyun (((g) & 0x3) << 20) | \
668*4882a593Smuzhiyun (((s) & 0x1) << 22) | \
669*4882a593Smuzhiyun (((c) & 0x7) << 23)))
670*4882a593Smuzhiyun
671*4882a593Smuzhiyun /* To grandfather in prior block linear format modifiers to the above layout,
672*4882a593Smuzhiyun * the page kind "0", which corresponds to "pitch/linear" and hence is unusable
673*4882a593Smuzhiyun * with block-linear layouts, is remapped within drivers to the value 0xfe,
674*4882a593Smuzhiyun * which corresponds to the "generic" kind used for simple single-sample
675*4882a593Smuzhiyun * uncompressed color formats on Fermi - Volta GPUs.
676*4882a593Smuzhiyun */
677*4882a593Smuzhiyun static inline __u64
drm_fourcc_canonicalize_nvidia_format_mod(__u64 modifier)678*4882a593Smuzhiyun drm_fourcc_canonicalize_nvidia_format_mod(__u64 modifier)
679*4882a593Smuzhiyun {
680*4882a593Smuzhiyun if (!(modifier & 0x10) || (modifier & (0xff << 12)))
681*4882a593Smuzhiyun return modifier;
682*4882a593Smuzhiyun else
683*4882a593Smuzhiyun return modifier | (0xfe << 12);
684*4882a593Smuzhiyun }
685*4882a593Smuzhiyun
686*4882a593Smuzhiyun /*
687*4882a593Smuzhiyun * 16Bx2 Block Linear layout, used by Tegra K1 and later
688*4882a593Smuzhiyun *
689*4882a593Smuzhiyun * Pixels are arranged in 64x8 Groups Of Bytes (GOBs). GOBs are then stacked
690*4882a593Smuzhiyun * vertically by a power of 2 (1 to 32 GOBs) to form a block.
691*4882a593Smuzhiyun *
692*4882a593Smuzhiyun * Within a GOB, data is ordered as 16B x 2 lines sectors laid in Z-shape.
693*4882a593Smuzhiyun *
694*4882a593Smuzhiyun * Parameter 'v' is the log2 encoding of the number of GOBs stacked vertically.
695*4882a593Smuzhiyun * Valid values are:
696*4882a593Smuzhiyun *
697*4882a593Smuzhiyun * 0 == ONE_GOB
698*4882a593Smuzhiyun * 1 == TWO_GOBS
699*4882a593Smuzhiyun * 2 == FOUR_GOBS
700*4882a593Smuzhiyun * 3 == EIGHT_GOBS
701*4882a593Smuzhiyun * 4 == SIXTEEN_GOBS
702*4882a593Smuzhiyun * 5 == THIRTYTWO_GOBS
703*4882a593Smuzhiyun *
704*4882a593Smuzhiyun * Chapter 20 "Pixel Memory Formats" of the Tegra X1 TRM describes this format
705*4882a593Smuzhiyun * in full detail.
706*4882a593Smuzhiyun */
707*4882a593Smuzhiyun #define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(v) \
708*4882a593Smuzhiyun DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 0, 0, 0, (v))
709*4882a593Smuzhiyun
710*4882a593Smuzhiyun #define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_ONE_GOB \
711*4882a593Smuzhiyun DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(0)
712*4882a593Smuzhiyun #define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_TWO_GOB \
713*4882a593Smuzhiyun DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(1)
714*4882a593Smuzhiyun #define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_FOUR_GOB \
715*4882a593Smuzhiyun DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(2)
716*4882a593Smuzhiyun #define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_EIGHT_GOB \
717*4882a593Smuzhiyun DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(3)
718*4882a593Smuzhiyun #define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_SIXTEEN_GOB \
719*4882a593Smuzhiyun DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(4)
720*4882a593Smuzhiyun #define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_THIRTYTWO_GOB \
721*4882a593Smuzhiyun DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(5)
722*4882a593Smuzhiyun
723*4882a593Smuzhiyun /*
724*4882a593Smuzhiyun * Some Broadcom modifiers take parameters, for example the number of
725*4882a593Smuzhiyun * vertical lines in the image. Reserve the lower 32 bits for modifier
726*4882a593Smuzhiyun * type, and the next 24 bits for parameters. Top 8 bits are the
727*4882a593Smuzhiyun * vendor code.
728*4882a593Smuzhiyun */
729*4882a593Smuzhiyun #define __fourcc_mod_broadcom_param_shift 8
730*4882a593Smuzhiyun #define __fourcc_mod_broadcom_param_bits 48
731*4882a593Smuzhiyun #define fourcc_mod_broadcom_code(val, params) \
732*4882a593Smuzhiyun fourcc_mod_code(BROADCOM, ((((__u64)params) << __fourcc_mod_broadcom_param_shift) | val))
733*4882a593Smuzhiyun #define fourcc_mod_broadcom_param(m) \
734*4882a593Smuzhiyun ((int)(((m) >> __fourcc_mod_broadcom_param_shift) & \
735*4882a593Smuzhiyun ((1ULL << __fourcc_mod_broadcom_param_bits) - 1)))
736*4882a593Smuzhiyun #define fourcc_mod_broadcom_mod(m) \
737*4882a593Smuzhiyun ((m) & ~(((1ULL << __fourcc_mod_broadcom_param_bits) - 1) << \
738*4882a593Smuzhiyun __fourcc_mod_broadcom_param_shift))
739*4882a593Smuzhiyun
740*4882a593Smuzhiyun /*
741*4882a593Smuzhiyun * Broadcom VC4 "T" format
742*4882a593Smuzhiyun *
743*4882a593Smuzhiyun * This is the primary layout that the V3D GPU can texture from (it
744*4882a593Smuzhiyun * can't do linear). The T format has:
745*4882a593Smuzhiyun *
746*4882a593Smuzhiyun * - 64b utiles of pixels in a raster-order grid according to cpp. It's 4x4
747*4882a593Smuzhiyun * pixels at 32 bit depth.
748*4882a593Smuzhiyun *
749*4882a593Smuzhiyun * - 1k subtiles made of a 4x4 raster-order grid of 64b utiles (so usually
750*4882a593Smuzhiyun * 16x16 pixels).
751*4882a593Smuzhiyun *
752*4882a593Smuzhiyun * - 4k tiles made of a 2x2 grid of 1k subtiles (so usually 32x32 pixels). On
753*4882a593Smuzhiyun * even 4k tile rows, they're arranged as (BL, TL, TR, BR), and on odd rows
754*4882a593Smuzhiyun * they're (TR, BR, BL, TL), where bottom left is start of memory.
755*4882a593Smuzhiyun *
756*4882a593Smuzhiyun * - an image made of 4k tiles in rows either left-to-right (even rows of 4k
757*4882a593Smuzhiyun * tiles) or right-to-left (odd rows of 4k tiles).
758*4882a593Smuzhiyun */
759*4882a593Smuzhiyun #define DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED fourcc_mod_code(BROADCOM, 1)
760*4882a593Smuzhiyun
761*4882a593Smuzhiyun /*
762*4882a593Smuzhiyun * Broadcom SAND format
763*4882a593Smuzhiyun *
764*4882a593Smuzhiyun * This is the native format that the H.264 codec block uses. For VC4
765*4882a593Smuzhiyun * HVS, it is only valid for H.264 (NV12/21) and RGBA modes.
766*4882a593Smuzhiyun *
767*4882a593Smuzhiyun * The image can be considered to be split into columns, and the
768*4882a593Smuzhiyun * columns are placed consecutively into memory. The width of those
769*4882a593Smuzhiyun * columns can be either 32, 64, 128, or 256 pixels, but in practice
770*4882a593Smuzhiyun * only 128 pixel columns are used.
771*4882a593Smuzhiyun *
772*4882a593Smuzhiyun * The pitch between the start of each column is set to optimally
773*4882a593Smuzhiyun * switch between SDRAM banks. This is passed as the number of lines
774*4882a593Smuzhiyun * of column width in the modifier (we can't use the stride value due
775*4882a593Smuzhiyun * to various core checks that look at it , so you should set the
776*4882a593Smuzhiyun * stride to width*cpp).
777*4882a593Smuzhiyun *
778*4882a593Smuzhiyun * Note that the column height for this format modifier is the same
779*4882a593Smuzhiyun * for all of the planes, assuming that each column contains both Y
780*4882a593Smuzhiyun * and UV. Some SAND-using hardware stores UV in a separate tiled
781*4882a593Smuzhiyun * image from Y to reduce the column height, which is not supported
782*4882a593Smuzhiyun * with these modifiers.
783*4882a593Smuzhiyun */
784*4882a593Smuzhiyun
785*4882a593Smuzhiyun #define DRM_FORMAT_MOD_BROADCOM_SAND32_COL_HEIGHT(v) \
786*4882a593Smuzhiyun fourcc_mod_broadcom_code(2, v)
787*4882a593Smuzhiyun #define DRM_FORMAT_MOD_BROADCOM_SAND64_COL_HEIGHT(v) \
788*4882a593Smuzhiyun fourcc_mod_broadcom_code(3, v)
789*4882a593Smuzhiyun #define DRM_FORMAT_MOD_BROADCOM_SAND128_COL_HEIGHT(v) \
790*4882a593Smuzhiyun fourcc_mod_broadcom_code(4, v)
791*4882a593Smuzhiyun #define DRM_FORMAT_MOD_BROADCOM_SAND256_COL_HEIGHT(v) \
792*4882a593Smuzhiyun fourcc_mod_broadcom_code(5, v)
793*4882a593Smuzhiyun
794*4882a593Smuzhiyun #define DRM_FORMAT_MOD_BROADCOM_SAND32 \
795*4882a593Smuzhiyun DRM_FORMAT_MOD_BROADCOM_SAND32_COL_HEIGHT(0)
796*4882a593Smuzhiyun #define DRM_FORMAT_MOD_BROADCOM_SAND64 \
797*4882a593Smuzhiyun DRM_FORMAT_MOD_BROADCOM_SAND64_COL_HEIGHT(0)
798*4882a593Smuzhiyun #define DRM_FORMAT_MOD_BROADCOM_SAND128 \
799*4882a593Smuzhiyun DRM_FORMAT_MOD_BROADCOM_SAND128_COL_HEIGHT(0)
800*4882a593Smuzhiyun #define DRM_FORMAT_MOD_BROADCOM_SAND256 \
801*4882a593Smuzhiyun DRM_FORMAT_MOD_BROADCOM_SAND256_COL_HEIGHT(0)
802*4882a593Smuzhiyun
803*4882a593Smuzhiyun /* Broadcom UIF format
804*4882a593Smuzhiyun *
805*4882a593Smuzhiyun * This is the common format for the current Broadcom multimedia
806*4882a593Smuzhiyun * blocks, including V3D 3.x and newer, newer video codecs, and
807*4882a593Smuzhiyun * displays.
808*4882a593Smuzhiyun *
809*4882a593Smuzhiyun * The image consists of utiles (64b blocks), UIF blocks (2x2 utiles),
810*4882a593Smuzhiyun * and macroblocks (4x4 UIF blocks). Those 4x4 UIF block groups are
811*4882a593Smuzhiyun * stored in columns, with padding between the columns to ensure that
812*4882a593Smuzhiyun * moving from one column to the next doesn't hit the same SDRAM page
813*4882a593Smuzhiyun * bank.
814*4882a593Smuzhiyun *
815*4882a593Smuzhiyun * To calculate the padding, it is assumed that each hardware block
816*4882a593Smuzhiyun * and the software driving it knows the platform's SDRAM page size,
817*4882a593Smuzhiyun * number of banks, and XOR address, and that it's identical between
818*4882a593Smuzhiyun * all blocks using the format. This tiling modifier will use XOR as
819*4882a593Smuzhiyun * necessary to reduce the padding. If a hardware block can't do XOR,
820*4882a593Smuzhiyun * the assumption is that a no-XOR tiling modifier will be created.
821*4882a593Smuzhiyun */
822*4882a593Smuzhiyun #define DRM_FORMAT_MOD_BROADCOM_UIF fourcc_mod_code(BROADCOM, 6)
823*4882a593Smuzhiyun
824*4882a593Smuzhiyun /*
825*4882a593Smuzhiyun * Arm Framebuffer Compression (AFBC) modifiers
826*4882a593Smuzhiyun *
827*4882a593Smuzhiyun * AFBC is a proprietary lossless image compression protocol and format.
828*4882a593Smuzhiyun * It provides fine-grained random access and minimizes the amount of data
829*4882a593Smuzhiyun * transferred between IP blocks.
830*4882a593Smuzhiyun *
831*4882a593Smuzhiyun * AFBC has several features which may be supported and/or used, which are
832*4882a593Smuzhiyun * represented using bits in the modifier. Not all combinations are valid,
833*4882a593Smuzhiyun * and different devices or use-cases may support different combinations.
834*4882a593Smuzhiyun *
835*4882a593Smuzhiyun * Further information on the use of AFBC modifiers can be found in
836*4882a593Smuzhiyun * Documentation/gpu/afbc.rst
837*4882a593Smuzhiyun */
838*4882a593Smuzhiyun
839*4882a593Smuzhiyun /*
840*4882a593Smuzhiyun * The top 4 bits (out of the 56 bits alloted for specifying vendor specific
841*4882a593Smuzhiyun * modifiers) denote the category for modifiers. Currently we have only two
842*4882a593Smuzhiyun * categories of modifiers ie AFBC and MISC. We can have a maximum of sixteen
843*4882a593Smuzhiyun * different categories.
844*4882a593Smuzhiyun */
845*4882a593Smuzhiyun #define DRM_FORMAT_MOD_ARM_CODE(__type, __val) \
846*4882a593Smuzhiyun fourcc_mod_code(ARM, ((__u64)(__type) << 52) | ((__val) & 0x000fffffffffffffULL))
847*4882a593Smuzhiyun
848*4882a593Smuzhiyun #define DRM_FORMAT_MOD_ARM_TYPE_AFBC 0x00
849*4882a593Smuzhiyun #define DRM_FORMAT_MOD_ARM_TYPE_MISC 0x01
850*4882a593Smuzhiyun
851*4882a593Smuzhiyun #define DRM_FORMAT_MOD_ARM_AFBC(__afbc_mode) \
852*4882a593Smuzhiyun DRM_FORMAT_MOD_ARM_CODE(DRM_FORMAT_MOD_ARM_TYPE_AFBC, __afbc_mode)
853*4882a593Smuzhiyun
854*4882a593Smuzhiyun /*
855*4882a593Smuzhiyun * AFBC superblock size
856*4882a593Smuzhiyun *
857*4882a593Smuzhiyun * Indicates the superblock size(s) used for the AFBC buffer. The buffer
858*4882a593Smuzhiyun * size (in pixels) must be aligned to a multiple of the superblock size.
859*4882a593Smuzhiyun * Four lowest significant bits(LSBs) are reserved for block size.
860*4882a593Smuzhiyun *
861*4882a593Smuzhiyun * Where one superblock size is specified, it applies to all planes of the
862*4882a593Smuzhiyun * buffer (e.g. 16x16, 32x8). When multiple superblock sizes are specified,
863*4882a593Smuzhiyun * the first applies to the Luma plane and the second applies to the Chroma
864*4882a593Smuzhiyun * plane(s). e.g. (32x8_64x4 means 32x8 Luma, with 64x4 Chroma).
865*4882a593Smuzhiyun * Multiple superblock sizes are only valid for multi-plane YCbCr formats.
866*4882a593Smuzhiyun */
867*4882a593Smuzhiyun #define AFBC_FORMAT_MOD_BLOCK_SIZE_MASK 0xf
868*4882a593Smuzhiyun #define AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 (1ULL)
869*4882a593Smuzhiyun #define AFBC_FORMAT_MOD_BLOCK_SIZE_32x8 (2ULL)
870*4882a593Smuzhiyun #define AFBC_FORMAT_MOD_BLOCK_SIZE_64x4 (3ULL)
871*4882a593Smuzhiyun #define AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4 (4ULL)
872*4882a593Smuzhiyun
873*4882a593Smuzhiyun /*
874*4882a593Smuzhiyun * AFBC lossless colorspace transform
875*4882a593Smuzhiyun *
876*4882a593Smuzhiyun * Indicates that the buffer makes use of the AFBC lossless colorspace
877*4882a593Smuzhiyun * transform.
878*4882a593Smuzhiyun */
879*4882a593Smuzhiyun #define AFBC_FORMAT_MOD_YTR (1ULL << 4)
880*4882a593Smuzhiyun
881*4882a593Smuzhiyun /*
882*4882a593Smuzhiyun * AFBC block-split
883*4882a593Smuzhiyun *
884*4882a593Smuzhiyun * Indicates that the payload of each superblock is split. The second
885*4882a593Smuzhiyun * half of the payload is positioned at a predefined offset from the start
886*4882a593Smuzhiyun * of the superblock payload.
887*4882a593Smuzhiyun */
888*4882a593Smuzhiyun #define AFBC_FORMAT_MOD_SPLIT (1ULL << 5)
889*4882a593Smuzhiyun
890*4882a593Smuzhiyun /*
891*4882a593Smuzhiyun * AFBC sparse layout
892*4882a593Smuzhiyun *
893*4882a593Smuzhiyun * This flag indicates that the payload of each superblock must be stored at a
894*4882a593Smuzhiyun * predefined position relative to the other superblocks in the same AFBC
895*4882a593Smuzhiyun * buffer. This order is the same order used by the header buffer. In this mode
896*4882a593Smuzhiyun * each superblock is given the same amount of space as an uncompressed
897*4882a593Smuzhiyun * superblock of the particular format would require, rounding up to the next
898*4882a593Smuzhiyun * multiple of 128 bytes in size.
899*4882a593Smuzhiyun */
900*4882a593Smuzhiyun #define AFBC_FORMAT_MOD_SPARSE (1ULL << 6)
901*4882a593Smuzhiyun
902*4882a593Smuzhiyun /*
903*4882a593Smuzhiyun * AFBC copy-block restrict
904*4882a593Smuzhiyun *
905*4882a593Smuzhiyun * Buffers with this flag must obey the copy-block restriction. The restriction
906*4882a593Smuzhiyun * is such that there are no copy-blocks referring across the border of 8x8
907*4882a593Smuzhiyun * blocks. For the subsampled data the 8x8 limitation is also subsampled.
908*4882a593Smuzhiyun */
909*4882a593Smuzhiyun #define AFBC_FORMAT_MOD_CBR (1ULL << 7)
910*4882a593Smuzhiyun
911*4882a593Smuzhiyun /*
912*4882a593Smuzhiyun * AFBC tiled layout
913*4882a593Smuzhiyun *
914*4882a593Smuzhiyun * The tiled layout groups superblocks in 8x8 or 4x4 tiles, where all
915*4882a593Smuzhiyun * superblocks inside a tile are stored together in memory. 8x8 tiles are used
916*4882a593Smuzhiyun * for pixel formats up to and including 32 bpp while 4x4 tiles are used for
917*4882a593Smuzhiyun * larger bpp formats. The order between the tiles is scan line.
918*4882a593Smuzhiyun * When the tiled layout is used, the buffer size (in pixels) must be aligned
919*4882a593Smuzhiyun * to the tile size.
920*4882a593Smuzhiyun */
921*4882a593Smuzhiyun #define AFBC_FORMAT_MOD_TILED (1ULL << 8)
922*4882a593Smuzhiyun
923*4882a593Smuzhiyun /*
924*4882a593Smuzhiyun * AFBC solid color blocks
925*4882a593Smuzhiyun *
926*4882a593Smuzhiyun * Indicates that the buffer makes use of solid-color blocks, whereby bandwidth
927*4882a593Smuzhiyun * can be reduced if a whole superblock is a single color.
928*4882a593Smuzhiyun */
929*4882a593Smuzhiyun #define AFBC_FORMAT_MOD_SC (1ULL << 9)
930*4882a593Smuzhiyun
931*4882a593Smuzhiyun /*
932*4882a593Smuzhiyun * AFBC double-buffer
933*4882a593Smuzhiyun *
934*4882a593Smuzhiyun * Indicates that the buffer is allocated in a layout safe for front-buffer
935*4882a593Smuzhiyun * rendering.
936*4882a593Smuzhiyun */
937*4882a593Smuzhiyun #define AFBC_FORMAT_MOD_DB (1ULL << 10)
938*4882a593Smuzhiyun
939*4882a593Smuzhiyun /*
940*4882a593Smuzhiyun * AFBC buffer content hints
941*4882a593Smuzhiyun *
942*4882a593Smuzhiyun * Indicates that the buffer includes per-superblock content hints.
943*4882a593Smuzhiyun */
944*4882a593Smuzhiyun #define AFBC_FORMAT_MOD_BCH (1ULL << 11)
945*4882a593Smuzhiyun
946*4882a593Smuzhiyun /* AFBC uncompressed storage mode
947*4882a593Smuzhiyun *
948*4882a593Smuzhiyun * Indicates that the buffer is using AFBC uncompressed storage mode.
949*4882a593Smuzhiyun * In this mode all superblock payloads in the buffer use the uncompressed
950*4882a593Smuzhiyun * storage mode, which is usually only used for data which cannot be compressed.
951*4882a593Smuzhiyun * The buffer layout is the same as for AFBC buffers without USM set, this only
952*4882a593Smuzhiyun * affects the storage mode of the individual superblocks. Note that even a
953*4882a593Smuzhiyun * buffer without USM set may use uncompressed storage mode for some or all
954*4882a593Smuzhiyun * superblocks, USM just guarantees it for all.
955*4882a593Smuzhiyun */
956*4882a593Smuzhiyun #define AFBC_FORMAT_MOD_USM (1ULL << 12)
957*4882a593Smuzhiyun
958*4882a593Smuzhiyun /*
959*4882a593Smuzhiyun * Arm 16x16 Block U-Interleaved modifier
960*4882a593Smuzhiyun *
961*4882a593Smuzhiyun * This is used by Arm Mali Utgard and Midgard GPUs. It divides the image
962*4882a593Smuzhiyun * into 16x16 pixel blocks. Blocks are stored linearly in order, but pixels
963*4882a593Smuzhiyun * in the block are reordered.
964*4882a593Smuzhiyun */
965*4882a593Smuzhiyun #define DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED \
966*4882a593Smuzhiyun DRM_FORMAT_MOD_ARM_CODE(DRM_FORMAT_MOD_ARM_TYPE_MISC, 1ULL)
967*4882a593Smuzhiyun
968*4882a593Smuzhiyun /*
969*4882a593Smuzhiyun * Allwinner tiled modifier
970*4882a593Smuzhiyun *
971*4882a593Smuzhiyun * This tiling mode is implemented by the VPU found on all Allwinner platforms,
972*4882a593Smuzhiyun * codenamed sunxi. It is associated with a YUV format that uses either 2 or 3
973*4882a593Smuzhiyun * planes.
974*4882a593Smuzhiyun *
975*4882a593Smuzhiyun * With this tiling, the luminance samples are disposed in tiles representing
976*4882a593Smuzhiyun * 32x32 pixels and the chrominance samples in tiles representing 32x64 pixels.
977*4882a593Smuzhiyun * The pixel order in each tile is linear and the tiles are disposed linearly,
978*4882a593Smuzhiyun * both in row-major order.
979*4882a593Smuzhiyun */
980*4882a593Smuzhiyun #define DRM_FORMAT_MOD_ALLWINNER_TILED fourcc_mod_code(ALLWINNER, 1)
981*4882a593Smuzhiyun
982*4882a593Smuzhiyun /*
983*4882a593Smuzhiyun * Amlogic Video Framebuffer Compression modifiers
984*4882a593Smuzhiyun *
985*4882a593Smuzhiyun * Amlogic uses a proprietary lossless image compression protocol and format
986*4882a593Smuzhiyun * for their hardware video codec accelerators, either video decoders or
987*4882a593Smuzhiyun * video input encoders.
988*4882a593Smuzhiyun *
989*4882a593Smuzhiyun * It considerably reduces memory bandwidth while writing and reading
990*4882a593Smuzhiyun * frames in memory.
991*4882a593Smuzhiyun *
992*4882a593Smuzhiyun * The underlying storage is considered to be 3 components, 8bit or 10-bit
993*4882a593Smuzhiyun * per component YCbCr 420, single plane :
994*4882a593Smuzhiyun * - DRM_FORMAT_YUV420_8BIT
995*4882a593Smuzhiyun * - DRM_FORMAT_YUV420_10BIT
996*4882a593Smuzhiyun *
997*4882a593Smuzhiyun * The first 8 bits of the mode defines the layout, then the following 8 bits
998*4882a593Smuzhiyun * defines the options changing the layout.
999*4882a593Smuzhiyun *
1000*4882a593Smuzhiyun * Not all combinations are valid, and different SoCs may support different
1001*4882a593Smuzhiyun * combinations of layout and options.
1002*4882a593Smuzhiyun */
1003*4882a593Smuzhiyun #define __fourcc_mod_amlogic_layout_mask 0xff
1004*4882a593Smuzhiyun #define __fourcc_mod_amlogic_options_shift 8
1005*4882a593Smuzhiyun #define __fourcc_mod_amlogic_options_mask 0xff
1006*4882a593Smuzhiyun
1007*4882a593Smuzhiyun #define DRM_FORMAT_MOD_AMLOGIC_FBC(__layout, __options) \
1008*4882a593Smuzhiyun fourcc_mod_code(AMLOGIC, \
1009*4882a593Smuzhiyun ((__layout) & __fourcc_mod_amlogic_layout_mask) | \
1010*4882a593Smuzhiyun (((__options) & __fourcc_mod_amlogic_options_mask) \
1011*4882a593Smuzhiyun << __fourcc_mod_amlogic_options_shift))
1012*4882a593Smuzhiyun
1013*4882a593Smuzhiyun /* Amlogic FBC Layouts */
1014*4882a593Smuzhiyun
1015*4882a593Smuzhiyun /*
1016*4882a593Smuzhiyun * Amlogic FBC Basic Layout
1017*4882a593Smuzhiyun *
1018*4882a593Smuzhiyun * The basic layout is composed of:
1019*4882a593Smuzhiyun * - a body content organized in 64x32 superblocks with 4096 bytes per
1020*4882a593Smuzhiyun * superblock in default mode.
1021*4882a593Smuzhiyun * - a 32 bytes per 128x64 header block
1022*4882a593Smuzhiyun *
1023*4882a593Smuzhiyun * This layout is transferrable between Amlogic SoCs supporting this modifier.
1024*4882a593Smuzhiyun */
1025*4882a593Smuzhiyun #define AMLOGIC_FBC_LAYOUT_BASIC (1ULL)
1026*4882a593Smuzhiyun
1027*4882a593Smuzhiyun /*
1028*4882a593Smuzhiyun * Amlogic FBC Scatter Memory layout
1029*4882a593Smuzhiyun *
1030*4882a593Smuzhiyun * Indicates the header contains IOMMU references to the compressed
1031*4882a593Smuzhiyun * frames content to optimize memory access and layout.
1032*4882a593Smuzhiyun *
1033*4882a593Smuzhiyun * In this mode, only the header memory address is needed, thus the
1034*4882a593Smuzhiyun * content memory organization is tied to the current producer
1035*4882a593Smuzhiyun * execution and cannot be saved/dumped neither transferrable between
1036*4882a593Smuzhiyun * Amlogic SoCs supporting this modifier.
1037*4882a593Smuzhiyun *
1038*4882a593Smuzhiyun * Due to the nature of the layout, these buffers are not expected to
1039*4882a593Smuzhiyun * be accessible by the user-space clients, but only accessible by the
1040*4882a593Smuzhiyun * hardware producers and consumers.
1041*4882a593Smuzhiyun *
1042*4882a593Smuzhiyun * The user-space clients should expect a failure while trying to mmap
1043*4882a593Smuzhiyun * the DMA-BUF handle returned by the producer.
1044*4882a593Smuzhiyun */
1045*4882a593Smuzhiyun #define AMLOGIC_FBC_LAYOUT_SCATTER (2ULL)
1046*4882a593Smuzhiyun
1047*4882a593Smuzhiyun /* Amlogic FBC Layout Options Bit Mask */
1048*4882a593Smuzhiyun
1049*4882a593Smuzhiyun /*
1050*4882a593Smuzhiyun * Amlogic FBC Memory Saving mode
1051*4882a593Smuzhiyun *
1052*4882a593Smuzhiyun * Indicates the storage is packed when pixel size is multiple of word
1053*4882a593Smuzhiyun * boudaries, i.e. 8bit should be stored in this mode to save allocation
1054*4882a593Smuzhiyun * memory.
1055*4882a593Smuzhiyun *
1056*4882a593Smuzhiyun * This mode reduces body layout to 3072 bytes per 64x32 superblock with
1057*4882a593Smuzhiyun * the basic layout and 3200 bytes per 64x32 superblock combined with
1058*4882a593Smuzhiyun * the scatter layout.
1059*4882a593Smuzhiyun */
1060*4882a593Smuzhiyun #define AMLOGIC_FBC_OPTION_MEM_SAVING (1ULL << 0)
1061*4882a593Smuzhiyun
1062*4882a593Smuzhiyun #define ROCKCHIP_TILED_BLOCK_SIZE_MASK 0xf
1063*4882a593Smuzhiyun #define ROCKCHIP_TILED_BLOCK_SIZE_8x8 (1ULL)
1064*4882a593Smuzhiyun #define ROCKCHIP_TILED_BLOCK_SIZE_4x4_MODE0 (2ULL)
1065*4882a593Smuzhiyun #define ROCKCHIP_TILED_BLOCK_SIZE_4x4_MODE1 (3ULL)
1066*4882a593Smuzhiyun
1067*4882a593Smuzhiyun #define DRM_FORMAT_MOD_ROCKCHIP_TILED(_mode) fourcc_mod_code(ROCKCHIP, _mode)
1068*4882a593Smuzhiyun
1069*4882a593Smuzhiyun #define IS_ROCKCHIP_TILED_MOD(val) (((val) >> 56) == DRM_FORMAT_MOD_VENDOR_ROCKCHIP)
1070*4882a593Smuzhiyun
1071*4882a593Smuzhiyun #if defined(__cplusplus)
1072*4882a593Smuzhiyun }
1073*4882a593Smuzhiyun #endif
1074*4882a593Smuzhiyun
1075*4882a593Smuzhiyun #endif /* DRM_FOURCC_H */
1076