1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
5 * EFI framebuffer driver based on GOP
20 static const struct efi_framebuffer {
25 } efi_framebuffer_format_map[] = {
26 [EFI_GOT_RGBA8] = { {0, 8}, {8, 8}, {16, 8}, {24, 8} },
27 [EFI_GOT_BGRA8] = { {16, 8}, {8, 8}, {0, 8}, {24, 8} },
30 static void efi_find_pixel_bits(u32 mask, u8 *pos, u8 *size)
38 while (!(mask & 0x1)) {
53 static int get_mode_info(struct vesa_mode_info *vesa)
55 efi_guid_t efi_gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
56 struct efi_boot_services *boot = efi_get_boot();
57 struct efi_gop_mode *mode;
62 return log_msg_ret("sys", -ENOSYS);
63 ret = boot->locate_protocol(&efi_gop_guid, NULL, (void **)&gop);
65 return log_msg_ret("prot", -ENOTSUPP);
68 vesa->phys_base_ptr = mode->fb_base;
69 vesa->x_resolution = mode->info->width;
70 vesa->y_resolution = mode->info->height;
75 static int save_vesa_mode(struct vesa_mode_info *vesa)
77 struct efi_entry_gopmode *mode;
78 const struct efi_framebuffer *fbinfo;
82 if (IS_ENABLED(CONFIG_EFI_APP)) {
83 ret = get_mode_info(vesa);
85 printf("EFI graphics output protocol not found\n");
89 ret = efi_info_get(EFIET_GOP_MODE, (void **)&mode, &size);
91 printf("EFI graphics output protocol mode not found\n");
94 vesa->phys_base_ptr = mode->fb_base;
95 vesa->x_resolution = mode->info->width;
96 vesa->y_resolution = mode->info->height;
99 if (mode->info->pixel_format < EFI_GOT_BITMASK) {
100 fbinfo = &efi_framebuffer_format_map[mode->info->pixel_format];
101 vesa->red_mask_size = fbinfo->red.size;
102 vesa->red_mask_pos = fbinfo->red.pos;
103 vesa->green_mask_size = fbinfo->green.size;
104 vesa->green_mask_pos = fbinfo->green.pos;
105 vesa->blue_mask_size = fbinfo->blue.size;
106 vesa->blue_mask_pos = fbinfo->blue.pos;
107 vesa->reserved_mask_size = fbinfo->rsvd.size;
108 vesa->reserved_mask_pos = fbinfo->rsvd.pos;
110 vesa->bits_per_pixel = 32;
111 vesa->bytes_per_scanline = mode->info->pixels_per_scanline * 4;
112 } else if (mode->info->pixel_format == EFI_GOT_BITMASK) {
113 efi_find_pixel_bits(mode->info->pixel_bitmask[0],
115 &vesa->red_mask_size);
116 efi_find_pixel_bits(mode->info->pixel_bitmask[1],
117 &vesa->green_mask_pos,
118 &vesa->green_mask_size);
119 efi_find_pixel_bits(mode->info->pixel_bitmask[2],
120 &vesa->blue_mask_pos,
121 &vesa->blue_mask_size);
122 efi_find_pixel_bits(mode->info->pixel_bitmask[3],
123 &vesa->reserved_mask_pos,
124 &vesa->reserved_mask_size);
125 vesa->bits_per_pixel = vesa->red_mask_size +
126 vesa->green_mask_size +
127 vesa->blue_mask_size +
128 vesa->reserved_mask_size;
129 vesa->bytes_per_scanline = (mode->info->pixels_per_scanline *
130 vesa->bits_per_pixel) / 8;
132 debug("efi set unknown framebuffer format: %d\n",
133 mode->info->pixel_format);
140 static int efi_video_probe(struct udevice *dev)
142 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
143 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
144 struct vesa_mode_info *vesa = &mode_info.vesa;
147 /* Initialize vesa_mode_info structure */
148 ret = save_vesa_mode(vesa);
152 ret = vbe_setup_video_priv(vesa, uc_priv, plat);
156 printf("Video: %dx%dx%d\n", uc_priv->xsize, uc_priv->ysize,
157 vesa->bits_per_pixel);
162 printf("No video mode configured in EFI!\n");
166 static const struct udevice_id efi_video_ids[] = {
167 { .compatible = "efi-fb" },
171 U_BOOT_DRIVER(efi_video) = {
174 .of_match = efi_video_ids,
175 .probe = efi_video_probe,