blob: 1afe8418e127342771b9989ef115d5c69bff5d73 [file] [log] [blame]
Tom Rini70df9d62018-05-07 17:02:21 -04001// SPDX-License-Identifier: GPL-2.0+
Alexander Grafd65783d2016-03-15 18:38:21 +01002/*
3 * EFI application disk support
4 *
5 * Copyright (c) 2016 Alexander Graf
Alexander Grafd65783d2016-03-15 18:38:21 +01006 */
7
8#include <common.h>
Alexander Graf792284f2016-06-05 22:34:31 +02009#include <dm.h>
Alexander Grafd65783d2016-03-15 18:38:21 +010010#include <efi_loader.h>
11#include <inttypes.h>
12#include <lcd.h>
13#include <malloc.h>
Alexander Graf792284f2016-06-05 22:34:31 +020014#include <video.h>
Alexander Grafd65783d2016-03-15 18:38:21 +010015
16DECLARE_GLOBAL_DATA_PTR;
17
18static const efi_guid_t efi_gop_guid = EFI_GOP_GUID;
19
20struct 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 Graf792284f2016-06-05 22:34:31 +020028 /* Fields we only have acces to during init */
29 u32 bpix;
Rob Clark92cec962017-07-21 15:00:27 -040030 void *fb;
Alexander Grafd65783d2016-03-15 18:38:21 +010031};
32
33static efi_status_t EFIAPI gop_query_mode(struct efi_gop *this, u32 mode_number,
Heinrich Schuchardt8b28d5c2017-10-26 19:25:51 +020034 efi_uintn_t *size_of_info,
Alexander Grafd65783d2016-03-15 18:38:21 +010035 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
48static 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 Schuchardt9370d5a2018-03-16 19:59:06 +010058static __always_inline struct efi_gop_pixel efi_vid16_to_blt_col(u16 vid)
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +010059{
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 Schuchardt9370d5a2018-03-16 19:59:06 +010072static __always_inline u16 efi_blt_col_to_vid16(struct efi_gop_pixel *blt)
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +010073{
74 return (u16)(blt->red >> 3) << 11 |
75 (u16)(blt->green >> 2) << 5 |
76 (u16)(blt->blue >> 3);
77}
78
Alexander Grafa3800bd2018-03-15 15:02:28 +010079static __always_inline efi_status_t gop_blt_int(struct efi_gop *this,
Alexander Graf18f436c2018-03-15 15:02:29 +010080 struct efi_gop_pixel *bufferp,
Alexander Grafa3800bd2018-03-15 15:02:28 +010081 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 Graf18f436c2018-03-15 15:02:29 +010086 efi_uintn_t delta,
87 efi_uintn_t vid_bpp)
Alexander Grafd65783d2016-03-15 18:38:21 +010088{
Alexander Graf792284f2016-06-05 22:34:31 +020089 struct efi_gop_obj *gopobj = container_of(this, struct efi_gop_obj, ops);
Alexander Graf18f436c2018-03-15 15:02:29 +010090 efi_uintn_t i, j, linelen, slineoff = 0, dlineoff, swidth, dwidth;
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +010091 u32 *fb32 = gopobj->fb;
92 u16 *fb16 = gopobj->fb;
Alexander Graf18f436c2018-03-15 15:02:29 +010093 struct efi_gop_pixel *buffer = __builtin_assume_aligned(bufferp, 4);
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +010094
Heinrich Schuchardt5f86d332018-03-14 19:57:02 +010095 if (delta) {
96 /* Check for 4 byte alignment */
97 if (delta & 3)
Alexander Grafa3800bd2018-03-15 15:02:28 +010098 return EFI_INVALID_PARAMETER;
Heinrich Schuchardt5f86d332018-03-14 19:57:02 +010099 linelen = delta >> 2;
100 } else {
101 linelen = width;
102 }
103
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +0100104 /* 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 Grafa3800bd2018-03-15 15:02:28 +0100110 return EFI_INVALID_PARAMETER;
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +0100111 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 Grafa3800bd2018-03-15 15:02:28 +0100116 return EFI_INVALID_PARAMETER;
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +0100117 break;
118 default:
Alexander Grafa3800bd2018-03-15 15:02:28 +0100119 return EFI_INVALID_PARAMETER;
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +0100120 }
Alexander Grafd65783d2016-03-15 18:38:21 +0100121
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +0100122 /* 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 Grafa3800bd2018-03-15 15:02:28 +0100129 return EFI_INVALID_PARAMETER;
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +0100130 break;
131 case EFI_BLT_VIDEO_TO_BLT_BUFFER:
132 if (dx + width > linelen)
Alexander Grafa3800bd2018-03-15 15:02:28 +0100133 return EFI_INVALID_PARAMETER;
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +0100134 break;
135 }
Alexander Grafd65783d2016-03-15 18:38:21 +0100136
Alexander Graf18f436c2018-03-15 15:02:29 +0100137 /* 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 Schuchardta2c715f2018-02-07 22:14:22 +0100168 for (i = 0; i < height; i++) {
169 for (j = 0; j < width; j++) {
170 struct efi_gop_pixel pix;
Alexander Grafd65783d2016-03-15 18:38:21 +0100171
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +0100172 /* 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 Graf18f436c2018-03-15 15:02:29 +0100178 pix = buffer[slineoff + j + sx];
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +0100179 break;
180 case EFI_BLT_VIDEO_TO_BLT_BUFFER:
181 case EFI_BLT_VIDEO_TO_VIDEO:
Alexander Graf18f436c2018-03-15 15:02:29 +0100182 if (vid_bpp == 32)
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +0100183 pix = *(struct efi_gop_pixel *)&fb32[
Alexander Graf18f436c2018-03-15 15:02:29 +0100184 slineoff + j + sx];
185 else
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +0100186 pix = efi_vid16_to_blt_col(fb16[
Alexander Graf18f436c2018-03-15 15:02:29 +0100187 slineoff + j + sx]);
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +0100188 break;
189 }
Alexander Grafd65783d2016-03-15 18:38:21 +0100190
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +0100191 /* Write destination pixel */
192 switch (operation) {
193 case EFI_BLT_VIDEO_TO_BLT_BUFFER:
Alexander Graf18f436c2018-03-15 15:02:29 +0100194 buffer[dlineoff + j + dx] = pix;
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +0100195 break;
196 case EFI_BLT_BUFFER_TO_VIDEO:
197 case EFI_BLT_VIDEO_FILL:
198 case EFI_BLT_VIDEO_TO_VIDEO:
Alexander Graf18f436c2018-03-15 15:02:29 +0100199 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
214static 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 Schuchardta2c715f2018-02-07 22:14:22 +0100220#ifdef CONFIG_DM_VIDEO
Alexander Graf18f436c2018-03-15 15:02:29 +0100221 case VIDEO_BPP32:
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +0100222#else
Alexander Graf18f436c2018-03-15 15:02:29 +0100223 case LCD_COLOR32:
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +0100224#endif
Alexander Graf18f436c2018-03-15 15:02:29 +0100225 vid_bpp = 32;
226 break;
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +0100227#ifdef CONFIG_DM_VIDEO
Alexander Graf18f436c2018-03-15 15:02:29 +0100228 case VIDEO_BPP16:
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +0100229#else
Alexander Graf18f436c2018-03-15 15:02:29 +0100230 case LCD_COLOR16:
Heinrich Schuchardta2c715f2018-02-07 22:14:22 +0100231#endif
Alexander Graf18f436c2018-03-15 15:02:29 +0100232 vid_bpp = 16;
233 break;
Alexander Grafd65783d2016-03-15 18:38:21 +0100234 }
235
Alexander Graf18f436c2018-03-15 15:02:29 +0100236 return vid_bpp;
Alexander Grafa3800bd2018-03-15 15:02:28 +0100237}
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 */
248static 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 Graf18f436c2018-03-15 15:02:29 +0100253 efi_uintn_t height, efi_uintn_t delta,
254 efi_uintn_t vid_bpp)
Alexander Grafa3800bd2018-03-15 15:02:28 +0100255{
256 return gop_blt_int(this, buffer, EFI_BLT_VIDEO_FILL, sx, sy, dx,
Alexander Graf18f436c2018-03-15 15:02:29 +0100257 dy, width, height, delta, vid_bpp);
Alexander Grafa3800bd2018-03-15 15:02:28 +0100258}
259
Alexander Graf18f436c2018-03-15 15:02:29 +0100260static 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
271static 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 Grafa3800bd2018-03-15 15:02:28 +0100277{
278 return gop_blt_int(this, buffer, EFI_BLT_BUFFER_TO_VIDEO, sx, sy, dx,
Alexander Graf18f436c2018-03-15 15:02:29 +0100279 dy, width, height, delta, 32);
Alexander Grafa3800bd2018-03-15 15:02:28 +0100280}
281
282static 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 Graf18f436c2018-03-15 15:02:29 +0100287 efi_uintn_t height, efi_uintn_t delta,
288 efi_uintn_t vid_bpp)
Alexander Grafa3800bd2018-03-15 15:02:28 +0100289{
290 return gop_blt_int(this, buffer, EFI_BLT_VIDEO_TO_VIDEO, sx, sy, dx,
Alexander Graf18f436c2018-03-15 15:02:29 +0100291 dy, width, height, delta, vid_bpp);
Alexander Grafa3800bd2018-03-15 15:02:28 +0100292}
293
294static 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 Graf18f436c2018-03-15 15:02:29 +0100299 efi_uintn_t height, efi_uintn_t delta,
300 efi_uintn_t vid_bpp)
Alexander Grafa3800bd2018-03-15 15:02:28 +0100301{
302 return gop_blt_int(this, buffer, EFI_BLT_VIDEO_TO_BLT_BUFFER, sx, sy,
Alexander Graf18f436c2018-03-15 15:02:29 +0100303 dx, dy, width, height, delta, vid_bpp);
Alexander Grafa3800bd2018-03-15 15:02:28 +0100304}
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 */
324efi_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 Graf18f436c2018-03-15 15:02:29 +0100331 efi_uintn_t vid_bpp;
Alexander Grafa3800bd2018-03-15 15:02:28 +0100332
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 Graf18f436c2018-03-15 15:02:29 +0100336 vid_bpp = gop_get_bpp(this);
337
Alexander Grafa3800bd2018-03-15 15:02:28 +0100338 /* 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 Graf18f436c2018-03-15 15:02:29 +0100342 dy, width, height, delta, vid_bpp);
Alexander Grafa3800bd2018-03-15 15:02:28 +0100343 break;
344 case EFI_BLT_BUFFER_TO_VIDEO:
Alexander Graf18f436c2018-03-15 15:02:29 +0100345 /* 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 Grafa3800bd2018-03-15 15:02:28 +0100354 break;
355 case EFI_BLT_VIDEO_TO_VIDEO:
356 ret = gop_blt_vid_to_vid(this, buffer, operation, sx, sy, dx,
Alexander Graf18f436c2018-03-15 15:02:29 +0100357 dy, width, height, delta, vid_bpp);
Alexander Grafa3800bd2018-03-15 15:02:28 +0100358 break;
359 case EFI_BLT_VIDEO_TO_BLT_BUFFER:
360 ret = gop_blt_vid_to_buf(this, buffer, operation, sx, sy, dx,
Alexander Graf18f436c2018-03-15 15:02:29 +0100361 dy, width, height, delta, vid_bpp);
Alexander Grafa3800bd2018-03-15 15:02:28 +0100362 break;
363 default:
364 ret = EFI_UNSUPPORTED;
365 }
366
367 if (ret != EFI_SUCCESS)
368 return EFI_EXIT(ret);
369
Alexander Graf792284f2016-06-05 22:34:31 +0200370#ifdef CONFIG_DM_VIDEO
371 video_sync_all();
372#else
Alexander Grafd65783d2016-03-15 18:38:21 +0100373 lcd_sync();
Alexander Graf792284f2016-06-05 22:34:31 +0200374#endif
Alexander Grafd65783d2016-03-15 18:38:21 +0100375
376 return EFI_EXIT(EFI_SUCCESS);
377}
378
Heinrich Schuchardtb91c0842018-03-03 15:28:55 +0100379/*
380 * Install graphical output protocol.
381 *
382 * If no supported video device exists this is not considered as an
383 * error.
384 */
385efi_status_t efi_gop_register(void)
Alexander Grafd65783d2016-03-15 18:38:21 +0100386{
387 struct efi_gop_obj *gopobj;
Alexander Graf792284f2016-06-05 22:34:31 +0200388 u32 bpix, col, row;
Alexander Grafbc766392016-06-07 00:57:05 +0200389 u64 fb_base, fb_size;
Rob Clark92cec962017-07-21 15:00:27 -0400390 void *fb;
Heinrich Schuchardtbde9a9b2017-11-26 14:05:14 +0100391 efi_status_t ret;
Alexander Grafd65783d2016-03-15 18:38:21 +0100392
Alexander Graf792284f2016-06-05 22:34:31 +0200393#ifdef CONFIG_DM_VIDEO
394 struct udevice *vdev;
Heinrich Schuchardtb91c0842018-03-03 15:28:55 +0100395 struct video_priv *priv;
Alexander Graf792284f2016-06-05 22:34:31 +0200396
397 /* We only support a single video output device for now */
Heinrich Schuchardtb91c0842018-03-03 15:28:55 +0100398 if (uclass_first_device(UCLASS_VIDEO, &vdev) || !vdev) {
399 debug("WARNING: No video device\n");
400 return EFI_SUCCESS;
401 }
Alexander Graf792284f2016-06-05 22:34:31 +0200402
Heinrich Schuchardtb91c0842018-03-03 15:28:55 +0100403 priv = dev_get_uclass_priv(vdev);
Alexander Graf792284f2016-06-05 22:34:31 +0200404 bpix = priv->bpix;
405 col = video_get_xsize(vdev);
406 row = video_get_ysize(vdev);
Alexander Grafbc766392016-06-07 00:57:05 +0200407 fb_base = (uintptr_t)priv->fb;
408 fb_size = priv->fb_size;
Rob Clark92cec962017-07-21 15:00:27 -0400409 fb = priv->fb;
Alexander Graf792284f2016-06-05 22:34:31 +0200410#else
Alexander Grafbc766392016-06-07 00:57:05 +0200411 int line_len;
Alexander Graf792284f2016-06-05 22:34:31 +0200412
413 bpix = panel_info.vl_bpix;
414 col = panel_info.vl_col;
415 row = panel_info.vl_row;
Alexander Grafbc766392016-06-07 00:57:05 +0200416 fb_base = gd->fb_base;
417 fb_size = lcd_get_size(&line_len);
Alexander Grafda29c602017-07-31 09:15:57 +0200418 fb = (void*)gd->fb_base;
Alexander Graf792284f2016-06-05 22:34:31 +0200419#endif
420
421 switch (bpix) {
422#ifdef CONFIG_DM_VIDEO
423 case VIDEO_BPP16:
424 case VIDEO_BPP32:
425#else
Alexander Grafd65783d2016-03-15 18:38:21 +0100426 case LCD_COLOR32:
427 case LCD_COLOR16:
Alexander Graf792284f2016-06-05 22:34:31 +0200428#endif
Alexander Grafd65783d2016-03-15 18:38:21 +0100429 break;
430 default:
431 /* So far, we only work in 16 or 32 bit mode */
Heinrich Schuchardtb91c0842018-03-03 15:28:55 +0100432 debug("WARNING: Unsupported video mode\n");
433 return EFI_SUCCESS;
Alexander Grafd65783d2016-03-15 18:38:21 +0100434 }
435
436 gopobj = calloc(1, sizeof(*gopobj));
Heinrich Schuchardt9aaa35b2017-10-26 19:25:45 +0200437 if (!gopobj) {
438 printf("ERROR: Out of memory\n");
Heinrich Schuchardtb91c0842018-03-03 15:28:55 +0100439 return EFI_OUT_OF_RESOURCES;
Heinrich Schuchardt9aaa35b2017-10-26 19:25:45 +0200440 }
Alexander Grafd65783d2016-03-15 18:38:21 +0100441
Heinrich Schuchardtbde9a9b2017-11-26 14:05:14 +0100442 /* Hook up to the device list */
Heinrich Schuchardt967d7de2017-11-26 14:05:23 +0100443 efi_add_handle(&gopobj->parent);
Heinrich Schuchardtbde9a9b2017-11-26 14:05:14 +0100444
Alexander Grafd65783d2016-03-15 18:38:21 +0100445 /* Fill in object data */
Heinrich Schuchardtbde9a9b2017-11-26 14:05:14 +0100446 ret = efi_add_protocol(gopobj->parent.handle, &efi_gop_guid,
447 &gopobj->ops);
448 if (ret != EFI_SUCCESS) {
Heinrich Schuchardtb91c0842018-03-03 15:28:55 +0100449 printf("ERROR: Failure adding gop protocol\n");
450 return ret;
Heinrich Schuchardtbde9a9b2017-11-26 14:05:14 +0100451 }
Alexander Grafd65783d2016-03-15 18:38:21 +0100452 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 Grafd65783d2016-03-15 18:38:21 +0100460
Alexander Grafbc766392016-06-07 00:57:05 +0200461#ifdef CONFIG_DM_VIDEO
Heinrich Schuchardtb91c0842018-03-03 15:28:55 +0100462 if (bpix == VIDEO_BPP32)
Alexander Grafbc766392016-06-07 00:57:05 +0200463#else
Heinrich Schuchardtb91c0842018-03-03 15:28:55 +0100464 if (bpix == LCD_COLOR32)
Alexander Grafbc766392016-06-07 00:57:05 +0200465#endif
Heinrich Schuchardtb91c0842018-03-03 15:28:55 +0100466 {
Alexander Grafbc766392016-06-07 00:57:05 +0200467 /* 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 Grafd65783d2016-03-15 18:38:21 +0100472 gopobj->info.version = 0;
Alexander Graf792284f2016-06-05 22:34:31 +0200473 gopobj->info.width = col;
474 gopobj->info.height = row;
Alexander Grafd65783d2016-03-15 18:38:21 +0100475 gopobj->info.pixel_format = EFI_GOT_RGBA8;
Alexander Graf792284f2016-06-05 22:34:31 +0200476 gopobj->info.pixels_per_scanline = col;
477
478 gopobj->bpix = bpix;
Rob Clark92cec962017-07-21 15:00:27 -0400479 gopobj->fb = fb;
Alexander Grafd65783d2016-03-15 18:38:21 +0100480
Heinrich Schuchardtb91c0842018-03-03 15:28:55 +0100481 return EFI_SUCCESS;
Alexander Grafd65783d2016-03-15 18:38:21 +0100482}