drivers/accel/habanalabs/common/hw_queue.c
Source file repositories/reference/linux-study-clean/drivers/accel/habanalabs/common/hw_queue.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/accel/habanalabs/common/hw_queue.c- Extension
.c- Size
- 31350 bytes
- Lines
- 1155
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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
habanalabs.hlinux/slab.h
Detected Declarations
function hl_hw_queue_add_ptrfunction queue_ci_getfunction queue_free_slotsfunction hl_hw_queue_update_cifunction hl_hw_queue_submit_bdfunction ext_queue_sanity_checksfunction int_queue_sanity_checksfunction hw_queue_sanity_checksfunction hl_hw_queue_send_cb_no_cmplfunction hl_hw_queue_send_cb_no_cmplfunction ext_queue_schedule_jobfunction int_queue_schedule_jobfunction hw_queue_schedule_jobfunction init_signal_csfunction hl_hw_queue_encaps_sig_set_sob_infofunction init_wait_csfunction init_signal_wait_csfunction encaps_sig_first_staged_cs_handlerfunction hl_hw_queue_schedule_csfunction list_for_each_entry_safefunction hl_hw_queue_inc_ci_kernelfunction ext_and_cpu_queue_initfunction int_queue_initfunction cpu_queue_initfunction ext_queue_initfunction hw_queue_initfunction sync_stream_queue_initfunction sync_stream_queue_resetfunction queue_initfunction queue_finifunction hl_hw_queues_createfunction hl_hw_queues_destroyfunction hl_hw_queue_reset
Annotated Snippet
if (atomic_add_negative(num_of_entries * -1, free_slots)) {
dev_dbg(hdev->dev, "No space for %d on CQ %d\n",
num_of_entries, q->hw_queue_id);
atomic_add(num_of_entries, free_slots);
return -EAGAIN;
}
}
return 0;
}
/*
* int_queue_sanity_checks - perform some sanity checks on internal queue
*
* @hdev : pointer to hl_device structure
* @q : pointer to hl_hw_queue structure
* @num_of_entries : how many entries to check for space
*
* H/W queues spinlock should be taken before calling this function
*
* Perform the following:
* - Make sure we have enough space in the h/w queue
*
*/
static int int_queue_sanity_checks(struct hl_device *hdev,
struct hl_hw_queue *q,
int num_of_entries)
{
int free_slots_cnt;
if (num_of_entries > q->int_queue_len) {
dev_err(hdev->dev,
"Cannot populate queue %u with %u jobs\n",
q->hw_queue_id, num_of_entries);
return -ENOMEM;
}
/* Check we have enough space in the queue */
free_slots_cnt = queue_free_slots(q, q->int_queue_len);
if (free_slots_cnt < num_of_entries) {
dev_dbg(hdev->dev, "Queue %d doesn't have room for %d CBs\n",
q->hw_queue_id, num_of_entries);
return -EAGAIN;
}
return 0;
}
/*
* hw_queue_sanity_checks() - Make sure we have enough space in the h/w queue
* @hdev: Pointer to hl_device structure.
* @q: Pointer to hl_hw_queue structure.
* @num_of_entries: How many entries to check for space.
*
* Notice: We do not reserve queue entries so this function mustn't be called
* more than once per CS for the same queue
*
*/
static int hw_queue_sanity_checks(struct hl_device *hdev, struct hl_hw_queue *q,
int num_of_entries)
{
int free_slots_cnt;
/* Check we have enough space in the queue */
free_slots_cnt = queue_free_slots(q, HL_QUEUE_LENGTH);
if (free_slots_cnt < num_of_entries) {
dev_dbg(hdev->dev, "Queue %d doesn't have room for %d CBs\n",
q->hw_queue_id, num_of_entries);
return -EAGAIN;
}
return 0;
}
/*
* hl_hw_queue_send_cb_no_cmpl - send a single CB (not a JOB) without completion
*
* @hdev: pointer to hl_device structure
* @hw_queue_id: Queue's type
* @cb_size: size of CB
* @cb_ptr: pointer to CB location
*
* This function sends a single CB, that must NOT generate a completion entry.
* Sending CPU messages can be done instead via 'hl_hw_queue_submit_bd()'
*/
int hl_hw_queue_send_cb_no_cmpl(struct hl_device *hdev, u32 hw_queue_id,
u32 cb_size, u64 cb_ptr)
{
Annotation
- Immediate include surface: `habanalabs.h`, `linux/slab.h`.
- Detected declarations: `function hl_hw_queue_add_ptr`, `function queue_ci_get`, `function queue_free_slots`, `function hl_hw_queue_update_ci`, `function hl_hw_queue_submit_bd`, `function ext_queue_sanity_checks`, `function int_queue_sanity_checks`, `function hw_queue_sanity_checks`, `function hl_hw_queue_send_cb_no_cmpl`, `function hl_hw_queue_send_cb_no_cmpl`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.