drm_fourcc.h revision 41687f09
1e88f27b3Smrg/*
2e88f27b3Smrg * Copyright 2011 Intel Corporation
3e88f27b3Smrg *
4e88f27b3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
5e88f27b3Smrg * copy of this software and associated documentation files (the "Software"),
6e88f27b3Smrg * to deal in the Software without restriction, including without limitation
7e88f27b3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8e88f27b3Smrg * and/or sell copies of the Software, and to permit persons to whom the
9e88f27b3Smrg * Software is furnished to do so, subject to the following conditions:
10e88f27b3Smrg *
11e88f27b3Smrg * The above copyright notice and this permission notice (including the next
12e88f27b3Smrg * paragraph) shall be included in all copies or substantial portions of the
13e88f27b3Smrg * Software.
14e88f27b3Smrg *
15e88f27b3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16e88f27b3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17e88f27b3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18e88f27b3Smrg * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19e88f27b3Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20e88f27b3Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21e88f27b3Smrg * OTHER DEALINGS IN THE SOFTWARE.
22e88f27b3Smrg */
23e88f27b3Smrg
24e88f27b3Smrg#ifndef DRM_FOURCC_H
25e88f27b3Smrg#define DRM_FOURCC_H
26e88f27b3Smrg
273f012e29Smrg#include "drm.h"
28e88f27b3Smrg
29d8807b2fSmrg#if defined(__cplusplus)
30d8807b2fSmrgextern "C" {
31d8807b2fSmrg#endif
32d8807b2fSmrg
337cdc0497Smrg/**
347cdc0497Smrg * DOC: overview
357cdc0497Smrg *
367cdc0497Smrg * In the DRM subsystem, framebuffer pixel formats are described using the
377cdc0497Smrg * fourcc codes defined in `include/uapi/drm/drm_fourcc.h`. In addition to the
387cdc0497Smrg * fourcc code, a Format Modifier may optionally be provided, in order to
397cdc0497Smrg * further describe the buffer's format - for example tiling or compression.
407cdc0497Smrg *
417cdc0497Smrg * Format Modifiers
427cdc0497Smrg * ----------------
437cdc0497Smrg *
447cdc0497Smrg * Format modifiers are used in conjunction with a fourcc code, forming a
457cdc0497Smrg * unique fourcc:modifier pair. This format:modifier pair must fully define the
467cdc0497Smrg * format and data layout of the buffer, and should be the only way to describe
477cdc0497Smrg * that particular buffer.
487cdc0497Smrg *
497cdc0497Smrg * Having multiple fourcc:modifier pairs which describe the same layout should
507cdc0497Smrg * be avoided, as such aliases run the risk of different drivers exposing
517cdc0497Smrg * different names for the same data format, forcing userspace to understand
527cdc0497Smrg * that they are aliases.
537cdc0497Smrg *
547cdc0497Smrg * Format modifiers may change any property of the buffer, including the number
557cdc0497Smrg * of planes and/or the required allocation size. Format modifiers are
567cdc0497Smrg * vendor-namespaced, and as such the relationship between a fourcc code and a
577cdc0497Smrg * modifier is specific to the modifer being used. For example, some modifiers
587cdc0497Smrg * may preserve meaning - such as number of planes - from the fourcc code,
597cdc0497Smrg * whereas others may not.
607cdc0497Smrg *
6141687f09Smrg * Modifiers must uniquely encode buffer layout. In other words, a buffer must
6241687f09Smrg * match only a single modifier. A modifier must not be a subset of layouts of
6341687f09Smrg * another modifier. For instance, it's incorrect to encode pitch alignment in
6441687f09Smrg * a modifier: a buffer may match a 64-pixel aligned modifier and a 32-pixel
6541687f09Smrg * aligned modifier. That said, modifiers can have implicit minimal
6641687f09Smrg * requirements.
6741687f09Smrg *
6841687f09Smrg * For modifiers where the combination of fourcc code and modifier can alias,
6941687f09Smrg * a canonical pair needs to be defined and used by all drivers. Preferred
7041687f09Smrg * combinations are also encouraged where all combinations might lead to
7141687f09Smrg * confusion and unnecessarily reduced interoperability. An example for the
7241687f09Smrg * latter is AFBC, where the ABGR layouts are preferred over ARGB layouts.
7341687f09Smrg *
7441687f09Smrg * There are two kinds of modifier users:
7541687f09Smrg *
7641687f09Smrg * - Kernel and user-space drivers: for drivers it's important that modifiers
7741687f09Smrg *   don't alias, otherwise two drivers might support the same format but use
7841687f09Smrg *   different aliases, preventing them from sharing buffers in an efficient
7941687f09Smrg *   format.
8041687f09Smrg * - Higher-level programs interfacing with KMS/GBM/EGL/Vulkan/etc: these users
8141687f09Smrg *   see modifiers as opaque tokens they can check for equality and intersect.
8241687f09Smrg *   These users musn't need to know to reason about the modifier value
8341687f09Smrg *   (i.e. they are not expected to extract information out of the modifier).
8441687f09Smrg *
857cdc0497Smrg * Vendors should document their modifier usage in as much detail as
867cdc0497Smrg * possible, to ensure maximum compatibility across devices, drivers and
877cdc0497Smrg * applications.
887cdc0497Smrg *
897cdc0497Smrg * The authoritative list of format modifier codes is found in
907cdc0497Smrg * `include/uapi/drm/drm_fourcc.h`
917cdc0497Smrg */
927cdc0497Smrg
933f012e29Smrg#define fourcc_code(a, b, c, d) ((__u32)(a) | ((__u32)(b) << 8) | \
943f012e29Smrg				 ((__u32)(c) << 16) | ((__u32)(d) << 24))
95e88f27b3Smrg
9641687f09Smrg#define DRM_FORMAT_BIG_ENDIAN (1U<<31) /* format is big endian instead of little endian */
97e88f27b3Smrg
987cdc0497Smrg/* Reserve 0 for the invalid format specifier */
997cdc0497Smrg#define DRM_FORMAT_INVALID	0
1007cdc0497Smrg
101e88f27b3Smrg/* color index */
102e88f27b3Smrg#define DRM_FORMAT_C8		fourcc_code('C', '8', ' ', ' ') /* [7:0] C */
103e88f27b3Smrg
1043f012e29Smrg/* 8 bpp Red */
1053f012e29Smrg#define DRM_FORMAT_R8		fourcc_code('R', '8', ' ', ' ') /* [7:0] R */
1063f012e29Smrg
107d8807b2fSmrg/* 16 bpp Red */
108d8807b2fSmrg#define DRM_FORMAT_R16		fourcc_code('R', '1', '6', ' ') /* [15:0] R little endian */
109d8807b2fSmrg
1103f012e29Smrg/* 16 bpp RG */
1113f012e29Smrg#define DRM_FORMAT_RG88		fourcc_code('R', 'G', '8', '8') /* [15:0] R:G 8:8 little endian */
1123f012e29Smrg#define DRM_FORMAT_GR88		fourcc_code('G', 'R', '8', '8') /* [15:0] G:R 8:8 little endian */
1133f012e29Smrg
114d8807b2fSmrg/* 32 bpp RG */
115d8807b2fSmrg#define DRM_FORMAT_RG1616	fourcc_code('R', 'G', '3', '2') /* [31:0] R:G 16:16 little endian */
116d8807b2fSmrg#define DRM_FORMAT_GR1616	fourcc_code('G', 'R', '3', '2') /* [31:0] G:R 16:16 little endian */
117d8807b2fSmrg
118e88f27b3Smrg/* 8 bpp RGB */
119e88f27b3Smrg#define DRM_FORMAT_RGB332	fourcc_code('R', 'G', 'B', '8') /* [7:0] R:G:B 3:3:2 */
120e88f27b3Smrg#define DRM_FORMAT_BGR233	fourcc_code('B', 'G', 'R', '8') /* [7:0] B:G:R 2:3:3 */
121e88f27b3Smrg
122e88f27b3Smrg/* 16 bpp RGB */
123e88f27b3Smrg#define DRM_FORMAT_XRGB4444	fourcc_code('X', 'R', '1', '2') /* [15:0] x:R:G:B 4:4:4:4 little endian */
124e88f27b3Smrg#define DRM_FORMAT_XBGR4444	fourcc_code('X', 'B', '1', '2') /* [15:0] x:B:G:R 4:4:4:4 little endian */
125e88f27b3Smrg#define DRM_FORMAT_RGBX4444	fourcc_code('R', 'X', '1', '2') /* [15:0] R:G:B:x 4:4:4:4 little endian */
126e88f27b3Smrg#define DRM_FORMAT_BGRX4444	fourcc_code('B', 'X', '1', '2') /* [15:0] B:G:R:x 4:4:4:4 little endian */
127e88f27b3Smrg
128e88f27b3Smrg#define DRM_FORMAT_ARGB4444	fourcc_code('A', 'R', '1', '2') /* [15:0] A:R:G:B 4:4:4:4 little endian */
129e88f27b3Smrg#define DRM_FORMAT_ABGR4444	fourcc_code('A', 'B', '1', '2') /* [15:0] A:B:G:R 4:4:4:4 little endian */
130e88f27b3Smrg#define DRM_FORMAT_RGBA4444	fourcc_code('R', 'A', '1', '2') /* [15:0] R:G:B:A 4:4:4:4 little endian */
131e88f27b3Smrg#define DRM_FORMAT_BGRA4444	fourcc_code('B', 'A', '1', '2') /* [15:0] B:G:R:A 4:4:4:4 little endian */
132e88f27b3Smrg
133e88f27b3Smrg#define DRM_FORMAT_XRGB1555	fourcc_code('X', 'R', '1', '5') /* [15:0] x:R:G:B 1:5:5:5 little endian */
134e88f27b3Smrg#define DRM_FORMAT_XBGR1555	fourcc_code('X', 'B', '1', '5') /* [15:0] x:B:G:R 1:5:5:5 little endian */
135e88f27b3Smrg#define DRM_FORMAT_RGBX5551	fourcc_code('R', 'X', '1', '5') /* [15:0] R:G:B:x 5:5:5:1 little endian */
136e88f27b3Smrg#define DRM_FORMAT_BGRX5551	fourcc_code('B', 'X', '1', '5') /* [15:0] B:G:R:x 5:5:5:1 little endian */
137e88f27b3Smrg
138e88f27b3Smrg#define DRM_FORMAT_ARGB1555	fourcc_code('A', 'R', '1', '5') /* [15:0] A:R:G:B 1:5:5:5 little endian */
139e88f27b3Smrg#define DRM_FORMAT_ABGR1555	fourcc_code('A', 'B', '1', '5') /* [15:0] A:B:G:R 1:5:5:5 little endian */
140e88f27b3Smrg#define DRM_FORMAT_RGBA5551	fourcc_code('R', 'A', '1', '5') /* [15:0] R:G:B:A 5:5:5:1 little endian */
141e88f27b3Smrg#define DRM_FORMAT_BGRA5551	fourcc_code('B', 'A', '1', '5') /* [15:0] B:G:R:A 5:5:5:1 little endian */
142e88f27b3Smrg
143e88f27b3Smrg#define DRM_FORMAT_RGB565	fourcc_code('R', 'G', '1', '6') /* [15:0] R:G:B 5:6:5 little endian */
144e88f27b3Smrg#define DRM_FORMAT_BGR565	fourcc_code('B', 'G', '1', '6') /* [15:0] B:G:R 5:6:5 little endian */
145e88f27b3Smrg
146e88f27b3Smrg/* 24 bpp RGB */
147e88f27b3Smrg#define DRM_FORMAT_RGB888	fourcc_code('R', 'G', '2', '4') /* [23:0] R:G:B little endian */
148e88f27b3Smrg#define DRM_FORMAT_BGR888	fourcc_code('B', 'G', '2', '4') /* [23:0] B:G:R little endian */
149e88f27b3Smrg
150e88f27b3Smrg/* 32 bpp RGB */
151e88f27b3Smrg#define DRM_FORMAT_XRGB8888	fourcc_code('X', 'R', '2', '4') /* [31:0] x:R:G:B 8:8:8:8 little endian */
152e88f27b3Smrg#define DRM_FORMAT_XBGR8888	fourcc_code('X', 'B', '2', '4') /* [31:0] x:B:G:R 8:8:8:8 little endian */
153e88f27b3Smrg#define DRM_FORMAT_RGBX8888	fourcc_code('R', 'X', '2', '4') /* [31:0] R:G:B:x 8:8:8:8 little endian */
154e88f27b3Smrg#define DRM_FORMAT_BGRX8888	fourcc_code('B', 'X', '2', '4') /* [31:0] B:G:R:x 8:8:8:8 little endian */
155e88f27b3Smrg
156e88f27b3Smrg#define DRM_FORMAT_ARGB8888	fourcc_code('A', 'R', '2', '4') /* [31:0] A:R:G:B 8:8:8:8 little endian */
157e88f27b3Smrg#define DRM_FORMAT_ABGR8888	fourcc_code('A', 'B', '2', '4') /* [31:0] A:B:G:R 8:8:8:8 little endian */
158e88f27b3Smrg#define DRM_FORMAT_RGBA8888	fourcc_code('R', 'A', '2', '4') /* [31:0] R:G:B:A 8:8:8:8 little endian */
159e88f27b3Smrg#define DRM_FORMAT_BGRA8888	fourcc_code('B', 'A', '2', '4') /* [31:0] B:G:R:A 8:8:8:8 little endian */
160e88f27b3Smrg
161e88f27b3Smrg#define DRM_FORMAT_XRGB2101010	fourcc_code('X', 'R', '3', '0') /* [31:0] x:R:G:B 2:10:10:10 little endian */
162e88f27b3Smrg#define DRM_FORMAT_XBGR2101010	fourcc_code('X', 'B', '3', '0') /* [31:0] x:B:G:R 2:10:10:10 little endian */
163e88f27b3Smrg#define DRM_FORMAT_RGBX1010102	fourcc_code('R', 'X', '3', '0') /* [31:0] R:G:B:x 10:10:10:2 little endian */
164e88f27b3Smrg#define DRM_FORMAT_BGRX1010102	fourcc_code('B', 'X', '3', '0') /* [31:0] B:G:R:x 10:10:10:2 little endian */
165e88f27b3Smrg
166e88f27b3Smrg#define DRM_FORMAT_ARGB2101010	fourcc_code('A', 'R', '3', '0') /* [31:0] A:R:G:B 2:10:10:10 little endian */
167e88f27b3Smrg#define DRM_FORMAT_ABGR2101010	fourcc_code('A', 'B', '3', '0') /* [31:0] A:B:G:R 2:10:10:10 little endian */
168e88f27b3Smrg#define DRM_FORMAT_RGBA1010102	fourcc_code('R', 'A', '3', '0') /* [31:0] R:G:B:A 10:10:10:2 little endian */
169e88f27b3Smrg#define DRM_FORMAT_BGRA1010102	fourcc_code('B', 'A', '3', '0') /* [31:0] B:G:R:A 10:10:10:2 little endian */
170e88f27b3Smrg
1715324fb0dSmrg/*
1725324fb0dSmrg * Floating point 64bpp RGB
1735324fb0dSmrg * IEEE 754-2008 binary16 half-precision float
1745324fb0dSmrg * [15:0] sign:exponent:mantissa 1:5:10
1755324fb0dSmrg */
1765324fb0dSmrg#define DRM_FORMAT_XRGB16161616F fourcc_code('X', 'R', '4', 'H') /* [63:0] x:R:G:B 16:16:16:16 little endian */
1775324fb0dSmrg#define DRM_FORMAT_XBGR16161616F fourcc_code('X', 'B', '4', 'H') /* [63:0] x:B:G:R 16:16:16:16 little endian */
1785324fb0dSmrg
1795324fb0dSmrg#define DRM_FORMAT_ARGB16161616F fourcc_code('A', 'R', '4', 'H') /* [63:0] A:R:G:B 16:16:16:16 little endian */
1805324fb0dSmrg#define DRM_FORMAT_ABGR16161616F fourcc_code('A', 'B', '4', 'H') /* [63:0] A:B:G:R 16:16:16:16 little endian */
1815324fb0dSmrg
18241687f09Smrg/*
18341687f09Smrg * RGBA format with 10-bit components packed in 64-bit per pixel, with 6 bits
18441687f09Smrg * of unused padding per component:
18541687f09Smrg */
18641687f09Smrg#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 */
18741687f09Smrg
188e88f27b3Smrg/* packed YCbCr */
189e88f27b3Smrg#define DRM_FORMAT_YUYV		fourcc_code('Y', 'U', 'Y', 'V') /* [31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian */
190e88f27b3Smrg#define DRM_FORMAT_YVYU		fourcc_code('Y', 'V', 'Y', 'U') /* [31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian */
191e88f27b3Smrg#define DRM_FORMAT_UYVY		fourcc_code('U', 'Y', 'V', 'Y') /* [31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian */
192e88f27b3Smrg#define DRM_FORMAT_VYUY		fourcc_code('V', 'Y', 'U', 'Y') /* [31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian */
193e88f27b3Smrg
194e88f27b3Smrg#define DRM_FORMAT_AYUV		fourcc_code('A', 'Y', 'U', 'V') /* [31:0] A:Y:Cb:Cr 8:8:8:8 little endian */
1955324fb0dSmrg#define DRM_FORMAT_XYUV8888	fourcc_code('X', 'Y', 'U', 'V') /* [31:0] X:Y:Cb:Cr 8:8:8:8 little endian */
1965324fb0dSmrg#define DRM_FORMAT_VUY888	fourcc_code('V', 'U', '2', '4') /* [23:0] Cr:Cb:Y 8:8:8 little endian */
1975324fb0dSmrg#define DRM_FORMAT_VUY101010	fourcc_code('V', 'U', '3', '0') /* Y followed by U then V, 10:10:10. Non-linear modifier only */
1985324fb0dSmrg
1995324fb0dSmrg/*
2005324fb0dSmrg * packed Y2xx indicate for each component, xx valid data occupy msb
2015324fb0dSmrg * 16-xx padding occupy lsb
2025324fb0dSmrg */
2035324fb0dSmrg#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 */
2045324fb0dSmrg#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 */
2055324fb0dSmrg#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 */
2065324fb0dSmrg
2075324fb0dSmrg/*
2085324fb0dSmrg * packed Y4xx indicate for each component, xx valid data occupy msb
2095324fb0dSmrg * 16-xx padding occupy lsb except Y410
2105324fb0dSmrg */
2115324fb0dSmrg#define DRM_FORMAT_Y410         fourcc_code('Y', '4', '1', '0') /* [31:0] A:Cr:Y:Cb 2:10:10:10 little endian */
2125324fb0dSmrg#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 */
2135324fb0dSmrg#define DRM_FORMAT_Y416         fourcc_code('Y', '4', '1', '6') /* [63:0] A:Cr:Y:Cb 16:16:16:16 little endian */
2145324fb0dSmrg
2155324fb0dSmrg#define DRM_FORMAT_XVYU2101010	fourcc_code('X', 'V', '3', '0') /* [31:0] X:Cr:Y:Cb 2:10:10:10 little endian */
2165324fb0dSmrg#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 */
2175324fb0dSmrg#define DRM_FORMAT_XVYU16161616	fourcc_code('X', 'V', '4', '8') /* [63:0] X:Cr:Y:Cb 16:16:16:16 little endian */
2185324fb0dSmrg
2195324fb0dSmrg/*
2205324fb0dSmrg * packed YCbCr420 2x2 tiled formats
2215324fb0dSmrg * first 64 bits will contain Y,Cb,Cr components for a 2x2 tile
2225324fb0dSmrg */
2235324fb0dSmrg/* [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 */
2245324fb0dSmrg#define DRM_FORMAT_Y0L0		fourcc_code('Y', '0', 'L', '0')
2255324fb0dSmrg/* [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 */
2265324fb0dSmrg#define DRM_FORMAT_X0L0		fourcc_code('X', '0', 'L', '0')
2275324fb0dSmrg
2285324fb0dSmrg/* [63:0]   A3:A2:Y3:Cr0:Y2:A1:A0:Y1:Cb0:Y0  1:1:10:10:10:1:1:10:10:10 little endian */
2295324fb0dSmrg#define DRM_FORMAT_Y0L2		fourcc_code('Y', '0', 'L', '2')
2305324fb0dSmrg/* [63:0]   X3:X2:Y3:Cr0:Y2:X1:X0:Y1:Cb0:Y0  1:1:10:10:10:1:1:10:10:10 little endian */
2315324fb0dSmrg#define DRM_FORMAT_X0L2		fourcc_code('X', '0', 'L', '2')
2325324fb0dSmrg
2335324fb0dSmrg/*
2345324fb0dSmrg * 1-plane YUV 4:2:0
2355324fb0dSmrg * In these formats, the component ordering is specified (Y, followed by U
2365324fb0dSmrg * then V), but the exact Linear layout is undefined.
2375324fb0dSmrg * These formats can only be used with a non-Linear modifier.
2385324fb0dSmrg */
2395324fb0dSmrg#define DRM_FORMAT_YUV420_8BIT	fourcc_code('Y', 'U', '0', '8')
2405324fb0dSmrg#define DRM_FORMAT_YUV420_10BIT	fourcc_code('Y', 'U', '1', '0')
241e88f27b3Smrg
242d8807b2fSmrg/*
243d8807b2fSmrg * 2 plane RGB + A
244d8807b2fSmrg * index 0 = RGB plane, same format as the corresponding non _A8 format has
245d8807b2fSmrg * index 1 = A plane, [7:0] A
246d8807b2fSmrg */
247d8807b2fSmrg#define DRM_FORMAT_XRGB8888_A8	fourcc_code('X', 'R', 'A', '8')
248d8807b2fSmrg#define DRM_FORMAT_XBGR8888_A8	fourcc_code('X', 'B', 'A', '8')
249d8807b2fSmrg#define DRM_FORMAT_RGBX8888_A8	fourcc_code('R', 'X', 'A', '8')
250d8807b2fSmrg#define DRM_FORMAT_BGRX8888_A8	fourcc_code('B', 'X', 'A', '8')
251d8807b2fSmrg#define DRM_FORMAT_RGB888_A8	fourcc_code('R', '8', 'A', '8')
252d8807b2fSmrg#define DRM_FORMAT_BGR888_A8	fourcc_code('B', '8', 'A', '8')
253d8807b2fSmrg#define DRM_FORMAT_RGB565_A8	fourcc_code('R', '5', 'A', '8')
254d8807b2fSmrg#define DRM_FORMAT_BGR565_A8	fourcc_code('B', '5', 'A', '8')
255d8807b2fSmrg
256e88f27b3Smrg/*
257e88f27b3Smrg * 2 plane YCbCr
258e88f27b3Smrg * index 0 = Y plane, [7:0] Y
259e88f27b3Smrg * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
260e88f27b3Smrg * or
261e88f27b3Smrg * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
262e88f27b3Smrg */
263e88f27b3Smrg#define DRM_FORMAT_NV12		fourcc_code('N', 'V', '1', '2') /* 2x2 subsampled Cr:Cb plane */
264e88f27b3Smrg#define DRM_FORMAT_NV21		fourcc_code('N', 'V', '2', '1') /* 2x2 subsampled Cb:Cr plane */
265e88f27b3Smrg#define DRM_FORMAT_NV16		fourcc_code('N', 'V', '1', '6') /* 2x1 subsampled Cr:Cb plane */
266e88f27b3Smrg#define DRM_FORMAT_NV61		fourcc_code('N', 'V', '6', '1') /* 2x1 subsampled Cb:Cr plane */
2673f012e29Smrg#define DRM_FORMAT_NV24		fourcc_code('N', 'V', '2', '4') /* non-subsampled Cr:Cb plane */
2683f012e29Smrg#define DRM_FORMAT_NV42		fourcc_code('N', 'V', '4', '2') /* non-subsampled Cb:Cr plane */
26941687f09Smrg/*
27041687f09Smrg * 2 plane YCbCr
27141687f09Smrg * index 0 = Y plane, [39:0] Y3:Y2:Y1:Y0 little endian
27241687f09Smrg * index 1 = Cr:Cb plane, [39:0] Cr1:Cb1:Cr0:Cb0 little endian
27341687f09Smrg */
27441687f09Smrg#define DRM_FORMAT_NV15		fourcc_code('N', 'V', '1', '5') /* 2x2 subsampled Cr:Cb plane */
275e88f27b3Smrg
2765324fb0dSmrg/*
2775324fb0dSmrg * 2 plane YCbCr MSB aligned
2785324fb0dSmrg * index 0 = Y plane, [15:0] Y:x [10:6] little endian
2795324fb0dSmrg * index 1 = Cr:Cb plane, [31:0] Cr:x:Cb:x [10:6:10:6] little endian
2805324fb0dSmrg */
2815324fb0dSmrg#define DRM_FORMAT_P210		fourcc_code('P', '2', '1', '0') /* 2x1 subsampled Cr:Cb plane, 10 bit per channel */
2825324fb0dSmrg
2835324fb0dSmrg/*
2845324fb0dSmrg * 2 plane YCbCr MSB aligned
2855324fb0dSmrg * index 0 = Y plane, [15:0] Y:x [10:6] little endian
2865324fb0dSmrg * index 1 = Cr:Cb plane, [31:0] Cr:x:Cb:x [10:6:10:6] little endian
2875324fb0dSmrg */
2885324fb0dSmrg#define DRM_FORMAT_P010		fourcc_code('P', '0', '1', '0') /* 2x2 subsampled Cr:Cb plane 10 bits per channel */
2895324fb0dSmrg
2905324fb0dSmrg/*
2915324fb0dSmrg * 2 plane YCbCr MSB aligned
2925324fb0dSmrg * index 0 = Y plane, [15:0] Y:x [12:4] little endian
2935324fb0dSmrg * index 1 = Cr:Cb plane, [31:0] Cr:x:Cb:x [12:4:12:4] little endian
2945324fb0dSmrg */
2955324fb0dSmrg#define DRM_FORMAT_P012		fourcc_code('P', '0', '1', '2') /* 2x2 subsampled Cr:Cb plane 12 bits per channel */
2965324fb0dSmrg
2975324fb0dSmrg/*
2985324fb0dSmrg * 2 plane YCbCr MSB aligned
2995324fb0dSmrg * index 0 = Y plane, [15:0] Y little endian
3005324fb0dSmrg * index 1 = Cr:Cb plane, [31:0] Cr:Cb [16:16] little endian
3015324fb0dSmrg */
3025324fb0dSmrg#define DRM_FORMAT_P016		fourcc_code('P', '0', '1', '6') /* 2x2 subsampled Cr:Cb plane 16 bits per channel */
3035324fb0dSmrg
30441687f09Smrg/* 3 plane non-subsampled (444) YCbCr
30541687f09Smrg * 16 bits per component, but only 10 bits are used and 6 bits are padded
30641687f09Smrg * index 0: Y plane, [15:0] Y:x [10:6] little endian
30741687f09Smrg * index 1: Cb plane, [15:0] Cb:x [10:6] little endian
30841687f09Smrg * index 2: Cr plane, [15:0] Cr:x [10:6] little endian
30941687f09Smrg */
31041687f09Smrg#define DRM_FORMAT_Q410		fourcc_code('Q', '4', '1', '0')
31141687f09Smrg
31241687f09Smrg/* 3 plane non-subsampled (444) YCrCb
31341687f09Smrg * 16 bits per component, but only 10 bits are used and 6 bits are padded
31441687f09Smrg * index 0: Y plane, [15:0] Y:x [10:6] little endian
31541687f09Smrg * index 1: Cr plane, [15:0] Cr:x [10:6] little endian
31641687f09Smrg * index 2: Cb plane, [15:0] Cb:x [10:6] little endian
31741687f09Smrg */
31841687f09Smrg#define DRM_FORMAT_Q401		fourcc_code('Q', '4', '0', '1')
31941687f09Smrg
320e88f27b3Smrg/*
321e88f27b3Smrg * 3 plane YCbCr
322e88f27b3Smrg * index 0: Y plane, [7:0] Y
323e88f27b3Smrg * index 1: Cb plane, [7:0] Cb
324e88f27b3Smrg * index 2: Cr plane, [7:0] Cr
325e88f27b3Smrg * or
326e88f27b3Smrg * index 1: Cr plane, [7:0] Cr
327e88f27b3Smrg * index 2: Cb plane, [7:0] Cb
328e88f27b3Smrg */
329e88f27b3Smrg#define DRM_FORMAT_YUV410	fourcc_code('Y', 'U', 'V', '9') /* 4x4 subsampled Cb (1) and Cr (2) planes */
330e88f27b3Smrg#define DRM_FORMAT_YVU410	fourcc_code('Y', 'V', 'U', '9') /* 4x4 subsampled Cr (1) and Cb (2) planes */
331e88f27b3Smrg#define DRM_FORMAT_YUV411	fourcc_code('Y', 'U', '1', '1') /* 4x1 subsampled Cb (1) and Cr (2) planes */
332e88f27b3Smrg#define DRM_FORMAT_YVU411	fourcc_code('Y', 'V', '1', '1') /* 4x1 subsampled Cr (1) and Cb (2) planes */
333e88f27b3Smrg#define DRM_FORMAT_YUV420	fourcc_code('Y', 'U', '1', '2') /* 2x2 subsampled Cb (1) and Cr (2) planes */
334e88f27b3Smrg#define DRM_FORMAT_YVU420	fourcc_code('Y', 'V', '1', '2') /* 2x2 subsampled Cr (1) and Cb (2) planes */
335e88f27b3Smrg#define DRM_FORMAT_YUV422	fourcc_code('Y', 'U', '1', '6') /* 2x1 subsampled Cb (1) and Cr (2) planes */
336e88f27b3Smrg#define DRM_FORMAT_YVU422	fourcc_code('Y', 'V', '1', '6') /* 2x1 subsampled Cr (1) and Cb (2) planes */
337e88f27b3Smrg#define DRM_FORMAT_YUV444	fourcc_code('Y', 'U', '2', '4') /* non-subsampled Cb (1) and Cr (2) planes */
338e88f27b3Smrg#define DRM_FORMAT_YVU444	fourcc_code('Y', 'V', '2', '4') /* non-subsampled Cr (1) and Cb (2) planes */
339e88f27b3Smrg
3403f012e29Smrg
3413f012e29Smrg/*
3423f012e29Smrg * Format Modifiers:
3433f012e29Smrg *
3443f012e29Smrg * Format modifiers describe, typically, a re-ordering or modification
3453f012e29Smrg * of the data in a plane of an FB.  This can be used to express tiled/
3463f012e29Smrg * swizzled formats, or compression, or a combination of the two.
3473f012e29Smrg *
3483f012e29Smrg * The upper 8 bits of the format modifier are a vendor-id as assigned
3493f012e29Smrg * below.  The lower 56 bits are assigned as vendor sees fit.
3503f012e29Smrg */
3513f012e29Smrg
3523f012e29Smrg/* Vendor Ids: */
353d8807b2fSmrg#define DRM_FORMAT_MOD_VENDOR_NONE    0
3543f012e29Smrg#define DRM_FORMAT_MOD_VENDOR_INTEL   0x01
3553f012e29Smrg#define DRM_FORMAT_MOD_VENDOR_AMD     0x02
35600a23bdaSmrg#define DRM_FORMAT_MOD_VENDOR_NVIDIA  0x03
3573f012e29Smrg#define DRM_FORMAT_MOD_VENDOR_SAMSUNG 0x04
3583f012e29Smrg#define DRM_FORMAT_MOD_VENDOR_QCOM    0x05
359d8807b2fSmrg#define DRM_FORMAT_MOD_VENDOR_VIVANTE 0x06
360d8807b2fSmrg#define DRM_FORMAT_MOD_VENDOR_BROADCOM 0x07
3617cdc0497Smrg#define DRM_FORMAT_MOD_VENDOR_ARM     0x08
3625324fb0dSmrg#define DRM_FORMAT_MOD_VENDOR_ALLWINNER 0x09
36341687f09Smrg#define DRM_FORMAT_MOD_VENDOR_AMLOGIC 0x0a
3645324fb0dSmrg
3653f012e29Smrg/* add more to the end as needed */
3663f012e29Smrg
367d8807b2fSmrg#define DRM_FORMAT_RESERVED	      ((1ULL << 56) - 1)
368d8807b2fSmrg
3693f012e29Smrg#define fourcc_mod_code(vendor, val) \
37000a23bdaSmrg	((((__u64)DRM_FORMAT_MOD_VENDOR_## vendor) << 56) | ((val) & 0x00ffffffffffffffULL))
3713f012e29Smrg
3723f012e29Smrg/*
3733f012e29Smrg * Format Modifier tokens:
3743f012e29Smrg *
3753f012e29Smrg * When adding a new token please document the layout with a code comment,
3763f012e29Smrg * similar to the fourcc codes above. drm_fourcc.h is considered the
3773f012e29Smrg * authoritative source for all of these.
37841687f09Smrg *
37941687f09Smrg * Generic modifier names:
38041687f09Smrg *
38141687f09Smrg * DRM_FORMAT_MOD_GENERIC_* definitions are used to provide vendor-neutral names
38241687f09Smrg * for layouts which are common across multiple vendors. To preserve
38341687f09Smrg * compatibility, in cases where a vendor-specific definition already exists and
38441687f09Smrg * a generic name for it is desired, the common name is a purely symbolic alias
38541687f09Smrg * and must use the same numerical value as the original definition.
38641687f09Smrg *
38741687f09Smrg * Note that generic names should only be used for modifiers which describe
38841687f09Smrg * generic layouts (such as pixel re-ordering), which may have
38941687f09Smrg * independently-developed support across multiple vendors.
39041687f09Smrg *
39141687f09Smrg * In future cases where a generic layout is identified before merging with a
39241687f09Smrg * vendor-specific modifier, a new 'GENERIC' vendor or modifier using vendor
39341687f09Smrg * 'NONE' could be considered. This should only be for obvious, exceptional
39441687f09Smrg * cases to avoid polluting the 'GENERIC' namespace with modifiers which only
39541687f09Smrg * apply to a single vendor.
39641687f09Smrg *
39741687f09Smrg * Generic names should not be used for cases where multiple hardware vendors
39841687f09Smrg * have implementations of the same standardised compression scheme (such as
39941687f09Smrg * AFBC). In those cases, all implementations should use the same format
40041687f09Smrg * modifier(s), reflecting the vendor of the standard.
4013f012e29Smrg */
4023f012e29Smrg
40341687f09Smrg#define DRM_FORMAT_MOD_GENERIC_16_16_TILE DRM_FORMAT_MOD_SAMSUNG_16_16_TILE
40441687f09Smrg
405d8807b2fSmrg/*
406d8807b2fSmrg * Invalid Modifier
407d8807b2fSmrg *
408d8807b2fSmrg * This modifier can be used as a sentinel to terminate the format modifiers
409d8807b2fSmrg * list, or to initialize a variable with an invalid modifier. It might also be
410d8807b2fSmrg * used to report an error back to userspace for certain APIs.
411d8807b2fSmrg */
412d8807b2fSmrg#define DRM_FORMAT_MOD_INVALID	fourcc_mod_code(NONE, DRM_FORMAT_RESERVED)
413d8807b2fSmrg
414d8807b2fSmrg/*
415d8807b2fSmrg * Linear Layout
416d8807b2fSmrg *
417d8807b2fSmrg * Just plain linear layout. Note that this is different from no specifying any
418d8807b2fSmrg * modifier (e.g. not setting DRM_MODE_FB_MODIFIERS in the DRM_ADDFB2 ioctl),
419d8807b2fSmrg * which tells the driver to also take driver-internal information into account
420d8807b2fSmrg * and so might actually result in a tiled framebuffer.
421d8807b2fSmrg */
422d8807b2fSmrg#define DRM_FORMAT_MOD_LINEAR	fourcc_mod_code(NONE, 0)
423d8807b2fSmrg
42441687f09Smrg/*
42541687f09Smrg * Deprecated: use DRM_FORMAT_MOD_LINEAR instead
42641687f09Smrg *
42741687f09Smrg * The "none" format modifier doesn't actually mean that the modifier is
42841687f09Smrg * implicit, instead it means that the layout is linear. Whether modifiers are
42941687f09Smrg * used is out-of-band information carried in an API-specific way (e.g. in a
43041687f09Smrg * flag for drm_mode_fb_cmd2).
43141687f09Smrg */
43241687f09Smrg#define DRM_FORMAT_MOD_NONE	0
43341687f09Smrg
4343f012e29Smrg/* Intel framebuffer modifiers */
4353f012e29Smrg
4363f012e29Smrg/*
4373f012e29Smrg * Intel X-tiling layout
4383f012e29Smrg *
4393f012e29Smrg * This is a tiled layout using 4Kb tiles (except on gen2 where the tiles 2Kb)
4403f012e29Smrg * in row-major layout. Within the tile bytes are laid out row-major, with
4413f012e29Smrg * a platform-dependent stride. On top of that the memory can apply
4423f012e29Smrg * platform-depending swizzling of some higher address bits into bit6.
4433f012e29Smrg *
44441687f09Smrg * Note that this layout is only accurate on intel gen 8+ or valleyview chipsets.
44541687f09Smrg * On earlier platforms the is highly platforms specific and not useful for
44641687f09Smrg * cross-driver sharing. It exists since on a given platform it does uniquely
44741687f09Smrg * identify the layout in a simple way for i915-specific userspace, which
44841687f09Smrg * facilitated conversion of userspace to modifiers. Additionally the exact
44941687f09Smrg * format on some really old platforms is not known.
4503f012e29Smrg */
4513f012e29Smrg#define I915_FORMAT_MOD_X_TILED	fourcc_mod_code(INTEL, 1)
4523f012e29Smrg
4533f012e29Smrg/*
4543f012e29Smrg * Intel Y-tiling layout
4553f012e29Smrg *
4563f012e29Smrg * This is a tiled layout using 4Kb tiles (except on gen2 where the tiles 2Kb)
4573f012e29Smrg * in row-major layout. Within the tile bytes are laid out in OWORD (16 bytes)
4583f012e29Smrg * chunks column-major, with a platform-dependent height. On top of that the
4593f012e29Smrg * memory can apply platform-depending swizzling of some higher address bits
4603f012e29Smrg * into bit6.
4613f012e29Smrg *
46241687f09Smrg * Note that this layout is only accurate on intel gen 8+ or valleyview chipsets.
46341687f09Smrg * On earlier platforms the is highly platforms specific and not useful for
46441687f09Smrg * cross-driver sharing. It exists since on a given platform it does uniquely
46541687f09Smrg * identify the layout in a simple way for i915-specific userspace, which
46641687f09Smrg * facilitated conversion of userspace to modifiers. Additionally the exact
46741687f09Smrg * format on some really old platforms is not known.
4683f012e29Smrg */
4693f012e29Smrg#define I915_FORMAT_MOD_Y_TILED	fourcc_mod_code(INTEL, 2)
4703f012e29Smrg
4713f012e29Smrg/*
4723f012e29Smrg * Intel Yf-tiling layout
4733f012e29Smrg *
4743f012e29Smrg * This is a tiled layout using 4Kb tiles in row-major layout.
4753f012e29Smrg * Within the tile pixels are laid out in 16 256 byte units / sub-tiles which
4763f012e29Smrg * are arranged in four groups (two wide, two high) with column-major layout.
4775324fb0dSmrg * Each group therefore consists out of four 256 byte units, which are also laid
4783f012e29Smrg * out as 2x2 column-major.
4793f012e29Smrg * 256 byte units are made out of four 64 byte blocks of pixels, producing
4803f012e29Smrg * either a square block or a 2:1 unit.
4813f012e29Smrg * 64 byte blocks of pixels contain four pixel rows of 16 bytes, where the width
4823f012e29Smrg * in pixel depends on the pixel depth.
4833f012e29Smrg */
4843f012e29Smrg#define I915_FORMAT_MOD_Yf_TILED fourcc_mod_code(INTEL, 3)
4853f012e29Smrg
486d8807b2fSmrg/*
487d8807b2fSmrg * Intel color control surface (CCS) for render compression
488d8807b2fSmrg *
489d8807b2fSmrg * The framebuffer format must be one of the 8:8:8:8 RGB formats.
490d8807b2fSmrg * The main surface will be plane index 0 and must be Y/Yf-tiled,
491d8807b2fSmrg * the CCS will be plane index 1.
492d8807b2fSmrg *
493d8807b2fSmrg * Each CCS tile matches a 1024x512 pixel area of the main surface.
494d8807b2fSmrg * To match certain aspects of the 3D hardware the CCS is
495d8807b2fSmrg * considered to be made up of normal 128Bx32 Y tiles, Thus
496d8807b2fSmrg * the CCS pitch must be specified in multiples of 128 bytes.
497d8807b2fSmrg *
498d8807b2fSmrg * In reality the CCS tile appears to be a 64Bx64 Y tile, composed
499d8807b2fSmrg * of QWORD (8 bytes) chunks instead of OWORD (16 bytes) chunks.
500d8807b2fSmrg * But that fact is not relevant unless the memory is accessed
501d8807b2fSmrg * directly.
502d8807b2fSmrg */
503d8807b2fSmrg#define I915_FORMAT_MOD_Y_TILED_CCS	fourcc_mod_code(INTEL, 4)
504d8807b2fSmrg#define I915_FORMAT_MOD_Yf_TILED_CCS	fourcc_mod_code(INTEL, 5)
505d8807b2fSmrg
50641687f09Smrg/*
50741687f09Smrg * Intel color control surfaces (CCS) for Gen-12 render compression.
50841687f09Smrg *
50941687f09Smrg * The main surface is Y-tiled and at plane index 0, the CCS is linear and
51041687f09Smrg * at index 1. A 64B CCS cache line corresponds to an area of 4x1 tiles in
51141687f09Smrg * main surface. In other words, 4 bits in CCS map to a main surface cache
51241687f09Smrg * line pair. The main surface pitch is required to be a multiple of four
51341687f09Smrg * Y-tile widths.
51441687f09Smrg */
51541687f09Smrg#define I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS fourcc_mod_code(INTEL, 6)
51641687f09Smrg
51741687f09Smrg/*
51841687f09Smrg * Intel color control surfaces (CCS) for Gen-12 media compression
51941687f09Smrg *
52041687f09Smrg * The main surface is Y-tiled and at plane index 0, the CCS is linear and
52141687f09Smrg * at index 1. A 64B CCS cache line corresponds to an area of 4x1 tiles in
52241687f09Smrg * main surface. In other words, 4 bits in CCS map to a main surface cache
52341687f09Smrg * line pair. The main surface pitch is required to be a multiple of four
52441687f09Smrg * Y-tile widths. For semi-planar formats like NV12, CCS planes follow the
52541687f09Smrg * Y and UV planes i.e., planes 0 and 1 are used for Y and UV surfaces,
52641687f09Smrg * planes 2 and 3 for the respective CCS.
52741687f09Smrg */
52841687f09Smrg#define I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS fourcc_mod_code(INTEL, 7)
52941687f09Smrg
5303f012e29Smrg/*
5313f012e29Smrg * Tiled, NV12MT, grouped in 64 (pixels) x 32 (lines) -sized macroblocks
5323f012e29Smrg *
5333f012e29Smrg * Macroblocks are laid in a Z-shape, and each pixel data is following the
5343f012e29Smrg * standard NV12 style.
5353f012e29Smrg * As for NV12, an image is the result of two frame buffers: one for Y,
5363f012e29Smrg * one for the interleaved Cb/Cr components (1/2 the height of the Y buffer).
5373f012e29Smrg * Alignment requirements are (for each buffer):
5383f012e29Smrg * - multiple of 128 pixels for the width
5393f012e29Smrg * - multiple of  32 pixels for the height
5403f012e29Smrg *
5413f012e29Smrg * For more information: see https://linuxtv.org/downloads/v4l-dvb-apis/re32.html
5423f012e29Smrg */
5433f012e29Smrg#define DRM_FORMAT_MOD_SAMSUNG_64_32_TILE	fourcc_mod_code(SAMSUNG, 1)
5443f012e29Smrg
5455324fb0dSmrg/*
5465324fb0dSmrg * Tiled, 16 (pixels) x 16 (lines) - sized macroblocks
5475324fb0dSmrg *
5485324fb0dSmrg * This is a simple tiled layout using tiles of 16x16 pixels in a row-major
5495324fb0dSmrg * layout. For YCbCr formats Cb/Cr components are taken in such a way that
5505324fb0dSmrg * they correspond to their 16x16 luma block.
5515324fb0dSmrg */
5525324fb0dSmrg#define DRM_FORMAT_MOD_SAMSUNG_16_16_TILE	fourcc_mod_code(SAMSUNG, 2)
5535324fb0dSmrg
5547cdc0497Smrg/*
5557cdc0497Smrg * Qualcomm Compressed Format
5567cdc0497Smrg *
5577cdc0497Smrg * Refers to a compressed variant of the base format that is compressed.
5587cdc0497Smrg * Implementation may be platform and base-format specific.
5597cdc0497Smrg *
5607cdc0497Smrg * Each macrotile consists of m x n (mostly 4 x 4) tiles.
5617cdc0497Smrg * Pixel data pitch/stride is aligned with macrotile width.
5627cdc0497Smrg * Pixel data height is aligned with macrotile height.
5637cdc0497Smrg * Entire pixel data buffer is aligned with 4k(bytes).
5647cdc0497Smrg */
5657cdc0497Smrg#define DRM_FORMAT_MOD_QCOM_COMPRESSED	fourcc_mod_code(QCOM, 1)
5667cdc0497Smrg
567d8807b2fSmrg/* Vivante framebuffer modifiers */
568d8807b2fSmrg
569d8807b2fSmrg/*
570d8807b2fSmrg * Vivante 4x4 tiling layout
571d8807b2fSmrg *
572d8807b2fSmrg * This is a simple tiled layout using tiles of 4x4 pixels in a row-major
573d8807b2fSmrg * layout.
574d8807b2fSmrg */
575d8807b2fSmrg#define DRM_FORMAT_MOD_VIVANTE_TILED		fourcc_mod_code(VIVANTE, 1)
576d8807b2fSmrg
577d8807b2fSmrg/*
578d8807b2fSmrg * Vivante 64x64 super-tiling layout
579d8807b2fSmrg *
580d8807b2fSmrg * This is a tiled layout using 64x64 pixel super-tiles, where each super-tile
581d8807b2fSmrg * contains 8x4 groups of 2x4 tiles of 4x4 pixels (like above) each, all in row-
582d8807b2fSmrg * major layout.
583d8807b2fSmrg *
584d8807b2fSmrg * For more information: see
585d8807b2fSmrg * https://github.com/etnaviv/etna_viv/blob/master/doc/hardware.md#texture-tiling
586d8807b2fSmrg */
587d8807b2fSmrg#define DRM_FORMAT_MOD_VIVANTE_SUPER_TILED	fourcc_mod_code(VIVANTE, 2)
588d8807b2fSmrg
589d8807b2fSmrg/*
590d8807b2fSmrg * Vivante 4x4 tiling layout for dual-pipe
591d8807b2fSmrg *
592d8807b2fSmrg * Same as the 4x4 tiling layout, except every second 4x4 pixel tile starts at a
593d8807b2fSmrg * different base address. Offsets from the base addresses are therefore halved
594d8807b2fSmrg * compared to the non-split tiled layout.
595d8807b2fSmrg */
596d8807b2fSmrg#define DRM_FORMAT_MOD_VIVANTE_SPLIT_TILED	fourcc_mod_code(VIVANTE, 3)
597d8807b2fSmrg
598d8807b2fSmrg/*
599d8807b2fSmrg * Vivante 64x64 super-tiling layout for dual-pipe
600d8807b2fSmrg *
601d8807b2fSmrg * Same as the 64x64 super-tiling layout, except every second 4x4 pixel tile
602d8807b2fSmrg * starts at a different base address. Offsets from the base addresses are
603d8807b2fSmrg * therefore halved compared to the non-split super-tiled layout.
604d8807b2fSmrg */
605d8807b2fSmrg#define DRM_FORMAT_MOD_VIVANTE_SPLIT_SUPER_TILED fourcc_mod_code(VIVANTE, 4)
606d8807b2fSmrg
60700a23bdaSmrg/* NVIDIA frame buffer modifiers */
608d8807b2fSmrg
609d8807b2fSmrg/*
610d8807b2fSmrg * Tegra Tiled Layout, used by Tegra 2, 3 and 4.
611d8807b2fSmrg *
612d8807b2fSmrg * Pixels are arranged in simple tiles of 16 x 16 bytes.
613d8807b2fSmrg */
61400a23bdaSmrg#define DRM_FORMAT_MOD_NVIDIA_TEGRA_TILED fourcc_mod_code(NVIDIA, 1)
615d8807b2fSmrg
616d8807b2fSmrg/*
61741687f09Smrg * Generalized Block Linear layout, used by desktop GPUs starting with NV50/G80,
61841687f09Smrg * and Tegra GPUs starting with Tegra K1.
61941687f09Smrg *
62041687f09Smrg * Pixels are arranged in Groups of Bytes (GOBs).  GOB size and layout varies
62141687f09Smrg * based on the architecture generation.  GOBs themselves are then arranged in
62241687f09Smrg * 3D blocks, with the block dimensions (in terms of GOBs) always being a power
62341687f09Smrg * of two, and hence expressible as their log2 equivalent (E.g., "2" represents
62441687f09Smrg * a block depth or height of "4").
62541687f09Smrg *
62641687f09Smrg * Chapter 20 "Pixel Memory Formats" of the Tegra X1 TRM describes this format
62741687f09Smrg * in full detail.
62841687f09Smrg *
62941687f09Smrg *       Macro
63041687f09Smrg * Bits  Param Description
63141687f09Smrg * ----  ----- -----------------------------------------------------------------
63241687f09Smrg *
63341687f09Smrg *  3:0  h     log2(height) of each block, in GOBs.  Placed here for
63441687f09Smrg *             compatibility with the existing
63541687f09Smrg *             DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK()-based modifiers.
63641687f09Smrg *
63741687f09Smrg *  4:4  -     Must be 1, to indicate block-linear layout.  Necessary for
63841687f09Smrg *             compatibility with the existing
63941687f09Smrg *             DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK()-based modifiers.
64041687f09Smrg *
64141687f09Smrg *  8:5  -     Reserved (To support 3D-surfaces with variable log2(depth) block
64241687f09Smrg *             size).  Must be zero.
64341687f09Smrg *
64441687f09Smrg *             Note there is no log2(width) parameter.  Some portions of the
64541687f09Smrg *             hardware support a block width of two gobs, but it is impractical
64641687f09Smrg *             to use due to lack of support elsewhere, and has no known
64741687f09Smrg *             benefits.
64841687f09Smrg *
64941687f09Smrg * 11:9  -     Reserved (To support 2D-array textures with variable array stride
65041687f09Smrg *             in blocks, specified via log2(tile width in blocks)).  Must be
65141687f09Smrg *             zero.
65241687f09Smrg *
65341687f09Smrg * 19:12 k     Page Kind.  This value directly maps to a field in the page
65441687f09Smrg *             tables of all GPUs >= NV50.  It affects the exact layout of bits
65541687f09Smrg *             in memory and can be derived from the tuple
65641687f09Smrg *
65741687f09Smrg *               (format, GPU model, compression type, samples per pixel)
65841687f09Smrg *
65941687f09Smrg *             Where compression type is defined below.  If GPU model were
66041687f09Smrg *             implied by the format modifier, format, or memory buffer, page
66141687f09Smrg *             kind would not need to be included in the modifier itself, but
66241687f09Smrg *             since the modifier should define the layout of the associated
66341687f09Smrg *             memory buffer independent from any device or other context, it
66441687f09Smrg *             must be included here.
66541687f09Smrg *
66641687f09Smrg * 21:20 g     GOB Height and Page Kind Generation.  The height of a GOB changed
66741687f09Smrg *             starting with Fermi GPUs.  Additionally, the mapping between page
66841687f09Smrg *             kind and bit layout has changed at various points.
66941687f09Smrg *
67041687f09Smrg *               0 = Gob Height 8, Fermi - Volta, Tegra K1+ Page Kind mapping
67141687f09Smrg *               1 = Gob Height 4, G80 - GT2XX Page Kind mapping
67241687f09Smrg *               2 = Gob Height 8, Turing+ Page Kind mapping
67341687f09Smrg *               3 = Reserved for future use.
67441687f09Smrg *
67541687f09Smrg * 22:22 s     Sector layout.  On Tegra GPUs prior to Xavier, there is a further
67641687f09Smrg *             bit remapping step that occurs at an even lower level than the
67741687f09Smrg *             page kind and block linear swizzles.  This causes the layout of
67841687f09Smrg *             surfaces mapped in those SOC's GPUs to be incompatible with the
67941687f09Smrg *             equivalent mapping on other GPUs in the same system.
68041687f09Smrg *
68141687f09Smrg *               0 = Tegra K1 - Tegra Parker/TX2 Layout.
68241687f09Smrg *               1 = Desktop GPU and Tegra Xavier+ Layout
68341687f09Smrg *
68441687f09Smrg * 25:23 c     Lossless Framebuffer Compression type.
68541687f09Smrg *
68641687f09Smrg *               0 = none
68741687f09Smrg *               1 = ROP/3D, layout 1, exact compression format implied by Page
68841687f09Smrg *                   Kind field
68941687f09Smrg *               2 = ROP/3D, layout 2, exact compression format implied by Page
69041687f09Smrg *                   Kind field
69141687f09Smrg *               3 = CDE horizontal
69241687f09Smrg *               4 = CDE vertical
69341687f09Smrg *               5 = Reserved for future use
69441687f09Smrg *               6 = Reserved for future use
69541687f09Smrg *               7 = Reserved for future use
69641687f09Smrg *
69741687f09Smrg * 55:25 -     Reserved for future use.  Must be zero.
69841687f09Smrg */
69941687f09Smrg#define DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(c, s, g, k, h) \
70041687f09Smrg	fourcc_mod_code(NVIDIA, (0x10 | \
70141687f09Smrg				 ((h) & 0xf) | \
70241687f09Smrg				 (((k) & 0xff) << 12) | \
70341687f09Smrg				 (((g) & 0x3) << 20) | \
70441687f09Smrg				 (((s) & 0x1) << 22) | \
70541687f09Smrg				 (((c) & 0x7) << 23)))
70641687f09Smrg
70741687f09Smrg/* To grandfather in prior block linear format modifiers to the above layout,
70841687f09Smrg * the page kind "0", which corresponds to "pitch/linear" and hence is unusable
70941687f09Smrg * with block-linear layouts, is remapped within drivers to the value 0xfe,
71041687f09Smrg * which corresponds to the "generic" kind used for simple single-sample
71141687f09Smrg * uncompressed color formats on Fermi - Volta GPUs.
71241687f09Smrg */
71341687f09Smrgstatic __inline__ __u64
71441687f09Smrgdrm_fourcc_canonicalize_nvidia_format_mod(__u64 modifier)
71541687f09Smrg{
71641687f09Smrg	if (!(modifier & 0x10) || (modifier & (0xff << 12)))
71741687f09Smrg		return modifier;
71841687f09Smrg	else
71941687f09Smrg		return modifier | (0xfe << 12);
72041687f09Smrg}
72141687f09Smrg
72241687f09Smrg/*
72341687f09Smrg * 16Bx2 Block Linear layout, used by Tegra K1 and later
724d8807b2fSmrg *
725d8807b2fSmrg * Pixels are arranged in 64x8 Groups Of Bytes (GOBs). GOBs are then stacked
726d8807b2fSmrg * vertically by a power of 2 (1 to 32 GOBs) to form a block.
727d8807b2fSmrg *
728d8807b2fSmrg * Within a GOB, data is ordered as 16B x 2 lines sectors laid in Z-shape.
729d8807b2fSmrg *
730d8807b2fSmrg * Parameter 'v' is the log2 encoding of the number of GOBs stacked vertically.
731d8807b2fSmrg * Valid values are:
732d8807b2fSmrg *
733d8807b2fSmrg * 0 == ONE_GOB
734d8807b2fSmrg * 1 == TWO_GOBS
735d8807b2fSmrg * 2 == FOUR_GOBS
736d8807b2fSmrg * 3 == EIGHT_GOBS
737d8807b2fSmrg * 4 == SIXTEEN_GOBS
738d8807b2fSmrg * 5 == THIRTYTWO_GOBS
739d8807b2fSmrg *
740d8807b2fSmrg * Chapter 20 "Pixel Memory Formats" of the Tegra X1 TRM describes this format
741d8807b2fSmrg * in full detail.
742d8807b2fSmrg */
74300a23bdaSmrg#define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(v) \
74441687f09Smrg	DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 0, 0, 0, (v))
74500a23bdaSmrg
74600a23bdaSmrg#define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_ONE_GOB \
74741687f09Smrg	DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(0)
74800a23bdaSmrg#define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_TWO_GOB \
74941687f09Smrg	DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(1)
75000a23bdaSmrg#define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_FOUR_GOB \
75141687f09Smrg	DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(2)
75200a23bdaSmrg#define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_EIGHT_GOB \
75341687f09Smrg	DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(3)
75400a23bdaSmrg#define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_SIXTEEN_GOB \
75541687f09Smrg	DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(4)
75600a23bdaSmrg#define DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_THIRTYTWO_GOB \
75741687f09Smrg	DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(5)
758d8807b2fSmrg
7597cdc0497Smrg/*
7607cdc0497Smrg * Some Broadcom modifiers take parameters, for example the number of
7617cdc0497Smrg * vertical lines in the image. Reserve the lower 32 bits for modifier
7627cdc0497Smrg * type, and the next 24 bits for parameters. Top 8 bits are the
7637cdc0497Smrg * vendor code.
7647cdc0497Smrg */
7657cdc0497Smrg#define __fourcc_mod_broadcom_param_shift 8
7667cdc0497Smrg#define __fourcc_mod_broadcom_param_bits 48
7677cdc0497Smrg#define fourcc_mod_broadcom_code(val, params) \
7687cdc0497Smrg	fourcc_mod_code(BROADCOM, ((((__u64)params) << __fourcc_mod_broadcom_param_shift) | val))
7697cdc0497Smrg#define fourcc_mod_broadcom_param(m) \
7707cdc0497Smrg	((int)(((m) >> __fourcc_mod_broadcom_param_shift) &	\
7717cdc0497Smrg	       ((1ULL << __fourcc_mod_broadcom_param_bits) - 1)))
7727cdc0497Smrg#define fourcc_mod_broadcom_mod(m) \
7737cdc0497Smrg	((m) & ~(((1ULL << __fourcc_mod_broadcom_param_bits) - 1) <<	\
7747cdc0497Smrg		 __fourcc_mod_broadcom_param_shift))
7757cdc0497Smrg
776d8807b2fSmrg/*
777d8807b2fSmrg * Broadcom VC4 "T" format
778d8807b2fSmrg *
779d8807b2fSmrg * This is the primary layout that the V3D GPU can texture from (it
780d8807b2fSmrg * can't do linear).  The T format has:
781d8807b2fSmrg *
782d8807b2fSmrg * - 64b utiles of pixels in a raster-order grid according to cpp.  It's 4x4
783d8807b2fSmrg *   pixels at 32 bit depth.
784d8807b2fSmrg *
785d8807b2fSmrg * - 1k subtiles made of a 4x4 raster-order grid of 64b utiles (so usually
786d8807b2fSmrg *   16x16 pixels).
787d8807b2fSmrg *
788d8807b2fSmrg * - 4k tiles made of a 2x2 grid of 1k subtiles (so usually 32x32 pixels).  On
789d8807b2fSmrg *   even 4k tile rows, they're arranged as (BL, TL, TR, BR), and on odd rows
790d8807b2fSmrg *   they're (TR, BR, BL, TL), where bottom left is start of memory.
791d8807b2fSmrg *
792d8807b2fSmrg * - an image made of 4k tiles in rows either left-to-right (even rows of 4k
793d8807b2fSmrg *   tiles) or right-to-left (odd rows of 4k tiles).
794d8807b2fSmrg */
795d8807b2fSmrg#define DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED fourcc_mod_code(BROADCOM, 1)
796d8807b2fSmrg
7977cdc0497Smrg/*
7987cdc0497Smrg * Broadcom SAND format
7997cdc0497Smrg *
8007cdc0497Smrg * This is the native format that the H.264 codec block uses.  For VC4
8017cdc0497Smrg * HVS, it is only valid for H.264 (NV12/21) and RGBA modes.
8027cdc0497Smrg *
8037cdc0497Smrg * The image can be considered to be split into columns, and the
8047cdc0497Smrg * columns are placed consecutively into memory.  The width of those
8057cdc0497Smrg * columns can be either 32, 64, 128, or 256 pixels, but in practice
8067cdc0497Smrg * only 128 pixel columns are used.
8077cdc0497Smrg *
8087cdc0497Smrg * The pitch between the start of each column is set to optimally
8097cdc0497Smrg * switch between SDRAM banks. This is passed as the number of lines
8107cdc0497Smrg * of column width in the modifier (we can't use the stride value due
8117cdc0497Smrg * to various core checks that look at it , so you should set the
8127cdc0497Smrg * stride to width*cpp).
8137cdc0497Smrg *
8147cdc0497Smrg * Note that the column height for this format modifier is the same
8157cdc0497Smrg * for all of the planes, assuming that each column contains both Y
8167cdc0497Smrg * and UV.  Some SAND-using hardware stores UV in a separate tiled
8177cdc0497Smrg * image from Y to reduce the column height, which is not supported
8187cdc0497Smrg * with these modifiers.
8197cdc0497Smrg */
8207cdc0497Smrg
8217cdc0497Smrg#define DRM_FORMAT_MOD_BROADCOM_SAND32_COL_HEIGHT(v) \
8227cdc0497Smrg	fourcc_mod_broadcom_code(2, v)
8237cdc0497Smrg#define DRM_FORMAT_MOD_BROADCOM_SAND64_COL_HEIGHT(v) \
8247cdc0497Smrg	fourcc_mod_broadcom_code(3, v)
8257cdc0497Smrg#define DRM_FORMAT_MOD_BROADCOM_SAND128_COL_HEIGHT(v) \
8267cdc0497Smrg	fourcc_mod_broadcom_code(4, v)
8277cdc0497Smrg#define DRM_FORMAT_MOD_BROADCOM_SAND256_COL_HEIGHT(v) \
8287cdc0497Smrg	fourcc_mod_broadcom_code(5, v)
8297cdc0497Smrg
8307cdc0497Smrg#define DRM_FORMAT_MOD_BROADCOM_SAND32 \
8317cdc0497Smrg	DRM_FORMAT_MOD_BROADCOM_SAND32_COL_HEIGHT(0)
8327cdc0497Smrg#define DRM_FORMAT_MOD_BROADCOM_SAND64 \
8337cdc0497Smrg	DRM_FORMAT_MOD_BROADCOM_SAND64_COL_HEIGHT(0)
8347cdc0497Smrg#define DRM_FORMAT_MOD_BROADCOM_SAND128 \
8357cdc0497Smrg	DRM_FORMAT_MOD_BROADCOM_SAND128_COL_HEIGHT(0)
8367cdc0497Smrg#define DRM_FORMAT_MOD_BROADCOM_SAND256 \
8377cdc0497Smrg	DRM_FORMAT_MOD_BROADCOM_SAND256_COL_HEIGHT(0)
8387cdc0497Smrg
8397cdc0497Smrg/* Broadcom UIF format
8407cdc0497Smrg *
8417cdc0497Smrg * This is the common format for the current Broadcom multimedia
8427cdc0497Smrg * blocks, including V3D 3.x and newer, newer video codecs, and
8437cdc0497Smrg * displays.
8447cdc0497Smrg *
8457cdc0497Smrg * The image consists of utiles (64b blocks), UIF blocks (2x2 utiles),
8467cdc0497Smrg * and macroblocks (4x4 UIF blocks).  Those 4x4 UIF block groups are
8477cdc0497Smrg * stored in columns, with padding between the columns to ensure that
8487cdc0497Smrg * moving from one column to the next doesn't hit the same SDRAM page
8497cdc0497Smrg * bank.
8507cdc0497Smrg *
8517cdc0497Smrg * To calculate the padding, it is assumed that each hardware block
8527cdc0497Smrg * and the software driving it knows the platform's SDRAM page size,
8537cdc0497Smrg * number of banks, and XOR address, and that it's identical between
8547cdc0497Smrg * all blocks using the format.  This tiling modifier will use XOR as
8557cdc0497Smrg * necessary to reduce the padding.  If a hardware block can't do XOR,
8567cdc0497Smrg * the assumption is that a no-XOR tiling modifier will be created.
8577cdc0497Smrg */
8587cdc0497Smrg#define DRM_FORMAT_MOD_BROADCOM_UIF fourcc_mod_code(BROADCOM, 6)
8597cdc0497Smrg
8607cdc0497Smrg/*
8617cdc0497Smrg * Arm Framebuffer Compression (AFBC) modifiers
8627cdc0497Smrg *
8637cdc0497Smrg * AFBC is a proprietary lossless image compression protocol and format.
8647cdc0497Smrg * It provides fine-grained random access and minimizes the amount of data
8657cdc0497Smrg * transferred between IP blocks.
8667cdc0497Smrg *
8677cdc0497Smrg * AFBC has several features which may be supported and/or used, which are
8687cdc0497Smrg * represented using bits in the modifier. Not all combinations are valid,
8697cdc0497Smrg * and different devices or use-cases may support different combinations.
8705324fb0dSmrg *
8715324fb0dSmrg * Further information on the use of AFBC modifiers can be found in
8725324fb0dSmrg * Documentation/gpu/afbc.rst
8737cdc0497Smrg */
87441687f09Smrg
87541687f09Smrg/*
87641687f09Smrg * The top 4 bits (out of the 56 bits alloted for specifying vendor specific
87741687f09Smrg * modifiers) denote the category for modifiers. Currently we have only two
87841687f09Smrg * categories of modifiers ie AFBC and MISC. We can have a maximum of sixteen
87941687f09Smrg * different categories.
88041687f09Smrg */
88141687f09Smrg#define DRM_FORMAT_MOD_ARM_CODE(__type, __val) \
88241687f09Smrg	fourcc_mod_code(ARM, ((__u64)(__type) << 52) | ((__val) & 0x000fffffffffffffULL))
88341687f09Smrg
88441687f09Smrg#define DRM_FORMAT_MOD_ARM_TYPE_AFBC 0x00
88541687f09Smrg#define DRM_FORMAT_MOD_ARM_TYPE_MISC 0x01
88641687f09Smrg
88741687f09Smrg#define DRM_FORMAT_MOD_ARM_AFBC(__afbc_mode) \
88841687f09Smrg	DRM_FORMAT_MOD_ARM_CODE(DRM_FORMAT_MOD_ARM_TYPE_AFBC, __afbc_mode)
8897cdc0497Smrg
8907cdc0497Smrg/*
8917cdc0497Smrg * AFBC superblock size
8927cdc0497Smrg *
8937cdc0497Smrg * Indicates the superblock size(s) used for the AFBC buffer. The buffer
8947cdc0497Smrg * size (in pixels) must be aligned to a multiple of the superblock size.
8957cdc0497Smrg * Four lowest significant bits(LSBs) are reserved for block size.
8965324fb0dSmrg *
8975324fb0dSmrg * Where one superblock size is specified, it applies to all planes of the
8985324fb0dSmrg * buffer (e.g. 16x16, 32x8). When multiple superblock sizes are specified,
8995324fb0dSmrg * the first applies to the Luma plane and the second applies to the Chroma
9005324fb0dSmrg * plane(s). e.g. (32x8_64x4 means 32x8 Luma, with 64x4 Chroma).
9015324fb0dSmrg * Multiple superblock sizes are only valid for multi-plane YCbCr formats.
9027cdc0497Smrg */
9037cdc0497Smrg#define AFBC_FORMAT_MOD_BLOCK_SIZE_MASK      0xf
9047cdc0497Smrg#define AFBC_FORMAT_MOD_BLOCK_SIZE_16x16     (1ULL)
9057cdc0497Smrg#define AFBC_FORMAT_MOD_BLOCK_SIZE_32x8      (2ULL)
9065324fb0dSmrg#define AFBC_FORMAT_MOD_BLOCK_SIZE_64x4      (3ULL)
9075324fb0dSmrg#define AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4 (4ULL)
9087cdc0497Smrg
9097cdc0497Smrg/*
9107cdc0497Smrg * AFBC lossless colorspace transform
9117cdc0497Smrg *
9127cdc0497Smrg * Indicates that the buffer makes use of the AFBC lossless colorspace
9137cdc0497Smrg * transform.
9147cdc0497Smrg */
9157cdc0497Smrg#define AFBC_FORMAT_MOD_YTR     (1ULL <<  4)
9167cdc0497Smrg
9177cdc0497Smrg/*
9187cdc0497Smrg * AFBC block-split
9197cdc0497Smrg *
9207cdc0497Smrg * Indicates that the payload of each superblock is split. The second
9217cdc0497Smrg * half of the payload is positioned at a predefined offset from the start
9227cdc0497Smrg * of the superblock payload.
9237cdc0497Smrg */
9247cdc0497Smrg#define AFBC_FORMAT_MOD_SPLIT   (1ULL <<  5)
9257cdc0497Smrg
9267cdc0497Smrg/*
9277cdc0497Smrg * AFBC sparse layout
9287cdc0497Smrg *
9297cdc0497Smrg * This flag indicates that the payload of each superblock must be stored at a
9307cdc0497Smrg * predefined position relative to the other superblocks in the same AFBC
9317cdc0497Smrg * buffer. This order is the same order used by the header buffer. In this mode
9327cdc0497Smrg * each superblock is given the same amount of space as an uncompressed
9337cdc0497Smrg * superblock of the particular format would require, rounding up to the next
9347cdc0497Smrg * multiple of 128 bytes in size.
9357cdc0497Smrg */
9367cdc0497Smrg#define AFBC_FORMAT_MOD_SPARSE  (1ULL <<  6)
9377cdc0497Smrg
9387cdc0497Smrg/*
9397cdc0497Smrg * AFBC copy-block restrict
9407cdc0497Smrg *
9417cdc0497Smrg * Buffers with this flag must obey the copy-block restriction. The restriction
9427cdc0497Smrg * is such that there are no copy-blocks referring across the border of 8x8
9437cdc0497Smrg * blocks. For the subsampled data the 8x8 limitation is also subsampled.
9447cdc0497Smrg */
9457cdc0497Smrg#define AFBC_FORMAT_MOD_CBR     (1ULL <<  7)
9467cdc0497Smrg
9477cdc0497Smrg/*
9487cdc0497Smrg * AFBC tiled layout
9497cdc0497Smrg *
9507cdc0497Smrg * The tiled layout groups superblocks in 8x8 or 4x4 tiles, where all
9517cdc0497Smrg * superblocks inside a tile are stored together in memory. 8x8 tiles are used
9527cdc0497Smrg * for pixel formats up to and including 32 bpp while 4x4 tiles are used for
9537cdc0497Smrg * larger bpp formats. The order between the tiles is scan line.
9547cdc0497Smrg * When the tiled layout is used, the buffer size (in pixels) must be aligned
9557cdc0497Smrg * to the tile size.
9567cdc0497Smrg */
9577cdc0497Smrg#define AFBC_FORMAT_MOD_TILED   (1ULL <<  8)
9587cdc0497Smrg
9597cdc0497Smrg/*
9607cdc0497Smrg * AFBC solid color blocks
9617cdc0497Smrg *
9627cdc0497Smrg * Indicates that the buffer makes use of solid-color blocks, whereby bandwidth
9637cdc0497Smrg * can be reduced if a whole superblock is a single color.
9647cdc0497Smrg */
9657cdc0497Smrg#define AFBC_FORMAT_MOD_SC      (1ULL <<  9)
9667cdc0497Smrg
9675324fb0dSmrg/*
9685324fb0dSmrg * AFBC double-buffer
9695324fb0dSmrg *
9705324fb0dSmrg * Indicates that the buffer is allocated in a layout safe for front-buffer
9715324fb0dSmrg * rendering.
9725324fb0dSmrg */
9735324fb0dSmrg#define AFBC_FORMAT_MOD_DB      (1ULL << 10)
9745324fb0dSmrg
9755324fb0dSmrg/*
9765324fb0dSmrg * AFBC buffer content hints
9775324fb0dSmrg *
9785324fb0dSmrg * Indicates that the buffer includes per-superblock content hints.
9795324fb0dSmrg */
9805324fb0dSmrg#define AFBC_FORMAT_MOD_BCH     (1ULL << 11)
9815324fb0dSmrg
98241687f09Smrg/* AFBC uncompressed storage mode
98341687f09Smrg *
98441687f09Smrg * Indicates that the buffer is using AFBC uncompressed storage mode.
98541687f09Smrg * In this mode all superblock payloads in the buffer use the uncompressed
98641687f09Smrg * storage mode, which is usually only used for data which cannot be compressed.
98741687f09Smrg * The buffer layout is the same as for AFBC buffers without USM set, this only
98841687f09Smrg * affects the storage mode of the individual superblocks. Note that even a
98941687f09Smrg * buffer without USM set may use uncompressed storage mode for some or all
99041687f09Smrg * superblocks, USM just guarantees it for all.
99141687f09Smrg */
99241687f09Smrg#define AFBC_FORMAT_MOD_USM	(1ULL << 12)
99341687f09Smrg
99441687f09Smrg/*
99541687f09Smrg * Arm 16x16 Block U-Interleaved modifier
99641687f09Smrg *
99741687f09Smrg * This is used by Arm Mali Utgard and Midgard GPUs. It divides the image
99841687f09Smrg * into 16x16 pixel blocks. Blocks are stored linearly in order, but pixels
99941687f09Smrg * in the block are reordered.
100041687f09Smrg */
100141687f09Smrg#define DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED \
100241687f09Smrg	DRM_FORMAT_MOD_ARM_CODE(DRM_FORMAT_MOD_ARM_TYPE_MISC, 1ULL)
100341687f09Smrg
10045324fb0dSmrg/*
10055324fb0dSmrg * Allwinner tiled modifier
10065324fb0dSmrg *
10075324fb0dSmrg * This tiling mode is implemented by the VPU found on all Allwinner platforms,
10085324fb0dSmrg * codenamed sunxi. It is associated with a YUV format that uses either 2 or 3
10095324fb0dSmrg * planes.
10105324fb0dSmrg *
10115324fb0dSmrg * With this tiling, the luminance samples are disposed in tiles representing
10125324fb0dSmrg * 32x32 pixels and the chrominance samples in tiles representing 32x64 pixels.
10135324fb0dSmrg * The pixel order in each tile is linear and the tiles are disposed linearly,
10145324fb0dSmrg * both in row-major order.
10155324fb0dSmrg */
10165324fb0dSmrg#define DRM_FORMAT_MOD_ALLWINNER_TILED fourcc_mod_code(ALLWINNER, 1)
10175324fb0dSmrg
101841687f09Smrg/*
101941687f09Smrg * Amlogic Video Framebuffer Compression modifiers
102041687f09Smrg *
102141687f09Smrg * Amlogic uses a proprietary lossless image compression protocol and format
102241687f09Smrg * for their hardware video codec accelerators, either video decoders or
102341687f09Smrg * video input encoders.
102441687f09Smrg *
102541687f09Smrg * It considerably reduces memory bandwidth while writing and reading
102641687f09Smrg * frames in memory.
102741687f09Smrg *
102841687f09Smrg * The underlying storage is considered to be 3 components, 8bit or 10-bit
102941687f09Smrg * per component YCbCr 420, single plane :
103041687f09Smrg * - DRM_FORMAT_YUV420_8BIT
103141687f09Smrg * - DRM_FORMAT_YUV420_10BIT
103241687f09Smrg *
103341687f09Smrg * The first 8 bits of the mode defines the layout, then the following 8 bits
103441687f09Smrg * defines the options changing the layout.
103541687f09Smrg *
103641687f09Smrg * Not all combinations are valid, and different SoCs may support different
103741687f09Smrg * combinations of layout and options.
103841687f09Smrg */
103941687f09Smrg#define __fourcc_mod_amlogic_layout_mask 0xf
104041687f09Smrg#define __fourcc_mod_amlogic_options_shift 8
104141687f09Smrg#define __fourcc_mod_amlogic_options_mask 0xf
104241687f09Smrg
104341687f09Smrg#define DRM_FORMAT_MOD_AMLOGIC_FBC(__layout, __options) \
104441687f09Smrg	fourcc_mod_code(AMLOGIC, \
104541687f09Smrg			((__layout) & __fourcc_mod_amlogic_layout_mask) | \
104641687f09Smrg			(((__options) & __fourcc_mod_amlogic_options_mask) \
104741687f09Smrg			 << __fourcc_mod_amlogic_options_shift))
104841687f09Smrg
104941687f09Smrg/* Amlogic FBC Layouts */
105041687f09Smrg
105141687f09Smrg/*
105241687f09Smrg * Amlogic FBC Basic Layout
105341687f09Smrg *
105441687f09Smrg * The basic layout is composed of:
105541687f09Smrg * - a body content organized in 64x32 superblocks with 4096 bytes per
105641687f09Smrg *   superblock in default mode.
105741687f09Smrg * - a 32 bytes per 128x64 header block
105841687f09Smrg *
105941687f09Smrg * This layout is transferrable between Amlogic SoCs supporting this modifier.
106041687f09Smrg */
106141687f09Smrg#define AMLOGIC_FBC_LAYOUT_BASIC		(1ULL)
106241687f09Smrg
106341687f09Smrg/*
106441687f09Smrg * Amlogic FBC Scatter Memory layout
106541687f09Smrg *
106641687f09Smrg * Indicates the header contains IOMMU references to the compressed
106741687f09Smrg * frames content to optimize memory access and layout.
106841687f09Smrg *
106941687f09Smrg * In this mode, only the header memory address is needed, thus the
107041687f09Smrg * content memory organization is tied to the current producer
107141687f09Smrg * execution and cannot be saved/dumped neither transferrable between
107241687f09Smrg * Amlogic SoCs supporting this modifier.
107341687f09Smrg *
107441687f09Smrg * Due to the nature of the layout, these buffers are not expected to
107541687f09Smrg * be accessible by the user-space clients, but only accessible by the
107641687f09Smrg * hardware producers and consumers.
107741687f09Smrg *
107841687f09Smrg * The user-space clients should expect a failure while trying to mmap
107941687f09Smrg * the DMA-BUF handle returned by the producer.
108041687f09Smrg */
108141687f09Smrg#define AMLOGIC_FBC_LAYOUT_SCATTER		(2ULL)
108241687f09Smrg
108341687f09Smrg/* Amlogic FBC Layout Options Bit Mask */
108441687f09Smrg
108541687f09Smrg/*
108641687f09Smrg * Amlogic FBC Memory Saving mode
108741687f09Smrg *
108841687f09Smrg * Indicates the storage is packed when pixel size is multiple of word
108941687f09Smrg * boudaries, i.e. 8bit should be stored in this mode to save allocation
109041687f09Smrg * memory.
109141687f09Smrg *
109241687f09Smrg * This mode reduces body layout to 3072 bytes per 64x32 superblock with
109341687f09Smrg * the basic layout and 3200 bytes per 64x32 superblock combined with
109441687f09Smrg * the scatter layout.
109541687f09Smrg */
109641687f09Smrg#define AMLOGIC_FBC_OPTION_MEM_SAVING		(1ULL << 0)
109741687f09Smrg
109841687f09Smrg/*
109941687f09Smrg * AMD modifiers
110041687f09Smrg *
110141687f09Smrg * Memory layout:
110241687f09Smrg *
110341687f09Smrg * without DCC:
110441687f09Smrg *   - main surface
110541687f09Smrg *
110641687f09Smrg * with DCC & without DCC_RETILE:
110741687f09Smrg *   - main surface in plane 0
110841687f09Smrg *   - DCC surface in plane 1 (RB-aligned, pipe-aligned if DCC_PIPE_ALIGN is set)
110941687f09Smrg *
111041687f09Smrg * with DCC & DCC_RETILE:
111141687f09Smrg *   - main surface in plane 0
111241687f09Smrg *   - displayable DCC surface in plane 1 (not RB-aligned & not pipe-aligned)
111341687f09Smrg *   - pipe-aligned DCC surface in plane 2 (RB-aligned & pipe-aligned)
111441687f09Smrg *
111541687f09Smrg * For multi-plane formats the above surfaces get merged into one plane for
111641687f09Smrg * each format plane, based on the required alignment only.
111741687f09Smrg *
111841687f09Smrg * Bits  Parameter                Notes
111941687f09Smrg * ----- ------------------------ ---------------------------------------------
112041687f09Smrg *
112141687f09Smrg *   7:0 TILE_VERSION             Values are AMD_FMT_MOD_TILE_VER_*
112241687f09Smrg *  12:8 TILE                     Values are AMD_FMT_MOD_TILE_<version>_*
112341687f09Smrg *    13 DCC
112441687f09Smrg *    14 DCC_RETILE
112541687f09Smrg *    15 DCC_PIPE_ALIGN
112641687f09Smrg *    16 DCC_INDEPENDENT_64B
112741687f09Smrg *    17 DCC_INDEPENDENT_128B
112841687f09Smrg * 19:18 DCC_MAX_COMPRESSED_BLOCK Values are AMD_FMT_MOD_DCC_BLOCK_*
112941687f09Smrg *    20 DCC_CONSTANT_ENCODE
113041687f09Smrg * 23:21 PIPE_XOR_BITS            Only for some chips
113141687f09Smrg * 26:24 BANK_XOR_BITS            Only for some chips
113241687f09Smrg * 29:27 PACKERS                  Only for some chips
113341687f09Smrg * 32:30 RB                       Only for some chips
113441687f09Smrg * 35:33 PIPE                     Only for some chips
113541687f09Smrg * 55:36 -                        Reserved for future use, must be zero
113641687f09Smrg */
113741687f09Smrg#define AMD_FMT_MOD fourcc_mod_code(AMD, 0)
113841687f09Smrg
113941687f09Smrg#define IS_AMD_FMT_MOD(val) (((val) >> 56) == DRM_FORMAT_MOD_VENDOR_AMD)
114041687f09Smrg
114141687f09Smrg/* Reserve 0 for GFX8 and older */
114241687f09Smrg#define AMD_FMT_MOD_TILE_VER_GFX9 1
114341687f09Smrg#define AMD_FMT_MOD_TILE_VER_GFX10 2
114441687f09Smrg#define AMD_FMT_MOD_TILE_VER_GFX10_RBPLUS 3
114541687f09Smrg
114641687f09Smrg/*
114741687f09Smrg * 64K_S is the same for GFX9/GFX10/GFX10_RBPLUS and hence has GFX9 as canonical
114841687f09Smrg * version.
114941687f09Smrg */
115041687f09Smrg#define AMD_FMT_MOD_TILE_GFX9_64K_S 9
115141687f09Smrg
115241687f09Smrg/*
115341687f09Smrg * 64K_D for non-32 bpp is the same for GFX9/GFX10/GFX10_RBPLUS and hence has
115441687f09Smrg * GFX9 as canonical version.
115541687f09Smrg */
115641687f09Smrg#define AMD_FMT_MOD_TILE_GFX9_64K_D 10
115741687f09Smrg#define AMD_FMT_MOD_TILE_GFX9_64K_S_X 25
115841687f09Smrg#define AMD_FMT_MOD_TILE_GFX9_64K_D_X 26
115941687f09Smrg#define AMD_FMT_MOD_TILE_GFX9_64K_R_X 27
116041687f09Smrg
116141687f09Smrg#define AMD_FMT_MOD_DCC_BLOCK_64B 0
116241687f09Smrg#define AMD_FMT_MOD_DCC_BLOCK_128B 1
116341687f09Smrg#define AMD_FMT_MOD_DCC_BLOCK_256B 2
116441687f09Smrg
116541687f09Smrg#define AMD_FMT_MOD_TILE_VERSION_SHIFT 0
116641687f09Smrg#define AMD_FMT_MOD_TILE_VERSION_MASK 0xFF
116741687f09Smrg#define AMD_FMT_MOD_TILE_SHIFT 8
116841687f09Smrg#define AMD_FMT_MOD_TILE_MASK 0x1F
116941687f09Smrg
117041687f09Smrg/* Whether DCC compression is enabled. */
117141687f09Smrg#define AMD_FMT_MOD_DCC_SHIFT 13
117241687f09Smrg#define AMD_FMT_MOD_DCC_MASK 0x1
117341687f09Smrg
117441687f09Smrg/*
117541687f09Smrg * Whether to include two DCC surfaces, one which is rb & pipe aligned, and
117641687f09Smrg * one which is not-aligned.
117741687f09Smrg */
117841687f09Smrg#define AMD_FMT_MOD_DCC_RETILE_SHIFT 14
117941687f09Smrg#define AMD_FMT_MOD_DCC_RETILE_MASK 0x1
118041687f09Smrg
118141687f09Smrg/* Only set if DCC_RETILE = false */
118241687f09Smrg#define AMD_FMT_MOD_DCC_PIPE_ALIGN_SHIFT 15
118341687f09Smrg#define AMD_FMT_MOD_DCC_PIPE_ALIGN_MASK 0x1
118441687f09Smrg
118541687f09Smrg#define AMD_FMT_MOD_DCC_INDEPENDENT_64B_SHIFT 16
118641687f09Smrg#define AMD_FMT_MOD_DCC_INDEPENDENT_64B_MASK 0x1
118741687f09Smrg#define AMD_FMT_MOD_DCC_INDEPENDENT_128B_SHIFT 17
118841687f09Smrg#define AMD_FMT_MOD_DCC_INDEPENDENT_128B_MASK 0x1
118941687f09Smrg#define AMD_FMT_MOD_DCC_MAX_COMPRESSED_BLOCK_SHIFT 18
119041687f09Smrg#define AMD_FMT_MOD_DCC_MAX_COMPRESSED_BLOCK_MASK 0x3
119141687f09Smrg
119241687f09Smrg/*
119341687f09Smrg * DCC supports embedding some clear colors directly in the DCC surface.
119441687f09Smrg * However, on older GPUs the rendering HW ignores the embedded clear color
119541687f09Smrg * and prefers the driver provided color. This necessitates doing a fastclear
119641687f09Smrg * eliminate operation before a process transfers control.
119741687f09Smrg *
119841687f09Smrg * If this bit is set that means the fastclear eliminate is not needed for these
119941687f09Smrg * embeddable colors.
120041687f09Smrg */
120141687f09Smrg#define AMD_FMT_MOD_DCC_CONSTANT_ENCODE_SHIFT 20
120241687f09Smrg#define AMD_FMT_MOD_DCC_CONSTANT_ENCODE_MASK 0x1
120341687f09Smrg
120441687f09Smrg/*
120541687f09Smrg * The below fields are for accounting for per GPU differences. These are only
120641687f09Smrg * relevant for GFX9 and later and if the tile field is *_X/_T.
120741687f09Smrg *
120841687f09Smrg * PIPE_XOR_BITS = always needed
120941687f09Smrg * BANK_XOR_BITS = only for TILE_VER_GFX9
121041687f09Smrg * PACKERS = only for TILE_VER_GFX10_RBPLUS
121141687f09Smrg * RB = only for TILE_VER_GFX9 & DCC
121241687f09Smrg * PIPE = only for TILE_VER_GFX9 & DCC & (DCC_RETILE | DCC_PIPE_ALIGN)
121341687f09Smrg */
121441687f09Smrg#define AMD_FMT_MOD_PIPE_XOR_BITS_SHIFT 21
121541687f09Smrg#define AMD_FMT_MOD_PIPE_XOR_BITS_MASK 0x7
121641687f09Smrg#define AMD_FMT_MOD_BANK_XOR_BITS_SHIFT 24
121741687f09Smrg#define AMD_FMT_MOD_BANK_XOR_BITS_MASK 0x7
121841687f09Smrg#define AMD_FMT_MOD_PACKERS_SHIFT 27
121941687f09Smrg#define AMD_FMT_MOD_PACKERS_MASK 0x7
122041687f09Smrg#define AMD_FMT_MOD_RB_SHIFT 30
122141687f09Smrg#define AMD_FMT_MOD_RB_MASK 0x7
122241687f09Smrg#define AMD_FMT_MOD_PIPE_SHIFT 33
122341687f09Smrg#define AMD_FMT_MOD_PIPE_MASK 0x7
122441687f09Smrg
122541687f09Smrg#define AMD_FMT_MOD_SET(field, value) \
122641687f09Smrg	((uint64_t)(value) << AMD_FMT_MOD_##field##_SHIFT)
122741687f09Smrg#define AMD_FMT_MOD_GET(field, value) \
122841687f09Smrg	(((value) >> AMD_FMT_MOD_##field##_SHIFT) & AMD_FMT_MOD_##field##_MASK)
122941687f09Smrg#define AMD_FMT_MOD_CLEAR(field) \
123041687f09Smrg	(~((uint64_t)AMD_FMT_MOD_##field##_MASK << AMD_FMT_MOD_##field##_SHIFT))
123141687f09Smrg
1232d8807b2fSmrg#if defined(__cplusplus)
1233d8807b2fSmrg}
1234d8807b2fSmrg#endif
1235d8807b2fSmrg
1236e88f27b3Smrg#endif /* DRM_FOURCC_H */
1237