drivers/gpu/drm/rockchip/rockchip_drm_gem.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/rockchip/rockchip_drm_gem.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/rockchip/rockchip_drm_gem.c- Extension
.c- Size
- 13473 bytes
- Lines
- 553
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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-buf.hlinux/iommu.hlinux/vmalloc.hdrm/drm.hdrm/drm_dumb_buffers.hdrm/drm_fb_helper.hdrm/drm_gem.hdrm/drm_gem_dma_helper.hdrm/drm_prime.hdrm/drm_print.hdrm/drm_vma_manager.hrockchip_drm_drv.hrockchip_drm_gem.h
Detected Declarations
function Copyrightfunction rockchip_gem_iommu_unmapfunction rockchip_gem_get_pagesfunction rockchip_gem_put_pagesfunction rockchip_gem_alloc_iommufunction rockchip_gem_alloc_dmafunction rockchip_gem_alloc_buffunction rockchip_gem_free_iommufunction rockchip_gem_free_dmafunction rockchip_gem_free_buffunction rockchip_drm_gem_object_mmap_iommufunction rockchip_drm_gem_object_mmap_dmafunction rockchip_drm_gem_object_mmapfunction rockchip_gem_release_objectfunction rockchip_gem_alloc_objectfunction rockchip_gem_create_objectfunction rockchip_gem_free_objectfunction rockchip_gem_create_with_handlefunction rockchip_gem_dumb_createfunction rockchip_gem_iommu_map_sgfunction rockchip_gem_dma_map_sgfunction rockchip_gem_prime_import_sg_tablefunction rockchip_gem_prime_vmapfunction rockchip_gem_prime_vunmap
Annotated Snippet
if (!rk_obj->kvaddr) {
DRM_ERROR("failed to vmap() buffer\n");
ret = -ENOMEM;
goto err_unmap;
}
}
return 0;
err_unmap:
rockchip_gem_iommu_unmap(rk_obj);
err_free:
rockchip_gem_put_pages(rk_obj);
return ret;
}
static int rockchip_gem_alloc_dma(struct rockchip_gem_object *rk_obj,
bool alloc_kmap)
{
struct drm_gem_object *obj = &rk_obj->base;
struct drm_device *drm = obj->dev;
rk_obj->dma_attrs = DMA_ATTR_WRITE_COMBINE;
if (!alloc_kmap)
rk_obj->dma_attrs |= DMA_ATTR_NO_KERNEL_MAPPING;
rk_obj->kvaddr = dma_alloc_attrs(drm->dev, obj->size,
&rk_obj->dma_addr, GFP_KERNEL,
rk_obj->dma_attrs);
if (!rk_obj->kvaddr) {
DRM_ERROR("failed to allocate %zu byte dma buffer", obj->size);
return -ENOMEM;
}
return 0;
}
static int rockchip_gem_alloc_buf(struct rockchip_gem_object *rk_obj,
bool alloc_kmap)
{
struct drm_gem_object *obj = &rk_obj->base;
struct drm_device *drm = obj->dev;
struct rockchip_drm_private *private = drm->dev_private;
if (private->domain)
return rockchip_gem_alloc_iommu(rk_obj, alloc_kmap);
else
return rockchip_gem_alloc_dma(rk_obj, alloc_kmap);
}
static void rockchip_gem_free_iommu(struct rockchip_gem_object *rk_obj)
{
vunmap(rk_obj->kvaddr);
rockchip_gem_iommu_unmap(rk_obj);
rockchip_gem_put_pages(rk_obj);
}
static void rockchip_gem_free_dma(struct rockchip_gem_object *rk_obj)
{
struct drm_gem_object *obj = &rk_obj->base;
struct drm_device *drm = obj->dev;
dma_free_attrs(drm->dev, obj->size, rk_obj->kvaddr, rk_obj->dma_addr,
rk_obj->dma_attrs);
}
static void rockchip_gem_free_buf(struct rockchip_gem_object *rk_obj)
{
if (rk_obj->pages)
rockchip_gem_free_iommu(rk_obj);
else
rockchip_gem_free_dma(rk_obj);
}
static int rockchip_drm_gem_object_mmap_iommu(struct drm_gem_object *obj,
struct vm_area_struct *vma)
{
struct rockchip_gem_object *rk_obj = to_rockchip_obj(obj);
unsigned int count = obj->size >> PAGE_SHIFT;
unsigned long user_count = vma_pages(vma);
if (user_count == 0)
return -ENXIO;
return vm_map_pages(vma, rk_obj->pages, count);
}
static int rockchip_drm_gem_object_mmap_dma(struct drm_gem_object *obj,
Annotation
- Immediate include surface: `linux/dma-buf.h`, `linux/iommu.h`, `linux/vmalloc.h`, `drm/drm.h`, `drm/drm_dumb_buffers.h`, `drm/drm_fb_helper.h`, `drm/drm_gem.h`, `drm/drm_gem_dma_helper.h`.
- Detected declarations: `function Copyright`, `function rockchip_gem_iommu_unmap`, `function rockchip_gem_get_pages`, `function rockchip_gem_put_pages`, `function rockchip_gem_alloc_iommu`, `function rockchip_gem_alloc_dma`, `function rockchip_gem_alloc_buf`, `function rockchip_gem_free_iommu`, `function rockchip_gem_free_dma`, `function rockchip_gem_free_buf`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.