drivers/gpu/drm/i915/gem/i915_gem_context.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/i915/gem/i915_gem_context.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/i915/gem/i915_gem_context.c- Extension
.c- Size
- 68426 bytes
- Lines
- 2722
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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
linux/highmem.hlinux/log2.hlinux/nospec.hdrm/drm_cache.hdrm/drm_print.hdrm/drm_syncobj.hgt/gen6_ppgtt.hgt/intel_context.hgt/intel_context_param.hgt/intel_engine_heartbeat.hgt/intel_engine_user.hgt/intel_gpu_commands.hgt/intel_ring.hgt/shmem_utils.hpxp/intel_pxp.hi915_file_private.hi915_gem_context.hi915_trace.hi915_user_extensions.hselftests/mock_context.cselftests/i915_gem_context.c
Detected Declarations
struct set_proto_ctx_enginesstruct create_extfunction i915_lut_handle_freefunction lut_closefunction list_for_each_entryfunction lookup_user_enginefunction validate_priorityfunction proto_context_closefunction proto_context_set_persistencefunction proto_context_set_protectedfunction proto_context_createfunction proto_context_register_lockedfunction proto_context_registerfunction i915_gem_vm_lookupfunction set_proto_ctx_vmfunction set_proto_ctx_engines_balancefunction set_proto_ctx_engines_bondfunction set_proto_ctx_engines_parallel_submitfunction set_proto_ctx_enginesfunction set_proto_ctx_sseufunction set_proto_ctx_paramfunction intel_context_set_gemfunction __unpin_enginesfunction unpin_enginesfunction __free_enginesfunction free_enginesfunction free_engines_rcufunction accumulate_runtimefunction engines_notifyfunction for_each_uabi_enginefunction perma_pin_contextsfunction for_each_childfunction for_each_childfunction i915_gem_context_release_workfunction i915_gem_context_releasefunction __context_engines_staticfunction __reset_contextfunction __cancel_enginefunction kill_enginesfunction kill_contextfunction engines_idle_releasefunction for_each_gem_enginefunction set_closed_namefunction context_closefunction __context_set_persistencefunction i915_gem_create_contextfunction init_contextsfunction i915_gem_init__contexts
Annotated Snippet
struct set_proto_ctx_engines {
struct drm_i915_private *i915;
unsigned num_engines;
struct i915_gem_proto_engine *engines;
};
static int
set_proto_ctx_engines_balance(struct i915_user_extension __user *base,
void *data)
{
struct i915_context_engines_load_balance __user *ext =
container_of_user(base, typeof(*ext), base);
const struct set_proto_ctx_engines *set = data;
struct drm_i915_private *i915 = set->i915;
struct intel_engine_cs **siblings;
u16 num_siblings, idx;
unsigned int n;
int err;
if (!HAS_EXECLISTS(i915))
return -ENODEV;
if (get_user(idx, &ext->engine_index))
return -EFAULT;
if (idx >= set->num_engines) {
drm_dbg(&i915->drm, "Invalid placement value, %d >= %d\n",
idx, set->num_engines);
return -EINVAL;
}
idx = array_index_nospec(idx, set->num_engines);
if (set->engines[idx].type != I915_GEM_ENGINE_TYPE_INVALID) {
drm_dbg(&i915->drm,
"Invalid placement[%d], already occupied\n", idx);
return -EEXIST;
}
if (get_user(num_siblings, &ext->num_siblings))
return -EFAULT;
err = check_user_mbz(&ext->flags);
if (err)
return err;
err = check_user_mbz(&ext->mbz64);
if (err)
return err;
if (num_siblings == 0)
return 0;
siblings = kmalloc_objs(*siblings, num_siblings);
if (!siblings)
return -ENOMEM;
for (n = 0; n < num_siblings; n++) {
struct i915_engine_class_instance ci;
if (copy_from_user(&ci, &ext->engines[n], sizeof(ci))) {
err = -EFAULT;
goto err_siblings;
}
siblings[n] = intel_engine_lookup_user(i915,
ci.engine_class,
ci.engine_instance);
if (!siblings[n]) {
drm_dbg(&i915->drm,
"Invalid sibling[%d]: { class:%d, inst:%d }\n",
n, ci.engine_class, ci.engine_instance);
err = -EINVAL;
goto err_siblings;
}
}
if (num_siblings == 1) {
set->engines[idx].type = I915_GEM_ENGINE_TYPE_PHYSICAL;
set->engines[idx].engine = siblings[0];
kfree(siblings);
} else {
set->engines[idx].type = I915_GEM_ENGINE_TYPE_BALANCED;
set->engines[idx].num_siblings = num_siblings;
set->engines[idx].siblings = siblings;
}
return 0;
err_siblings:
kfree(siblings);
Annotation
- Immediate include surface: `linux/highmem.h`, `linux/log2.h`, `linux/nospec.h`, `drm/drm_cache.h`, `drm/drm_print.h`, `drm/drm_syncobj.h`, `gt/gen6_ppgtt.h`, `gt/intel_context.h`.
- Detected declarations: `struct set_proto_ctx_engines`, `struct create_ext`, `function i915_lut_handle_free`, `function lut_close`, `function list_for_each_entry`, `function lookup_user_engine`, `function validate_priority`, `function proto_context_close`, `function proto_context_set_persistence`, `function proto_context_set_protected`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.