drivers/gpu/drm/i915/i915_gem.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/i915/i915_gem.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/i915/i915_gem.c- Extension
.c- Size
- 35699 bytes
- Lines
- 1356
- 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/dma-fence-array.hlinux/kthread.hlinux/dma-resv.hlinux/shmem_fs.hlinux/slab.hlinux/stop_machine.hlinux/swap.hlinux/pci.hlinux/dma-buf.hlinux/mman.hdrm/drm_cache.hdrm/drm_print.hdrm/drm_vma_manager.hgem/i915_gem_clflush.hgem/i915_gem_context.hgem/i915_gem_ioctls.hgem/i915_gem_mman.hgem/i915_gem_object_frontbuffer.hgem/i915_gem_pm.hgem/i915_gem_region.hgt/intel_engine_user.hgt/intel_gt.hgt/intel_gt_pm.hgt/intel_workarounds.hi915_drv.hi915_file_private.hi915_trace.hi915_vgpu.hintel_clock_gating.hselftests/mock_gem_device.cselftests/i915_gem.c
Detected Declarations
function filesfunction remove_mappable_nodefunction i915_gem_get_aperture_ioctlfunction i915_gem_object_unbindfunction shmem_preadfunction i915_gem_shmem_preadfunction gtt_user_readfunction i915_gem_gtt_cleanupfunction i915_gem_gtt_preadfunction i915_gem_pread_ioctlfunction ggtt_writefunction i915_gem_gtt_pwrite_fastfunction shmem_pwritefunction i915_gem_shmem_pwritefunction i915_gem_pwrite_ioctlfunction i915_gem_sw_finish_ioctlfunction i915_gem_runtime_suspendfunction discard_ggtt_vmafunction i915_gem_object_ggtt_pin_wwfunction i915_gem_object_ggtt_pinfunction for_i915_gem_wwfunction i915_gem_madvise_ioctlfunction objectsfunction abovefunction i915_gem_initfunction for_each_gtfunction for_each_gtfunction i915_gem_driver_registerfunction i915_gem_driver_unregisterfunction i915_gem_driver_removefunction i915_gem_driver_releasefunction for_each_gtfunction i915_gem_init__mmfunction i915_gem_init_earlyfunction i915_gem_cleanup_earlyfunction i915_gem_open
Annotated Snippet
if (flags & I915_GEM_OBJECT_UNBIND_TEST) {
ret = -EBUSY;
break;
}
/*
* Requiring the vm destructor to take the object lock
* before destroying a vma would help us eliminate the
* i915_vm_tryget() here, AND thus also the barrier stuff
* at the end. That's an easy fix, but sleeping locks in
* a kthread should generally be avoided.
*/
ret = -EAGAIN;
if (!i915_vm_tryget(vma->vm))
break;
spin_unlock(&obj->vma.lock);
/*
* Since i915_vma_parked() takes the object lock
* before vma destruction, it won't race us here,
* and destroy the vma from under us.
*/
ret = -EBUSY;
if (flags & I915_GEM_OBJECT_UNBIND_ASYNC) {
assert_object_held(vma->obj);
ret = i915_vma_unbind_async(vma, vm_trylock);
}
if (ret == -EBUSY && (flags & I915_GEM_OBJECT_UNBIND_ACTIVE ||
!i915_vma_is_active(vma))) {
if (vm_trylock) {
if (mutex_trylock(&vma->vm->mutex)) {
ret = __i915_vma_unbind(vma);
mutex_unlock(&vma->vm->mutex);
}
} else {
ret = i915_vma_unbind(vma);
}
}
i915_vm_put(vma->vm);
spin_lock(&obj->vma.lock);
}
list_splice_init(&still_in_list, &obj->vma.list);
spin_unlock(&obj->vma.lock);
if (ret == -EAGAIN && flags & I915_GEM_OBJECT_UNBIND_BARRIER) {
rcu_barrier(); /* flush the i915_vm_release() */
goto try_again;
}
intel_runtime_pm_put(rpm, wakeref);
return ret;
}
static int
shmem_pread(struct page *page, int offset, int len, char __user *user_data,
bool needs_clflush)
{
char *vaddr;
int ret;
vaddr = kmap(page);
if (needs_clflush)
drm_clflush_virt_range(vaddr + offset, len);
ret = __copy_to_user(user_data, vaddr + offset, len);
kunmap(page);
return ret ? -EFAULT : 0;
}
static int
i915_gem_shmem_pread(struct drm_i915_gem_object *obj,
struct drm_i915_gem_pread *args)
{
unsigned int needs_clflush;
char __user *user_data;
unsigned long offset;
pgoff_t idx;
u64 remain;
int ret;
ret = i915_gem_object_lock_interruptible(obj, NULL);
if (ret)
Annotation
- Immediate include surface: `linux/dma-fence-array.h`, `linux/kthread.h`, `linux/dma-resv.h`, `linux/shmem_fs.h`, `linux/slab.h`, `linux/stop_machine.h`, `linux/swap.h`, `linux/pci.h`.
- Detected declarations: `function files`, `function remove_mappable_node`, `function i915_gem_get_aperture_ioctl`, `function i915_gem_object_unbind`, `function shmem_pread`, `function i915_gem_shmem_pread`, `function gtt_user_read`, `function i915_gem_gtt_cleanup`, `function i915_gem_gtt_pread`, `function i915_gem_pread_ioctl`.
- 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.