blob: a4aa9bcf61a1ea61ee87fae2b60e05016d59555e [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>
Alexander Grafbe8d3242016-03-15 18:38:21 +010011#include <lcd.h>
12#include <malloc.h>
Alexander Grafa8122412016-06-05 22:34:31 +020013#include <video.h>
Alexander Grafbe8d3242016-03-15 18:38:21 +010014
15DECLARE_GLOBAL_DATA_PTR;
16
17static const efi_guid_t efi_gop_guid = EFI_GOP_GUID;
18
19struct efi_gop_obj {
20 /* Generic EFI object parent class data */
21 struct efi_object parent;
22 /* EFI Interface callback struct for gop */
23 struct efi_gop ops;
24 /* The only mode we support */
25 struct efi_gop_mode_info info;
26 struct efi_gop_mode mode;
Alexander Grafa8122412016-06-05 22:34:31 +020027 /* Fields we only have acces to during init */
28 u32 bpix;
Rob Clarkca9193d2017-07-21 15:00:27 -040029 void *fb;
Alexander Grafbe8d3242016-03-15 18:38:21 +010030};
31
32static efi_status_t EFIAPI gop_query_mode(struct efi_gop *this, u32 mode_number,
Heinrich Schuchardt1c38a772017-10-26 19:25:51 +020033 efi_uintn_t *size_of_info,
Alexander Grafbe8d3242016-03-15 18:38:21 +010034 struct efi_gop_mode_info **info)
35{
36 struct efi_gop_obj *gopobj;
37
38 EFI_ENTRY("%p, %x, %p, %p", this, mode_number, size_of_info, info);
39
40 gopobj = container_of(this, struct efi_gop_obj, ops);
41 *size_of_info = sizeof(gopobj->info);
42 *info = &gopobj->info;
43
44 return EFI_EXIT(EFI_SUCCESS);
45}
46
47static efi_status_t EFIAPI gop_set_mode(struct efi_gop *this, u32 mode_number)
48{
49 EFI_ENTRY("%p, %x", this, mode_number);
50
51 if (mode_number != 0)
52 return EFI_EXIT(EFI_INVALID_PARAMETER);
53
54 return EFI_EXIT(EFI_SUCCESS);
55}
56
Heinrich Schuchardt90b658b2018-03-16 19:59:06 +010057static __always_inline struct efi_gop_pixel efi_vid16_to_blt_col(u16 vid)
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +010058{
59 struct efi_gop_pixel blt = {
60 .reserved = 0,
61 };
62
63 blt.blue = (vid & 0x1f) << 3;
64 vid >>= 5;
65 blt.green = (vid & 0x3f) << 2;
66 vid >>= 6;
67 blt.red = (vid & 0x1f) << 3;
68 return blt;
69}
70
Heinrich Schuchardt90b658b2018-03-16 19:59:06 +010071static __always_inline u16 efi_blt_col_to_vid16(struct efi_gop_pixel *blt)
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +010072{
73 return (u16)(blt->red >> 3) << 11 |
74 (u16)(blt->green >> 2) << 5 |
75 (u16)(blt->blue >> 3);
76}
77
Alexander Grafba718e62018-03-15 15:02:28 +010078static __always_inline efi_status_t gop_blt_int(struct efi_gop *this,
Alexander Graf8e475062018-03-15 15:02:29 +010079 struct efi_gop_pixel *bufferp,
Alexander Grafba718e62018-03-15 15:02:28 +010080 u32 operation, efi_uintn_t sx,
81 efi_uintn_t sy, efi_uintn_t dx,
82 efi_uintn_t dy,
83 efi_uintn_t width,
84 efi_uintn_t height,
Alexander Graf8e475062018-03-15 15:02:29 +010085 efi_uintn_t delta,
86 efi_uintn_t vid_bpp)
Alexander Grafbe8d3242016-03-15 18:38:21 +010087{
Alexander Grafa8122412016-06-05 22:34:31 +020088 struct efi_gop_obj *gopobj = container_of(this, struct efi_gop_obj, ops);
Alexander Graf8e475062018-03-15 15:02:29 +010089 efi_uintn_t i, j, linelen, slineoff = 0, dlineoff, swidth, dwidth;
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +010090 u32 *fb32 = gopobj->fb;
91 u16 *fb16 = gopobj->fb;
Alexander Graf8e475062018-03-15 15:02:29 +010092 struct efi_gop_pixel *buffer = __builtin_assume_aligned(bufferp, 4);
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +010093
Heinrich Schuchardt51a0f452018-03-14 19:57:02 +010094 if (delta) {
95 /* Check for 4 byte alignment */
96 if (delta & 3)
Alexander Grafba718e62018-03-15 15:02:28 +010097 return EFI_INVALID_PARAMETER;
Heinrich Schuchardt51a0f452018-03-14 19:57:02 +010098 linelen = delta >> 2;
99 } else {
100 linelen = width;
101 }
102
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100103 /* Check source rectangle */
104 switch (operation) {
105 case EFI_BLT_VIDEO_FILL:
Alexander Grafbe8d3242016-03-15 18:38:21 +0100106 break;
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100107 case EFI_BLT_BUFFER_TO_VIDEO:
108 if (sx + width > linelen)
Alexander Grafba718e62018-03-15 15:02:28 +0100109 return EFI_INVALID_PARAMETER;
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100110 break;
111 case EFI_BLT_VIDEO_TO_BLT_BUFFER:
112 case EFI_BLT_VIDEO_TO_VIDEO:
113 if (sx + width > gopobj->info.width ||
114 sy + height > gopobj->info.height)
Alexander Grafba718e62018-03-15 15:02:28 +0100115 return EFI_INVALID_PARAMETER;
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100116 break;
117 default:
Alexander Grafba718e62018-03-15 15:02:28 +0100118 return EFI_INVALID_PARAMETER;
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100119 }
Alexander Grafbe8d3242016-03-15 18:38:21 +0100120
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100121 /* Check destination rectangle */
122 switch (operation) {
123 case EFI_BLT_VIDEO_FILL:
124 case EFI_BLT_BUFFER_TO_VIDEO:
125 case EFI_BLT_VIDEO_TO_VIDEO:
126 if (dx + width > gopobj->info.width ||
127 dy + height > gopobj->info.height)
Alexander Grafba718e62018-03-15 15:02:28 +0100128 return EFI_INVALID_PARAMETER;
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100129 break;
130 case EFI_BLT_VIDEO_TO_BLT_BUFFER:
131 if (dx + width > linelen)
Alexander Grafba718e62018-03-15 15:02:28 +0100132 return EFI_INVALID_PARAMETER;
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100133 break;
134 }
135
Alexander Graf8e475062018-03-15 15:02:29 +0100136 /* Calculate line width */
137 switch (operation) {
138 case EFI_BLT_BUFFER_TO_VIDEO:
139 swidth = linelen;
140 break;
141 case EFI_BLT_VIDEO_TO_BLT_BUFFER:
142 case EFI_BLT_VIDEO_TO_VIDEO:
143 swidth = gopobj->info.width;
144 if (!vid_bpp)
145 return EFI_UNSUPPORTED;
146 break;
147 case EFI_BLT_VIDEO_FILL:
148 swidth = 0;
149 break;
150 }
151
152 switch (operation) {
153 case EFI_BLT_BUFFER_TO_VIDEO:
154 case EFI_BLT_VIDEO_FILL:
155 case EFI_BLT_VIDEO_TO_VIDEO:
156 dwidth = gopobj->info.width;
157 if (!vid_bpp)
158 return EFI_UNSUPPORTED;
159 break;
160 case EFI_BLT_VIDEO_TO_BLT_BUFFER:
161 dwidth = linelen;
162 break;
163 }
164
165 slineoff = swidth * sy;
166 dlineoff = dwidth * dy;
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100167 for (i = 0; i < height; i++) {
168 for (j = 0; j < width; j++) {
169 struct efi_gop_pixel pix;
170
171 /* Read source pixel */
172 switch (operation) {
173 case EFI_BLT_VIDEO_FILL:
174 pix = *buffer;
175 break;
176 case EFI_BLT_BUFFER_TO_VIDEO:
Alexander Graf8e475062018-03-15 15:02:29 +0100177 pix = buffer[slineoff + j + sx];
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100178 break;
179 case EFI_BLT_VIDEO_TO_BLT_BUFFER:
180 case EFI_BLT_VIDEO_TO_VIDEO:
Alexander Graf8e475062018-03-15 15:02:29 +0100181 if (vid_bpp == 32)
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100182 pix = *(struct efi_gop_pixel *)&fb32[
Alexander Graf8e475062018-03-15 15:02:29 +0100183 slineoff + j + sx];
184 else
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100185 pix = efi_vid16_to_blt_col(fb16[
Alexander Graf8e475062018-03-15 15:02:29 +0100186 slineoff + j + sx]);
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100187 break;
188 }
189
190 /* Write destination pixel */
191 switch (operation) {
192 case EFI_BLT_VIDEO_TO_BLT_BUFFER:
Alexander Graf8e475062018-03-15 15:02:29 +0100193 buffer[dlineoff + j + dx] = pix;
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100194 break;
195 case EFI_BLT_BUFFER_TO_VIDEO:
196 case EFI_BLT_VIDEO_FILL:
197 case EFI_BLT_VIDEO_TO_VIDEO:
Alexander Graf8e475062018-03-15 15:02:29 +0100198 if (vid_bpp == 32)
199 fb32[dlineoff + j + dx] = *(u32 *)&pix;
200 else
201 fb16[dlineoff + j + dx] =
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100202 efi_blt_col_to_vid16(&pix);
Heinrich Schuchardt0e0a3ce2018-02-07 22:14:22 +0100203 break;
Alexander Grafbe8d3242016-03-15 18:38:21 +0100204 }
205 }
Alexander Graf8e475062018-03-15 15:02:29 +0100206 slineoff += swidth;
207 dlineoff += dwidth;
Alexander Grafbe8d3242016-03-15 18:38:21 +0100208 }
209
Alexander Grafba718e62018-03-15 15:02:28 +0100210 return EFI_SUCCESS;
211}
212
Alexander Graf8e475062018-03-15 15:02:29 +0100213static efi_uintn_t gop_get_bpp(struct efi_gop *this)
214{
215 struct efi_gop_obj *gopobj = container_of(this, struct efi_gop_obj, ops);
216 efi_uintn_t vid_bpp = 0;
217
218 switch (gopobj->bpix) {
219#ifdef CONFIG_DM_VIDEO
220 case VIDEO_BPP32:
221#else
222 case LCD_COLOR32:
223#endif
224 vid_bpp = 32;
225 break;
226#ifdef CONFIG_DM_VIDEO
227 case VIDEO_BPP16:
228#else
229 case LCD_COLOR16:
230#endif
231 vid_bpp = 16;
232 break;
233 }
234
235 return vid_bpp;
236}
237
Alexander Grafba718e62018-03-15 15:02:28 +0100238/*
239 * Gcc can't optimize our BLT function well, but we need to make sure that
240 * our 2-dimensional loop gets executed very quickly, otherwise the system
241 * will feel slow.
242 *
243 * By manually putting all obvious branch targets into functions which call
244 * our generic blt function with constants, the compiler can successfully
245 * optimize for speed.
246 */
247static efi_status_t gop_blt_video_fill(struct efi_gop *this,
248 struct efi_gop_pixel *buffer,
249 u32 foo, efi_uintn_t sx,
250 efi_uintn_t sy, efi_uintn_t dx,
251 efi_uintn_t dy, efi_uintn_t width,
Alexander Graf8e475062018-03-15 15:02:29 +0100252 efi_uintn_t height, efi_uintn_t delta,
253 efi_uintn_t vid_bpp)
Alexander Grafba718e62018-03-15 15:02:28 +0100254{
255 return gop_blt_int(this, buffer, EFI_BLT_VIDEO_FILL, sx, sy, dx,
Alexander Graf8e475062018-03-15 15:02:29 +0100256 dy, width, height, delta, vid_bpp);
Alexander Grafba718e62018-03-15 15:02:28 +0100257}
258
Alexander Graf8e475062018-03-15 15:02:29 +0100259static efi_status_t gop_blt_buf_to_vid16(struct efi_gop *this,
260 struct efi_gop_pixel *buffer,
261 u32 foo, efi_uintn_t sx,
262 efi_uintn_t sy, efi_uintn_t dx,
263 efi_uintn_t dy, efi_uintn_t width,
264 efi_uintn_t height, efi_uintn_t delta)
Alexander Grafba718e62018-03-15 15:02:28 +0100265{
266 return gop_blt_int(this, buffer, EFI_BLT_BUFFER_TO_VIDEO, sx, sy, dx,
Alexander Graf8e475062018-03-15 15:02:29 +0100267 dy, width, height, delta, 16);
268}
269
270static efi_status_t gop_blt_buf_to_vid32(struct efi_gop *this,
271 struct efi_gop_pixel *buffer,
272 u32 foo, efi_uintn_t sx,
273 efi_uintn_t sy, efi_uintn_t dx,
274 efi_uintn_t dy, efi_uintn_t width,
275 efi_uintn_t height, efi_uintn_t delta)
276{
277 return gop_blt_int(this, buffer, EFI_BLT_BUFFER_TO_VIDEO, sx, sy, dx,
278 dy, width, height, delta, 32);
Alexander Grafba718e62018-03-15 15:02:28 +0100279}
280
281static efi_status_t gop_blt_vid_to_vid(struct efi_gop *this,
282 struct efi_gop_pixel *buffer,
283 u32 foo, efi_uintn_t sx,
284 efi_uintn_t sy, efi_uintn_t dx,
285 efi_uintn_t dy, efi_uintn_t width,
Alexander Graf8e475062018-03-15 15:02:29 +0100286 efi_uintn_t height, efi_uintn_t delta,
287 efi_uintn_t vid_bpp)
Alexander Grafba718e62018-03-15 15:02:28 +0100288{
289 return gop_blt_int(this, buffer, EFI_BLT_VIDEO_TO_VIDEO, sx, sy, dx,
Alexander Graf8e475062018-03-15 15:02:29 +0100290 dy, width, height, delta, vid_bpp);
Alexander Grafba718e62018-03-15 15:02:28 +0100291}
292
293static efi_status_t gop_blt_vid_to_buf(struct efi_gop *this,
294 struct efi_gop_pixel *buffer,
295 u32 foo, efi_uintn_t sx,
296 efi_uintn_t sy, efi_uintn_t dx,
297 efi_uintn_t dy, efi_uintn_t width,
Alexander Graf8e475062018-03-15 15:02:29 +0100298 efi_uintn_t height, efi_uintn_t delta,
299 efi_uintn_t vid_bpp)
Alexander Grafba718e62018-03-15 15:02:28 +0100300{
301 return gop_blt_int(this, buffer, EFI_BLT_VIDEO_TO_BLT_BUFFER, sx, sy,
Alexander Graf8e475062018-03-15 15:02:29 +0100302 dx, dy, width, height, delta, vid_bpp);
Alexander Grafba718e62018-03-15 15:02:28 +0100303}
304
305/*
306 * Copy rectangle.
307 *
308 * This function implements the Blt service of the EFI_GRAPHICS_OUTPUT_PROTOCOL.
309 * See the Unified Extensible Firmware Interface (UEFI) specification for
310 * details.
311 *
312 * @this: EFI_GRAPHICS_OUTPUT_PROTOCOL
313 * @buffer: pixel buffer
314 * @sx: source x-coordinate
315 * @sy: source y-coordinate
316 * @dx: destination x-coordinate
317 * @dy: destination y-coordinate
318 * @width: width of rectangle
319 * @height: height of rectangle
320 * @delta: length in bytes of a line in the pixel buffer (optional)
321 * @return: status code
322 */
323efi_status_t EFIAPI gop_blt(struct efi_gop *this, struct efi_gop_pixel *buffer,
324 u32 operation, efi_uintn_t sx,
325 efi_uintn_t sy, efi_uintn_t dx,
326 efi_uintn_t dy, efi_uintn_t width,
327 efi_uintn_t height, efi_uintn_t delta)
328{
329 efi_status_t ret = EFI_INVALID_PARAMETER;
Alexander Graf8e475062018-03-15 15:02:29 +0100330 efi_uintn_t vid_bpp;
Alexander Grafba718e62018-03-15 15:02:28 +0100331
332 EFI_ENTRY("%p, %p, %u, %zu, %zu, %zu, %zu, %zu, %zu, %zu", this,
333 buffer, operation, sx, sy, dx, dy, width, height, delta);
334
Alexander Graf8e475062018-03-15 15:02:29 +0100335 vid_bpp = gop_get_bpp(this);
336
Alexander Grafba718e62018-03-15 15:02:28 +0100337 /* Allow for compiler optimization */
338 switch (operation) {
339 case EFI_BLT_VIDEO_FILL:
340 ret = gop_blt_video_fill(this, buffer, operation, sx, sy, dx,
Alexander Graf8e475062018-03-15 15:02:29 +0100341 dy, width, height, delta, vid_bpp);
Alexander Grafba718e62018-03-15 15:02:28 +0100342 break;
343 case EFI_BLT_BUFFER_TO_VIDEO:
Alexander Graf8e475062018-03-15 15:02:29 +0100344 /* This needs to be super-fast, so duplicate for 16/32bpp */
345 if (vid_bpp == 32)
346 ret = gop_blt_buf_to_vid32(this, buffer, operation, sx,
347 sy, dx, dy, width, height,
348 delta);
349 else
350 ret = gop_blt_buf_to_vid16(this, buffer, operation, sx,
351 sy, dx, dy, width, height,
352 delta);
Alexander Grafba718e62018-03-15 15:02:28 +0100353 break;
354 case EFI_BLT_VIDEO_TO_VIDEO:
355 ret = gop_blt_vid_to_vid(this, buffer, operation, sx, sy, dx,
Alexander Graf8e475062018-03-15 15:02:29 +0100356 dy, width, height, delta, vid_bpp);
Alexander Grafba718e62018-03-15 15:02:28 +0100357 break;
358 case EFI_BLT_VIDEO_TO_BLT_BUFFER:
359 ret = gop_blt_vid_to_buf(this, buffer, operation, sx, sy, dx,
Alexander Graf8e475062018-03-15 15:02:29 +0100360 dy, width, height, delta, vid_bpp);
Alexander Grafba718e62018-03-15 15:02:28 +0100361 break;
362 default:
363 ret = EFI_UNSUPPORTED;
364 }
365
366 if (ret != EFI_SUCCESS)
367 return EFI_EXIT(ret);
368
Alexander Grafa8122412016-06-05 22:34:31 +0200369#ifdef CONFIG_DM_VIDEO
370 video_sync_all();
371#else
Alexander Grafbe8d3242016-03-15 18:38:21 +0100372 lcd_sync();
Alexander Grafa8122412016-06-05 22:34:31 +0200373#endif
Alexander Grafbe8d3242016-03-15 18:38:21 +0100374
375 return EFI_EXIT(EFI_SUCCESS);
376}
377
Heinrich Schuchardt80ea9b02018-03-03 15:28:55 +0100378/*
379 * Install graphical output protocol.
380 *
381 * If no supported video device exists this is not considered as an
382 * error.
383 */
384efi_status_t efi_gop_register(void)
Alexander Grafbe8d3242016-03-15 18:38:21 +0100385{
386 struct efi_gop_obj *gopobj;
Alexander Grafa8122412016-06-05 22:34:31 +0200387 u32 bpix, col, row;
Alexander Graf8f661a52016-06-07 00:57:05 +0200388 u64 fb_base, fb_size;
Rob Clarkca9193d2017-07-21 15:00:27 -0400389 void *fb;
Heinrich Schuchardt94493582017-11-26 14:05:14 +0100390 efi_status_t ret;
Alexander Grafbe8d3242016-03-15 18:38:21 +0100391
Alexander Grafa8122412016-06-05 22:34:31 +0200392#ifdef CONFIG_DM_VIDEO
393 struct udevice *vdev;
Heinrich Schuchardt80ea9b02018-03-03 15:28:55 +0100394 struct video_priv *priv;
Alexander Grafa8122412016-06-05 22:34:31 +0200395
396 /* We only support a single video output device for now */
Heinrich Schuchardt80ea9b02018-03-03 15:28:55 +0100397 if (uclass_first_device(UCLASS_VIDEO, &vdev) || !vdev) {
398 debug("WARNING: No video device\n");
399 return EFI_SUCCESS;
400 }
Alexander Grafa8122412016-06-05 22:34:31 +0200401
Heinrich Schuchardt80ea9b02018-03-03 15:28:55 +0100402 priv = dev_get_uclass_priv(vdev);
Alexander Grafa8122412016-06-05 22:34:31 +0200403 bpix = priv->bpix;
404 col = video_get_xsize(vdev);
405 row = video_get_ysize(vdev);
Alexander Graf8f661a52016-06-07 00:57:05 +0200406 fb_base = (uintptr_t)priv->fb;
407 fb_size = priv->fb_size;
Rob Clarkca9193d2017-07-21 15:00:27 -0400408 fb = priv->fb;
Alexander Grafa8122412016-06-05 22:34:31 +0200409#else
Alexander Graf8f661a52016-06-07 00:57:05 +0200410 int line_len;
Alexander Grafa8122412016-06-05 22:34:31 +0200411
412 bpix = panel_info.vl_bpix;
413 col = panel_info.vl_col;
414 row = panel_info.vl_row;
Alexander Graf8f661a52016-06-07 00:57:05 +0200415 fb_base = gd->fb_base;
416 fb_size = lcd_get_size(&line_len);
Alexander Grafc1ae1a12017-07-31 09:15:57 +0200417 fb = (void*)gd->fb_base;
Alexander Grafa8122412016-06-05 22:34:31 +0200418#endif
419
420 switch (bpix) {
421#ifdef CONFIG_DM_VIDEO
422 case VIDEO_BPP16:
423 case VIDEO_BPP32:
424#else
Alexander Grafbe8d3242016-03-15 18:38:21 +0100425 case LCD_COLOR32:
426 case LCD_COLOR16:
Alexander Grafa8122412016-06-05 22:34:31 +0200427#endif
Alexander Grafbe8d3242016-03-15 18:38:21 +0100428 break;
429 default:
430 /* So far, we only work in 16 or 32 bit mode */
Heinrich Schuchardt80ea9b02018-03-03 15:28:55 +0100431 debug("WARNING: Unsupported video mode\n");
432 return EFI_SUCCESS;
Alexander Grafbe8d3242016-03-15 18:38:21 +0100433 }
434
435 gopobj = calloc(1, sizeof(*gopobj));
Heinrich Schuchardt753edb12017-10-26 19:25:45 +0200436 if (!gopobj) {
437 printf("ERROR: Out of memory\n");
Heinrich Schuchardt80ea9b02018-03-03 15:28:55 +0100438 return EFI_OUT_OF_RESOURCES;
Heinrich Schuchardt753edb12017-10-26 19:25:45 +0200439 }
Alexander Grafbe8d3242016-03-15 18:38:21 +0100440
Heinrich Schuchardt94493582017-11-26 14:05:14 +0100441 /* Hook up to the device list */
Heinrich Schuchardt44549d62017-11-26 14:05:23 +0100442 efi_add_handle(&gopobj->parent);
Heinrich Schuchardt94493582017-11-26 14:05:14 +0100443
Alexander Grafbe8d3242016-03-15 18:38:21 +0100444 /* Fill in object data */
Heinrich Schuchardt94493582017-11-26 14:05:14 +0100445 ret = efi_add_protocol(gopobj->parent.handle, &efi_gop_guid,
446 &gopobj->ops);
447 if (ret != EFI_SUCCESS) {
Heinrich Schuchardt80ea9b02018-03-03 15:28:55 +0100448 printf("ERROR: Failure adding gop protocol\n");
449 return ret;
Heinrich Schuchardt94493582017-11-26 14:05:14 +0100450 }
Alexander Grafbe8d3242016-03-15 18:38:21 +0100451 gopobj->ops.query_mode = gop_query_mode;
452 gopobj->ops.set_mode = gop_set_mode;
453 gopobj->ops.blt = gop_blt;
454 gopobj->ops.mode = &gopobj->mode;
455
456 gopobj->mode.max_mode = 1;
457 gopobj->mode.info = &gopobj->info;
458 gopobj->mode.info_size = sizeof(gopobj->info);
Alexander Grafbe8d3242016-03-15 18:38:21 +0100459
Alexander Graf8f661a52016-06-07 00:57:05 +0200460#ifdef CONFIG_DM_VIDEO
Heinrich Schuchardt80ea9b02018-03-03 15:28:55 +0100461 if (bpix == VIDEO_BPP32)
Alexander Graf8f661a52016-06-07 00:57:05 +0200462#else
Heinrich Schuchardt80ea9b02018-03-03 15:28:55 +0100463 if (bpix == LCD_COLOR32)
Alexander Graf8f661a52016-06-07 00:57:05 +0200464#endif
Heinrich Schuchardt80ea9b02018-03-03 15:28:55 +0100465 {
Alexander Graf8f661a52016-06-07 00:57:05 +0200466 /* With 32bit color space we can directly expose the fb */
467 gopobj->mode.fb_base = fb_base;
468 gopobj->mode.fb_size = fb_size;
469 }
470
Alexander Grafbe8d3242016-03-15 18:38:21 +0100471 gopobj->info.version = 0;
Alexander Grafa8122412016-06-05 22:34:31 +0200472 gopobj->info.width = col;
473 gopobj->info.height = row;
Alexander Graf6fc2c702018-06-19 13:34:54 +0200474 gopobj->info.pixel_format = EFI_GOT_BGRA8;
Alexander Grafa8122412016-06-05 22:34:31 +0200475 gopobj->info.pixels_per_scanline = col;
476
477 gopobj->bpix = bpix;
Rob Clarkca9193d2017-07-21 15:00:27 -0400478 gopobj->fb = fb;
Alexander Grafbe8d3242016-03-15 18:38:21 +0100479
Heinrich Schuchardt80ea9b02018-03-03 15:28:55 +0100480 return EFI_SUCCESS;
Alexander Grafbe8d3242016-03-15 18:38:21 +0100481}