drivers/accel/habanalabs/common/habanalabs_drv.c
Source file repositories/reference/linux-study-clean/drivers/accel/habanalabs/common/habanalabs_drv.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/accel/habanalabs/common/habanalabs_drv.c- Extension
.c- Size
- 18309 bytes
- Lines
- 785
- 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.
- 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.h../include/hw_ip/pci/pci_general.hlinux/pci.hlinux/module.hlinux/vmalloc.hlinux/version.hdrm/drm_accel.hdrm/drm_drv.hdrm/drm_ioctl.htrace/events/habanalabs.h
Detected Declarations
function get_asic_typefunction is_asic_securedfunction hl_device_openfunction hl_device_open_ctrlfunction set_driver_behavior_per_devicefunction copy_kernel_module_params_to_devicefunction fixup_device_params_per_asicfunction fixup_device_paramsfunction allocate_device_idfunction IDfunction destroy_hdevfunction hl_pmops_suspendfunction hl_pmops_resumefunction hl_pci_probefunction hl_pci_removefunction hl_pci_err_detectedfunction hl_pci_err_resumefunction hl_pci_err_slot_resetfunction hl_pci_reset_preparefunction hl_pci_reset_donefunction hl_initfunction hl_exitmodule init hl_init
Annotated Snippet
static const struct file_operations hl_fops = {
.owner = THIS_MODULE,
.open = accel_open,
.release = drm_release,
.unlocked_ioctl = drm_ioctl,
.compat_ioctl = drm_compat_ioctl,
.llseek = noop_llseek,
.mmap = hl_mmap
};
static const struct drm_driver hl_driver = {
.driver_features = DRIVER_COMPUTE_ACCEL,
.name = HL_NAME,
.desc = HL_DRIVER_DESC,
.major = LINUX_VERSION_MAJOR,
.minor = LINUX_VERSION_PATCHLEVEL,
.patchlevel = LINUX_VERSION_SUBLEVEL,
.fops = &hl_fops,
.open = hl_device_open,
.postclose = hl_device_release,
.ioctls = hl_drm_ioctls,
.num_ioctls = ARRAY_SIZE(hl_drm_ioctls)
};
/*
* get_asic_type - translate device id to asic type
*
* @hdev: pointer to habanalabs device structure.
*
* Translate device id and revision id to asic type.
* In case of unidentified device, return -1
*/
static enum hl_asic_type get_asic_type(struct hl_device *hdev)
{
struct pci_dev *pdev = hdev->pdev;
enum hl_asic_type asic_type = ASIC_INVALID;
switch (pdev->device) {
case PCI_IDS_GOYA:
asic_type = ASIC_GOYA;
break;
case PCI_IDS_GAUDI:
asic_type = ASIC_GAUDI;
break;
case PCI_IDS_GAUDI_SEC:
asic_type = ASIC_GAUDI_SEC;
break;
case PCI_IDS_GAUDI2:
switch (pdev->revision) {
case REV_ID_A:
asic_type = ASIC_GAUDI2;
break;
case REV_ID_B:
asic_type = ASIC_GAUDI2B;
break;
case REV_ID_C:
asic_type = ASIC_GAUDI2C;
break;
case REV_ID_D:
asic_type = ASIC_GAUDI2D;
break;
default:
break;
}
break;
default:
break;
}
return asic_type;
}
static bool is_asic_secured(enum hl_asic_type asic_type)
{
switch (asic_type) {
case ASIC_GAUDI_SEC:
return true;
default:
return false;
}
}
/*
* hl_device_open() - open function for habanalabs device.
* @ddev: pointer to DRM device structure.
* @file: pointer to DRM file private data structure.
*
* Called when process opens an habanalabs device.
Annotation
- Immediate include surface: `habanalabs.h`, `../include/hw_ip/pci/pci_general.h`, `linux/pci.h`, `linux/module.h`, `linux/vmalloc.h`, `linux/version.h`, `drm/drm_accel.h`, `drm/drm_drv.h`.
- Detected declarations: `function get_asic_type`, `function is_asic_secured`, `function hl_device_open`, `function hl_device_open_ctrl`, `function set_driver_behavior_per_device`, `function copy_kernel_module_params_to_device`, `function fixup_device_params_per_asic`, `function fixup_device_params`, `function allocate_device_id`, `function ID`.
- 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.
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.