Tom Rini | 70df9d6 | 2018-05-07 17:02:21 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 2 | /* |
| 3 | * EFI application disk support |
| 4 | * |
| 5 | * Copyright (c) 2016 Alexander Graf |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Alexander Graf | 792284f | 2016-06-05 22:34:31 +0200 | [diff] [blame] | 9 | #include <dm.h> |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 10 | #include <efi_loader.h> |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 11 | #include <lcd.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 13 | #include <malloc.h> |
Alexander Graf | 792284f | 2016-06-05 22:34:31 +0200 | [diff] [blame] | 14 | #include <video.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 16 | |
| 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
Heinrich Schuchardt | 788ad41 | 2019-04-20 07:39:11 +0200 | [diff] [blame] | 19 | static const efi_guid_t efi_gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 20 | |
Heinrich Schuchardt | 7292872 | 2018-09-26 05:27:56 +0200 | [diff] [blame] | 21 | /** |
| 22 | * struct efi_gop_obj - graphical output protocol object |
| 23 | * |
| 24 | * @header: EFI object header |
| 25 | * @ops: graphical output protocol interface |
| 26 | * @info: graphical output mode information |
| 27 | * @mode: graphical output mode |
| 28 | * @bpix: bits per pixel |
| 29 | * @fb: frame buffer |
| 30 | */ |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 31 | struct efi_gop_obj { |
Heinrich Schuchardt | 7292872 | 2018-09-26 05:27:56 +0200 | [diff] [blame] | 32 | struct efi_object header; |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 33 | struct efi_gop ops; |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 34 | struct efi_gop_mode_info info; |
| 35 | struct efi_gop_mode mode; |
Heinrich Schuchardt | 7292872 | 2018-09-26 05:27:56 +0200 | [diff] [blame] | 36 | /* Fields we only have access to during init */ |
Alexander Graf | 792284f | 2016-06-05 22:34:31 +0200 | [diff] [blame] | 37 | u32 bpix; |
Rob Clark | 92cec96 | 2017-07-21 15:00:27 -0400 | [diff] [blame] | 38 | void *fb; |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | static efi_status_t EFIAPI gop_query_mode(struct efi_gop *this, u32 mode_number, |
Heinrich Schuchardt | 8b28d5c | 2017-10-26 19:25:51 +0200 | [diff] [blame] | 42 | efi_uintn_t *size_of_info, |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 43 | struct efi_gop_mode_info **info) |
| 44 | { |
| 45 | struct efi_gop_obj *gopobj; |
Heinrich Schuchardt | 5e1dbf7 | 2019-06-15 12:52:35 +0200 | [diff] [blame] | 46 | efi_status_t ret = EFI_SUCCESS; |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 47 | |
| 48 | EFI_ENTRY("%p, %x, %p, %p", this, mode_number, size_of_info, info); |
| 49 | |
Heinrich Schuchardt | 5e1dbf7 | 2019-06-15 12:52:35 +0200 | [diff] [blame] | 50 | if (!this || !size_of_info || !info || mode_number) { |
| 51 | ret = EFI_INVALID_PARAMETER; |
| 52 | goto out; |
| 53 | } |
| 54 | |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 55 | gopobj = container_of(this, struct efi_gop_obj, ops); |
Heinrich Schuchardt | 0301e36 | 2019-06-15 14:07:40 +0200 | [diff] [blame] | 56 | ret = efi_allocate_pool(EFI_BOOT_SERVICES_DATA, sizeof(gopobj->info), |
| 57 | (void **)info); |
| 58 | if (ret != EFI_SUCCESS) |
| 59 | goto out; |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 60 | *size_of_info = sizeof(gopobj->info); |
Heinrich Schuchardt | 0301e36 | 2019-06-15 14:07:40 +0200 | [diff] [blame] | 61 | memcpy(*info, &gopobj->info, sizeof(gopobj->info)); |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 62 | |
Heinrich Schuchardt | 5e1dbf7 | 2019-06-15 12:52:35 +0200 | [diff] [blame] | 63 | out: |
| 64 | return EFI_EXIT(ret); |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 65 | } |
| 66 | |
Mark Kettenis | d8ab334 | 2021-09-25 22:47:39 +0200 | [diff] [blame] | 67 | static __always_inline struct efi_gop_pixel efi_vid30_to_blt_col(u32 vid) |
| 68 | { |
| 69 | struct efi_gop_pixel blt = { |
| 70 | .reserved = 0, |
| 71 | }; |
| 72 | |
| 73 | blt.blue = (vid & 0x3ff) >> 2; |
| 74 | vid >>= 10; |
| 75 | blt.green = (vid & 0x3ff) >> 2; |
| 76 | vid >>= 10; |
| 77 | blt.red = (vid & 0x3ff) >> 2; |
| 78 | return blt; |
| 79 | } |
| 80 | |
| 81 | static __always_inline u32 efi_blt_col_to_vid30(struct efi_gop_pixel *blt) |
| 82 | { |
| 83 | return (u32)(blt->red << 2) << 20 | |
| 84 | (u32)(blt->green << 2) << 10 | |
| 85 | (u32)(blt->blue << 2); |
| 86 | } |
| 87 | |
Heinrich Schuchardt | 9370d5a | 2018-03-16 19:59:06 +0100 | [diff] [blame] | 88 | static __always_inline struct efi_gop_pixel efi_vid16_to_blt_col(u16 vid) |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 89 | { |
| 90 | struct efi_gop_pixel blt = { |
| 91 | .reserved = 0, |
| 92 | }; |
| 93 | |
| 94 | blt.blue = (vid & 0x1f) << 3; |
| 95 | vid >>= 5; |
| 96 | blt.green = (vid & 0x3f) << 2; |
| 97 | vid >>= 6; |
| 98 | blt.red = (vid & 0x1f) << 3; |
| 99 | return blt; |
| 100 | } |
| 101 | |
Heinrich Schuchardt | 9370d5a | 2018-03-16 19:59:06 +0100 | [diff] [blame] | 102 | static __always_inline u16 efi_blt_col_to_vid16(struct efi_gop_pixel *blt) |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 103 | { |
| 104 | return (u16)(blt->red >> 3) << 11 | |
| 105 | (u16)(blt->green >> 2) << 5 | |
| 106 | (u16)(blt->blue >> 3); |
| 107 | } |
| 108 | |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 109 | static __always_inline efi_status_t gop_blt_int(struct efi_gop *this, |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 110 | struct efi_gop_pixel *bufferp, |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 111 | u32 operation, efi_uintn_t sx, |
| 112 | efi_uintn_t sy, efi_uintn_t dx, |
| 113 | efi_uintn_t dy, |
| 114 | efi_uintn_t width, |
| 115 | efi_uintn_t height, |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 116 | efi_uintn_t delta, |
| 117 | efi_uintn_t vid_bpp) |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 118 | { |
Alexander Graf | 792284f | 2016-06-05 22:34:31 +0200 | [diff] [blame] | 119 | struct efi_gop_obj *gopobj = container_of(this, struct efi_gop_obj, ops); |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 120 | efi_uintn_t i, j, linelen, slineoff = 0, dlineoff, swidth, dwidth; |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 121 | u32 *fb32 = gopobj->fb; |
| 122 | u16 *fb16 = gopobj->fb; |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 123 | struct efi_gop_pixel *buffer = __builtin_assume_aligned(bufferp, 4); |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 124 | |
Heinrich Schuchardt | 5f86d33 | 2018-03-14 19:57:02 +0100 | [diff] [blame] | 125 | if (delta) { |
| 126 | /* Check for 4 byte alignment */ |
| 127 | if (delta & 3) |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 128 | return EFI_INVALID_PARAMETER; |
Heinrich Schuchardt | 5f86d33 | 2018-03-14 19:57:02 +0100 | [diff] [blame] | 129 | linelen = delta >> 2; |
| 130 | } else { |
| 131 | linelen = width; |
| 132 | } |
| 133 | |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 134 | /* Check source rectangle */ |
| 135 | switch (operation) { |
| 136 | case EFI_BLT_VIDEO_FILL: |
| 137 | break; |
| 138 | case EFI_BLT_BUFFER_TO_VIDEO: |
| 139 | if (sx + width > linelen) |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 140 | return EFI_INVALID_PARAMETER; |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 141 | break; |
| 142 | case EFI_BLT_VIDEO_TO_BLT_BUFFER: |
| 143 | case EFI_BLT_VIDEO_TO_VIDEO: |
| 144 | if (sx + width > gopobj->info.width || |
| 145 | sy + height > gopobj->info.height) |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 146 | return EFI_INVALID_PARAMETER; |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 147 | break; |
| 148 | default: |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 149 | return EFI_INVALID_PARAMETER; |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 150 | } |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 151 | |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 152 | /* Check destination rectangle */ |
| 153 | switch (operation) { |
| 154 | case EFI_BLT_VIDEO_FILL: |
| 155 | case EFI_BLT_BUFFER_TO_VIDEO: |
| 156 | case EFI_BLT_VIDEO_TO_VIDEO: |
| 157 | if (dx + width > gopobj->info.width || |
| 158 | dy + height > gopobj->info.height) |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 159 | return EFI_INVALID_PARAMETER; |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 160 | break; |
| 161 | case EFI_BLT_VIDEO_TO_BLT_BUFFER: |
| 162 | if (dx + width > linelen) |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 163 | return EFI_INVALID_PARAMETER; |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 164 | break; |
| 165 | } |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 166 | |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 167 | /* Calculate line width */ |
| 168 | switch (operation) { |
| 169 | case EFI_BLT_BUFFER_TO_VIDEO: |
| 170 | swidth = linelen; |
| 171 | break; |
| 172 | case EFI_BLT_VIDEO_TO_BLT_BUFFER: |
| 173 | case EFI_BLT_VIDEO_TO_VIDEO: |
| 174 | swidth = gopobj->info.width; |
| 175 | if (!vid_bpp) |
| 176 | return EFI_UNSUPPORTED; |
| 177 | break; |
| 178 | case EFI_BLT_VIDEO_FILL: |
| 179 | swidth = 0; |
| 180 | break; |
| 181 | } |
| 182 | |
| 183 | switch (operation) { |
| 184 | case EFI_BLT_BUFFER_TO_VIDEO: |
| 185 | case EFI_BLT_VIDEO_FILL: |
| 186 | case EFI_BLT_VIDEO_TO_VIDEO: |
| 187 | dwidth = gopobj->info.width; |
| 188 | if (!vid_bpp) |
| 189 | return EFI_UNSUPPORTED; |
| 190 | break; |
| 191 | case EFI_BLT_VIDEO_TO_BLT_BUFFER: |
| 192 | dwidth = linelen; |
| 193 | break; |
| 194 | } |
| 195 | |
| 196 | slineoff = swidth * sy; |
| 197 | dlineoff = dwidth * dy; |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 198 | for (i = 0; i < height; i++) { |
| 199 | for (j = 0; j < width; j++) { |
| 200 | struct efi_gop_pixel pix; |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 201 | |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 202 | /* Read source pixel */ |
| 203 | switch (operation) { |
| 204 | case EFI_BLT_VIDEO_FILL: |
| 205 | pix = *buffer; |
| 206 | break; |
| 207 | case EFI_BLT_BUFFER_TO_VIDEO: |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 208 | pix = buffer[slineoff + j + sx]; |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 209 | break; |
| 210 | case EFI_BLT_VIDEO_TO_BLT_BUFFER: |
| 211 | case EFI_BLT_VIDEO_TO_VIDEO: |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 212 | if (vid_bpp == 32) |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 213 | pix = *(struct efi_gop_pixel *)&fb32[ |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 214 | slineoff + j + sx]; |
Mark Kettenis | d8ab334 | 2021-09-25 22:47:39 +0200 | [diff] [blame] | 215 | else if (vid_bpp == 30) |
| 216 | pix = efi_vid30_to_blt_col(fb32[ |
| 217 | slineoff + j + sx]); |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 218 | else |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 219 | pix = efi_vid16_to_blt_col(fb16[ |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 220 | slineoff + j + sx]); |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 221 | break; |
| 222 | } |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 223 | |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 224 | /* Write destination pixel */ |
| 225 | switch (operation) { |
| 226 | case EFI_BLT_VIDEO_TO_BLT_BUFFER: |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 227 | buffer[dlineoff + j + dx] = pix; |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 228 | break; |
| 229 | case EFI_BLT_BUFFER_TO_VIDEO: |
| 230 | case EFI_BLT_VIDEO_FILL: |
| 231 | case EFI_BLT_VIDEO_TO_VIDEO: |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 232 | if (vid_bpp == 32) |
| 233 | fb32[dlineoff + j + dx] = *(u32 *)&pix; |
Mark Kettenis | d8ab334 | 2021-09-25 22:47:39 +0200 | [diff] [blame] | 234 | else if (vid_bpp == 30) |
| 235 | fb32[dlineoff + j + dx] = |
| 236 | efi_blt_col_to_vid30(&pix); |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 237 | else |
| 238 | fb16[dlineoff + j + dx] = |
| 239 | efi_blt_col_to_vid16(&pix); |
| 240 | break; |
| 241 | } |
| 242 | } |
| 243 | slineoff += swidth; |
| 244 | dlineoff += dwidth; |
| 245 | } |
| 246 | |
| 247 | return EFI_SUCCESS; |
| 248 | } |
| 249 | |
| 250 | static efi_uintn_t gop_get_bpp(struct efi_gop *this) |
| 251 | { |
| 252 | struct efi_gop_obj *gopobj = container_of(this, struct efi_gop_obj, ops); |
| 253 | efi_uintn_t vid_bpp = 0; |
| 254 | |
| 255 | switch (gopobj->bpix) { |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 256 | #ifdef CONFIG_DM_VIDEO |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 257 | case VIDEO_BPP32: |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 258 | #else |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 259 | case LCD_COLOR32: |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 260 | #endif |
Mark Kettenis | d8ab334 | 2021-09-25 22:47:39 +0200 | [diff] [blame] | 261 | if (gopobj->info.pixel_format == EFI_GOT_BGRA8) |
| 262 | vid_bpp = 32; |
| 263 | else |
| 264 | vid_bpp = 30; |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 265 | break; |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 266 | #ifdef CONFIG_DM_VIDEO |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 267 | case VIDEO_BPP16: |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 268 | #else |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 269 | case LCD_COLOR16: |
Heinrich Schuchardt | a2c715f | 2018-02-07 22:14:22 +0100 | [diff] [blame] | 270 | #endif |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 271 | vid_bpp = 16; |
| 272 | break; |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 273 | } |
| 274 | |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 275 | return vid_bpp; |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | /* |
Heinrich Schuchardt | 5e96f42 | 2018-10-18 21:51:38 +0200 | [diff] [blame] | 279 | * GCC can't optimize our BLT function well, but we need to make sure that |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 280 | * our 2-dimensional loop gets executed very quickly, otherwise the system |
| 281 | * will feel slow. |
| 282 | * |
| 283 | * By manually putting all obvious branch targets into functions which call |
Heinrich Schuchardt | 5e96f42 | 2018-10-18 21:51:38 +0200 | [diff] [blame] | 284 | * our generic BLT function with constants, the compiler can successfully |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 285 | * optimize for speed. |
| 286 | */ |
| 287 | static efi_status_t gop_blt_video_fill(struct efi_gop *this, |
| 288 | struct efi_gop_pixel *buffer, |
| 289 | u32 foo, efi_uintn_t sx, |
| 290 | efi_uintn_t sy, efi_uintn_t dx, |
| 291 | efi_uintn_t dy, efi_uintn_t width, |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 292 | efi_uintn_t height, efi_uintn_t delta, |
| 293 | efi_uintn_t vid_bpp) |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 294 | { |
| 295 | return gop_blt_int(this, buffer, EFI_BLT_VIDEO_FILL, sx, sy, dx, |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 296 | dy, width, height, delta, vid_bpp); |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 297 | } |
| 298 | |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 299 | static efi_status_t gop_blt_buf_to_vid16(struct efi_gop *this, |
| 300 | struct efi_gop_pixel *buffer, |
| 301 | u32 foo, efi_uintn_t sx, |
| 302 | efi_uintn_t sy, efi_uintn_t dx, |
| 303 | efi_uintn_t dy, efi_uintn_t width, |
| 304 | efi_uintn_t height, efi_uintn_t delta) |
| 305 | { |
| 306 | return gop_blt_int(this, buffer, EFI_BLT_BUFFER_TO_VIDEO, sx, sy, dx, |
| 307 | dy, width, height, delta, 16); |
| 308 | } |
| 309 | |
Mark Kettenis | d8ab334 | 2021-09-25 22:47:39 +0200 | [diff] [blame] | 310 | static efi_status_t gop_blt_buf_to_vid30(struct efi_gop *this, |
| 311 | struct efi_gop_pixel *buffer, |
| 312 | u32 foo, efi_uintn_t sx, |
| 313 | efi_uintn_t sy, efi_uintn_t dx, |
| 314 | efi_uintn_t dy, efi_uintn_t width, |
| 315 | efi_uintn_t height, efi_uintn_t delta) |
| 316 | { |
| 317 | return gop_blt_int(this, buffer, EFI_BLT_BUFFER_TO_VIDEO, sx, sy, dx, |
| 318 | dy, width, height, delta, 30); |
| 319 | } |
| 320 | |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 321 | static efi_status_t gop_blt_buf_to_vid32(struct efi_gop *this, |
| 322 | struct efi_gop_pixel *buffer, |
| 323 | u32 foo, efi_uintn_t sx, |
| 324 | efi_uintn_t sy, efi_uintn_t dx, |
| 325 | efi_uintn_t dy, efi_uintn_t width, |
| 326 | efi_uintn_t height, efi_uintn_t delta) |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 327 | { |
| 328 | return gop_blt_int(this, buffer, EFI_BLT_BUFFER_TO_VIDEO, sx, sy, dx, |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 329 | dy, width, height, delta, 32); |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | static efi_status_t gop_blt_vid_to_vid(struct efi_gop *this, |
| 333 | struct efi_gop_pixel *buffer, |
| 334 | u32 foo, efi_uintn_t sx, |
| 335 | efi_uintn_t sy, efi_uintn_t dx, |
| 336 | efi_uintn_t dy, efi_uintn_t width, |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 337 | efi_uintn_t height, efi_uintn_t delta, |
| 338 | efi_uintn_t vid_bpp) |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 339 | { |
| 340 | return gop_blt_int(this, buffer, EFI_BLT_VIDEO_TO_VIDEO, sx, sy, dx, |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 341 | dy, width, height, delta, vid_bpp); |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | static efi_status_t gop_blt_vid_to_buf(struct efi_gop *this, |
| 345 | struct efi_gop_pixel *buffer, |
| 346 | u32 foo, efi_uintn_t sx, |
| 347 | efi_uintn_t sy, efi_uintn_t dx, |
| 348 | efi_uintn_t dy, efi_uintn_t width, |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 349 | efi_uintn_t height, efi_uintn_t delta, |
| 350 | efi_uintn_t vid_bpp) |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 351 | { |
| 352 | return gop_blt_int(this, buffer, EFI_BLT_VIDEO_TO_BLT_BUFFER, sx, sy, |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 353 | dx, dy, width, height, delta, vid_bpp); |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 354 | } |
| 355 | |
Heinrich Schuchardt | e32595b | 2019-06-15 14:52:53 +0200 | [diff] [blame] | 356 | /** |
| 357 | * gop_set_mode() - set graphical output mode |
| 358 | * |
| 359 | * This function implements the SetMode() service. |
| 360 | * |
| 361 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 362 | * details. |
| 363 | * |
| 364 | * @this: the graphical output protocol |
Heinrich Schuchardt | dc305ad | 2019-09-05 20:37:13 +0200 | [diff] [blame] | 365 | * @mode_number: the mode to be set |
Heinrich Schuchardt | e32595b | 2019-06-15 14:52:53 +0200 | [diff] [blame] | 366 | * Return: status code |
| 367 | */ |
| 368 | static efi_status_t EFIAPI gop_set_mode(struct efi_gop *this, u32 mode_number) |
| 369 | { |
| 370 | struct efi_gop_obj *gopobj; |
| 371 | struct efi_gop_pixel buffer = {0, 0, 0, 0}; |
| 372 | efi_uintn_t vid_bpp; |
| 373 | efi_status_t ret = EFI_SUCCESS; |
| 374 | |
| 375 | EFI_ENTRY("%p, %x", this, mode_number); |
| 376 | |
| 377 | if (!this) { |
| 378 | ret = EFI_INVALID_PARAMETER; |
| 379 | goto out; |
| 380 | } |
| 381 | if (mode_number) { |
| 382 | ret = EFI_UNSUPPORTED; |
| 383 | goto out; |
| 384 | } |
| 385 | gopobj = container_of(this, struct efi_gop_obj, ops); |
| 386 | vid_bpp = gop_get_bpp(this); |
| 387 | ret = gop_blt_video_fill(this, &buffer, EFI_BLT_VIDEO_FILL, 0, 0, 0, 0, |
| 388 | gopobj->info.width, gopobj->info.height, 0, |
| 389 | vid_bpp); |
| 390 | out: |
| 391 | return EFI_EXIT(ret); |
| 392 | } |
| 393 | |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 394 | /* |
| 395 | * Copy rectangle. |
| 396 | * |
| 397 | * This function implements the Blt service of the EFI_GRAPHICS_OUTPUT_PROTOCOL. |
| 398 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 399 | * details. |
| 400 | * |
| 401 | * @this: EFI_GRAPHICS_OUTPUT_PROTOCOL |
| 402 | * @buffer: pixel buffer |
| 403 | * @sx: source x-coordinate |
| 404 | * @sy: source y-coordinate |
| 405 | * @dx: destination x-coordinate |
| 406 | * @dy: destination y-coordinate |
| 407 | * @width: width of rectangle |
| 408 | * @height: height of rectangle |
| 409 | * @delta: length in bytes of a line in the pixel buffer (optional) |
| 410 | * @return: status code |
| 411 | */ |
| 412 | efi_status_t EFIAPI gop_blt(struct efi_gop *this, struct efi_gop_pixel *buffer, |
| 413 | u32 operation, efi_uintn_t sx, |
| 414 | efi_uintn_t sy, efi_uintn_t dx, |
| 415 | efi_uintn_t dy, efi_uintn_t width, |
| 416 | efi_uintn_t height, efi_uintn_t delta) |
| 417 | { |
| 418 | efi_status_t ret = EFI_INVALID_PARAMETER; |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 419 | efi_uintn_t vid_bpp; |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 420 | |
| 421 | EFI_ENTRY("%p, %p, %u, %zu, %zu, %zu, %zu, %zu, %zu, %zu", this, |
| 422 | buffer, operation, sx, sy, dx, dy, width, height, delta); |
| 423 | |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 424 | vid_bpp = gop_get_bpp(this); |
| 425 | |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 426 | /* Allow for compiler optimization */ |
| 427 | switch (operation) { |
| 428 | case EFI_BLT_VIDEO_FILL: |
| 429 | ret = gop_blt_video_fill(this, buffer, operation, sx, sy, dx, |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 430 | dy, width, height, delta, vid_bpp); |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 431 | break; |
| 432 | case EFI_BLT_BUFFER_TO_VIDEO: |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 433 | /* This needs to be super-fast, so duplicate for 16/32bpp */ |
| 434 | if (vid_bpp == 32) |
| 435 | ret = gop_blt_buf_to_vid32(this, buffer, operation, sx, |
| 436 | sy, dx, dy, width, height, |
| 437 | delta); |
Mark Kettenis | d8ab334 | 2021-09-25 22:47:39 +0200 | [diff] [blame] | 438 | else if (vid_bpp == 30) |
| 439 | ret = gop_blt_buf_to_vid30(this, buffer, operation, sx, |
| 440 | sy, dx, dy, width, height, |
| 441 | delta); |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 442 | else |
| 443 | ret = gop_blt_buf_to_vid16(this, buffer, operation, sx, |
| 444 | sy, dx, dy, width, height, |
| 445 | delta); |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 446 | break; |
| 447 | case EFI_BLT_VIDEO_TO_VIDEO: |
| 448 | ret = gop_blt_vid_to_vid(this, buffer, operation, sx, sy, dx, |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 449 | dy, width, height, delta, vid_bpp); |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 450 | break; |
| 451 | case EFI_BLT_VIDEO_TO_BLT_BUFFER: |
| 452 | ret = gop_blt_vid_to_buf(this, buffer, operation, sx, sy, dx, |
Alexander Graf | 18f436c | 2018-03-15 15:02:29 +0100 | [diff] [blame] | 453 | dy, width, height, delta, vid_bpp); |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 454 | break; |
| 455 | default: |
Heinrich Schuchardt | 087c8c4 | 2019-06-15 12:42:46 +0200 | [diff] [blame] | 456 | ret = EFI_INVALID_PARAMETER; |
Alexander Graf | a3800bd | 2018-03-15 15:02:28 +0100 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | if (ret != EFI_SUCCESS) |
| 460 | return EFI_EXIT(ret); |
| 461 | |
Alexander Graf | 792284f | 2016-06-05 22:34:31 +0200 | [diff] [blame] | 462 | #ifdef CONFIG_DM_VIDEO |
| 463 | video_sync_all(); |
| 464 | #else |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 465 | lcd_sync(); |
Alexander Graf | 792284f | 2016-06-05 22:34:31 +0200 | [diff] [blame] | 466 | #endif |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 467 | |
| 468 | return EFI_EXIT(EFI_SUCCESS); |
| 469 | } |
| 470 | |
Heinrich Schuchardt | b91c084 | 2018-03-03 15:28:55 +0100 | [diff] [blame] | 471 | /* |
| 472 | * Install graphical output protocol. |
| 473 | * |
| 474 | * If no supported video device exists this is not considered as an |
| 475 | * error. |
| 476 | */ |
| 477 | efi_status_t efi_gop_register(void) |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 478 | { |
| 479 | struct efi_gop_obj *gopobj; |
Mark Kettenis | 3e4b3d5 | 2021-09-25 22:47:37 +0200 | [diff] [blame] | 480 | u32 bpix, format, col, row; |
Alexander Graf | bc76639 | 2016-06-07 00:57:05 +0200 | [diff] [blame] | 481 | u64 fb_base, fb_size; |
Rob Clark | 92cec96 | 2017-07-21 15:00:27 -0400 | [diff] [blame] | 482 | void *fb; |
Heinrich Schuchardt | bde9a9b | 2017-11-26 14:05:14 +0100 | [diff] [blame] | 483 | efi_status_t ret; |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 484 | |
Alexander Graf | 792284f | 2016-06-05 22:34:31 +0200 | [diff] [blame] | 485 | #ifdef CONFIG_DM_VIDEO |
| 486 | struct udevice *vdev; |
Heinrich Schuchardt | b91c084 | 2018-03-03 15:28:55 +0100 | [diff] [blame] | 487 | struct video_priv *priv; |
Alexander Graf | 792284f | 2016-06-05 22:34:31 +0200 | [diff] [blame] | 488 | |
| 489 | /* We only support a single video output device for now */ |
Heinrich Schuchardt | b91c084 | 2018-03-03 15:28:55 +0100 | [diff] [blame] | 490 | if (uclass_first_device(UCLASS_VIDEO, &vdev) || !vdev) { |
| 491 | debug("WARNING: No video device\n"); |
| 492 | return EFI_SUCCESS; |
| 493 | } |
Alexander Graf | 792284f | 2016-06-05 22:34:31 +0200 | [diff] [blame] | 494 | |
Heinrich Schuchardt | b91c084 | 2018-03-03 15:28:55 +0100 | [diff] [blame] | 495 | priv = dev_get_uclass_priv(vdev); |
Alexander Graf | 792284f | 2016-06-05 22:34:31 +0200 | [diff] [blame] | 496 | bpix = priv->bpix; |
Mark Kettenis | 3e4b3d5 | 2021-09-25 22:47:37 +0200 | [diff] [blame] | 497 | format = priv->format; |
Alexander Graf | 792284f | 2016-06-05 22:34:31 +0200 | [diff] [blame] | 498 | col = video_get_xsize(vdev); |
| 499 | row = video_get_ysize(vdev); |
Alexander Graf | bc76639 | 2016-06-07 00:57:05 +0200 | [diff] [blame] | 500 | fb_base = (uintptr_t)priv->fb; |
| 501 | fb_size = priv->fb_size; |
Rob Clark | 92cec96 | 2017-07-21 15:00:27 -0400 | [diff] [blame] | 502 | fb = priv->fb; |
Alexander Graf | 792284f | 2016-06-05 22:34:31 +0200 | [diff] [blame] | 503 | #else |
Alexander Graf | bc76639 | 2016-06-07 00:57:05 +0200 | [diff] [blame] | 504 | int line_len; |
Alexander Graf | 792284f | 2016-06-05 22:34:31 +0200 | [diff] [blame] | 505 | |
| 506 | bpix = panel_info.vl_bpix; |
Mark Kettenis | 3e4b3d5 | 2021-09-25 22:47:37 +0200 | [diff] [blame] | 507 | format = VIDEO_UNKNOWN; |
Alexander Graf | 792284f | 2016-06-05 22:34:31 +0200 | [diff] [blame] | 508 | col = panel_info.vl_col; |
| 509 | row = panel_info.vl_row; |
Alexander Graf | bc76639 | 2016-06-07 00:57:05 +0200 | [diff] [blame] | 510 | fb_base = gd->fb_base; |
| 511 | fb_size = lcd_get_size(&line_len); |
Alexander Graf | da29c60 | 2017-07-31 09:15:57 +0200 | [diff] [blame] | 512 | fb = (void*)gd->fb_base; |
Alexander Graf | 792284f | 2016-06-05 22:34:31 +0200 | [diff] [blame] | 513 | #endif |
| 514 | |
| 515 | switch (bpix) { |
| 516 | #ifdef CONFIG_DM_VIDEO |
| 517 | case VIDEO_BPP16: |
| 518 | case VIDEO_BPP32: |
| 519 | #else |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 520 | case LCD_COLOR32: |
| 521 | case LCD_COLOR16: |
Alexander Graf | 792284f | 2016-06-05 22:34:31 +0200 | [diff] [blame] | 522 | #endif |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 523 | break; |
| 524 | default: |
| 525 | /* So far, we only work in 16 or 32 bit mode */ |
Heinrich Schuchardt | b91c084 | 2018-03-03 15:28:55 +0100 | [diff] [blame] | 526 | debug("WARNING: Unsupported video mode\n"); |
| 527 | return EFI_SUCCESS; |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | gopobj = calloc(1, sizeof(*gopobj)); |
Heinrich Schuchardt | 9aaa35b | 2017-10-26 19:25:45 +0200 | [diff] [blame] | 531 | if (!gopobj) { |
| 532 | printf("ERROR: Out of memory\n"); |
Heinrich Schuchardt | b91c084 | 2018-03-03 15:28:55 +0100 | [diff] [blame] | 533 | return EFI_OUT_OF_RESOURCES; |
Heinrich Schuchardt | 9aaa35b | 2017-10-26 19:25:45 +0200 | [diff] [blame] | 534 | } |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 535 | |
Heinrich Schuchardt | bde9a9b | 2017-11-26 14:05:14 +0100 | [diff] [blame] | 536 | /* Hook up to the device list */ |
Heinrich Schuchardt | 7292872 | 2018-09-26 05:27:56 +0200 | [diff] [blame] | 537 | efi_add_handle(&gopobj->header); |
Heinrich Schuchardt | bde9a9b | 2017-11-26 14:05:14 +0100 | [diff] [blame] | 538 | |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 539 | /* Fill in object data */ |
Heinrich Schuchardt | 7292872 | 2018-09-26 05:27:56 +0200 | [diff] [blame] | 540 | ret = efi_add_protocol(&gopobj->header, &efi_gop_guid, |
Heinrich Schuchardt | bde9a9b | 2017-11-26 14:05:14 +0100 | [diff] [blame] | 541 | &gopobj->ops); |
| 542 | if (ret != EFI_SUCCESS) { |
Heinrich Schuchardt | 5e96f42 | 2018-10-18 21:51:38 +0200 | [diff] [blame] | 543 | printf("ERROR: Failure adding GOP protocol\n"); |
Heinrich Schuchardt | b91c084 | 2018-03-03 15:28:55 +0100 | [diff] [blame] | 544 | return ret; |
Heinrich Schuchardt | bde9a9b | 2017-11-26 14:05:14 +0100 | [diff] [blame] | 545 | } |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 546 | gopobj->ops.query_mode = gop_query_mode; |
| 547 | gopobj->ops.set_mode = gop_set_mode; |
| 548 | gopobj->ops.blt = gop_blt; |
| 549 | gopobj->ops.mode = &gopobj->mode; |
| 550 | |
| 551 | gopobj->mode.max_mode = 1; |
| 552 | gopobj->mode.info = &gopobj->info; |
| 553 | gopobj->mode.info_size = sizeof(gopobj->info); |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 554 | |
Heinrich Schuchardt | 6ea1b29 | 2019-06-15 14:52:53 +0200 | [diff] [blame] | 555 | gopobj->mode.fb_base = fb_base; |
| 556 | gopobj->mode.fb_size = fb_size; |
| 557 | |
| 558 | gopobj->info.version = 0; |
| 559 | gopobj->info.width = col; |
| 560 | gopobj->info.height = row; |
Alexander Graf | bc76639 | 2016-06-07 00:57:05 +0200 | [diff] [blame] | 561 | #ifdef CONFIG_DM_VIDEO |
Heinrich Schuchardt | b91c084 | 2018-03-03 15:28:55 +0100 | [diff] [blame] | 562 | if (bpix == VIDEO_BPP32) |
Alexander Graf | bc76639 | 2016-06-07 00:57:05 +0200 | [diff] [blame] | 563 | #else |
Heinrich Schuchardt | b91c084 | 2018-03-03 15:28:55 +0100 | [diff] [blame] | 564 | if (bpix == LCD_COLOR32) |
Alexander Graf | bc76639 | 2016-06-07 00:57:05 +0200 | [diff] [blame] | 565 | #endif |
Heinrich Schuchardt | b91c084 | 2018-03-03 15:28:55 +0100 | [diff] [blame] | 566 | { |
Mark Kettenis | 3e4b3d5 | 2021-09-25 22:47:37 +0200 | [diff] [blame] | 567 | if (format == VIDEO_X2R10G10B10) { |
| 568 | gopobj->info.pixel_format = EFI_GOT_BITMASK; |
| 569 | gopobj->info.pixel_bitmask[0] = 0x3ff00000; /* red */ |
| 570 | gopobj->info.pixel_bitmask[1] = 0x000ffc00; /* green */ |
| 571 | gopobj->info.pixel_bitmask[2] = 0x000003ff; /* blue */ |
| 572 | gopobj->info.pixel_bitmask[3] = 0xc0000000; /* reserved */ |
| 573 | } else { |
| 574 | gopobj->info.pixel_format = EFI_GOT_BGRA8; |
| 575 | } |
Heinrich Schuchardt | 6ea1b29 | 2019-06-15 14:52:53 +0200 | [diff] [blame] | 576 | } else { |
| 577 | gopobj->info.pixel_format = EFI_GOT_BITMASK; |
| 578 | gopobj->info.pixel_bitmask[0] = 0xf800; /* red */ |
| 579 | gopobj->info.pixel_bitmask[1] = 0x07e0; /* green */ |
| 580 | gopobj->info.pixel_bitmask[2] = 0x001f; /* blue */ |
Alexander Graf | bc76639 | 2016-06-07 00:57:05 +0200 | [diff] [blame] | 581 | } |
Alexander Graf | 792284f | 2016-06-05 22:34:31 +0200 | [diff] [blame] | 582 | gopobj->info.pixels_per_scanline = col; |
Alexander Graf | 792284f | 2016-06-05 22:34:31 +0200 | [diff] [blame] | 583 | gopobj->bpix = bpix; |
Rob Clark | 92cec96 | 2017-07-21 15:00:27 -0400 | [diff] [blame] | 584 | gopobj->fb = fb; |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 585 | |
Heinrich Schuchardt | b91c084 | 2018-03-03 15:28:55 +0100 | [diff] [blame] | 586 | return EFI_SUCCESS; |
Alexander Graf | d65783d | 2016-03-15 18:38:21 +0100 | [diff] [blame] | 587 | } |