drivers/accel/habanalabs/common/command_submission.c
Source file repositories/reference/linux-study-clean/drivers/accel/habanalabs/common/command_submission.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/accel/habanalabs/common/command_submission.c- Extension
.c- Size
- 103982 bytes
- Lines
- 3743
- 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
uapi/drm/habanalabs_accel.hhabanalabs.hlinux/uaccess.hlinux/slab.h
Detected Declarations
struct wait_interrupt_dataenum hl_cs_wait_statusfunction hl_push_cs_outcomefunction hl_pop_cs_outcomefunction hash_for_each_possiblefunction hl_sob_resetfunction hl_sob_reset_errorfunction hw_sob_putfunction hw_sob_put_errfunction hw_sob_getfunction hl_gen_sob_maskfunction hl_fence_releasefunction hl_fence_putfunction hl_fences_putfunction hl_fence_getfunction hl_fence_initfunction cs_getfunction cs_get_unless_zerofunction cs_putfunction cs_job_do_releasefunction hl_cs_job_putfunction cs_needs_completionfunction cs_needs_timeoutfunction is_cb_patchedfunction cs_parserfunction hl_complete_jobfunction is_staged_cs_last_existsfunction staged_cs_getfunction referencefunction cs_handle_tdrfunction force_complete_multi_csfunction complete_multi_csfunction cs_release_sob_reset_handlerfunction cs_do_releasefunction cs_timedoutfunction allocate_csfunction cs_rollbackfunction release_reserved_encaps_signalsfunction hl_cs_rollback_allfunction wake_pending_user_interrupt_threadsfunction hl_release_pending_user_interruptsfunction force_complete_csfunction list_for_each_entryfunction hl_abort_waiting_for_cs_completionsfunction job_wq_completionfunction cs_completionfunction hl_get_active_cs_numfunction validate_queue_index
Annotated Snippet
rc = hdev->asic_funcs->context_switch(hdev, ctx->asid);
if (rc) {
dev_err_ratelimited(hdev->dev,
"Failed to switch to context %d, rejecting CS! %d\n",
ctx->asid, rc);
/*
* If we timedout, or if the device is not IDLE
* while we want to do context-switch (-EBUSY),
* we need to soft-reset because QMAN is
* probably stuck. However, we can't call to
* reset here directly because of deadlock, so
* need to do it at the very end of this
* function
*/
if ((rc == -ETIMEDOUT) || (rc == -EBUSY))
need_soft_reset = true;
mutex_unlock(&hpriv->restore_phase_mutex);
goto out;
}
}
hdev->asic_funcs->restore_phase_topology(hdev);
chunks = (void __user *) (uintptr_t) args->in.chunks_restore;
num_chunks = args->in.num_chunks_restore;
if (!num_chunks) {
dev_dbg(hdev->dev,
"Need to run restore phase but restore CS is empty\n");
rc = 0;
} else {
rc = cs_ioctl_default(hpriv, chunks, num_chunks,
cs_seq, 0, 0, hdev->timeout_jiffies, &sob_count);
}
mutex_unlock(&hpriv->restore_phase_mutex);
if (rc) {
dev_err(hdev->dev,
"Failed to submit restore CS for context %d (%d)\n",
ctx->asid, rc);
goto out;
}
/* Need to wait for restore completion before execution phase */
if (num_chunks) {
enum hl_cs_wait_status status;
ret = _hl_cs_wait_ioctl(hdev, ctx,
jiffies_to_usecs(hdev->timeout_jiffies),
*cs_seq, &status, NULL);
if (ret) {
dev_err(hdev->dev,
"Restore CS for context %d failed to complete %d\n",
ctx->asid, ret);
rc = -ENOEXEC;
goto out;
}
}
if (hdev->supports_ctx_switch)
ctx->thread_ctx_switch_wait_token = 1;
} else if (hdev->supports_ctx_switch && !ctx->thread_ctx_switch_wait_token) {
rc = hl_poll_timeout_memory(hdev,
&ctx->thread_ctx_switch_wait_token, tmp, (tmp == 1),
100, jiffies_to_usecs(hdev->timeout_jiffies), false);
if (rc == -ETIMEDOUT) {
dev_err(hdev->dev,
"context switch phase timeout (%d)\n", tmp);
goto out;
}
}
out:
if ((rc == -ETIMEDOUT || rc == -EBUSY) && (need_soft_reset))
hl_device_reset(hdev, 0);
return rc;
}
/*
* hl_cs_signal_sob_wraparound_handler: handle SOB value wrapaound case.
* if the SOB value reaches the max value move to the other SOB reserved
* to the queue.
* @hdev: pointer to device structure
* @q_idx: stream queue index
* @hw_sob: the H/W SOB used in this signal CS.
* @count: signals count
Annotation
- Immediate include surface: `uapi/drm/habanalabs_accel.h`, `habanalabs.h`, `linux/uaccess.h`, `linux/slab.h`.
- Detected declarations: `struct wait_interrupt_data`, `enum hl_cs_wait_status`, `function hl_push_cs_outcome`, `function hl_pop_cs_outcome`, `function hash_for_each_possible`, `function hl_sob_reset`, `function hl_sob_reset_error`, `function hw_sob_put`, `function hw_sob_put_err`, `function hw_sob_get`.
- 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.