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