drivers/accel/amdxdna/aie2_ctx.c
Source file repositories/reference/linux-study-clean/drivers/accel/amdxdna/aie2_ctx.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/accel/amdxdna/aie2_ctx.c- Extension
.c- Size
- 30904 bytes
- Lines
- 1208
- 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.
- 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_gem.hdrm/drm_gem_shmem_helper.hdrm/drm_print.hdrm/drm_syncobj.hlinux/hmm.hlinux/types.hlinux/xarray.htrace/events/amdxdna.haie2_msg_priv.haie2_pci.haie2_solver.hamdxdna_ctx.hamdxdna_gem.hamdxdna_mailbox.hamdxdna_pci_drv.hamdxdna_pm.h
Detected Declarations
struct aie2_ctx_healthfunction aie2_tdr_signalfunction aie2_tdr_detectfunction aie2_job_releasefunction aie2_job_putfunction aie2_hwctx_stopfunction aie2_hwctx_restartfunction xa_for_each_rangefunction aie2_hwctx_wait_for_idlefunction aie2_hwctx_suspend_cbfunction aie2_hwctx_suspendfunction aie2_hwctx_resume_cbfunction aie2_hwctx_resumefunction aie2_sched_notifyfunction aie2_set_cmd_timeoutfunction aie2_sched_resp_handlerfunction aie2_sched_drvcmd_resp_handlerfunction aie2_sched_cmdlist_resp_handlerfunction aie2_sched_job_runfunction aie2_sched_job_freefunction aie2_sched_job_timedoutfunction aie2_hwctx_col_listfunction aie2_alloc_resourcefunction aie2_release_resourcefunction aie2_ctx_syncobj_createfunction aie2_ctx_syncobj_destroyfunction aie2_hwctx_initfunction aie2_hwctx_finifunction aie2_config_cu_resp_handlerfunction aie2_hwctx_cu_configfunction aie2_cmd_waitfunction aie2_hwctx_cfg_debug_bofunction aie2_hwctx_configfunction aie2_hwctx_sync_debug_bofunction aie2_populate_rangefunction aie2_cmd_submitfunction aie2_hmm_invalidatefunction aie2_hwctx_heap_expand
Annotated Snippet
struct aie2_ctx_health {
struct amdxdna_ctx_health header;
u32 txn_op_idx;
u32 ctx_pc;
u32 fatal_error_type;
u32 fatal_error_exception_type;
u32 fatal_error_exception_pc;
u32 fatal_error_app_module;
};
static inline void aie2_tdr_signal(struct amdxdna_dev *xdna)
{
WRITE_ONCE(xdna->dev_handle->tdr_status, AIE2_TDR_SIGNALED);
}
static bool aie2_tdr_detect(struct amdxdna_dev *xdna)
{
struct amdxdna_dev_hdl *ndev = xdna->dev_handle;
if (READ_ONCE(ndev->tdr_status) == AIE2_TDR_WAIT) {
XDNA_ERR(xdna, "TDR timeout detected");
return true;
}
WRITE_ONCE(ndev->tdr_status, AIE2_TDR_WAIT);
return false;
}
static void aie2_job_release(struct kref *ref)
{
struct amdxdna_sched_job *job;
job = container_of(ref, struct amdxdna_sched_job, refcnt);
amdxdna_sched_job_cleanup(job);
atomic64_inc(&job->hwctx->job_free_cnt);
wake_up(&job->hwctx->priv->job_free_wq);
if (job->out_fence)
dma_fence_put(job->out_fence);
kfree(job->aie2_job_health);
kfree(job);
}
static void aie2_job_put(struct amdxdna_sched_job *job)
{
kref_put(&job->refcnt, aie2_job_release);
}
/* The bad_job is used in aie2_sched_job_timedout, otherwise, set it to NULL */
static void aie2_hwctx_stop(struct amdxdna_dev *xdna, struct amdxdna_hwctx *hwctx,
struct drm_sched_job *bad_job)
{
drm_sched_stop(&hwctx->priv->sched, bad_job);
aie2_destroy_context(xdna->dev_handle, hwctx);
drm_sched_start(&hwctx->priv->sched, 0);
}
static int aie2_hwctx_restart(struct amdxdna_dev *xdna, struct amdxdna_hwctx *hwctx)
{
struct amdxdna_gem_obj *heap = hwctx->priv->heap;
unsigned long heap_id;
int ret;
ret = aie2_create_context(xdna->dev_handle, hwctx);
if (ret) {
XDNA_ERR(xdna, "Create hwctx failed, ret %d", ret);
goto out;
}
ret = aie2_map_host_buf(xdna->dev_handle, hwctx->fw_ctx_id,
amdxdna_obj_dma_addr(heap),
heap->mem.size);
if (ret) {
XDNA_ERR(xdna, "Map host buf failed, ret %d", ret);
goto out;
}
xa_for_each_range(&hwctx->client->dev_heap_xa, heap_id, heap, 1,
hwctx->last_attached_heap) {
ret = aie2_add_host_buf(xdna->dev_handle, hwctx->fw_ctx_id,
amdxdna_obj_dma_addr(heap),
heap->mem.size);
if (ret) {
XDNA_ERR(xdna, "Add heap %ld failed ret %d", heap_id, ret);
goto out;
}
}
ret = aie2_config_cu(hwctx, NULL);
if (ret) {
Annotation
- Immediate include surface: `drm/amdxdna_accel.h`, `drm/drm_device.h`, `drm/drm_gem.h`, `drm/drm_gem_shmem_helper.h`, `drm/drm_print.h`, `drm/drm_syncobj.h`, `linux/hmm.h`, `linux/types.h`.
- Detected declarations: `struct aie2_ctx_health`, `function aie2_tdr_signal`, `function aie2_tdr_detect`, `function aie2_job_release`, `function aie2_job_put`, `function aie2_hwctx_stop`, `function aie2_hwctx_restart`, `function xa_for_each_range`, `function aie2_hwctx_wait_for_idle`, `function aie2_hwctx_suspend_cb`.
- Atlas domain: Driver Families / drivers/accel.
- 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.