UEFI GOP Resolution Switching and Frame Buffers
The Unified Extensible Firmware Interface (UEFI) relies on the Graphics Output Protocol (GOP) to manage pre-boot display capabilities, replacing legacy BIOS INT 10h video services. GOP provides an architecture-independent interface that enables firmware and bootloaders to query display capabilities, switch display modes, and manage linear frame buffer allocations. This article details the mechanics of how GOP enumerates modes, executes resolution switches, allocates and structures linear frame buffers, and prepares the graphical handoff to the operating system.
Understanding the Graphics Output Protocol
The EFI_GRAPHICS_OUTPUT_PROTOCOL (GOP) is an interface
exposed by UEFI video drivers to provide basic 2D display functionality.
Unlike complex runtime graphics drivers, GOP is designed to be
lightweight, deterministic, and hardware-agnostic. It abstracts the
underlying display controller hardware while exposing two primary
mechanisms for displaying imagery: direct memory access to a flat,
linear frame buffer and software-driven block transfers through the
Blt (Block Transfer) function.
Resolution Enumeration and Switching
Display resolution management in GOP is structured around mode indices, configuration structures, and explicit protocol functions.
Mode Enumeration (
QueryMode): Before a resolution switch occurs, the firmware or bootloader must determine what display modes the hardware supports. GOP achieves this via theQueryMode()interface:EFI_STATUS QueryMode ( IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This, IN UINT32 ModeNumber, OUT UINTN *SizeOfInfo, OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info );Iterating from
0toMode->MaxMode - 1populates anEFI_GRAPHICS_OUTPUT_MODE_INFORMATIONstructure for each index. This structure defines:- HorizontalResolution and VerticalResolution: The visible pixel dimensions (e.g., 1920x1080).
- PixelFormat: The color ordering (e.g.,
PixelBlueGreenRedReserved8BitPerColor,PixelRedGreenBlueReserved8BitPerColor, orPixelBitMask). - PixelsPerScanLine: The stride or pitch of the buffer, which accounts for hardware memory alignment requirements that may exceed the horizontal resolution.
Mode Switching (
SetMode): To change the resolution, the consumer invokesSetMode():EFI_STATUS SetMode ( IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This, IN UINT32 ModeNumber );When
SetMode()is called, the underlying driver interacts directly with the GPU or display controller hardware:- It reprograms internal pixel clocks, phase-locked loops (PLLs), and timing controllers (CRTCs) to match the timing parameters (front porch, back porch, sync pulses) of the requested resolution.
- It updates the active display plane configurations to scale or center the image as required by the panel.
- It updates the global
EFI_GRAPHICS_OUTPUT_PROTOCOL_MODEstructure to reflect the new geometry and hardware addresses.
Frame Buffer Allocation and Management
The GOP frame buffer is a contiguous block of physical memory mapped directly to the display hardware.
Allocation Mechanism
GOP does not use standard heap allocations (such as
AllocatePool) for the active display surface. Instead, the
frame buffer is generally backed by one of two memory models:
- Discrete GPUs: The frame buffer resides within the video memory (VRAM) mapped into the CPU's physical address space through a PCI Base Address Register (BAR). The UEFI driver configures this MMIO (Memory-Mapped I/O) aperture during PCI bus enumeration.
- Integrated Graphics Processors (iGPUs): The system firmware reserves a slice of host system RAM—often referred to as Stolen Memory or Unified Memory Architecture (UMA)—configured via system registers early in the platform initialization (PEI) phase.
Memory Mapping and Attributes
The pointer to this space is exposed directly to consumers via
This->Mode->FrameBufferBase, typed as an
EFI_PHYSICAL_ADDRESS, along with
This->Mode->FrameBufferSize.
To maximize performance, this range is typically mapped with a Write-Combining (WC) or Uncacheable (UC) memory attribute in the CPU page tables or Memory Type Range Registers (MTRRs). Write-combining allows the CPU to coalesce sequential writes to the frame buffer into full cache-line bursts, mitigating memory bus bottlenecks without requiring the overhead of standard CPU cache coherency protocols.
Frame Buffer Invalidation During Resolution Switching
A critical architectural behavior of GOP is that the frame buffer
address and layout are not guaranteed to remain static across resolution
changes. When SetMode() executes:
- The base address (
FrameBufferBase) may change if the GPU hardware driver uses distinct internal memory segments for different display pipelines or modes. - The buffer size (
FrameBufferSize) increases or decreases according to the new vertical resolution andPixelsPerScanLine. - Any existing content inside the frame buffer is considered invalidated or undefined; hardware may wipe the buffer or map a new offset entirely.
Because of this behavior, bootloaders and UEFI applications must
never cache the FrameBufferBase address across calls to
SetMode(). The active base pointer must always be re-read
from This->Mode immediately following a mode switch.
Direct Frame Buffer Writing vs. Blt Operations
UEFI GOP supports two methods for modifying screen content:
- Direct Linear Access: Software writes directly to
FrameBufferBaseusing pointer arithmetic based on thePixelsPerScanLinestride: \[\text{Pixel Offset} = (Y \times \text{PixelsPerScanLine} + X) \times \text{BytesPerPixel}\] This is the fastest method for full-screen drawing and is typically used by modern OS bootloaders to render graphical splash screens. - Protocol-Driven Blt (
Blt): GOP includes aBlt()function to copy data to and from video hardware, perform screen-to-screen copies, and execute solid color fills. While convenient and guaranteed to work on hardware operating in restricted modes (such asPixelBltOnly), software-based direct writes generally supersedeBlt()due to the function call overhead associated with rendering complex interfaces.
OS Handoff and Transition
When the bootloader completes execution and calls
ExitBootServices(), GOP transitions out of scope. The UEFI
driver ceases execution, and all GOP protocol interfaces are destroyed.
However, the physical frame buffer hardware configuration established by
the final SetMode() invocation persists.
The bootloader packages the active FrameBufferBase,
dimensions, stride, and pixel format into boot parameter structures
(such as ACPI tables or kernel boot parameters like Linux's
screen_info). The operating system's kernel uses this
configuration to drive a flicker-free visual console until its own
native, accelerated GPU display drivers can be initialized.