drivers/misc/ocxl/file.c
Source file repositories/reference/linux-study-clean/drivers/misc/ocxl/file.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/ocxl/file.c- Extension
.c- Size
- 13564 bytes
- Lines
- 624
- Domain
- Driver Families
- Bucket
- drivers/misc
- 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.
- 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.
- 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
linux/fs.hlinux/poll.hlinux/sched/signal.hlinux/eventfd.hlinux/uaccess.huapi/misc/ocxl.hasm/reg.hasm/switch_to.hocxl_internal.h
Detected Declarations
function allocate_minorfunction free_minorfunction afu_openfunction afu_ioctl_attachfunction afu_ioctl_get_metadatafunction afu_ioctl_enable_p9_waitfunction afu_ioctl_get_featuresfunction irq_handlerfunction irq_freefunction afu_ioctlfunction afu_compat_ioctlfunction afu_mmapfunction has_xsl_errorfunction afu_events_pendingfunction afu_pollfunction append_xsl_errorfunction Headerfunction afu_releasefunction info_releasefunction ocxl_file_make_visiblefunction ocxl_file_make_invisiblefunction ocxl_file_register_afufunction ocxl_file_unregister_afufunction ocxl_file_initfunction ocxl_file_exit
Annotated Snippet
static const struct file_operations ocxl_afu_fops = {
.owner = THIS_MODULE,
.open = afu_open,
.unlocked_ioctl = afu_ioctl,
.compat_ioctl = afu_compat_ioctl,
.mmap = afu_mmap,
.poll = afu_poll,
.read = afu_read,
.release = afu_release,
};
// Free the info struct
static void info_release(struct device *dev)
{
struct ocxl_file_info *info = container_of(dev, struct ocxl_file_info, dev);
ocxl_afu_put(info->afu);
kfree(info);
}
static int ocxl_file_make_visible(struct ocxl_file_info *info)
{
int rc;
cdev_init(&info->cdev, &ocxl_afu_fops);
rc = cdev_add(&info->cdev, info->dev.devt, 1);
if (rc) {
dev_err(&info->dev, "Unable to add afu char device: %d\n", rc);
return rc;
}
return 0;
}
static void ocxl_file_make_invisible(struct ocxl_file_info *info)
{
cdev_del(&info->cdev);
}
static char *ocxl_devnode(const struct device *dev, umode_t *mode)
{
return kasprintf(GFP_KERNEL, "ocxl/%s", dev_name(dev));
}
static const struct class ocxl_class = {
.name = "ocxl",
.devnode = ocxl_devnode,
};
int ocxl_file_register_afu(struct ocxl_afu *afu)
{
int minor;
int rc;
struct ocxl_file_info *info;
struct ocxl_fn *fn = afu->fn;
struct pci_dev *pci_dev = to_pci_dev(fn->dev.parent);
info = kzalloc_obj(*info);
if (info == NULL)
return -ENOMEM;
minor = allocate_minor(info);
if (minor < 0) {
kfree(info);
return minor;
}
info->dev.parent = &fn->dev;
info->dev.devt = MKDEV(MAJOR(ocxl_dev), minor);
info->dev.class = &ocxl_class;
info->dev.release = info_release;
info->afu = afu;
ocxl_afu_get(afu);
rc = dev_set_name(&info->dev, "%s.%s.%hhu",
afu->config.name, dev_name(&pci_dev->dev), afu->config.idx);
if (rc)
goto err_put;
rc = device_register(&info->dev);
if (rc) {
free_minor(info);
put_device(&info->dev);
return rc;
}
rc = ocxl_sysfs_register_afu(info);
if (rc)
goto err_unregister;
Annotation
- Immediate include surface: `linux/fs.h`, `linux/poll.h`, `linux/sched/signal.h`, `linux/eventfd.h`, `linux/uaccess.h`, `uapi/misc/ocxl.h`, `asm/reg.h`, `asm/switch_to.h`.
- Detected declarations: `function allocate_minor`, `function free_minor`, `function afu_open`, `function afu_ioctl_attach`, `function afu_ioctl_get_metadata`, `function afu_ioctl_enable_p9_wait`, `function afu_ioctl_get_features`, `function irq_handler`, `function irq_free`, `function afu_ioctl`.
- Atlas domain: Driver Families / drivers/misc.
- Implementation status: pattern 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.
- 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.