drivers/accel/habanalabs/common/device.c
Source file repositories/reference/linux-study-clean/drivers/accel/habanalabs/common/device.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/accel/habanalabs/common/device.c- Extension
.c- Size
- 83762 bytes
- Lines
- 2966
- Domain
- Driver Families
- Bucket
- drivers/accel
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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
uapi/drm/habanalabs_accel.hhabanalabs.hlinux/pci.hlinux/hwmon.hlinux/vmalloc.hdrm/drm_accel.hdrm/drm_drv.htrace/events/habanalabs.h
Detected Declarations
enum dma_alloc_typefunction hl_set_dram_barfunction hl_access_sram_dram_regionfunction hl_asic_dma_free_commonfunction hl_asic_dma_free_coherent_callerfunction hl_asic_dma_pool_free_callerfunction hl_cpu_accessible_dma_pool_freefunction hl_dma_map_sgtable_callerfunction hl_asic_dma_map_sgtablefunction hl_dma_unmap_sgtable_callerfunction hl_asic_dma_unmap_sgtablefunction hl_access_cfg_regionfunction hl_access_dev_memfunction hl_engine_data_sprintffunction hl_device_statusfunction hl_device_operationalfunction hl_ctrl_device_operationalfunction print_idle_status_maskfunction hpriv_releasefunction hl_hpriv_getfunction hl_hpriv_putfunction print_device_in_use_infofunction hl_device_releasefunction hl_device_release_ctrlfunction __hl_mmapfunction hl_mmapfunction device_release_funcfunction device_init_cdevfunction cdev_sysfs_debugfs_addfunction cdev_sysfs_debugfs_removefunction device_hard_reset_pendingfunction device_release_watchdog_funcfunction device_early_initfunction device_early_finifunction is_pci_link_healthyfunction hl_device_eq_heartbeat_receivedfunction hl_device_heartbeatfunction device_late_initfunction device_late_finifunction hl_device_utilizationfunction hl_device_set_debug_modefunction take_release_locksfunction hl_abort_waiting_for_completionsfunction cleanup_resourcesfunction statefunction statefunction device_kill_open_processesfunction device_disable_open_processes
Annotated Snippet
static const struct file_operations hl_ctrl_ops = {
.owner = THIS_MODULE,
.open = hl_device_open_ctrl,
.release = hl_device_release_ctrl,
.unlocked_ioctl = hl_ioctl_control,
.compat_ioctl = hl_ioctl_control
};
static void device_release_func(struct device *dev)
{
kfree(dev);
}
/*
* device_init_cdev - Initialize cdev and device for habanalabs device
*
* @hdev: pointer to habanalabs device structure
* @class: pointer to the class object of the device
* @minor: minor number of the specific device
* @fops: file operations to install for this device
* @name: name of the device as it will appear in the filesystem
* @cdev: pointer to the char device object that will be initialized
* @dev: pointer to the device object that will be initialized
*
* Initialize a cdev and a Linux device for habanalabs's device.
*/
static int device_init_cdev(struct hl_device *hdev, const struct class *class,
int minor, const struct file_operations *fops,
char *name, struct cdev *cdev,
struct device **dev)
{
cdev_init(cdev, fops);
cdev->owner = THIS_MODULE;
*dev = kzalloc_obj(**dev);
if (!*dev)
return -ENOMEM;
device_initialize(*dev);
(*dev)->devt = MKDEV(hdev->major, minor);
(*dev)->class = class;
(*dev)->release = device_release_func;
dev_set_drvdata(*dev, hdev);
dev_set_name(*dev, "%s", name);
return 0;
}
static int cdev_sysfs_debugfs_add(struct hl_device *hdev)
{
const struct class *accel_class = hdev->drm.accel->kdev->class;
char name[32];
int rc;
hdev->cdev_idx = hdev->drm.accel->index;
/* Initialize cdev and device structures for the control device */
snprintf(name, sizeof(name), "accel_controlD%d", hdev->cdev_idx);
rc = device_init_cdev(hdev, accel_class, hdev->cdev_idx, &hl_ctrl_ops, name,
&hdev->cdev_ctrl, &hdev->dev_ctrl);
if (rc)
return rc;
rc = cdev_device_add(&hdev->cdev_ctrl, hdev->dev_ctrl);
if (rc) {
dev_err(hdev->dev_ctrl,
"failed to add an accel control char device to the system\n");
goto free_ctrl_device;
}
rc = hl_sysfs_init(hdev);
if (rc) {
dev_err(hdev->dev, "failed to initialize sysfs\n");
goto delete_ctrl_cdev_device;
}
hl_debugfs_add_device(hdev);
hdev->cdev_sysfs_debugfs_created = true;
return 0;
delete_ctrl_cdev_device:
cdev_device_del(&hdev->cdev_ctrl, hdev->dev_ctrl);
free_ctrl_device:
put_device(hdev->dev_ctrl);
return rc;
}
static void cdev_sysfs_debugfs_remove(struct hl_device *hdev)
Annotation
- Immediate include surface: `uapi/drm/habanalabs_accel.h`, `habanalabs.h`, `linux/pci.h`, `linux/hwmon.h`, `linux/vmalloc.h`, `drm/drm_accel.h`, `drm/drm_drv.h`, `trace/events/habanalabs.h`.
- Detected declarations: `enum dma_alloc_type`, `function hl_set_dram_bar`, `function hl_access_sram_dram_region`, `function hl_asic_dma_free_common`, `function hl_asic_dma_free_coherent_caller`, `function hl_asic_dma_pool_free_caller`, `function hl_cpu_accessible_dma_pool_free`, `function hl_dma_map_sgtable_caller`, `function hl_asic_dma_map_sgtable`, `function hl_dma_unmap_sgtable_caller`.
- Atlas domain: Driver Families / drivers/accel.
- Implementation status: pattern 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.