drivers/cxl/core/memdev.c
Source file repositories/reference/linux-study-clean/drivers/cxl/core/memdev.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/cxl/core/memdev.c- Extension
.c- Size
- 32807 bytes
- Lines
- 1251
- Domain
- Driver Families
- Bucket
- drivers/cxl
- 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
linux/io-64-nonatomic-lo-hi.hlinux/firmware.hlinux/device.hlinux/slab.hlinux/idr.hlinux/pci.hcxlmem.htrace.hcore.h
Detected Declarations
function cxl_memdev_releasefunction firmware_version_showfunction payload_max_showfunction label_storage_size_showfunction cxl_ram_sizefunction ram_size_showfunction pmem_size_showfunction serial_showfunction numa_node_showfunction security_state_showfunction security_sanitize_storefunction security_erase_storefunction cxl_memdev_has_poison_cmdfunction cxl_get_poison_by_memdevfunction cxl_trigger_poison_listfunction cxl_validate_poison_dpafunction cxl_inject_poison_lockedfunction cxl_inject_poisonfunction cxl_clear_poison_lockedfunction cxl_clear_poisonfunction pmem_qos_class_showfunction ram_qos_class_showfunction cxl_memdev_visiblefunction cxl_ram_visiblefunction cxl_pmem_visiblefunction cxl_memdev_security_visiblefunction cxl_memdev_update_perffunction is_cxl_memdevfunction set_exclusive_cxl_commandsfunction clear_exclusive_cxl_commandsfunction cxl_memdev_shutdownfunction cxl_memdev_unregisterfunction detach_memdevfunction __cxl_memdev_ioctlfunction cxl_memdev_ioctlfunction cxl_memdev_openfunction cxl_memdev_release_filefunction cxl_mem_get_fw_infofunction cxl_mem_activate_fwfunction cxl_mem_abort_fw_xferfunction cxl_fw_cleanupfunction cxl_fw_do_cancelfunction cxl_fw_preparefunction cxl_fw_writefunction cxl_fw_poll_completefunction cxl_fw_cancelfunction cxl_remove_fw_uploadfunction devm_cxl_setup_fw_upload
Annotated Snippet
const struct file_operations *fops,
const struct cxl_memdev_attach *attach)
{
struct cxl_memdev *cxlmd;
struct device *dev;
struct cdev *cdev;
int rc;
cxlmd = kzalloc_obj(*cxlmd);
if (!cxlmd)
return ERR_PTR(-ENOMEM);
rc = ida_alloc_max(&cxl_memdev_ida, CXL_MEM_MAX_DEVS - 1, GFP_KERNEL);
if (rc < 0)
goto err;
cxlmd->id = rc;
cxlmd->depth = -1;
cxlmd->attach = attach;
cxlmd->endpoint = ERR_PTR(-ENXIO);
dev = &cxlmd->dev;
device_initialize(dev);
lockdep_set_class(&dev->mutex, &cxl_memdev_key);
dev->parent = get_device(cxlds->dev);
dev->bus = &cxl_bus_type;
dev->devt = MKDEV(cxl_mem_major, cxlmd->id);
if (cxlds->type == CXL_DEVTYPE_DEVMEM)
dev->type = &cxl_memdev_type;
else
dev->type = &cxl_class_memdev_type;
device_set_pm_not_required(dev);
INIT_WORK(&cxlmd->detach_work, detach_memdev);
cdev = &cxlmd->cdev;
cdev_init(cdev, fops);
return cxlmd;
err:
kfree(cxlmd);
return ERR_PTR(rc);
}
static long __cxl_memdev_ioctl(struct cxl_memdev *cxlmd, unsigned int cmd,
unsigned long arg)
{
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds);
struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;
switch (cmd) {
case CXL_MEM_QUERY_COMMANDS:
return cxl_query_cmd(cxl_mbox, (void __user *)arg);
case CXL_MEM_SEND_COMMAND:
return cxl_send_cmd(cxl_mbox, (void __user *)arg);
default:
return -ENOTTY;
}
}
static long cxl_memdev_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
struct cxl_memdev *cxlmd = file->private_data;
struct cxl_dev_state *cxlds;
guard(rwsem_read)(&cxl_memdev_rwsem);
cxlds = cxlmd->cxlds;
if (cxlds && cxlds->type == CXL_DEVTYPE_CLASSMEM)
return __cxl_memdev_ioctl(cxlmd, cmd, arg);
return -ENXIO;
}
static int cxl_memdev_open(struct inode *inode, struct file *file)
{
struct cxl_memdev *cxlmd =
container_of(inode->i_cdev, typeof(*cxlmd), cdev);
get_device(&cxlmd->dev);
file->private_data = cxlmd;
return 0;
}
static int cxl_memdev_release_file(struct inode *inode, struct file *file)
{
struct cxl_memdev *cxlmd =
container_of(inode->i_cdev, typeof(*cxlmd), cdev);
put_device(&cxlmd->dev);
Annotation
- Immediate include surface: `linux/io-64-nonatomic-lo-hi.h`, `linux/firmware.h`, `linux/device.h`, `linux/slab.h`, `linux/idr.h`, `linux/pci.h`, `cxlmem.h`, `trace.h`.
- Detected declarations: `function cxl_memdev_release`, `function firmware_version_show`, `function payload_max_show`, `function label_storage_size_show`, `function cxl_ram_size`, `function ram_size_show`, `function pmem_size_show`, `function serial_show`, `function numa_node_show`, `function security_state_show`.
- Atlas domain: Driver Families / drivers/cxl.
- 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.