blob: 1afe8418e127342771b9989ef115d5c69bff5d73 [file] [log] [blame]
Tom Rinif739fcd2018-05-07 17:02:21 -04001// SPDX-License-Identifier: GPL-2.0+
Alexander Grafbe8d3242016-03-15 18:38:21 +01002/*
3 * EFI application disk support
4 *
5 * Copyright (c) 2016 Alexander Graf
Alexander Grafbe8d3242016-03-15 18:38:21 +01006 */
7
8#include <common.h>
Alexander Grafa8122412016-06-05 22:34:31 +02009#include <dm.h>
Alexander Grafbe8d3242016-03-15 18:38:21 +010010#include <efi_loader.h>
11#include <inttypes.h>
12#include <lcd.h>
13#include <malloc.h>
Alexander Grafa8122412016-06-05 22:34:31 +020014#include <video.h>
Alexander Grafbe8d3242016-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 Grafa8122412016-06-05 22:34:31 +020028 /* Fields we only have acces to during init */
29 u32 bpix;
Rob Clarkca9193d2017-07-21 15:00:27 -040030 void *fb;
Alexander Grafbe8d3242016-03-15 18:38:21 +010031};
32
33static efi_status_t EFIAPI gop_query_mode(struct efi_gop *this, u32 mode_number,
Heinrich Schuchardt1c38a772017-10-26 19:25:51 +020034 efi_uintn_t *size_of_info,
Alexander Grafbe8d3242016-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 Schuchardt90b658b2018-03-16 19:59:06 +010058static __always_inline struct efi_gop_pixel efi_vid16_to_blt_col(u16 vid)
Heinrich Schuchardt0e0a3ce2018-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 Schuchardt90b658b2018-03-16 19:59:06 +010072static __always_inline u16 efi_blt_col_to_vid16(struct efi_gop_pixel *blt)
Heinrich Schuchardt0e0a3ce2018-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 Grafba718e62018-03-15 15:02:28 +010079static __always_inline efi_status_t gop_blt_int(struct efi_gop *this,
Alexander Graf8e475062018-03-15 15:02:29 +010080 struct efi_gop_pixel *bufferp,
Alexander Grafba718e62018-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 Graf8e475062018-03-15 15:02:29 +010086 efi_uintn_t delta,
87 efi_uintn_t vid_bpp)
Alexander Grafbe8d3242016-03-15 18:38:21 +010088{
Alexander Grafa8122412016-06-05 22:34:31 +020089 struct efi_gop_obj *gopobj = container_of(this, struct efi_gop_obj, ops);
Alexander Graf8e475062018-03-15 15:02:29 +010090 efi_uintn_t i, j, linelen, slineoff = 0, dlineoff, swidth, dwidth;
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +010091 u32 *fb32 = gopobj->fb;
92 u16 *fb16 = gopobj->fb;
Alexander Graf8e475062018-03-15 15:02:29 +010093 struct efi_gop_pixel *buffer = __builtin_assume_aligned(bufferp, 4);
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +010094
Heinrich Schuchardt51a0f452018-03-14 19:57:02 +010095 if (delta) {
96 /* Check for 4 byte alignment */
97 if (delta & 3)
Alexander Grafba718e62018-03-15 15:02:28 +010098 return EFI_INVALID_PARAMETER;
Heinrich Schuchardt51a0f452018-03-14 19:57:02 +010099 linelen = delta >> 2;
100 } else {
101 linelen = width;
102 }
103
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100104 /* Check source rectangle */
105 switch (operation) {
106 case EFI_BLT_VIDEO_FILL:
Alexander Grafbe8d3242016-03-15 18:38:21 +0100107 break;
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100108 case EFI_BLT_BUFFER_TO_VIDEO:
109 if (sx + width > linelen)
Alexander Grafba718e62018-03-15 15:02:28 +0100110 return EFI_INVALID_PARAMETER;
Heinrich Schuchardt0e0a3ce2018-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 Grafba718e62018-03-15 15:02:28 +0100116 return EFI_INVALID_PARAMETER;
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100117 break;
118 default:
Alexander Grafba718e62018-03-15 15:02:28 +0100119 return EFI_INVALID_PARAMETER;
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100120 }
Alexander Grafbe8d3242016-03-15 18:38:21 +0100121
Heinrich Schuchardt0e0a3ce2018-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 Grafba718e62018-03-15 15:02:28 +0100129 return EFI_INVALID_PARAMETER;
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100130 break;
131 case EFI_BLT_VIDEO_TO_BLT_BUFFER:
132 if (dx + width > linelen)
Alexander Grafba718e62018-03-15 15:02:28 +0100133 return EFI_INVALID_PARAMETER;
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100134 break;
135 }
136
Alexander Graf8e475062018-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 Schuchardt0e0a3ce2018-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;
171
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 Graf8e475062018-03-15 15:02:29 +0100178 pix = buffer[slineoff + j + sx];
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100179 break;
180 case EFI_BLT_VIDEO_TO_BLT_BUFFER:
181 case EFI_BLT_VIDEO_TO_VIDEO:
Alexander Graf8e475062018-03-15 15:02:29 +0100182 if (vid_bpp == 32)
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100183 pix = *(struct efi_gop_pixel *)&fb32[
Alexander Graf8e475062018-03-15 15:02:29 +0100184 slineoff + j + sx];
185 else
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100186 pix = efi_vid16_to_blt_col(fb16[
Alexander Graf8e475062018-03-15 15:02:29 +0100187 slineoff + j + sx]);
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100188 break;
189 }
190
191 /* Write destination pixel */
192 switch (operation) {
193 case EFI_BLT_VIDEO_TO_BLT_BUFFER:
Alexander Graf8e475062018-03-15 15:02:29 +0100194 buffer[dlineoff + j + dx] = pix;
Heinrich Schuchardt0e0a3ce2018-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 Graf8e475062018-03-15 15:02:29 +0100199 if (vid_bpp == 32)
200 fb32[dlineoff + j + dx] = *(u32 *)&pix;
201 else
202 fb16[dlineoff + j + dx] =
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100203 efi_blt_col_to_vid16(&pix);
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100204 break;
Alexander Grafbe8d3242016-03-15 18:38:21 +0100205 }
206 }
Alexander Graf8e475062018-03-15 15:02:29 +0100207 slineoff += swidth;
208 dlineoff += dwidth;
Alexander Grafbe8d3242016-03-15 18:38:21 +0100209 }
210
Alexander Grafba718e62018-03-15 15:02:28 +0100211 return EFI_SUCCESS;
212}
213
Alexander Graf8e475062018-03-15 15:02:29 +0100214static 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) {
220#ifdef CONFIG_DM_VIDEO
221 case VIDEO_BPP32:
222#else
223 case LCD_COLOR32:
224#endif
225 vid_bpp = 32;
226 break;
227#ifdef CONFIG_DM_VIDEO
228 case VIDEO_BPP16:
229#else
230 case LCD_COLOR16:
231#endif
232 vid_bpp = 16;
233 break;
234 }
235
236 return vid_bpp;
237}
238
Alexander Grafba718e62018-03-15 15:02:28 +0100239/*
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 Graf8e475062018-03-15 15:02:29 +0100253 efi_uintn_t height, efi_uintn_t delta,
254 efi_uintn_t vid_bpp)
Alexander Grafba718e62018-03-15 15:02:28 +0100255{
256 return gop_blt_int(this, buffer, EFI_BLT_VIDEO_FILL, sx, sy, dx,
Alexander Graf8e475062018-03-15 15:02:29 +0100257 dy, width, height, delta, vid_bpp);
Alexander Grafba718e62018-03-15 15:02:28 +0100258}
259
Alexander Graf8e475062018-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)
Alexander Grafba718e62018-03-15 15:02:28 +0100266{
267 return gop_blt_int(this, buffer, EFI_BLT_BUFFER_TO_VIDEO, sx, sy, dx,
Alexander Graf8e475062018-03-15 15:02:29 +0100268 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)
277{
278 return gop_blt_int(this, buffer, EFI_BLT_BUFFER_TO_VIDEO, sx, sy, dx,
279 dy, width, height, delta, 32);
Alexander Grafba718e62018-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 Graf8e475062018-03-15 15:02:29 +0100287 efi_uintn_t height, efi_uintn_t delta,
288 efi_uintn_t vid_bpp)
Alexander Grafba718e62018-03-15 15:02:28 +0100289{
290 return gop_blt_int(this, buffer, EFI_BLT_VIDEO_TO_VIDEO, sx, sy, dx,
Alexander Graf8e475062018-03-15 15:02:29 +0100291 dy, width, height, delta, vid_bpp);
Alexander Grafba718e62018-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 Graf8e475062018-03-15 15:02:29 +0100299 efi_uintn_t height, efi_uintn_t delta,
300 efi_uintn_t vid_bpp)
Alexander Grafba718e62018-03-15 15:02:28 +0100301{
302 return gop_blt_int(this, buffer, EFI_BLT_VIDEO_TO_BLT_BUFFER, sx, sy,
Alexander Graf8e475062018-03-15 15:02:29 +0100303 dx, dy, width, height, delta, vid_bpp);
Alexander Grafba718e62018-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 Graf8e475062018-03-15 15:02:29 +0100331 efi_uintn_t vid_bpp;
Alexander Grafba718e62018-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 Graf8e475062018-03-15 15:02:29 +0100336 vid_bpp = gop_get_bpp(this);
337
Alexander Grafba718e62018-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 Graf8e475062018-03-15 15:02:29 +0100342 dy, width, height, delta, vid_bpp);
Alexander Grafba718e62018-03-15 15:02:28 +0100343 break;
344 case EFI_BLT_BUFFER_TO_VIDEO:
Alexander Graf8e475062018-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 Grafba718e62018-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 Graf8e475062018-03-15 15:02:29 +0100357 dy, width, height, delta, vid_bpp);
Alexander Grafba718e62018-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 Graf8e475062018-03-15 15:02:29 +0100361 dy, width, height, delta, vid_bpp);
Alexander Grafba718e62018-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 Grafa8122412016-06-05 22:34:31 +0200370#ifdef CONFIG_DM_VIDEO
371 video_sync_all();
372#else
Alexander Grafbe8d3242016-03-15 18:38:21 +0100373 lcd_sync();
Alexander Grafa8122412016-06-05 22:34:31 +0200374#endif
Alexander Grafbe8d3242016-03-15 18:38:21 +0100375
376 return EFI_EXIT(EFI_SUCCESS);
377}
378
Heinrich Schuchardt80ea9b02018-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 Grafbe8d3242016-03-15 18:38:21 +0100386{
387 struct efi_gop_obj *gopobj;
Alexander Grafa8122412016-06-05 22:34:31 +0200388 u32 bpix, col, row;
Alexander Graf8f661a52016-06-07 00:57:05 +0200389 u64 fb_base, fb_size;
Rob Clarkca9193d2017-07-21 15:00:27 -0400390 void *fb;
Heinrich Schuchardt94493582017-11-26 14:05:14 +0100391 efi_status_t ret;
Alexander Grafbe8d3242016-03-15 18:38:21 +0100392
Alexander Grafa8122412016-06-05 22:34:31 +0200393#ifdef CONFIG_DM_VIDEO
394 struct udevice *vdev;
Heinrich Schuchardt80ea9b02018-03-03 15:28:55 +0100395 struct video_priv *priv;
Alexander Grafa8122412016-06-05 22:34:31 +0200396
397 /* We only support a single video output device for now */
Heinrich Schuchardt80ea9b02018-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 Grafa8122412016-06-05 22:34:31 +0200402
Heinrich Schuchardt80ea9b02018-03-03 15:28:55 +0100403 priv = dev_get_uclass_priv(vdev);
Alexander Grafa8122412016-06-05 22:34:31 +0200404 bpix = priv->bpix;
405 col = video_get_xsize(vdev);
406 row = video_get_ysize(vdev);
Alexander Graf8f661a52016-06-07 00:57:05 +0200407 fb_base = (uintptr_t)priv->fb;
408 fb_size = priv->fb_size;
Rob Clarkca9193d2017-07-21 15:00:27 -0400409 fb = priv->fb;
Alexander Grafa8122412016-06-05 22:34:31 +0200410#else
Alexander Graf8f661a52016-06-07 00:57:05 +0200411 int line_len;
Alexander Grafa8122412016-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 Graf8f661a52016-06-07 00:57:05 +0200416 fb_base = gd->fb_base;
417 fb_size = lcd_get_size(&line_len);
Alexander Grafc1ae1a12017-07-31 09:15:57 +0200418 fb = (void*)gd->fb_base;
Alexander Grafa8122412016-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 Grafbe8d3242016-03-15 18:38:21 +0100426 case LCD_COLOR32:
427 case LCD_COLOR16:
Alexander Grafa8122412016-06-05 22:34:31 +0200428#endif
Alexander Grafbe8d3242016-03-15 18:38:21 +0100429 break;
430 default:
431 /* So far, we only work in 16 or 32 bit mode */
Heinrich Schuchardt80ea9b02018-03-03 15:28:55 +0100432 debug("WARNING: Unsupported video mode\n");
433 return EFI_SUCCESS;
Alexander Grafbe8d3242016-03-15 18:38:21 +0100434 }
435
436 gopobj = calloc(1, sizeof(*gopobj));
Heinrich Schuchardt753edb12017-10-26 19:25:45 +0200437 if (!gopobj) {
438 printf("ERROR: Out of memory\n");
Heinrich Schuchardt80ea9b02018-03-03 15:28:55 +0100439 return EFI_OUT_OF_RESOURCES;
Heinrich Schuchardt753edb12017-10-26 19:25:45 +0200440 }
Alexander Grafbe8d3242016-03-15 18:38:21 +0100441
Heinrich Schuchardt94493582017-11-26 14:05:14 +0100442 /* Hook up to the device list */
Heinrich Schuchardt44549d62017-11-26 14:05:23 +0100443 efi_add_handle(&gopobj->parent);
Heinrich Schuchardt94493582017-11-26 14:05:14 +0100444
Alexander Grafbe8d3242016-03-15 18:38:21 +0100445 /* Fill in object data */
Heinrich Schuchardt94493582017-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 Schuchardt80ea9b02018-03-03 15:28:55 +0100449 printf("ERROR: Failure adding gop protocol\n");
450 return ret;
Heinrich Schuchardt94493582017-11-26 14:05:14 +0100451 }
Alexander Grafbe8d3242016-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 Grafbe8d3242016-03-15 18:38:21 +0100460
Alexander Graf8f661a52016-06-07 00:57:05 +0200461#ifdef CONFIG_DM_VIDEO
Heinrich Schuchardt80ea9b02018-03-03 15:28:55 +0100462 if (bpix == VIDEO_BPP32)
Alexander Graf8f661a52016-06-07 00:57:05 +0200463#else
Heinrich Schuchardt80ea9b02018-03-03 15:28:55 +0100464 if (bpix == LCD_COLOR32)
Alexander Graf8f661a52016-06-07 00:57:05 +0200465#endif
Heinrich Schuchardt80ea9b02018-03-03 15:28:55 +0100466 {
Alexander Graf8f661a52016-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 Grafbe8d3242016-03-15 18:38:21 +0100472 gopobj->info.version = 0;
Alexander Grafa8122412016-06-05 22:34:31 +0200473 gopobj->info.width = col;
474 gopobj->info.height = row;
Alexander Grafbe8d3242016-03-15 18:38:21 +0100475 gopobj->info.pixel_format = EFI_GOT_RGBA8;
Alexander Grafa8122412016-06-05 22:34:31 +0200476 gopobj->info.pixels_per_scanline = col;
477
478 gopobj->bpix = bpix;
Rob Clarkca9193d2017-07-21 15:00:27 -0400479 gopobj->fb = fb;
Alexander Grafbe8d3242016-03-15 18:38:21 +0100480
Heinrich Schuchardt80ea9b02018-03-03 15:28:55 +0100481 return EFI_SUCCESS;
Alexander Grafbe8d3242016-03-15 18:38:21 +0100482}