drivers/gpu/drm/i915/i915_scatterlist.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/i915/i915_scatterlist.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/i915/i915_scatterlist.c- Extension
.c- Size
- 6163 bytes
- Lines
- 243
- 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.
- 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
i915_scatterlist.hi915_ttm_buddy_manager.hlinux/gpu_buddy.hdrm/drm_mm.hlinux/slab.hselftests/scatterlist.c
Detected Declarations
function i915_sg_trimfunction i915_refct_sgt_releasefunction i915_refct_sgt_initfunction list_for_each_entry
Annotated Snippet
if (offset != prev_end || sg->length >= max_segment) {
if (st->nents)
sg = __sg_next(sg);
sg_dma_address(sg) = region_start + offset;
GEM_BUG_ON(!IS_ALIGNED(sg_dma_address(sg),
page_alignment));
sg_dma_len(sg) = 0;
sg->length = 0;
st->nents++;
}
len = min_t(u64, block_size, max_segment - sg->length);
sg->length += len;
sg_dma_len(sg) += len;
offset += len;
block_size -= len;
prev_end = offset;
}
sg_mark_end(sg);
i915_sg_trim(st);
return rsgt;
}
/**
* i915_rsgt_from_buddy_resource - Create a refcounted sg_table from a struct
* i915_buddy_block list
* @res: The struct i915_ttm_buddy_resource.
* @region_start: An offset to add to the dma addresses of the sg list.
* @page_alignment: Required page alignment for each sg entry. Power of two.
*
* Create a struct sg_table, initializing it from struct i915_buddy_block list,
* taking a maximum segment length into account, splitting into segments
* if necessary.
*
* Return: A pointer to a kmalloced struct i915_refct_sgts on success, negative
* error code cast to an error pointer on failure.
*/
struct i915_refct_sgt *i915_rsgt_from_buddy_resource(struct ttm_resource *res,
u64 region_start,
u32 page_alignment)
{
struct i915_ttm_buddy_resource *bman_res = to_ttm_buddy_resource(res);
const u64 size = res->size;
const u32 max_segment = round_down(UINT_MAX, page_alignment);
struct gpu_buddy *mm = bman_res->mm;
struct list_head *blocks = &bman_res->blocks;
struct gpu_buddy_block *block;
struct i915_refct_sgt *rsgt;
struct scatterlist *sg;
struct sg_table *st;
resource_size_t prev_end;
GEM_BUG_ON(list_empty(blocks));
GEM_BUG_ON(!max_segment);
rsgt = kmalloc_obj(*rsgt, GFP_KERNEL | __GFP_NOWARN);
if (!rsgt)
return ERR_PTR(-ENOMEM);
i915_refct_sgt_init(rsgt, size);
st = &rsgt->table;
/* restricted by sg_alloc_table */
if (WARN_ON(overflows_type(PFN_UP(res->size), unsigned int))) {
i915_refct_sgt_put(rsgt);
return ERR_PTR(-E2BIG);
}
if (sg_alloc_table(st, PFN_UP(res->size), GFP_KERNEL | __GFP_NOWARN)) {
i915_refct_sgt_put(rsgt);
return ERR_PTR(-ENOMEM);
}
sg = st->sgl;
st->nents = 0;
prev_end = (resource_size_t)-1;
list_for_each_entry(block, blocks, link) {
u64 block_size, offset;
block_size = min_t(u64, size, gpu_buddy_block_size(mm, block));
offset = gpu_buddy_block_offset(block);
while (block_size) {
u64 len;
Annotation
- Immediate include surface: `i915_scatterlist.h`, `i915_ttm_buddy_manager.h`, `linux/gpu_buddy.h`, `drm/drm_mm.h`, `linux/slab.h`, `selftests/scatterlist.c`.
- Detected declarations: `function i915_sg_trim`, `function i915_refct_sgt_release`, `function i915_refct_sgt_init`, `function list_for_each_entry`.
- 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.