2018-06-12 15:36:22 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
|
|
|
|
*
|
|
|
|
* EFI framebuffer driver based on GOP
|
|
|
|
*/
|
|
|
|
|
2023-03-10 20:47:13 +00:00
|
|
|
#define LOG_CATEGORY LOGC_EFI
|
|
|
|
|
2018-06-12 15:36:22 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <efi_api.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2022-07-30 21:52:04 +00:00
|
|
|
#include <vesa.h>
|
2018-06-12 15:36:22 +00:00
|
|
|
#include <video.h>
|
|
|
|
|
|
|
|
struct pixel {
|
|
|
|
u8 pos;
|
|
|
|
u8 size;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct efi_framebuffer {
|
|
|
|
struct pixel red;
|
|
|
|
struct pixel green;
|
|
|
|
struct pixel blue;
|
|
|
|
struct pixel rsvd;
|
|
|
|
} efi_framebuffer_format_map[] = {
|
|
|
|
[EFI_GOT_RGBA8] = { {0, 8}, {8, 8}, {16, 8}, {24, 8} },
|
|
|
|
[EFI_GOT_BGRA8] = { {16, 8}, {8, 8}, {0, 8}, {24, 8} },
|
|
|
|
};
|
|
|
|
|
|
|
|
static void efi_find_pixel_bits(u32 mask, u8 *pos, u8 *size)
|
|
|
|
{
|
|
|
|
u8 first, len;
|
|
|
|
|
|
|
|
first = 0;
|
|
|
|
len = 0;
|
|
|
|
|
|
|
|
if (mask) {
|
|
|
|
while (!(mask & 0x1)) {
|
|
|
|
mask = mask >> 1;
|
|
|
|
first++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (mask & 0x1) {
|
|
|
|
mask = mask >> 1;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*pos = first;
|
|
|
|
*size = len;
|
|
|
|
}
|
|
|
|
|
2023-03-10 20:47:11 +00:00
|
|
|
/**
|
|
|
|
* get_mode_info() - Ask EFI for the mode information
|
|
|
|
*
|
|
|
|
* Gets info from the graphics-output protocol
|
|
|
|
*
|
|
|
|
* @vesa: Place to put the mode information
|
2023-03-10 20:47:13 +00:00
|
|
|
* @fbp: Returns the address of the frame buffer
|
2023-03-10 20:47:12 +00:00
|
|
|
* @infop: Returns a pointer to the mode info
|
2023-03-10 20:47:11 +00:00
|
|
|
* Returns: 0 if OK, -ENOSYS if boot services are not available, -ENOTSUPP if
|
|
|
|
* the protocol is not supported by EFI
|
|
|
|
*/
|
2023-03-10 20:47:13 +00:00
|
|
|
static int get_mode_info(struct vesa_mode_info *vesa, u64 *fbp,
|
2023-03-10 20:47:12 +00:00
|
|
|
struct efi_gop_mode_info **infop)
|
2021-11-04 03:09:10 +00:00
|
|
|
{
|
|
|
|
efi_guid_t efi_gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
|
|
|
|
struct efi_boot_services *boot = efi_get_boot();
|
|
|
|
struct efi_gop_mode *mode;
|
|
|
|
struct efi_gop *gop;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!boot)
|
|
|
|
return log_msg_ret("sys", -ENOSYS);
|
|
|
|
ret = boot->locate_protocol(&efi_gop_guid, NULL, (void **)&gop);
|
|
|
|
if (ret)
|
|
|
|
return log_msg_ret("prot", -ENOTSUPP);
|
|
|
|
mode = gop->mode;
|
2023-03-10 20:47:13 +00:00
|
|
|
log_debug("maxmode %u, mode %u, info %p, size %lx, fb %lx, fb_size %lx\n",
|
|
|
|
mode->max_mode, mode->mode, mode->info, mode->info_size,
|
|
|
|
(ulong)mode->fb_base, (ulong)mode->fb_size);
|
|
|
|
|
2021-11-04 03:09:10 +00:00
|
|
|
vesa->phys_base_ptr = mode->fb_base;
|
2023-03-10 20:47:13 +00:00
|
|
|
*fbp = mode->fb_base;
|
2021-11-04 03:09:10 +00:00
|
|
|
vesa->x_resolution = mode->info->width;
|
|
|
|
vesa->y_resolution = mode->info->height;
|
2023-03-10 20:47:12 +00:00
|
|
|
*infop = mode->info;
|
2021-11-04 03:09:10 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-03-10 20:47:11 +00:00
|
|
|
/**
|
|
|
|
* get_mode_from_entry() - Obtain fb info from the EFIET_GOP_MODE payload entry
|
|
|
|
*
|
|
|
|
* This gets the mode information provided by the stub to the payload and puts
|
|
|
|
* it into a vesa structure. It also returns the mode information.
|
|
|
|
*
|
|
|
|
* @vesa: Place to put the mode information
|
2023-03-10 20:47:13 +00:00
|
|
|
* @fbp: Returns the address of the frame buffer
|
2023-03-10 20:47:11 +00:00
|
|
|
* @infop: Returns a pointer to the mode info
|
|
|
|
* Returns: 0 if OK, -ve on error
|
|
|
|
*/
|
2023-03-10 20:47:13 +00:00
|
|
|
static int get_mode_from_entry(struct vesa_mode_info *vesa, u64 *fbp,
|
2023-03-10 20:47:11 +00:00
|
|
|
struct efi_gop_mode_info **infop)
|
|
|
|
{
|
|
|
|
struct efi_gop_mode *mode;
|
|
|
|
int size;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = efi_info_get(EFIET_GOP_MODE, (void **)&mode, &size);
|
|
|
|
if (ret) {
|
|
|
|
printf("EFI graphics output entry not found\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
vesa->phys_base_ptr = mode->fb_base;
|
2023-03-10 20:47:13 +00:00
|
|
|
*fbp = mode->fb_base;
|
2023-03-10 20:47:11 +00:00
|
|
|
vesa->x_resolution = mode->info->width;
|
|
|
|
vesa->y_resolution = mode->info->height;
|
|
|
|
*infop = mode->info;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-03-10 20:47:13 +00:00
|
|
|
static int save_vesa_mode(struct vesa_mode_info *vesa, u64 *fbp)
|
2018-06-12 15:36:22 +00:00
|
|
|
{
|
|
|
|
const struct efi_framebuffer *fbinfo;
|
2023-03-10 20:47:11 +00:00
|
|
|
struct efi_gop_mode_info *info;
|
2018-06-12 15:36:22 +00:00
|
|
|
int ret;
|
|
|
|
|
2023-03-10 20:47:11 +00:00
|
|
|
if (IS_ENABLED(CONFIG_EFI_APP))
|
2023-03-10 20:47:13 +00:00
|
|
|
ret = get_mode_info(vesa, fbp, &info);
|
2023-03-10 20:47:11 +00:00
|
|
|
else
|
2023-03-10 20:47:13 +00:00
|
|
|
ret = get_mode_from_entry(vesa, fbp, &info);
|
2023-03-10 20:47:11 +00:00
|
|
|
if (ret) {
|
|
|
|
printf("EFI graphics output protocol not found (err=%dE)\n",
|
|
|
|
ret);
|
|
|
|
return ret;
|
2018-06-12 15:36:22 +00:00
|
|
|
}
|
|
|
|
|
2023-03-10 20:47:11 +00:00
|
|
|
if (info->pixel_format < EFI_GOT_BITMASK) {
|
|
|
|
fbinfo = &efi_framebuffer_format_map[info->pixel_format];
|
2018-06-12 15:36:22 +00:00
|
|
|
vesa->red_mask_size = fbinfo->red.size;
|
|
|
|
vesa->red_mask_pos = fbinfo->red.pos;
|
|
|
|
vesa->green_mask_size = fbinfo->green.size;
|
|
|
|
vesa->green_mask_pos = fbinfo->green.pos;
|
|
|
|
vesa->blue_mask_size = fbinfo->blue.size;
|
|
|
|
vesa->blue_mask_pos = fbinfo->blue.pos;
|
|
|
|
vesa->reserved_mask_size = fbinfo->rsvd.size;
|
|
|
|
vesa->reserved_mask_pos = fbinfo->rsvd.pos;
|
|
|
|
|
|
|
|
vesa->bits_per_pixel = 32;
|
2023-03-10 20:47:11 +00:00
|
|
|
vesa->bytes_per_scanline = info->pixels_per_scanline * 4;
|
|
|
|
} else if (info->pixel_format == EFI_GOT_BITMASK) {
|
|
|
|
efi_find_pixel_bits(info->pixel_bitmask[0],
|
2018-06-12 15:36:22 +00:00
|
|
|
&vesa->red_mask_pos,
|
|
|
|
&vesa->red_mask_size);
|
2023-03-10 20:47:11 +00:00
|
|
|
efi_find_pixel_bits(info->pixel_bitmask[1],
|
2018-06-12 15:36:22 +00:00
|
|
|
&vesa->green_mask_pos,
|
|
|
|
&vesa->green_mask_size);
|
2023-03-10 20:47:11 +00:00
|
|
|
efi_find_pixel_bits(info->pixel_bitmask[2],
|
2018-06-12 15:36:22 +00:00
|
|
|
&vesa->blue_mask_pos,
|
|
|
|
&vesa->blue_mask_size);
|
2023-03-10 20:47:11 +00:00
|
|
|
efi_find_pixel_bits(info->pixel_bitmask[3],
|
2018-06-12 15:36:22 +00:00
|
|
|
&vesa->reserved_mask_pos,
|
|
|
|
&vesa->reserved_mask_size);
|
|
|
|
vesa->bits_per_pixel = vesa->red_mask_size +
|
|
|
|
vesa->green_mask_size +
|
|
|
|
vesa->blue_mask_size +
|
|
|
|
vesa->reserved_mask_size;
|
2023-03-10 20:47:11 +00:00
|
|
|
vesa->bytes_per_scanline = (info->pixels_per_scanline *
|
2018-06-12 15:36:22 +00:00
|
|
|
vesa->bits_per_pixel) / 8;
|
|
|
|
} else {
|
2023-03-10 20:47:13 +00:00
|
|
|
log_err("Unknown framebuffer format: %d\n", info->pixel_format);
|
2018-06-12 15:36:22 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int efi_video_probe(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct video_uc_plat *plat = dev_get_uclass_plat(dev);
|
2018-06-12 15:36:22 +00:00
|
|
|
struct video_priv *uc_priv = dev_get_uclass_priv(dev);
|
|
|
|
struct vesa_mode_info *vesa = &mode_info.vesa;
|
2023-03-10 20:47:13 +00:00
|
|
|
u64 fb;
|
2018-06-12 15:36:22 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Initialize vesa_mode_info structure */
|
2023-03-10 20:47:13 +00:00
|
|
|
ret = save_vesa_mode(vesa, &fb);
|
2018-06-12 15:36:22 +00:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
2023-03-10 20:47:13 +00:00
|
|
|
ret = vesa_setup_video_priv(vesa, fb, uc_priv, plat);
|
2018-06-12 15:36:22 +00:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
2023-03-10 20:47:13 +00:00
|
|
|
printf("Video: %dx%dx%d @ %lx\n", uc_priv->xsize, uc_priv->ysize,
|
|
|
|
vesa->bits_per_pixel, (ulong)fb);
|
2018-06-12 15:36:22 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
printf("No video mode configured in EFI!\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-03-10 20:47:16 +00:00
|
|
|
static int efi_video_bind(struct udevice *dev)
|
|
|
|
{
|
|
|
|
if (IS_ENABLED(CONFIG_VIDEO_COPY)) {
|
|
|
|
struct video_uc_plat *plat = dev_get_uclass_plat(dev);
|
|
|
|
struct vesa_mode_info vesa;
|
|
|
|
int ret;
|
|
|
|
u64 fb;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialise vesa_mode_info structure so we can figure out the
|
|
|
|
* required framebuffer size. If something goes wrong, just do
|
|
|
|
* without a copy framebuffer
|
|
|
|
*/
|
|
|
|
ret = save_vesa_mode(&vesa, &fb);
|
|
|
|
if (!ret) {
|
|
|
|
/* this is not reached if the EFI call failed */
|
|
|
|
plat->copy_size = vesa.bytes_per_scanline *
|
|
|
|
vesa.y_resolution;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-06-12 15:36:22 +00:00
|
|
|
static const struct udevice_id efi_video_ids[] = {
|
|
|
|
{ .compatible = "efi-fb" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(efi_video) = {
|
|
|
|
.name = "efi_video",
|
|
|
|
.id = UCLASS_VIDEO,
|
|
|
|
.of_match = efi_video_ids,
|
2023-03-10 20:47:16 +00:00
|
|
|
.bind = efi_video_bind,
|
2018-06-12 15:36:22 +00:00
|
|
|
.probe = efi_video_probe,
|
|
|
|
};
|