Managing Ownership of the Framebuffer Aperture¶
A graphics device might be supported by different drivers, but only onedriver can be active at any given time. Many systems load a genericgraphics drivers, such as EFI-GOP or VESA, early during the boot process.During later boot stages, they replace the generic driver with a dedicated,hardware-specific driver. To take over the device, the dedicated driverfirst has to remove the generic driver. Aperture functions manageownership of framebuffer memory and hand-over between drivers.
Graphics drivers should callaperture_remove_conflicting_devices()at the top of their probe function. The function removes any genericdriver that is currently associated with the given framebuffer memory.An example for a graphics device on the platform bus is shown below.
staticintexample_probe(structplatform_device*pdev){structresource*mem;resource_size_tbase,size;intret;mem=platform_get_resource(pdev,IORESOURCE_MEM,0);if(!mem)return-ENODEV;base=mem->start;size=resource_size(mem);ret=aperture_remove_conflicting_devices(base,size,"example");if(ret)returnret;// Initialize the hardware...return0;}staticconststructplatform_driverexample_driver={.probe=example_probe,...};
The given example reads the platform device’s I/O-memory range from thedevice instance. An active framebuffer will be located within this range.The call toaperture_remove_conflicting_devices() releases drivers thathave previously claimed ownership of the range and are currently drivingoutput on the framebuffer. If successful, the new driver can take overthe device.
While the given example uses a platform device, the aperture helpers workwith every bus that has an addressable framebuffer. In the case of PCI,device drivers can also callaperture_remove_conflicting_pci_devices() andlet the function detect the apertures automatically. Device drivers withoutknowledge of the framebuffer’s location can callaperture_remove_all_conflicting_devices(), which removes all known devices.
Drivers that are susceptible to being removed by other drivers, such asgeneric EFI or VESA drivers, have to register themselves as owners of theirframebuffer apertures. Ownership of the framebuffer memory is achievedby callingdevm_aperture_acquire_for_platform_device(). If successful, thedriver is the owner of the framebuffer range. The function fails if theframebuffer is already owned by another driver. See below for an example.
staticintgeneric_probe(structplatform_device*pdev){structresource*mem;resource_size_tbase,size;mem=platform_get_resource(pdev,IORESOURCE_MEM,0);if(!mem)return-ENODEV;base=mem->start;size=resource_size(mem);ret=devm_aperture_acquire_for_platform_device(pdev,base,size);if(ret)returnret;// Initialize the hardware...return0;}staticintgeneric_remove(structplatform_device*){// Hot-unplug the device...return0;}staticconststructplatform_drivergeneric_driver={.probe=generic_probe,.remove=generic_remove,...};
The similar to the previous example, the generic driver claims ownershipof the framebuffer memory from its probe function. This will fail if thememory range, or parts of it, is already owned by another driver.
If successful, the generic driver is now subject to forced removal byanother driver. This only works for platform drivers that support hotunplugging. When a driver callsaperture_remove_conflicting_devices()et al for the registered framebuffer range, the aperture helpers callplatform_device_unregister() and the generic driver unloads itself. Thegeneric driver also has to provide a remove function to make this work.Once hot unplugged from hardware, it may not access the device’sregisters, framebuffer memory, ROM, etc afterwards.
- intaperture_remove_all_conflicting_devices(constchar*name)¶
remove all existing framebuffers
Parameters
constchar*namea descriptive name of the requesting driver
Description
This function removes all graphics device drivers. Use this function on systemsthat can have their framebuffer located anywhere in memory.
Return
0 on success, or a negative errno code otherwise
- intdevm_aperture_acquire_for_platform_device(structplatform_device*pdev,resource_size_tbase,resource_size_tsize)¶
Acquires ownership of an aperture on behalf of a platform device.
Parameters
structplatform_device*pdevthe platform device to own the aperture
resource_size_tbasethe aperture’s byte offset in physical memory
resource_size_tsizethe aperture size in bytes
Description
Installs the given device as the new owner of the aperture. The functionexpects the aperture to be provided by a platform device. If anotherdriver takes over ownership of the aperture, aperture helpers will thenunregister the platform device automatically. All acquired apertures arereleased automatically when the underlying device goes away.
The function fails if the aperture, or parts of it, is currentlyowned by another device. To evict current owners, callers should useremove_conflicting_devices() et al. before calling this function.
Return
0 on success, or a negative errno value otherwise.
- intaperture_remove_conflicting_devices(resource_size_tbase,resource_size_tsize,constchar*name)¶
remove devices in the given range
Parameters
resource_size_tbasethe aperture’s base address in physical memory
resource_size_tsizeaperture size in bytes
constchar*namea descriptive name of the requesting driver
Description
This function removes devices that own apertures withinbase andsize.
Return
0 on success, or a negative errno code otherwise
- int__aperture_remove_legacy_vga_devices(structpci_dev*pdev)¶
remove legacy VGA devices of a PCI devices
Parameters
structpci_dev*pdevPCI device
Description
This function removes VGA devices provided bypdev, such as a VGAframebuffer or a console. This is useful if you have a VGA-compatiblePCI graphics device with framebuffers in non-BAR locations. Driversshould acquire ownership of those memory areas and afterwards callthis helper to release remaining VGA devices.
If your hardware has its framebuffers accessible via PCI BARS, useaperture_remove_conflicting_pci_devices() instead. The function willrelease any VGA devices automatically.
- WARNING: Apparently we must remove graphics drivers before calling
this helper. Otherwise the vga fbdev driver falls over ifwe have vgacon configured.
Return
0 on success, or a negative errno code otherwise
- intaperture_remove_conflicting_pci_devices(structpci_dev*pdev,constchar*name)¶
remove existing framebuffers for PCI devices
Parameters
structpci_dev*pdevPCI device
constchar*namea descriptive name of the requesting driver
Description
This function removes devices that own apertures within any ofpdev’smemory bars. The function assumes that PCI device with shadowed ROMdrives a primary display and therefore kicks out vga16fb as well.
Return
0 on success, or a negative errno code otherwise