drivers/gpu/drm/nouveau/nouveau_prime.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/nouveau/nouveau_prime.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/nouveau/nouveau_prime.c- Extension
.c- Size
- 3585 bytes
- Lines
- 129
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/dma-buf.hdrm/ttm/ttm_tt.hnouveau_drv.hnouveau_gem.h
Detected Declarations
function filesfunction nouveau_gem_prime_pinfunction nouveau_gem_prime_unpin
Annotated Snippet
#include <linux/dma-buf.h>
#include <drm/ttm/ttm_tt.h>
#include "nouveau_drv.h"
#include "nouveau_gem.h"
struct sg_table *nouveau_gem_prime_get_sg_table(struct drm_gem_object *obj)
{
struct nouveau_bo *nvbo = nouveau_gem_object(obj);
return drm_prime_pages_to_sg(obj->dev, nvbo->bo.ttm->pages,
nvbo->bo.ttm->num_pages);
}
struct drm_gem_object *nouveau_gem_prime_import_sg_table(struct drm_device *dev,
struct dma_buf_attachment *attach,
struct sg_table *sg)
{
struct nouveau_drm *drm = nouveau_drm(dev);
struct drm_gem_object *obj;
struct nouveau_bo *nvbo;
struct dma_resv *robj = attach->dmabuf->resv;
u64 size = attach->dmabuf->size;
int align = 0;
int ret;
dma_resv_lock(robj, NULL);
nvbo = nouveau_bo_alloc(&drm->client, &size, &align,
NOUVEAU_GEM_DOMAIN_GART, 0, 0, true);
if (IS_ERR(nvbo)) {
obj = ERR_CAST(nvbo);
goto unlock;
}
nvbo->valid_domains = NOUVEAU_GEM_DOMAIN_GART;
nvbo->bo.base.funcs = &nouveau_gem_object_funcs;
/* Initialize the embedded gem-object. We return a single gem-reference
* to the caller, instead of a normal nouveau_bo ttm reference. */
ret = drm_gem_object_init(dev, &nvbo->bo.base, size);
if (ret) {
drm_gem_object_release(&nvbo->bo.base);
kfree(nvbo);
obj = ERR_PTR(-ENOMEM);
goto unlock;
}
ret = nouveau_bo_init(nvbo, size, align, NOUVEAU_GEM_DOMAIN_GART,
sg, robj);
if (ret) {
obj = ERR_PTR(ret);
goto unlock;
}
obj = &nvbo->bo.base;
unlock:
dma_resv_unlock(robj);
return obj;
}
int nouveau_gem_prime_pin(struct drm_gem_object *obj)
{
struct nouveau_bo *nvbo = nouveau_gem_object(obj);
int ret;
/* pin buffer into GTT */
ret = nouveau_bo_pin_locked(nvbo, NOUVEAU_GEM_DOMAIN_GART, false);
if (ret)
ret = -EINVAL;
return ret;
}
void nouveau_gem_prime_unpin(struct drm_gem_object *obj)
{
struct nouveau_bo *nvbo = nouveau_gem_object(obj);
nouveau_bo_unpin_locked(nvbo);
}
struct dma_buf *nouveau_gem_prime_export(struct drm_gem_object *gobj,
int flags)
{
struct nouveau_bo *nvbo = nouveau_gem_object(gobj);
struct ttm_operation_ctx ctx = {
.interruptible = true,
.no_wait_gpu = true,
/* We opt to avoid OOM on system pages allocations */
Annotation
- Immediate include surface: `linux/dma-buf.h`, `drm/ttm/ttm_tt.h`, `nouveau_drv.h`, `nouveau_gem.h`.
- Detected declarations: `function files`, `function nouveau_gem_prime_pin`, `function nouveau_gem_prime_unpin`.
- 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.