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