drivers/accel/rocket/rocket_gem.c
Source file repositories/reference/linux-study-clean/drivers/accel/rocket/rocket_gem.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/accel/rocket/rocket_gem.c- Extension
.c- Size
- 4886 bytes
- Lines
- 192
- Domain
- Driver Families
- Bucket
- drivers/accel
- 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.
- 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_device.hdrm/drm_print.hdrm/drm_utils.hdrm/rocket_accel.hlinux/dma-mapping.hlinux/iommu.hrocket_drv.hrocket_gem.h
Detected Declarations
function rocket_gem_bo_freefunction rocket_ioctl_create_bofunction rocket_ioctl_prep_bofunction rocket_ioctl_fini_bo
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/* Copyright 2024-2025 Tomeu Vizoso <tomeu@tomeuvizoso.net> */
#include <drm/drm_device.h>
#include <drm/drm_print.h>
#include <drm/drm_utils.h>
#include <drm/rocket_accel.h>
#include <linux/dma-mapping.h>
#include <linux/iommu.h>
#include "rocket_drv.h"
#include "rocket_gem.h"
static void rocket_gem_bo_free(struct drm_gem_object *obj)
{
struct rocket_gem_object *bo = to_rocket_bo(obj);
struct rocket_file_priv *rocket_priv = bo->driver_priv;
size_t unmapped;
drm_WARN_ON(obj->dev, refcount_read(&bo->base.pages_use_count) > 1);
unmapped = iommu_unmap(bo->domain->domain, bo->mm.start, bo->size);
drm_WARN_ON(obj->dev, unmapped != bo->size);
mutex_lock(&rocket_priv->mm_lock);
drm_mm_remove_node(&bo->mm);
mutex_unlock(&rocket_priv->mm_lock);
rocket_iommu_domain_put(bo->domain);
bo->domain = NULL;
drm_gem_shmem_free(&bo->base);
}
static const struct drm_gem_object_funcs rocket_gem_funcs = {
.free = rocket_gem_bo_free,
.print_info = drm_gem_shmem_object_print_info,
.pin = drm_gem_shmem_object_pin,
.unpin = drm_gem_shmem_object_unpin,
.get_sg_table = drm_gem_shmem_object_get_sg_table,
.vmap = drm_gem_shmem_object_vmap,
.vunmap = drm_gem_shmem_object_vunmap,
.mmap = drm_gem_shmem_object_mmap,
.vm_ops = &drm_gem_shmem_vm_ops,
};
struct drm_gem_object *rocket_gem_create_object(struct drm_device *dev, size_t size)
{
struct rocket_gem_object *obj;
obj = kzalloc_obj(*obj);
if (!obj)
return ERR_PTR(-ENOMEM);
obj->base.base.funcs = &rocket_gem_funcs;
return &obj->base.base;
}
int rocket_ioctl_create_bo(struct drm_device *dev, void *data, struct drm_file *file)
{
struct rocket_file_priv *rocket_priv = file->driver_priv;
struct drm_rocket_create_bo *args = data;
struct drm_gem_shmem_object *shmem_obj;
struct rocket_gem_object *rkt_obj;
struct drm_gem_object *gem_obj;
struct sg_table *sgt;
int ret;
shmem_obj = drm_gem_shmem_create(dev, args->size);
if (IS_ERR(shmem_obj))
return PTR_ERR(shmem_obj);
gem_obj = &shmem_obj->base;
rkt_obj = to_rocket_bo(gem_obj);
rkt_obj->driver_priv = rocket_priv;
rkt_obj->domain = rocket_iommu_domain_get(rocket_priv);
rkt_obj->size = args->size;
rkt_obj->offset = 0;
sgt = drm_gem_shmem_get_pages_sgt(shmem_obj);
if (IS_ERR(sgt)) {
ret = PTR_ERR(sgt);
goto err;
}
mutex_lock(&rocket_priv->mm_lock);
ret = drm_mm_insert_node_generic(&rocket_priv->mm, &rkt_obj->mm,
rkt_obj->size, PAGE_SIZE,
Annotation
- Immediate include surface: `drm/drm_device.h`, `drm/drm_print.h`, `drm/drm_utils.h`, `drm/rocket_accel.h`, `linux/dma-mapping.h`, `linux/iommu.h`, `rocket_drv.h`, `rocket_gem.h`.
- Detected declarations: `function rocket_gem_bo_free`, `function rocket_ioctl_create_bo`, `function rocket_ioctl_prep_bo`, `function rocket_ioctl_fini_bo`.
- Atlas domain: Driver Families / drivers/accel.
- Implementation status: source implementation candidate.
- 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.