drivers/gpu/drm/drm_lease.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/drm_lease.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/drm_lease.c- Extension
.c- Size
- 20043 bytes
- Lines
- 733
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/file.hlinux/uaccess.hdrm/drm_auth.hdrm/drm_crtc.hdrm/drm_drv.hdrm/drm_file.hdrm/drm_lease.hdrm/drm_print.hdrm_crtc_internal.hdrm_internal.h
Detected Declarations
function _drm_find_lesseefunction _drm_lease_held_masterfunction _drm_has_leasedfunction _drm_lease_heldfunction drm_lease_heldfunction drm_lease_filter_crtcsfunction ERR_PTRfunction idr_for_each_entryfunction drm_lease_destroyfunction _drm_lease_revokefunction drm_lease_revokefunction validate_leasefunction fill_object_idrfunction drm_mode_create_lease_ioctlfunction drm_mode_list_lessees_ioctlfunction drm_mode_get_lease_ioctlfunction drm_mode_revoke_lease_ioctl
Annotated Snippet
if (_drm_lease_held_master(master, crtc->base.id)) {
uint32_t mask_in = 1ul << count_in;
if ((crtcs_in & mask_in) != 0) {
uint32_t mask_out = 1ul << count_out;
crtcs_out |= mask_out;
}
count_out++;
}
count_in++;
}
mutex_unlock(&master->dev->mode_config.idr_mutex);
out:
drm_master_put(&master);
return crtcs_out;
}
/*
* Uses drm_master_create to allocate a new drm_master, then checks to
* make sure all of the desired objects can be leased, atomically
* leasing them to the new drmmaster.
*
* ERR_PTR(-EACCES) some other master holds the title to any object
* ERR_PTR(-ENOENT) some object is not a valid DRM object for this device
* ERR_PTR(-EBUSY) some other lessee holds title to this object
* ERR_PTR(-EEXIST) same object specified more than once in the provided list
* ERR_PTR(-ENOMEM) allocation failed
*/
static struct drm_master *drm_lease_create(struct drm_master *lessor, struct idr *leases)
{
struct drm_device *dev = lessor->dev;
int error;
struct drm_master *lessee;
int object;
int id;
void *entry;
drm_dbg_lease(dev, "lessor %d\n", lessor->lessee_id);
lessee = drm_master_create(lessor->dev);
if (!lessee) {
drm_dbg_lease(dev, "drm_master_create failed\n");
return ERR_PTR(-ENOMEM);
}
mutex_lock(&dev->mode_config.idr_mutex);
idr_for_each_entry(leases, entry, object) {
error = 0;
if (!idr_find(&dev->mode_config.object_idr, object))
error = -ENOENT;
else if (_drm_has_leased(lessor, object))
error = -EBUSY;
if (error != 0) {
drm_dbg_lease(dev, "object %d failed %d\n", object, error);
goto out_lessee;
}
}
/* Insert the new lessee into the tree */
id = idr_alloc(&(drm_lease_owner(lessor)->lessee_idr), lessee, 1, 0, GFP_KERNEL);
if (id < 0) {
error = id;
goto out_lessee;
}
lessee->lessee_id = id;
lessee->lessor = drm_master_get(lessor);
list_add_tail(&lessee->lessee_list, &lessor->lessees);
/* Move the leases over */
lessee->leases = *leases;
drm_dbg_lease(dev, "new lessee %d %p, lessor %d %p\n",
lessee->lessee_id, lessee, lessor->lessee_id, lessor);
mutex_unlock(&dev->mode_config.idr_mutex);
return lessee;
out_lessee:
mutex_unlock(&dev->mode_config.idr_mutex);
drm_master_put(&lessee);
return ERR_PTR(error);
}
void drm_lease_destroy(struct drm_master *master)
Annotation
- Immediate include surface: `linux/file.h`, `linux/uaccess.h`, `drm/drm_auth.h`, `drm/drm_crtc.h`, `drm/drm_drv.h`, `drm/drm_file.h`, `drm/drm_lease.h`, `drm/drm_print.h`.
- Detected declarations: `function _drm_find_lessee`, `function _drm_lease_held_master`, `function _drm_has_leased`, `function _drm_lease_held`, `function drm_lease_held`, `function drm_lease_filter_crtcs`, `function ERR_PTR`, `function idr_for_each_entry`, `function drm_lease_destroy`, `function _drm_lease_revoke`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.