drivers/video/aperture.c
Source file repositories/reference/linux-study-clean/drivers/video/aperture.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/video/aperture.c- Extension
.c- Size
- 11815 bytes
- Lines
- 375
- Domain
- Driver Families
- Bucket
- drivers/video
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/aperture.hlinux/device.hlinux/list.hlinux/mutex.hlinux/pci.hlinux/platform_device.hlinux/slab.hlinux/sysfb.hlinux/types.hlinux/vgaarb.hvideo/vga.h
Detected Declarations
struct aperture_rangefunction overlapfunction devm_aperture_acquire_releasefunction devm_aperture_acquirefunction list_for_eachfunction aperture_detach_platform_devicefunction remove_conflicting_devicesfunction aperture_detach_devicesfunction list_for_each_safefunction aperture_remove_conflicting_devicesfunction aperture_remove_conflicting_pci_devicesfunction aperture_remove_conflicting_pci_devicesexport devm_aperture_acquire_for_platform_deviceexport aperture_remove_conflicting_devicesexport __aperture_remove_legacy_vga_devicesexport aperture_remove_conflicting_pci_devices
Annotated Snippet
struct aperture_range {
struct device *dev;
resource_size_t base;
resource_size_t size;
struct list_head lh;
void (*detach)(struct device *dev);
};
static LIST_HEAD(apertures);
static DEFINE_MUTEX(apertures_lock);
static bool overlap(resource_size_t base1, resource_size_t end1,
resource_size_t base2, resource_size_t end2)
{
return (base1 < end2) && (end1 > base2);
}
static void devm_aperture_acquire_release(void *data)
{
struct aperture_range *ap = data;
bool detached = !ap->dev;
if (detached)
return;
mutex_lock(&apertures_lock);
list_del(&ap->lh);
mutex_unlock(&apertures_lock);
}
static int devm_aperture_acquire(struct device *dev,
resource_size_t base, resource_size_t size,
void (*detach)(struct device *))
{
size_t end = base + size;
struct list_head *pos;
struct aperture_range *ap;
mutex_lock(&apertures_lock);
list_for_each(pos, &apertures) {
ap = container_of(pos, struct aperture_range, lh);
if (overlap(base, end, ap->base, ap->base + ap->size)) {
mutex_unlock(&apertures_lock);
return -EBUSY;
}
}
ap = devm_kzalloc(dev, sizeof(*ap), GFP_KERNEL);
if (!ap) {
mutex_unlock(&apertures_lock);
return -ENOMEM;
}
ap->dev = dev;
ap->base = base;
ap->size = size;
ap->detach = detach;
INIT_LIST_HEAD(&ap->lh);
list_add(&ap->lh, &apertures);
mutex_unlock(&apertures_lock);
return devm_add_action_or_reset(dev, devm_aperture_acquire_release, ap);
}
static void aperture_detach_platform_device(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
/*
* Remove the device from the device hierarchy. This is the right thing
* to do for firmware-based fb drivers, such as EFI, VESA or VGA. After
* the new driver takes over the hardware, the firmware device's state
* will be lost.
*
* For non-platform devices, a new callback would be required.
*
* If the aperture helpers ever need to handle native drivers, this call
* would only have to unplug the DRM device, so that the hardware device
* stays around after detachment.
*/
platform_device_unregister(pdev);
}
/**
* devm_aperture_acquire_for_platform_device - Acquires ownership of an aperture
* on behalf of a platform device.
* @pdev: the platform device to own the aperture
Annotation
- Immediate include surface: `linux/aperture.h`, `linux/device.h`, `linux/list.h`, `linux/mutex.h`, `linux/pci.h`, `linux/platform_device.h`, `linux/slab.h`, `linux/sysfb.h`.
- Detected declarations: `struct aperture_range`, `function overlap`, `function devm_aperture_acquire_release`, `function devm_aperture_acquire`, `function list_for_each`, `function aperture_detach_platform_device`, `function remove_conflicting_devices`, `function aperture_detach_devices`, `function list_for_each_safe`, `function aperture_remove_conflicting_devices`.
- Atlas domain: Driver Families / drivers/video.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.