drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c- Extension
.c- Size
- 15173 bytes
- Lines
- 596
- 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 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
vmwgfx_bo.hvmwgfx_drv.hdrm/ttm/ttm_placement.h
Detected Declarations
function __vmw_piter_non_sg_nextfunction __vmw_piter_sg_nextfunction __vmw_piter_dma_addrfunction __vmw_piter_sg_addrfunction vmw_piter_startfunction vmw_ttm_unmap_from_dmafunction dma_sync_sg_for_cpufunction vmw_ttm_map_dmafunction vmw_ttm_unmap_dmafunction vmw_ttm_bindfunction vmw_ttm_unbindfunction vmw_ttm_destroyfunction vmw_ttm_populatefunction vmw_ttm_unpopulatefunction vmw_evict_flagsfunction vmw_ttm_io_mem_reservefunction vmw_move_notifyfunction vmw_swap_notifyfunction vmw_memtype_is_systemfunction vmw_movefunction vmw_bo_create_and_populate
Annotated Snippet
if (vmw_tt->dma_ttm.page_flags & TTM_TT_FLAG_EXTERNAL) {
vsgt->sgt = vmw_tt->dma_ttm.sg;
} else {
vsgt->sgt = &vmw_tt->sgt;
ret = sg_alloc_table_from_pages_segment(&vmw_tt->sgt,
vsgt->pages, vsgt->num_pages, 0,
(unsigned long)vsgt->num_pages << PAGE_SHIFT,
dma_get_max_seg_size(dev_priv->drm.dev),
GFP_KERNEL);
if (ret)
goto out_sg_alloc_fail;
}
ret = vmw_ttm_map_for_dma(vmw_tt);
if (unlikely(ret != 0))
goto out_map_fail;
break;
default:
break;
}
vmw_tt->mapped = true;
return 0;
out_map_fail:
drm_warn(&dev_priv->drm, "VSG table map failed!");
sg_free_table(vsgt->sgt);
vsgt->sgt = NULL;
out_sg_alloc_fail:
return ret;
}
/**
* vmw_ttm_unmap_dma - Tear down any TTM page device mappings
*
* @vmw_tt: Pointer to a struct vmw_ttm_tt
*
* Tear down any previously set up device DMA mappings and free
* any storage space allocated for them. If there are no mappings set up,
* this function is a NOP.
*/
static void vmw_ttm_unmap_dma(struct vmw_ttm_tt *vmw_tt)
{
struct vmw_private *dev_priv = vmw_tt->dev_priv;
if (!vmw_tt->vsgt.sgt)
return;
switch (dev_priv->map_mode) {
case vmw_dma_map_bind:
case vmw_dma_map_populate:
vmw_ttm_unmap_from_dma(vmw_tt);
sg_free_table(vmw_tt->vsgt.sgt);
vmw_tt->vsgt.sgt = NULL;
break;
default:
break;
}
vmw_tt->mapped = false;
}
/**
* vmw_bo_sg_table - Return a struct vmw_sg_table object for a
* TTM buffer object
*
* @bo: Pointer to a struct ttm_buffer_object
*
* Returns a pointer to a struct vmw_sg_table object. The object should
* not be freed after use.
* Note that for the device addresses to be valid, the buffer object must
* either be reserved or pinned.
*/
const struct vmw_sg_table *vmw_bo_sg_table(struct ttm_buffer_object *bo)
{
struct vmw_ttm_tt *vmw_tt =
container_of(bo->ttm, struct vmw_ttm_tt, dma_ttm);
return &vmw_tt->vsgt;
}
static int vmw_ttm_bind(struct ttm_device *bdev,
struct ttm_tt *ttm, struct ttm_resource *bo_mem)
{
struct vmw_ttm_tt *vmw_be =
container_of(ttm, struct vmw_ttm_tt, dma_ttm);
int ret = 0;
if (!bo_mem)
Annotation
- Immediate include surface: `vmwgfx_bo.h`, `vmwgfx_drv.h`, `drm/ttm/ttm_placement.h`.
- Detected declarations: `function __vmw_piter_non_sg_next`, `function __vmw_piter_sg_next`, `function __vmw_piter_dma_addr`, `function __vmw_piter_sg_addr`, `function vmw_piter_start`, `function vmw_ttm_unmap_from_dma`, `function dma_sync_sg_for_cpu`, `function vmw_ttm_map_dma`, `function vmw_ttm_unmap_dma`, `function vmw_ttm_bind`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source implementation candidate.
- 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.