u-boot/drivers/video/vesa.c
Bin Meng bff002d45b video: vesa: Use mtrr_set_next_var() for graphics memory
At present this uses mtrr_add_request() & mtrr_commit() combination
to program the MTRR for graphics memory. This usage has two major
issues as below:

- mtrr_commit() will re-initialize all MTRR registers from index 0,
  using the settings previously added by mtrr_add_request() and saved
  in gd->arch.mtrr_req[], which won't cause any issue but is unnecessary
- The way such combination works is based on the assumption that U-Boot
  has full control with MTRR programming (e.g.: U-Boot without any blob
  that does all low-level initialization on its own, or using FSP2 which
  does not touch MTRR), but this is not the case with FSP. FSP programs
  some MTRRs during its execution but U-Boot does not have the settings
  saved in gd->arch.mtrr_req[] and when doing mtrr_commit() it will
  corrupt what was already programmed previously.

Correct this to use mtrr_set_next_var() instead.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-08-01 10:06:46 +08:00

60 lines
1.3 KiB
C

// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2016, Bin Meng <bmeng.cn@gmail.com>
*/
#include <common.h>
#include <dm.h>
#include <log.h>
#include <pci.h>
#include <vesa.h>
#include <video.h>
#include <asm/mtrr.h>
static int vesa_video_probe(struct udevice *dev)
{
struct video_uc_plat *plat = dev_get_uclass_plat(dev);
ulong fbbase;
int ret;
ret = vesa_setup_video(dev, NULL);
if (ret)
return log_ret(ret);
/* Use write-combining for the graphics memory, 256MB */
fbbase = IS_ENABLED(CONFIG_VIDEO_COPY) ? plat->copy_base : plat->base;
mtrr_set_next_var(MTRR_TYPE_WRCOMB, fbbase, 256 << 20);
return 0;
}
static int vesa_video_bind(struct udevice *dev)
{
struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
/* Set the maximum supported resolution */
uc_plat->size = 2560 * 1600 * 4;
log_debug("%s: Frame buffer size %x\n", __func__, uc_plat->size);
return 0;
}
static const struct udevice_id vesa_video_ids[] = {
{ .compatible = "vesa-fb" },
{ }
};
U_BOOT_DRIVER(vesa_video) = {
.name = "vesa_video",
.id = UCLASS_VIDEO,
.of_match = vesa_video_ids,
.bind = vesa_video_bind,
.probe = vesa_video_probe,
};
static struct pci_device_id vesa_video_supported[] = {
{ PCI_DEVICE_CLASS(PCI_CLASS_DISPLAY_VGA << 8, ~0) },
{ },
};
U_BOOT_PCI_DEVICE(vesa_video, vesa_video_supported);