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