drivers/gpu/drm/loongson/lsdc_gem.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/loongson/lsdc_gem.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/loongson/lsdc_gem.c- Extension
.c- Size
- 6207 bytes
- Lines
- 276
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/dma-buf.hdrm/drm_debugfs.hdrm/drm_dumb_buffers.hdrm/drm_file.hdrm/drm_gem.hdrm/drm_prime.hdrm/drm_print.hlsdc_drv.hlsdc_gem.hlsdc_ttm.h
Detected Declarations
function Copyrightfunction lsdc_gem_prime_unpinfunction lsdc_gem_object_freefunction lsdc_gem_object_vmapfunction lsdc_gem_object_vunmapfunction lsdc_gem_object_mmapfunction lsdc_prime_import_sg_tablefunction lsdc_dumb_createfunction lsdc_gem_initfunction lsdc_show_buffer_objectfunction list_for_each_entry
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2023 Loongson Technology Corporation Limited
*/
#include <linux/dma-buf.h>
#include <drm/drm_debugfs.h>
#include <drm/drm_dumb_buffers.h>
#include <drm/drm_file.h>
#include <drm/drm_gem.h>
#include <drm/drm_prime.h>
#include <drm/drm_print.h>
#include "lsdc_drv.h"
#include "lsdc_gem.h"
#include "lsdc_ttm.h"
static int lsdc_gem_prime_pin(struct drm_gem_object *obj)
{
struct lsdc_bo *lbo = gem_to_lsdc_bo(obj);
int ret;
dma_resv_assert_held(obj->resv);
ret = lsdc_bo_pin(lbo, LSDC_GEM_DOMAIN_GTT, NULL);
if (likely(ret == 0))
lbo->sharing_count++;
return ret;
}
static void lsdc_gem_prime_unpin(struct drm_gem_object *obj)
{
struct lsdc_bo *lbo = gem_to_lsdc_bo(obj);
dma_resv_assert_held(obj->resv);
lsdc_bo_unpin(lbo);
if (lbo->sharing_count)
lbo->sharing_count--;
}
static struct sg_table *lsdc_gem_prime_get_sg_table(struct drm_gem_object *obj)
{
struct ttm_buffer_object *tbo = to_ttm_bo(obj);
struct ttm_tt *tt = tbo->ttm;
if (!tt) {
drm_err(obj->dev, "sharing a buffer without backing memory\n");
return ERR_PTR(-ENOMEM);
}
return drm_prime_pages_to_sg(obj->dev, tt->pages, tt->num_pages);
}
static void lsdc_gem_object_free(struct drm_gem_object *obj)
{
struct ttm_buffer_object *tbo = to_ttm_bo(obj);
if (tbo)
ttm_bo_fini(tbo);
}
static int lsdc_gem_object_vmap(struct drm_gem_object *obj, struct iosys_map *map)
{
struct ttm_buffer_object *tbo = to_ttm_bo(obj);
struct lsdc_bo *lbo = to_lsdc_bo(tbo);
int ret;
if (lbo->vmap_count > 0) {
++lbo->vmap_count;
goto out;
}
ret = lsdc_bo_pin(lbo, 0, NULL);
if (unlikely(ret)) {
drm_err(obj->dev, "pin %p for vmap failed\n", lbo);
return ret;
}
ret = ttm_bo_vmap(tbo, &lbo->map);
if (ret) {
drm_err(obj->dev, "ttm bo vmap failed\n");
lsdc_bo_unpin(lbo);
return ret;
}
lbo->vmap_count = 1;
Annotation
- Immediate include surface: `linux/dma-buf.h`, `drm/drm_debugfs.h`, `drm/drm_dumb_buffers.h`, `drm/drm_file.h`, `drm/drm_gem.h`, `drm/drm_prime.h`, `drm/drm_print.h`, `lsdc_drv.h`.
- Detected declarations: `function Copyright`, `function lsdc_gem_prime_unpin`, `function lsdc_gem_object_free`, `function lsdc_gem_object_vmap`, `function lsdc_gem_object_vunmap`, `function lsdc_gem_object_mmap`, `function lsdc_prime_import_sg_table`, `function lsdc_dumb_create`, `function lsdc_gem_init`, `function lsdc_show_buffer_object`.
- 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.
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.