abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 1 | /* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 13 | #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__ |
| 14 | |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 15 | #include <uapi/drm/drm_fourcc.h> |
abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 16 | #include <uapi/media/msm_media_info.h> |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 17 | |
Clarence Ip | c475b08 | 2016-06-26 09:27:23 -0400 | [diff] [blame] | 18 | #include "sde_kms.h" |
| 19 | #include "sde_formats.h" |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 20 | |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 21 | #define SDE_UBWC_META_MACRO_W_H 16 |
| 22 | #define SDE_UBWC_META_BLOCK_SIZE 256 |
abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 23 | #define SDE_UBWC_PLANE_SIZE_ALIGNMENT 4096 |
| 24 | |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 25 | #define SDE_MAX_IMG_WIDTH 0x3FFF |
| 26 | #define SDE_MAX_IMG_HEIGHT 0x3FFF |
| 27 | |
| 28 | /** |
| 29 | * SDE supported format packing, bpp, and other format |
| 30 | * information. |
| 31 | * SDE currently only supports interleaved RGB formats |
| 32 | * UBWC support for a pixel format is indicated by the flag, |
| 33 | * there is additional meta data plane for such formats |
| 34 | */ |
| 35 | |
| 36 | #define INTERLEAVED_RGB_FMT(fmt, a, r, g, b, e0, e1, e2, e3, uc, alpha, \ |
| 37 | bp, flg, fm, np) \ |
| 38 | { \ |
| 39 | .base.pixel_format = DRM_FORMAT_ ## fmt, \ |
| 40 | .fetch_planes = SDE_PLANE_INTERLEAVED, \ |
| 41 | .alpha_enable = alpha, \ |
| 42 | .element = { (e0), (e1), (e2), (e3) }, \ |
| 43 | .bits = { g, b, r, a }, \ |
| 44 | .chroma_sample = SDE_CHROMA_RGB, \ |
| 45 | .unpack_align_msb = 0, \ |
| 46 | .unpack_tight = 1, \ |
| 47 | .unpack_count = uc, \ |
| 48 | .bpp = bp, \ |
| 49 | .fetch_mode = fm, \ |
abeykun | 2997c81 | 2016-10-04 11:34:15 -0400 | [diff] [blame] | 50 | .flag = {(flg)}, \ |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 51 | .num_planes = np \ |
| 52 | } |
| 53 | |
| 54 | #define INTERLEAVED_YUV_FMT(fmt, a, r, g, b, e0, e1, e2, e3, \ |
| 55 | alpha, chroma, count, bp, flg, fm, np) \ |
| 56 | { \ |
| 57 | .base.pixel_format = DRM_FORMAT_ ## fmt, \ |
| 58 | .fetch_planes = SDE_PLANE_INTERLEAVED, \ |
| 59 | .alpha_enable = alpha, \ |
| 60 | .element = { (e0), (e1), (e2), (e3)}, \ |
| 61 | .bits = { g, b, r, a }, \ |
| 62 | .chroma_sample = chroma, \ |
| 63 | .unpack_align_msb = 0, \ |
| 64 | .unpack_tight = 1, \ |
| 65 | .unpack_count = count, \ |
| 66 | .bpp = bp, \ |
| 67 | .fetch_mode = fm, \ |
abeykun | 2997c81 | 2016-10-04 11:34:15 -0400 | [diff] [blame] | 68 | .flag = {(flg)}, \ |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 69 | .num_planes = np \ |
| 70 | } |
| 71 | |
abeykun | 5ed42e1 | 2016-08-24 17:09:26 -0400 | [diff] [blame] | 72 | #define PSEUDO_YUV_FMT(fmt, a, r, g, b, e0, e1, chroma, flg, fm, np) \ |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 73 | { \ |
| 74 | .base.pixel_format = DRM_FORMAT_ ## fmt, \ |
| 75 | .fetch_planes = SDE_PLANE_PSEUDO_PLANAR, \ |
| 76 | .alpha_enable = false, \ |
| 77 | .element = { (e0), (e1), 0, 0 }, \ |
| 78 | .bits = { g, b, r, a }, \ |
| 79 | .chroma_sample = chroma, \ |
| 80 | .unpack_align_msb = 0, \ |
| 81 | .unpack_tight = 1, \ |
| 82 | .unpack_count = 2, \ |
| 83 | .bpp = 2, \ |
| 84 | .fetch_mode = fm, \ |
abeykun | 2997c81 | 2016-10-04 11:34:15 -0400 | [diff] [blame] | 85 | .flag = {(flg)}, \ |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 86 | .num_planes = np \ |
| 87 | } |
| 88 | |
abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 89 | #define PSEUDO_YUV_FMT_LOOSE(fmt, a, r, g, b, e0, e1, chroma, flg, fm, np)\ |
| 90 | { \ |
| 91 | .base.pixel_format = DRM_FORMAT_ ## fmt, \ |
| 92 | .fetch_planes = SDE_PLANE_PSEUDO_PLANAR, \ |
| 93 | .alpha_enable = false, \ |
| 94 | .element = { (e0), (e1), 0, 0 }, \ |
| 95 | .bits = { g, b, r, a }, \ |
| 96 | .chroma_sample = chroma, \ |
| 97 | .unpack_align_msb = 1, \ |
| 98 | .unpack_tight = 0, \ |
| 99 | .unpack_count = 2, \ |
| 100 | .bpp = 2, \ |
| 101 | .fetch_mode = fm, \ |
abeykun | 2997c81 | 2016-10-04 11:34:15 -0400 | [diff] [blame] | 102 | .flag = {(flg)}, \ |
abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 103 | .num_planes = np \ |
| 104 | } |
| 105 | |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 106 | #define PLANAR_YUV_FMT(fmt, a, r, g, b, e0, e1, e2, alpha, chroma, bp, \ |
| 107 | flg, fm, np) \ |
| 108 | { \ |
| 109 | .base.pixel_format = DRM_FORMAT_ ## fmt, \ |
| 110 | .fetch_planes = SDE_PLANE_PLANAR, \ |
| 111 | .alpha_enable = alpha, \ |
| 112 | .element = { (e0), (e1), (e2), 0 }, \ |
| 113 | .bits = { g, b, r, a }, \ |
| 114 | .chroma_sample = chroma, \ |
| 115 | .unpack_align_msb = 0, \ |
| 116 | .unpack_tight = 1, \ |
| 117 | .unpack_count = 1, \ |
| 118 | .bpp = bp, \ |
| 119 | .fetch_mode = fm, \ |
abeykun | 2997c81 | 2016-10-04 11:34:15 -0400 | [diff] [blame] | 120 | .flag = {(flg)}, \ |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 121 | .num_planes = np \ |
| 122 | } |
| 123 | |
abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 124 | /* |
| 125 | * struct sde_media_color_map - maps drm format to media format |
| 126 | * @format: DRM base pixel format |
| 127 | * @color: Media API color related to DRM format |
| 128 | */ |
| 129 | struct sde_media_color_map { |
| 130 | uint32_t format; |
| 131 | uint32_t color; |
| 132 | }; |
| 133 | |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 134 | static const struct sde_format sde_format_map[] = { |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 135 | INTERLEAVED_RGB_FMT(ARGB8888, |
| 136 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 137 | C3_ALPHA, C2_R_Cr, C0_G_Y, C1_B_Cb, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 138 | true, 4, 0, |
| 139 | SDE_FETCH_LINEAR, 1), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 140 | |
| 141 | INTERLEAVED_RGB_FMT(ABGR8888, |
| 142 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 143 | C3_ALPHA, C1_B_Cb, C0_G_Y, C2_R_Cr, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 144 | true, 4, 0, |
| 145 | SDE_FETCH_LINEAR, 1), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 146 | |
Narendra Muppalla | 88ad726 | 2016-10-31 18:14:21 -0700 | [diff] [blame] | 147 | INTERLEAVED_RGB_FMT(XBGR8888, |
| 148 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 149 | C3_ALPHA, C1_B_Cb, C0_G_Y, C2_R_Cr, 4, |
| 150 | true, 4, 0, |
| 151 | SDE_FETCH_LINEAR, 1), |
| 152 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 153 | INTERLEAVED_RGB_FMT(RGBA8888, |
| 154 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 155 | C2_R_Cr, C0_G_Y, C1_B_Cb, C3_ALPHA, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 156 | true, 4, 0, |
| 157 | SDE_FETCH_LINEAR, 1), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 158 | |
| 159 | INTERLEAVED_RGB_FMT(BGRA8888, |
| 160 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 161 | C1_B_Cb, C0_G_Y, C2_R_Cr, C3_ALPHA, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 162 | true, 4, 0, |
| 163 | SDE_FETCH_LINEAR, 1), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 164 | |
Alan Kwong | 3232ca5 | 2016-07-29 02:27:47 -0400 | [diff] [blame] | 165 | INTERLEAVED_RGB_FMT(BGRX8888, |
| 166 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 167 | C1_B_Cb, C0_G_Y, C2_R_Cr, C3_ALPHA, 4, |
Alan Kwong | 3232ca5 | 2016-07-29 02:27:47 -0400 | [diff] [blame] | 168 | false, 4, 0, |
| 169 | SDE_FETCH_LINEAR, 1), |
| 170 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 171 | INTERLEAVED_RGB_FMT(XRGB8888, |
| 172 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 173 | C3_ALPHA, C2_R_Cr, C0_G_Y, C1_B_Cb, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 174 | false, 4, 0, |
| 175 | SDE_FETCH_LINEAR, 1), |
| 176 | |
| 177 | INTERLEAVED_RGB_FMT(RGBX8888, |
| 178 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 179 | C2_R_Cr, C0_G_Y, C1_B_Cb, C3_ALPHA, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 180 | false, 4, 0, |
| 181 | SDE_FETCH_LINEAR, 1), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 182 | |
| 183 | INTERLEAVED_RGB_FMT(RGB888, |
| 184 | 0, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 185 | C2_R_Cr, C0_G_Y, C1_B_Cb, 0, 3, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 186 | false, 3, 0, |
| 187 | SDE_FETCH_LINEAR, 1), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 188 | |
| 189 | INTERLEAVED_RGB_FMT(BGR888, |
| 190 | 0, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 191 | C1_B_Cb, C0_G_Y, C2_R_Cr, 0, 3, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 192 | false, 3, 0, |
| 193 | SDE_FETCH_LINEAR, 1), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 194 | |
| 195 | INTERLEAVED_RGB_FMT(RGB565, |
| 196 | 0, COLOR_5BIT, COLOR_6BIT, COLOR_5BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 197 | C2_R_Cr, C0_G_Y, C1_B_Cb, 0, 3, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 198 | false, 2, 0, |
| 199 | SDE_FETCH_LINEAR, 1), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 200 | |
| 201 | INTERLEAVED_RGB_FMT(BGR565, |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 202 | 0, COLOR_5BIT, COLOR_6BIT, COLOR_5BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 203 | C1_B_Cb, C0_G_Y, C2_R_Cr, 0, 3, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 204 | false, 2, 0, |
| 205 | SDE_FETCH_LINEAR, 1), |
| 206 | |
| 207 | INTERLEAVED_RGB_FMT(ARGB1555, |
| 208 | COLOR_ALPHA_1BIT, COLOR_5BIT, COLOR_5BIT, COLOR_5BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 209 | C3_ALPHA, C2_R_Cr, C0_G_Y, C1_B_Cb, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 210 | true, 2, 0, |
| 211 | SDE_FETCH_LINEAR, 1), |
| 212 | |
| 213 | INTERLEAVED_RGB_FMT(ABGR1555, |
| 214 | COLOR_ALPHA_1BIT, COLOR_5BIT, COLOR_5BIT, COLOR_5BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 215 | C3_ALPHA, C1_B_Cb, C0_G_Y, C2_R_Cr, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 216 | true, 2, 0, |
| 217 | SDE_FETCH_LINEAR, 1), |
| 218 | |
| 219 | INTERLEAVED_RGB_FMT(RGBA5551, |
| 220 | COLOR_ALPHA_1BIT, COLOR_5BIT, COLOR_5BIT, COLOR_5BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 221 | C2_R_Cr, C0_G_Y, C1_B_Cb, C3_ALPHA, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 222 | true, 2, 0, |
| 223 | SDE_FETCH_LINEAR, 1), |
| 224 | |
| 225 | INTERLEAVED_RGB_FMT(BGRA5551, |
| 226 | COLOR_ALPHA_1BIT, COLOR_5BIT, COLOR_5BIT, COLOR_5BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 227 | C1_B_Cb, C0_G_Y, C2_R_Cr, C3_ALPHA, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 228 | true, 2, 0, |
| 229 | SDE_FETCH_LINEAR, 1), |
| 230 | |
| 231 | INTERLEAVED_RGB_FMT(XRGB1555, |
| 232 | COLOR_ALPHA_1BIT, COLOR_5BIT, COLOR_5BIT, COLOR_5BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 233 | C3_ALPHA, C2_R_Cr, C0_G_Y, C1_B_Cb, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 234 | false, 2, 0, |
| 235 | SDE_FETCH_LINEAR, 1), |
| 236 | |
| 237 | INTERLEAVED_RGB_FMT(XBGR1555, |
| 238 | COLOR_ALPHA_1BIT, COLOR_5BIT, COLOR_5BIT, COLOR_5BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 239 | C3_ALPHA, C1_B_Cb, C0_G_Y, C2_R_Cr, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 240 | false, 2, 0, |
| 241 | SDE_FETCH_LINEAR, 1), |
| 242 | |
| 243 | INTERLEAVED_RGB_FMT(RGBX5551, |
| 244 | COLOR_ALPHA_1BIT, COLOR_5BIT, COLOR_5BIT, COLOR_5BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 245 | C2_R_Cr, C0_G_Y, C1_B_Cb, C3_ALPHA, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 246 | false, 2, 0, |
| 247 | SDE_FETCH_LINEAR, 1), |
| 248 | |
| 249 | INTERLEAVED_RGB_FMT(BGRX5551, |
| 250 | COLOR_ALPHA_1BIT, COLOR_5BIT, COLOR_5BIT, COLOR_5BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 251 | C1_B_Cb, C0_G_Y, C2_R_Cr, C3_ALPHA, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 252 | false, 2, 0, |
| 253 | SDE_FETCH_LINEAR, 1), |
| 254 | |
| 255 | INTERLEAVED_RGB_FMT(ARGB4444, |
| 256 | COLOR_ALPHA_4BIT, COLOR_4BIT, COLOR_4BIT, COLOR_4BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 257 | C3_ALPHA, C2_R_Cr, C0_G_Y, C1_B_Cb, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 258 | true, 2, 0, |
| 259 | SDE_FETCH_LINEAR, 1), |
| 260 | |
| 261 | INTERLEAVED_RGB_FMT(ABGR4444, |
| 262 | COLOR_ALPHA_4BIT, COLOR_4BIT, COLOR_4BIT, COLOR_4BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 263 | C3_ALPHA, C1_B_Cb, C0_G_Y, C2_R_Cr, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 264 | true, 2, 0, |
| 265 | SDE_FETCH_LINEAR, 1), |
| 266 | |
| 267 | INTERLEAVED_RGB_FMT(RGBA4444, |
| 268 | COLOR_ALPHA_4BIT, COLOR_4BIT, COLOR_4BIT, COLOR_4BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 269 | C2_R_Cr, C0_G_Y, C1_B_Cb, C3_ALPHA, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 270 | true, 2, 0, |
| 271 | SDE_FETCH_LINEAR, 1), |
| 272 | |
| 273 | INTERLEAVED_RGB_FMT(BGRA4444, |
| 274 | COLOR_ALPHA_4BIT, COLOR_4BIT, COLOR_4BIT, COLOR_4BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 275 | C1_B_Cb, C0_G_Y, C2_R_Cr, C3_ALPHA, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 276 | true, 2, 0, |
| 277 | SDE_FETCH_LINEAR, 1), |
| 278 | |
| 279 | INTERLEAVED_RGB_FMT(XRGB4444, |
| 280 | COLOR_ALPHA_4BIT, COLOR_4BIT, COLOR_4BIT, COLOR_4BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 281 | C3_ALPHA, C2_R_Cr, C0_G_Y, C1_B_Cb, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 282 | false, 2, 0, |
| 283 | SDE_FETCH_LINEAR, 1), |
| 284 | |
| 285 | INTERLEAVED_RGB_FMT(XBGR4444, |
| 286 | COLOR_ALPHA_4BIT, COLOR_4BIT, COLOR_4BIT, COLOR_4BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 287 | C3_ALPHA, C1_B_Cb, C0_G_Y, C2_R_Cr, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 288 | false, 2, 0, |
| 289 | SDE_FETCH_LINEAR, 1), |
| 290 | |
| 291 | INTERLEAVED_RGB_FMT(RGBX4444, |
| 292 | COLOR_ALPHA_4BIT, COLOR_4BIT, COLOR_4BIT, COLOR_4BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 293 | C2_R_Cr, C0_G_Y, C1_B_Cb, C3_ALPHA, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 294 | false, 2, 0, |
| 295 | SDE_FETCH_LINEAR, 1), |
| 296 | |
| 297 | INTERLEAVED_RGB_FMT(BGRX4444, |
| 298 | COLOR_ALPHA_4BIT, COLOR_4BIT, COLOR_4BIT, COLOR_4BIT, |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 299 | C1_B_Cb, C0_G_Y, C2_R_Cr, C3_ALPHA, 4, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 300 | false, 2, 0, |
| 301 | SDE_FETCH_LINEAR, 1), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 302 | |
abeykun | 5ed42e1 | 2016-08-24 17:09:26 -0400 | [diff] [blame] | 303 | INTERLEAVED_RGB_FMT(BGRA1010102, |
| 304 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 305 | C1_B_Cb, C0_G_Y, C2_R_Cr, C3_ALPHA, 4, |
| 306 | true, 4, SDE_FORMAT_FLAG_DX, |
| 307 | SDE_FETCH_LINEAR, 1), |
| 308 | |
| 309 | INTERLEAVED_RGB_FMT(RGBA1010102, |
| 310 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 311 | C2_R_Cr, C0_G_Y, C1_B_Cb, C3_ALPHA, 4, |
| 312 | true, 4, SDE_FORMAT_FLAG_DX, |
| 313 | SDE_FETCH_LINEAR, 1), |
| 314 | |
| 315 | INTERLEAVED_RGB_FMT(ABGR2101010, |
| 316 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 317 | C3_ALPHA, C1_B_Cb, C0_G_Y, C2_R_Cr, 4, |
| 318 | true, 4, SDE_FORMAT_FLAG_DX, |
| 319 | SDE_FETCH_LINEAR, 1), |
| 320 | |
| 321 | INTERLEAVED_RGB_FMT(ARGB2101010, |
| 322 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 323 | C3_ALPHA, C2_R_Cr, C0_G_Y, C1_B_Cb, 4, |
| 324 | true, 4, SDE_FORMAT_FLAG_DX, |
| 325 | SDE_FETCH_LINEAR, 1), |
| 326 | |
| 327 | INTERLEAVED_RGB_FMT(XRGB2101010, |
| 328 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 329 | C3_ALPHA, C2_R_Cr, C0_G_Y, C1_B_Cb, 4, |
| 330 | false, 4, SDE_FORMAT_FLAG_DX, |
| 331 | SDE_FETCH_LINEAR, 1), |
| 332 | |
| 333 | INTERLEAVED_RGB_FMT(BGRX1010102, |
| 334 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 335 | C1_B_Cb, C0_G_Y, C2_R_Cr, C3_ALPHA, 4, |
| 336 | false, 4, SDE_FORMAT_FLAG_DX, |
| 337 | SDE_FETCH_LINEAR, 1), |
| 338 | |
| 339 | INTERLEAVED_RGB_FMT(XBGR2101010, |
| 340 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 341 | C3_ALPHA, C1_B_Cb, C0_G_Y, C2_R_Cr, 4, |
| 342 | false, 4, SDE_FORMAT_FLAG_DX, |
| 343 | SDE_FETCH_LINEAR, 1), |
| 344 | |
| 345 | INTERLEAVED_RGB_FMT(RGBX1010102, |
| 346 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 347 | C2_R_Cr, C0_G_Y, C1_B_Cb, C3_ALPHA, 4, |
| 348 | false, 4, SDE_FORMAT_FLAG_DX, |
| 349 | SDE_FETCH_LINEAR, 1), |
| 350 | |
| 351 | PSEUDO_YUV_FMT(NV12, |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 352 | 0, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 353 | C1_B_Cb, C2_R_Cr, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 354 | SDE_CHROMA_420, SDE_FORMAT_FLAG_YUV, |
| 355 | SDE_FETCH_LINEAR, 2), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 356 | |
abeykun | 5ed42e1 | 2016-08-24 17:09:26 -0400 | [diff] [blame] | 357 | PSEUDO_YUV_FMT(NV21, |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 358 | 0, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 359 | C2_R_Cr, C1_B_Cb, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 360 | SDE_CHROMA_420, SDE_FORMAT_FLAG_YUV, |
| 361 | SDE_FETCH_LINEAR, 2), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 362 | |
abeykun | 5ed42e1 | 2016-08-24 17:09:26 -0400 | [diff] [blame] | 363 | PSEUDO_YUV_FMT(NV16, |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 364 | 0, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 365 | C1_B_Cb, C2_R_Cr, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 366 | SDE_CHROMA_H2V1, SDE_FORMAT_FLAG_YUV, |
| 367 | SDE_FETCH_LINEAR, 2), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 368 | |
abeykun | 5ed42e1 | 2016-08-24 17:09:26 -0400 | [diff] [blame] | 369 | PSEUDO_YUV_FMT(NV61, |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 370 | 0, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 371 | C2_R_Cr, C1_B_Cb, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 372 | SDE_CHROMA_H2V1, SDE_FORMAT_FLAG_YUV, |
| 373 | SDE_FETCH_LINEAR, 2), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 374 | |
| 375 | INTERLEAVED_YUV_FMT(VYUY, |
| 376 | 0, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 377 | C2_R_Cr, C0_G_Y, C1_B_Cb, C0_G_Y, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 378 | false, SDE_CHROMA_H2V1, 4, 2, SDE_FORMAT_FLAG_YUV, |
| 379 | SDE_FETCH_LINEAR, 2), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 380 | |
| 381 | INTERLEAVED_YUV_FMT(UYVY, |
| 382 | 0, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 383 | C1_B_Cb, C0_G_Y, C2_R_Cr, C0_G_Y, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 384 | false, SDE_CHROMA_H2V1, 4, 2, SDE_FORMAT_FLAG_YUV, |
| 385 | SDE_FETCH_LINEAR, 2), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 386 | |
| 387 | INTERLEAVED_YUV_FMT(YUYV, |
| 388 | 0, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 389 | C0_G_Y, C1_B_Cb, C0_G_Y, C2_R_Cr, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 390 | false, SDE_CHROMA_H2V1, 4, 2, SDE_FORMAT_FLAG_YUV, |
| 391 | SDE_FETCH_LINEAR, 2), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 392 | |
| 393 | INTERLEAVED_YUV_FMT(YVYU, |
| 394 | 0, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 395 | C0_G_Y, C2_R_Cr, C0_G_Y, C1_B_Cb, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 396 | false, SDE_CHROMA_H2V1, 4, 2, SDE_FORMAT_FLAG_YUV, |
| 397 | SDE_FETCH_LINEAR, 2), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 398 | |
| 399 | PLANAR_YUV_FMT(YUV420, |
| 400 | 0, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
Lloyd Atkinson | 51944c5 | 2017-02-10 11:22:47 -0800 | [diff] [blame] | 401 | C2_R_Cr, C1_B_Cb, C0_G_Y, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 402 | false, SDE_CHROMA_420, 1, SDE_FORMAT_FLAG_YUV, |
| 403 | SDE_FETCH_LINEAR, 3), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 404 | |
| 405 | PLANAR_YUV_FMT(YVU420, |
| 406 | 0, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
Lloyd Atkinson | 51944c5 | 2017-02-10 11:22:47 -0800 | [diff] [blame] | 407 | C1_B_Cb, C2_R_Cr, C0_G_Y, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 408 | false, SDE_CHROMA_420, 1, SDE_FORMAT_FLAG_YUV, |
| 409 | SDE_FETCH_LINEAR, 3), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 410 | }; |
| 411 | |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 412 | /* |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 413 | * A5x tile formats tables: |
| 414 | * These tables hold the A5x tile formats supported. |
| 415 | */ |
| 416 | static const struct sde_format sde_format_map_tile[] = { |
| 417 | INTERLEAVED_RGB_FMT(ARGB8888, |
| 418 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 419 | C3_ALPHA, C2_R_Cr, C0_G_Y, C1_B_Cb, 4, |
| 420 | true, 4, 0, |
| 421 | SDE_FETCH_UBWC, 1), |
| 422 | |
| 423 | INTERLEAVED_RGB_FMT(ABGR8888, |
| 424 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 425 | C3_ALPHA, C1_B_Cb, C0_G_Y, C2_R_Cr, 4, |
| 426 | true, 4, 0, |
| 427 | SDE_FETCH_UBWC, 1), |
| 428 | |
| 429 | INTERLEAVED_RGB_FMT(RGBA8888, |
| 430 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 431 | C2_R_Cr, C0_G_Y, C1_B_Cb, C3_ALPHA, 4, |
| 432 | true, 4, 0, |
| 433 | SDE_FETCH_UBWC, 1), |
| 434 | |
| 435 | INTERLEAVED_RGB_FMT(BGRA8888, |
| 436 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 437 | C1_B_Cb, C0_G_Y, C2_R_Cr, C3_ALPHA, 4, |
| 438 | true, 4, 0, |
| 439 | SDE_FETCH_UBWC, 1), |
| 440 | |
| 441 | INTERLEAVED_RGB_FMT(BGRX8888, |
| 442 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 443 | C1_B_Cb, C0_G_Y, C2_R_Cr, C3_ALPHA, 4, |
| 444 | false, 4, 0, |
| 445 | SDE_FETCH_UBWC, 1), |
| 446 | |
| 447 | INTERLEAVED_RGB_FMT(XRGB8888, |
| 448 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 449 | C3_ALPHA, C2_R_Cr, C0_G_Y, C1_B_Cb, 4, |
| 450 | false, 4, 0, |
| 451 | SDE_FETCH_UBWC, 1), |
| 452 | |
| 453 | INTERLEAVED_RGB_FMT(RGBX8888, |
| 454 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 455 | C2_R_Cr, C0_G_Y, C1_B_Cb, C3_ALPHA, 4, |
| 456 | false, 4, 0, |
| 457 | SDE_FETCH_UBWC, 1), |
| 458 | |
| 459 | PSEUDO_YUV_FMT(NV12, |
| 460 | 0, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 461 | C1_B_Cb, C2_R_Cr, |
| 462 | SDE_CHROMA_420, SDE_FORMAT_FLAG_YUV, |
| 463 | SDE_FETCH_UBWC, 2), |
| 464 | |
| 465 | PSEUDO_YUV_FMT(NV21, |
| 466 | 0, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 467 | C2_R_Cr, C1_B_Cb, |
| 468 | SDE_CHROMA_420, SDE_FORMAT_FLAG_YUV, |
| 469 | SDE_FETCH_UBWC, 2), |
| 470 | }; |
| 471 | |
| 472 | static const struct sde_format sde_format_map_p010_tile[] = { |
| 473 | PSEUDO_YUV_FMT_LOOSE(NV12, |
| 474 | 0, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 475 | C1_B_Cb, C2_R_Cr, |
| 476 | SDE_CHROMA_420, (SDE_FORMAT_FLAG_YUV | SDE_FORMAT_FLAG_DX), |
| 477 | SDE_FETCH_UBWC, 2), |
| 478 | }; |
| 479 | |
| 480 | static const struct sde_format sde_format_map_tp10_tile[] = { |
| 481 | PSEUDO_YUV_FMT(NV12, |
| 482 | 0, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 483 | C1_B_Cb, C2_R_Cr, |
| 484 | SDE_CHROMA_420, (SDE_FORMAT_FLAG_YUV | SDE_FORMAT_FLAG_DX), |
| 485 | SDE_FETCH_UBWC, 2), |
| 486 | }; |
| 487 | |
| 488 | /* |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 489 | * UBWC formats table: |
| 490 | * This table holds the UBWC formats supported. |
| 491 | * If a compression ratio needs to be used for this or any other format, |
| 492 | * the data will be passed by user-space. |
| 493 | */ |
| 494 | static const struct sde_format sde_format_map_ubwc[] = { |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 495 | INTERLEAVED_RGB_FMT(RGB565, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 496 | 0, COLOR_5BIT, COLOR_6BIT, COLOR_5BIT, |
| 497 | C2_R_Cr, C0_G_Y, C1_B_Cb, 0, 3, |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 498 | false, 2, SDE_FORMAT_FLAG_COMPRESSED, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 499 | SDE_FETCH_UBWC, 2), |
| 500 | |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 501 | INTERLEAVED_RGB_FMT(RGBA8888, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 502 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 503 | C2_R_Cr, C0_G_Y, C1_B_Cb, C3_ALPHA, 4, |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 504 | true, 4, SDE_FORMAT_FLAG_COMPRESSED, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 505 | SDE_FETCH_UBWC, 2), |
| 506 | |
Dhaval Patel | 17ec915 | 2016-08-30 17:49:07 -0700 | [diff] [blame] | 507 | INTERLEAVED_RGB_FMT(RGBX8888, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 508 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 509 | C2_R_Cr, C0_G_Y, C1_B_Cb, C3_ALPHA, 4, |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 510 | false, 4, SDE_FORMAT_FLAG_COMPRESSED, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 511 | SDE_FETCH_UBWC, 2), |
| 512 | |
abeykun | 5ed42e1 | 2016-08-24 17:09:26 -0400 | [diff] [blame] | 513 | INTERLEAVED_RGB_FMT(RGBA1010102, |
| 514 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 515 | C2_R_Cr, C0_G_Y, C1_B_Cb, C3_ALPHA, 4, |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 516 | true, 4, SDE_FORMAT_FLAG_DX | SDE_FORMAT_FLAG_COMPRESSED, |
abeykun | 5ed42e1 | 2016-08-24 17:09:26 -0400 | [diff] [blame] | 517 | SDE_FETCH_UBWC, 2), |
| 518 | |
| 519 | INTERLEAVED_RGB_FMT(RGBX1010102, |
| 520 | COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 521 | C2_R_Cr, C0_G_Y, C1_B_Cb, C3_ALPHA, 4, |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 522 | true, 4, SDE_FORMAT_FLAG_DX | SDE_FORMAT_FLAG_COMPRESSED, |
abeykun | 5ed42e1 | 2016-08-24 17:09:26 -0400 | [diff] [blame] | 523 | SDE_FETCH_UBWC, 2), |
| 524 | |
| 525 | PSEUDO_YUV_FMT(NV12, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 526 | 0, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 527 | C1_B_Cb, C2_R_Cr, |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 528 | SDE_CHROMA_420, SDE_FORMAT_FLAG_YUV | |
| 529 | SDE_FORMAT_FLAG_COMPRESSED, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 530 | SDE_FETCH_UBWC, 4), |
| 531 | }; |
| 532 | |
abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 533 | static const struct sde_format sde_format_map_p010[] = { |
| 534 | PSEUDO_YUV_FMT_LOOSE(NV12, |
| 535 | 0, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 536 | C1_B_Cb, C2_R_Cr, |
| 537 | SDE_CHROMA_420, (SDE_FORMAT_FLAG_YUV | SDE_FORMAT_FLAG_DX), |
| 538 | SDE_FETCH_LINEAR, 2), |
| 539 | }; |
| 540 | |
| 541 | static const struct sde_format sde_format_map_p010_ubwc[] = { |
| 542 | PSEUDO_YUV_FMT_LOOSE(NV12, |
| 543 | 0, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 544 | C1_B_Cb, C2_R_Cr, |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 545 | SDE_CHROMA_420, (SDE_FORMAT_FLAG_YUV | SDE_FORMAT_FLAG_DX | |
| 546 | SDE_FORMAT_FLAG_COMPRESSED), |
abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 547 | SDE_FETCH_UBWC, 4), |
| 548 | }; |
| 549 | |
abeykun | 1d4ff03 | 2016-08-26 11:31:44 -0400 | [diff] [blame] | 550 | static const struct sde_format sde_format_map_tp10_ubwc[] = { |
| 551 | PSEUDO_YUV_FMT(NV12, |
| 552 | 0, COLOR_8BIT, COLOR_8BIT, COLOR_8BIT, |
| 553 | C1_B_Cb, C2_R_Cr, |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 554 | SDE_CHROMA_420, (SDE_FORMAT_FLAG_YUV | SDE_FORMAT_FLAG_DX | |
| 555 | SDE_FORMAT_FLAG_COMPRESSED), |
abeykun | 1d4ff03 | 2016-08-26 11:31:44 -0400 | [diff] [blame] | 556 | SDE_FETCH_UBWC, 4), |
| 557 | }; |
| 558 | |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 559 | /* _sde_get_v_h_subsample_rate - Get subsample rates for all formats we support |
| 560 | * Note: Not using the drm_format_*_subsampling since we have formats |
| 561 | */ |
| 562 | static void _sde_get_v_h_subsample_rate( |
| 563 | enum sde_chroma_samp_type chroma_sample, |
| 564 | uint32_t *v_sample, |
| 565 | uint32_t *h_sample) |
| 566 | { |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 567 | if (!v_sample || !h_sample) |
| 568 | return; |
| 569 | |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 570 | switch (chroma_sample) { |
| 571 | case SDE_CHROMA_H2V1: |
| 572 | *v_sample = 1; |
| 573 | *h_sample = 2; |
| 574 | break; |
| 575 | case SDE_CHROMA_H1V2: |
| 576 | *v_sample = 2; |
| 577 | *h_sample = 1; |
| 578 | break; |
| 579 | case SDE_CHROMA_420: |
| 580 | *v_sample = 2; |
| 581 | *h_sample = 2; |
| 582 | break; |
| 583 | default: |
| 584 | *v_sample = 1; |
| 585 | *h_sample = 1; |
| 586 | break; |
| 587 | } |
| 588 | } |
| 589 | |
abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 590 | static int _sde_format_get_media_color_ubwc(const struct sde_format *fmt) |
| 591 | { |
| 592 | static const struct sde_media_color_map sde_media_ubwc_map[] = { |
| 593 | {DRM_FORMAT_RGBA8888, COLOR_FMT_RGBA8888_UBWC}, |
| 594 | {DRM_FORMAT_RGBX8888, COLOR_FMT_RGBA8888_UBWC}, |
| 595 | {DRM_FORMAT_RGBA1010102, COLOR_FMT_RGBA1010102_UBWC}, |
| 596 | {DRM_FORMAT_RGBX1010102, COLOR_FMT_RGBA1010102_UBWC}, |
| 597 | {DRM_FORMAT_RGB565, COLOR_FMT_RGB565_UBWC}, |
| 598 | }; |
| 599 | int color_fmt = -1; |
| 600 | int i; |
| 601 | |
| 602 | if (fmt->base.pixel_format == DRM_FORMAT_NV12) { |
| 603 | if (SDE_FORMAT_IS_DX(fmt)) { |
| 604 | if (fmt->unpack_tight) |
| 605 | color_fmt = COLOR_FMT_NV12_BPP10_UBWC; |
| 606 | else |
| 607 | color_fmt = COLOR_FMT_P010_UBWC; |
| 608 | } else |
| 609 | color_fmt = COLOR_FMT_NV12_UBWC; |
| 610 | return color_fmt; |
| 611 | } |
| 612 | |
| 613 | for (i = 0; i < ARRAY_SIZE(sde_media_ubwc_map); ++i) |
| 614 | if (fmt->base.pixel_format == sde_media_ubwc_map[i].format) { |
| 615 | color_fmt = sde_media_ubwc_map[i].color; |
| 616 | break; |
| 617 | } |
| 618 | return color_fmt; |
| 619 | } |
| 620 | |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 621 | static int _sde_format_get_plane_sizes_ubwc( |
| 622 | const struct sde_format *fmt, |
| 623 | const uint32_t width, |
| 624 | const uint32_t height, |
| 625 | struct sde_hw_fmt_layout *layout) |
| 626 | { |
| 627 | int i; |
abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 628 | int color; |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 629 | bool meta = SDE_FORMAT_IS_UBWC(fmt); |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 630 | |
| 631 | memset(layout, 0, sizeof(struct sde_hw_fmt_layout)); |
| 632 | layout->format = fmt; |
| 633 | layout->width = width; |
| 634 | layout->height = height; |
| 635 | layout->num_planes = fmt->num_planes; |
| 636 | |
abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 637 | color = _sde_format_get_media_color_ubwc(fmt); |
| 638 | if (color < 0) { |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 639 | DRM_ERROR("UBWC format not supported for fmt:0x%X\n", |
| 640 | fmt->base.pixel_format); |
| 641 | return -EINVAL; |
| 642 | } |
| 643 | |
abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 644 | if (SDE_FORMAT_IS_YUV(layout->format)) { |
| 645 | uint32_t y_sclines, uv_sclines; |
| 646 | uint32_t y_meta_scanlines = 0; |
| 647 | uint32_t uv_meta_scanlines = 0; |
| 648 | |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 649 | layout->num_planes = 2; |
abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 650 | layout->plane_pitch[0] = VENUS_Y_STRIDE(color, width); |
| 651 | y_sclines = VENUS_Y_SCANLINES(color, height); |
| 652 | layout->plane_size[0] = MSM_MEDIA_ALIGN(layout->plane_pitch[0] * |
| 653 | y_sclines, SDE_UBWC_PLANE_SIZE_ALIGNMENT); |
| 654 | |
| 655 | layout->plane_pitch[1] = VENUS_UV_STRIDE(color, width); |
| 656 | uv_sclines = VENUS_UV_SCANLINES(color, height); |
| 657 | layout->plane_size[1] = MSM_MEDIA_ALIGN(layout->plane_pitch[1] * |
| 658 | uv_sclines, SDE_UBWC_PLANE_SIZE_ALIGNMENT); |
| 659 | |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 660 | if (!meta) |
| 661 | goto done; |
| 662 | |
| 663 | layout->num_planes += 2; |
abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 664 | layout->plane_pitch[2] = VENUS_Y_META_STRIDE(color, width); |
| 665 | y_meta_scanlines = VENUS_Y_META_SCANLINES(color, height); |
| 666 | layout->plane_size[2] = MSM_MEDIA_ALIGN(layout->plane_pitch[2] * |
| 667 | y_meta_scanlines, SDE_UBWC_PLANE_SIZE_ALIGNMENT); |
| 668 | |
| 669 | layout->plane_pitch[3] = VENUS_UV_META_STRIDE(color, width); |
| 670 | uv_meta_scanlines = VENUS_UV_META_SCANLINES(color, height); |
| 671 | layout->plane_size[3] = MSM_MEDIA_ALIGN(layout->plane_pitch[3] * |
| 672 | uv_meta_scanlines, SDE_UBWC_PLANE_SIZE_ALIGNMENT); |
| 673 | |
| 674 | } else { |
| 675 | uint32_t rgb_scanlines, rgb_meta_scanlines; |
| 676 | |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 677 | layout->num_planes = 1; |
abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 678 | |
| 679 | layout->plane_pitch[0] = VENUS_RGB_STRIDE(color, width); |
| 680 | rgb_scanlines = VENUS_RGB_SCANLINES(color, height); |
| 681 | layout->plane_size[0] = MSM_MEDIA_ALIGN(layout->plane_pitch[0] * |
| 682 | rgb_scanlines, SDE_UBWC_PLANE_SIZE_ALIGNMENT); |
| 683 | |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 684 | if (!meta) |
| 685 | goto done; |
| 686 | layout->num_planes += 2; |
abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 687 | layout->plane_pitch[2] = VENUS_RGB_META_STRIDE(color, width); |
| 688 | rgb_meta_scanlines = VENUS_RGB_META_SCANLINES(color, height); |
| 689 | layout->plane_size[2] = MSM_MEDIA_ALIGN(layout->plane_pitch[2] * |
| 690 | rgb_meta_scanlines, SDE_UBWC_PLANE_SIZE_ALIGNMENT); |
| 691 | } |
| 692 | |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 693 | done: |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 694 | for (i = 0; i < SDE_MAX_PLANES; i++) |
| 695 | layout->total_size += layout->plane_size[i]; |
| 696 | |
| 697 | return 0; |
| 698 | } |
| 699 | |
| 700 | static int _sde_format_get_plane_sizes_linear( |
| 701 | const struct sde_format *fmt, |
| 702 | const uint32_t width, |
| 703 | const uint32_t height, |
| 704 | struct sde_hw_fmt_layout *layout) |
| 705 | { |
| 706 | int i; |
| 707 | |
| 708 | memset(layout, 0, sizeof(struct sde_hw_fmt_layout)); |
| 709 | layout->format = fmt; |
| 710 | layout->width = width; |
| 711 | layout->height = height; |
| 712 | layout->num_planes = fmt->num_planes; |
| 713 | |
| 714 | /* Due to memset above, only need to set planes of interest */ |
| 715 | if (fmt->fetch_planes == SDE_PLANE_INTERLEAVED) { |
| 716 | layout->num_planes = 1; |
| 717 | layout->plane_size[0] = width * height * layout->format->bpp; |
| 718 | layout->plane_pitch[0] = width * layout->format->bpp; |
| 719 | } else { |
| 720 | uint32_t v_subsample, h_subsample; |
| 721 | uint32_t chroma_samp; |
abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 722 | uint32_t bpp = 1; |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 723 | |
| 724 | chroma_samp = fmt->chroma_sample; |
| 725 | _sde_get_v_h_subsample_rate(chroma_samp, &v_subsample, |
| 726 | &h_subsample); |
| 727 | |
| 728 | if (width % h_subsample || height % v_subsample) { |
| 729 | DRM_ERROR("mismatch in subsample vs dimensions\n"); |
| 730 | return -EINVAL; |
| 731 | } |
| 732 | |
abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 733 | if ((fmt->base.pixel_format == DRM_FORMAT_NV12) && |
| 734 | (SDE_FORMAT_IS_DX(fmt))) |
| 735 | bpp = 2; |
| 736 | layout->plane_pitch[0] = width * bpp; |
| 737 | layout->plane_pitch[1] = layout->plane_pitch[0] / h_subsample; |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 738 | layout->plane_size[0] = layout->plane_pitch[0] * height; |
| 739 | layout->plane_size[1] = layout->plane_pitch[1] * |
| 740 | (height / v_subsample); |
| 741 | |
| 742 | if (fmt->fetch_planes == SDE_PLANE_PSEUDO_PLANAR) { |
| 743 | layout->num_planes = 2; |
| 744 | layout->plane_size[1] *= 2; |
| 745 | layout->plane_pitch[1] *= 2; |
| 746 | } else { |
| 747 | /* planar */ |
| 748 | layout->num_planes = 3; |
| 749 | layout->plane_size[2] = layout->plane_size[1]; |
| 750 | layout->plane_pitch[2] = layout->plane_pitch[1]; |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | for (i = 0; i < SDE_MAX_PLANES; i++) |
| 755 | layout->total_size += layout->plane_size[i]; |
| 756 | |
| 757 | return 0; |
| 758 | } |
| 759 | |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 760 | int sde_format_get_plane_sizes( |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 761 | const struct sde_format *fmt, |
| 762 | const uint32_t w, |
| 763 | const uint32_t h, |
| 764 | struct sde_hw_fmt_layout *layout) |
| 765 | { |
| 766 | if (!layout || !fmt) { |
| 767 | DRM_ERROR("invalid pointer\n"); |
| 768 | return -EINVAL; |
| 769 | } |
| 770 | |
| 771 | if ((w > SDE_MAX_IMG_WIDTH) || (h > SDE_MAX_IMG_HEIGHT)) { |
| 772 | DRM_ERROR("image dimensions outside max range\n"); |
| 773 | return -ERANGE; |
| 774 | } |
| 775 | |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 776 | if (SDE_FORMAT_IS_UBWC(fmt) || SDE_FORMAT_IS_TILE(fmt)) |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 777 | return _sde_format_get_plane_sizes_ubwc(fmt, w, h, layout); |
| 778 | |
| 779 | return _sde_format_get_plane_sizes_linear(fmt, w, h, layout); |
| 780 | } |
| 781 | |
Alan Kwong | 4aacd53 | 2017-02-04 18:51:33 -0800 | [diff] [blame] | 782 | int sde_format_get_block_size(const struct sde_format *fmt, |
| 783 | uint32_t *w, uint32_t *h) |
| 784 | { |
| 785 | if (!fmt || !w || !h) { |
| 786 | DRM_ERROR("invalid pointer\n"); |
| 787 | return -EINVAL; |
| 788 | } |
| 789 | |
| 790 | /* TP10 is 96x96 and all others are 128x128 */ |
| 791 | if (SDE_FORMAT_IS_YUV(fmt) && SDE_FORMAT_IS_DX(fmt) && |
| 792 | (fmt->num_planes == 2) && fmt->unpack_tight) |
| 793 | *w = *h = 96; |
| 794 | else |
| 795 | *w = *h = 128; |
| 796 | |
| 797 | return 0; |
| 798 | } |
| 799 | |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 800 | uint32_t sde_format_get_framebuffer_size( |
| 801 | const uint32_t format, |
| 802 | const uint32_t width, |
| 803 | const uint32_t height, |
| 804 | const uint64_t *modifiers, |
| 805 | const uint32_t modifiers_len) |
| 806 | { |
| 807 | const struct sde_format *fmt; |
| 808 | struct sde_hw_fmt_layout layout; |
| 809 | |
| 810 | fmt = sde_get_sde_format_ext(format, modifiers, modifiers_len); |
| 811 | if (!fmt) |
| 812 | return 0; |
| 813 | |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 814 | if (sde_format_get_plane_sizes(fmt, width, height, &layout)) |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 815 | layout.total_size = 0; |
| 816 | |
| 817 | return layout.total_size; |
| 818 | } |
| 819 | |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 820 | static int _sde_format_populate_addrs_ubwc( |
| 821 | int mmu_id, |
| 822 | struct drm_framebuffer *fb, |
| 823 | struct sde_hw_fmt_layout *layout) |
| 824 | { |
| 825 | uint32_t base_addr; |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 826 | bool meta; |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 827 | |
| 828 | if (!fb || !layout) { |
| 829 | DRM_ERROR("invalid pointers\n"); |
| 830 | return -EINVAL; |
| 831 | } |
| 832 | |
| 833 | base_addr = msm_framebuffer_iova(fb, mmu_id, 0); |
| 834 | if (!base_addr) { |
| 835 | DRM_ERROR("failed to retrieve base addr\n"); |
| 836 | return -EFAULT; |
| 837 | } |
| 838 | |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 839 | meta = SDE_FORMAT_IS_UBWC(layout->format); |
| 840 | |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 841 | /* Per-format logic for verifying active planes */ |
| 842 | if (SDE_FORMAT_IS_YUV(layout->format)) { |
| 843 | /************************************************/ |
| 844 | /* UBWC ** */ |
| 845 | /* buffer ** SDE PLANE */ |
| 846 | /* format ** */ |
| 847 | /************************************************/ |
| 848 | /* ------------------- ** -------------------- */ |
| 849 | /* | Y meta | ** | Y bitstream | */ |
| 850 | /* | data | ** | plane | */ |
| 851 | /* ------------------- ** -------------------- */ |
| 852 | /* | Y bitstream | ** | CbCr bitstream | */ |
| 853 | /* | data | ** | plane | */ |
| 854 | /* ------------------- ** -------------------- */ |
| 855 | /* | Cbcr metadata | ** | Y meta | */ |
| 856 | /* | data | ** | plane | */ |
| 857 | /* ------------------- ** -------------------- */ |
| 858 | /* | CbCr bitstream | ** | CbCr meta | */ |
| 859 | /* | data | ** | plane | */ |
| 860 | /* ------------------- ** -------------------- */ |
| 861 | /************************************************/ |
| 862 | |
| 863 | /* configure Y bitstream plane */ |
| 864 | layout->plane_addr[0] = base_addr + layout->plane_size[2]; |
| 865 | |
| 866 | /* configure CbCr bitstream plane */ |
| 867 | layout->plane_addr[1] = base_addr + layout->plane_size[0] |
| 868 | + layout->plane_size[2] + layout->plane_size[3]; |
| 869 | |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 870 | if (!meta) |
| 871 | goto done; |
| 872 | |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 873 | /* configure Y metadata plane */ |
| 874 | layout->plane_addr[2] = base_addr; |
| 875 | |
| 876 | /* configure CbCr metadata plane */ |
| 877 | layout->plane_addr[3] = base_addr + layout->plane_size[0] |
| 878 | + layout->plane_size[2]; |
| 879 | |
| 880 | } else { |
| 881 | /************************************************/ |
| 882 | /* UBWC ** */ |
| 883 | /* buffer ** SDE PLANE */ |
| 884 | /* format ** */ |
| 885 | /************************************************/ |
| 886 | /* ------------------- ** -------------------- */ |
| 887 | /* | RGB meta | ** | RGB bitstream | */ |
| 888 | /* | data | ** | plane | */ |
| 889 | /* ------------------- ** -------------------- */ |
| 890 | /* | RGB bitstream | ** | NONE | */ |
| 891 | /* | data | ** | | */ |
| 892 | /* ------------------- ** -------------------- */ |
| 893 | /* ** | RGB meta | */ |
| 894 | /* ** | plane | */ |
| 895 | /* ** -------------------- */ |
| 896 | /************************************************/ |
| 897 | |
| 898 | layout->plane_addr[0] = base_addr + layout->plane_size[2]; |
| 899 | layout->plane_addr[1] = 0; |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 900 | |
| 901 | if (!meta) |
| 902 | goto done; |
| 903 | |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 904 | layout->plane_addr[2] = base_addr; |
| 905 | layout->plane_addr[3] = 0; |
| 906 | } |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 907 | done: |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 908 | return 0; |
| 909 | } |
| 910 | |
| 911 | static int _sde_format_populate_addrs_linear( |
| 912 | int mmu_id, |
| 913 | struct drm_framebuffer *fb, |
| 914 | struct sde_hw_fmt_layout *layout) |
| 915 | { |
| 916 | unsigned int i; |
| 917 | |
| 918 | /* Can now check the pitches given vs pitches expected */ |
| 919 | for (i = 0; i < layout->num_planes; ++i) { |
| 920 | if (layout->plane_pitch[i] != fb->pitches[i]) { |
| 921 | DRM_ERROR("plane %u expected pitch %u, fb %u\n", |
| 922 | i, layout->plane_pitch[i], fb->pitches[i]); |
| 923 | return -EINVAL; |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | /* Populate addresses for simple formats here */ |
| 928 | for (i = 0; i < layout->num_planes; ++i) { |
| 929 | layout->plane_addr[i] = msm_framebuffer_iova(fb, mmu_id, i); |
| 930 | if (!layout->plane_addr[i]) { |
| 931 | DRM_ERROR("failed to retrieve base addr\n"); |
| 932 | return -EFAULT; |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | return 0; |
| 937 | } |
| 938 | |
| 939 | int sde_format_populate_layout( |
| 940 | int mmu_id, |
| 941 | struct drm_framebuffer *fb, |
| 942 | struct sde_hw_fmt_layout *layout) |
| 943 | { |
Clarence Ip | b6eb236 | 2016-09-08 16:18:13 -0400 | [diff] [blame] | 944 | uint32_t plane_addr[SDE_MAX_PLANES]; |
| 945 | int i, ret; |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 946 | |
| 947 | if (!fb || !layout) { |
| 948 | DRM_ERROR("invalid arguments\n"); |
| 949 | return -EINVAL; |
| 950 | } |
| 951 | |
| 952 | if ((fb->width > SDE_MAX_IMG_WIDTH) || |
| 953 | (fb->height > SDE_MAX_IMG_HEIGHT)) { |
| 954 | DRM_ERROR("image dimensions outside max range\n"); |
| 955 | return -ERANGE; |
| 956 | } |
| 957 | |
| 958 | layout->format = to_sde_format(msm_framebuffer_format(fb)); |
| 959 | |
| 960 | /* Populate the plane sizes etc via get_format */ |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 961 | ret = sde_format_get_plane_sizes(layout->format, fb->width, fb->height, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 962 | layout); |
| 963 | if (ret) |
| 964 | return ret; |
| 965 | |
Clarence Ip | b6eb236 | 2016-09-08 16:18:13 -0400 | [diff] [blame] | 966 | for (i = 0; i < SDE_MAX_PLANES; ++i) |
| 967 | plane_addr[i] = layout->plane_addr[i]; |
| 968 | |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 969 | /* Populate the addresses given the fb */ |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 970 | if (SDE_FORMAT_IS_UBWC(layout->format) || |
| 971 | SDE_FORMAT_IS_TILE(layout->format)) |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 972 | ret = _sde_format_populate_addrs_ubwc(mmu_id, fb, layout); |
| 973 | else |
| 974 | ret = _sde_format_populate_addrs_linear(mmu_id, fb, layout); |
| 975 | |
Clarence Ip | b6eb236 | 2016-09-08 16:18:13 -0400 | [diff] [blame] | 976 | /* check if anything changed */ |
| 977 | if (!ret && !memcmp(plane_addr, layout->plane_addr, sizeof(plane_addr))) |
| 978 | ret = -EAGAIN; |
| 979 | |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 980 | return ret; |
| 981 | } |
| 982 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 983 | static void _sde_format_calc_offset_linear(struct sde_hw_fmt_layout *source, |
| 984 | u32 x, u32 y) |
| 985 | { |
| 986 | if ((x == 0) && (y == 0)) |
| 987 | return; |
| 988 | |
| 989 | source->plane_addr[0] += y * source->plane_pitch[0]; |
| 990 | |
| 991 | if (source->num_planes == 1) { |
| 992 | source->plane_addr[0] += x * source->format->bpp; |
| 993 | } else { |
| 994 | uint32_t xoff, yoff; |
| 995 | uint32_t v_subsample = 1; |
| 996 | uint32_t h_subsample = 1; |
| 997 | |
| 998 | _sde_get_v_h_subsample_rate(source->format->chroma_sample, |
| 999 | &v_subsample, &h_subsample); |
| 1000 | |
| 1001 | xoff = x / h_subsample; |
| 1002 | yoff = y / v_subsample; |
| 1003 | |
| 1004 | source->plane_addr[0] += x; |
| 1005 | source->plane_addr[1] += xoff + |
| 1006 | (yoff * source->plane_pitch[1]); |
| 1007 | if (source->num_planes == 2) /* pseudo planar */ |
| 1008 | source->plane_addr[1] += xoff; |
| 1009 | else /* planar */ |
| 1010 | source->plane_addr[2] += xoff + |
| 1011 | (yoff * source->plane_pitch[2]); |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | int sde_format_populate_layout_with_roi( |
| 1016 | int mmu_id, |
| 1017 | struct drm_framebuffer *fb, |
| 1018 | struct sde_rect *roi, |
| 1019 | struct sde_hw_fmt_layout *layout) |
| 1020 | { |
| 1021 | int ret; |
| 1022 | |
| 1023 | ret = sde_format_populate_layout(mmu_id, fb, layout); |
| 1024 | if (ret || !roi) |
| 1025 | return ret; |
| 1026 | |
| 1027 | if (!roi->w || !roi->h || (roi->x + roi->w > fb->width) || |
| 1028 | (roi->y + roi->h > fb->height)) { |
| 1029 | DRM_ERROR("invalid roi=[%d,%d,%d,%d], fb=[%u,%u]\n", |
| 1030 | roi->x, roi->y, roi->w, roi->h, |
| 1031 | fb->width, fb->height); |
| 1032 | ret = -EINVAL; |
| 1033 | } else if (SDE_FORMAT_IS_LINEAR(layout->format)) { |
| 1034 | _sde_format_calc_offset_linear(layout, roi->x, roi->y); |
| 1035 | layout->width = roi->w; |
| 1036 | layout->height = roi->h; |
| 1037 | } else if (roi->x || roi->y || (roi->w != fb->width) || |
| 1038 | (roi->h != fb->height)) { |
| 1039 | DRM_ERROR("non-linear layout with roi not supported\n"); |
| 1040 | ret = -EINVAL; |
| 1041 | } |
| 1042 | |
| 1043 | return ret; |
| 1044 | } |
| 1045 | |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1046 | int sde_format_check_modified_format( |
| 1047 | const struct msm_kms *kms, |
| 1048 | const struct msm_format *msm_fmt, |
| 1049 | const struct drm_mode_fb_cmd2 *cmd, |
| 1050 | struct drm_gem_object **bos) |
| 1051 | { |
| 1052 | int ret, i, num_base_fmt_planes; |
| 1053 | const struct sde_format *fmt; |
| 1054 | struct sde_hw_fmt_layout layout; |
| 1055 | uint32_t bos_total_size = 0; |
| 1056 | |
| 1057 | if (!msm_fmt || !cmd || !bos) { |
| 1058 | DRM_ERROR("invalid arguments\n"); |
| 1059 | return -EINVAL; |
| 1060 | } |
| 1061 | |
| 1062 | fmt = to_sde_format(msm_fmt); |
| 1063 | num_base_fmt_planes = drm_format_num_planes(fmt->base.pixel_format); |
| 1064 | |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 1065 | ret = sde_format_get_plane_sizes(fmt, cmd->width, cmd->height, |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1066 | &layout); |
| 1067 | if (ret) |
| 1068 | return ret; |
| 1069 | |
| 1070 | for (i = 0; i < num_base_fmt_planes; i++) { |
| 1071 | if (!bos[i]) { |
| 1072 | DRM_ERROR("invalid handle for plane %d\n", i); |
| 1073 | return -EINVAL; |
| 1074 | } |
| 1075 | bos_total_size += bos[i]->size; |
| 1076 | } |
| 1077 | |
| 1078 | if (bos_total_size < layout.total_size) { |
| 1079 | DRM_ERROR("buffers total size too small %u expected %u\n", |
| 1080 | bos_total_size, layout.total_size); |
| 1081 | return -EINVAL; |
| 1082 | } |
| 1083 | |
| 1084 | return 0; |
| 1085 | } |
| 1086 | |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 1087 | const struct sde_format *sde_get_sde_format_ext( |
| 1088 | const uint32_t format, |
| 1089 | const uint64_t *modifiers, |
| 1090 | const uint32_t modifiers_len) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1091 | { |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1092 | uint32_t i = 0; |
| 1093 | uint64_t mod0 = 0; |
| 1094 | const struct sde_format *fmt = NULL; |
| 1095 | const struct sde_format *map = NULL; |
| 1096 | ssize_t map_size = 0; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1097 | |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 1098 | /* |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1099 | * Currently only support exactly zero or one modifier. |
| 1100 | * All planes used must specify the same modifier. |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 1101 | */ |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1102 | if (modifiers_len && !modifiers) { |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 1103 | SDE_ERROR("invalid modifiers array\n"); |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 1104 | return NULL; |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1105 | } else if (modifiers && modifiers_len && modifiers[0]) { |
| 1106 | mod0 = modifiers[0]; |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 1107 | SDE_DEBUG("plane format modifier 0x%llX\n", mod0); |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1108 | for (i = 1; i < modifiers_len; i++) { |
| 1109 | if (modifiers[i] != mod0) { |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 1110 | SDE_ERROR("bad fmt mod 0x%llX on plane %d\n", |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 1111 | modifiers[i], i); |
| 1112 | return NULL; |
| 1113 | } |
| 1114 | } |
| 1115 | } |
| 1116 | |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1117 | switch (mod0) { |
| 1118 | case 0: |
| 1119 | map = sde_format_map; |
| 1120 | map_size = ARRAY_SIZE(sde_format_map); |
| 1121 | break; |
| 1122 | case DRM_FORMAT_MOD_QCOM_COMPRESSED: |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 1123 | case DRM_FORMAT_MOD_QCOM_COMPRESSED | DRM_FORMAT_MOD_QCOM_TILE: |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1124 | map = sde_format_map_ubwc; |
| 1125 | map_size = ARRAY_SIZE(sde_format_map_ubwc); |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 1126 | SDE_DEBUG("found fmt 0x%X DRM_FORMAT_MOD_QCOM_COMPRESSED\n", |
| 1127 | format); |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1128 | break; |
abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 1129 | case DRM_FORMAT_MOD_QCOM_DX: |
| 1130 | map = sde_format_map_p010; |
| 1131 | map_size = ARRAY_SIZE(sde_format_map_p010); |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 1132 | SDE_DEBUG("found fmt 0x%X DRM_FORMAT_MOD_QCOM_DX\n", format); |
abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 1133 | break; |
| 1134 | case (DRM_FORMAT_MOD_QCOM_DX | DRM_FORMAT_MOD_QCOM_COMPRESSED): |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 1135 | case (DRM_FORMAT_MOD_QCOM_DX | DRM_FORMAT_MOD_QCOM_COMPRESSED | |
| 1136 | DRM_FORMAT_MOD_QCOM_TILE): |
abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 1137 | map = sde_format_map_p010_ubwc; |
| 1138 | map_size = ARRAY_SIZE(sde_format_map_p010_ubwc); |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 1139 | SDE_DEBUG("found fmt 0x%X DRM_FORMAT_MOD_QCOM_COMPRESSED/DX\n", |
| 1140 | format); |
abeykun | adfec29 | 2016-08-26 10:48:09 -0400 | [diff] [blame] | 1141 | break; |
abeykun | 1d4ff03 | 2016-08-26 11:31:44 -0400 | [diff] [blame] | 1142 | case (DRM_FORMAT_MOD_QCOM_DX | DRM_FORMAT_MOD_QCOM_COMPRESSED | |
| 1143 | DRM_FORMAT_MOD_QCOM_TIGHT): |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 1144 | case (DRM_FORMAT_MOD_QCOM_DX | DRM_FORMAT_MOD_QCOM_COMPRESSED | |
| 1145 | DRM_FORMAT_MOD_QCOM_TIGHT | DRM_FORMAT_MOD_QCOM_TILE): |
abeykun | 1d4ff03 | 2016-08-26 11:31:44 -0400 | [diff] [blame] | 1146 | map = sde_format_map_tp10_ubwc; |
| 1147 | map_size = ARRAY_SIZE(sde_format_map_tp10_ubwc); |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 1148 | SDE_DEBUG( |
| 1149 | "found fmt 0x%X DRM_FORMAT_MOD_QCOM_COMPRESSED/DX/TIGHT\n", |
abeykun | 1d4ff03 | 2016-08-26 11:31:44 -0400 | [diff] [blame] | 1150 | format); |
| 1151 | break; |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 1152 | case DRM_FORMAT_MOD_QCOM_TILE: |
| 1153 | map = sde_format_map_tile; |
| 1154 | map_size = ARRAY_SIZE(sde_format_map_tile); |
| 1155 | SDE_DEBUG("found fmt 0x%X DRM_FORMAT_MOD_QCOM_TILE\n", format); |
| 1156 | break; |
| 1157 | case (DRM_FORMAT_MOD_QCOM_TILE | DRM_FORMAT_MOD_QCOM_DX): |
| 1158 | map = sde_format_map_p010_tile; |
| 1159 | map_size = ARRAY_SIZE(sde_format_map_p010_tile); |
| 1160 | SDE_DEBUG("found fmt 0x%X DRM_FORMAT_MOD_QCOM_TILE/DX\n", |
| 1161 | format); |
| 1162 | break; |
| 1163 | case (DRM_FORMAT_MOD_QCOM_TILE | DRM_FORMAT_MOD_QCOM_DX | |
| 1164 | DRM_FORMAT_MOD_QCOM_TIGHT): |
| 1165 | map = sde_format_map_tp10_tile; |
| 1166 | map_size = ARRAY_SIZE(sde_format_map_tp10_tile); |
| 1167 | SDE_DEBUG("found fmt 0x%X DRM_FORMAT_MOD_QCOM_TILE/DX/TIGHT\n", |
| 1168 | format); |
| 1169 | break; |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1170 | default: |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 1171 | SDE_ERROR("unsupported format modifier %llX\n", mod0); |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1172 | return NULL; |
| 1173 | } |
| 1174 | |
| 1175 | for (i = 0; i < map_size; i++) { |
| 1176 | if (format == map[i].base.pixel_format) { |
| 1177 | fmt = &map[i]; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1178 | break; |
| 1179 | } |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1180 | } |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1181 | |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 1182 | if (fmt == NULL) |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 1183 | SDE_ERROR("unsupported fmt 0x%X modifier 0x%llX\n", |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1184 | format, mod0); |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 1185 | else |
Alan Kwong | 4fc006e | 2017-01-29 18:19:34 -0800 | [diff] [blame] | 1186 | SDE_DEBUG("fmt %s mod 0x%llX ubwc %d yuv %d\n", |
Lloyd Atkinson | fa2489c | 2016-05-25 15:16:03 -0400 | [diff] [blame] | 1187 | drm_get_format_name(format), mod0, |
| 1188 | SDE_FORMAT_IS_UBWC(fmt), |
| 1189 | SDE_FORMAT_IS_YUV(fmt)); |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 1190 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1191 | return fmt; |
| 1192 | } |
| 1193 | |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 1194 | const struct msm_format *sde_get_msm_format( |
| 1195 | struct msm_kms *kms, |
| 1196 | const uint32_t format, |
| 1197 | const uint64_t *modifiers, |
| 1198 | const uint32_t modifiers_len) |
| 1199 | { |
| 1200 | const struct sde_format *fmt = sde_get_sde_format_ext(format, |
| 1201 | modifiers, modifiers_len); |
| 1202 | if (fmt) |
| 1203 | return &fmt->base; |
| 1204 | return NULL; |
| 1205 | } |
| 1206 | |
Clarence Ip | ea3d626 | 2016-07-15 16:20:11 -0400 | [diff] [blame] | 1207 | uint32_t sde_populate_formats( |
| 1208 | const struct sde_format_extended *format_list, |
| 1209 | uint32_t *pixel_formats, |
| 1210 | uint64_t *pixel_modifiers, |
| 1211 | uint32_t pixel_formats_max) |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 1212 | { |
Clarence Ip | ea3d626 | 2016-07-15 16:20:11 -0400 | [diff] [blame] | 1213 | uint32_t i, fourcc_format; |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 1214 | |
Clarence Ip | ea3d626 | 2016-07-15 16:20:11 -0400 | [diff] [blame] | 1215 | if (!format_list || !pixel_formats) |
| 1216 | return 0; |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 1217 | |
Clarence Ip | ea3d626 | 2016-07-15 16:20:11 -0400 | [diff] [blame] | 1218 | for (i = 0, fourcc_format = 0; |
| 1219 | format_list->fourcc_format && i < pixel_formats_max; |
| 1220 | ++format_list) { |
| 1221 | /* verify if listed format is in sde_format_map? */ |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 1222 | |
Clarence Ip | ea3d626 | 2016-07-15 16:20:11 -0400 | [diff] [blame] | 1223 | /* optionally return modified formats */ |
| 1224 | if (pixel_modifiers) { |
| 1225 | /* assume same modifier for all fb planes */ |
| 1226 | pixel_formats[i] = format_list->fourcc_format; |
| 1227 | pixel_modifiers[i++] = format_list->modifier; |
| 1228 | } else { |
| 1229 | /* assume base formats grouped together */ |
| 1230 | if (fourcc_format != format_list->fourcc_format) { |
| 1231 | fourcc_format = format_list->fourcc_format; |
| 1232 | pixel_formats[i++] = fourcc_format; |
| 1233 | } |
| 1234 | } |
Lloyd Atkinson | 9a67349 | 2016-07-05 11:41:57 -0400 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | return i; |
| 1238 | } |