18e8ee850SGerd Hoffmann /*
28e8ee850SGerd Hoffmann  * Copyright 2011 Intel Corporation
38e8ee850SGerd Hoffmann  *
48e8ee850SGerd Hoffmann  * Permission is hereby granted, free of charge, to any person obtaining a
58e8ee850SGerd Hoffmann  * copy of this software and associated documentation files (the "Software"),
68e8ee850SGerd Hoffmann  * to deal in the Software without restriction, including without limitation
78e8ee850SGerd Hoffmann  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
88e8ee850SGerd Hoffmann  * and/or sell copies of the Software, and to permit persons to whom the
98e8ee850SGerd Hoffmann  * Software is furnished to do so, subject to the following conditions:
108e8ee850SGerd Hoffmann  *
118e8ee850SGerd Hoffmann  * The above copyright notice and this permission notice (including the next
128e8ee850SGerd Hoffmann  * paragraph) shall be included in all copies or substantial portions of the
138e8ee850SGerd Hoffmann  * Software.
148e8ee850SGerd Hoffmann  *
158e8ee850SGerd Hoffmann  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
168e8ee850SGerd Hoffmann  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
178e8ee850SGerd Hoffmann  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
188e8ee850SGerd Hoffmann  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
198e8ee850SGerd Hoffmann  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
208e8ee850SGerd Hoffmann  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
218e8ee850SGerd Hoffmann  * OTHER DEALINGS IN THE SOFTWARE.
228e8ee850SGerd Hoffmann  */
238e8ee850SGerd Hoffmann 
248e8ee850SGerd Hoffmann #ifndef DRM_FOURCC_H
258e8ee850SGerd Hoffmann #define DRM_FOURCC_H
268e8ee850SGerd Hoffmann 
278e8ee850SGerd Hoffmann 
288e8ee850SGerd Hoffmann #if defined(__cplusplus)
298e8ee850SGerd Hoffmann extern "C" {
308e8ee850SGerd Hoffmann #endif
318e8ee850SGerd Hoffmann 
32da054c64SPaolo Bonzini /**
33da054c64SPaolo Bonzini  * DOC: overview
34da054c64SPaolo Bonzini  *
35da054c64SPaolo Bonzini  * In the DRM subsystem, framebuffer pixel formats are described using the
36da054c64SPaolo Bonzini  * fourcc codes defined in `include/uapi/drm/drm_fourcc.h`. In addition to the
37da054c64SPaolo Bonzini  * fourcc code, a Format Modifier may optionally be provided, in order to
38da054c64SPaolo Bonzini  * further describe the buffer's format - for example tiling or compression.
39da054c64SPaolo Bonzini  *
40da054c64SPaolo Bonzini  * Format Modifiers
41da054c64SPaolo Bonzini  * ----------------
42da054c64SPaolo Bonzini  *
43da054c64SPaolo Bonzini  * Format modifiers are used in conjunction with a fourcc code, forming a
44da054c64SPaolo Bonzini  * unique fourcc:modifier pair. This format:modifier pair must fully define the
45da054c64SPaolo Bonzini  * format and data layout of the buffer, and should be the only way to describe
46da054c64SPaolo Bonzini  * that particular buffer.
47da054c64SPaolo Bonzini  *
48da054c64SPaolo Bonzini  * Having multiple fourcc:modifier pairs which describe the same layout should
49da054c64SPaolo Bonzini  * be avoided, as such aliases run the risk of different drivers exposing
50da054c64SPaolo Bonzini  * different names for the same data format, forcing userspace to understand
51da054c64SPaolo Bonzini  * that they are aliases.
52da054c64SPaolo Bonzini  *
53da054c64SPaolo Bonzini  * Format modifiers may change any property of the buffer, including the number
54da054c64SPaolo Bonzini  * of planes and/or the required allocation size. Format modifiers are
55da054c64SPaolo Bonzini  * vendor-namespaced, and as such the relationship between a fourcc code and a
56*6a02465fSDaniel Henrique Barboza  * modifier is specific to the modifier being used. For example, some modifiers
57da054c64SPaolo Bonzini  * may preserve meaning - such as number of planes - from the fourcc code,
58da054c64SPaolo Bonzini  * whereas others may not.
59da054c64SPaolo Bonzini  *
60b3c818a4SEric Farman  * Modifiers must uniquely encode buffer layout. In other words, a buffer must
61b3c818a4SEric Farman  * match only a single modifier. A modifier must not be a subset of layouts of
62b3c818a4SEric Farman  * another modifier. For instance, it's incorrect to encode pitch alignment in
63b3c818a4SEric Farman  * a modifier: a buffer may match a 64-pixel aligned modifier and a 32-pixel
64b3c818a4SEric Farman  * aligned modifier. That said, modifiers can have implicit minimal
65b3c818a4SEric Farman  * requirements.
66b3c818a4SEric Farman  *
67b3c818a4SEric Farman  * For modifiers where the combination of fourcc code and modifier can alias,
68b3c818a4SEric Farman  * a canonical pair needs to be defined and used by all drivers. Preferred
69b3c818a4SEric Farman  * combinations are also encouraged where all combinations might lead to
70b3c818a4SEric Farman  * confusion and unnecessarily reduced interoperability. An example for the
71b3c818a4SEric Farman  * latter is AFBC, where the ABGR layouts are preferred over ARGB layouts.
72b3c818a4SEric Farman  *
73b3c818a4SEric Farman  * There are two kinds of modifier users:
74b3c818a4SEric Farman  *
75b3c818a4SEric Farman  * - Kernel and user-space drivers: for drivers it's important that modifiers
76b3c818a4SEric Farman  *   don't alias, otherwise two drivers might support the same format but use
77b3c818a4SEric Farman  *   different aliases, preventing them from sharing buffers in an efficient
78b3c818a4SEric Farman  *   format.
79b3c818a4SEric Farman  * - Higher-level programs interfacing with KMS/GBM/EGL/Vulkan/etc: these users
80b3c818a4SEric Farman  *   see modifiers as opaque tokens they can check for equality and intersect.
81*6a02465fSDaniel Henrique Barboza  *   These users mustn't need to know to reason about the modifier value
82b3c818a4SEric Farman  *   (i.e. they are not expected to extract information out of the modifier).
83b3c818a4SEric Farman  *
84da054c64SPaolo Bonzini  * Vendors should document their modifier usage in as much detail as
85da054c64SPaolo Bonzini  * possible, to ensure maximum compatibility across devices, drivers and
86da054c64SPaolo Bonzini  * applications.
87da054c64SPaolo Bonzini  *
88da054c64SPaolo Bonzini  * The authoritative list of format modifier codes is found in
89da054c64SPaolo Bonzini  * `include/uapi/drm/drm_fourcc.h`
90c5c0fdbeSDavid 'Digit' Turner  *
91c5c0fdbeSDavid 'Digit' Turner  * Open Source User Waiver
92c5c0fdbeSDavid 'Digit' Turner  * -----------------------
93c5c0fdbeSDavid 'Digit' Turner  *
94c5c0fdbeSDavid 'Digit' Turner  * Because this is the authoritative source for pixel formats and modifiers
95c5c0fdbeSDavid 'Digit' Turner  * referenced by GL, Vulkan extensions and other standards and hence used both
96c5c0fdbeSDavid 'Digit' Turner  * by open source and closed source driver stacks, the usual requirement for an
97c5c0fdbeSDavid 'Digit' Turner  * upstream in-kernel or open source userspace user does not apply.
98c5c0fdbeSDavid 'Digit' Turner  *
99c5c0fdbeSDavid 'Digit' Turner  * To ensure, as much as feasible, compatibility across stacks and avoid
100c5c0fdbeSDavid 'Digit' Turner  * confusion with incompatible enumerations stakeholders for all relevant driver
101c5c0fdbeSDavid 'Digit' Turner  * stacks should approve additions.
102da054c64SPaolo Bonzini  */
103da054c64SPaolo Bonzini 
1048e8ee850SGerd Hoffmann #define fourcc_code(a, b, c, d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \
1058e8ee850SGerd Hoffmann 				 ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
1068e8ee850SGerd Hoffmann 
10750fd0c37SBharata B Rao #define DRM_FORMAT_BIG_ENDIAN (1U<<31) /* format is big endian instead of little endian */
1088e8ee850SGerd Hoffmann 
109da054c64SPaolo Bonzini /* Reserve 0 for the invalid format specifier */
110da054c64SPaolo Bonzini #define DRM_FORMAT_INVALID	0
111da054c64SPaolo Bonzini 
1128e8ee850SGerd Hoffmann /* color index */
11393e0932bSPeter Xu #define DRM_FORMAT_C1		fourcc_code('C', '1', ' ', ' ') /* [7:0] C0:C1:C2:C3:C4:C5:C6:C7 1:1:1:1:1:1:1:1 eight pixels/byte */
11493e0932bSPeter Xu #define DRM_FORMAT_C2		fourcc_code('C', '2', ' ', ' ') /* [7:0] C0:C1:C2:C3 2:2:2:2 four pixels/byte */
11593e0932bSPeter Xu #define DRM_FORMAT_C4		fourcc_code('C', '4', ' ', ' ') /* [7:0] C0:C1 4:4 two pixels/byte */
1168e8ee850SGerd Hoffmann #define DRM_FORMAT_C8		fourcc_code('C', '8', ' ', ' ') /* [7:0] C */
1178e8ee850SGerd Hoffmann 
11893e0932bSPeter Xu /* 1 bpp Darkness (inverse relationship between channel value and brightness) */
11993e0932bSPeter Xu #define DRM_FORMAT_D1		fourcc_code('D', '1', ' ', ' ') /* [7:0] D0:D1:D2:D3:D4:D5:D6:D7 1:1:1:1:1:1:1:1 eight pixels/byte */
12093e0932bSPeter Xu 
12193e0932bSPeter Xu /* 2 bpp Darkness (inverse relationship between channel value and brightness) */
12293e0932bSPeter Xu #define DRM_FORMAT_D2		fourcc_code('D', '2', ' ', ' ') /* [7:0] D0:D1:D2:D3 2:2:2:2 four pixels/byte */
12393e0932bSPeter Xu 
12493e0932bSPeter Xu /* 4 bpp Darkness (inverse relationship between channel value and brightness) */
12593e0932bSPeter Xu #define DRM_FORMAT_D4		fourcc_code('D', '4', ' ', ' ') /* [7:0] D0:D1 4:4 two pixels/byte */
12693e0932bSPeter Xu 
12793e0932bSPeter Xu /* 8 bpp Darkness (inverse relationship between channel value and brightness) */
12893e0932bSPeter Xu #define DRM_FORMAT_D8		fourcc_code('D', '8', ' ', ' ') /* [7:0] D */
12993e0932bSPeter Xu 
13093e0932bSPeter Xu /* 1 bpp Red (direct relationship between channel value and brightness) */
13193e0932bSPeter Xu #define DRM_FORMAT_R1		fourcc_code('R', '1', ' ', ' ') /* [7:0] R0:R1:R2:R3:R4:R5:R6:R7 1:1:1:1:1:1:1:1 eight pixels/byte */
13293e0932bSPeter Xu 
13393e0932bSPeter Xu /* 2 bpp Red (direct relationship between channel value and brightness) */
13493e0932bSPeter Xu #define DRM_FORMAT_R2		fourcc_code('R', '2', ' ', ' ') /* [7:0] R0:R1:R2:R3 2:2:2:2 four pixels/byte */
13593e0932bSPeter Xu 
13693e0932bSPeter Xu /* 4 bpp Red (direct relationship between channel value and brightness) */
13793e0932bSPeter Xu #define DRM_FORMAT_R4		fourcc_code('R', '4', ' ', ' ') /* [7:0] R0:R1 4:4 two pixels/byte */
13893e0932bSPeter Xu 
13993e0932bSPeter Xu /* 8 bpp Red (direct relationship between channel value and brightness) */
1408e8ee850SGerd Hoffmann #define DRM_FORMAT_R8		fourcc_code('R', '8', ' ', ' ') /* [7:0] R */
1418e8ee850SGerd Hoffmann 
14293e0932bSPeter Xu /* 10 bpp Red (direct relationship between channel value and brightness) */
14343709a0cSPaolo Bonzini #define DRM_FORMAT_R10		fourcc_code('R', '1', '0', ' ') /* [15:0] x:R 6:10 little endian */
14443709a0cSPaolo Bonzini 
14593e0932bSPeter Xu /* 12 bpp Red (direct relationship between channel value and brightness) */
14643709a0cSPaolo Bonzini #define DRM_FORMAT_R12		fourcc_code('R', '1', '2', ' ') /* [15:0] x:R 4:12 little endian */
14743709a0cSPaolo Bonzini 
14893e0932bSPeter Xu /* 16 bpp Red (direct relationship between channel value and brightness) */
1498e8ee850SGerd Hoffmann #define DRM_FORMAT_R16		fourcc_code('R', '1', '6', ' ') /* [15:0] R little endian */
1508e8ee850SGerd Hoffmann 
1518e8ee850SGerd Hoffmann /* 16 bpp RG */
1528e8ee850SGerd Hoffmann #define DRM_FORMAT_RG88		fourcc_code('R', 'G', '8', '8') /* [15:0] R:G 8:8 little endian */
1538e8ee850SGerd Hoffmann #define DRM_FORMAT_GR88		fourcc_code('G', 'R', '8', '8') /* [15:0] G:R 8:8 little endian */
1548e8ee850SGerd Hoffmann 
1558e8ee850SGerd Hoffmann /* 32 bpp RG */
1568e8ee850SGerd Hoffmann #define DRM_FORMAT_RG1616	fourcc_code('R', 'G', '3', '2') /* [31:0] R:G 16:16 little endian */
1578e8ee850SGerd Hoffmann #define DRM_FORMAT_GR1616	fourcc_code('G', 'R', '3', '2') /* [31:0] G:R 16:16 little endian */
1588e8ee850SGerd Hoffmann 
1598e8ee850SGerd Hoffmann /* 8 bpp RGB */
1608e8ee850SGerd Hoffmann #define DRM_FORMAT_RGB332	fourcc_code('R', 'G', 'B', '8') /* [7:0] R:G:B 3:3:2 */
1618e8ee850SGerd Hoffmann #define DRM_FORMAT_BGR233	fourcc_code('B', 'G', 'R', '8') /* [7:0] B:G:R 2:3:3 */
1628e8ee850SGerd Hoffmann 
1638e8ee850SGerd Hoffmann /* 16 bpp RGB */
1648e8ee850SGerd Hoffmann #define DRM_FORMAT_XRGB4444	fourcc_code('X', 'R', '1', '2') /* [15:0] x:R:G:B 4:4:4:4 little endian */
1658e8ee850SGerd Hoffmann #define DRM_FORMAT_XBGR4444	fourcc_code('X', 'B', '1', '2') /* [15:0] x:B:G:R 4:4:4:4 little endian */
1668e8ee850SGerd Hoffmann #define DRM_FORMAT_RGBX4444	fourcc_code('R', 'X', '1', '2') /* [15:0] R:G:B:x 4:4:4:4 little endian */
1678e8ee850SGerd Hoffmann #define DRM_FORMAT_BGRX4444	fourcc_code('B', 'X', '1', '2') /* [15:0] B:G:R:x 4:4:4:4 little endian */
1688e8ee850SGerd Hoffmann 
1698e8ee850SGerd Hoffmann #define DRM_FORMAT_ARGB4444	fourcc_code('A', 'R', '1', '2') /* [15:0] A:R:G:B 4:4:4:4 little endian */
1708e8ee850SGerd Hoffmann #define DRM_FORMAT_ABGR4444	fourcc_code('A', 'B', '1', '2') /* [15:0] A:B:G:R 4:4:4:4 little endian */
1718e8ee850SGerd Hoffmann #define DRM_FORMAT_RGBA4444	fourcc_code('R', 'A', '1', '2') /* [15:0] R:G:B:A 4:4:4:4 little endian */
1728e8ee850SGerd Hoffmann #define DRM_FORMAT_BGRA4444	fourcc_code('B', 'A', '1', '2') /* [15:0] B:G:R:A 4:4:4:4 little endian */
1738e8ee850SGerd Hoffmann 
1748e8ee850SGerd Hoffmann #define DRM_FORMAT_XRGB1555	fourcc_code('X', 'R', '1', '5') /* [15:0] x:R:G:B 1:5:5:5 little endian */
1758e8ee850SGerd Hoffmann #define DRM_FORMAT_XBGR1555	fourcc_code('X', 'B', '1', '5') /* [15:0] x:B:G:R 1:5:5:5 little endian */
1768e8ee850SGerd Hoffmann #define DRM_FORMAT_RGBX5551	fourcc_code('R', 'X', '1', '5') /* [15:0] R:G:B:x 5:5:5:1 little endian */
1778e8ee850SGerd Hoffmann #define DRM_FORMAT_BGRX5551	fourcc_code('B', 'X', '1', '5') /* [15:0] B:G:R:x 5:5:5:1 little endian */
1788e8ee850SGerd Hoffmann 
1798e8ee850SGerd Hoffmann #define DRM_FORMAT_ARGB1555	fourcc_code('A', 'R', '1', '5') /* [15:0] A:R:G:B 1:5:5:5 little endian */
1808e8ee850SGerd Hoffmann #define DRM_FORMAT_ABGR1555	fourcc_code('A', 'B', '1', '5') /* [15:0] A:B:G:R 1:5:5:5 little endian */
1818e8ee850SGerd Hoffmann #define DRM_FORMAT_RGBA5551	fourcc_code('R', 'A', '1', '5') /* [15:0] R:G:B:A 5:5:5:1 little endian */
1828e8ee850SGerd Hoffmann #define DRM_FORMAT_BGRA5551	fourcc_code('B', 'A', '1', '5') /* [15:0] B:G:R:A 5:5:5:1 little endian */
1838e8ee850SGerd Hoffmann 
1848e8ee850SGerd Hoffmann #define DRM_FORMAT_RGB565	fourcc_code('R', 'G', '1', '6') /* [15:0] R:G:B 5:6:5 little endian */
1858e8ee850SGerd Hoffmann #define DRM_FORMAT_BGR565	fourcc_code('B', 'G', '1', '6') /* [15:0] B:G:R 5:6:5 little endian */
1868e8ee850SGerd Hoffmann 
1878e8ee850SGerd Hoffmann /* 24 bpp RGB */
1888e8ee850SGerd Hoffmann #define DRM_FORMAT_RGB888	fourcc_code('R', 'G', '2', '4') /* [23:0] R:G:B little endian */
1898e8ee850SGerd Hoffmann #define DRM_FORMAT_BGR888	fourcc_code('B', 'G', '2', '4') /* [23:0] B:G:R little endian */
1908e8ee850SGerd Hoffmann 
1918e8ee850SGerd Hoffmann /* 32 bpp RGB */
1928e8ee850SGerd Hoffmann #define DRM_FORMAT_XRGB8888	fourcc_code('X', 'R', '2', '4') /* [31:0] x:R:G:B 8:8:8:8 little endian */
1938e8ee850SGerd Hoffmann #define DRM_FORMAT_XBGR8888	fourcc_code('X', 'B', '2', '4') /* [31:0] x:B:G:R 8:8:8:8 little endian */
1948e8ee850SGerd Hoffmann #define DRM_FORMAT_RGBX8888	fourcc_code('R', 'X', '2', '4') /* [31:0] R:G:B:x 8:8:8:8 little endian */
1958e8ee850SGerd Hoffmann #define DRM_FORMAT_BGRX8888	fourcc_code('B', 'X', '2', '4') /* [31:0] B:G:R:x 8:8:8:8 little endian */
1968e8ee850SGerd Hoffmann 
1978e8ee850SGerd Hoffmann #define DRM_FORMAT_ARGB8888	fourcc_code('A', 'R', '2', '4') /* [31:0] A:R:G:B 8:8:8:8 little endian */
1988e8ee850SGerd Hoffmann #define DRM_FORMAT_ABGR8888	fourcc_code('A', 'B', '2', '4') /* [31:0] A:B:G:R 8:8:8:8 little endian */
1998e8ee850SGerd Hoffmann #define DRM_FORMAT_RGBA8888	fourcc_code('R', 'A', '2', '4') /* [31:0] R:G:B:A 8:8:8:8 little endian */
2008e8ee850SGerd Hoffmann #define DRM_FORMAT_BGRA8888	fourcc_code('B', 'A', '2', '4') /* [31:0] B:G:R:A 8:8:8:8 little endian */
2018e8ee850SGerd Hoffmann 
2028e8ee850SGerd Hoffmann #define DRM_FORMAT_XRGB2101010	fourcc_code('X', 'R', '3', '0') /* [31:0] x:R:G:B 2:10:10:10 little endian */
2038e8ee850SGerd Hoffmann #define DRM_FORMAT_XBGR2101010	fourcc_code('X', 'B', '3', '0') /* [31:0] x:B:G:R 2:10:10:10 little endian */
2048e8ee850SGerd Hoffmann #define DRM_FORMAT_RGBX1010102	fourcc_code('R', 'X', '3', '0') /* [31:0] R:G:B:x 10:10:10:2 little endian */
2058e8ee850SGerd Hoffmann #define DRM_FORMAT_BGRX1010102	fourcc_code('B', 'X', '3', '0') /* [31:0] B:G:R:x 10:10:10:2 little endian */
2068e8ee850SGerd Hoffmann 
2078e8ee850SGerd Hoffmann #define DRM_FORMAT_ARGB2101010	fourcc_code('A', 'R', '3', '0') /* [31:0] A:R:G:B 2:10:10:10 little endian */
2088e8ee850SGerd Hoffmann #define DRM_FORMAT_ABGR2101010	fourcc_code('A', 'B', '3', '0') /* [31:0] A:B:G:R 2:10:10:10 little endian */
2098e8ee850SGerd Hoffmann #define DRM_FORMAT_RGBA1010102	fourcc_code('R', 'A', '3', '0') /* [31:0] R:G:B:A 10:10:10:2 little endian */
2108e8ee850SGerd Hoffmann #define DRM_FORMAT_BGRA1010102	fourcc_code('B', 'A', '3', '0') /* [31:0] B:G:R:A 10:10:10:2 little endian */
2118e8ee850SGerd Hoffmann 
212327d4b7fSBharata B Rao /* 64 bpp RGB */
213327d4b7fSBharata B Rao #define DRM_FORMAT_XRGB16161616	fourcc_code('X', 'R', '4', '8') /* [63:0] x:R:G:B 16:16:16:16 little endian */
214327d4b7fSBharata B Rao #define DRM_FORMAT_XBGR16161616	fourcc_code('X', 'B', '4', '8') /* [63:0] x:B:G:R 16:16:16:16 little endian */
215327d4b7fSBharata B Rao 
216327d4b7fSBharata B Rao #define DRM_FORMAT_ARGB16161616	fourcc_code('A', 'R', '4', '8') /* [63:0] A:R:G:B 16:16:16:16 little endian */
217327d4b7fSBharata B Rao #define DRM_FORMAT_ABGR16161616	fourcc_code('A', 'B', '4', '8') /* [63:0] A:B:G:R 16:16:16:16 little endian */
218327d4b7fSBharata B Rao 
219d9cb4336SCornelia Huck /*
220d9cb4336SCornelia Huck  * Floating point 64bpp RGB
221d9cb4336SCornelia Huck  * IEEE 754-2008 binary16 half-precision float
222d9cb4336SCornelia Huck  * [15:0] sign:exponent:mantissa 1:5:10
223d9cb4336SCornelia Huck  */
224d9cb4336SCornelia Huck #define DRM_FORMAT_XRGB16161616F fourcc_code('X', 'R', '4', 'H') /* [63:0] x:R:G:B 16:16:16:16 little endian */
225d9cb4336SCornelia Huck #define DRM_FORMAT_XBGR16161616F fourcc_code('X', 'B', '4', 'H') /* [63:0] x:B:G:R 16:16:16:16 little endian */
226d9cb4336SCornelia Huck 
227d9cb4336SCornelia Huck #define DRM_FORMAT_ARGB16161616F fourcc_code('A', 'R', '4', 'H') /* [63:0] A:R:G:B 16:16:16:16 little endian */
228d9cb4336SCornelia Huck #define DRM_FORMAT_ABGR16161616F fourcc_code('A', 'B', '4', 'H') /* [63:0] A:B:G:R 16:16:16:16 little endian */
229d9cb4336SCornelia Huck 
230b3c818a4SEric Farman /*
231b3c818a4SEric Farman  * RGBA format with 10-bit components packed in 64-bit per pixel, with 6 bits
232b3c818a4SEric Farman  * of unused padding per component:
233b3c818a4SEric Farman  */
234b3c818a4SEric Farman #define DRM_FORMAT_AXBXGXRX106106106106 fourcc_code('A', 'B', '1', '0') /* [63:0] A:x:B:x:G:x:R:x 10:6:10:6:10:6:10:6 little endian */
235b3c818a4SEric Farman 
2368e8ee850SGerd Hoffmann /* packed YCbCr */
2378e8ee850SGerd Hoffmann #define DRM_FORMAT_YUYV		fourcc_code('Y', 'U', 'Y', 'V') /* [31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian */
2388e8ee850SGerd Hoffmann #define DRM_FORMAT_YVYU		fourcc_code('Y', 'V', 'Y', 'U') /* [31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian */
2398e8ee850SGerd Hoffmann #define DRM_FORMAT_UYVY		fourcc_code('U', 'Y', 'V', 'Y') /* [31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian */
2408e8ee850SGerd Hoffmann #define DRM_FORMAT_VYUY		fourcc_code('V', 'Y', 'U', 'Y') /* [31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian */
2418e8ee850SGerd Hoffmann 
2428e8ee850SGerd Hoffmann #define DRM_FORMAT_AYUV		fourcc_code('A', 'Y', 'U', 'V') /* [31:0] A:Y:Cb:Cr 8:8:8:8 little endian */
24393e0932bSPeter Xu #define DRM_FORMAT_AVUY8888	fourcc_code('A', 'V', 'U', 'Y') /* [31:0] A:Cr:Cb:Y 8:8:8:8 little endian */
244da054c64SPaolo Bonzini #define DRM_FORMAT_XYUV8888	fourcc_code('X', 'Y', 'U', 'V') /* [31:0] X:Y:Cb:Cr 8:8:8:8 little endian */
24593e0932bSPeter Xu #define DRM_FORMAT_XVUY8888	fourcc_code('X', 'V', 'U', 'Y') /* [31:0] X:Cr:Cb:Y 8:8:8:8 little endian */
246d9cb4336SCornelia Huck #define DRM_FORMAT_VUY888	fourcc_code('V', 'U', '2', '4') /* [23:0] Cr:Cb:Y 8:8:8 little endian */
247d9cb4336SCornelia Huck #define DRM_FORMAT_VUY101010	fourcc_code('V', 'U', '3', '0') /* Y followed by U then V, 10:10:10. Non-linear modifier only */
248d9cb4336SCornelia Huck 
249d9cb4336SCornelia Huck /*
250d9cb4336SCornelia Huck  * packed Y2xx indicate for each component, xx valid data occupy msb
251d9cb4336SCornelia Huck  * 16-xx padding occupy lsb
252d9cb4336SCornelia Huck  */
253d9cb4336SCornelia Huck #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 */
254d9cb4336SCornelia Huck #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 */
255d9cb4336SCornelia Huck #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 */
256d9cb4336SCornelia Huck 
257d9cb4336SCornelia Huck /*
258d9cb4336SCornelia Huck  * packed Y4xx indicate for each component, xx valid data occupy msb
259d9cb4336SCornelia Huck  * 16-xx padding occupy lsb except Y410
260d9cb4336SCornelia Huck  */
261d9cb4336SCornelia Huck #define DRM_FORMAT_Y410         fourcc_code('Y', '4', '1', '0') /* [31:0] A:Cr:Y:Cb 2:10:10:10 little endian */
262d9cb4336SCornelia Huck #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 */
263d9cb4336SCornelia Huck #define DRM_FORMAT_Y416         fourcc_code('Y', '4', '1', '6') /* [63:0] A:Cr:Y:Cb 16:16:16:16 little endian */
264d9cb4336SCornelia Huck 
265d9cb4336SCornelia Huck #define DRM_FORMAT_XVYU2101010	fourcc_code('X', 'V', '3', '0') /* [31:0] X:Cr:Y:Cb 2:10:10:10 little endian */
266d9cb4336SCornelia Huck #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 */
267d9cb4336SCornelia Huck #define DRM_FORMAT_XVYU16161616	fourcc_code('X', 'V', '4', '8') /* [63:0] X:Cr:Y:Cb 16:16:16:16 little endian */
268da054c64SPaolo Bonzini 
269da054c64SPaolo Bonzini /*
270da054c64SPaolo Bonzini  * packed YCbCr420 2x2 tiled formats
271da054c64SPaolo Bonzini  * first 64 bits will contain Y,Cb,Cr components for a 2x2 tile
272da054c64SPaolo Bonzini  */
273da054c64SPaolo Bonzini /* [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 */
274da054c64SPaolo Bonzini #define DRM_FORMAT_Y0L0		fourcc_code('Y', '0', 'L', '0')
275da054c64SPaolo Bonzini /* [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 */
276da054c64SPaolo Bonzini #define DRM_FORMAT_X0L0		fourcc_code('X', '0', 'L', '0')
277da054c64SPaolo Bonzini 
278da054c64SPaolo Bonzini /* [63:0]   A3:A2:Y3:Cr0:Y2:A1:A0:Y1:Cb0:Y0  1:1:10:10:10:1:1:10:10:10 little endian */
279da054c64SPaolo Bonzini #define DRM_FORMAT_Y0L2		fourcc_code('Y', '0', 'L', '2')
280da054c64SPaolo Bonzini /* [63:0]   X3:X2:Y3:Cr0:Y2:X1:X0:Y1:Cb0:Y0  1:1:10:10:10:1:1:10:10:10 little endian */
281da054c64SPaolo Bonzini #define DRM_FORMAT_X0L2		fourcc_code('X', '0', 'L', '2')
2828e8ee850SGerd Hoffmann 
2838e8ee850SGerd Hoffmann /*
284d9cb4336SCornelia Huck  * 1-plane YUV 4:2:0
285d9cb4336SCornelia Huck  * In these formats, the component ordering is specified (Y, followed by U
286d9cb4336SCornelia Huck  * then V), but the exact Linear layout is undefined.
287d9cb4336SCornelia Huck  * These formats can only be used with a non-Linear modifier.
288d9cb4336SCornelia Huck  */
289d9cb4336SCornelia Huck #define DRM_FORMAT_YUV420_8BIT	fourcc_code('Y', 'U', '0', '8')
290d9cb4336SCornelia Huck #define DRM_FORMAT_YUV420_10BIT	fourcc_code('Y', 'U', '1', '0')
291d9cb4336SCornelia Huck 
292d9cb4336SCornelia Huck /*
2938e8ee850SGerd Hoffmann  * 2 plane RGB + A
2948e8ee850SGerd Hoffmann  * index 0 = RGB plane, same format as the corresponding non _A8 format has
2958e8ee850SGerd Hoffmann  * index 1 = A plane, [7:0] A
2968e8ee850SGerd Hoffmann  */
2978e8ee850SGerd Hoffmann #define DRM_FORMAT_XRGB8888_A8	fourcc_code('X', 'R', 'A', '8')
2988e8ee850SGerd Hoffmann #define DRM_FORMAT_XBGR8888_A8	fourcc_code('X', 'B', 'A', '8')
2998e8ee850SGerd Hoffmann #define DRM_FORMAT_RGBX8888_A8	fourcc_code('R', 'X', 'A', '8')
3008e8ee850SGerd Hoffmann #define DRM_FORMAT_BGRX8888_A8	fourcc_code('B', 'X', 'A', '8')
3018e8ee850SGerd Hoffmann #define DRM_FORMAT_RGB888_A8	fourcc_code('R', '8', 'A', '8')
3028e8ee850SGerd Hoffmann #define DRM_FORMAT_BGR888_A8	fourcc_code('B', '8', 'A', '8')
3038e8ee850SGerd Hoffmann #define DRM_FORMAT_RGB565_A8	fourcc_code('R', '5', 'A', '8')
3048e8ee850SGerd Hoffmann #define DRM_FORMAT_BGR565_A8	fourcc_code('B', '5', 'A', '8')
3058e8ee850SGerd Hoffmann 
3068e8ee850SGerd Hoffmann /*
3078e8ee850SGerd Hoffmann  * 2 plane YCbCr
3088e8ee850SGerd Hoffmann  * index 0 = Y plane, [7:0] Y
3098e8ee850SGerd Hoffmann  * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
3108e8ee850SGerd Hoffmann  * or
3118e8ee850SGerd Hoffmann  * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
3128e8ee850SGerd Hoffmann  */
3138e8ee850SGerd Hoffmann #define DRM_FORMAT_NV12		fourcc_code('N', 'V', '1', '2') /* 2x2 subsampled Cr:Cb plane */
3148e8ee850SGerd Hoffmann #define DRM_FORMAT_NV21		fourcc_code('N', 'V', '2', '1') /* 2x2 subsampled Cb:Cr plane */
3158e8ee850SGerd Hoffmann #define DRM_FORMAT_NV16		fourcc_code('N', 'V', '1', '6') /* 2x1 subsampled Cr:Cb plane */
3168e8ee850SGerd Hoffmann #define DRM_FORMAT_NV61		fourcc_code('N', 'V', '6', '1') /* 2x1 subsampled Cb:Cr plane */
3178e8ee850SGerd Hoffmann #define DRM_FORMAT_NV24		fourcc_code('N', 'V', '2', '4') /* non-subsampled Cr:Cb plane */
3188e8ee850SGerd Hoffmann #define DRM_FORMAT_NV42		fourcc_code('N', 'V', '4', '2') /* non-subsampled Cb:Cr plane */
319e6546342SJason Wang /*
320e6546342SJason Wang  * 2 plane YCbCr
321e6546342SJason Wang  * index 0 = Y plane, [39:0] Y3:Y2:Y1:Y0 little endian
322e6546342SJason Wang  * index 1 = Cr:Cb plane, [39:0] Cr1:Cb1:Cr0:Cb0 little endian
323e6546342SJason Wang  */
324e6546342SJason Wang #define DRM_FORMAT_NV15		fourcc_code('N', 'V', '1', '5') /* 2x2 subsampled Cr:Cb plane */
325efb91426SDaniel Henrique Barboza #define DRM_FORMAT_NV20		fourcc_code('N', 'V', '2', '0') /* 2x1 subsampled Cr:Cb plane */
326efb91426SDaniel Henrique Barboza #define DRM_FORMAT_NV30		fourcc_code('N', 'V', '3', '0') /* non-subsampled Cr:Cb plane */
3278e8ee850SGerd Hoffmann 
3288e8ee850SGerd Hoffmann /*
329d9cb4336SCornelia Huck  * 2 plane YCbCr MSB aligned
330d9cb4336SCornelia Huck  * index 0 = Y plane, [15:0] Y:x [10:6] little endian
331d9cb4336SCornelia Huck  * index 1 = Cr:Cb plane, [31:0] Cr:x:Cb:x [10:6:10:6] little endian
332d9cb4336SCornelia Huck  */
333d9cb4336SCornelia Huck #define DRM_FORMAT_P210		fourcc_code('P', '2', '1', '0') /* 2x1 subsampled Cr:Cb plane, 10 bit per channel */
334d9cb4336SCornelia Huck 
335d9cb4336SCornelia Huck /*
336d9cb4336SCornelia Huck  * 2 plane YCbCr MSB aligned
337d9cb4336SCornelia Huck  * index 0 = Y plane, [15:0] Y:x [10:6] little endian
338d9cb4336SCornelia Huck  * index 1 = Cr:Cb plane, [31:0] Cr:x:Cb:x [10:6:10:6] little endian
339d9cb4336SCornelia Huck  */
340d9cb4336SCornelia Huck #define DRM_FORMAT_P010		fourcc_code('P', '0', '1', '0') /* 2x2 subsampled Cr:Cb plane 10 bits per channel */
341d9cb4336SCornelia Huck 
342d9cb4336SCornelia Huck /*
343d9cb4336SCornelia Huck  * 2 plane YCbCr MSB aligned
344d9cb4336SCornelia Huck  * index 0 = Y plane, [15:0] Y:x [12:4] little endian
345d9cb4336SCornelia Huck  * index 1 = Cr:Cb plane, [31:0] Cr:x:Cb:x [12:4:12:4] little endian
346d9cb4336SCornelia Huck  */
347d9cb4336SCornelia Huck #define DRM_FORMAT_P012		fourcc_code('P', '0', '1', '2') /* 2x2 subsampled Cr:Cb plane 12 bits per channel */
348d9cb4336SCornelia Huck 
349d9cb4336SCornelia Huck /*
350d9cb4336SCornelia Huck  * 2 plane YCbCr MSB aligned
351d9cb4336SCornelia Huck  * index 0 = Y plane, [15:0] Y little endian
352d9cb4336SCornelia Huck  * index 1 = Cr:Cb plane, [31:0] Cr:Cb [16:16] little endian
353d9cb4336SCornelia Huck  */
354d9cb4336SCornelia Huck #define DRM_FORMAT_P016		fourcc_code('P', '0', '1', '6') /* 2x2 subsampled Cr:Cb plane 16 bits per channel */
355d9cb4336SCornelia Huck 
356ef17dd6aSVivek Goyal /* 2 plane YCbCr420.
357ef17dd6aSVivek Goyal  * 3 10 bit components and 2 padding bits packed into 4 bytes.
358ef17dd6aSVivek Goyal  * index 0 = Y plane, [31:0] x:Y2:Y1:Y0 2:10:10:10 little endian
359ef17dd6aSVivek Goyal  * index 1 = Cr:Cb plane, [63:0] x:Cr2:Cb2:Cr1:x:Cb1:Cr0:Cb0 [2:10:10:10:2:10:10:10] little endian
360ef17dd6aSVivek Goyal  */
361ef17dd6aSVivek Goyal #define DRM_FORMAT_P030		fourcc_code('P', '0', '3', '0') /* 2x2 subsampled Cr:Cb plane 10 bits per channel packed */
362ef17dd6aSVivek Goyal 
363e6546342SJason Wang /* 3 plane non-subsampled (444) YCbCr
364e6546342SJason Wang  * 16 bits per component, but only 10 bits are used and 6 bits are padded
365e6546342SJason Wang  * index 0: Y plane, [15:0] Y:x [10:6] little endian
366e6546342SJason Wang  * index 1: Cb plane, [15:0] Cb:x [10:6] little endian
367e6546342SJason Wang  * index 2: Cr plane, [15:0] Cr:x [10:6] little endian
368e6546342SJason Wang  */
369e6546342SJason Wang #define DRM_FORMAT_Q410		fourcc_code('Q', '4', '1', '0')
370e6546342SJason Wang 
371e6546342SJason Wang /* 3 plane non-subsampled (444) YCrCb
372e6546342SJason Wang  * 16 bits per component, but only 10 bits are used and 6 bits are padded
373e6546342SJason Wang  * index 0: Y plane, [15:0] Y:x [10:6] little endian
374e6546342SJason Wang  * index 1: Cr plane, [15:0] Cr:x [10:6] little endian
375e6546342SJason Wang  * index 2: Cb plane, [15:0] Cb:x [10:6] little endian
376e6546342SJason Wang  */
377e6546342SJason Wang #define DRM_FORMAT_Q401		fourcc_code('Q', '4', '0', '1')
378e6546342SJason Wang 
379d9cb4336SCornelia Huck /*
3808e8ee850SGerd Hoffmann  * 3 plane YCbCr
3818e8ee850SGerd Hoffmann  * index 0: Y plane, [7:0] Y
3828e8ee850SGerd Hoffmann  * index 1: Cb plane, [7:0] Cb
3838e8ee850SGerd Hoffmann  * index 2: Cr plane, [7:0] Cr
3848e8ee850SGerd Hoffmann  * or
3858e8ee850SGerd Hoffmann  * index 1: Cr plane, [7:0] Cr
3868e8ee850SGerd Hoffmann  * index 2: Cb plane, [7:0] Cb
3878e8ee850SGerd Hoffmann  */
3888e8ee850SGerd Hoffmann #define DRM_FORMAT_YUV410	fourcc_code('Y', 'U', 'V', '9') /* 4x4 subsampled Cb (1) and Cr (2) planes */
3898e8ee850SGerd Hoffmann #define DRM_FORMAT_YVU410	fourcc_code('Y', 'V', 'U', '9') /* 4x4 subsampled Cr (1) and Cb (2) planes */
3908e8ee850SGerd Hoffmann #define DRM_FORMAT_YUV411	fourcc_code('Y', 'U', '1', '1') /* 4x1 subsampled Cb (1) and Cr (2) planes */
3918e8ee850SGerd Hoffmann #define DRM_FORMAT_YVU411	fourcc_code('Y', 'V', '1', '1') /* 4x1 subsampled Cr (1) and Cb (2) planes */
3928e8ee850SGerd Hoffmann #define DRM_FORMAT_YUV420	fourcc_code('Y', 'U', '1', '2') /* 2x2 subsampled Cb (1) and Cr (2) planes */
3938e8ee850SGerd Hoffmann #define DRM_FORMAT_YVU420	fourcc_code('Y', 'V', '1', '2') /* 2x2 subsampled Cr (1) and Cb (2) planes */
3948e8ee850SGerd Hoffmann #define DRM_FORMAT_YUV422	fourcc_code('Y', 'U', '1', '6') /* 2x1 subsampled Cb (1) and Cr (2) planes */
3958e8ee850SGerd Hoffmann #define DRM_FORMAT_YVU422	fourcc_code('Y', 'V', '1', '6') /* 2x1 subsampled Cr (1) and Cb (2) planes */
3968e8ee850SGerd Hoffmann #define DRM_FORMAT_YUV444	fourcc_code('Y', 'U', '2', '4') /* non-subsampled Cb (1) and Cr (2) planes */
3978e8ee850SGerd Hoffmann #define DRM_FORMAT_YVU444	fourcc_code('Y', 'V', '2', '4') /* non-subsampled Cr (1) and Cb (2) planes */
3988e8ee850SGerd Hoffmann 
3998e8ee850SGerd Hoffmann 
4008e8ee850SGerd Hoffmann /*
4018e8ee850SGerd Hoffmann  * Format Modifiers:
4028e8ee850SGerd Hoffmann  *
4038e8ee850SGerd Hoffmann  * Format modifiers describe, typically, a re-ordering or modification
4048e8ee850SGerd Hoffmann  * of the data in a plane of an FB.  This can be used to express tiled/
4058e8ee850SGerd Hoffmann  * swizzled formats, or compression, or a combination of the two.
4068e8ee850SGerd Hoffmann  *
4078e8ee850SGerd Hoffmann  * The upper 8 bits of the format modifier are a vendor-id as assigned
4088e8ee850SGerd Hoffmann  * below.  The lower 56 bits are assigned as vendor sees fit.
4098e8ee850SGerd Hoffmann  */
4108e8ee850SGerd Hoffmann 
4118e8ee850SGerd Hoffmann /* Vendor Ids: */
4128e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_VENDOR_NONE    0
4138e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_VENDOR_INTEL   0x01
4148e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_VENDOR_AMD     0x02
4158e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_VENDOR_NVIDIA  0x03
4168e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_VENDOR_SAMSUNG 0x04
4178e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_VENDOR_QCOM    0x05
4188e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_VENDOR_VIVANTE 0x06
4198e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_VENDOR_BROADCOM 0x07
420d36f7de8SCornelia Huck #define DRM_FORMAT_MOD_VENDOR_ARM     0x08
421d9cb4336SCornelia Huck #define DRM_FORMAT_MOD_VENDOR_ALLWINNER 0x09
422e6546342SJason Wang #define DRM_FORMAT_MOD_VENDOR_AMLOGIC 0x0a
423d9cb4336SCornelia Huck 
4248e8ee850SGerd Hoffmann /* add more to the end as needed */
4258e8ee850SGerd Hoffmann 
4268e8ee850SGerd Hoffmann #define DRM_FORMAT_RESERVED	      ((1ULL << 56) - 1)
4278e8ee850SGerd Hoffmann 
42843709a0cSPaolo Bonzini #define fourcc_mod_get_vendor(modifier) \
42943709a0cSPaolo Bonzini 	(((modifier) >> 56) & 0xff)
43043709a0cSPaolo Bonzini 
43143709a0cSPaolo Bonzini #define fourcc_mod_is_vendor(modifier, vendor) \
43243709a0cSPaolo Bonzini 	(fourcc_mod_get_vendor(modifier) == DRM_FORMAT_MOD_VENDOR_## vendor)
43343709a0cSPaolo Bonzini 
4348e8ee850SGerd Hoffmann #define fourcc_mod_code(vendor, val) \
4358e8ee850SGerd Hoffmann 	((((uint64_t)DRM_FORMAT_MOD_VENDOR_## vendor) << 56) | ((val) & 0x00ffffffffffffffULL))
4368e8ee850SGerd Hoffmann 
4378e8ee850SGerd Hoffmann /*
4388e8ee850SGerd Hoffmann  * Format Modifier tokens:
4398e8ee850SGerd Hoffmann  *
4408e8ee850SGerd Hoffmann  * When adding a new token please document the layout with a code comment,
4418e8ee850SGerd Hoffmann  * similar to the fourcc codes above. drm_fourcc.h is considered the
4428e8ee850SGerd Hoffmann  * authoritative source for all of these.
443e6546342SJason Wang  *
444e6546342SJason Wang  * Generic modifier names:
445e6546342SJason Wang  *
446e6546342SJason Wang  * DRM_FORMAT_MOD_GENERIC_* definitions are used to provide vendor-neutral names
447e6546342SJason Wang  * for layouts which are common across multiple vendors. To preserve
448e6546342SJason Wang  * compatibility, in cases where a vendor-specific definition already exists and
449e6546342SJason Wang  * a generic name for it is desired, the common name is a purely symbolic alias
450e6546342SJason Wang  * and must use the same numerical value as the original definition.
451e6546342SJason Wang  *
452e6546342SJason Wang  * Note that generic names should only be used for modifiers which describe
453e6546342SJason Wang  * generic layouts (such as pixel re-ordering), which may have
454e6546342SJason Wang  * independently-developed support across multiple vendors.
455e6546342SJason Wang  *
456e6546342SJason Wang  * In future cases where a generic layout is identified before merging with a
457e6546342SJason Wang  * vendor-specific modifier, a new 'GENERIC' vendor or modifier using vendor
458e6546342SJason Wang  * 'NONE' could be considered. This should only be for obvious, exceptional
459e6546342SJason Wang  * cases to avoid polluting the 'GENERIC' namespace with modifiers which only
460e6546342SJason Wang  * apply to a single vendor.
461e6546342SJason Wang  *
462e6546342SJason Wang  * Generic names should not be used for cases where multiple hardware vendors
463e6546342SJason Wang  * have implementations of the same standardised compression scheme (such as
464e6546342SJason Wang  * AFBC). In those cases, all implementations should use the same format
465e6546342SJason Wang  * modifier(s), reflecting the vendor of the standard.
4668e8ee850SGerd Hoffmann  */
4678e8ee850SGerd Hoffmann 
468e6546342SJason Wang #define DRM_FORMAT_MOD_GENERIC_16_16_TILE DRM_FORMAT_MOD_SAMSUNG_16_16_TILE
469e6546342SJason Wang 
4708e8ee850SGerd Hoffmann /*
4718e8ee850SGerd Hoffmann  * Invalid Modifier
4728e8ee850SGerd Hoffmann  *
4738e8ee850SGerd Hoffmann  * This modifier can be used as a sentinel to terminate the format modifiers
4748e8ee850SGerd Hoffmann  * list, or to initialize a variable with an invalid modifier. It might also be
4758e8ee850SGerd Hoffmann  * used to report an error back to userspace for certain APIs.
4768e8ee850SGerd Hoffmann  */
4778e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_INVALID	fourcc_mod_code(NONE, DRM_FORMAT_RESERVED)
4788e8ee850SGerd Hoffmann 
4798e8ee850SGerd Hoffmann /*
4808e8ee850SGerd Hoffmann  * Linear Layout
4818e8ee850SGerd Hoffmann  *
4828e8ee850SGerd Hoffmann  * Just plain linear layout. Note that this is different from no specifying any
4838e8ee850SGerd Hoffmann  * modifier (e.g. not setting DRM_MODE_FB_MODIFIERS in the DRM_ADDFB2 ioctl),
4848e8ee850SGerd Hoffmann  * which tells the driver to also take driver-internal information into account
4858e8ee850SGerd Hoffmann  * and so might actually result in a tiled framebuffer.
4868e8ee850SGerd Hoffmann  */
4878e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_LINEAR	fourcc_mod_code(NONE, 0)
4888e8ee850SGerd Hoffmann 
489b3c818a4SEric Farman /*
490b3c818a4SEric Farman  * Deprecated: use DRM_FORMAT_MOD_LINEAR instead
491b3c818a4SEric Farman  *
492b3c818a4SEric Farman  * The "none" format modifier doesn't actually mean that the modifier is
493b3c818a4SEric Farman  * implicit, instead it means that the layout is linear. Whether modifiers are
494b3c818a4SEric Farman  * used is out-of-band information carried in an API-specific way (e.g. in a
495b3c818a4SEric Farman  * flag for drm_mode_fb_cmd2).
496b3c818a4SEric Farman  */
497b3c818a4SEric Farman #define DRM_FORMAT_MOD_NONE	0
498b3c818a4SEric Farman 
4998e8ee850SGerd Hoffmann /* Intel framebuffer modifiers */
5008e8ee850SGerd Hoffmann 
5018e8ee850SGerd Hoffmann /*
5028e8ee850SGerd Hoffmann  * Intel X-tiling layout
5038e8ee850SGerd Hoffmann  *
5048e8ee850SGerd Hoffmann  * This is a tiled layout using 4Kb tiles (except on gen2 where the tiles 2Kb)
5058e8ee850SGerd Hoffmann  * in row-major layout. Within the tile bytes are laid out row-major, with
5068e8ee850SGerd Hoffmann  * a platform-dependent stride. On top of that the memory can apply
5078e8ee850SGerd Hoffmann  * platform-depending swizzling of some higher address bits into bit6.
5088e8ee850SGerd Hoffmann  *
509f76b348eSCornelia Huck  * Note that this layout is only accurate on intel gen 8+ or valleyview chipsets.
510f76b348eSCornelia Huck  * On earlier platforms the is highly platforms specific and not useful for
511f76b348eSCornelia Huck  * cross-driver sharing. It exists since on a given platform it does uniquely
512f76b348eSCornelia Huck  * identify the layout in a simple way for i915-specific userspace, which
513f76b348eSCornelia Huck  * facilitated conversion of userspace to modifiers. Additionally the exact
514f76b348eSCornelia Huck  * format on some really old platforms is not known.
5158e8ee850SGerd Hoffmann  */
5168e8ee850SGerd Hoffmann #define I915_FORMAT_MOD_X_TILED	fourcc_mod_code(INTEL, 1)
5178e8ee850SGerd Hoffmann 
5188e8ee850SGerd Hoffmann /*
5198e8ee850SGerd Hoffmann  * Intel Y-tiling layout
5208e8ee850SGerd Hoffmann  *
5218e8ee850SGerd Hoffmann  * This is a tiled layout using 4Kb tiles (except on gen2 where the tiles 2Kb)
5228e8ee850SGerd Hoffmann  * in row-major layout. Within the tile bytes are laid out in OWORD (16 bytes)
5238e8ee850SGerd Hoffmann  * chunks column-major, with a platform-dependent height. On top of that the
5248e8ee850SGerd Hoffmann  * memory can apply platform-depending swizzling of some higher address bits
5258e8ee850SGerd Hoffmann  * into bit6.
5268e8ee850SGerd Hoffmann  *
527f76b348eSCornelia Huck  * Note that this layout is only accurate on intel gen 8+ or valleyview chipsets.
528f76b348eSCornelia Huck  * On earlier platforms the is highly platforms specific and not useful for
529f76b348eSCornelia Huck  * cross-driver sharing. It exists since on a given platform it does uniquely
530f76b348eSCornelia Huck  * identify the layout in a simple way for i915-specific userspace, which
531f76b348eSCornelia Huck  * facilitated conversion of userspace to modifiers. Additionally the exact
532f76b348eSCornelia Huck  * format on some really old platforms is not known.
5338e8ee850SGerd Hoffmann  */
5348e8ee850SGerd Hoffmann #define I915_FORMAT_MOD_Y_TILED	fourcc_mod_code(INTEL, 2)
5358e8ee850SGerd Hoffmann 
5368e8ee850SGerd Hoffmann /*
5378e8ee850SGerd Hoffmann  * Intel Yf-tiling layout
5388e8ee850SGerd Hoffmann  *
5398e8ee850SGerd Hoffmann  * This is a tiled layout using 4Kb tiles in row-major layout.
5408e8ee850SGerd Hoffmann  * Within the tile pixels are laid out in 16 256 byte units / sub-tiles which
5418e8ee850SGerd Hoffmann  * are arranged in four groups (two wide, two high) with column-major layout.
542*6a02465fSDaniel Henrique Barboza  * Each group therefore consists out of four 256 byte units, which are also laid
5438e8ee850SGerd Hoffmann  * out as 2x2 column-major.
5448e8ee850SGerd Hoffmann  * 256 byte units are made out of four 64 byte blocks of pixels, producing
5458e8ee850SGerd Hoffmann  * either a square block or a 2:1 unit.
5468e8ee850SGerd Hoffmann  * 64 byte blocks of pixels contain four pixel rows of 16 bytes, where the width
5478e8ee850SGerd Hoffmann  * in pixel depends on the pixel depth.
5488e8ee850SGerd Hoffmann  */
5498e8ee850SGerd Hoffmann #define I915_FORMAT_MOD_Yf_TILED fourcc_mod_code(INTEL, 3)
5508e8ee850SGerd Hoffmann 
5518e8ee850SGerd Hoffmann /*
5528e8ee850SGerd Hoffmann  * Intel color control surface (CCS) for render compression
5538e8ee850SGerd Hoffmann  *
5548e8ee850SGerd Hoffmann  * The framebuffer format must be one of the 8:8:8:8 RGB formats.
5558e8ee850SGerd Hoffmann  * The main surface will be plane index 0 and must be Y/Yf-tiled,
5568e8ee850SGerd Hoffmann  * the CCS will be plane index 1.
5578e8ee850SGerd Hoffmann  *
5588e8ee850SGerd Hoffmann  * Each CCS tile matches a 1024x512 pixel area of the main surface.
5598e8ee850SGerd Hoffmann  * To match certain aspects of the 3D hardware the CCS is
5608e8ee850SGerd Hoffmann  * considered to be made up of normal 128Bx32 Y tiles, Thus
5618e8ee850SGerd Hoffmann  * the CCS pitch must be specified in multiples of 128 bytes.
5628e8ee850SGerd Hoffmann  *
5638e8ee850SGerd Hoffmann  * In reality the CCS tile appears to be a 64Bx64 Y tile, composed
5648e8ee850SGerd Hoffmann  * of QWORD (8 bytes) chunks instead of OWORD (16 bytes) chunks.
5658e8ee850SGerd Hoffmann  * But that fact is not relevant unless the memory is accessed
5668e8ee850SGerd Hoffmann  * directly.
5678e8ee850SGerd Hoffmann  */
5688e8ee850SGerd Hoffmann #define I915_FORMAT_MOD_Y_TILED_CCS	fourcc_mod_code(INTEL, 4)
5698e8ee850SGerd Hoffmann #define I915_FORMAT_MOD_Yf_TILED_CCS	fourcc_mod_code(INTEL, 5)
5708e8ee850SGerd Hoffmann 
5718e8ee850SGerd Hoffmann /*
572ddda3748SCornelia Huck  * Intel color control surfaces (CCS) for Gen-12 render compression.
573ddda3748SCornelia Huck  *
574ddda3748SCornelia Huck  * The main surface is Y-tiled and at plane index 0, the CCS is linear and
575ddda3748SCornelia Huck  * at index 1. A 64B CCS cache line corresponds to an area of 4x1 tiles in
576ddda3748SCornelia Huck  * main surface. In other words, 4 bits in CCS map to a main surface cache
577ddda3748SCornelia Huck  * line pair. The main surface pitch is required to be a multiple of four
578ddda3748SCornelia Huck  * Y-tile widths.
579ddda3748SCornelia Huck  */
580ddda3748SCornelia Huck #define I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS fourcc_mod_code(INTEL, 6)
581ddda3748SCornelia Huck 
582ddda3748SCornelia Huck /*
583ddda3748SCornelia Huck  * Intel color control surfaces (CCS) for Gen-12 media compression
584ddda3748SCornelia Huck  *
585ddda3748SCornelia Huck  * The main surface is Y-tiled and at plane index 0, the CCS is linear and
586ddda3748SCornelia Huck  * at index 1. A 64B CCS cache line corresponds to an area of 4x1 tiles in
587ddda3748SCornelia Huck  * main surface. In other words, 4 bits in CCS map to a main surface cache
588ddda3748SCornelia Huck  * line pair. The main surface pitch is required to be a multiple of four
589ddda3748SCornelia Huck  * Y-tile widths. For semi-planar formats like NV12, CCS planes follow the
590ddda3748SCornelia Huck  * Y and UV planes i.e., planes 0 and 1 are used for Y and UV surfaces,
591ddda3748SCornelia Huck  * planes 2 and 3 for the respective CCS.
592ddda3748SCornelia Huck  */
593ddda3748SCornelia Huck #define I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS fourcc_mod_code(INTEL, 7)
594ddda3748SCornelia Huck 
595ddda3748SCornelia Huck /*
596278f064eSEduardo Habkost  * Intel Color Control Surface with Clear Color (CCS) for Gen-12 render
597278f064eSEduardo Habkost  * compression.
598278f064eSEduardo Habkost  *
599278f064eSEduardo Habkost  * The main surface is Y-tiled and is at plane index 0 whereas CCS is linear
600278f064eSEduardo Habkost  * and at index 1. The clear color is stored at index 2, and the pitch should
601d525f73fSChenyi Qiang  * be 64 bytes aligned. The clear color structure is 256 bits. The first 128 bits
602278f064eSEduardo Habkost  * represents Raw Clear Color Red, Green, Blue and Alpha color each represented
603278f064eSEduardo Habkost  * by 32 bits. The raw clear color is consumed by the 3d engine and generates
604278f064eSEduardo Habkost  * the converted clear color of size 64 bits. The first 32 bits store the Lower
605278f064eSEduardo Habkost  * Converted Clear Color value and the next 32 bits store the Higher Converted
606278f064eSEduardo Habkost  * Clear Color value when applicable. The Converted Clear Color values are
607278f064eSEduardo Habkost  * consumed by the DE. The last 64 bits are used to store Color Discard Enable
608278f064eSEduardo Habkost  * and Depth Clear Value Valid which are ignored by the DE. A CCS cache line
609278f064eSEduardo Habkost  * corresponds to an area of 4x1 tiles in the main surface. The main surface
610278f064eSEduardo Habkost  * pitch is required to be a multiple of 4 tile widths.
611278f064eSEduardo Habkost  */
612278f064eSEduardo Habkost #define I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC fourcc_mod_code(INTEL, 8)
613278f064eSEduardo Habkost 
614278f064eSEduardo Habkost /*
615d525f73fSChenyi Qiang  * Intel Tile 4 layout
616d525f73fSChenyi Qiang  *
617d525f73fSChenyi Qiang  * This is a tiled layout using 4KB tiles in a row-major layout. It has the same
618d525f73fSChenyi Qiang  * shape as Tile Y at two granularities: 4KB (128B x 32) and 64B (16B x 4). It
619d525f73fSChenyi Qiang  * only differs from Tile Y at the 256B granularity in between. At this
620d525f73fSChenyi Qiang  * granularity, Tile Y has a shape of 16B x 32 rows, but this tiling has a shape
621d525f73fSChenyi Qiang  * of 64B x 8 rows.
622d525f73fSChenyi Qiang  */
623d525f73fSChenyi Qiang #define I915_FORMAT_MOD_4_TILED         fourcc_mod_code(INTEL, 9)
624d525f73fSChenyi Qiang 
625d525f73fSChenyi Qiang /*
626d525f73fSChenyi Qiang  * Intel color control surfaces (CCS) for DG2 render compression.
627d525f73fSChenyi Qiang  *
628d525f73fSChenyi Qiang  * The main surface is Tile 4 and at plane index 0. The CCS data is stored
629d525f73fSChenyi Qiang  * outside of the GEM object in a reserved memory area dedicated for the
630d525f73fSChenyi Qiang  * storage of the CCS data for all RC/RC_CC/MC compressible GEM objects. The
631d525f73fSChenyi Qiang  * main surface pitch is required to be a multiple of four Tile 4 widths.
632d525f73fSChenyi Qiang  */
633d525f73fSChenyi Qiang #define I915_FORMAT_MOD_4_TILED_DG2_RC_CCS fourcc_mod_code(INTEL, 10)
634d525f73fSChenyi Qiang 
635d525f73fSChenyi Qiang /*
636d525f73fSChenyi Qiang  * Intel color control surfaces (CCS) for DG2 media compression.
637d525f73fSChenyi Qiang  *
638d525f73fSChenyi Qiang  * The main surface is Tile 4 and at plane index 0. For semi-planar formats
639d525f73fSChenyi Qiang  * like NV12, the Y and UV planes are Tile 4 and are located at plane indices
640d525f73fSChenyi Qiang  * 0 and 1, respectively. The CCS for all planes are stored outside of the
641d525f73fSChenyi Qiang  * GEM object in a reserved memory area dedicated for the storage of the
642d525f73fSChenyi Qiang  * CCS data for all RC/RC_CC/MC compressible GEM objects. The main surface
643d525f73fSChenyi Qiang  * pitch is required to be a multiple of four Tile 4 widths.
644d525f73fSChenyi Qiang  */
645d525f73fSChenyi Qiang #define I915_FORMAT_MOD_4_TILED_DG2_MC_CCS fourcc_mod_code(INTEL, 11)
646d525f73fSChenyi Qiang 
647d525f73fSChenyi Qiang /*
648d525f73fSChenyi Qiang  * Intel Color Control Surface with Clear Color (CCS) for DG2 render compression.
649d525f73fSChenyi Qiang  *
650d525f73fSChenyi Qiang  * The main surface is Tile 4 and at plane index 0. The CCS data is stored
651d525f73fSChenyi Qiang  * outside of the GEM object in a reserved memory area dedicated for the
652d525f73fSChenyi Qiang  * storage of the CCS data for all RC/RC_CC/MC compressible GEM objects. The
653d525f73fSChenyi Qiang  * main surface pitch is required to be a multiple of four Tile 4 widths. The
654d525f73fSChenyi Qiang  * clear color is stored at plane index 1 and the pitch should be 64 bytes
655d525f73fSChenyi Qiang  * aligned. The format of the 256 bits of clear color data matches the one used
656d525f73fSChenyi Qiang  * for the I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC modifier, see its description
657d525f73fSChenyi Qiang  * for details.
658d525f73fSChenyi Qiang  */
659d525f73fSChenyi Qiang #define I915_FORMAT_MOD_4_TILED_DG2_RC_CCS_CC fourcc_mod_code(INTEL, 12)
660d525f73fSChenyi Qiang 
661d525f73fSChenyi Qiang /*
662d0bf492fSCédric Le Goater  * Intel Color Control Surfaces (CCS) for display ver. 14 render compression.
663d0bf492fSCédric Le Goater  *
664d0bf492fSCédric Le Goater  * The main surface is tile4 and at plane index 0, the CCS is linear and
665d0bf492fSCédric Le Goater  * at index 1. A 64B CCS cache line corresponds to an area of 4x1 tiles in
666d0bf492fSCédric Le Goater  * main surface. In other words, 4 bits in CCS map to a main surface cache
667d0bf492fSCédric Le Goater  * line pair. The main surface pitch is required to be a multiple of four
668d0bf492fSCédric Le Goater  * tile4 widths.
669d0bf492fSCédric Le Goater  */
670d0bf492fSCédric Le Goater #define I915_FORMAT_MOD_4_TILED_MTL_RC_CCS fourcc_mod_code(INTEL, 13)
671d0bf492fSCédric Le Goater 
672d0bf492fSCédric Le Goater /*
673d0bf492fSCédric Le Goater  * Intel Color Control Surfaces (CCS) for display ver. 14 media compression
674d0bf492fSCédric Le Goater  *
675d0bf492fSCédric Le Goater  * The main surface is tile4 and at plane index 0, the CCS is linear and
676d0bf492fSCédric Le Goater  * at index 1. A 64B CCS cache line corresponds to an area of 4x1 tiles in
677d0bf492fSCédric Le Goater  * main surface. In other words, 4 bits in CCS map to a main surface cache
678d0bf492fSCédric Le Goater  * line pair. The main surface pitch is required to be a multiple of four
679d0bf492fSCédric Le Goater  * tile4 widths. For semi-planar formats like NV12, CCS planes follow the
680d0bf492fSCédric Le Goater  * Y and UV planes i.e., planes 0 and 1 are used for Y and UV surfaces,
681d0bf492fSCédric Le Goater  * planes 2 and 3 for the respective CCS.
682d0bf492fSCédric Le Goater  */
683d0bf492fSCédric Le Goater #define I915_FORMAT_MOD_4_TILED_MTL_MC_CCS fourcc_mod_code(INTEL, 14)
684d0bf492fSCédric Le Goater 
685d0bf492fSCédric Le Goater /*
686d0bf492fSCédric Le Goater  * Intel Color Control Surface with Clear Color (CCS) for display ver. 14 render
687d0bf492fSCédric Le Goater  * compression.
688d0bf492fSCédric Le Goater  *
689d0bf492fSCédric Le Goater  * The main surface is tile4 and is at plane index 0 whereas CCS is linear
690d0bf492fSCédric Le Goater  * and at index 1. The clear color is stored at index 2, and the pitch should
691d0bf492fSCédric Le Goater  * be ignored. The clear color structure is 256 bits. The first 128 bits
692d0bf492fSCédric Le Goater  * represents Raw Clear Color Red, Green, Blue and Alpha color each represented
693d0bf492fSCédric Le Goater  * by 32 bits. The raw clear color is consumed by the 3d engine and generates
694d0bf492fSCédric Le Goater  * the converted clear color of size 64 bits. The first 32 bits store the Lower
695d0bf492fSCédric Le Goater  * Converted Clear Color value and the next 32 bits store the Higher Converted
696d0bf492fSCédric Le Goater  * Clear Color value when applicable. The Converted Clear Color values are
697d0bf492fSCédric Le Goater  * consumed by the DE. The last 64 bits are used to store Color Discard Enable
698d0bf492fSCédric Le Goater  * and Depth Clear Value Valid which are ignored by the DE. A CCS cache line
699d0bf492fSCédric Le Goater  * corresponds to an area of 4x1 tiles in the main surface. The main surface
700d0bf492fSCédric Le Goater  * pitch is required to be a multiple of 4 tile widths.
701d0bf492fSCédric Le Goater  */
702d0bf492fSCédric Le Goater #define I915_FORMAT_MOD_4_TILED_MTL_RC_CCS_CC fourcc_mod_code(INTEL, 15)
703d0bf492fSCédric Le Goater 
704d0bf492fSCédric Le Goater /*
7058e8ee850SGerd Hoffmann  * Tiled, NV12MT, grouped in 64 (pixels) x 32 (lines) -sized macroblocks
7068e8ee850SGerd Hoffmann  *
7078e8ee850SGerd Hoffmann  * Macroblocks are laid in a Z-shape, and each pixel data is following the
7088e8ee850SGerd Hoffmann  * standard NV12 style.
7098e8ee850SGerd Hoffmann  * As for NV12, an image is the result of two frame buffers: one for Y,
7108e8ee850SGerd Hoffmann  * one for the interleaved Cb/Cr components (1/2 the height of the Y buffer).
7118e8ee850SGerd Hoffmann  * Alignment requirements are (for each buffer):
7128e8ee850SGerd Hoffmann  * - multiple of 128 pixels for the width
7138e8ee850SGerd Hoffmann  * - multiple of  32 pixels for the height
7148e8ee850SGerd Hoffmann  *
7158e8ee850SGerd Hoffmann  * For more information: see https://linuxtv.org/downloads/v4l-dvb-apis/re32.html
7168e8ee850SGerd Hoffmann  */
7178e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_SAMSUNG_64_32_TILE	fourcc_mod_code(SAMSUNG, 1)
7188e8ee850SGerd Hoffmann 
719d36f7de8SCornelia Huck /*
720da054c64SPaolo Bonzini  * Tiled, 16 (pixels) x 16 (lines) - sized macroblocks
721da054c64SPaolo Bonzini  *
722da054c64SPaolo Bonzini  * This is a simple tiled layout using tiles of 16x16 pixels in a row-major
723da054c64SPaolo Bonzini  * layout. For YCbCr formats Cb/Cr components are taken in such a way that
724da054c64SPaolo Bonzini  * they correspond to their 16x16 luma block.
725da054c64SPaolo Bonzini  */
726da054c64SPaolo Bonzini #define DRM_FORMAT_MOD_SAMSUNG_16_16_TILE	fourcc_mod_code(SAMSUNG, 2)
727da054c64SPaolo Bonzini 
728da054c64SPaolo Bonzini /*
729d36f7de8SCornelia Huck  * Qualcomm Compressed Format
730d36f7de8SCornelia Huck  *
731d36f7de8SCornelia Huck  * Refers to a compressed variant of the base format that is compressed.
732d36f7de8SCornelia Huck  * Implementation may be platform and base-format specific.
733d36f7de8SCornelia Huck  *
734d36f7de8SCornelia Huck  * Each macrotile consists of m x n (mostly 4 x 4) tiles.
735d36f7de8SCornelia Huck  * Pixel data pitch/stride is aligned with macrotile width.
736d36f7de8SCornelia Huck  * Pixel data height is aligned with macrotile height.
737d36f7de8SCornelia Huck  * Entire pixel data buffer is aligned with 4k(bytes).
738d36f7de8SCornelia Huck  */
739d36f7de8SCornelia Huck #define DRM_FORMAT_MOD_QCOM_COMPRESSED	fourcc_mod_code(QCOM, 1)
740d36f7de8SCornelia Huck 
741d525f73fSChenyi Qiang /*
742d525f73fSChenyi Qiang  * Qualcomm Tiled Format
743d525f73fSChenyi Qiang  *
744d525f73fSChenyi Qiang  * Similar to DRM_FORMAT_MOD_QCOM_COMPRESSED but not compressed.
745d525f73fSChenyi Qiang  * Implementation may be platform and base-format specific.
746d525f73fSChenyi Qiang  *
747d525f73fSChenyi Qiang  * Each macrotile consists of m x n (mostly 4 x 4) tiles.
748d525f73fSChenyi Qiang  * Pixel data pitch/stride is aligned with macrotile width.
749d525f73fSChenyi Qiang  * Pixel data height is aligned with macrotile height.
750d525f73fSChenyi Qiang  * Entire pixel data buffer is aligned with 4k(bytes).
751d525f73fSChenyi Qiang  */
752d525f73fSChenyi Qiang #define DRM_FORMAT_MOD_QCOM_TILED3	fourcc_mod_code(QCOM, 3)
753d525f73fSChenyi Qiang 
754d525f73fSChenyi Qiang /*
755d525f73fSChenyi Qiang  * Qualcomm Alternate Tiled Format
756d525f73fSChenyi Qiang  *
757d525f73fSChenyi Qiang  * Alternate tiled format typically only used within GMEM.
758d525f73fSChenyi Qiang  * Implementation may be platform and base-format specific.
759d525f73fSChenyi Qiang  */
760d525f73fSChenyi Qiang #define DRM_FORMAT_MOD_QCOM_TILED2	fourcc_mod_code(QCOM, 2)
761d525f73fSChenyi Qiang 
762d525f73fSChenyi Qiang 
7638e8ee850SGerd Hoffmann /* Vivante framebuffer modifiers */
7648e8ee850SGerd Hoffmann 
7658e8ee850SGerd Hoffmann /*
7668e8ee850SGerd Hoffmann  * Vivante 4x4 tiling layout
7678e8ee850SGerd Hoffmann  *
7688e8ee850SGerd Hoffmann  * This is a simple tiled layout using tiles of 4x4 pixels in a row-major
7698e8ee850SGerd Hoffmann  * layout.
7708e8ee850SGerd Hoffmann  */
7718e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_VIVANTE_TILED		fourcc_mod_code(VIVANTE, 1)
7728e8ee850SGerd Hoffmann 
7738e8ee850SGerd Hoffmann /*
7748e8ee850SGerd Hoffmann  * Vivante 64x64 super-tiling layout
7758e8ee850SGerd Hoffmann  *
7768e8ee850SGerd Hoffmann  * This is a tiled layout using 64x64 pixel super-tiles, where each super-tile
7778e8ee850SGerd Hoffmann  * contains 8x4 groups of 2x4 tiles of 4x4 pixels (like above) each, all in row-
7788e8ee850SGerd Hoffmann  * major layout.
7798e8ee850SGerd Hoffmann  *
7808e8ee850SGerd Hoffmann  * For more information: see
7818e8ee850SGerd Hoffmann  * https://github.com/etnaviv/etna_viv/blob/master/doc/hardware.md#texture-tiling
7828e8ee850SGerd Hoffmann  */
7838e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_VIVANTE_SUPER_TILED	fourcc_mod_code(VIVANTE, 2)
7848e8ee850SGerd Hoffmann 
7858e8ee850SGerd Hoffmann /*
7868e8ee850SGerd Hoffmann  * Vivante 4x4 tiling layout for dual-pipe
7878e8ee850SGerd Hoffmann  *
7888e8ee850SGerd Hoffmann  * Same as the 4x4 tiling layout, except every second 4x4 pixel tile starts at a
7898e8ee850SGerd Hoffmann  * different base address. Offsets from the base addresses are therefore halved
7908e8ee850SGerd Hoffmann  * compared to the non-split tiled layout.
7918e8ee850SGerd Hoffmann  */
7928e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_VIVANTE_SPLIT_TILED	fourcc_mod_code(VIVANTE, 3)
7938e8ee850SGerd Hoffmann 
7948e8ee850SGerd Hoffmann /*
7958e8ee850SGerd Hoffmann  * Vivante 64x64 super-tiling layout for dual-pipe
7968e8ee850SGerd Hoffmann  *
7978e8ee850SGerd Hoffmann  * Same as the 64x64 super-tiling layout, except every second 4x4 pixel tile
7988e8ee850SGerd Hoffmann  * starts at a different base address. Offsets from the base addresses are
7998e8ee850SGerd Hoffmann  * therefore halved compared to the non-split super-tiled layout.
8008e8ee850SGerd Hoffmann  */
8018e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_VIVANTE_SPLIT_SUPER_TILED fourcc_mod_code(VIVANTE, 4)
8028e8ee850SGerd Hoffmann 
80393d7620cSAvihai Horon /*
80493d7620cSAvihai Horon  * Vivante TS (tile-status) buffer modifiers. They can be combined with all of
80593d7620cSAvihai Horon  * the color buffer tiling modifiers defined above. When TS is present it's a
80693d7620cSAvihai Horon  * separate buffer containing the clear/compression status of each tile. The
80793d7620cSAvihai Horon  * modifiers are defined as VIVANTE_MOD_TS_c_s, where c is the color buffer
80893d7620cSAvihai Horon  * tile size in bytes covered by one entry in the status buffer and s is the
80993d7620cSAvihai Horon  * number of status bits per entry.
81093d7620cSAvihai Horon  * We reserve the top 8 bits of the Vivante modifier space for tile status
81193d7620cSAvihai Horon  * clear/compression modifiers, as future cores might add some more TS layout
81293d7620cSAvihai Horon  * variations.
81393d7620cSAvihai Horon  */
81493d7620cSAvihai Horon #define VIVANTE_MOD_TS_64_4               (1ULL << 48)
81593d7620cSAvihai Horon #define VIVANTE_MOD_TS_64_2               (2ULL << 48)
81693d7620cSAvihai Horon #define VIVANTE_MOD_TS_128_4              (3ULL << 48)
81793d7620cSAvihai Horon #define VIVANTE_MOD_TS_256_4              (4ULL << 48)
81893d7620cSAvihai Horon #define VIVANTE_MOD_TS_MASK               (0xfULL << 48)
81993d7620cSAvihai Horon 
82093d7620cSAvihai Horon /*
82193d7620cSAvihai Horon  * Vivante compression modifiers. Those depend on a TS modifier being present
82293d7620cSAvihai Horon  * as the TS bits get reinterpreted as compression tags instead of simple
82393d7620cSAvihai Horon  * clear markers when compression is enabled.
82493d7620cSAvihai Horon  */
82593d7620cSAvihai Horon #define VIVANTE_MOD_COMP_DEC400           (1ULL << 52)
82693d7620cSAvihai Horon #define VIVANTE_MOD_COMP_MASK             (0xfULL << 52)
82793d7620cSAvihai Horon 
82893d7620cSAvihai Horon /* Masking out the extension bits will yield the base modifier. */
82993d7620cSAvihai Horon #define VIVANTE_MOD_EXT_MASK              (VIVANTE_MOD_TS_MASK | \
83093d7620cSAvihai Horon                                            VIVANTE_MOD_COMP_MASK)
83193d7620cSAvihai Horon 
8328e8ee850SGerd Hoffmann /* NVIDIA frame buffer modifiers */
8338e8ee850SGerd Hoffmann 
8348e8ee850SGerd Hoffmann /*
8358e8ee850SGerd Hoffmann  * Tegra Tiled Layout, used by Tegra 2, 3 and 4.
8368e8ee850SGerd Hoffmann  *
8378e8ee850SGerd Hoffmann  * Pixels are arranged in simple tiles of 16 x 16 bytes.
8388e8ee850SGerd Hoffmann  */
8398e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_NVIDIA_TEGRA_TILED fourcc_mod_code(NVIDIA, 1)
8408e8ee850SGerd Hoffmann 
8418e8ee850SGerd Hoffmann /*
842f76b348eSCornelia Huck  * Generalized Block Linear layout, used by desktop GPUs starting with NV50/G80,
843f76b348eSCornelia Huck  * and Tegra GPUs starting with Tegra K1.
844f76b348eSCornelia Huck  *
845f76b348eSCornelia Huck  * Pixels are arranged in Groups of Bytes (GOBs).  GOB size and layout varies
846f76b348eSCornelia Huck  * based on the architecture generation.  GOBs themselves are then arranged in
847f76b348eSCornelia Huck  * 3D blocks, with the block dimensions (in terms of GOBs) always being a power
848f76b348eSCornelia Huck  * of two, and hence expressible as their log2 equivalent (E.g., "2" represents
849f76b348eSCornelia Huck  * a block depth or height of "4").
850f76b348eSCornelia Huck  *
851f76b348eSCornelia Huck  * Chapter 20 "Pixel Memory Formats" of the Tegra X1 TRM describes this format
852f76b348eSCornelia Huck  * in full detail.
853f76b348eSCornelia Huck  *
854f76b348eSCornelia Huck  *       Macro
855f76b348eSCornelia Huck  * Bits  Param Description
856f76b348eSCornelia Huck  * ----  ----- -----------------------------------------------------------------
857f76b348eSCornelia Huck  *
858f76b348eSCornelia Huck  *  3:0  h     log2(height) of each block, in GOBs.  Placed here for
859f76b348eSCornelia Huck  *             compatibility with the existing
860f76b348eSCornelia Huck  *             DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK()-based modifiers.
861f76b348eSCornelia Huck  *
862f76b348eSCornelia Huck  *  4:4  -     Must be 1, to indicate block-linear layout.  Necessary for
863f76b348eSCornelia Huck  *             compatibility with the existing
864f76b348eSCornelia Huck  *             DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK()-based modifiers.
865f76b348eSCornelia Huck  *
866f76b348eSCornelia Huck  *  8:5  -     Reserved (To support 3D-surfaces with variable log2(depth) block
867f76b348eSCornelia Huck  *             size).  Must be zero.
868f76b348eSCornelia Huck  *
869f76b348eSCornelia Huck  *             Note there is no log2(width) parameter.  Some portions of the
870f76b348eSCornelia Huck  *             hardware support a block width of two gobs, but it is impractical
871f76b348eSCornelia Huck  *             to use due to lack of support elsewhere, and has no known
872f76b348eSCornelia Huck  *             benefits.
873f76b348eSCornelia Huck  *
874f76b348eSCornelia Huck  * 11:9  -     Reserved (To support 2D-array textures with variable array stride
875f76b348eSCornelia Huck  *             in blocks, specified via log2(tile width in blocks)).  Must be
876f76b348eSCornelia Huck  *             zero.
877f76b348eSCornelia Huck  *
878f76b348eSCornelia Huck  * 19:12 k     Page Kind.  This value directly maps to a field in the page
879f76b348eSCornelia Huck  *             tables of all GPUs >= NV50.  It affects the exact layout of bits
880f76b348eSCornelia Huck  *             in memory and can be derived from the tuple
881f76b348eSCornelia Huck  *
882f76b348eSCornelia Huck  *               (format, GPU model, compression type, samples per pixel)
883f76b348eSCornelia Huck  *
884f76b348eSCornelia Huck  *             Where compression type is defined below.  If GPU model were
885f76b348eSCornelia Huck  *             implied by the format modifier, format, or memory buffer, page
886f76b348eSCornelia Huck  *             kind would not need to be included in the modifier itself, but
887f76b348eSCornelia Huck  *             since the modifier should define the layout of the associated
888f76b348eSCornelia Huck  *             memory buffer independent from any device or other context, it
889f76b348eSCornelia Huck  *             must be included here.
890f76b348eSCornelia Huck  *
891f76b348eSCornelia Huck  * 21:20 g     GOB Height and Page Kind Generation.  The height of a GOB changed
892f76b348eSCornelia Huck  *             starting with Fermi GPUs.  Additionally, the mapping between page
893f76b348eSCornelia Huck  *             kind and bit layout has changed at various points.
894f76b348eSCornelia Huck  *
895f76b348eSCornelia Huck  *               0 = Gob Height 8, Fermi - Volta, Tegra K1+ Page Kind mapping
896f76b348eSCornelia Huck  *               1 = Gob Height 4, G80 - GT2XX Page Kind mapping
897f76b348eSCornelia Huck  *               2 = Gob Height 8, Turing+ Page Kind mapping
898f76b348eSCornelia Huck  *               3 = Reserved for future use.
899f76b348eSCornelia Huck  *
900f76b348eSCornelia Huck  * 22:22 s     Sector layout.  On Tegra GPUs prior to Xavier, there is a further
901f76b348eSCornelia Huck  *             bit remapping step that occurs at an even lower level than the
902f76b348eSCornelia Huck  *             page kind and block linear swizzles.  This causes the layout of
903f76b348eSCornelia Huck  *             surfaces mapped in those SOC's GPUs to be incompatible with the
904f76b348eSCornelia Huck  *             equivalent mapping on other GPUs in the same system.
905f76b348eSCornelia Huck  *
906f76b348eSCornelia Huck  *               0 = Tegra K1 - Tegra Parker/TX2 Layout.
907f76b348eSCornelia Huck  *               1 = Desktop GPU and Tegra Xavier+ Layout
908f76b348eSCornelia Huck  *
909f76b348eSCornelia Huck  * 25:23 c     Lossless Framebuffer Compression type.
910f76b348eSCornelia Huck  *
911f76b348eSCornelia Huck  *               0 = none
912f76b348eSCornelia Huck  *               1 = ROP/3D, layout 1, exact compression format implied by Page
913f76b348eSCornelia Huck  *                   Kind field
914f76b348eSCornelia Huck  *               2 = ROP/3D, layout 2, exact compression format implied by Page
915f76b348eSCornelia Huck  *                   Kind field
916f76b348eSCornelia Huck  *               3 = CDE horizontal
917f76b348eSCornelia Huck  *               4 = CDE vertical
918f76b348eSCornelia Huck  *               5 = Reserved for future use
919f76b348eSCornelia Huck  *               6 = Reserved for future use
920f76b348eSCornelia Huck  *               7 = Reserved for future use
921f76b348eSCornelia Huck  *
922f76b348eSCornelia Huck  * 55:25 -     Reserved for future use.  Must be zero.
923f76b348eSCornelia Huck  */
924f76b348eSCornelia Huck #define DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(c, s, g, k, h) \
925f76b348eSCornelia Huck 	fourcc_mod_code(NVIDIA, (0x10 | \
926f76b348eSCornelia Huck 				 ((h) & 0xf) | \
927f76b348eSCornelia Huck 				 (((k) & 0xff) << 12) | \
928f76b348eSCornelia Huck 				 (((g) & 0x3) << 20) | \
929f76b348eSCornelia Huck 				 (((s) & 0x1) << 22) | \
930f76b348eSCornelia Huck 				 (((c) & 0x7) << 23)))
931f76b348eSCornelia Huck 
932f76b348eSCornelia Huck /* To grandfather in prior block linear format modifiers to the above layout,
933f76b348eSCornelia Huck  * the page kind "0", which corresponds to "pitch/linear" and hence is unusable
934f76b348eSCornelia Huck  * with block-linear layouts, is remapped within drivers to the value 0xfe,
935f76b348eSCornelia Huck  * which corresponds to the "generic" kind used for simple single-sample
936f76b348eSCornelia Huck  * uncompressed color formats on Fermi - Volta GPUs.
937f76b348eSCornelia Huck  */
938f76b348eSCornelia Huck static inline uint64_t
drm_fourcc_canonicalize_nvidia_format_mod(uint64_t modifier)939f76b348eSCornelia Huck drm_fourcc_canonicalize_nvidia_format_mod(uint64_t modifier)
940f76b348eSCornelia Huck {
941f76b348eSCornelia Huck 	if (!(modifier & 0x10) || (modifier & (0xff << 12)))
942f76b348eSCornelia Huck 		return modifier;
943f76b348eSCornelia Huck 	else
944f76b348eSCornelia Huck 		return modifier | (0xfe << 12);
945f76b348eSCornelia Huck }
946f76b348eSCornelia Huck 
947f76b348eSCornelia Huck /*
948f76b348eSCornelia Huck  * 16Bx2 Block Linear layout, used by Tegra K1 and later
9498e8ee850SGerd Hoffmann  *
9508e8ee850SGerd Hoffmann  * Pixels are arranged in 64x8 Groups Of Bytes (GOBs). GOBs are then stacked
9518e8ee850SGerd Hoffmann  * vertically by a power of 2 (1 to 32 GOBs) to form a block.
9528e8ee850SGerd Hoffmann  *
9538e8ee850SGerd Hoffmann  * Within a GOB, data is ordered as 16B x 2 lines sectors laid in Z-shape.
9548e8ee850SGerd Hoffmann  *
9558e8ee850SGerd Hoffmann  * Parameter 'v' is the log2 encoding of the number of GOBs stacked vertically.
9568e8ee850SGerd Hoffmann  * Valid values are:
9578e8ee850SGerd Hoffmann  *
9588e8ee850SGerd Hoffmann  * 0 == ONE_GOB
9598e8ee850SGerd Hoffmann  * 1 == TWO_GOBS
9608e8ee850SGerd Hoffmann  * 2 == FOUR_GOBS
9618e8ee850SGerd Hoffmann  * 3 == EIGHT_GOBS
9628e8ee850SGerd Hoffmann  * 4 == SIXTEEN_GOBS
9638e8ee850SGerd Hoffmann  * 5 == THIRTYTWO_GOBS
9648e8ee850SGerd Hoffmann  *
9658e8ee850SGerd Hoffmann  * Chapter 20 "Pixel Memory Formats" of the Tegra X1 TRM describes this format
9668e8ee850SGerd Hoffmann  * in full detail.
9678e8ee850SGerd Hoffmann  */
9688e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(v) \
969f76b348eSCornelia Huck 	DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 0, 0, 0, (v))
9708e8ee850SGerd Hoffmann 
9718e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_ONE_GOB \
972f76b348eSCornelia Huck 	DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(0)
9738e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_TWO_GOB \
974f76b348eSCornelia Huck 	DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(1)
9758e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_FOUR_GOB \
976f76b348eSCornelia Huck 	DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(2)
9778e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_EIGHT_GOB \
978f76b348eSCornelia Huck 	DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(3)
9798e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_SIXTEEN_GOB \
980f76b348eSCornelia Huck 	DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(4)
9818e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_THIRTYTWO_GOB \
982f76b348eSCornelia Huck 	DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(5)
9838e8ee850SGerd Hoffmann 
9848e8ee850SGerd Hoffmann /*
985d36f7de8SCornelia Huck  * Some Broadcom modifiers take parameters, for example the number of
986d36f7de8SCornelia Huck  * vertical lines in the image. Reserve the lower 32 bits for modifier
987d36f7de8SCornelia Huck  * type, and the next 24 bits for parameters. Top 8 bits are the
988d36f7de8SCornelia Huck  * vendor code.
989d36f7de8SCornelia Huck  */
990d36f7de8SCornelia Huck #define __fourcc_mod_broadcom_param_shift 8
991d36f7de8SCornelia Huck #define __fourcc_mod_broadcom_param_bits 48
992d36f7de8SCornelia Huck #define fourcc_mod_broadcom_code(val, params) \
993d36f7de8SCornelia Huck 	fourcc_mod_code(BROADCOM, ((((uint64_t)params) << __fourcc_mod_broadcom_param_shift) | val))
994d36f7de8SCornelia Huck #define fourcc_mod_broadcom_param(m) \
995d36f7de8SCornelia Huck 	((int)(((m) >> __fourcc_mod_broadcom_param_shift) &	\
996d36f7de8SCornelia Huck 	       ((1ULL << __fourcc_mod_broadcom_param_bits) - 1)))
997d36f7de8SCornelia Huck #define fourcc_mod_broadcom_mod(m) \
998d36f7de8SCornelia Huck 	((m) & ~(((1ULL << __fourcc_mod_broadcom_param_bits) - 1) <<	\
999d36f7de8SCornelia Huck 		 __fourcc_mod_broadcom_param_shift))
1000d36f7de8SCornelia Huck 
1001d36f7de8SCornelia Huck /*
10028e8ee850SGerd Hoffmann  * Broadcom VC4 "T" format
10038e8ee850SGerd Hoffmann  *
10048e8ee850SGerd Hoffmann  * This is the primary layout that the V3D GPU can texture from (it
10058e8ee850SGerd Hoffmann  * can't do linear).  The T format has:
10068e8ee850SGerd Hoffmann  *
10078e8ee850SGerd Hoffmann  * - 64b utiles of pixels in a raster-order grid according to cpp.  It's 4x4
10088e8ee850SGerd Hoffmann  *   pixels at 32 bit depth.
10098e8ee850SGerd Hoffmann  *
10108e8ee850SGerd Hoffmann  * - 1k subtiles made of a 4x4 raster-order grid of 64b utiles (so usually
10118e8ee850SGerd Hoffmann  *   16x16 pixels).
10128e8ee850SGerd Hoffmann  *
10138e8ee850SGerd Hoffmann  * - 4k tiles made of a 2x2 grid of 1k subtiles (so usually 32x32 pixels).  On
10148e8ee850SGerd Hoffmann  *   even 4k tile rows, they're arranged as (BL, TL, TR, BR), and on odd rows
10158e8ee850SGerd Hoffmann  *   they're (TR, BR, BL, TL), where bottom left is start of memory.
10168e8ee850SGerd Hoffmann  *
10178e8ee850SGerd Hoffmann  * - an image made of 4k tiles in rows either left-to-right (even rows of 4k
10188e8ee850SGerd Hoffmann  *   tiles) or right-to-left (odd rows of 4k tiles).
10198e8ee850SGerd Hoffmann  */
10208e8ee850SGerd Hoffmann #define DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED fourcc_mod_code(BROADCOM, 1)
10218e8ee850SGerd Hoffmann 
1022d36f7de8SCornelia Huck /*
1023d36f7de8SCornelia Huck  * Broadcom SAND format
1024d36f7de8SCornelia Huck  *
1025d36f7de8SCornelia Huck  * This is the native format that the H.264 codec block uses.  For VC4
1026d36f7de8SCornelia Huck  * HVS, it is only valid for H.264 (NV12/21) and RGBA modes.
1027d36f7de8SCornelia Huck  *
1028d36f7de8SCornelia Huck  * The image can be considered to be split into columns, and the
1029d36f7de8SCornelia Huck  * columns are placed consecutively into memory.  The width of those
1030d36f7de8SCornelia Huck  * columns can be either 32, 64, 128, or 256 pixels, but in practice
1031d36f7de8SCornelia Huck  * only 128 pixel columns are used.
1032d36f7de8SCornelia Huck  *
1033d36f7de8SCornelia Huck  * The pitch between the start of each column is set to optimally
1034d36f7de8SCornelia Huck  * switch between SDRAM banks. This is passed as the number of lines
1035d36f7de8SCornelia Huck  * of column width in the modifier (we can't use the stride value due
1036d36f7de8SCornelia Huck  * to various core checks that look at it , so you should set the
1037d36f7de8SCornelia Huck  * stride to width*cpp).
1038d36f7de8SCornelia Huck  *
1039d36f7de8SCornelia Huck  * Note that the column height for this format modifier is the same
1040d36f7de8SCornelia Huck  * for all of the planes, assuming that each column contains both Y
1041d36f7de8SCornelia Huck  * and UV.  Some SAND-using hardware stores UV in a separate tiled
1042d36f7de8SCornelia Huck  * image from Y to reduce the column height, which is not supported
1043d36f7de8SCornelia Huck  * with these modifiers.
1044ef17dd6aSVivek Goyal  *
1045ef17dd6aSVivek Goyal  * The DRM_FORMAT_MOD_BROADCOM_SAND128_COL_HEIGHT modifier is also
1046ef17dd6aSVivek Goyal  * supported for DRM_FORMAT_P030 where the columns remain as 128 bytes
1047ef17dd6aSVivek Goyal  * wide, but as this is a 10 bpp format that translates to 96 pixels.
1048d36f7de8SCornelia Huck  */
1049d36f7de8SCornelia Huck 
1050d36f7de8SCornelia Huck #define DRM_FORMAT_MOD_BROADCOM_SAND32_COL_HEIGHT(v) \
1051d36f7de8SCornelia Huck 	fourcc_mod_broadcom_code(2, v)
1052d36f7de8SCornelia Huck #define DRM_FORMAT_MOD_BROADCOM_SAND64_COL_HEIGHT(v) \
1053d36f7de8SCornelia Huck 	fourcc_mod_broadcom_code(3, v)
1054d36f7de8SCornelia Huck #define DRM_FORMAT_MOD_BROADCOM_SAND128_COL_HEIGHT(v) \
1055d36f7de8SCornelia Huck 	fourcc_mod_broadcom_code(4, v)
1056d36f7de8SCornelia Huck #define DRM_FORMAT_MOD_BROADCOM_SAND256_COL_HEIGHT(v) \
1057d36f7de8SCornelia Huck 	fourcc_mod_broadcom_code(5, v)
1058d36f7de8SCornelia Huck 
1059d36f7de8SCornelia Huck #define DRM_FORMAT_MOD_BROADCOM_SAND32 \
1060d36f7de8SCornelia Huck 	DRM_FORMAT_MOD_BROADCOM_SAND32_COL_HEIGHT(0)
1061d36f7de8SCornelia Huck #define DRM_FORMAT_MOD_BROADCOM_SAND64 \
1062d36f7de8SCornelia Huck 	DRM_FORMAT_MOD_BROADCOM_SAND64_COL_HEIGHT(0)
1063d36f7de8SCornelia Huck #define DRM_FORMAT_MOD_BROADCOM_SAND128 \
1064d36f7de8SCornelia Huck 	DRM_FORMAT_MOD_BROADCOM_SAND128_COL_HEIGHT(0)
1065d36f7de8SCornelia Huck #define DRM_FORMAT_MOD_BROADCOM_SAND256 \
1066d36f7de8SCornelia Huck 	DRM_FORMAT_MOD_BROADCOM_SAND256_COL_HEIGHT(0)
1067d36f7de8SCornelia Huck 
1068d36f7de8SCornelia Huck /* Broadcom UIF format
1069d36f7de8SCornelia Huck  *
1070d36f7de8SCornelia Huck  * This is the common format for the current Broadcom multimedia
1071d36f7de8SCornelia Huck  * blocks, including V3D 3.x and newer, newer video codecs, and
1072d36f7de8SCornelia Huck  * displays.
1073d36f7de8SCornelia Huck  *
1074d36f7de8SCornelia Huck  * The image consists of utiles (64b blocks), UIF blocks (2x2 utiles),
1075d36f7de8SCornelia Huck  * and macroblocks (4x4 UIF blocks).  Those 4x4 UIF block groups are
1076d36f7de8SCornelia Huck  * stored in columns, with padding between the columns to ensure that
1077d36f7de8SCornelia Huck  * moving from one column to the next doesn't hit the same SDRAM page
1078d36f7de8SCornelia Huck  * bank.
1079d36f7de8SCornelia Huck  *
1080d36f7de8SCornelia Huck  * To calculate the padding, it is assumed that each hardware block
1081d36f7de8SCornelia Huck  * and the software driving it knows the platform's SDRAM page size,
1082d36f7de8SCornelia Huck  * number of banks, and XOR address, and that it's identical between
1083d36f7de8SCornelia Huck  * all blocks using the format.  This tiling modifier will use XOR as
1084d36f7de8SCornelia Huck  * necessary to reduce the padding.  If a hardware block can't do XOR,
1085d36f7de8SCornelia Huck  * the assumption is that a no-XOR tiling modifier will be created.
1086d36f7de8SCornelia Huck  */
1087d36f7de8SCornelia Huck #define DRM_FORMAT_MOD_BROADCOM_UIF fourcc_mod_code(BROADCOM, 6)
1088d36f7de8SCornelia Huck 
1089d36f7de8SCornelia Huck /*
1090d36f7de8SCornelia Huck  * Arm Framebuffer Compression (AFBC) modifiers
1091d36f7de8SCornelia Huck  *
1092d36f7de8SCornelia Huck  * AFBC is a proprietary lossless image compression protocol and format.
1093d36f7de8SCornelia Huck  * It provides fine-grained random access and minimizes the amount of data
1094d36f7de8SCornelia Huck  * transferred between IP blocks.
1095d36f7de8SCornelia Huck  *
1096d36f7de8SCornelia Huck  * AFBC has several features which may be supported and/or used, which are
1097d36f7de8SCornelia Huck  * represented using bits in the modifier. Not all combinations are valid,
1098d36f7de8SCornelia Huck  * and different devices or use-cases may support different combinations.
1099d9cb4336SCornelia Huck  *
1100d9cb4336SCornelia Huck  * Further information on the use of AFBC modifiers can be found in
1101d9cb4336SCornelia Huck  * Documentation/gpu/afbc.rst
1102d36f7de8SCornelia Huck  */
110350fd0c37SBharata B Rao 
110450fd0c37SBharata B Rao /*
1105*6a02465fSDaniel Henrique Barboza  * The top 4 bits (out of the 56 bits allotted for specifying vendor specific
110643709a0cSPaolo Bonzini  * modifiers) denote the category for modifiers. Currently we have three
110743709a0cSPaolo Bonzini  * categories of modifiers ie AFBC, MISC and AFRC. We can have a maximum of
110843709a0cSPaolo Bonzini  * sixteen different categories.
110950fd0c37SBharata B Rao  */
111050fd0c37SBharata B Rao #define DRM_FORMAT_MOD_ARM_CODE(__type, __val) \
111150fd0c37SBharata B Rao 	fourcc_mod_code(ARM, ((uint64_t)(__type) << 52) | ((__val) & 0x000fffffffffffffULL))
111250fd0c37SBharata B Rao 
111350fd0c37SBharata B Rao #define DRM_FORMAT_MOD_ARM_TYPE_AFBC 0x00
111450fd0c37SBharata B Rao #define DRM_FORMAT_MOD_ARM_TYPE_MISC 0x01
111550fd0c37SBharata B Rao 
111650fd0c37SBharata B Rao #define DRM_FORMAT_MOD_ARM_AFBC(__afbc_mode) \
111750fd0c37SBharata B Rao 	DRM_FORMAT_MOD_ARM_CODE(DRM_FORMAT_MOD_ARM_TYPE_AFBC, __afbc_mode)
1118d36f7de8SCornelia Huck 
1119d36f7de8SCornelia Huck /*
1120d36f7de8SCornelia Huck  * AFBC superblock size
1121d36f7de8SCornelia Huck  *
1122d36f7de8SCornelia Huck  * Indicates the superblock size(s) used for the AFBC buffer. The buffer
1123d36f7de8SCornelia Huck  * size (in pixels) must be aligned to a multiple of the superblock size.
1124d36f7de8SCornelia Huck  * Four lowest significant bits(LSBs) are reserved for block size.
1125d9cb4336SCornelia Huck  *
1126d9cb4336SCornelia Huck  * Where one superblock size is specified, it applies to all planes of the
1127d9cb4336SCornelia Huck  * buffer (e.g. 16x16, 32x8). When multiple superblock sizes are specified,
1128d9cb4336SCornelia Huck  * the first applies to the Luma plane and the second applies to the Chroma
1129d9cb4336SCornelia Huck  * plane(s). e.g. (32x8_64x4 means 32x8 Luma, with 64x4 Chroma).
1130d9cb4336SCornelia Huck  * Multiple superblock sizes are only valid for multi-plane YCbCr formats.
1131d36f7de8SCornelia Huck  */
1132d36f7de8SCornelia Huck #define AFBC_FORMAT_MOD_BLOCK_SIZE_MASK      0xf
1133d36f7de8SCornelia Huck #define AFBC_FORMAT_MOD_BLOCK_SIZE_16x16     (1ULL)
1134d36f7de8SCornelia Huck #define AFBC_FORMAT_MOD_BLOCK_SIZE_32x8      (2ULL)
1135d9cb4336SCornelia Huck #define AFBC_FORMAT_MOD_BLOCK_SIZE_64x4      (3ULL)
1136d9cb4336SCornelia Huck #define AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4 (4ULL)
1137d36f7de8SCornelia Huck 
1138d36f7de8SCornelia Huck /*
1139d36f7de8SCornelia Huck  * AFBC lossless colorspace transform
1140d36f7de8SCornelia Huck  *
1141d36f7de8SCornelia Huck  * Indicates that the buffer makes use of the AFBC lossless colorspace
1142d36f7de8SCornelia Huck  * transform.
1143d36f7de8SCornelia Huck  */
1144d36f7de8SCornelia Huck #define AFBC_FORMAT_MOD_YTR     (1ULL <<  4)
1145d36f7de8SCornelia Huck 
1146d36f7de8SCornelia Huck /*
1147d36f7de8SCornelia Huck  * AFBC block-split
1148d36f7de8SCornelia Huck  *
1149d36f7de8SCornelia Huck  * Indicates that the payload of each superblock is split. The second
1150d36f7de8SCornelia Huck  * half of the payload is positioned at a predefined offset from the start
1151d36f7de8SCornelia Huck  * of the superblock payload.
1152d36f7de8SCornelia Huck  */
1153d36f7de8SCornelia Huck #define AFBC_FORMAT_MOD_SPLIT   (1ULL <<  5)
1154d36f7de8SCornelia Huck 
1155d36f7de8SCornelia Huck /*
1156d36f7de8SCornelia Huck  * AFBC sparse layout
1157d36f7de8SCornelia Huck  *
1158d36f7de8SCornelia Huck  * This flag indicates that the payload of each superblock must be stored at a
1159d36f7de8SCornelia Huck  * predefined position relative to the other superblocks in the same AFBC
1160d36f7de8SCornelia Huck  * buffer. This order is the same order used by the header buffer. In this mode
1161d36f7de8SCornelia Huck  * each superblock is given the same amount of space as an uncompressed
1162d36f7de8SCornelia Huck  * superblock of the particular format would require, rounding up to the next
1163d36f7de8SCornelia Huck  * multiple of 128 bytes in size.
1164d36f7de8SCornelia Huck  */
1165d36f7de8SCornelia Huck #define AFBC_FORMAT_MOD_SPARSE  (1ULL <<  6)
1166d36f7de8SCornelia Huck 
1167d36f7de8SCornelia Huck /*
1168d36f7de8SCornelia Huck  * AFBC copy-block restrict
1169d36f7de8SCornelia Huck  *
1170d36f7de8SCornelia Huck  * Buffers with this flag must obey the copy-block restriction. The restriction
1171d36f7de8SCornelia Huck  * is such that there are no copy-blocks referring across the border of 8x8
1172d36f7de8SCornelia Huck  * blocks. For the subsampled data the 8x8 limitation is also subsampled.
1173d36f7de8SCornelia Huck  */
1174d36f7de8SCornelia Huck #define AFBC_FORMAT_MOD_CBR     (1ULL <<  7)
1175d36f7de8SCornelia Huck 
1176d36f7de8SCornelia Huck /*
1177d36f7de8SCornelia Huck  * AFBC tiled layout
1178d36f7de8SCornelia Huck  *
1179d36f7de8SCornelia Huck  * The tiled layout groups superblocks in 8x8 or 4x4 tiles, where all
1180d36f7de8SCornelia Huck  * superblocks inside a tile are stored together in memory. 8x8 tiles are used
1181d36f7de8SCornelia Huck  * for pixel formats up to and including 32 bpp while 4x4 tiles are used for
1182d36f7de8SCornelia Huck  * larger bpp formats. The order between the tiles is scan line.
1183d36f7de8SCornelia Huck  * When the tiled layout is used, the buffer size (in pixels) must be aligned
1184d36f7de8SCornelia Huck  * to the tile size.
1185d36f7de8SCornelia Huck  */
1186d36f7de8SCornelia Huck #define AFBC_FORMAT_MOD_TILED   (1ULL <<  8)
1187d36f7de8SCornelia Huck 
1188d36f7de8SCornelia Huck /*
1189d36f7de8SCornelia Huck  * AFBC solid color blocks
1190d36f7de8SCornelia Huck  *
1191d36f7de8SCornelia Huck  * Indicates that the buffer makes use of solid-color blocks, whereby bandwidth
1192d36f7de8SCornelia Huck  * can be reduced if a whole superblock is a single color.
1193d36f7de8SCornelia Huck  */
1194d36f7de8SCornelia Huck #define AFBC_FORMAT_MOD_SC      (1ULL <<  9)
1195d36f7de8SCornelia Huck 
1196d9cb4336SCornelia Huck /*
1197d9cb4336SCornelia Huck  * AFBC double-buffer
1198d9cb4336SCornelia Huck  *
1199d9cb4336SCornelia Huck  * Indicates that the buffer is allocated in a layout safe for front-buffer
1200d9cb4336SCornelia Huck  * rendering.
1201d9cb4336SCornelia Huck  */
1202d9cb4336SCornelia Huck #define AFBC_FORMAT_MOD_DB      (1ULL << 10)
1203d9cb4336SCornelia Huck 
1204d9cb4336SCornelia Huck /*
1205d9cb4336SCornelia Huck  * AFBC buffer content hints
1206d9cb4336SCornelia Huck  *
1207d9cb4336SCornelia Huck  * Indicates that the buffer includes per-superblock content hints.
1208d9cb4336SCornelia Huck  */
1209d9cb4336SCornelia Huck #define AFBC_FORMAT_MOD_BCH     (1ULL << 11)
1210d9cb4336SCornelia Huck 
1211e6546342SJason Wang /* AFBC uncompressed storage mode
1212e6546342SJason Wang  *
1213e6546342SJason Wang  * Indicates that the buffer is using AFBC uncompressed storage mode.
1214e6546342SJason Wang  * In this mode all superblock payloads in the buffer use the uncompressed
1215e6546342SJason Wang  * storage mode, which is usually only used for data which cannot be compressed.
1216e6546342SJason Wang  * The buffer layout is the same as for AFBC buffers without USM set, this only
1217e6546342SJason Wang  * affects the storage mode of the individual superblocks. Note that even a
1218e6546342SJason Wang  * buffer without USM set may use uncompressed storage mode for some or all
1219e6546342SJason Wang  * superblocks, USM just guarantees it for all.
1220e6546342SJason Wang  */
1221e6546342SJason Wang #define AFBC_FORMAT_MOD_USM	(1ULL << 12)
1222e6546342SJason Wang 
1223d9cb4336SCornelia Huck /*
122443709a0cSPaolo Bonzini  * Arm Fixed-Rate Compression (AFRC) modifiers
122543709a0cSPaolo Bonzini  *
122643709a0cSPaolo Bonzini  * AFRC is a proprietary fixed rate image compression protocol and format,
122743709a0cSPaolo Bonzini  * designed to provide guaranteed bandwidth and memory footprint
122843709a0cSPaolo Bonzini  * reductions in graphics and media use-cases.
122943709a0cSPaolo Bonzini  *
123043709a0cSPaolo Bonzini  * AFRC buffers consist of one or more planes, with the same components
123143709a0cSPaolo Bonzini  * and meaning as an uncompressed buffer using the same pixel format.
123243709a0cSPaolo Bonzini  *
123343709a0cSPaolo Bonzini  * Within each plane, the pixel/luma/chroma values are grouped into
123443709a0cSPaolo Bonzini  * "coding unit" blocks which are individually compressed to a
123543709a0cSPaolo Bonzini  * fixed size (in bytes). All coding units within a given plane of a buffer
123643709a0cSPaolo Bonzini  * store the same number of values, and have the same compressed size.
123743709a0cSPaolo Bonzini  *
123843709a0cSPaolo Bonzini  * The coding unit size is configurable, allowing different rates of compression.
123943709a0cSPaolo Bonzini  *
124043709a0cSPaolo Bonzini  * The start of each AFRC buffer plane must be aligned to an alignment granule which
124143709a0cSPaolo Bonzini  * depends on the coding unit size.
124243709a0cSPaolo Bonzini  *
124343709a0cSPaolo Bonzini  * Coding Unit Size   Plane Alignment
124443709a0cSPaolo Bonzini  * ----------------   ---------------
124543709a0cSPaolo Bonzini  * 16 bytes           1024 bytes
124643709a0cSPaolo Bonzini  * 24 bytes           512  bytes
124743709a0cSPaolo Bonzini  * 32 bytes           2048 bytes
124843709a0cSPaolo Bonzini  *
124943709a0cSPaolo Bonzini  * Coding units are grouped into paging tiles. AFRC buffer dimensions must be aligned
125043709a0cSPaolo Bonzini  * to a multiple of the paging tile dimensions.
125143709a0cSPaolo Bonzini  * The dimensions of each paging tile depend on whether the buffer is optimised for
125243709a0cSPaolo Bonzini  * scanline (SCAN layout) or rotated (ROT layout) access.
125343709a0cSPaolo Bonzini  *
125443709a0cSPaolo Bonzini  * Layout   Paging Tile Width   Paging Tile Height
125543709a0cSPaolo Bonzini  * ------   -----------------   ------------------
125643709a0cSPaolo Bonzini  * SCAN     16 coding units     4 coding units
125743709a0cSPaolo Bonzini  * ROT      8  coding units     8 coding units
125843709a0cSPaolo Bonzini  *
125943709a0cSPaolo Bonzini  * The dimensions of each coding unit depend on the number of components
126043709a0cSPaolo Bonzini  * in the compressed plane and whether the buffer is optimised for
126143709a0cSPaolo Bonzini  * scanline (SCAN layout) or rotated (ROT layout) access.
126243709a0cSPaolo Bonzini  *
126343709a0cSPaolo Bonzini  * Number of Components in Plane   Layout      Coding Unit Width   Coding Unit Height
126443709a0cSPaolo Bonzini  * -----------------------------   ---------   -----------------   ------------------
126543709a0cSPaolo Bonzini  * 1                               SCAN        16 samples          4 samples
126643709a0cSPaolo Bonzini  * Example: 16x4 luma samples in a 'Y' plane
126743709a0cSPaolo Bonzini  *          16x4 chroma 'V' values, in the 'V' plane of a fully-planar YUV buffer
126843709a0cSPaolo Bonzini  * -----------------------------   ---------   -----------------   ------------------
126943709a0cSPaolo Bonzini  * 1                               ROT         8 samples           8 samples
127043709a0cSPaolo Bonzini  * Example: 8x8 luma samples in a 'Y' plane
127143709a0cSPaolo Bonzini  *          8x8 chroma 'V' values, in the 'V' plane of a fully-planar YUV buffer
127243709a0cSPaolo Bonzini  * -----------------------------   ---------   -----------------   ------------------
127343709a0cSPaolo Bonzini  * 2                               DONT CARE   8 samples           4 samples
127443709a0cSPaolo Bonzini  * Example: 8x4 chroma pairs in the 'UV' plane of a semi-planar YUV buffer
127543709a0cSPaolo Bonzini  * -----------------------------   ---------   -----------------   ------------------
127643709a0cSPaolo Bonzini  * 3                               DONT CARE   4 samples           4 samples
127743709a0cSPaolo Bonzini  * Example: 4x4 pixels in an RGB buffer without alpha
127843709a0cSPaolo Bonzini  * -----------------------------   ---------   -----------------   ------------------
127943709a0cSPaolo Bonzini  * 4                               DONT CARE   4 samples           4 samples
128043709a0cSPaolo Bonzini  * Example: 4x4 pixels in an RGB buffer with alpha
128143709a0cSPaolo Bonzini  */
128243709a0cSPaolo Bonzini 
128343709a0cSPaolo Bonzini #define DRM_FORMAT_MOD_ARM_TYPE_AFRC 0x02
128443709a0cSPaolo Bonzini 
128543709a0cSPaolo Bonzini #define DRM_FORMAT_MOD_ARM_AFRC(__afrc_mode) \
128643709a0cSPaolo Bonzini 	DRM_FORMAT_MOD_ARM_CODE(DRM_FORMAT_MOD_ARM_TYPE_AFRC, __afrc_mode)
128743709a0cSPaolo Bonzini 
128843709a0cSPaolo Bonzini /*
128943709a0cSPaolo Bonzini  * AFRC coding unit size modifier.
129043709a0cSPaolo Bonzini  *
129143709a0cSPaolo Bonzini  * Indicates the number of bytes used to store each compressed coding unit for
129243709a0cSPaolo Bonzini  * one or more planes in an AFRC encoded buffer. The coding unit size for chrominance
129343709a0cSPaolo Bonzini  * is the same for both Cb and Cr, which may be stored in separate planes.
129443709a0cSPaolo Bonzini  *
129543709a0cSPaolo Bonzini  * AFRC_FORMAT_MOD_CU_SIZE_P0 indicates the number of bytes used to store
129643709a0cSPaolo Bonzini  * each compressed coding unit in the first plane of the buffer. For RGBA buffers
129743709a0cSPaolo Bonzini  * this is the only plane, while for semi-planar and fully-planar YUV buffers,
129843709a0cSPaolo Bonzini  * this corresponds to the luma plane.
129943709a0cSPaolo Bonzini  *
130043709a0cSPaolo Bonzini  * AFRC_FORMAT_MOD_CU_SIZE_P12 indicates the number of bytes used to store
130143709a0cSPaolo Bonzini  * each compressed coding unit in the second and third planes in the buffer.
130243709a0cSPaolo Bonzini  * For semi-planar and fully-planar YUV buffers, this corresponds to the chroma plane(s).
130343709a0cSPaolo Bonzini  *
130443709a0cSPaolo Bonzini  * For single-plane buffers, AFRC_FORMAT_MOD_CU_SIZE_P0 must be specified
130543709a0cSPaolo Bonzini  * and AFRC_FORMAT_MOD_CU_SIZE_P12 must be zero.
130643709a0cSPaolo Bonzini  * For semi-planar and fully-planar buffers, both AFRC_FORMAT_MOD_CU_SIZE_P0 and
130743709a0cSPaolo Bonzini  * AFRC_FORMAT_MOD_CU_SIZE_P12 must be specified.
130843709a0cSPaolo Bonzini  */
130943709a0cSPaolo Bonzini #define AFRC_FORMAT_MOD_CU_SIZE_MASK 0xf
131043709a0cSPaolo Bonzini #define AFRC_FORMAT_MOD_CU_SIZE_16 (1ULL)
131143709a0cSPaolo Bonzini #define AFRC_FORMAT_MOD_CU_SIZE_24 (2ULL)
131243709a0cSPaolo Bonzini #define AFRC_FORMAT_MOD_CU_SIZE_32 (3ULL)
131343709a0cSPaolo Bonzini 
131443709a0cSPaolo Bonzini #define AFRC_FORMAT_MOD_CU_SIZE_P0(__afrc_cu_size) (__afrc_cu_size)
131543709a0cSPaolo Bonzini #define AFRC_FORMAT_MOD_CU_SIZE_P12(__afrc_cu_size) ((__afrc_cu_size) << 4)
131643709a0cSPaolo Bonzini 
131743709a0cSPaolo Bonzini /*
131843709a0cSPaolo Bonzini  * AFRC scanline memory layout.
131943709a0cSPaolo Bonzini  *
132043709a0cSPaolo Bonzini  * Indicates if the buffer uses the scanline-optimised layout
132143709a0cSPaolo Bonzini  * for an AFRC encoded buffer, otherwise, it uses the rotation-optimised layout.
132243709a0cSPaolo Bonzini  * The memory layout is the same for all planes.
132343709a0cSPaolo Bonzini  */
132443709a0cSPaolo Bonzini #define AFRC_FORMAT_MOD_LAYOUT_SCAN (1ULL << 8)
132543709a0cSPaolo Bonzini 
132643709a0cSPaolo Bonzini /*
132750fd0c37SBharata B Rao  * Arm 16x16 Block U-Interleaved modifier
132850fd0c37SBharata B Rao  *
132950fd0c37SBharata B Rao  * This is used by Arm Mali Utgard and Midgard GPUs. It divides the image
133050fd0c37SBharata B Rao  * into 16x16 pixel blocks. Blocks are stored linearly in order, but pixels
133150fd0c37SBharata B Rao  * in the block are reordered.
133250fd0c37SBharata B Rao  */
133350fd0c37SBharata B Rao #define DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED \
133450fd0c37SBharata B Rao 	DRM_FORMAT_MOD_ARM_CODE(DRM_FORMAT_MOD_ARM_TYPE_MISC, 1ULL)
133550fd0c37SBharata B Rao 
133650fd0c37SBharata B Rao /*
1337d9cb4336SCornelia Huck  * Allwinner tiled modifier
1338d9cb4336SCornelia Huck  *
1339d9cb4336SCornelia Huck  * This tiling mode is implemented by the VPU found on all Allwinner platforms,
1340d9cb4336SCornelia Huck  * codenamed sunxi. It is associated with a YUV format that uses either 2 or 3
1341d9cb4336SCornelia Huck  * planes.
1342d9cb4336SCornelia Huck  *
1343d9cb4336SCornelia Huck  * With this tiling, the luminance samples are disposed in tiles representing
1344d9cb4336SCornelia Huck  * 32x32 pixels and the chrominance samples in tiles representing 32x64 pixels.
1345d9cb4336SCornelia Huck  * The pixel order in each tile is linear and the tiles are disposed linearly,
1346d9cb4336SCornelia Huck  * both in row-major order.
1347d9cb4336SCornelia Huck  */
1348d9cb4336SCornelia Huck #define DRM_FORMAT_MOD_ALLWINNER_TILED fourcc_mod_code(ALLWINNER, 1)
1349d9cb4336SCornelia Huck 
1350e6546342SJason Wang /*
1351e6546342SJason Wang  * Amlogic Video Framebuffer Compression modifiers
1352e6546342SJason Wang  *
1353e6546342SJason Wang  * Amlogic uses a proprietary lossless image compression protocol and format
1354e6546342SJason Wang  * for their hardware video codec accelerators, either video decoders or
1355e6546342SJason Wang  * video input encoders.
1356e6546342SJason Wang  *
1357e6546342SJason Wang  * It considerably reduces memory bandwidth while writing and reading
1358e6546342SJason Wang  * frames in memory.
1359e6546342SJason Wang  *
1360e6546342SJason Wang  * The underlying storage is considered to be 3 components, 8bit or 10-bit
1361e6546342SJason Wang  * per component YCbCr 420, single plane :
1362e6546342SJason Wang  * - DRM_FORMAT_YUV420_8BIT
1363e6546342SJason Wang  * - DRM_FORMAT_YUV420_10BIT
1364e6546342SJason Wang  *
1365e6546342SJason Wang  * The first 8 bits of the mode defines the layout, then the following 8 bits
1366e6546342SJason Wang  * defines the options changing the layout.
1367e6546342SJason Wang  *
1368e6546342SJason Wang  * Not all combinations are valid, and different SoCs may support different
1369e6546342SJason Wang  * combinations of layout and options.
1370e6546342SJason Wang  */
1371278f064eSEduardo Habkost #define __fourcc_mod_amlogic_layout_mask 0xff
1372e6546342SJason Wang #define __fourcc_mod_amlogic_options_shift 8
1373278f064eSEduardo Habkost #define __fourcc_mod_amlogic_options_mask 0xff
1374e6546342SJason Wang 
1375e6546342SJason Wang #define DRM_FORMAT_MOD_AMLOGIC_FBC(__layout, __options) \
1376e6546342SJason Wang 	fourcc_mod_code(AMLOGIC, \
1377e6546342SJason Wang 			((__layout) & __fourcc_mod_amlogic_layout_mask) | \
1378e6546342SJason Wang 			(((__options) & __fourcc_mod_amlogic_options_mask) \
1379e6546342SJason Wang 			 << __fourcc_mod_amlogic_options_shift))
1380e6546342SJason Wang 
1381e6546342SJason Wang /* Amlogic FBC Layouts */
1382e6546342SJason Wang 
1383e6546342SJason Wang /*
1384e6546342SJason Wang  * Amlogic FBC Basic Layout
1385e6546342SJason Wang  *
1386e6546342SJason Wang  * The basic layout is composed of:
1387e6546342SJason Wang  * - a body content organized in 64x32 superblocks with 4096 bytes per
1388e6546342SJason Wang  *   superblock in default mode.
1389e6546342SJason Wang  * - a 32 bytes per 128x64 header block
1390e6546342SJason Wang  *
1391e6546342SJason Wang  * This layout is transferrable between Amlogic SoCs supporting this modifier.
1392e6546342SJason Wang  */
1393e6546342SJason Wang #define AMLOGIC_FBC_LAYOUT_BASIC		(1ULL)
1394e6546342SJason Wang 
1395e6546342SJason Wang /*
1396e6546342SJason Wang  * Amlogic FBC Scatter Memory layout
1397e6546342SJason Wang  *
1398e6546342SJason Wang  * Indicates the header contains IOMMU references to the compressed
1399e6546342SJason Wang  * frames content to optimize memory access and layout.
1400e6546342SJason Wang  *
1401e6546342SJason Wang  * In this mode, only the header memory address is needed, thus the
1402e6546342SJason Wang  * content memory organization is tied to the current producer
1403e6546342SJason Wang  * execution and cannot be saved/dumped neither transferrable between
1404e6546342SJason Wang  * Amlogic SoCs supporting this modifier.
1405e6546342SJason Wang  *
1406e6546342SJason Wang  * Due to the nature of the layout, these buffers are not expected to
1407e6546342SJason Wang  * be accessible by the user-space clients, but only accessible by the
1408e6546342SJason Wang  * hardware producers and consumers.
1409e6546342SJason Wang  *
1410e6546342SJason Wang  * The user-space clients should expect a failure while trying to mmap
1411e6546342SJason Wang  * the DMA-BUF handle returned by the producer.
1412e6546342SJason Wang  */
1413e6546342SJason Wang #define AMLOGIC_FBC_LAYOUT_SCATTER		(2ULL)
1414e6546342SJason Wang 
1415e6546342SJason Wang /* Amlogic FBC Layout Options Bit Mask */
1416e6546342SJason Wang 
1417e6546342SJason Wang /*
1418e6546342SJason Wang  * Amlogic FBC Memory Saving mode
1419e6546342SJason Wang  *
1420e6546342SJason Wang  * Indicates the storage is packed when pixel size is multiple of word
1421*6a02465fSDaniel Henrique Barboza  * boundaries, i.e. 8bit should be stored in this mode to save allocation
1422e6546342SJason Wang  * memory.
1423e6546342SJason Wang  *
1424e6546342SJason Wang  * This mode reduces body layout to 3072 bytes per 64x32 superblock with
1425e6546342SJason Wang  * the basic layout and 3200 bytes per 64x32 superblock combined with
1426e6546342SJason Wang  * the scatter layout.
1427e6546342SJason Wang  */
1428e6546342SJason Wang #define AMLOGIC_FBC_OPTION_MEM_SAVING		(1ULL << 0)
1429e6546342SJason Wang 
1430b3c818a4SEric Farman /*
1431b3c818a4SEric Farman  * AMD modifiers
1432b3c818a4SEric Farman  *
1433b3c818a4SEric Farman  * Memory layout:
1434b3c818a4SEric Farman  *
1435b3c818a4SEric Farman  * without DCC:
1436b3c818a4SEric Farman  *   - main surface
1437b3c818a4SEric Farman  *
1438b3c818a4SEric Farman  * with DCC & without DCC_RETILE:
1439b3c818a4SEric Farman  *   - main surface in plane 0
1440b3c818a4SEric Farman  *   - DCC surface in plane 1 (RB-aligned, pipe-aligned if DCC_PIPE_ALIGN is set)
1441b3c818a4SEric Farman  *
1442b3c818a4SEric Farman  * with DCC & DCC_RETILE:
1443b3c818a4SEric Farman  *   - main surface in plane 0
1444b3c818a4SEric Farman  *   - displayable DCC surface in plane 1 (not RB-aligned & not pipe-aligned)
1445b3c818a4SEric Farman  *   - pipe-aligned DCC surface in plane 2 (RB-aligned & pipe-aligned)
1446b3c818a4SEric Farman  *
1447b3c818a4SEric Farman  * For multi-plane formats the above surfaces get merged into one plane for
1448b3c818a4SEric Farman  * each format plane, based on the required alignment only.
1449b3c818a4SEric Farman  *
1450b3c818a4SEric Farman  * Bits  Parameter                Notes
1451b3c818a4SEric Farman  * ----- ------------------------ ---------------------------------------------
1452b3c818a4SEric Farman  *
1453b3c818a4SEric Farman  *   7:0 TILE_VERSION             Values are AMD_FMT_MOD_TILE_VER_*
1454b3c818a4SEric Farman  *  12:8 TILE                     Values are AMD_FMT_MOD_TILE_<version>_*
1455b3c818a4SEric Farman  *    13 DCC
1456b3c818a4SEric Farman  *    14 DCC_RETILE
1457b3c818a4SEric Farman  *    15 DCC_PIPE_ALIGN
1458b3c818a4SEric Farman  *    16 DCC_INDEPENDENT_64B
1459b3c818a4SEric Farman  *    17 DCC_INDEPENDENT_128B
1460b3c818a4SEric Farman  * 19:18 DCC_MAX_COMPRESSED_BLOCK Values are AMD_FMT_MOD_DCC_BLOCK_*
1461b3c818a4SEric Farman  *    20 DCC_CONSTANT_ENCODE
1462b3c818a4SEric Farman  * 23:21 PIPE_XOR_BITS            Only for some chips
1463b3c818a4SEric Farman  * 26:24 BANK_XOR_BITS            Only for some chips
1464b3c818a4SEric Farman  * 29:27 PACKERS                  Only for some chips
1465b3c818a4SEric Farman  * 32:30 RB                       Only for some chips
1466b3c818a4SEric Farman  * 35:33 PIPE                     Only for some chips
1467b3c818a4SEric Farman  * 55:36 -                        Reserved for future use, must be zero
1468b3c818a4SEric Farman  */
1469b3c818a4SEric Farman #define AMD_FMT_MOD fourcc_mod_code(AMD, 0)
1470b3c818a4SEric Farman 
1471b3c818a4SEric Farman #define IS_AMD_FMT_MOD(val) (((val) >> 56) == DRM_FORMAT_MOD_VENDOR_AMD)
1472b3c818a4SEric Farman 
1473b3c818a4SEric Farman /* Reserve 0 for GFX8 and older */
1474b3c818a4SEric Farman #define AMD_FMT_MOD_TILE_VER_GFX9 1
1475b3c818a4SEric Farman #define AMD_FMT_MOD_TILE_VER_GFX10 2
1476b3c818a4SEric Farman #define AMD_FMT_MOD_TILE_VER_GFX10_RBPLUS 3
1477d525f73fSChenyi Qiang #define AMD_FMT_MOD_TILE_VER_GFX11 4
1478b3c818a4SEric Farman 
1479b3c818a4SEric Farman /*
1480b3c818a4SEric Farman  * 64K_S is the same for GFX9/GFX10/GFX10_RBPLUS and hence has GFX9 as canonical
1481b3c818a4SEric Farman  * version.
1482b3c818a4SEric Farman  */
1483b3c818a4SEric Farman #define AMD_FMT_MOD_TILE_GFX9_64K_S 9
1484b3c818a4SEric Farman 
1485b3c818a4SEric Farman /*
1486b3c818a4SEric Farman  * 64K_D for non-32 bpp is the same for GFX9/GFX10/GFX10_RBPLUS and hence has
1487b3c818a4SEric Farman  * GFX9 as canonical version.
1488b3c818a4SEric Farman  */
1489b3c818a4SEric Farman #define AMD_FMT_MOD_TILE_GFX9_64K_D 10
1490b3c818a4SEric Farman #define AMD_FMT_MOD_TILE_GFX9_64K_S_X 25
1491b3c818a4SEric Farman #define AMD_FMT_MOD_TILE_GFX9_64K_D_X 26
1492b3c818a4SEric Farman #define AMD_FMT_MOD_TILE_GFX9_64K_R_X 27
1493d525f73fSChenyi Qiang #define AMD_FMT_MOD_TILE_GFX11_256K_R_X 31
1494b3c818a4SEric Farman 
1495b3c818a4SEric Farman #define AMD_FMT_MOD_DCC_BLOCK_64B 0
1496b3c818a4SEric Farman #define AMD_FMT_MOD_DCC_BLOCK_128B 1
1497b3c818a4SEric Farman #define AMD_FMT_MOD_DCC_BLOCK_256B 2
1498b3c818a4SEric Farman 
1499b3c818a4SEric Farman #define AMD_FMT_MOD_TILE_VERSION_SHIFT 0
1500b3c818a4SEric Farman #define AMD_FMT_MOD_TILE_VERSION_MASK 0xFF
1501b3c818a4SEric Farman #define AMD_FMT_MOD_TILE_SHIFT 8
1502b3c818a4SEric Farman #define AMD_FMT_MOD_TILE_MASK 0x1F
1503b3c818a4SEric Farman 
1504b3c818a4SEric Farman /* Whether DCC compression is enabled. */
1505b3c818a4SEric Farman #define AMD_FMT_MOD_DCC_SHIFT 13
1506b3c818a4SEric Farman #define AMD_FMT_MOD_DCC_MASK 0x1
1507b3c818a4SEric Farman 
1508b3c818a4SEric Farman /*
1509b3c818a4SEric Farman  * Whether to include two DCC surfaces, one which is rb & pipe aligned, and
1510b3c818a4SEric Farman  * one which is not-aligned.
1511b3c818a4SEric Farman  */
1512b3c818a4SEric Farman #define AMD_FMT_MOD_DCC_RETILE_SHIFT 14
1513b3c818a4SEric Farman #define AMD_FMT_MOD_DCC_RETILE_MASK 0x1
1514b3c818a4SEric Farman 
1515b3c818a4SEric Farman /* Only set if DCC_RETILE = false */
1516b3c818a4SEric Farman #define AMD_FMT_MOD_DCC_PIPE_ALIGN_SHIFT 15
1517b3c818a4SEric Farman #define AMD_FMT_MOD_DCC_PIPE_ALIGN_MASK 0x1
1518b3c818a4SEric Farman 
1519b3c818a4SEric Farman #define AMD_FMT_MOD_DCC_INDEPENDENT_64B_SHIFT 16
1520b3c818a4SEric Farman #define AMD_FMT_MOD_DCC_INDEPENDENT_64B_MASK 0x1
1521b3c818a4SEric Farman #define AMD_FMT_MOD_DCC_INDEPENDENT_128B_SHIFT 17
1522b3c818a4SEric Farman #define AMD_FMT_MOD_DCC_INDEPENDENT_128B_MASK 0x1
1523b3c818a4SEric Farman #define AMD_FMT_MOD_DCC_MAX_COMPRESSED_BLOCK_SHIFT 18
1524b3c818a4SEric Farman #define AMD_FMT_MOD_DCC_MAX_COMPRESSED_BLOCK_MASK 0x3
1525b3c818a4SEric Farman 
1526b3c818a4SEric Farman /*
1527b3c818a4SEric Farman  * DCC supports embedding some clear colors directly in the DCC surface.
1528b3c818a4SEric Farman  * However, on older GPUs the rendering HW ignores the embedded clear color
1529b3c818a4SEric Farman  * and prefers the driver provided color. This necessitates doing a fastclear
1530b3c818a4SEric Farman  * eliminate operation before a process transfers control.
1531b3c818a4SEric Farman  *
1532b3c818a4SEric Farman  * If this bit is set that means the fastclear eliminate is not needed for these
1533b3c818a4SEric Farman  * embeddable colors.
1534b3c818a4SEric Farman  */
1535b3c818a4SEric Farman #define AMD_FMT_MOD_DCC_CONSTANT_ENCODE_SHIFT 20
1536b3c818a4SEric Farman #define AMD_FMT_MOD_DCC_CONSTANT_ENCODE_MASK 0x1
1537b3c818a4SEric Farman 
1538b3c818a4SEric Farman /*
1539b3c818a4SEric Farman  * The below fields are for accounting for per GPU differences. These are only
1540b3c818a4SEric Farman  * relevant for GFX9 and later and if the tile field is *_X/_T.
1541b3c818a4SEric Farman  *
1542b3c818a4SEric Farman  * PIPE_XOR_BITS = always needed
1543b3c818a4SEric Farman  * BANK_XOR_BITS = only for TILE_VER_GFX9
1544b3c818a4SEric Farman  * PACKERS = only for TILE_VER_GFX10_RBPLUS
1545b3c818a4SEric Farman  * RB = only for TILE_VER_GFX9 & DCC
1546b3c818a4SEric Farman  * PIPE = only for TILE_VER_GFX9 & DCC & (DCC_RETILE | DCC_PIPE_ALIGN)
1547b3c818a4SEric Farman  */
1548b3c818a4SEric Farman #define AMD_FMT_MOD_PIPE_XOR_BITS_SHIFT 21
1549b3c818a4SEric Farman #define AMD_FMT_MOD_PIPE_XOR_BITS_MASK 0x7
1550b3c818a4SEric Farman #define AMD_FMT_MOD_BANK_XOR_BITS_SHIFT 24
1551b3c818a4SEric Farman #define AMD_FMT_MOD_BANK_XOR_BITS_MASK 0x7
1552b3c818a4SEric Farman #define AMD_FMT_MOD_PACKERS_SHIFT 27
1553b3c818a4SEric Farman #define AMD_FMT_MOD_PACKERS_MASK 0x7
1554b3c818a4SEric Farman #define AMD_FMT_MOD_RB_SHIFT 30
1555b3c818a4SEric Farman #define AMD_FMT_MOD_RB_MASK 0x7
1556b3c818a4SEric Farman #define AMD_FMT_MOD_PIPE_SHIFT 33
1557b3c818a4SEric Farman #define AMD_FMT_MOD_PIPE_MASK 0x7
1558b3c818a4SEric Farman 
1559b3c818a4SEric Farman #define AMD_FMT_MOD_SET(field, value) \
1560b3c818a4SEric Farman 	((uint64_t)(value) << AMD_FMT_MOD_##field##_SHIFT)
1561b3c818a4SEric Farman #define AMD_FMT_MOD_GET(field, value) \
1562b3c818a4SEric Farman 	(((value) >> AMD_FMT_MOD_##field##_SHIFT) & AMD_FMT_MOD_##field##_MASK)
1563b3c818a4SEric Farman #define AMD_FMT_MOD_CLEAR(field) \
1564b3c818a4SEric Farman 	(~((uint64_t)AMD_FMT_MOD_##field##_MASK << AMD_FMT_MOD_##field##_SHIFT))
1565b3c818a4SEric Farman 
15668e8ee850SGerd Hoffmann #if defined(__cplusplus)
15678e8ee850SGerd Hoffmann }
15688e8ee850SGerd Hoffmann #endif
15698e8ee850SGerd Hoffmann 
15708e8ee850SGerd Hoffmann #endif /* DRM_FOURCC_H */
1571