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