1 // SPDX-License-Identifier: GPL-2.0+
5 * EFI framebuffer driver based on GOP
8 #define LOG_CATEGORY LOGC_EFI
22 static const struct efi_framebuffer {
27 } efi_framebuffer_format_map[] = {
28 [EFI_GOT_RGBA8] = { {0, 8}, {8, 8}, {16, 8}, {24, 8} },
29 [EFI_GOT_BGRA8] = { {16, 8}, {8, 8}, {0, 8}, {24, 8} },
32 static void efi_find_pixel_bits(u32 mask, u8 *pos, u8 *size)
40 while (!(mask & 0x1)) {
56 * get_mode_info() - Ask EFI for the mode information
58 * Gets info from the graphics-output protocol
60 * @vesa: Place to put the mode information
61 * @fbp: Returns the address of the frame buffer
62 * @infop: Returns a pointer to the mode info
63 * Returns: 0 if OK, -ENOSYS if boot services are not available, -ENOTSUPP if
64 * the protocol is not supported by EFI
66 static int get_mode_info(struct vesa_mode_info *vesa, u64 *fbp,
67 struct efi_gop_mode_info **infop)
69 efi_guid_t efi_gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
70 struct efi_boot_services *boot = efi_get_boot();
71 struct efi_gop_mode *mode;
76 return log_msg_ret("sys", -ENOSYS);
77 ret = boot->locate_protocol(&efi_gop_guid, NULL, (void **)&gop);
79 return log_msg_ret("prot", -ENOTSUPP);
81 log_debug("maxmode %u, mode %u, info %p, size %lx, fb %lx, fb_size %lx\n",
82 mode->max_mode, mode->mode, mode->info, mode->info_size,
83 (ulong)mode->fb_base, (ulong)mode->fb_size);
85 vesa->phys_base_ptr = mode->fb_base;
87 vesa->x_resolution = mode->info->width;
88 vesa->y_resolution = mode->info->height;
95 * get_mode_from_entry() - Obtain fb info from the EFIET_GOP_MODE payload entry
97 * This gets the mode information provided by the stub to the payload and puts
98 * it into a vesa structure. It also returns the mode information.
100 * @vesa: Place to put the mode information
101 * @fbp: Returns the address of the frame buffer
102 * @infop: Returns a pointer to the mode info
103 * Returns: 0 if OK, -ve on error
105 static int get_mode_from_entry(struct vesa_mode_info *vesa, u64 *fbp,
106 struct efi_gop_mode_info **infop)
108 struct efi_gop_mode *mode;
112 ret = efi_info_get(EFIET_GOP_MODE, (void **)&mode, &size);
114 printf("EFI graphics output entry not found\n");
117 vesa->phys_base_ptr = mode->fb_base;
118 *fbp = mode->fb_base;
119 vesa->x_resolution = mode->info->width;
120 vesa->y_resolution = mode->info->height;
126 static int save_vesa_mode(struct vesa_mode_info *vesa, u64 *fbp)
128 const struct efi_framebuffer *fbinfo;
129 struct efi_gop_mode_info *info;
132 if (IS_ENABLED(CONFIG_EFI_APP))
133 ret = get_mode_info(vesa, fbp, &info);
135 ret = get_mode_from_entry(vesa, fbp, &info);
137 printf("EFI graphics output protocol not found (err=%dE)\n",
142 if (info->pixel_format < EFI_GOT_BITMASK) {
143 fbinfo = &efi_framebuffer_format_map[info->pixel_format];
144 vesa->red_mask_size = fbinfo->red.size;
145 vesa->red_mask_pos = fbinfo->red.pos;
146 vesa->green_mask_size = fbinfo->green.size;
147 vesa->green_mask_pos = fbinfo->green.pos;
148 vesa->blue_mask_size = fbinfo->blue.size;
149 vesa->blue_mask_pos = fbinfo->blue.pos;
150 vesa->reserved_mask_size = fbinfo->rsvd.size;
151 vesa->reserved_mask_pos = fbinfo->rsvd.pos;
153 vesa->bits_per_pixel = 32;
154 vesa->bytes_per_scanline = info->pixels_per_scanline * 4;
155 } else if (info->pixel_format == EFI_GOT_BITMASK) {
156 efi_find_pixel_bits(info->pixel_bitmask[0],
158 &vesa->red_mask_size);
159 efi_find_pixel_bits(info->pixel_bitmask[1],
160 &vesa->green_mask_pos,
161 &vesa->green_mask_size);
162 efi_find_pixel_bits(info->pixel_bitmask[2],
163 &vesa->blue_mask_pos,
164 &vesa->blue_mask_size);
165 efi_find_pixel_bits(info->pixel_bitmask[3],
166 &vesa->reserved_mask_pos,
167 &vesa->reserved_mask_size);
168 vesa->bits_per_pixel = vesa->red_mask_size +
169 vesa->green_mask_size +
170 vesa->blue_mask_size +
171 vesa->reserved_mask_size;
172 vesa->bytes_per_scanline = (info->pixels_per_scanline *
173 vesa->bits_per_pixel) / 8;
175 log_err("Unknown framebuffer format: %d\n", info->pixel_format);
182 static int efi_video_probe(struct udevice *dev)
184 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
185 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
186 struct vesa_mode_info *vesa = &mode_info.vesa;
190 /* Initialize vesa_mode_info structure */
191 ret = save_vesa_mode(vesa, &fb);
195 ret = vesa_setup_video_priv(vesa, fb, uc_priv, plat);
199 printf("Video: %dx%dx%d @ %lx\n", uc_priv->xsize, uc_priv->ysize,
200 vesa->bits_per_pixel, (ulong)fb);
205 printf("No video mode configured in EFI!\n");
209 static int efi_video_bind(struct udevice *dev)
211 if (IS_ENABLED(CONFIG_VIDEO_COPY)) {
212 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
213 struct vesa_mode_info vesa;
218 * Initialise vesa_mode_info structure so we can figure out the
219 * required framebuffer size. If something goes wrong, just do
220 * without a copy framebuffer
222 ret = save_vesa_mode(&vesa, &fb);
224 /* this is not reached if the EFI call failed */
225 plat->copy_size = vesa.bytes_per_scanline *
233 static const struct udevice_id efi_video_ids[] = {
234 { .compatible = "efi-fb" },
238 U_BOOT_DRIVER(efi_video) = {
241 .of_match = efi_video_ids,
242 .bind = efi_video_bind,
243 .probe = efi_video_probe,