drivers/accel/habanalabs/common/habanalabs_ioctl.c
Source file repositories/reference/linux-study-clean/drivers/accel/habanalabs/common/habanalabs_ioctl.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/accel/habanalabs/common/habanalabs_ioctl.c- Extension
.c- Size
- 37263 bytes
- Lines
- 1320
- 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/fs.hlinux/kernel.hlinux/pci.hlinux/slab.hlinux/uaccess.hlinux/vmalloc.h
Detected Declarations
function device_status_infofunction hw_ip_infofunction hw_events_infofunction events_infofunction dram_usage_infofunction hw_idlefunction debug_coresightfunction device_utilizationfunction get_clk_ratefunction get_reset_countfunction time_sync_infofunction pci_counters_infofunction clk_throttle_infofunction cs_counters_infofunction sync_manager_infofunction total_energy_consumption_infofunction pll_frequency_infofunction power_infofunction open_stats_infofunction dram_pending_rows_infofunction dram_replaced_rows_infofunction last_err_open_dev_infofunction cs_timeout_infofunction razwi_infofunction undefined_opcode_infofunction dev_mem_alloc_page_sizes_infofunction sec_attest_infofunction dev_info_signedfunction eventfd_registerfunction eventfd_unregisterfunction engine_status_infofunction page_fault_infofunction user_mappings_infofunction hw_err_infofunction fw_err_infofunction engine_err_infofunction send_fw_generic_requestfunction _hl_info_ioctlfunction hl_info_ioctlfunction hl_info_ioctl_controlfunction hl_debug_ioctlfunction _hl_ioctlfunction hl_ioctl_control
Annotated Snippet
if (!input) {
rc = -ENOMEM;
goto out;
}
if (copy_from_user(input, u64_to_user_ptr(args->input_ptr),
args->input_size)) {
rc = -EFAULT;
dev_err(hdev->dev, "failed to copy input debug data\n");
goto out;
}
params->input = input;
}
if (args->output_ptr && args->output_size) {
output = kzalloc(args->output_size, GFP_KERNEL);
if (!output) {
rc = -ENOMEM;
goto out;
}
params->output = output;
params->output_size = args->output_size;
}
rc = hdev->asic_funcs->debug_coresight(hdev, ctx, params);
if (rc) {
dev_err(hdev->dev,
"debug coresight operation failed %d\n", rc);
goto out;
}
if (output && copy_to_user((void __user *) (uintptr_t) args->output_ptr,
output, args->output_size)) {
dev_err(hdev->dev, "copy to user failed in debug ioctl\n");
rc = -EFAULT;
goto out;
}
out:
kfree(params);
kfree(output);
kfree(input);
return rc;
}
static int device_utilization(struct hl_device *hdev, struct hl_info_args *args)
{
struct hl_info_device_utilization device_util = {0};
u32 max_size = args->return_size;
void __user *out = (void __user *) (uintptr_t) args->return_pointer;
int rc;
if ((!max_size) || (!out))
return -EINVAL;
rc = hl_device_utilization(hdev, &device_util.utilization);
if (rc)
return -EINVAL;
return copy_to_user(out, &device_util,
min((size_t) max_size, sizeof(device_util))) ? -EFAULT : 0;
}
static int get_clk_rate(struct hl_device *hdev, struct hl_info_args *args)
{
struct hl_info_clk_rate clk_rate = {0};
u32 max_size = args->return_size;
void __user *out = (void __user *) (uintptr_t) args->return_pointer;
int rc;
if ((!max_size) || (!out))
return -EINVAL;
rc = hl_fw_get_clk_rate(hdev, &clk_rate.cur_clk_rate_mhz, &clk_rate.max_clk_rate_mhz);
if (rc)
return rc;
return copy_to_user(out, &clk_rate, min_t(size_t, max_size, sizeof(clk_rate)))
? -EFAULT : 0;
}
static int get_reset_count(struct hl_device *hdev, struct hl_info_args *args)
{
struct hl_info_reset_count reset_count = {0};
u32 max_size = args->return_size;
void __user *out = (void __user *) (uintptr_t) args->return_pointer;
Annotation
- Immediate include surface: `uapi/drm/habanalabs_accel.h`, `habanalabs.h`, `linux/fs.h`, `linux/kernel.h`, `linux/pci.h`, `linux/slab.h`, `linux/uaccess.h`, `linux/vmalloc.h`.
- Detected declarations: `function device_status_info`, `function hw_ip_info`, `function hw_events_info`, `function events_info`, `function dram_usage_info`, `function hw_idle`, `function debug_coresight`, `function device_utilization`, `function get_clk_rate`, `function get_reset_count`.
- 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.