drivers/accel/amdxdna/amdxdna_ctx.c
Source file repositories/reference/linux-study-clean/drivers/accel/amdxdna/amdxdna_ctx.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/accel/amdxdna/amdxdna_ctx.c- Extension
.c- Size
- 18186 bytes
- Lines
- 740
- Domain
- Driver Families
- Bucket
- drivers/accel
- 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 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
drm/amdxdna_accel.hdrm/drm_device.hdrm/drm_drv.hdrm/drm_file.hdrm/drm_gem.hdrm/drm_gem_shmem_helper.hdrm/drm_print.hdrm/gpu_scheduler.hlinux/xarray.htrace/events/amdxdna.hamdxdna_ctx.hamdxdna_gem.hamdxdna_pci_drv.hamdxdna_pm.h
Detected Declarations
struct amdxdna_fencefunction amdxdna_hwctx_release_expanded_heapfunction xa_for_each_rangefunction amdxdna_hwctx_destroy_rcufunction amdxdna_hwctx_walkfunction amdxdna_cmd_get_cu_idxfunction amdxdna_cmd_set_errorfunction closefunction amdxdna_for_each_hwctxfunction amdxdna_drm_create_hwctx_ioctlfunction amdxdna_drm_destroy_hwctx_ioctlfunction amdxdna_drm_config_hwctx_ioctlfunction amdxdna_hwctx_sync_debug_bofunction amdxdna_hwctx_expand_heapfunction xa_for_each_rangefunction amdxdna_update_heapfunction amdxdna_for_each_hwctxfunction amdxdna_arg_bos_putfunction amdxdna_arg_bos_lookupfunction amdxdna_sched_job_cleanupfunction amdxdna_cmd_submitfunction amdxdna_drm_submit_execbuffunction amdxdna_drm_submit_cmd_ioctlfunction amdxdna_drm_wait_cmd_ioctl
Annotated Snippet
struct amdxdna_fence {
struct dma_fence base;
spinlock_t lock; /* for base */
struct amdxdna_hwctx *hwctx;
};
static const char *amdxdna_fence_get_driver_name(struct dma_fence *fence)
{
return KBUILD_MODNAME;
}
static const char *amdxdna_fence_get_timeline_name(struct dma_fence *fence)
{
struct amdxdna_fence *xdna_fence;
xdna_fence = container_of(fence, struct amdxdna_fence, base);
return xdna_fence->hwctx->name;
}
static const struct dma_fence_ops fence_ops = {
.get_driver_name = amdxdna_fence_get_driver_name,
.get_timeline_name = amdxdna_fence_get_timeline_name,
};
static struct dma_fence *amdxdna_fence_create(struct amdxdna_hwctx *hwctx)
{
struct amdxdna_fence *fence;
fence = kzalloc_obj(*fence);
if (!fence)
return NULL;
fence->hwctx = hwctx;
spin_lock_init(&fence->lock);
dma_fence_init(&fence->base, &fence_ops, &fence->lock, hwctx->id, 0);
return &fence->base;
}
static void amdxdna_hwctx_release_expanded_heap(struct amdxdna_hwctx *hwctx)
{
struct amdxdna_client *client = hwctx->client;
struct amdxdna_gem_obj *heap;
unsigned long heap_id;
mutex_lock(&client->mm_lock);
if (hwctx->last_attached_heap) {
xa_for_each_range(&client->dev_heap_xa, heap_id, heap, 1,
hwctx->last_attached_heap) {
amdxdna_gem_unpin(heap);
drm_gem_object_put(to_gobj(heap));
}
}
mutex_unlock(&client->mm_lock);
}
static void amdxdna_hwctx_destroy_rcu(struct amdxdna_hwctx *hwctx,
struct srcu_struct *ss)
{
struct amdxdna_client *client = hwctx->client;
struct amdxdna_dev *xdna = client->xdna;
synchronize_srcu(ss);
/* At this point, user is not able to submit new commands */
xdna->dev_info->ops->hwctx_fini(hwctx);
amdxdna_hwctx_release_expanded_heap(hwctx);
kfree(hwctx->name);
kfree(hwctx);
}
int amdxdna_hwctx_walk(struct amdxdna_client *client, void *arg,
int (*walk)(struct amdxdna_hwctx *hwctx, void *arg))
{
struct amdxdna_hwctx *hwctx;
unsigned long hwctx_id;
int ret = 0, idx;
idx = srcu_read_lock(&client->hwctx_srcu);
amdxdna_for_each_hwctx(client, hwctx_id, hwctx) {
ret = walk(hwctx, arg);
if (ret)
break;
}
srcu_read_unlock(&client->hwctx_srcu, idx);
return ret;
}
Annotation
- Immediate include surface: `drm/amdxdna_accel.h`, `drm/drm_device.h`, `drm/drm_drv.h`, `drm/drm_file.h`, `drm/drm_gem.h`, `drm/drm_gem_shmem_helper.h`, `drm/drm_print.h`, `drm/gpu_scheduler.h`.
- Detected declarations: `struct amdxdna_fence`, `function amdxdna_hwctx_release_expanded_heap`, `function xa_for_each_range`, `function amdxdna_hwctx_destroy_rcu`, `function amdxdna_hwctx_walk`, `function amdxdna_cmd_get_cu_idx`, `function amdxdna_cmd_set_error`, `function close`, `function amdxdna_for_each_hwctx`, `function amdxdna_drm_create_hwctx_ioctl`.
- Atlas domain: Driver Families / drivers/accel.
- Implementation status: source 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.