drivers/accel/habanalabs/common/hldio.c
Source file repositories/reference/linux-study-clean/drivers/accel/habanalabs/common/hldio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/accel/habanalabs/common/hldio.c- Extension
.c- Size
- 10104 bytes
- Lines
- 438
- 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.
- 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.hhldio.hgenerated/uapi/linux/version.hlinux/pci-p2pdma.hlinux/blkdev.hlinux/vmalloc.h
Detected Declarations
struct hl_dio_fdstruct hl_direct_iofunction hl_device_supports_nvmefunction hl_dio_fd_registerfunction hl_dio_fd_unregisterfunction hl_dio_count_iofunction hl_dio_get_iopathfunction hl_dio_put_iopathfunction hl_dio_set_io_enabledfunction hl_dio_validate_iofunction hl_direct_iofunction hl_direct_io_completefunction hl_dio_ssd2hlfunction hl_p2p_region_finifunction hl_p2p_region_fini_allfunction hl_p2p_region_initfunction hl_dio_startfunction hl_dio_stop
Annotated Snippet
struct hl_dio_fd {
/* Back pointer in case we need it in async completion */
struct hl_ctx *ctx;
/* Associated fd struct */
struct file *filp;
};
/*
* This is a single IO descriptor
*/
struct hl_direct_io {
struct hl_dio_fd f;
struct kiocb kio;
struct bio_vec *bv;
struct iov_iter iter;
u64 device_va;
u64 off_bytes;
u64 len_bytes;
u32 type;
};
bool hl_device_supports_nvme(struct hl_device *hdev)
{
return hdev->asic_prop.supports_nvme;
}
static int hl_dio_fd_register(struct hl_ctx *ctx, int fd, struct hl_dio_fd *f)
{
struct hl_device *hdev = ctx->hdev;
struct block_device *bd;
struct super_block *sb;
struct inode *inode;
struct gendisk *gd;
struct device *disk_dev;
int rc;
f->filp = fget(fd);
if (!f->filp) {
rc = -ENOENT;
goto out;
}
if (!(f->filp->f_flags & O_DIRECT)) {
dev_err(hdev->dev, "file is not in the direct mode\n");
rc = -EINVAL;
goto fput;
}
if (!f->filp->f_op->read_iter) {
dev_err(hdev->dev, "read iter is not supported, need to fall back to legacy\n");
rc = -EINVAL;
goto fput;
}
inode = file_inode(f->filp);
sb = inode->i_sb;
bd = sb->s_bdev;
gd = bd->bd_disk;
if (inode->i_blocks << sb->s_blocksize_bits < i_size_read(inode)) {
dev_err(hdev->dev, "sparse files are not currently supported\n");
rc = -EINVAL;
goto fput;
}
if (!bd || !gd) {
dev_err(hdev->dev, "invalid block device\n");
rc = -ENODEV;
goto fput;
}
/* Get the underlying device from the block device */
disk_dev = disk_to_dev(gd);
if (!dma_pci_p2pdma_supported(disk_dev)) {
dev_err(hdev->dev, "device does not support PCI P2P DMA\n");
rc = -EOPNOTSUPP;
goto fput;
}
/*
* @TODO: Maybe we need additional checks here
*/
f->ctx = ctx;
rc = 0;
goto out;
fput:
fput(f->filp);
out:
return rc;
Annotation
- Immediate include surface: `habanalabs.h`, `hldio.h`, `generated/uapi/linux/version.h`, `linux/pci-p2pdma.h`, `linux/blkdev.h`, `linux/vmalloc.h`.
- Detected declarations: `struct hl_dio_fd`, `struct hl_direct_io`, `function hl_device_supports_nvme`, `function hl_dio_fd_register`, `function hl_dio_fd_unregister`, `function hl_dio_count_io`, `function hl_dio_get_iopath`, `function hl_dio_put_iopath`, `function hl_dio_set_io_enabled`, `function hl_dio_validate_io`.
- Atlas domain: Driver Families / drivers/accel.
- Implementation status: source implementation candidate.
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.