drivers/gpu/drm/nouveau/nouveau_gem.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/nouveau/nouveau_gem.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/nouveau/nouveau_gem.c- Extension
.c- Size
- 27141 bytes
- Lines
- 1047
- 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
drm/drm_gem_ttm_helper.hnouveau_drv.hnouveau_dma.hnouveau_fence.hnouveau_abi16.hnouveau_ttm.hnouveau_gem.hnouveau_mem.hnouveau_vmm.hnvif/class.hnvif/push206e.h
Detected Declarations
struct nouveau_gem_object_unmapstruct validate_opfunction Copyrightfunction nouveau_gem_object_delfunction nouveau_gem_object_openfunction nouveau_gem_object_deletefunction nouveau_gem_object_delete_workfunction nouveau_gem_object_unmapfunction nouveau_gem_object_closefunction nouveau_gem_newfunction nouveau_gem_infofunction nouveau_gem_ioctl_newfunction nouveau_gem_set_domainfunction validate_fini_no_ticketfunction validate_finifunction validate_initfunction validate_listfunction list_for_each_entryfunction nouveau_gem_pushbuf_validatefunction nouveau_gem_pushbuf_reloc_applyfunction nouveau_gem_ioctl_pushbuffunction list_for_each_entryfunction nouveau_gem_ioctl_cpu_prepfunction nouveau_gem_ioctl_cpu_finifunction nouveau_gem_ioctl_info
Annotated Snippet
struct nouveau_gem_object_unmap {
struct nouveau_cli_work work;
struct nouveau_vma *vma;
};
static void
nouveau_gem_object_delete(struct nouveau_vma *vma)
{
nouveau_fence_unref(&vma->fence);
nouveau_vma_del(&vma);
}
static void
nouveau_gem_object_delete_work(struct nouveau_cli_work *w)
{
struct nouveau_gem_object_unmap *work =
container_of(w, typeof(*work), work);
nouveau_gem_object_delete(work->vma);
kfree(work);
}
static void
nouveau_gem_object_unmap(struct nouveau_bo *nvbo, struct nouveau_vma *vma)
{
struct dma_fence *fence = vma->fence ? &vma->fence->base : NULL;
struct nouveau_gem_object_unmap *work;
list_del_init(&vma->head);
if (!fence) {
nouveau_gem_object_delete(vma);
return;
}
if (!(work = kmalloc_obj(*work))) {
WARN_ON(dma_fence_wait_timeout(fence, false, 2 * HZ) <= 0);
nouveau_gem_object_delete(vma);
return;
}
work->work.func = nouveau_gem_object_delete_work;
work->vma = vma;
nouveau_cli_work_queue(vma->vmm->cli, fence, &work->work);
}
void
nouveau_gem_object_close(struct drm_gem_object *gem, struct drm_file *file_priv)
{
struct nouveau_cli *cli = nouveau_cli(file_priv);
struct nouveau_bo *nvbo = nouveau_gem_object(gem);
struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev);
struct device *dev = drm->dev->dev;
struct nouveau_vmm *vmm = nouveau_cli_vmm(cli);
struct nouveau_vma *vma;
int ret;
if (vmm->vmm.object.oclass < NVIF_CLASS_VMM_NV50)
return;
if (nouveau_cli_uvmm(cli))
return;
ret = ttm_bo_reserve(&nvbo->bo, false, false, NULL);
if (ret)
return;
vma = nouveau_vma_find(nvbo, vmm);
if (vma) {
if (--vma->refs == 0) {
ret = pm_runtime_get_sync(dev);
if (!WARN_ON(ret < 0 && ret != -EACCES)) {
nouveau_gem_object_unmap(nvbo, vma);
pm_runtime_mark_last_busy(dev);
}
pm_runtime_put_autosuspend(dev);
}
}
ttm_bo_unreserve(&nvbo->bo);
}
const struct drm_gem_object_funcs nouveau_gem_object_funcs = {
.free = nouveau_gem_object_del,
.open = nouveau_gem_object_open,
.close = nouveau_gem_object_close,
.export = nouveau_gem_prime_export,
.pin = nouveau_gem_prime_pin,
.unpin = nouveau_gem_prime_unpin,
.get_sg_table = nouveau_gem_prime_get_sg_table,
.vmap = drm_gem_ttm_vmap,
.vunmap = drm_gem_ttm_vunmap,
Annotation
- Immediate include surface: `drm/drm_gem_ttm_helper.h`, `nouveau_drv.h`, `nouveau_dma.h`, `nouveau_fence.h`, `nouveau_abi16.h`, `nouveau_ttm.h`, `nouveau_gem.h`, `nouveau_mem.h`.
- Detected declarations: `struct nouveau_gem_object_unmap`, `struct validate_op`, `function Copyright`, `function nouveau_gem_object_del`, `function nouveau_gem_object_open`, `function nouveau_gem_object_delete`, `function nouveau_gem_object_delete_work`, `function nouveau_gem_object_unmap`, `function nouveau_gem_object_close`, `function nouveau_gem_new`.
- 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.