drivers/gpu/drm/i915/gem/i915_gem_userptr.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/i915/gem/i915_gem_userptr.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/i915/gem/i915_gem_userptr.c- Extension
.c- Size
- 14714 bytes
- Lines
- 557
- 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.
- 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/mmu_context.hlinux/mempolicy.hlinux/swap.hlinux/sched/mm.hdrm/drm_print.hi915_drv.hi915_gem_ioctls.hi915_gem_object.hi915_scatterlist.h
Detected Declarations
function filesfunction i915_gem_userptr_init__mmu_notifierfunction i915_gem_object_userptr_drop_reffunction i915_gem_userptr_get_pagesfunction i915_gem_userptr_put_pagesfunction for_each_sgt_pagefunction i915_gem_object_userptr_unbindfunction i915_gem_object_userptr_submit_initfunction i915_gem_object_userptr_submit_donefunction i915_gem_object_userptr_validatefunction i915_gem_userptr_releasefunction i915_gem_userptr_dmabuf_exportfunction i915_gem_userptr_pwritefunction i915_gem_userptr_preadfunction probe_rangefunction space
Annotated Snippet
if (max_segment > PAGE_SIZE) {
max_segment = PAGE_SIZE;
goto alloc_table;
}
goto err;
}
WARN_ON_ONCE(!(obj->cache_coherent & I915_BO_CACHE_COHERENT_FOR_WRITE));
if (i915_gem_object_can_bypass_llc(obj))
obj->cache_dirty = true;
__i915_gem_object_set_pages(obj, st);
return 0;
err:
i915_gem_object_userptr_drop_ref(obj);
err_free:
kfree(st);
return ret;
}
static void
i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj,
struct sg_table *pages)
{
struct sgt_iter sgt_iter;
struct page *page;
if (!pages)
return;
__i915_gem_object_release_shmem(obj, pages, true);
i915_gem_gtt_finish_pages(obj, pages);
/*
* We always mark objects as dirty when they are used by the GPU,
* just in case. However, if we set the vma as being read-only we know
* that the object will never have been written to.
*/
if (i915_gem_object_is_readonly(obj))
obj->mm.dirty = false;
for_each_sgt_page(page, sgt_iter, pages) {
if (obj->mm.dirty && trylock_page(page)) {
/*
* As this may not be anonymous memory (e.g. shmem)
* but exist on a real mapping, we have to lock
* the page in order to dirty it -- holding
* the page reference is not sufficient to
* prevent the inode from being truncated.
* Play safe and take the lock.
*
* However...!
*
* The mmu-notifier can be invalidated for a
* migrate_folio, that is alreadying holding the lock
* on the folio. Such a try_to_unmap() will result
* in us calling put_pages() and so recursively try
* to lock the page. We avoid that deadlock with
* a trylock_page() and in exchange we risk missing
* some page dirtying.
*/
set_page_dirty(page);
unlock_page(page);
}
mark_page_accessed(page);
}
obj->mm.dirty = false;
sg_free_table(pages);
kfree(pages);
i915_gem_object_userptr_drop_ref(obj);
}
static int i915_gem_object_userptr_unbind(struct drm_i915_gem_object *obj)
{
struct sg_table *pages;
int err;
err = i915_gem_object_unbind(obj, I915_GEM_OBJECT_UNBIND_ACTIVE);
if (err)
return err;
if (GEM_WARN_ON(i915_gem_object_has_pinned_pages(obj)))
return -EBUSY;
Annotation
- Immediate include surface: `linux/mmu_context.h`, `linux/mempolicy.h`, `linux/swap.h`, `linux/sched/mm.h`, `drm/drm_print.h`, `i915_drv.h`, `i915_gem_ioctls.h`, `i915_gem_object.h`.
- Detected declarations: `function files`, `function i915_gem_userptr_init__mmu_notifier`, `function i915_gem_object_userptr_drop_ref`, `function i915_gem_userptr_get_pages`, `function i915_gem_userptr_put_pages`, `function for_each_sgt_page`, `function i915_gem_object_userptr_unbind`, `function i915_gem_object_userptr_submit_init`, `function i915_gem_object_userptr_submit_done`, `function i915_gem_object_userptr_validate`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source implementation candidate.
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.